repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
sequence
docstring
stringlengths
6
2.61k
docstring_tokens
sequence
sha
stringlengths
40
40
url
stringlengths
85
252
partition
stringclasses
1 value
src-d/go-git
worktree_commit.go
Commit
func (w *Worktree) Commit(msg string, opts *CommitOptions) (plumbing.Hash, error) { if err := opts.Validate(w.r); err != nil { return plumbing.ZeroHash, err } if opts.All { if err := w.autoAddModifiedAndDeleted(); err != nil { return plumbing.ZeroHash, err } } idx, err := w.r.Storer.Index() if err != nil { return plumbing.ZeroHash, err } h := &buildTreeHelper{ fs: w.Filesystem, s: w.r.Storer, } tree, err := h.BuildTree(idx) if err != nil { return plumbing.ZeroHash, err } commit, err := w.buildCommitObject(msg, opts, tree) if err != nil { return plumbing.ZeroHash, err } return commit, w.updateHEAD(commit) }
go
func (w *Worktree) Commit(msg string, opts *CommitOptions) (plumbing.Hash, error) { if err := opts.Validate(w.r); err != nil { return plumbing.ZeroHash, err } if opts.All { if err := w.autoAddModifiedAndDeleted(); err != nil { return plumbing.ZeroHash, err } } idx, err := w.r.Storer.Index() if err != nil { return plumbing.ZeroHash, err } h := &buildTreeHelper{ fs: w.Filesystem, s: w.r.Storer, } tree, err := h.BuildTree(idx) if err != nil { return plumbing.ZeroHash, err } commit, err := w.buildCommitObject(msg, opts, tree) if err != nil { return plumbing.ZeroHash, err } return commit, w.updateHEAD(commit) }
[ "func", "(", "w", "*", "Worktree", ")", "Commit", "(", "msg", "string", ",", "opts", "*", "CommitOptions", ")", "(", "plumbing", ".", "Hash", ",", "error", ")", "{", "if", "err", ":=", "opts", ".", "Validate", "(", "w", ".", "r", ")", ";", "err", "!=", "nil", "{", "return", "plumbing", ".", "ZeroHash", ",", "err", "\n", "}", "\n\n", "if", "opts", ".", "All", "{", "if", "err", ":=", "w", ".", "autoAddModifiedAndDeleted", "(", ")", ";", "err", "!=", "nil", "{", "return", "plumbing", ".", "ZeroHash", ",", "err", "\n", "}", "\n", "}", "\n\n", "idx", ",", "err", ":=", "w", ".", "r", ".", "Storer", ".", "Index", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "plumbing", ".", "ZeroHash", ",", "err", "\n", "}", "\n\n", "h", ":=", "&", "buildTreeHelper", "{", "fs", ":", "w", ".", "Filesystem", ",", "s", ":", "w", ".", "r", ".", "Storer", ",", "}", "\n\n", "tree", ",", "err", ":=", "h", ".", "BuildTree", "(", "idx", ")", "\n", "if", "err", "!=", "nil", "{", "return", "plumbing", ".", "ZeroHash", ",", "err", "\n", "}", "\n\n", "commit", ",", "err", ":=", "w", ".", "buildCommitObject", "(", "msg", ",", "opts", ",", "tree", ")", "\n", "if", "err", "!=", "nil", "{", "return", "plumbing", ".", "ZeroHash", ",", "err", "\n", "}", "\n\n", "return", "commit", ",", "w", ".", "updateHEAD", "(", "commit", ")", "\n", "}" ]
// Commit stores the current contents of the index in a new commit along with // a log message from the user describing the changes.
[ "Commit", "stores", "the", "current", "contents", "of", "the", "index", "in", "a", "new", "commit", "along", "with", "a", "log", "message", "from", "the", "user", "describing", "the", "changes", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/worktree_commit.go#L21-L53
train
src-d/go-git
worktree_commit.go
BuildTree
func (h *buildTreeHelper) BuildTree(idx *index.Index) (plumbing.Hash, error) { const rootNode = "" h.trees = map[string]*object.Tree{rootNode: {}} h.entries = map[string]*object.TreeEntry{} for _, e := range idx.Entries { if err := h.commitIndexEntry(e); err != nil { return plumbing.ZeroHash, err } } return h.copyTreeToStorageRecursive(rootNode, h.trees[rootNode]) }
go
func (h *buildTreeHelper) BuildTree(idx *index.Index) (plumbing.Hash, error) { const rootNode = "" h.trees = map[string]*object.Tree{rootNode: {}} h.entries = map[string]*object.TreeEntry{} for _, e := range idx.Entries { if err := h.commitIndexEntry(e); err != nil { return plumbing.ZeroHash, err } } return h.copyTreeToStorageRecursive(rootNode, h.trees[rootNode]) }
[ "func", "(", "h", "*", "buildTreeHelper", ")", "BuildTree", "(", "idx", "*", "index", ".", "Index", ")", "(", "plumbing", ".", "Hash", ",", "error", ")", "{", "const", "rootNode", "=", "\"", "\"", "\n", "h", ".", "trees", "=", "map", "[", "string", "]", "*", "object", ".", "Tree", "{", "rootNode", ":", "{", "}", "}", "\n", "h", ".", "entries", "=", "map", "[", "string", "]", "*", "object", ".", "TreeEntry", "{", "}", "\n\n", "for", "_", ",", "e", ":=", "range", "idx", ".", "Entries", "{", "if", "err", ":=", "h", ".", "commitIndexEntry", "(", "e", ")", ";", "err", "!=", "nil", "{", "return", "plumbing", ".", "ZeroHash", ",", "err", "\n", "}", "\n", "}", "\n\n", "return", "h", ".", "copyTreeToStorageRecursive", "(", "rootNode", ",", "h", ".", "trees", "[", "rootNode", "]", ")", "\n", "}" ]
// BuildTree builds the tree objects and push its to the storer, the hash // of the root tree is returned.
[ "BuildTree", "builds", "the", "tree", "objects", "and", "push", "its", "to", "the", "storer", "the", "hash", "of", "the", "root", "tree", "is", "returned", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/worktree_commit.go#L142-L154
train
src-d/go-git
plumbing/format/idxfile/idxfile.go
Contains
func (idx *MemoryIndex) Contains(h plumbing.Hash) (bool, error) { _, ok := idx.findHashIndex(h) return ok, nil }
go
func (idx *MemoryIndex) Contains(h plumbing.Hash) (bool, error) { _, ok := idx.findHashIndex(h) return ok, nil }
[ "func", "(", "idx", "*", "MemoryIndex", ")", "Contains", "(", "h", "plumbing", ".", "Hash", ")", "(", "bool", ",", "error", ")", "{", "_", ",", "ok", ":=", "idx", ".", "findHashIndex", "(", "h", ")", "\n", "return", "ok", ",", "nil", "\n", "}" ]
// Contains implements the Index interface.
[ "Contains", "implements", "the", "Index", "interface", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/format/idxfile/idxfile.go#L109-L112
train
src-d/go-git
plumbing/format/idxfile/idxfile.go
FindOffset
func (idx *MemoryIndex) FindOffset(h plumbing.Hash) (int64, error) { if len(idx.FanoutMapping) <= int(h[0]) { return 0, plumbing.ErrObjectNotFound } k := idx.FanoutMapping[h[0]] i, ok := idx.findHashIndex(h) if !ok { return 0, plumbing.ErrObjectNotFound } offset := idx.getOffset(k, i) if !idx.offsetHashIsFull { // Save the offset for reverse lookup if idx.offsetHash == nil { idx.offsetHash = make(map[int64]plumbing.Hash) } idx.offsetHash[int64(offset)] = h } return int64(offset), nil }
go
func (idx *MemoryIndex) FindOffset(h plumbing.Hash) (int64, error) { if len(idx.FanoutMapping) <= int(h[0]) { return 0, plumbing.ErrObjectNotFound } k := idx.FanoutMapping[h[0]] i, ok := idx.findHashIndex(h) if !ok { return 0, plumbing.ErrObjectNotFound } offset := idx.getOffset(k, i) if !idx.offsetHashIsFull { // Save the offset for reverse lookup if idx.offsetHash == nil { idx.offsetHash = make(map[int64]plumbing.Hash) } idx.offsetHash[int64(offset)] = h } return int64(offset), nil }
[ "func", "(", "idx", "*", "MemoryIndex", ")", "FindOffset", "(", "h", "plumbing", ".", "Hash", ")", "(", "int64", ",", "error", ")", "{", "if", "len", "(", "idx", ".", "FanoutMapping", ")", "<=", "int", "(", "h", "[", "0", "]", ")", "{", "return", "0", ",", "plumbing", ".", "ErrObjectNotFound", "\n", "}", "\n\n", "k", ":=", "idx", ".", "FanoutMapping", "[", "h", "[", "0", "]", "]", "\n", "i", ",", "ok", ":=", "idx", ".", "findHashIndex", "(", "h", ")", "\n", "if", "!", "ok", "{", "return", "0", ",", "plumbing", ".", "ErrObjectNotFound", "\n", "}", "\n\n", "offset", ":=", "idx", ".", "getOffset", "(", "k", ",", "i", ")", "\n\n", "if", "!", "idx", ".", "offsetHashIsFull", "{", "// Save the offset for reverse lookup", "if", "idx", ".", "offsetHash", "==", "nil", "{", "idx", ".", "offsetHash", "=", "make", "(", "map", "[", "int64", "]", "plumbing", ".", "Hash", ")", "\n", "}", "\n", "idx", ".", "offsetHash", "[", "int64", "(", "offset", ")", "]", "=", "h", "\n", "}", "\n\n", "return", "int64", "(", "offset", ")", ",", "nil", "\n", "}" ]
// FindOffset implements the Index interface.
[ "FindOffset", "implements", "the", "Index", "interface", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/format/idxfile/idxfile.go#L115-L137
train
src-d/go-git
plumbing/format/idxfile/idxfile.go
FindCRC32
func (idx *MemoryIndex) FindCRC32(h plumbing.Hash) (uint32, error) { k := idx.FanoutMapping[h[0]] i, ok := idx.findHashIndex(h) if !ok { return 0, plumbing.ErrObjectNotFound } return idx.getCRC32(k, i), nil }
go
func (idx *MemoryIndex) FindCRC32(h plumbing.Hash) (uint32, error) { k := idx.FanoutMapping[h[0]] i, ok := idx.findHashIndex(h) if !ok { return 0, plumbing.ErrObjectNotFound } return idx.getCRC32(k, i), nil }
[ "func", "(", "idx", "*", "MemoryIndex", ")", "FindCRC32", "(", "h", "plumbing", ".", "Hash", ")", "(", "uint32", ",", "error", ")", "{", "k", ":=", "idx", ".", "FanoutMapping", "[", "h", "[", "0", "]", "]", "\n", "i", ",", "ok", ":=", "idx", ".", "findHashIndex", "(", "h", ")", "\n", "if", "!", "ok", "{", "return", "0", ",", "plumbing", ".", "ErrObjectNotFound", "\n", "}", "\n\n", "return", "idx", ".", "getCRC32", "(", "k", ",", "i", ")", ",", "nil", "\n", "}" ]
// FindCRC32 implements the Index interface.
[ "FindCRC32", "implements", "the", "Index", "interface", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/format/idxfile/idxfile.go#L155-L163
train
src-d/go-git
plumbing/format/idxfile/idxfile.go
FindHash
func (idx *MemoryIndex) FindHash(o int64) (plumbing.Hash, error) { var hash plumbing.Hash var ok bool if idx.offsetHash != nil { if hash, ok = idx.offsetHash[o]; ok { return hash, nil } } // Lazily generate the reverse offset/hash map if required. if !idx.offsetHashIsFull || idx.offsetHash == nil { if err := idx.genOffsetHash(); err != nil { return plumbing.ZeroHash, err } hash, ok = idx.offsetHash[o] } if !ok { return plumbing.ZeroHash, plumbing.ErrObjectNotFound } return hash, nil }
go
func (idx *MemoryIndex) FindHash(o int64) (plumbing.Hash, error) { var hash plumbing.Hash var ok bool if idx.offsetHash != nil { if hash, ok = idx.offsetHash[o]; ok { return hash, nil } } // Lazily generate the reverse offset/hash map if required. if !idx.offsetHashIsFull || idx.offsetHash == nil { if err := idx.genOffsetHash(); err != nil { return plumbing.ZeroHash, err } hash, ok = idx.offsetHash[o] } if !ok { return plumbing.ZeroHash, plumbing.ErrObjectNotFound } return hash, nil }
[ "func", "(", "idx", "*", "MemoryIndex", ")", "FindHash", "(", "o", "int64", ")", "(", "plumbing", ".", "Hash", ",", "error", ")", "{", "var", "hash", "plumbing", ".", "Hash", "\n", "var", "ok", "bool", "\n\n", "if", "idx", ".", "offsetHash", "!=", "nil", "{", "if", "hash", ",", "ok", "=", "idx", ".", "offsetHash", "[", "o", "]", ";", "ok", "{", "return", "hash", ",", "nil", "\n", "}", "\n", "}", "\n\n", "// Lazily generate the reverse offset/hash map if required.", "if", "!", "idx", ".", "offsetHashIsFull", "||", "idx", ".", "offsetHash", "==", "nil", "{", "if", "err", ":=", "idx", ".", "genOffsetHash", "(", ")", ";", "err", "!=", "nil", "{", "return", "plumbing", ".", "ZeroHash", ",", "err", "\n", "}", "\n\n", "hash", ",", "ok", "=", "idx", ".", "offsetHash", "[", "o", "]", "\n", "}", "\n\n", "if", "!", "ok", "{", "return", "plumbing", ".", "ZeroHash", ",", "plumbing", ".", "ErrObjectNotFound", "\n", "}", "\n\n", "return", "hash", ",", "nil", "\n", "}" ]
// FindHash implements the Index interface.
[ "FindHash", "implements", "the", "Index", "interface", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/format/idxfile/idxfile.go#L171-L195
train
src-d/go-git
plumbing/format/idxfile/idxfile.go
Count
func (idx *MemoryIndex) Count() (int64, error) { return int64(idx.Fanout[fanout-1]), nil }
go
func (idx *MemoryIndex) Count() (int64, error) { return int64(idx.Fanout[fanout-1]), nil }
[ "func", "(", "idx", "*", "MemoryIndex", ")", "Count", "(", ")", "(", "int64", ",", "error", ")", "{", "return", "int64", "(", "idx", ".", "Fanout", "[", "fanout", "-", "1", "]", ")", ",", "nil", "\n", "}" ]
// Count implements the Index interface.
[ "Count", "implements", "the", "Index", "interface", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/format/idxfile/idxfile.go#L223-L225
train
src-d/go-git
plumbing/format/idxfile/idxfile.go
EntriesByOffset
func (idx *MemoryIndex) EntriesByOffset() (EntryIter, error) { count, err := idx.Count() if err != nil { return nil, err } iter := &idxfileEntryOffsetIter{ entries: make(entriesByOffset, count), } entries, err := idx.Entries() if err != nil { return nil, err } for pos := 0; int64(pos) < count; pos++ { entry, err := entries.Next() if err != nil { return nil, err } iter.entries[pos] = entry } sort.Sort(iter.entries) return iter, nil }
go
func (idx *MemoryIndex) EntriesByOffset() (EntryIter, error) { count, err := idx.Count() if err != nil { return nil, err } iter := &idxfileEntryOffsetIter{ entries: make(entriesByOffset, count), } entries, err := idx.Entries() if err != nil { return nil, err } for pos := 0; int64(pos) < count; pos++ { entry, err := entries.Next() if err != nil { return nil, err } iter.entries[pos] = entry } sort.Sort(iter.entries) return iter, nil }
[ "func", "(", "idx", "*", "MemoryIndex", ")", "EntriesByOffset", "(", ")", "(", "EntryIter", ",", "error", ")", "{", "count", ",", "err", ":=", "idx", ".", "Count", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "iter", ":=", "&", "idxfileEntryOffsetIter", "{", "entries", ":", "make", "(", "entriesByOffset", ",", "count", ")", ",", "}", "\n\n", "entries", ",", "err", ":=", "idx", ".", "Entries", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "for", "pos", ":=", "0", ";", "int64", "(", "pos", ")", "<", "count", ";", "pos", "++", "{", "entry", ",", "err", ":=", "entries", ".", "Next", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "iter", ".", "entries", "[", "pos", "]", "=", "entry", "\n", "}", "\n\n", "sort", ".", "Sort", "(", "iter", ".", "entries", ")", "\n\n", "return", "iter", ",", "nil", "\n", "}" ]
// EntriesByOffset implements the Index interface.
[ "EntriesByOffset", "implements", "the", "Index", "interface", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/format/idxfile/idxfile.go#L233-L260
train
src-d/go-git
plumbing/reference.go
NewRemoteReferenceName
func NewRemoteReferenceName(remote, name string) ReferenceName { return ReferenceName(refRemotePrefix + fmt.Sprintf("%s/%s", remote, name)) }
go
func NewRemoteReferenceName(remote, name string) ReferenceName { return ReferenceName(refRemotePrefix + fmt.Sprintf("%s/%s", remote, name)) }
[ "func", "NewRemoteReferenceName", "(", "remote", ",", "name", "string", ")", "ReferenceName", "{", "return", "ReferenceName", "(", "refRemotePrefix", "+", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "remote", ",", "name", ")", ")", "\n", "}" ]
// NewRemoteReferenceName returns a reference name describing a remote branch // based on his short name and the remote name.
[ "NewRemoteReferenceName", "returns", "a", "reference", "name", "describing", "a", "remote", "branch", "based", "on", "his", "short", "name", "and", "the", "remote", "name", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/reference.go#L72-L74
train
src-d/go-git
plumbing/reference.go
NewRemoteHEADReferenceName
func NewRemoteHEADReferenceName(remote string) ReferenceName { return ReferenceName(refRemotePrefix + fmt.Sprintf("%s/%s", remote, HEAD)) }
go
func NewRemoteHEADReferenceName(remote string) ReferenceName { return ReferenceName(refRemotePrefix + fmt.Sprintf("%s/%s", remote, HEAD)) }
[ "func", "NewRemoteHEADReferenceName", "(", "remote", "string", ")", "ReferenceName", "{", "return", "ReferenceName", "(", "refRemotePrefix", "+", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "remote", ",", "HEAD", ")", ")", "\n", "}" ]
// NewRemoteHEADReferenceName returns a reference name describing a the HEAD // branch of a remote.
[ "NewRemoteHEADReferenceName", "returns", "a", "reference", "name", "describing", "a", "the", "HEAD", "branch", "of", "a", "remote", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/reference.go#L78-L80
train
src-d/go-git
plumbing/reference.go
Short
func (r ReferenceName) Short() string { s := string(r) res := s for _, format := range RefRevParseRules { _, err := fmt.Sscanf(s, format, &res) if err == nil { continue } } return res }
go
func (r ReferenceName) Short() string { s := string(r) res := s for _, format := range RefRevParseRules { _, err := fmt.Sscanf(s, format, &res) if err == nil { continue } } return res }
[ "func", "(", "r", "ReferenceName", ")", "Short", "(", ")", "string", "{", "s", ":=", "string", "(", "r", ")", "\n", "res", ":=", "s", "\n", "for", "_", ",", "format", ":=", "range", "RefRevParseRules", "{", "_", ",", "err", ":=", "fmt", ".", "Sscanf", "(", "s", ",", "format", ",", "&", "res", ")", "\n", "if", "err", "==", "nil", "{", "continue", "\n", "}", "\n", "}", "\n\n", "return", "res", "\n", "}" ]
// Short returns the short name of a ReferenceName
[ "Short", "returns", "the", "short", "name", "of", "a", "ReferenceName" ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/reference.go#L113-L124
train
src-d/go-git
plumbing/reference.go
NewReferenceFromStrings
func NewReferenceFromStrings(name, target string) *Reference { n := ReferenceName(name) if strings.HasPrefix(target, symrefPrefix) { target := ReferenceName(target[len(symrefPrefix):]) return NewSymbolicReference(n, target) } return NewHashReference(n, NewHash(target)) }
go
func NewReferenceFromStrings(name, target string) *Reference { n := ReferenceName(name) if strings.HasPrefix(target, symrefPrefix) { target := ReferenceName(target[len(symrefPrefix):]) return NewSymbolicReference(n, target) } return NewHashReference(n, NewHash(target)) }
[ "func", "NewReferenceFromStrings", "(", "name", ",", "target", "string", ")", "*", "Reference", "{", "n", ":=", "ReferenceName", "(", "name", ")", "\n\n", "if", "strings", ".", "HasPrefix", "(", "target", ",", "symrefPrefix", ")", "{", "target", ":=", "ReferenceName", "(", "target", "[", "len", "(", "symrefPrefix", ")", ":", "]", ")", "\n", "return", "NewSymbolicReference", "(", "n", ",", "target", ")", "\n", "}", "\n\n", "return", "NewHashReference", "(", "n", ",", "NewHash", "(", "target", ")", ")", "\n", "}" ]
// NewReferenceFromStrings creates a reference from name and target as string, // the resulting reference can be a SymbolicReference or a HashReference base // on the target provided
[ "NewReferenceFromStrings", "creates", "a", "reference", "from", "name", "and", "target", "as", "string", "the", "resulting", "reference", "can", "be", "a", "SymbolicReference", "or", "a", "HashReference", "base", "on", "the", "target", "provided" ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/reference.go#L142-L151
train
src-d/go-git
plumbing/reference.go
NewSymbolicReference
func NewSymbolicReference(n, target ReferenceName) *Reference { return &Reference{ t: SymbolicReference, n: n, target: target, } }
go
func NewSymbolicReference(n, target ReferenceName) *Reference { return &Reference{ t: SymbolicReference, n: n, target: target, } }
[ "func", "NewSymbolicReference", "(", "n", ",", "target", "ReferenceName", ")", "*", "Reference", "{", "return", "&", "Reference", "{", "t", ":", "SymbolicReference", ",", "n", ":", "n", ",", "target", ":", "target", ",", "}", "\n", "}" ]
// NewSymbolicReference creates a new SymbolicReference reference
[ "NewSymbolicReference", "creates", "a", "new", "SymbolicReference", "reference" ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/reference.go#L154-L160
train
src-d/go-git
plumbing/reference.go
NewHashReference
func NewHashReference(n ReferenceName, h Hash) *Reference { return &Reference{ t: HashReference, n: n, h: h, } }
go
func NewHashReference(n ReferenceName, h Hash) *Reference { return &Reference{ t: HashReference, n: n, h: h, } }
[ "func", "NewHashReference", "(", "n", "ReferenceName", ",", "h", "Hash", ")", "*", "Reference", "{", "return", "&", "Reference", "{", "t", ":", "HashReference", ",", "n", ":", "n", ",", "h", ":", "h", ",", "}", "\n", "}" ]
// NewHashReference creates a new HashReference reference
[ "NewHashReference", "creates", "a", "new", "HashReference", "reference" ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/reference.go#L163-L169
train
src-d/go-git
plumbing/protocol/packp/uppackreq.go
Encode
func (u *UploadHaves) Encode(w io.Writer, flush bool) error { e := pktline.NewEncoder(w) plumbing.HashesSort(u.Haves) var last plumbing.Hash for _, have := range u.Haves { if bytes.Equal(last[:], have[:]) { continue } if err := e.Encodef("have %s\n", have); err != nil { return fmt.Errorf("sending haves for %q: %s", have, err) } last = have } if flush && len(u.Haves) != 0 { if err := e.Flush(); err != nil { return fmt.Errorf("sending flush-pkt after haves: %s", err) } } return nil }
go
func (u *UploadHaves) Encode(w io.Writer, flush bool) error { e := pktline.NewEncoder(w) plumbing.HashesSort(u.Haves) var last plumbing.Hash for _, have := range u.Haves { if bytes.Equal(last[:], have[:]) { continue } if err := e.Encodef("have %s\n", have); err != nil { return fmt.Errorf("sending haves for %q: %s", have, err) } last = have } if flush && len(u.Haves) != 0 { if err := e.Flush(); err != nil { return fmt.Errorf("sending flush-pkt after haves: %s", err) } } return nil }
[ "func", "(", "u", "*", "UploadHaves", ")", "Encode", "(", "w", "io", ".", "Writer", ",", "flush", "bool", ")", "error", "{", "e", ":=", "pktline", ".", "NewEncoder", "(", "w", ")", "\n\n", "plumbing", ".", "HashesSort", "(", "u", ".", "Haves", ")", "\n\n", "var", "last", "plumbing", ".", "Hash", "\n", "for", "_", ",", "have", ":=", "range", "u", ".", "Haves", "{", "if", "bytes", ".", "Equal", "(", "last", "[", ":", "]", ",", "have", "[", ":", "]", ")", "{", "continue", "\n", "}", "\n\n", "if", "err", ":=", "e", ".", "Encodef", "(", "\"", "\\n", "\"", ",", "have", ")", ";", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "have", ",", "err", ")", "\n", "}", "\n\n", "last", "=", "have", "\n", "}", "\n\n", "if", "flush", "&&", "len", "(", "u", ".", "Haves", ")", "!=", "0", "{", "if", "err", ":=", "e", ".", "Flush", "(", ")", ";", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Encode encodes the UploadHaves into the Writer. If flush is true, a flush // command will be encoded at the end of the writer content.
[ "Encode", "encodes", "the", "UploadHaves", "into", "the", "Writer", ".", "If", "flush", "is", "true", "a", "flush", "command", "will", "be", "encoded", "at", "the", "end", "of", "the", "writer", "content", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/protocol/packp/uppackreq.go#L73-L98
train
src-d/go-git
plumbing/transport/http/common.go
applyHeadersToRequest
func applyHeadersToRequest(req *http.Request, content *bytes.Buffer, host string, requestType string) { req.Header.Add("User-Agent", "git/1.0") req.Header.Add("Host", host) // host:port if content == nil { req.Header.Add("Accept", "*/*") return } req.Header.Add("Accept", fmt.Sprintf("application/x-%s-result", requestType)) req.Header.Add("Content-Type", fmt.Sprintf("application/x-%s-request", requestType)) req.Header.Add("Content-Length", strconv.Itoa(content.Len())) }
go
func applyHeadersToRequest(req *http.Request, content *bytes.Buffer, host string, requestType string) { req.Header.Add("User-Agent", "git/1.0") req.Header.Add("Host", host) // host:port if content == nil { req.Header.Add("Accept", "*/*") return } req.Header.Add("Accept", fmt.Sprintf("application/x-%s-result", requestType)) req.Header.Add("Content-Type", fmt.Sprintf("application/x-%s-request", requestType)) req.Header.Add("Content-Length", strconv.Itoa(content.Len())) }
[ "func", "applyHeadersToRequest", "(", "req", "*", "http", ".", "Request", ",", "content", "*", "bytes", ".", "Buffer", ",", "host", "string", ",", "requestType", "string", ")", "{", "req", ".", "Header", ".", "Add", "(", "\"", "\"", ",", "\"", "\"", ")", "\n", "req", ".", "Header", ".", "Add", "(", "\"", "\"", ",", "host", ")", "// host:port", "\n\n", "if", "content", "==", "nil", "{", "req", ".", "Header", ".", "Add", "(", "\"", "\"", ",", "\"", "\"", ")", "\n", "return", "\n", "}", "\n\n", "req", ".", "Header", ".", "Add", "(", "\"", "\"", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "requestType", ")", ")", "\n", "req", ".", "Header", ".", "Add", "(", "\"", "\"", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "requestType", ")", ")", "\n", "req", ".", "Header", ".", "Add", "(", "\"", "\"", ",", "strconv", ".", "Itoa", "(", "content", ".", "Len", "(", ")", ")", ")", "\n", "}" ]
// it requires a bytes.Buffer, because we need to know the length
[ "it", "requires", "a", "bytes", ".", "Buffer", "because", "we", "need", "to", "know", "the", "length" ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/transport/http/common.go#L19-L31
train
src-d/go-git
plumbing/transport/http/common.go
NewErr
func NewErr(r *http.Response) error { if r.StatusCode >= http.StatusOK && r.StatusCode < http.StatusMultipleChoices { return nil } switch r.StatusCode { case http.StatusUnauthorized: return transport.ErrAuthenticationRequired case http.StatusForbidden: return transport.ErrAuthorizationFailed case http.StatusNotFound: return transport.ErrRepositoryNotFound } return plumbing.NewUnexpectedError(&Err{r}) }
go
func NewErr(r *http.Response) error { if r.StatusCode >= http.StatusOK && r.StatusCode < http.StatusMultipleChoices { return nil } switch r.StatusCode { case http.StatusUnauthorized: return transport.ErrAuthenticationRequired case http.StatusForbidden: return transport.ErrAuthorizationFailed case http.StatusNotFound: return transport.ErrRepositoryNotFound } return plumbing.NewUnexpectedError(&Err{r}) }
[ "func", "NewErr", "(", "r", "*", "http", ".", "Response", ")", "error", "{", "if", "r", ".", "StatusCode", ">=", "http", ".", "StatusOK", "&&", "r", ".", "StatusCode", "<", "http", ".", "StatusMultipleChoices", "{", "return", "nil", "\n", "}", "\n\n", "switch", "r", ".", "StatusCode", "{", "case", "http", ".", "StatusUnauthorized", ":", "return", "transport", ".", "ErrAuthenticationRequired", "\n", "case", "http", ".", "StatusForbidden", ":", "return", "transport", ".", "ErrAuthorizationFailed", "\n", "case", "http", ".", "StatusNotFound", ":", "return", "transport", ".", "ErrRepositoryNotFound", "\n", "}", "\n\n", "return", "plumbing", ".", "NewUnexpectedError", "(", "&", "Err", "{", "r", "}", ")", "\n", "}" ]
// NewErr returns a new Err based on a http response
[ "NewErr", "returns", "a", "new", "Err", "based", "on", "a", "http", "response" ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/transport/http/common.go#L255-L270
train
src-d/go-git
plumbing/format/packfile/delta_selector.go
ObjectsToPack
func (dw *deltaSelector) ObjectsToPack( hashes []plumbing.Hash, packWindow uint, ) ([]*ObjectToPack, error) { otp, err := dw.objectsToPack(hashes, packWindow) if err != nil { return nil, err } if packWindow == 0 { return otp, nil } dw.sort(otp) var objectGroups [][]*ObjectToPack var prev *ObjectToPack i := -1 for _, obj := range otp { if prev == nil || prev.Type() != obj.Type() { objectGroups = append(objectGroups, []*ObjectToPack{obj}) i++ prev = obj } else { objectGroups[i] = append(objectGroups[i], obj) } } var wg sync.WaitGroup var once sync.Once for _, objs := range objectGroups { objs := objs wg.Add(1) go func() { if walkErr := dw.walk(objs, packWindow); walkErr != nil { once.Do(func() { err = walkErr }) } wg.Done() }() } wg.Wait() if err != nil { return nil, err } return otp, nil }
go
func (dw *deltaSelector) ObjectsToPack( hashes []plumbing.Hash, packWindow uint, ) ([]*ObjectToPack, error) { otp, err := dw.objectsToPack(hashes, packWindow) if err != nil { return nil, err } if packWindow == 0 { return otp, nil } dw.sort(otp) var objectGroups [][]*ObjectToPack var prev *ObjectToPack i := -1 for _, obj := range otp { if prev == nil || prev.Type() != obj.Type() { objectGroups = append(objectGroups, []*ObjectToPack{obj}) i++ prev = obj } else { objectGroups[i] = append(objectGroups[i], obj) } } var wg sync.WaitGroup var once sync.Once for _, objs := range objectGroups { objs := objs wg.Add(1) go func() { if walkErr := dw.walk(objs, packWindow); walkErr != nil { once.Do(func() { err = walkErr }) } wg.Done() }() } wg.Wait() if err != nil { return nil, err } return otp, nil }
[ "func", "(", "dw", "*", "deltaSelector", ")", "ObjectsToPack", "(", "hashes", "[", "]", "plumbing", ".", "Hash", ",", "packWindow", "uint", ",", ")", "(", "[", "]", "*", "ObjectToPack", ",", "error", ")", "{", "otp", ",", "err", ":=", "dw", ".", "objectsToPack", "(", "hashes", ",", "packWindow", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "if", "packWindow", "==", "0", "{", "return", "otp", ",", "nil", "\n", "}", "\n\n", "dw", ".", "sort", "(", "otp", ")", "\n\n", "var", "objectGroups", "[", "]", "[", "]", "*", "ObjectToPack", "\n", "var", "prev", "*", "ObjectToPack", "\n", "i", ":=", "-", "1", "\n", "for", "_", ",", "obj", ":=", "range", "otp", "{", "if", "prev", "==", "nil", "||", "prev", ".", "Type", "(", ")", "!=", "obj", ".", "Type", "(", ")", "{", "objectGroups", "=", "append", "(", "objectGroups", ",", "[", "]", "*", "ObjectToPack", "{", "obj", "}", ")", "\n", "i", "++", "\n", "prev", "=", "obj", "\n", "}", "else", "{", "objectGroups", "[", "i", "]", "=", "append", "(", "objectGroups", "[", "i", "]", ",", "obj", ")", "\n", "}", "\n", "}", "\n\n", "var", "wg", "sync", ".", "WaitGroup", "\n", "var", "once", "sync", ".", "Once", "\n", "for", "_", ",", "objs", ":=", "range", "objectGroups", "{", "objs", ":=", "objs", "\n", "wg", ".", "Add", "(", "1", ")", "\n", "go", "func", "(", ")", "{", "if", "walkErr", ":=", "dw", ".", "walk", "(", "objs", ",", "packWindow", ")", ";", "walkErr", "!=", "nil", "{", "once", ".", "Do", "(", "func", "(", ")", "{", "err", "=", "walkErr", "\n", "}", ")", "\n", "}", "\n", "wg", ".", "Done", "(", ")", "\n", "}", "(", ")", "\n", "}", "\n", "wg", ".", "Wait", "(", ")", "\n\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "otp", ",", "nil", "\n", "}" ]
// ObjectsToPack creates a list of ObjectToPack from the hashes // provided, creating deltas if it's suitable, using an specific // internal logic. `packWindow` specifies the size of the sliding // window used to compare objects for delta compression; 0 turns off // delta compression entirely.
[ "ObjectsToPack", "creates", "a", "list", "of", "ObjectToPack", "from", "the", "hashes", "provided", "creating", "deltas", "if", "it", "s", "suitable", "using", "an", "specific", "internal", "logic", ".", "packWindow", "specifies", "the", "size", "of", "the", "sliding", "window", "used", "to", "compare", "objects", "for", "delta", "compression", ";", "0", "turns", "off", "delta", "compression", "entirely", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/format/packfile/delta_selector.go#L36-L85
train
src-d/go-git
plumbing/revlist/revlist.go
Objects
func Objects( s storer.EncodedObjectStorer, objs, ignore []plumbing.Hash, ) ([]plumbing.Hash, error) { return ObjectsWithStorageForIgnores(s, s, objs, ignore) }
go
func Objects( s storer.EncodedObjectStorer, objs, ignore []plumbing.Hash, ) ([]plumbing.Hash, error) { return ObjectsWithStorageForIgnores(s, s, objs, ignore) }
[ "func", "Objects", "(", "s", "storer", ".", "EncodedObjectStorer", ",", "objs", ",", "ignore", "[", "]", "plumbing", ".", "Hash", ",", ")", "(", "[", "]", "plumbing", ".", "Hash", ",", "error", ")", "{", "return", "ObjectsWithStorageForIgnores", "(", "s", ",", "s", ",", "objs", ",", "ignore", ")", "\n", "}" ]
// Objects applies a complementary set. It gets all the hashes from all // the reachable objects from the given objects. Ignore param are object hashes // that we want to ignore on the result. All that objects must be accessible // from the object storer.
[ "Objects", "applies", "a", "complementary", "set", ".", "It", "gets", "all", "the", "hashes", "from", "all", "the", "reachable", "objects", "from", "the", "given", "objects", ".", "Ignore", "param", "are", "object", "hashes", "that", "we", "want", "to", "ignore", "on", "the", "result", ".", "All", "that", "objects", "must", "be", "accessible", "from", "the", "object", "storer", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/revlist/revlist.go#L19-L25
train
src-d/go-git
plumbing/revlist/revlist.go
processObject
func processObject( s storer.EncodedObjectStorer, h plumbing.Hash, seen map[plumbing.Hash]bool, visited map[plumbing.Hash]bool, ignore []plumbing.Hash, walkerFunc func(h plumbing.Hash), ) error { if seen[h] { return nil } o, err := s.EncodedObject(plumbing.AnyObject, h) if err != nil { return err } do, err := object.DecodeObject(s, o) if err != nil { return err } switch do := do.(type) { case *object.Commit: return reachableObjects(do, seen, visited, ignore, walkerFunc) case *object.Tree: return iterateCommitTrees(seen, do, walkerFunc) case *object.Tag: walkerFunc(do.Hash) return processObject(s, do.Target, seen, visited, ignore, walkerFunc) case *object.Blob: walkerFunc(do.Hash) default: return fmt.Errorf("object type not valid: %s. "+ "Object reference: %s", o.Type(), o.Hash()) } return nil }
go
func processObject( s storer.EncodedObjectStorer, h plumbing.Hash, seen map[plumbing.Hash]bool, visited map[plumbing.Hash]bool, ignore []plumbing.Hash, walkerFunc func(h plumbing.Hash), ) error { if seen[h] { return nil } o, err := s.EncodedObject(plumbing.AnyObject, h) if err != nil { return err } do, err := object.DecodeObject(s, o) if err != nil { return err } switch do := do.(type) { case *object.Commit: return reachableObjects(do, seen, visited, ignore, walkerFunc) case *object.Tree: return iterateCommitTrees(seen, do, walkerFunc) case *object.Tag: walkerFunc(do.Hash) return processObject(s, do.Target, seen, visited, ignore, walkerFunc) case *object.Blob: walkerFunc(do.Hash) default: return fmt.Errorf("object type not valid: %s. "+ "Object reference: %s", o.Type(), o.Hash()) } return nil }
[ "func", "processObject", "(", "s", "storer", ".", "EncodedObjectStorer", ",", "h", "plumbing", ".", "Hash", ",", "seen", "map", "[", "plumbing", ".", "Hash", "]", "bool", ",", "visited", "map", "[", "plumbing", ".", "Hash", "]", "bool", ",", "ignore", "[", "]", "plumbing", ".", "Hash", ",", "walkerFunc", "func", "(", "h", "plumbing", ".", "Hash", ")", ",", ")", "error", "{", "if", "seen", "[", "h", "]", "{", "return", "nil", "\n", "}", "\n\n", "o", ",", "err", ":=", "s", ".", "EncodedObject", "(", "plumbing", ".", "AnyObject", ",", "h", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "do", ",", "err", ":=", "object", ".", "DecodeObject", "(", "s", ",", "o", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "switch", "do", ":=", "do", ".", "(", "type", ")", "{", "case", "*", "object", ".", "Commit", ":", "return", "reachableObjects", "(", "do", ",", "seen", ",", "visited", ",", "ignore", ",", "walkerFunc", ")", "\n", "case", "*", "object", ".", "Tree", ":", "return", "iterateCommitTrees", "(", "seen", ",", "do", ",", "walkerFunc", ")", "\n", "case", "*", "object", ".", "Tag", ":", "walkerFunc", "(", "do", ".", "Hash", ")", "\n", "return", "processObject", "(", "s", ",", "do", ".", "Target", ",", "seen", ",", "visited", ",", "ignore", ",", "walkerFunc", ")", "\n", "case", "*", "object", ".", "Blob", ":", "walkerFunc", "(", "do", ".", "Hash", ")", "\n", "default", ":", "return", "fmt", ".", "Errorf", "(", "\"", "\"", "+", "\"", "\"", ",", "o", ".", "Type", "(", ")", ",", "o", ".", "Hash", "(", ")", ")", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// processObject obtains the object using the hash an process it depending of its type
[ "processObject", "obtains", "the", "object", "using", "the", "hash", "an", "process", "it", "depending", "of", "its", "type" ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/revlist/revlist.go#L76-L114
train
src-d/go-git
plumbing/revlist/revlist.go
reachableObjects
func reachableObjects( commit *object.Commit, seen map[plumbing.Hash]bool, visited map[plumbing.Hash]bool, ignore []plumbing.Hash, cb func(h plumbing.Hash), ) error { i := object.NewCommitPreorderIter(commit, seen, ignore) pending := make(map[plumbing.Hash]bool) addPendingParents(pending, visited, commit) for { commit, err := i.Next() if err == io.EOF { break } if err != nil { return err } if pending[commit.Hash] { delete(pending, commit.Hash) } addPendingParents(pending, visited, commit) if visited[commit.Hash] && len(pending) == 0 { break } if seen[commit.Hash] { continue } cb(commit.Hash) tree, err := commit.Tree() if err != nil { return err } if err := iterateCommitTrees(seen, tree, cb); err != nil { return err } } return nil }
go
func reachableObjects( commit *object.Commit, seen map[plumbing.Hash]bool, visited map[plumbing.Hash]bool, ignore []plumbing.Hash, cb func(h plumbing.Hash), ) error { i := object.NewCommitPreorderIter(commit, seen, ignore) pending := make(map[plumbing.Hash]bool) addPendingParents(pending, visited, commit) for { commit, err := i.Next() if err == io.EOF { break } if err != nil { return err } if pending[commit.Hash] { delete(pending, commit.Hash) } addPendingParents(pending, visited, commit) if visited[commit.Hash] && len(pending) == 0 { break } if seen[commit.Hash] { continue } cb(commit.Hash) tree, err := commit.Tree() if err != nil { return err } if err := iterateCommitTrees(seen, tree, cb); err != nil { return err } } return nil }
[ "func", "reachableObjects", "(", "commit", "*", "object", ".", "Commit", ",", "seen", "map", "[", "plumbing", ".", "Hash", "]", "bool", ",", "visited", "map", "[", "plumbing", ".", "Hash", "]", "bool", ",", "ignore", "[", "]", "plumbing", ".", "Hash", ",", "cb", "func", "(", "h", "plumbing", ".", "Hash", ")", ",", ")", "error", "{", "i", ":=", "object", ".", "NewCommitPreorderIter", "(", "commit", ",", "seen", ",", "ignore", ")", "\n", "pending", ":=", "make", "(", "map", "[", "plumbing", ".", "Hash", "]", "bool", ")", "\n", "addPendingParents", "(", "pending", ",", "visited", ",", "commit", ")", "\n", "for", "{", "commit", ",", "err", ":=", "i", ".", "Next", "(", ")", "\n", "if", "err", "==", "io", ".", "EOF", "{", "break", "\n", "}", "\n\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "if", "pending", "[", "commit", ".", "Hash", "]", "{", "delete", "(", "pending", ",", "commit", ".", "Hash", ")", "\n", "}", "\n\n", "addPendingParents", "(", "pending", ",", "visited", ",", "commit", ")", "\n\n", "if", "visited", "[", "commit", ".", "Hash", "]", "&&", "len", "(", "pending", ")", "==", "0", "{", "break", "\n", "}", "\n\n", "if", "seen", "[", "commit", ".", "Hash", "]", "{", "continue", "\n", "}", "\n\n", "cb", "(", "commit", ".", "Hash", ")", "\n\n", "tree", ",", "err", ":=", "commit", ".", "Tree", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "if", "err", ":=", "iterateCommitTrees", "(", "seen", ",", "tree", ",", "cb", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// reachableObjects returns, using the callback function, all the reachable // objects from the specified commit. To avoid to iterate over seen commits, // if a commit hash is into the 'seen' set, we will not iterate all his trees // and blobs objects.
[ "reachableObjects", "returns", "using", "the", "callback", "function", "all", "the", "reachable", "objects", "from", "the", "specified", "commit", ".", "To", "avoid", "to", "iterate", "over", "seen", "commits", "if", "a", "commit", "hash", "is", "into", "the", "seen", "set", "we", "will", "not", "iterate", "all", "his", "trees", "and", "blobs", "objects", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/revlist/revlist.go#L120-L167
train
src-d/go-git
plumbing/revlist/revlist.go
iterateCommitTrees
func iterateCommitTrees( seen map[plumbing.Hash]bool, tree *object.Tree, cb func(h plumbing.Hash), ) error { if seen[tree.Hash] { return nil } cb(tree.Hash) treeWalker := object.NewTreeWalker(tree, true, seen) for { _, e, err := treeWalker.Next() if err == io.EOF { break } if err != nil { return err } if e.Mode == filemode.Submodule { continue } if seen[e.Hash] { continue } cb(e.Hash) } return nil }
go
func iterateCommitTrees( seen map[plumbing.Hash]bool, tree *object.Tree, cb func(h plumbing.Hash), ) error { if seen[tree.Hash] { return nil } cb(tree.Hash) treeWalker := object.NewTreeWalker(tree, true, seen) for { _, e, err := treeWalker.Next() if err == io.EOF { break } if err != nil { return err } if e.Mode == filemode.Submodule { continue } if seen[e.Hash] { continue } cb(e.Hash) } return nil }
[ "func", "iterateCommitTrees", "(", "seen", "map", "[", "plumbing", ".", "Hash", "]", "bool", ",", "tree", "*", "object", ".", "Tree", ",", "cb", "func", "(", "h", "plumbing", ".", "Hash", ")", ",", ")", "error", "{", "if", "seen", "[", "tree", ".", "Hash", "]", "{", "return", "nil", "\n", "}", "\n\n", "cb", "(", "tree", ".", "Hash", ")", "\n\n", "treeWalker", ":=", "object", ".", "NewTreeWalker", "(", "tree", ",", "true", ",", "seen", ")", "\n\n", "for", "{", "_", ",", "e", ",", "err", ":=", "treeWalker", ".", "Next", "(", ")", "\n", "if", "err", "==", "io", ".", "EOF", "{", "break", "\n", "}", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "if", "e", ".", "Mode", "==", "filemode", ".", "Submodule", "{", "continue", "\n", "}", "\n\n", "if", "seen", "[", "e", ".", "Hash", "]", "{", "continue", "\n", "}", "\n\n", "cb", "(", "e", ".", "Hash", ")", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// iterateCommitTrees iterate all reachable trees from the given commit
[ "iterateCommitTrees", "iterate", "all", "reachable", "trees", "from", "the", "given", "commit" ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/revlist/revlist.go#L178-L212
train
src-d/go-git
plumbing/protocol/packp/common.go
NewErrUnexpectedData
func NewErrUnexpectedData(msg string, data []byte) error { return &ErrUnexpectedData{Msg: msg, Data: data} }
go
func NewErrUnexpectedData(msg string, data []byte) error { return &ErrUnexpectedData{Msg: msg, Data: data} }
[ "func", "NewErrUnexpectedData", "(", "msg", "string", ",", "data", "[", "]", "byte", ")", "error", "{", "return", "&", "ErrUnexpectedData", "{", "Msg", ":", "msg", ",", "Data", ":", "data", "}", "\n", "}" ]
// NewErrUnexpectedData returns a new ErrUnexpectedData containing the data and // the message given
[ "NewErrUnexpectedData", "returns", "a", "new", "ErrUnexpectedData", "containing", "the", "data", "and", "the", "message", "given" ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/protocol/packp/common.go#L60-L62
train
src-d/go-git
utils/binary/write.go
WriteUint64
func WriteUint64(w io.Writer, value uint64) error { return binary.Write(w, binary.BigEndian, value) }
go
func WriteUint64(w io.Writer, value uint64) error { return binary.Write(w, binary.BigEndian, value) }
[ "func", "WriteUint64", "(", "w", "io", ".", "Writer", ",", "value", "uint64", ")", "error", "{", "return", "binary", ".", "Write", "(", "w", ",", "binary", ".", "BigEndian", ",", "value", ")", "\n", "}" ]
// WriteUint64 writes the binary representation of a uint64 into w, in BigEndian // order
[ "WriteUint64", "writes", "the", "binary", "representation", "of", "a", "uint64", "into", "w", "in", "BigEndian", "order" ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/utils/binary/write.go#L36-L38
train
src-d/go-git
utils/binary/write.go
WriteUint32
func WriteUint32(w io.Writer, value uint32) error { return binary.Write(w, binary.BigEndian, value) }
go
func WriteUint32(w io.Writer, value uint32) error { return binary.Write(w, binary.BigEndian, value) }
[ "func", "WriteUint32", "(", "w", "io", ".", "Writer", ",", "value", "uint32", ")", "error", "{", "return", "binary", ".", "Write", "(", "w", ",", "binary", ".", "BigEndian", ",", "value", ")", "\n", "}" ]
// WriteUint32 writes the binary representation of a uint32 into w, in BigEndian // order
[ "WriteUint32", "writes", "the", "binary", "representation", "of", "a", "uint32", "into", "w", "in", "BigEndian", "order" ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/utils/binary/write.go#L42-L44
train
src-d/go-git
utils/binary/write.go
WriteUint16
func WriteUint16(w io.Writer, value uint16) error { return binary.Write(w, binary.BigEndian, value) }
go
func WriteUint16(w io.Writer, value uint16) error { return binary.Write(w, binary.BigEndian, value) }
[ "func", "WriteUint16", "(", "w", "io", ".", "Writer", ",", "value", "uint16", ")", "error", "{", "return", "binary", ".", "Write", "(", "w", ",", "binary", ".", "BigEndian", ",", "value", ")", "\n", "}" ]
// WriteUint16 writes the binary representation of a uint16 into w, in BigEndian // order
[ "WriteUint16", "writes", "the", "binary", "representation", "of", "a", "uint16", "into", "w", "in", "BigEndian", "order" ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/utils/binary/write.go#L48-L50
train
src-d/go-git
internal/url/url.go
FindScpLikeComponents
func FindScpLikeComponents(url string) (user, host, port, path string) { m := scpLikeUrlRegExp.FindStringSubmatch(url) return m[1], m[2], m[3], m[4] }
go
func FindScpLikeComponents(url string) (user, host, port, path string) { m := scpLikeUrlRegExp.FindStringSubmatch(url) return m[1], m[2], m[3], m[4] }
[ "func", "FindScpLikeComponents", "(", "url", "string", ")", "(", "user", ",", "host", ",", "port", ",", "path", "string", ")", "{", "m", ":=", "scpLikeUrlRegExp", ".", "FindStringSubmatch", "(", "url", ")", "\n", "return", "m", "[", "1", "]", ",", "m", "[", "2", "]", ",", "m", "[", "3", "]", ",", "m", "[", "4", "]", "\n", "}" ]
// FindScpLikeComponents returns the user, host, port and path of the // given SCP-like URL.
[ "FindScpLikeComponents", "returns", "the", "user", "host", "port", "and", "path", "of", "the", "given", "SCP", "-", "like", "URL", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/internal/url/url.go#L26-L29
train
src-d/go-git
plumbing/object/commit.go
GetCommit
func GetCommit(s storer.EncodedObjectStorer, h plumbing.Hash) (*Commit, error) { o, err := s.EncodedObject(plumbing.CommitObject, h) if err != nil { return nil, err } return DecodeCommit(s, o) }
go
func GetCommit(s storer.EncodedObjectStorer, h plumbing.Hash) (*Commit, error) { o, err := s.EncodedObject(plumbing.CommitObject, h) if err != nil { return nil, err } return DecodeCommit(s, o) }
[ "func", "GetCommit", "(", "s", "storer", ".", "EncodedObjectStorer", ",", "h", "plumbing", ".", "Hash", ")", "(", "*", "Commit", ",", "error", ")", "{", "o", ",", "err", ":=", "s", ".", "EncodedObject", "(", "plumbing", ".", "CommitObject", ",", "h", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "DecodeCommit", "(", "s", ",", "o", ")", "\n", "}" ]
// GetCommit gets a commit from an object storer and decodes it.
[ "GetCommit", "gets", "a", "commit", "from", "an", "object", "storer", "and", "decodes", "it", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/object/commit.go#L54-L61
train
src-d/go-git
plumbing/object/commit.go
Tree
func (c *Commit) Tree() (*Tree, error) { return GetTree(c.s, c.TreeHash) }
go
func (c *Commit) Tree() (*Tree, error) { return GetTree(c.s, c.TreeHash) }
[ "func", "(", "c", "*", "Commit", ")", "Tree", "(", ")", "(", "*", "Tree", ",", "error", ")", "{", "return", "GetTree", "(", "c", ".", "s", ",", "c", ".", "TreeHash", ")", "\n", "}" ]
// Tree returns the Tree from the commit.
[ "Tree", "returns", "the", "Tree", "from", "the", "commit", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/object/commit.go#L75-L77
train
src-d/go-git
plumbing/object/commit.go
PatchContext
func (c *Commit) PatchContext(ctx context.Context, to *Commit) (*Patch, error) { fromTree, err := c.Tree() if err != nil { return nil, err } toTree, err := to.Tree() if err != nil { return nil, err } return fromTree.PatchContext(ctx, toTree) }
go
func (c *Commit) PatchContext(ctx context.Context, to *Commit) (*Patch, error) { fromTree, err := c.Tree() if err != nil { return nil, err } toTree, err := to.Tree() if err != nil { return nil, err } return fromTree.PatchContext(ctx, toTree) }
[ "func", "(", "c", "*", "Commit", ")", "PatchContext", "(", "ctx", "context", ".", "Context", ",", "to", "*", "Commit", ")", "(", "*", "Patch", ",", "error", ")", "{", "fromTree", ",", "err", ":=", "c", ".", "Tree", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "toTree", ",", "err", ":=", "to", ".", "Tree", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "fromTree", ".", "PatchContext", "(", "ctx", ",", "toTree", ")", "\n", "}" ]
// PatchContext returns the Patch between the actual commit and the provided one. // Error will be return if context expires. Provided context must be non-nil.
[ "PatchContext", "returns", "the", "Patch", "between", "the", "actual", "commit", "and", "the", "provided", "one", ".", "Error", "will", "be", "return", "if", "context", "expires", ".", "Provided", "context", "must", "be", "non", "-", "nil", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/object/commit.go#L81-L93
train
src-d/go-git
plumbing/object/commit.go
Patch
func (c *Commit) Patch(to *Commit) (*Patch, error) { return c.PatchContext(context.Background(), to) }
go
func (c *Commit) Patch(to *Commit) (*Patch, error) { return c.PatchContext(context.Background(), to) }
[ "func", "(", "c", "*", "Commit", ")", "Patch", "(", "to", "*", "Commit", ")", "(", "*", "Patch", ",", "error", ")", "{", "return", "c", ".", "PatchContext", "(", "context", ".", "Background", "(", ")", ",", "to", ")", "\n", "}" ]
// Patch returns the Patch between the actual commit and the provided one.
[ "Patch", "returns", "the", "Patch", "between", "the", "actual", "commit", "and", "the", "provided", "one", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/object/commit.go#L96-L98
train
src-d/go-git
plumbing/object/commit.go
Parents
func (c *Commit) Parents() CommitIter { return NewCommitIter(c.s, storer.NewEncodedObjectLookupIter(c.s, plumbing.CommitObject, c.ParentHashes), ) }
go
func (c *Commit) Parents() CommitIter { return NewCommitIter(c.s, storer.NewEncodedObjectLookupIter(c.s, plumbing.CommitObject, c.ParentHashes), ) }
[ "func", "(", "c", "*", "Commit", ")", "Parents", "(", ")", "CommitIter", "{", "return", "NewCommitIter", "(", "c", ".", "s", ",", "storer", ".", "NewEncodedObjectLookupIter", "(", "c", ".", "s", ",", "plumbing", ".", "CommitObject", ",", "c", ".", "ParentHashes", ")", ",", ")", "\n", "}" ]
// Parents return a CommitIter to the parent Commits.
[ "Parents", "return", "a", "CommitIter", "to", "the", "parent", "Commits", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/object/commit.go#L101-L105
train
src-d/go-git
plumbing/object/commit.go
Parent
func (c *Commit) Parent(i int) (*Commit, error) { if len(c.ParentHashes) == 0 || i > len(c.ParentHashes)-1 { return nil, ErrParentNotFound } return GetCommit(c.s, c.ParentHashes[i]) }
go
func (c *Commit) Parent(i int) (*Commit, error) { if len(c.ParentHashes) == 0 || i > len(c.ParentHashes)-1 { return nil, ErrParentNotFound } return GetCommit(c.s, c.ParentHashes[i]) }
[ "func", "(", "c", "*", "Commit", ")", "Parent", "(", "i", "int", ")", "(", "*", "Commit", ",", "error", ")", "{", "if", "len", "(", "c", ".", "ParentHashes", ")", "==", "0", "||", "i", ">", "len", "(", "c", ".", "ParentHashes", ")", "-", "1", "{", "return", "nil", ",", "ErrParentNotFound", "\n", "}", "\n\n", "return", "GetCommit", "(", "c", ".", "s", ",", "c", ".", "ParentHashes", "[", "i", "]", ")", "\n", "}" ]
// Parent returns the ith parent of a commit.
[ "Parent", "returns", "the", "ith", "parent", "of", "a", "commit", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/object/commit.go#L115-L121
train
src-d/go-git
plumbing/object/commit.go
File
func (c *Commit) File(path string) (*File, error) { tree, err := c.Tree() if err != nil { return nil, err } return tree.File(path) }
go
func (c *Commit) File(path string) (*File, error) { tree, err := c.Tree() if err != nil { return nil, err } return tree.File(path) }
[ "func", "(", "c", "*", "Commit", ")", "File", "(", "path", "string", ")", "(", "*", "File", ",", "error", ")", "{", "tree", ",", "err", ":=", "c", ".", "Tree", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "tree", ".", "File", "(", "path", ")", "\n", "}" ]
// File returns the file with the specified "path" in the commit and a // nil error if the file exists. If the file does not exist, it returns // a nil file and the ErrFileNotFound error.
[ "File", "returns", "the", "file", "with", "the", "specified", "path", "in", "the", "commit", "and", "a", "nil", "error", "if", "the", "file", "exists", ".", "If", "the", "file", "does", "not", "exist", "it", "returns", "a", "nil", "file", "and", "the", "ErrFileNotFound", "error", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/object/commit.go#L126-L133
train
src-d/go-git
plumbing/object/commit.go
Files
func (c *Commit) Files() (*FileIter, error) { tree, err := c.Tree() if err != nil { return nil, err } return tree.Files(), nil }
go
func (c *Commit) Files() (*FileIter, error) { tree, err := c.Tree() if err != nil { return nil, err } return tree.Files(), nil }
[ "func", "(", "c", "*", "Commit", ")", "Files", "(", ")", "(", "*", "FileIter", ",", "error", ")", "{", "tree", ",", "err", ":=", "c", ".", "Tree", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "tree", ".", "Files", "(", ")", ",", "nil", "\n", "}" ]
// Files returns a FileIter allowing to iterate over the Tree
[ "Files", "returns", "a", "FileIter", "allowing", "to", "iterate", "over", "the", "Tree" ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/object/commit.go#L136-L143
train
src-d/go-git
plumbing/object/commit.go
Decode
func (c *Commit) Decode(o plumbing.EncodedObject) (err error) { if o.Type() != plumbing.CommitObject { return ErrUnsupportedObject } c.Hash = o.Hash() reader, err := o.Reader() if err != nil { return err } defer ioutil.CheckClose(reader, &err) r := bufPool.Get().(*bufio.Reader) defer bufPool.Put(r) r.Reset(reader) var message bool var pgpsig bool for { line, err := r.ReadBytes('\n') if err != nil && err != io.EOF { return err } if pgpsig { if len(line) > 0 && line[0] == ' ' { line = bytes.TrimLeft(line, " ") c.PGPSignature += string(line) continue } else { pgpsig = false } } if !message { line = bytes.TrimSpace(line) if len(line) == 0 { message = true continue } split := bytes.SplitN(line, []byte{' '}, 2) var data []byte if len(split) == 2 { data = split[1] } switch string(split[0]) { case "tree": c.TreeHash = plumbing.NewHash(string(data)) case "parent": c.ParentHashes = append(c.ParentHashes, plumbing.NewHash(string(data))) case "author": c.Author.Decode(data) case "committer": c.Committer.Decode(data) case headerpgp: c.PGPSignature += string(data) + "\n" pgpsig = true } } else { c.Message += string(line) } if err == io.EOF { return nil } } }
go
func (c *Commit) Decode(o plumbing.EncodedObject) (err error) { if o.Type() != plumbing.CommitObject { return ErrUnsupportedObject } c.Hash = o.Hash() reader, err := o.Reader() if err != nil { return err } defer ioutil.CheckClose(reader, &err) r := bufPool.Get().(*bufio.Reader) defer bufPool.Put(r) r.Reset(reader) var message bool var pgpsig bool for { line, err := r.ReadBytes('\n') if err != nil && err != io.EOF { return err } if pgpsig { if len(line) > 0 && line[0] == ' ' { line = bytes.TrimLeft(line, " ") c.PGPSignature += string(line) continue } else { pgpsig = false } } if !message { line = bytes.TrimSpace(line) if len(line) == 0 { message = true continue } split := bytes.SplitN(line, []byte{' '}, 2) var data []byte if len(split) == 2 { data = split[1] } switch string(split[0]) { case "tree": c.TreeHash = plumbing.NewHash(string(data)) case "parent": c.ParentHashes = append(c.ParentHashes, plumbing.NewHash(string(data))) case "author": c.Author.Decode(data) case "committer": c.Committer.Decode(data) case headerpgp: c.PGPSignature += string(data) + "\n" pgpsig = true } } else { c.Message += string(line) } if err == io.EOF { return nil } } }
[ "func", "(", "c", "*", "Commit", ")", "Decode", "(", "o", "plumbing", ".", "EncodedObject", ")", "(", "err", "error", ")", "{", "if", "o", ".", "Type", "(", ")", "!=", "plumbing", ".", "CommitObject", "{", "return", "ErrUnsupportedObject", "\n", "}", "\n\n", "c", ".", "Hash", "=", "o", ".", "Hash", "(", ")", "\n\n", "reader", ",", "err", ":=", "o", ".", "Reader", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "defer", "ioutil", ".", "CheckClose", "(", "reader", ",", "&", "err", ")", "\n\n", "r", ":=", "bufPool", ".", "Get", "(", ")", ".", "(", "*", "bufio", ".", "Reader", ")", "\n", "defer", "bufPool", ".", "Put", "(", "r", ")", "\n", "r", ".", "Reset", "(", "reader", ")", "\n\n", "var", "message", "bool", "\n", "var", "pgpsig", "bool", "\n", "for", "{", "line", ",", "err", ":=", "r", ".", "ReadBytes", "(", "'\\n'", ")", "\n", "if", "err", "!=", "nil", "&&", "err", "!=", "io", ".", "EOF", "{", "return", "err", "\n", "}", "\n\n", "if", "pgpsig", "{", "if", "len", "(", "line", ")", ">", "0", "&&", "line", "[", "0", "]", "==", "' '", "{", "line", "=", "bytes", ".", "TrimLeft", "(", "line", ",", "\"", "\"", ")", "\n", "c", ".", "PGPSignature", "+=", "string", "(", "line", ")", "\n", "continue", "\n", "}", "else", "{", "pgpsig", "=", "false", "\n", "}", "\n", "}", "\n\n", "if", "!", "message", "{", "line", "=", "bytes", ".", "TrimSpace", "(", "line", ")", "\n", "if", "len", "(", "line", ")", "==", "0", "{", "message", "=", "true", "\n", "continue", "\n", "}", "\n\n", "split", ":=", "bytes", ".", "SplitN", "(", "line", ",", "[", "]", "byte", "{", "' '", "}", ",", "2", ")", "\n\n", "var", "data", "[", "]", "byte", "\n", "if", "len", "(", "split", ")", "==", "2", "{", "data", "=", "split", "[", "1", "]", "\n", "}", "\n\n", "switch", "string", "(", "split", "[", "0", "]", ")", "{", "case", "\"", "\"", ":", "c", ".", "TreeHash", "=", "plumbing", ".", "NewHash", "(", "string", "(", "data", ")", ")", "\n", "case", "\"", "\"", ":", "c", ".", "ParentHashes", "=", "append", "(", "c", ".", "ParentHashes", ",", "plumbing", ".", "NewHash", "(", "string", "(", "data", ")", ")", ")", "\n", "case", "\"", "\"", ":", "c", ".", "Author", ".", "Decode", "(", "data", ")", "\n", "case", "\"", "\"", ":", "c", ".", "Committer", ".", "Decode", "(", "data", ")", "\n", "case", "headerpgp", ":", "c", ".", "PGPSignature", "+=", "string", "(", "data", ")", "+", "\"", "\\n", "\"", "\n", "pgpsig", "=", "true", "\n", "}", "\n", "}", "else", "{", "c", ".", "Message", "+=", "string", "(", "line", ")", "\n", "}", "\n\n", "if", "err", "==", "io", ".", "EOF", "{", "return", "nil", "\n", "}", "\n", "}", "\n", "}" ]
// Decode transforms a plumbing.EncodedObject into a Commit struct.
[ "Decode", "transforms", "a", "plumbing", ".", "EncodedObject", "into", "a", "Commit", "struct", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/object/commit.go#L161-L231
train
src-d/go-git
plumbing/object/commit.go
Encode
func (b *Commit) Encode(o plumbing.EncodedObject) error { return b.encode(o, true) }
go
func (b *Commit) Encode(o plumbing.EncodedObject) error { return b.encode(o, true) }
[ "func", "(", "b", "*", "Commit", ")", "Encode", "(", "o", "plumbing", ".", "EncodedObject", ")", "error", "{", "return", "b", ".", "encode", "(", "o", ",", "true", ")", "\n", "}" ]
// Encode transforms a Commit into a plumbing.EncodedObject.
[ "Encode", "transforms", "a", "Commit", "into", "a", "plumbing", ".", "EncodedObject", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/object/commit.go#L234-L236
train
src-d/go-git
plumbing/object/commit.go
StatsContext
func (c *Commit) StatsContext(ctx context.Context) (FileStats, error) { fromTree, err := c.Tree() if err != nil { return nil, err } toTree := &Tree{} if c.NumParents() != 0 { firstParent, err := c.Parents().Next() if err != nil { return nil, err } toTree, err = firstParent.Tree() if err != nil { return nil, err } } patch, err := toTree.PatchContext(ctx, fromTree) if err != nil { return nil, err } return getFileStatsFromFilePatches(patch.FilePatches()), nil }
go
func (c *Commit) StatsContext(ctx context.Context) (FileStats, error) { fromTree, err := c.Tree() if err != nil { return nil, err } toTree := &Tree{} if c.NumParents() != 0 { firstParent, err := c.Parents().Next() if err != nil { return nil, err } toTree, err = firstParent.Tree() if err != nil { return nil, err } } patch, err := toTree.PatchContext(ctx, fromTree) if err != nil { return nil, err } return getFileStatsFromFilePatches(patch.FilePatches()), nil }
[ "func", "(", "c", "*", "Commit", ")", "StatsContext", "(", "ctx", "context", ".", "Context", ")", "(", "FileStats", ",", "error", ")", "{", "fromTree", ",", "err", ":=", "c", ".", "Tree", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "toTree", ":=", "&", "Tree", "{", "}", "\n", "if", "c", ".", "NumParents", "(", ")", "!=", "0", "{", "firstParent", ",", "err", ":=", "c", ".", "Parents", "(", ")", ".", "Next", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "toTree", ",", "err", "=", "firstParent", ".", "Tree", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "}", "\n\n", "patch", ",", "err", ":=", "toTree", ".", "PatchContext", "(", "ctx", ",", "fromTree", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "getFileStatsFromFilePatches", "(", "patch", ".", "FilePatches", "(", ")", ")", ",", "nil", "\n", "}" ]
// StatsContext returns the stats of a commit. Error will be return if context // expires. Provided context must be non-nil.
[ "StatsContext", "returns", "the", "stats", "of", "a", "commit", ".", "Error", "will", "be", "return", "if", "context", "expires", ".", "Provided", "context", "must", "be", "non", "-", "nil", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/object/commit.go#L308-L333
train
src-d/go-git
plumbing/object/commit.go
NewCommitIter
func NewCommitIter(s storer.EncodedObjectStorer, iter storer.EncodedObjectIter) CommitIter { return &storerCommitIter{iter, s} }
go
func NewCommitIter(s storer.EncodedObjectStorer, iter storer.EncodedObjectIter) CommitIter { return &storerCommitIter{iter, s} }
[ "func", "NewCommitIter", "(", "s", "storer", ".", "EncodedObjectStorer", ",", "iter", "storer", ".", "EncodedObjectIter", ")", "CommitIter", "{", "return", "&", "storerCommitIter", "{", "iter", ",", "s", "}", "\n", "}" ]
// NewCommitIter takes a storer.EncodedObjectStorer and a // storer.EncodedObjectIter and returns a CommitIter that iterates over all // commits contained in the storer.EncodedObjectIter. // // Any non-commit object returned by the storer.EncodedObjectIter is skipped.
[ "NewCommitIter", "takes", "a", "storer", ".", "EncodedObjectStorer", "and", "a", "storer", ".", "EncodedObjectIter", "and", "returns", "a", "CommitIter", "that", "iterates", "over", "all", "commits", "contained", "in", "the", "storer", ".", "EncodedObjectIter", ".", "Any", "non", "-", "commit", "object", "returned", "by", "the", "storer", ".", "EncodedObjectIter", "is", "skipped", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/object/commit.go#L399-L401
train
src-d/go-git
plumbing/object/commit.go
Next
func (iter *storerCommitIter) Next() (*Commit, error) { obj, err := iter.EncodedObjectIter.Next() if err != nil { return nil, err } return DecodeCommit(iter.s, obj) }
go
func (iter *storerCommitIter) Next() (*Commit, error) { obj, err := iter.EncodedObjectIter.Next() if err != nil { return nil, err } return DecodeCommit(iter.s, obj) }
[ "func", "(", "iter", "*", "storerCommitIter", ")", "Next", "(", ")", "(", "*", "Commit", ",", "error", ")", "{", "obj", ",", "err", ":=", "iter", ".", "EncodedObjectIter", ".", "Next", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "DecodeCommit", "(", "iter", ".", "s", ",", "obj", ")", "\n", "}" ]
// Next moves the iterator to the next commit and returns a pointer to it. If // there are no more commits, it returns io.EOF.
[ "Next", "moves", "the", "iterator", "to", "the", "next", "commit", "and", "returns", "a", "pointer", "to", "it", ".", "If", "there", "are", "no", "more", "commits", "it", "returns", "io", ".", "EOF", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/object/commit.go#L405-L412
train
src-d/go-git
plumbing/object/commit.go
ForEach
func (iter *storerCommitIter) ForEach(cb func(*Commit) error) error { return iter.EncodedObjectIter.ForEach(func(obj plumbing.EncodedObject) error { c, err := DecodeCommit(iter.s, obj) if err != nil { return err } return cb(c) }) }
go
func (iter *storerCommitIter) ForEach(cb func(*Commit) error) error { return iter.EncodedObjectIter.ForEach(func(obj plumbing.EncodedObject) error { c, err := DecodeCommit(iter.s, obj) if err != nil { return err } return cb(c) }) }
[ "func", "(", "iter", "*", "storerCommitIter", ")", "ForEach", "(", "cb", "func", "(", "*", "Commit", ")", "error", ")", "error", "{", "return", "iter", ".", "EncodedObjectIter", ".", "ForEach", "(", "func", "(", "obj", "plumbing", ".", "EncodedObject", ")", "error", "{", "c", ",", "err", ":=", "DecodeCommit", "(", "iter", ".", "s", ",", "obj", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "cb", "(", "c", ")", "\n", "}", ")", "\n", "}" ]
// ForEach call the cb function for each commit contained on this iter until // an error appends or the end of the iter is reached. If ErrStop is sent // the iteration is stopped but no error is returned. The iterator is closed.
[ "ForEach", "call", "the", "cb", "function", "for", "each", "commit", "contained", "on", "this", "iter", "until", "an", "error", "appends", "or", "the", "end", "of", "the", "iter", "is", "reached", ".", "If", "ErrStop", "is", "sent", "the", "iteration", "is", "stopped", "but", "no", "error", "is", "returned", ".", "The", "iterator", "is", "closed", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/object/commit.go#L417-L426
train
src-d/go-git
plumbing/object/object.go
GetObject
func GetObject(s storer.EncodedObjectStorer, h plumbing.Hash) (Object, error) { o, err := s.EncodedObject(plumbing.AnyObject, h) if err != nil { return nil, err } return DecodeObject(s, o) }
go
func GetObject(s storer.EncodedObjectStorer, h plumbing.Hash) (Object, error) { o, err := s.EncodedObject(plumbing.AnyObject, h) if err != nil { return nil, err } return DecodeObject(s, o) }
[ "func", "GetObject", "(", "s", "storer", ".", "EncodedObjectStorer", ",", "h", "plumbing", ".", "Hash", ")", "(", "Object", ",", "error", ")", "{", "o", ",", "err", ":=", "s", ".", "EncodedObject", "(", "plumbing", ".", "AnyObject", ",", "h", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "DecodeObject", "(", "s", ",", "o", ")", "\n", "}" ]
// GetObject gets an object from an object storer and decodes it.
[ "GetObject", "gets", "an", "object", "from", "an", "object", "storer", "and", "decodes", "it", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/object/object.go#L51-L58
train
src-d/go-git
plumbing/object/object.go
DecodeObject
func DecodeObject(s storer.EncodedObjectStorer, o plumbing.EncodedObject) (Object, error) { switch o.Type() { case plumbing.CommitObject: return DecodeCommit(s, o) case plumbing.TreeObject: return DecodeTree(s, o) case plumbing.BlobObject: return DecodeBlob(o) case plumbing.TagObject: return DecodeTag(s, o) default: return nil, plumbing.ErrInvalidType } }
go
func DecodeObject(s storer.EncodedObjectStorer, o plumbing.EncodedObject) (Object, error) { switch o.Type() { case plumbing.CommitObject: return DecodeCommit(s, o) case plumbing.TreeObject: return DecodeTree(s, o) case plumbing.BlobObject: return DecodeBlob(o) case plumbing.TagObject: return DecodeTag(s, o) default: return nil, plumbing.ErrInvalidType } }
[ "func", "DecodeObject", "(", "s", "storer", ".", "EncodedObjectStorer", ",", "o", "plumbing", ".", "EncodedObject", ")", "(", "Object", ",", "error", ")", "{", "switch", "o", ".", "Type", "(", ")", "{", "case", "plumbing", ".", "CommitObject", ":", "return", "DecodeCommit", "(", "s", ",", "o", ")", "\n", "case", "plumbing", ".", "TreeObject", ":", "return", "DecodeTree", "(", "s", ",", "o", ")", "\n", "case", "plumbing", ".", "BlobObject", ":", "return", "DecodeBlob", "(", "o", ")", "\n", "case", "plumbing", ".", "TagObject", ":", "return", "DecodeTag", "(", "s", ",", "o", ")", "\n", "default", ":", "return", "nil", ",", "plumbing", ".", "ErrInvalidType", "\n", "}", "\n", "}" ]
// DecodeObject decodes an encoded object into an Object and associates it to // the given object storer.
[ "DecodeObject", "decodes", "an", "encoded", "object", "into", "an", "Object", "and", "associates", "it", "to", "the", "given", "object", "storer", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/object/object.go#L62-L75
train
src-d/go-git
plumbing/object/object.go
Decode
func (s *Signature) Decode(b []byte) { open := bytes.LastIndexByte(b, '<') close := bytes.LastIndexByte(b, '>') if open == -1 || close == -1 { return } if close < open { return } s.Name = string(bytes.Trim(b[:open], " ")) s.Email = string(b[open+1 : close]) hasTime := close+2 < len(b) if hasTime { s.decodeTimeAndTimeZone(b[close+2:]) } }
go
func (s *Signature) Decode(b []byte) { open := bytes.LastIndexByte(b, '<') close := bytes.LastIndexByte(b, '>') if open == -1 || close == -1 { return } if close < open { return } s.Name = string(bytes.Trim(b[:open], " ")) s.Email = string(b[open+1 : close]) hasTime := close+2 < len(b) if hasTime { s.decodeTimeAndTimeZone(b[close+2:]) } }
[ "func", "(", "s", "*", "Signature", ")", "Decode", "(", "b", "[", "]", "byte", ")", "{", "open", ":=", "bytes", ".", "LastIndexByte", "(", "b", ",", "'<'", ")", "\n", "close", ":=", "bytes", ".", "LastIndexByte", "(", "b", ",", "'>'", ")", "\n", "if", "open", "==", "-", "1", "||", "close", "==", "-", "1", "{", "return", "\n", "}", "\n\n", "if", "close", "<", "open", "{", "return", "\n", "}", "\n\n", "s", ".", "Name", "=", "string", "(", "bytes", ".", "Trim", "(", "b", "[", ":", "open", "]", ",", "\"", "\"", ")", ")", "\n", "s", ".", "Email", "=", "string", "(", "b", "[", "open", "+", "1", ":", "close", "]", ")", "\n\n", "hasTime", ":=", "close", "+", "2", "<", "len", "(", "b", ")", "\n", "if", "hasTime", "{", "s", ".", "decodeTimeAndTimeZone", "(", "b", "[", "close", "+", "2", ":", "]", ")", "\n", "}", "\n", "}" ]
// Decode decodes a byte slice into a signature
[ "Decode", "decodes", "a", "byte", "slice", "into", "a", "signature" ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/object/object.go#L91-L109
train
src-d/go-git
plumbing/object/object.go
Encode
func (s *Signature) Encode(w io.Writer) error { if _, err := fmt.Fprintf(w, "%s <%s> ", s.Name, s.Email); err != nil { return err } if err := s.encodeTimeAndTimeZone(w); err != nil { return err } return nil }
go
func (s *Signature) Encode(w io.Writer) error { if _, err := fmt.Fprintf(w, "%s <%s> ", s.Name, s.Email); err != nil { return err } if err := s.encodeTimeAndTimeZone(w); err != nil { return err } return nil }
[ "func", "(", "s", "*", "Signature", ")", "Encode", "(", "w", "io", ".", "Writer", ")", "error", "{", "if", "_", ",", "err", ":=", "fmt", ".", "Fprintf", "(", "w", ",", "\"", "\"", ",", "s", ".", "Name", ",", "s", ".", "Email", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "err", ":=", "s", ".", "encodeTimeAndTimeZone", "(", "w", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Encode encodes a Signature into a writer.
[ "Encode", "encodes", "a", "Signature", "into", "a", "writer", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/object/object.go#L112-L120
train
src-d/go-git
plumbing/object/object.go
Next
func (iter *ObjectIter) Next() (Object, error) { for { obj, err := iter.EncodedObjectIter.Next() if err != nil { return nil, err } o, err := iter.toObject(obj) if err == plumbing.ErrInvalidType { continue } if err != nil { return nil, err } return o, nil } }
go
func (iter *ObjectIter) Next() (Object, error) { for { obj, err := iter.EncodedObjectIter.Next() if err != nil { return nil, err } o, err := iter.toObject(obj) if err == plumbing.ErrInvalidType { continue } if err != nil { return nil, err } return o, nil } }
[ "func", "(", "iter", "*", "ObjectIter", ")", "Next", "(", ")", "(", "Object", ",", "error", ")", "{", "for", "{", "obj", ",", "err", ":=", "iter", ".", "EncodedObjectIter", ".", "Next", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "o", ",", "err", ":=", "iter", ".", "toObject", "(", "obj", ")", "\n", "if", "err", "==", "plumbing", ".", "ErrInvalidType", "{", "continue", "\n", "}", "\n\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "o", ",", "nil", "\n", "}", "\n", "}" ]
// Next moves the iterator to the next object and returns a pointer to it. If // there are no more objects, it returns io.EOF.
[ "Next", "moves", "the", "iterator", "to", "the", "next", "object", "and", "returns", "a", "pointer", "to", "it", ".", "If", "there", "are", "no", "more", "objects", "it", "returns", "io", ".", "EOF", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/object/object.go#L182-L200
train
src-d/go-git
utils/merkletrie/change.go
String
func (a Action) String() string { switch a { case Insert: return "Insert" case Delete: return "Delete" case Modify: return "Modify" default: panic(fmt.Sprintf("unsupported action: %d", a)) } }
go
func (a Action) String() string { switch a { case Insert: return "Insert" case Delete: return "Delete" case Modify: return "Modify" default: panic(fmt.Sprintf("unsupported action: %d", a)) } }
[ "func", "(", "a", "Action", ")", "String", "(", ")", "string", "{", "switch", "a", "{", "case", "Insert", ":", "return", "\"", "\"", "\n", "case", "Delete", ":", "return", "\"", "\"", "\n", "case", "Modify", ":", "return", "\"", "\"", "\n", "default", ":", "panic", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "a", ")", ")", "\n", "}", "\n", "}" ]
// String returns the action as a human readable text.
[ "String", "returns", "the", "action", "as", "a", "human", "readable", "text", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/utils/merkletrie/change.go#L23-L34
train
src-d/go-git
utils/merkletrie/change.go
Action
func (c *Change) Action() (Action, error) { if c.From == nil && c.To == nil { return Action(0), fmt.Errorf("malformed change: nil from and to") } if c.From == nil { return Insert, nil } if c.To == nil { return Delete, nil } return Modify, nil }
go
func (c *Change) Action() (Action, error) { if c.From == nil && c.To == nil { return Action(0), fmt.Errorf("malformed change: nil from and to") } if c.From == nil { return Insert, nil } if c.To == nil { return Delete, nil } return Modify, nil }
[ "func", "(", "c", "*", "Change", ")", "Action", "(", ")", "(", "Action", ",", "error", ")", "{", "if", "c", ".", "From", "==", "nil", "&&", "c", ".", "To", "==", "nil", "{", "return", "Action", "(", "0", ")", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "if", "c", ".", "From", "==", "nil", "{", "return", "Insert", ",", "nil", "\n", "}", "\n", "if", "c", ".", "To", "==", "nil", "{", "return", "Delete", ",", "nil", "\n", "}", "\n\n", "return", "Modify", ",", "nil", "\n", "}" ]
// Action is convenience method that returns what Action c represents.
[ "Action", "is", "convenience", "method", "that", "returns", "what", "Action", "c", "represents", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/utils/merkletrie/change.go#L45-L57
train
src-d/go-git
utils/merkletrie/change.go
NewModify
func NewModify(a, b noder.Path) Change { return Change{ From: a, To: b, } }
go
func NewModify(a, b noder.Path) Change { return Change{ From: a, To: b, } }
[ "func", "NewModify", "(", "a", ",", "b", "noder", ".", "Path", ")", "Change", "{", "return", "Change", "{", "From", ":", "a", ",", "To", ":", "b", ",", "}", "\n", "}" ]
// NewModify returns a new Change representing that a has been modified and // it is now b.
[ "NewModify", "returns", "a", "new", "Change", "representing", "that", "a", "has", "been", "modified", "and", "it", "is", "now", "b", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/utils/merkletrie/change.go#L67-L72
train
src-d/go-git
utils/merkletrie/change.go
AddRecursiveInsert
func (l *Changes) AddRecursiveInsert(root noder.Path) error { return l.addRecursive(root, NewInsert) }
go
func (l *Changes) AddRecursiveInsert(root noder.Path) error { return l.addRecursive(root, NewInsert) }
[ "func", "(", "l", "*", "Changes", ")", "AddRecursiveInsert", "(", "root", "noder", ".", "Path", ")", "error", "{", "return", "l", ".", "addRecursive", "(", "root", ",", "NewInsert", ")", "\n", "}" ]
// AddRecursiveInsert adds the required changes to insert all the // file-like noders found in root, recursively.
[ "AddRecursiveInsert", "adds", "the", "required", "changes", "to", "insert", "all", "the", "file", "-", "like", "noders", "found", "in", "root", "recursively", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/utils/merkletrie/change.go#L111-L113
train
src-d/go-git
utils/merkletrie/change.go
AddRecursiveDelete
func (l *Changes) AddRecursiveDelete(root noder.Path) error { return l.addRecursive(root, NewDelete) }
go
func (l *Changes) AddRecursiveDelete(root noder.Path) error { return l.addRecursive(root, NewDelete) }
[ "func", "(", "l", "*", "Changes", ")", "AddRecursiveDelete", "(", "root", "noder", ".", "Path", ")", "error", "{", "return", "l", ".", "addRecursive", "(", "root", ",", "NewDelete", ")", "\n", "}" ]
// AddRecursiveDelete adds the required changes to delete all the // file-like noders found in root, recursively.
[ "AddRecursiveDelete", "adds", "the", "required", "changes", "to", "delete", "all", "the", "file", "-", "like", "noders", "found", "in", "root", "recursively", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/utils/merkletrie/change.go#L117-L119
train
src-d/go-git
plumbing/object/tree.go
GetTree
func GetTree(s storer.EncodedObjectStorer, h plumbing.Hash) (*Tree, error) { o, err := s.EncodedObject(plumbing.TreeObject, h) if err != nil { return nil, err } return DecodeTree(s, o) }
go
func GetTree(s storer.EncodedObjectStorer, h plumbing.Hash) (*Tree, error) { o, err := s.EncodedObject(plumbing.TreeObject, h) if err != nil { return nil, err } return DecodeTree(s, o) }
[ "func", "GetTree", "(", "s", "storer", ".", "EncodedObjectStorer", ",", "h", "plumbing", ".", "Hash", ")", "(", "*", "Tree", ",", "error", ")", "{", "o", ",", "err", ":=", "s", ".", "EncodedObject", "(", "plumbing", ".", "TreeObject", ",", "h", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "DecodeTree", "(", "s", ",", "o", ")", "\n", "}" ]
// GetTree gets a tree from an object storer and decodes it.
[ "GetTree", "gets", "a", "tree", "from", "an", "object", "storer", "and", "decodes", "it", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/object/tree.go#L44-L51
train
src-d/go-git
plumbing/object/tree.go
File
func (t *Tree) File(path string) (*File, error) { e, err := t.FindEntry(path) if err != nil { return nil, ErrFileNotFound } blob, err := GetBlob(t.s, e.Hash) if err != nil { if err == plumbing.ErrObjectNotFound { return nil, ErrFileNotFound } return nil, err } return NewFile(path, e.Mode, blob), nil }
go
func (t *Tree) File(path string) (*File, error) { e, err := t.FindEntry(path) if err != nil { return nil, ErrFileNotFound } blob, err := GetBlob(t.s, e.Hash) if err != nil { if err == plumbing.ErrObjectNotFound { return nil, ErrFileNotFound } return nil, err } return NewFile(path, e.Mode, blob), nil }
[ "func", "(", "t", "*", "Tree", ")", "File", "(", "path", "string", ")", "(", "*", "File", ",", "error", ")", "{", "e", ",", "err", ":=", "t", ".", "FindEntry", "(", "path", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "ErrFileNotFound", "\n", "}", "\n\n", "blob", ",", "err", ":=", "GetBlob", "(", "t", ".", "s", ",", "e", ".", "Hash", ")", "\n", "if", "err", "!=", "nil", "{", "if", "err", "==", "plumbing", ".", "ErrObjectNotFound", "{", "return", "nil", ",", "ErrFileNotFound", "\n", "}", "\n", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "NewFile", "(", "path", ",", "e", ".", "Mode", ",", "blob", ")", ",", "nil", "\n", "}" ]
// File returns the hash of the file identified by the `path` argument. // The path is interpreted as relative to the tree receiver.
[ "File", "returns", "the", "hash", "of", "the", "file", "identified", "by", "the", "path", "argument", ".", "The", "path", "is", "interpreted", "as", "relative", "to", "the", "tree", "receiver", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/object/tree.go#L73-L88
train
src-d/go-git
plumbing/object/tree.go
Size
func (t *Tree) Size(path string) (int64, error) { e, err := t.FindEntry(path) if err != nil { return 0, ErrEntryNotFound } return t.s.EncodedObjectSize(e.Hash) }
go
func (t *Tree) Size(path string) (int64, error) { e, err := t.FindEntry(path) if err != nil { return 0, ErrEntryNotFound } return t.s.EncodedObjectSize(e.Hash) }
[ "func", "(", "t", "*", "Tree", ")", "Size", "(", "path", "string", ")", "(", "int64", ",", "error", ")", "{", "e", ",", "err", ":=", "t", ".", "FindEntry", "(", "path", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "ErrEntryNotFound", "\n", "}", "\n\n", "return", "t", ".", "s", ".", "EncodedObjectSize", "(", "e", ".", "Hash", ")", "\n", "}" ]
// Size returns the plaintext size of an object, without reading it // into memory.
[ "Size", "returns", "the", "plaintext", "size", "of", "an", "object", "without", "reading", "it", "into", "memory", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/object/tree.go#L92-L99
train
src-d/go-git
plumbing/object/tree.go
Tree
func (t *Tree) Tree(path string) (*Tree, error) { e, err := t.FindEntry(path) if err != nil { return nil, ErrDirectoryNotFound } tree, err := GetTree(t.s, e.Hash) if err == plumbing.ErrObjectNotFound { return nil, ErrDirectoryNotFound } return tree, err }
go
func (t *Tree) Tree(path string) (*Tree, error) { e, err := t.FindEntry(path) if err != nil { return nil, ErrDirectoryNotFound } tree, err := GetTree(t.s, e.Hash) if err == plumbing.ErrObjectNotFound { return nil, ErrDirectoryNotFound } return tree, err }
[ "func", "(", "t", "*", "Tree", ")", "Tree", "(", "path", "string", ")", "(", "*", "Tree", ",", "error", ")", "{", "e", ",", "err", ":=", "t", ".", "FindEntry", "(", "path", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "ErrDirectoryNotFound", "\n", "}", "\n\n", "tree", ",", "err", ":=", "GetTree", "(", "t", ".", "s", ",", "e", ".", "Hash", ")", "\n", "if", "err", "==", "plumbing", ".", "ErrObjectNotFound", "{", "return", "nil", ",", "ErrDirectoryNotFound", "\n", "}", "\n\n", "return", "tree", ",", "err", "\n", "}" ]
// Tree returns the tree identified by the `path` argument. // The path is interpreted as relative to the tree receiver.
[ "Tree", "returns", "the", "tree", "identified", "by", "the", "path", "argument", ".", "The", "path", "is", "interpreted", "as", "relative", "to", "the", "tree", "receiver", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/object/tree.go#L103-L115
train
src-d/go-git
plumbing/object/tree.go
FindEntry
func (t *Tree) FindEntry(path string) (*TreeEntry, error) { if t.t == nil { t.t = make(map[string]*Tree) } pathParts := strings.Split(path, "/") startingTree := t pathCurrent := "" // search for the longest path in the tree path cache for i := len(pathParts) - 1; i > 1; i-- { path := filepath.Join(pathParts[:i]...) tree, ok := t.t[path] if ok { startingTree = tree pathParts = pathParts[i:] pathCurrent = path break } } var tree *Tree var err error for tree = startingTree; len(pathParts) > 1; pathParts = pathParts[1:] { if tree, err = tree.dir(pathParts[0]); err != nil { return nil, err } pathCurrent = filepath.Join(pathCurrent, pathParts[0]) t.t[pathCurrent] = tree } return tree.entry(pathParts[0]) }
go
func (t *Tree) FindEntry(path string) (*TreeEntry, error) { if t.t == nil { t.t = make(map[string]*Tree) } pathParts := strings.Split(path, "/") startingTree := t pathCurrent := "" // search for the longest path in the tree path cache for i := len(pathParts) - 1; i > 1; i-- { path := filepath.Join(pathParts[:i]...) tree, ok := t.t[path] if ok { startingTree = tree pathParts = pathParts[i:] pathCurrent = path break } } var tree *Tree var err error for tree = startingTree; len(pathParts) > 1; pathParts = pathParts[1:] { if tree, err = tree.dir(pathParts[0]); err != nil { return nil, err } pathCurrent = filepath.Join(pathCurrent, pathParts[0]) t.t[pathCurrent] = tree } return tree.entry(pathParts[0]) }
[ "func", "(", "t", "*", "Tree", ")", "FindEntry", "(", "path", "string", ")", "(", "*", "TreeEntry", ",", "error", ")", "{", "if", "t", ".", "t", "==", "nil", "{", "t", ".", "t", "=", "make", "(", "map", "[", "string", "]", "*", "Tree", ")", "\n", "}", "\n\n", "pathParts", ":=", "strings", ".", "Split", "(", "path", ",", "\"", "\"", ")", "\n", "startingTree", ":=", "t", "\n", "pathCurrent", ":=", "\"", "\"", "\n\n", "// search for the longest path in the tree path cache", "for", "i", ":=", "len", "(", "pathParts", ")", "-", "1", ";", "i", ">", "1", ";", "i", "--", "{", "path", ":=", "filepath", ".", "Join", "(", "pathParts", "[", ":", "i", "]", "...", ")", "\n\n", "tree", ",", "ok", ":=", "t", ".", "t", "[", "path", "]", "\n", "if", "ok", "{", "startingTree", "=", "tree", "\n", "pathParts", "=", "pathParts", "[", "i", ":", "]", "\n", "pathCurrent", "=", "path", "\n\n", "break", "\n", "}", "\n", "}", "\n\n", "var", "tree", "*", "Tree", "\n", "var", "err", "error", "\n", "for", "tree", "=", "startingTree", ";", "len", "(", "pathParts", ")", ">", "1", ";", "pathParts", "=", "pathParts", "[", "1", ":", "]", "{", "if", "tree", ",", "err", "=", "tree", ".", "dir", "(", "pathParts", "[", "0", "]", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "pathCurrent", "=", "filepath", ".", "Join", "(", "pathCurrent", ",", "pathParts", "[", "0", "]", ")", "\n", "t", ".", "t", "[", "pathCurrent", "]", "=", "tree", "\n", "}", "\n\n", "return", "tree", ".", "entry", "(", "pathParts", "[", "0", "]", ")", "\n", "}" ]
// FindEntry search a TreeEntry in this tree or any subtree.
[ "FindEntry", "search", "a", "TreeEntry", "in", "this", "tree", "or", "any", "subtree", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/object/tree.go#L128-L163
train
src-d/go-git
plumbing/object/tree.go
Decode
func (t *Tree) Decode(o plumbing.EncodedObject) (err error) { if o.Type() != plumbing.TreeObject { return ErrUnsupportedObject } t.Hash = o.Hash() if o.Size() == 0 { return nil } t.Entries = nil t.m = nil reader, err := o.Reader() if err != nil { return err } defer ioutil.CheckClose(reader, &err) r := bufPool.Get().(*bufio.Reader) defer bufPool.Put(r) r.Reset(reader) for { str, err := r.ReadString(' ') if err != nil { if err == io.EOF { break } return err } str = str[:len(str)-1] // strip last byte (' ') mode, err := filemode.New(str) if err != nil { return err } name, err := r.ReadString(0) if err != nil && err != io.EOF { return err } var hash plumbing.Hash if _, err = io.ReadFull(r, hash[:]); err != nil { return err } baseName := name[:len(name)-1] t.Entries = append(t.Entries, TreeEntry{ Hash: hash, Mode: mode, Name: baseName, }) } return nil }
go
func (t *Tree) Decode(o plumbing.EncodedObject) (err error) { if o.Type() != plumbing.TreeObject { return ErrUnsupportedObject } t.Hash = o.Hash() if o.Size() == 0 { return nil } t.Entries = nil t.m = nil reader, err := o.Reader() if err != nil { return err } defer ioutil.CheckClose(reader, &err) r := bufPool.Get().(*bufio.Reader) defer bufPool.Put(r) r.Reset(reader) for { str, err := r.ReadString(' ') if err != nil { if err == io.EOF { break } return err } str = str[:len(str)-1] // strip last byte (' ') mode, err := filemode.New(str) if err != nil { return err } name, err := r.ReadString(0) if err != nil && err != io.EOF { return err } var hash plumbing.Hash if _, err = io.ReadFull(r, hash[:]); err != nil { return err } baseName := name[:len(name)-1] t.Entries = append(t.Entries, TreeEntry{ Hash: hash, Mode: mode, Name: baseName, }) } return nil }
[ "func", "(", "t", "*", "Tree", ")", "Decode", "(", "o", "plumbing", ".", "EncodedObject", ")", "(", "err", "error", ")", "{", "if", "o", ".", "Type", "(", ")", "!=", "plumbing", ".", "TreeObject", "{", "return", "ErrUnsupportedObject", "\n", "}", "\n\n", "t", ".", "Hash", "=", "o", ".", "Hash", "(", ")", "\n", "if", "o", ".", "Size", "(", ")", "==", "0", "{", "return", "nil", "\n", "}", "\n\n", "t", ".", "Entries", "=", "nil", "\n", "t", ".", "m", "=", "nil", "\n\n", "reader", ",", "err", ":=", "o", ".", "Reader", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "defer", "ioutil", ".", "CheckClose", "(", "reader", ",", "&", "err", ")", "\n\n", "r", ":=", "bufPool", ".", "Get", "(", ")", ".", "(", "*", "bufio", ".", "Reader", ")", "\n", "defer", "bufPool", ".", "Put", "(", "r", ")", "\n", "r", ".", "Reset", "(", "reader", ")", "\n", "for", "{", "str", ",", "err", ":=", "r", ".", "ReadString", "(", "' '", ")", "\n", "if", "err", "!=", "nil", "{", "if", "err", "==", "io", ".", "EOF", "{", "break", "\n", "}", "\n\n", "return", "err", "\n", "}", "\n", "str", "=", "str", "[", ":", "len", "(", "str", ")", "-", "1", "]", "// strip last byte (' ')", "\n\n", "mode", ",", "err", ":=", "filemode", ".", "New", "(", "str", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "name", ",", "err", ":=", "r", ".", "ReadString", "(", "0", ")", "\n", "if", "err", "!=", "nil", "&&", "err", "!=", "io", ".", "EOF", "{", "return", "err", "\n", "}", "\n\n", "var", "hash", "plumbing", ".", "Hash", "\n", "if", "_", ",", "err", "=", "io", ".", "ReadFull", "(", "r", ",", "hash", "[", ":", "]", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "baseName", ":=", "name", "[", ":", "len", "(", "name", ")", "-", "1", "]", "\n", "t", ".", "Entries", "=", "append", "(", "t", ".", "Entries", ",", "TreeEntry", "{", "Hash", ":", "hash", ",", "Mode", ":", "mode", ",", "Name", ":", "baseName", ",", "}", ")", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Decode transform an plumbing.EncodedObject into a Tree struct
[ "Decode", "transform", "an", "plumbing", ".", "EncodedObject", "into", "a", "Tree", "struct" ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/object/tree.go#L214-L271
train
src-d/go-git
plumbing/object/tree.go
Encode
func (t *Tree) Encode(o plumbing.EncodedObject) (err error) { o.SetType(plumbing.TreeObject) w, err := o.Writer() if err != nil { return err } defer ioutil.CheckClose(w, &err) for _, entry := range t.Entries { if _, err = fmt.Fprintf(w, "%o %s", entry.Mode, entry.Name); err != nil { return err } if _, err = w.Write([]byte{0x00}); err != nil { return err } if _, err = w.Write([]byte(entry.Hash[:])); err != nil { return err } } return err }
go
func (t *Tree) Encode(o plumbing.EncodedObject) (err error) { o.SetType(plumbing.TreeObject) w, err := o.Writer() if err != nil { return err } defer ioutil.CheckClose(w, &err) for _, entry := range t.Entries { if _, err = fmt.Fprintf(w, "%o %s", entry.Mode, entry.Name); err != nil { return err } if _, err = w.Write([]byte{0x00}); err != nil { return err } if _, err = w.Write([]byte(entry.Hash[:])); err != nil { return err } } return err }
[ "func", "(", "t", "*", "Tree", ")", "Encode", "(", "o", "plumbing", ".", "EncodedObject", ")", "(", "err", "error", ")", "{", "o", ".", "SetType", "(", "plumbing", ".", "TreeObject", ")", "\n", "w", ",", "err", ":=", "o", ".", "Writer", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "defer", "ioutil", ".", "CheckClose", "(", "w", ",", "&", "err", ")", "\n", "for", "_", ",", "entry", ":=", "range", "t", ".", "Entries", "{", "if", "_", ",", "err", "=", "fmt", ".", "Fprintf", "(", "w", ",", "\"", "\"", ",", "entry", ".", "Mode", ",", "entry", ".", "Name", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "if", "_", ",", "err", "=", "w", ".", "Write", "(", "[", "]", "byte", "{", "0x00", "}", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "if", "_", ",", "err", "=", "w", ".", "Write", "(", "[", "]", "byte", "(", "entry", ".", "Hash", "[", ":", "]", ")", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n\n", "return", "err", "\n", "}" ]
// Encode transforms a Tree into a plumbing.EncodedObject.
[ "Encode", "transforms", "a", "Tree", "into", "a", "plumbing", ".", "EncodedObject", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/object/tree.go#L274-L297
train
src-d/go-git
plumbing/object/tree.go
Diff
func (from *Tree) Diff(to *Tree) (Changes, error) { return DiffTree(from, to) }
go
func (from *Tree) Diff(to *Tree) (Changes, error) { return DiffTree(from, to) }
[ "func", "(", "from", "*", "Tree", ")", "Diff", "(", "to", "*", "Tree", ")", "(", "Changes", ",", "error", ")", "{", "return", "DiffTree", "(", "from", ",", "to", ")", "\n", "}" ]
// Diff returns a list of changes between this tree and the provided one
[ "Diff", "returns", "a", "list", "of", "changes", "between", "this", "tree", "and", "the", "provided", "one" ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/object/tree.go#L307-L309
train
src-d/go-git
plumbing/object/tree.go
DiffContext
func (from *Tree) DiffContext(ctx context.Context, to *Tree) (Changes, error) { return DiffTreeContext(ctx, from, to) }
go
func (from *Tree) DiffContext(ctx context.Context, to *Tree) (Changes, error) { return DiffTreeContext(ctx, from, to) }
[ "func", "(", "from", "*", "Tree", ")", "DiffContext", "(", "ctx", "context", ".", "Context", ",", "to", "*", "Tree", ")", "(", "Changes", ",", "error", ")", "{", "return", "DiffTreeContext", "(", "ctx", ",", "from", ",", "to", ")", "\n", "}" ]
// Diff returns a list of changes between this tree and the provided one // Error will be returned if context expires // Provided context must be non nil
[ "Diff", "returns", "a", "list", "of", "changes", "between", "this", "tree", "and", "the", "provided", "one", "Error", "will", "be", "returned", "if", "context", "expires", "Provided", "context", "must", "be", "non", "nil" ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/object/tree.go#L314-L316
train
src-d/go-git
plumbing/object/tree.go
Patch
func (from *Tree) Patch(to *Tree) (*Patch, error) { return from.PatchContext(context.Background(), to) }
go
func (from *Tree) Patch(to *Tree) (*Patch, error) { return from.PatchContext(context.Background(), to) }
[ "func", "(", "from", "*", "Tree", ")", "Patch", "(", "to", "*", "Tree", ")", "(", "*", "Patch", ",", "error", ")", "{", "return", "from", ".", "PatchContext", "(", "context", ".", "Background", "(", ")", ",", "to", ")", "\n", "}" ]
// Patch returns a slice of Patch objects with all the changes between trees // in chunks. This representation can be used to create several diff outputs.
[ "Patch", "returns", "a", "slice", "of", "Patch", "objects", "with", "all", "the", "changes", "between", "trees", "in", "chunks", ".", "This", "representation", "can", "be", "used", "to", "create", "several", "diff", "outputs", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/object/tree.go#L320-L322
train
src-d/go-git
plumbing/object/tree.go
PatchContext
func (from *Tree) PatchContext(ctx context.Context, to *Tree) (*Patch, error) { changes, err := DiffTreeContext(ctx, from, to) if err != nil { return nil, err } return changes.PatchContext(ctx) }
go
func (from *Tree) PatchContext(ctx context.Context, to *Tree) (*Patch, error) { changes, err := DiffTreeContext(ctx, from, to) if err != nil { return nil, err } return changes.PatchContext(ctx) }
[ "func", "(", "from", "*", "Tree", ")", "PatchContext", "(", "ctx", "context", ".", "Context", ",", "to", "*", "Tree", ")", "(", "*", "Patch", ",", "error", ")", "{", "changes", ",", "err", ":=", "DiffTreeContext", "(", "ctx", ",", "from", ",", "to", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "changes", ".", "PatchContext", "(", "ctx", ")", "\n", "}" ]
// Patch returns a slice of Patch objects with all the changes between trees // in chunks. This representation can be used to create several diff outputs. // If context expires, an error will be returned // Provided context must be non-nil
[ "Patch", "returns", "a", "slice", "of", "Patch", "objects", "with", "all", "the", "changes", "between", "trees", "in", "chunks", ".", "This", "representation", "can", "be", "used", "to", "create", "several", "diff", "outputs", ".", "If", "context", "expires", "an", "error", "will", "be", "returned", "Provided", "context", "must", "be", "non", "-", "nil" ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/object/tree.go#L328-L335
train
src-d/go-git
plumbing/object/tree.go
Tree
func (w *TreeWalker) Tree() *Tree { current := len(w.stack) - 1 if w.stack[current].pos == 0 { current-- } if current < 0 { return nil } return w.stack[current].t }
go
func (w *TreeWalker) Tree() *Tree { current := len(w.stack) - 1 if w.stack[current].pos == 0 { current-- } if current < 0 { return nil } return w.stack[current].t }
[ "func", "(", "w", "*", "TreeWalker", ")", "Tree", "(", ")", "*", "Tree", "{", "current", ":=", "len", "(", "w", ".", "stack", ")", "-", "1", "\n", "if", "w", ".", "stack", "[", "current", "]", ".", "pos", "==", "0", "{", "current", "--", "\n", "}", "\n\n", "if", "current", "<", "0", "{", "return", "nil", "\n", "}", "\n\n", "return", "w", ".", "stack", "[", "current", "]", ".", "t", "\n", "}" ]
// Tree returns the tree that the tree walker most recently operated on.
[ "Tree", "returns", "the", "tree", "that", "the", "tree", "walker", "most", "recently", "operated", "on", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/object/tree.go#L447-L458
train
src-d/go-git
plumbing/object/tree.go
Next
func (iter *TreeIter) Next() (*Tree, error) { for { obj, err := iter.EncodedObjectIter.Next() if err != nil { return nil, err } if obj.Type() != plumbing.TreeObject { continue } return DecodeTree(iter.s, obj) } }
go
func (iter *TreeIter) Next() (*Tree, error) { for { obj, err := iter.EncodedObjectIter.Next() if err != nil { return nil, err } if obj.Type() != plumbing.TreeObject { continue } return DecodeTree(iter.s, obj) } }
[ "func", "(", "iter", "*", "TreeIter", ")", "Next", "(", ")", "(", "*", "Tree", ",", "error", ")", "{", "for", "{", "obj", ",", "err", ":=", "iter", ".", "EncodedObjectIter", ".", "Next", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "if", "obj", ".", "Type", "(", ")", "!=", "plumbing", ".", "TreeObject", "{", "continue", "\n", "}", "\n\n", "return", "DecodeTree", "(", "iter", ".", "s", ",", "obj", ")", "\n", "}", "\n", "}" ]
// Next moves the iterator to the next tree and returns a pointer to it. If // there are no more trees, it returns io.EOF.
[ "Next", "moves", "the", "iterator", "to", "the", "next", "tree", "and", "returns", "a", "pointer", "to", "it", ".", "If", "there", "are", "no", "more", "trees", "it", "returns", "io", ".", "EOF", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/object/tree.go#L482-L495
train
src-d/go-git
plumbing/object/tree.go
ForEach
func (iter *TreeIter) ForEach(cb func(*Tree) error) error { return iter.EncodedObjectIter.ForEach(func(obj plumbing.EncodedObject) error { if obj.Type() != plumbing.TreeObject { return nil } t, err := DecodeTree(iter.s, obj) if err != nil { return err } return cb(t) }) }
go
func (iter *TreeIter) ForEach(cb func(*Tree) error) error { return iter.EncodedObjectIter.ForEach(func(obj plumbing.EncodedObject) error { if obj.Type() != plumbing.TreeObject { return nil } t, err := DecodeTree(iter.s, obj) if err != nil { return err } return cb(t) }) }
[ "func", "(", "iter", "*", "TreeIter", ")", "ForEach", "(", "cb", "func", "(", "*", "Tree", ")", "error", ")", "error", "{", "return", "iter", ".", "EncodedObjectIter", ".", "ForEach", "(", "func", "(", "obj", "plumbing", ".", "EncodedObject", ")", "error", "{", "if", "obj", ".", "Type", "(", ")", "!=", "plumbing", ".", "TreeObject", "{", "return", "nil", "\n", "}", "\n\n", "t", ",", "err", ":=", "DecodeTree", "(", "iter", ".", "s", ",", "obj", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "cb", "(", "t", ")", "\n", "}", ")", "\n", "}" ]
// ForEach call the cb function for each tree contained on this iter until // an error happens or the end of the iter is reached. If ErrStop is sent // the iteration is stop but no error is returned. The iterator is closed.
[ "ForEach", "call", "the", "cb", "function", "for", "each", "tree", "contained", "on", "this", "iter", "until", "an", "error", "happens", "or", "the", "end", "of", "the", "iter", "is", "reached", ".", "If", "ErrStop", "is", "sent", "the", "iteration", "is", "stop", "but", "no", "error", "is", "returned", ".", "The", "iterator", "is", "closed", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/object/tree.go#L500-L513
train
src-d/go-git
plumbing/format/packfile/diff_delta.go
GetDelta
func GetDelta(base, target plumbing.EncodedObject) (plumbing.EncodedObject, error) { return getDelta(new(deltaIndex), base, target) }
go
func GetDelta(base, target plumbing.EncodedObject) (plumbing.EncodedObject, error) { return getDelta(new(deltaIndex), base, target) }
[ "func", "GetDelta", "(", "base", ",", "target", "plumbing", ".", "EncodedObject", ")", "(", "plumbing", ".", "EncodedObject", ",", "error", ")", "{", "return", "getDelta", "(", "new", "(", "deltaIndex", ")", ",", "base", ",", "target", ")", "\n", "}" ]
// GetDelta returns an EncodedObject of type OFSDeltaObject. Base and Target object, // will be loaded into memory to be able to create the delta object. // To generate target again, you will need the obtained object and "base" one. // Error will be returned if base or target object cannot be read.
[ "GetDelta", "returns", "an", "EncodedObject", "of", "type", "OFSDeltaObject", ".", "Base", "and", "Target", "object", "will", "be", "loaded", "into", "memory", "to", "be", "able", "to", "create", "the", "delta", "object", ".", "To", "generate", "target", "again", "you", "will", "need", "the", "obtained", "object", "and", "base", "one", ".", "Error", "will", "be", "returned", "if", "base", "or", "target", "object", "cannot", "be", "read", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/format/packfile/diff_delta.go#L26-L28
train
src-d/go-git
plumbing/format/packfile/diff_delta.go
DiffDelta
func DiffDelta(src, tgt []byte) []byte { return diffDelta(new(deltaIndex), src, tgt) }
go
func DiffDelta(src, tgt []byte) []byte { return diffDelta(new(deltaIndex), src, tgt) }
[ "func", "DiffDelta", "(", "src", ",", "tgt", "[", "]", "byte", ")", "[", "]", "byte", "{", "return", "diffDelta", "(", "new", "(", "deltaIndex", ")", ",", "src", ",", "tgt", ")", "\n", "}" ]
// DiffDelta returns the delta that transforms src into tgt.
[ "DiffDelta", "returns", "the", "delta", "that", "transforms", "src", "into", "tgt", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/format/packfile/diff_delta.go#L74-L76
train
src-d/go-git
plumbing/object/treenoder.go
NewTreeRootNode
func NewTreeRootNode(t *Tree) noder.Noder { if t == nil { return &treeNoder{} } return &treeNoder{ parent: t, name: "", mode: filemode.Dir, hash: t.Hash, } }
go
func NewTreeRootNode(t *Tree) noder.Noder { if t == nil { return &treeNoder{} } return &treeNoder{ parent: t, name: "", mode: filemode.Dir, hash: t.Hash, } }
[ "func", "NewTreeRootNode", "(", "t", "*", "Tree", ")", "noder", ".", "Noder", "{", "if", "t", "==", "nil", "{", "return", "&", "treeNoder", "{", "}", "\n", "}", "\n\n", "return", "&", "treeNoder", "{", "parent", ":", "t", ",", "name", ":", "\"", "\"", ",", "mode", ":", "filemode", ".", "Dir", ",", "hash", ":", "t", ".", "Hash", ",", "}", "\n", "}" ]
// NewTreeRootNode returns the root node of a Tree
[ "NewTreeRootNode", "returns", "the", "root", "node", "of", "a", "Tree" ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/object/treenoder.go#L28-L39
train
src-d/go-git
plumbing/object/treenoder.go
Children
func (t *treeNoder) Children() ([]noder.Noder, error) { if t.mode != filemode.Dir { return noder.NoChildren, nil } // children are memoized for efficiency if t.children != nil { return t.children, nil } // the parent of the returned children will be ourself as a tree if // we are a not the root treenoder. The root is special as it // is is own parent. parent := t.parent if !t.isRoot() { var err error if parent, err = t.parent.Tree(t.name); err != nil { return nil, err } } return transformChildren(parent) }
go
func (t *treeNoder) Children() ([]noder.Noder, error) { if t.mode != filemode.Dir { return noder.NoChildren, nil } // children are memoized for efficiency if t.children != nil { return t.children, nil } // the parent of the returned children will be ourself as a tree if // we are a not the root treenoder. The root is special as it // is is own parent. parent := t.parent if !t.isRoot() { var err error if parent, err = t.parent.Tree(t.name); err != nil { return nil, err } } return transformChildren(parent) }
[ "func", "(", "t", "*", "treeNoder", ")", "Children", "(", ")", "(", "[", "]", "noder", ".", "Noder", ",", "error", ")", "{", "if", "t", ".", "mode", "!=", "filemode", ".", "Dir", "{", "return", "noder", ".", "NoChildren", ",", "nil", "\n", "}", "\n\n", "// children are memoized for efficiency", "if", "t", ".", "children", "!=", "nil", "{", "return", "t", ".", "children", ",", "nil", "\n", "}", "\n\n", "// the parent of the returned children will be ourself as a tree if", "// we are a not the root treenoder. The root is special as it", "// is is own parent.", "parent", ":=", "t", ".", "parent", "\n", "if", "!", "t", ".", "isRoot", "(", ")", "{", "var", "err", "error", "\n", "if", "parent", ",", "err", "=", "t", ".", "parent", ".", "Tree", "(", "t", ".", "name", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "}", "\n\n", "return", "transformChildren", "(", "parent", ")", "\n", "}" ]
// Children will return the children of a treenoder as treenoders, // building them from the children of the wrapped git tree.
[ "Children", "will", "return", "the", "children", "of", "a", "treenoder", "as", "treenoders", "building", "them", "from", "the", "children", "of", "the", "wrapped", "git", "tree", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/object/treenoder.go#L66-L88
train
src-d/go-git
plumbing/object/treenoder.go
transformChildren
func transformChildren(t *Tree) ([]noder.Noder, error) { var err error var e TreeEntry // there will be more tree entries than children in the tree, // due to submodules and empty directories, but I think it is still // worth it to pre-allocate the whole array now, even if sometimes // is bigger than needed. ret := make([]noder.Noder, 0, len(t.Entries)) walker := NewTreeWalker(t, false, nil) // don't recurse // don't defer walker.Close() for efficiency reasons. for { _, e, err = walker.Next() if err == io.EOF { break } if err != nil { walker.Close() return nil, err } ret = append(ret, &treeNoder{ parent: t, name: e.Name, mode: e.Mode, hash: e.Hash, }) } walker.Close() return ret, nil }
go
func transformChildren(t *Tree) ([]noder.Noder, error) { var err error var e TreeEntry // there will be more tree entries than children in the tree, // due to submodules and empty directories, but I think it is still // worth it to pre-allocate the whole array now, even if sometimes // is bigger than needed. ret := make([]noder.Noder, 0, len(t.Entries)) walker := NewTreeWalker(t, false, nil) // don't recurse // don't defer walker.Close() for efficiency reasons. for { _, e, err = walker.Next() if err == io.EOF { break } if err != nil { walker.Close() return nil, err } ret = append(ret, &treeNoder{ parent: t, name: e.Name, mode: e.Mode, hash: e.Hash, }) } walker.Close() return ret, nil }
[ "func", "transformChildren", "(", "t", "*", "Tree", ")", "(", "[", "]", "noder", ".", "Noder", ",", "error", ")", "{", "var", "err", "error", "\n", "var", "e", "TreeEntry", "\n\n", "// there will be more tree entries than children in the tree,", "// due to submodules and empty directories, but I think it is still", "// worth it to pre-allocate the whole array now, even if sometimes", "// is bigger than needed.", "ret", ":=", "make", "(", "[", "]", "noder", ".", "Noder", ",", "0", ",", "len", "(", "t", ".", "Entries", ")", ")", "\n\n", "walker", ":=", "NewTreeWalker", "(", "t", ",", "false", ",", "nil", ")", "// don't recurse", "\n", "// don't defer walker.Close() for efficiency reasons.", "for", "{", "_", ",", "e", ",", "err", "=", "walker", ".", "Next", "(", ")", "\n", "if", "err", "==", "io", ".", "EOF", "{", "break", "\n", "}", "\n", "if", "err", "!=", "nil", "{", "walker", ".", "Close", "(", ")", "\n", "return", "nil", ",", "err", "\n", "}", "\n\n", "ret", "=", "append", "(", "ret", ",", "&", "treeNoder", "{", "parent", ":", "t", ",", "name", ":", "e", ".", "Name", ",", "mode", ":", "e", ".", "Mode", ",", "hash", ":", "e", ".", "Hash", ",", "}", ")", "\n", "}", "\n", "walker", ".", "Close", "(", ")", "\n\n", "return", "ret", ",", "nil", "\n", "}" ]
// Returns the children of a tree as treenoders. // Efficiency is key here.
[ "Returns", "the", "children", "of", "a", "tree", "as", "treenoders", ".", "Efficiency", "is", "key", "here", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/object/treenoder.go#L92-L124
train
src-d/go-git
blame.go
Blame
func Blame(c *object.Commit, path string) (*BlameResult, error) { // The file to blame is identified by the input arguments: // commit and path. commit is a Commit object obtained from a Repository. Path // represents a path to a specific file contained into the repository. // // Blaming a file is a two step process: // // 1. Create a linear history of the commits affecting a file. We use // revlist.New for that. // // 2. Then build a graph with a node for every line in every file in // the history of the file. // // Each node is assigned a commit: Start by the nodes in the first // commit. Assign that commit as the creator of all its lines. // // Then jump to the nodes in the next commit, and calculate the diff // between the two files. Newly created lines get // assigned the new commit as its origin. Modified lines also get // this new commit. Untouched lines retain the old commit. // // All this work is done in the assignOrigin function which holds all // the internal relevant data in a "blame" struct, that is not // exported. // // TODO: ways to improve the efficiency of this function: // 1. Improve revlist // 2. Improve how to traverse the history (example a backward traversal will // be much more efficient) // // TODO: ways to improve the function in general: // 1. Add memoization between revlist and assign. // 2. It is using much more memory than needed, see the TODOs below. b := new(blame) b.fRev = c b.path = path // get all the file revisions if err := b.fillRevs(); err != nil { return nil, err } // calculate the line tracking graph and fill in // file contents in data. if err := b.fillGraphAndData(); err != nil { return nil, err } file, err := b.fRev.File(b.path) if err != nil { return nil, err } finalLines, err := file.Lines() if err != nil { return nil, err } // Each node (line) holds the commit where it was introduced or // last modified. To achieve that we use the FORWARD algorithm // described in Zimmermann, et al. "Mining Version Archives for // Co-changed Lines", in proceedings of the Mining Software // Repositories workshop, Shanghai, May 22-23, 2006. lines, err := newLines(finalLines, b.sliceGraph(len(b.graph)-1)) if err != nil { return nil, err } return &BlameResult{ Path: path, Rev: c.Hash, Lines: lines, }, nil }
go
func Blame(c *object.Commit, path string) (*BlameResult, error) { // The file to blame is identified by the input arguments: // commit and path. commit is a Commit object obtained from a Repository. Path // represents a path to a specific file contained into the repository. // // Blaming a file is a two step process: // // 1. Create a linear history of the commits affecting a file. We use // revlist.New for that. // // 2. Then build a graph with a node for every line in every file in // the history of the file. // // Each node is assigned a commit: Start by the nodes in the first // commit. Assign that commit as the creator of all its lines. // // Then jump to the nodes in the next commit, and calculate the diff // between the two files. Newly created lines get // assigned the new commit as its origin. Modified lines also get // this new commit. Untouched lines retain the old commit. // // All this work is done in the assignOrigin function which holds all // the internal relevant data in a "blame" struct, that is not // exported. // // TODO: ways to improve the efficiency of this function: // 1. Improve revlist // 2. Improve how to traverse the history (example a backward traversal will // be much more efficient) // // TODO: ways to improve the function in general: // 1. Add memoization between revlist and assign. // 2. It is using much more memory than needed, see the TODOs below. b := new(blame) b.fRev = c b.path = path // get all the file revisions if err := b.fillRevs(); err != nil { return nil, err } // calculate the line tracking graph and fill in // file contents in data. if err := b.fillGraphAndData(); err != nil { return nil, err } file, err := b.fRev.File(b.path) if err != nil { return nil, err } finalLines, err := file.Lines() if err != nil { return nil, err } // Each node (line) holds the commit where it was introduced or // last modified. To achieve that we use the FORWARD algorithm // described in Zimmermann, et al. "Mining Version Archives for // Co-changed Lines", in proceedings of the Mining Software // Repositories workshop, Shanghai, May 22-23, 2006. lines, err := newLines(finalLines, b.sliceGraph(len(b.graph)-1)) if err != nil { return nil, err } return &BlameResult{ Path: path, Rev: c.Hash, Lines: lines, }, nil }
[ "func", "Blame", "(", "c", "*", "object", ".", "Commit", ",", "path", "string", ")", "(", "*", "BlameResult", ",", "error", ")", "{", "// The file to blame is identified by the input arguments:", "// commit and path. commit is a Commit object obtained from a Repository. Path", "// represents a path to a specific file contained into the repository.", "//", "// Blaming a file is a two step process:", "//", "// 1. Create a linear history of the commits affecting a file. We use", "// revlist.New for that.", "//", "// 2. Then build a graph with a node for every line in every file in", "// the history of the file.", "//", "// Each node is assigned a commit: Start by the nodes in the first", "// commit. Assign that commit as the creator of all its lines.", "//", "// Then jump to the nodes in the next commit, and calculate the diff", "// between the two files. Newly created lines get", "// assigned the new commit as its origin. Modified lines also get", "// this new commit. Untouched lines retain the old commit.", "//", "// All this work is done in the assignOrigin function which holds all", "// the internal relevant data in a \"blame\" struct, that is not", "// exported.", "//", "// TODO: ways to improve the efficiency of this function:", "// 1. Improve revlist", "// 2. Improve how to traverse the history (example a backward traversal will", "// be much more efficient)", "//", "// TODO: ways to improve the function in general:", "// 1. Add memoization between revlist and assign.", "// 2. It is using much more memory than needed, see the TODOs below.", "b", ":=", "new", "(", "blame", ")", "\n", "b", ".", "fRev", "=", "c", "\n", "b", ".", "path", "=", "path", "\n\n", "// get all the file revisions", "if", "err", ":=", "b", ".", "fillRevs", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "// calculate the line tracking graph and fill in", "// file contents in data.", "if", "err", ":=", "b", ".", "fillGraphAndData", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "file", ",", "err", ":=", "b", ".", "fRev", ".", "File", "(", "b", ".", "path", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "finalLines", ",", "err", ":=", "file", ".", "Lines", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "// Each node (line) holds the commit where it was introduced or", "// last modified. To achieve that we use the FORWARD algorithm", "// described in Zimmermann, et al. \"Mining Version Archives for", "// Co-changed Lines\", in proceedings of the Mining Software", "// Repositories workshop, Shanghai, May 22-23, 2006.", "lines", ",", "err", ":=", "newLines", "(", "finalLines", ",", "b", ".", "sliceGraph", "(", "len", "(", "b", ".", "graph", ")", "-", "1", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "&", "BlameResult", "{", "Path", ":", "path", ",", "Rev", ":", "c", ".", "Hash", ",", "Lines", ":", "lines", ",", "}", ",", "nil", "\n", "}" ]
// Blame returns a BlameResult with the information about the last author of // each line from file `path` at commit `c`.
[ "Blame", "returns", "a", "BlameResult", "with", "the", "information", "about", "the", "last", "author", "of", "each", "line", "from", "file", "path", "at", "commit", "c", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/blame.go#L29-L102
train
src-d/go-git
blame.go
fillRevs
func (b *blame) fillRevs() error { var err error b.revs, err = references(b.fRev, b.path) return err }
go
func (b *blame) fillRevs() error { var err error b.revs, err = references(b.fRev, b.path) return err }
[ "func", "(", "b", "*", "blame", ")", "fillRevs", "(", ")", "error", "{", "var", "err", "error", "\n\n", "b", ".", "revs", ",", "err", "=", "references", "(", "b", ".", "fRev", ",", "b", ".", "path", ")", "\n", "return", "err", "\n", "}" ]
// calculate the history of a file "path", starting from commit "from", sorted by commit date.
[ "calculate", "the", "history", "of", "a", "file", "path", "starting", "from", "commit", "from", "sorted", "by", "commit", "date", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/blame.go#L164-L169
train
src-d/go-git
blame.go
fillGraphAndData
func (b *blame) fillGraphAndData() error { //TODO: not all commits are needed, only the current rev and the prev b.graph = make([][]*object.Commit, len(b.revs)) b.data = make([]string, len(b.revs)) // file contents in all the revisions // for every revision of the file, starting with the first // one... for i, rev := range b.revs { // get the contents of the file file, err := rev.File(b.path) if err != nil { return nil } b.data[i], err = file.Contents() if err != nil { return err } nLines := countLines(b.data[i]) // create a node for each line b.graph[i] = make([]*object.Commit, nLines) // assign a commit to each node // if this is the first revision, then the node is assigned to // this first commit. if i == 0 { for j := 0; j < nLines; j++ { b.graph[i][j] = (*object.Commit)(b.revs[i]) } } else { // if this is not the first commit, then assign to the old // commit or to the new one, depending on what the diff // says. b.assignOrigin(i, i-1) } } return nil }
go
func (b *blame) fillGraphAndData() error { //TODO: not all commits are needed, only the current rev and the prev b.graph = make([][]*object.Commit, len(b.revs)) b.data = make([]string, len(b.revs)) // file contents in all the revisions // for every revision of the file, starting with the first // one... for i, rev := range b.revs { // get the contents of the file file, err := rev.File(b.path) if err != nil { return nil } b.data[i], err = file.Contents() if err != nil { return err } nLines := countLines(b.data[i]) // create a node for each line b.graph[i] = make([]*object.Commit, nLines) // assign a commit to each node // if this is the first revision, then the node is assigned to // this first commit. if i == 0 { for j := 0; j < nLines; j++ { b.graph[i][j] = (*object.Commit)(b.revs[i]) } } else { // if this is not the first commit, then assign to the old // commit or to the new one, depending on what the diff // says. b.assignOrigin(i, i-1) } } return nil }
[ "func", "(", "b", "*", "blame", ")", "fillGraphAndData", "(", ")", "error", "{", "//TODO: not all commits are needed, only the current rev and the prev", "b", ".", "graph", "=", "make", "(", "[", "]", "[", "]", "*", "object", ".", "Commit", ",", "len", "(", "b", ".", "revs", ")", ")", "\n", "b", ".", "data", "=", "make", "(", "[", "]", "string", ",", "len", "(", "b", ".", "revs", ")", ")", "// file contents in all the revisions", "\n", "// for every revision of the file, starting with the first", "// one...", "for", "i", ",", "rev", ":=", "range", "b", ".", "revs", "{", "// get the contents of the file", "file", ",", "err", ":=", "rev", ".", "File", "(", "b", ".", "path", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", "\n", "}", "\n", "b", ".", "data", "[", "i", "]", ",", "err", "=", "file", ".", "Contents", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "nLines", ":=", "countLines", "(", "b", ".", "data", "[", "i", "]", ")", "\n", "// create a node for each line", "b", ".", "graph", "[", "i", "]", "=", "make", "(", "[", "]", "*", "object", ".", "Commit", ",", "nLines", ")", "\n", "// assign a commit to each node", "// if this is the first revision, then the node is assigned to", "// this first commit.", "if", "i", "==", "0", "{", "for", "j", ":=", "0", ";", "j", "<", "nLines", ";", "j", "++", "{", "b", ".", "graph", "[", "i", "]", "[", "j", "]", "=", "(", "*", "object", ".", "Commit", ")", "(", "b", ".", "revs", "[", "i", "]", ")", "\n", "}", "\n", "}", "else", "{", "// if this is not the first commit, then assign to the old", "// commit or to the new one, depending on what the diff", "// says.", "b", ".", "assignOrigin", "(", "i", ",", "i", "-", "1", ")", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// build graph of a file from its revision history
[ "build", "graph", "of", "a", "file", "from", "its", "revision", "history" ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/blame.go#L172-L206
train
src-d/go-git
blame.go
GoString
func (b *blame) GoString() string { var buf bytes.Buffer file, err := b.fRev.File(b.path) if err != nil { panic("PrettyPrint: internal error in repo.Data") } contents, err := file.Contents() if err != nil { panic("PrettyPrint: internal error in repo.Data") } lines := strings.Split(contents, "\n") // max line number length mlnl := len(strconv.Itoa(len(lines))) // max author length mal := b.maxAuthorLength() format := fmt.Sprintf("%%s (%%-%ds %%%dd) %%s\n", mal, mlnl) fVs := b.graph[len(b.graph)-1] for ln, v := range fVs { fmt.Fprintf(&buf, format, v.Hash.String()[:8], prettyPrintAuthor(fVs[ln]), ln+1, lines[ln]) } return buf.String() }
go
func (b *blame) GoString() string { var buf bytes.Buffer file, err := b.fRev.File(b.path) if err != nil { panic("PrettyPrint: internal error in repo.Data") } contents, err := file.Contents() if err != nil { panic("PrettyPrint: internal error in repo.Data") } lines := strings.Split(contents, "\n") // max line number length mlnl := len(strconv.Itoa(len(lines))) // max author length mal := b.maxAuthorLength() format := fmt.Sprintf("%%s (%%-%ds %%%dd) %%s\n", mal, mlnl) fVs := b.graph[len(b.graph)-1] for ln, v := range fVs { fmt.Fprintf(&buf, format, v.Hash.String()[:8], prettyPrintAuthor(fVs[ln]), ln+1, lines[ln]) } return buf.String() }
[ "func", "(", "b", "*", "blame", ")", "GoString", "(", ")", "string", "{", "var", "buf", "bytes", ".", "Buffer", "\n\n", "file", ",", "err", ":=", "b", ".", "fRev", ".", "File", "(", "b", ".", "path", ")", "\n", "if", "err", "!=", "nil", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n", "contents", ",", "err", ":=", "file", ".", "Contents", "(", ")", "\n", "if", "err", "!=", "nil", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n\n", "lines", ":=", "strings", ".", "Split", "(", "contents", ",", "\"", "\\n", "\"", ")", "\n", "// max line number length", "mlnl", ":=", "len", "(", "strconv", ".", "Itoa", "(", "len", "(", "lines", ")", ")", ")", "\n", "// max author length", "mal", ":=", "b", ".", "maxAuthorLength", "(", ")", "\n", "format", ":=", "fmt", ".", "Sprintf", "(", "\"", "\\n", "\"", ",", "mal", ",", "mlnl", ")", "\n\n", "fVs", ":=", "b", ".", "graph", "[", "len", "(", "b", ".", "graph", ")", "-", "1", "]", "\n", "for", "ln", ",", "v", ":=", "range", "fVs", "{", "fmt", ".", "Fprintf", "(", "&", "buf", ",", "format", ",", "v", ".", "Hash", ".", "String", "(", ")", "[", ":", "8", "]", ",", "prettyPrintAuthor", "(", "fVs", "[", "ln", "]", ")", ",", "ln", "+", "1", ",", "lines", "[", "ln", "]", ")", "\n", "}", "\n", "return", "buf", ".", "String", "(", ")", "\n", "}" ]
// GoString prints the results of a Blame using git-blame's style.
[ "GoString", "prints", "the", "results", "of", "a", "Blame", "using", "git", "-", "blame", "s", "style", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/blame.go#L248-L274
train
src-d/go-git
blame.go
prettyPrintAuthor
func prettyPrintAuthor(c *object.Commit) string { return fmt.Sprintf("%s %s", c.Author.Name, c.Author.When.Format("2006-01-02")) }
go
func prettyPrintAuthor(c *object.Commit) string { return fmt.Sprintf("%s %s", c.Author.Name, c.Author.When.Format("2006-01-02")) }
[ "func", "prettyPrintAuthor", "(", "c", "*", "object", ".", "Commit", ")", "string", "{", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "c", ".", "Author", ".", "Name", ",", "c", ".", "Author", ".", "When", ".", "Format", "(", "\"", "\"", ")", ")", "\n", "}" ]
// utility function to pretty print the author.
[ "utility", "function", "to", "pretty", "print", "the", "author", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/blame.go#L277-L279
train
src-d/go-git
blame.go
maxAuthorLength
func (b *blame) maxAuthorLength() int { memo := make(map[plumbing.Hash]struct{}, len(b.graph)-1) fVs := b.graph[len(b.graph)-1] m := 0 for ln := range fVs { if _, ok := memo[fVs[ln].Hash]; ok { continue } memo[fVs[ln].Hash] = struct{}{} m = max(m, utf8.RuneCountInString(prettyPrintAuthor(fVs[ln]))) } return m }
go
func (b *blame) maxAuthorLength() int { memo := make(map[plumbing.Hash]struct{}, len(b.graph)-1) fVs := b.graph[len(b.graph)-1] m := 0 for ln := range fVs { if _, ok := memo[fVs[ln].Hash]; ok { continue } memo[fVs[ln].Hash] = struct{}{} m = max(m, utf8.RuneCountInString(prettyPrintAuthor(fVs[ln]))) } return m }
[ "func", "(", "b", "*", "blame", ")", "maxAuthorLength", "(", ")", "int", "{", "memo", ":=", "make", "(", "map", "[", "plumbing", ".", "Hash", "]", "struct", "{", "}", ",", "len", "(", "b", ".", "graph", ")", "-", "1", ")", "\n", "fVs", ":=", "b", ".", "graph", "[", "len", "(", "b", ".", "graph", ")", "-", "1", "]", "\n", "m", ":=", "0", "\n", "for", "ln", ":=", "range", "fVs", "{", "if", "_", ",", "ok", ":=", "memo", "[", "fVs", "[", "ln", "]", ".", "Hash", "]", ";", "ok", "{", "continue", "\n", "}", "\n", "memo", "[", "fVs", "[", "ln", "]", ".", "Hash", "]", "=", "struct", "{", "}", "{", "}", "\n", "m", "=", "max", "(", "m", ",", "utf8", ".", "RuneCountInString", "(", "prettyPrintAuthor", "(", "fVs", "[", "ln", "]", ")", ")", ")", "\n", "}", "\n", "return", "m", "\n", "}" ]
// utility function to calculate the number of runes needed // to print the longest author name in the blame of a file.
[ "utility", "function", "to", "calculate", "the", "number", "of", "runes", "needed", "to", "print", "the", "longest", "author", "name", "in", "the", "blame", "of", "a", "file", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/blame.go#L283-L295
train
src-d/go-git
internal/revision/scanner.go
tokenizeExpression
func tokenizeExpression(ch rune, tokenType token, check runeCategoryValidator, r *bufio.Reader) (token, string, error) { var data []rune data = append(data, ch) for { c, _, err := r.ReadRune() if c == zeroRune { break } if err != nil { return tokenError, "", err } if check(c) { data = append(data, c) } else { err := r.UnreadRune() if err != nil { return tokenError, "", err } return tokenType, string(data), nil } } return tokenType, string(data), nil }
go
func tokenizeExpression(ch rune, tokenType token, check runeCategoryValidator, r *bufio.Reader) (token, string, error) { var data []rune data = append(data, ch) for { c, _, err := r.ReadRune() if c == zeroRune { break } if err != nil { return tokenError, "", err } if check(c) { data = append(data, c) } else { err := r.UnreadRune() if err != nil { return tokenError, "", err } return tokenType, string(data), nil } } return tokenType, string(data), nil }
[ "func", "tokenizeExpression", "(", "ch", "rune", ",", "tokenType", "token", ",", "check", "runeCategoryValidator", ",", "r", "*", "bufio", ".", "Reader", ")", "(", "token", ",", "string", ",", "error", ")", "{", "var", "data", "[", "]", "rune", "\n", "data", "=", "append", "(", "data", ",", "ch", ")", "\n\n", "for", "{", "c", ",", "_", ",", "err", ":=", "r", ".", "ReadRune", "(", ")", "\n\n", "if", "c", "==", "zeroRune", "{", "break", "\n", "}", "\n\n", "if", "err", "!=", "nil", "{", "return", "tokenError", ",", "\"", "\"", ",", "err", "\n", "}", "\n\n", "if", "check", "(", "c", ")", "{", "data", "=", "append", "(", "data", ",", "c", ")", "\n", "}", "else", "{", "err", ":=", "r", ".", "UnreadRune", "(", ")", "\n\n", "if", "err", "!=", "nil", "{", "return", "tokenError", ",", "\"", "\"", ",", "err", "\n", "}", "\n\n", "return", "tokenType", ",", "string", "(", "data", ")", ",", "nil", "\n", "}", "\n", "}", "\n\n", "return", "tokenType", ",", "string", "(", "data", ")", ",", "nil", "\n", "}" ]
// tokenizeExpression aggegates a series of runes matching check predicate into a single // string and provides given tokenType as token type
[ "tokenizeExpression", "aggegates", "a", "series", "of", "runes", "matching", "check", "predicate", "into", "a", "single", "string", "and", "provides", "given", "tokenType", "as", "token", "type" ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/internal/revision/scanner.go#L15-L44
train
src-d/go-git
internal/revision/scanner.go
newScanner
func newScanner(r io.Reader) *scanner { return &scanner{r: bufio.NewReader(r)} }
go
func newScanner(r io.Reader) *scanner { return &scanner{r: bufio.NewReader(r)} }
[ "func", "newScanner", "(", "r", "io", ".", "Reader", ")", "*", "scanner", "{", "return", "&", "scanner", "{", "r", ":", "bufio", ".", "NewReader", "(", "r", ")", "}", "\n", "}" ]
// newScanner returns a new instance of scanner.
[ "newScanner", "returns", "a", "new", "instance", "of", "scanner", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/internal/revision/scanner.go#L54-L56
train
src-d/go-git
internal/revision/scanner.go
scan
func (s *scanner) scan() (token, string, error) { ch, _, err := s.r.ReadRune() if err != nil && err != io.EOF { return tokenError, "", err } switch ch { case zeroRune: return eof, "", nil case ':': return colon, string(ch), nil case '~': return tilde, string(ch), nil case '^': return caret, string(ch), nil case '.': return dot, string(ch), nil case '/': return slash, string(ch), nil case '{': return obrace, string(ch), nil case '}': return cbrace, string(ch), nil case '-': return minus, string(ch), nil case '@': return at, string(ch), nil case '\\': return aslash, string(ch), nil case '?': return qmark, string(ch), nil case '*': return asterisk, string(ch), nil case '[': return obracket, string(ch), nil case '!': return emark, string(ch), nil } if unicode.IsSpace(ch) { return space, string(ch), nil } if unicode.IsControl(ch) { return control, string(ch), nil } if unicode.IsLetter(ch) { return tokenizeExpression(ch, word, unicode.IsLetter, s.r) } if unicode.IsNumber(ch) { return tokenizeExpression(ch, number, unicode.IsNumber, s.r) } return tokenError, string(ch), nil }
go
func (s *scanner) scan() (token, string, error) { ch, _, err := s.r.ReadRune() if err != nil && err != io.EOF { return tokenError, "", err } switch ch { case zeroRune: return eof, "", nil case ':': return colon, string(ch), nil case '~': return tilde, string(ch), nil case '^': return caret, string(ch), nil case '.': return dot, string(ch), nil case '/': return slash, string(ch), nil case '{': return obrace, string(ch), nil case '}': return cbrace, string(ch), nil case '-': return minus, string(ch), nil case '@': return at, string(ch), nil case '\\': return aslash, string(ch), nil case '?': return qmark, string(ch), nil case '*': return asterisk, string(ch), nil case '[': return obracket, string(ch), nil case '!': return emark, string(ch), nil } if unicode.IsSpace(ch) { return space, string(ch), nil } if unicode.IsControl(ch) { return control, string(ch), nil } if unicode.IsLetter(ch) { return tokenizeExpression(ch, word, unicode.IsLetter, s.r) } if unicode.IsNumber(ch) { return tokenizeExpression(ch, number, unicode.IsNumber, s.r) } return tokenError, string(ch), nil }
[ "func", "(", "s", "*", "scanner", ")", "scan", "(", ")", "(", "token", ",", "string", ",", "error", ")", "{", "ch", ",", "_", ",", "err", ":=", "s", ".", "r", ".", "ReadRune", "(", ")", "\n\n", "if", "err", "!=", "nil", "&&", "err", "!=", "io", ".", "EOF", "{", "return", "tokenError", ",", "\"", "\"", ",", "err", "\n", "}", "\n\n", "switch", "ch", "{", "case", "zeroRune", ":", "return", "eof", ",", "\"", "\"", ",", "nil", "\n", "case", "':'", ":", "return", "colon", ",", "string", "(", "ch", ")", ",", "nil", "\n", "case", "'~'", ":", "return", "tilde", ",", "string", "(", "ch", ")", ",", "nil", "\n", "case", "'^'", ":", "return", "caret", ",", "string", "(", "ch", ")", ",", "nil", "\n", "case", "'.'", ":", "return", "dot", ",", "string", "(", "ch", ")", ",", "nil", "\n", "case", "'/'", ":", "return", "slash", ",", "string", "(", "ch", ")", ",", "nil", "\n", "case", "'{'", ":", "return", "obrace", ",", "string", "(", "ch", ")", ",", "nil", "\n", "case", "'}'", ":", "return", "cbrace", ",", "string", "(", "ch", ")", ",", "nil", "\n", "case", "'-'", ":", "return", "minus", ",", "string", "(", "ch", ")", ",", "nil", "\n", "case", "'@'", ":", "return", "at", ",", "string", "(", "ch", ")", ",", "nil", "\n", "case", "'\\\\'", ":", "return", "aslash", ",", "string", "(", "ch", ")", ",", "nil", "\n", "case", "'?'", ":", "return", "qmark", ",", "string", "(", "ch", ")", ",", "nil", "\n", "case", "'*'", ":", "return", "asterisk", ",", "string", "(", "ch", ")", ",", "nil", "\n", "case", "'['", ":", "return", "obracket", ",", "string", "(", "ch", ")", ",", "nil", "\n", "case", "'!'", ":", "return", "emark", ",", "string", "(", "ch", ")", ",", "nil", "\n", "}", "\n\n", "if", "unicode", ".", "IsSpace", "(", "ch", ")", "{", "return", "space", ",", "string", "(", "ch", ")", ",", "nil", "\n", "}", "\n\n", "if", "unicode", ".", "IsControl", "(", "ch", ")", "{", "return", "control", ",", "string", "(", "ch", ")", ",", "nil", "\n", "}", "\n\n", "if", "unicode", ".", "IsLetter", "(", "ch", ")", "{", "return", "tokenizeExpression", "(", "ch", ",", "word", ",", "unicode", ".", "IsLetter", ",", "s", ".", "r", ")", "\n", "}", "\n\n", "if", "unicode", ".", "IsNumber", "(", "ch", ")", "{", "return", "tokenizeExpression", "(", "ch", ",", "number", ",", "unicode", ".", "IsNumber", ",", "s", ".", "r", ")", "\n", "}", "\n\n", "return", "tokenError", ",", "string", "(", "ch", ")", ",", "nil", "\n", "}" ]
// Scan extracts tokens and their strings counterpart // from the reader
[ "Scan", "extracts", "tokens", "and", "their", "strings", "counterpart", "from", "the", "reader" ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/internal/revision/scanner.go#L60-L117
train
src-d/go-git
plumbing/format/diff/unified_encoder.go
addLineNumbers
func (c *hunksGenerator) addLineNumbers(la, lb int, linesBefore int, i int, op Operation) (cla, clb int) { cla = la - linesBefore // we need to search for a reference for the next diff switch { case linesBefore != 0 && c.ctxLines != 0: if lb > c.ctxLines { clb = lb - c.ctxLines + 1 } else { clb = 1 } case c.ctxLines == 0: clb = lb case i != len(c.chunks)-1: next := c.chunks[i+1] if next.Type() == op || next.Type() == Equal { // this diff will be into this chunk clb = lb + 1 } } return }
go
func (c *hunksGenerator) addLineNumbers(la, lb int, linesBefore int, i int, op Operation) (cla, clb int) { cla = la - linesBefore // we need to search for a reference for the next diff switch { case linesBefore != 0 && c.ctxLines != 0: if lb > c.ctxLines { clb = lb - c.ctxLines + 1 } else { clb = 1 } case c.ctxLines == 0: clb = lb case i != len(c.chunks)-1: next := c.chunks[i+1] if next.Type() == op || next.Type() == Equal { // this diff will be into this chunk clb = lb + 1 } } return }
[ "func", "(", "c", "*", "hunksGenerator", ")", "addLineNumbers", "(", "la", ",", "lb", "int", ",", "linesBefore", "int", ",", "i", "int", ",", "op", "Operation", ")", "(", "cla", ",", "clb", "int", ")", "{", "cla", "=", "la", "-", "linesBefore", "\n", "// we need to search for a reference for the next diff", "switch", "{", "case", "linesBefore", "!=", "0", "&&", "c", ".", "ctxLines", "!=", "0", ":", "if", "lb", ">", "c", ".", "ctxLines", "{", "clb", "=", "lb", "-", "c", ".", "ctxLines", "+", "1", "\n", "}", "else", "{", "clb", "=", "1", "\n", "}", "\n", "case", "c", ".", "ctxLines", "==", "0", ":", "clb", "=", "lb", "\n", "case", "i", "!=", "len", "(", "c", ".", "chunks", ")", "-", "1", ":", "next", ":=", "c", ".", "chunks", "[", "i", "+", "1", "]", "\n", "if", "next", ".", "Type", "(", ")", "==", "op", "||", "next", ".", "Type", "(", ")", "==", "Equal", "{", "// this diff will be into this chunk", "clb", "=", "lb", "+", "1", "\n", "}", "\n", "}", "\n\n", "return", "\n", "}" ]
// addLineNumbers obtains the line numbers in a new chunk
[ "addLineNumbers", "obtains", "the", "line", "numbers", "in", "a", "new", "chunk" ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/format/diff/unified_encoder.go#L235-L256
train
src-d/go-git
plumbing/protocol/packp/ulreq_decode.go
Decode
func (u *UploadRequest) Decode(r io.Reader) error { d := newUlReqDecoder(r) return d.Decode(u) }
go
func (u *UploadRequest) Decode(r io.Reader) error { d := newUlReqDecoder(r) return d.Decode(u) }
[ "func", "(", "u", "*", "UploadRequest", ")", "Decode", "(", "r", "io", ".", "Reader", ")", "error", "{", "d", ":=", "newUlReqDecoder", "(", "r", ")", "\n", "return", "d", ".", "Decode", "(", "u", ")", "\n", "}" ]
// Decode reads the next upload-request form its input and // stores it in the UploadRequest.
[ "Decode", "reads", "the", "next", "upload", "-", "request", "form", "its", "input", "and", "stores", "it", "in", "the", "UploadRequest", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/protocol/packp/ulreq_decode.go#L17-L20
train
src-d/go-git
plumbing/protocol/packp/ulreq_decode.go
error
func (d *ulReqDecoder) error(format string, a ...interface{}) { msg := fmt.Sprintf( "pkt-line %d: %s", d.nLine, fmt.Sprintf(format, a...), ) d.err = NewErrUnexpectedData(msg, d.line) }
go
func (d *ulReqDecoder) error(format string, a ...interface{}) { msg := fmt.Sprintf( "pkt-line %d: %s", d.nLine, fmt.Sprintf(format, a...), ) d.err = NewErrUnexpectedData(msg, d.line) }
[ "func", "(", "d", "*", "ulReqDecoder", ")", "error", "(", "format", "string", ",", "a", "...", "interface", "{", "}", ")", "{", "msg", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "d", ".", "nLine", ",", "fmt", ".", "Sprintf", "(", "format", ",", "a", "...", ")", ",", ")", "\n\n", "d", ".", "err", "=", "NewErrUnexpectedData", "(", "msg", ",", "d", ".", "line", ")", "\n", "}" ]
// fills out the parser stiky error
[ "fills", "out", "the", "parser", "stiky", "error" ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/protocol/packp/ulreq_decode.go#L47-L54
train
src-d/go-git
plumbing/protocol/packp/ulreq_decode.go
nextLine
func (d *ulReqDecoder) nextLine() bool { d.nLine++ if !d.s.Scan() { if d.err = d.s.Err(); d.err != nil { return false } d.error("EOF") return false } d.line = d.s.Bytes() d.line = bytes.TrimSuffix(d.line, eol) return true }
go
func (d *ulReqDecoder) nextLine() bool { d.nLine++ if !d.s.Scan() { if d.err = d.s.Err(); d.err != nil { return false } d.error("EOF") return false } d.line = d.s.Bytes() d.line = bytes.TrimSuffix(d.line, eol) return true }
[ "func", "(", "d", "*", "ulReqDecoder", ")", "nextLine", "(", ")", "bool", "{", "d", ".", "nLine", "++", "\n\n", "if", "!", "d", ".", "s", ".", "Scan", "(", ")", "{", "if", "d", ".", "err", "=", "d", ".", "s", ".", "Err", "(", ")", ";", "d", ".", "err", "!=", "nil", "{", "return", "false", "\n", "}", "\n\n", "d", ".", "error", "(", "\"", "\"", ")", "\n", "return", "false", "\n", "}", "\n\n", "d", ".", "line", "=", "d", ".", "s", ".", "Bytes", "(", ")", "\n", "d", ".", "line", "=", "bytes", ".", "TrimSuffix", "(", "d", ".", "line", ",", "eol", ")", "\n\n", "return", "true", "\n", "}" ]
// Reads a new pkt-line from the scanner, makes its payload available as // p.line and increments p.nLine. A successful invocation returns true, // otherwise, false is returned and the sticky error is filled out // accordingly. Trims eols at the end of the payloads.
[ "Reads", "a", "new", "pkt", "-", "line", "from", "the", "scanner", "makes", "its", "payload", "available", "as", "p", ".", "line", "and", "increments", "p", ".", "nLine", ".", "A", "successful", "invocation", "returns", "true", "otherwise", "false", "is", "returned", "and", "the", "sticky", "error", "is", "filled", "out", "accordingly", ".", "Trims", "eols", "at", "the", "end", "of", "the", "payloads", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/protocol/packp/ulreq_decode.go#L60-L76
train
src-d/go-git
utils/merkletrie/internal/fsnoder/new.go
New
func New(s string) (noder.Noder, error) { return decodeDir([]byte(s), root) }
go
func New(s string) (noder.Noder, error) { return decodeDir([]byte(s), root) }
[ "func", "New", "(", "s", "string", ")", "(", "noder", ".", "Noder", ",", "error", ")", "{", "return", "decodeDir", "(", "[", "]", "byte", "(", "s", ")", ",", "root", ")", "\n", "}" ]
// New function creates a full merkle trie from the string description of // a filesystem tree. See examples of the string format in the package // description.
[ "New", "function", "creates", "a", "full", "merkle", "trie", "from", "the", "string", "description", "of", "a", "filesystem", "tree", ".", "See", "examples", "of", "the", "string", "format", "in", "the", "package", "description", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/utils/merkletrie/internal/fsnoder/new.go#L14-L16
train
src-d/go-git
utils/merkletrie/internal/fsnoder/new.go
split
func split(data []byte) [][]byte { chunks := [][]byte{} start := 0 dirDepth := 0 for i, b := range data { switch b { case dirStartMark: dirDepth++ case dirEndMark: dirDepth-- case dirElementSep: if dirDepth == 0 { chunks = append(chunks, data[start:i+1]) start = i + 1 } } } chunks = append(chunks, data[start:]) return chunks }
go
func split(data []byte) [][]byte { chunks := [][]byte{} start := 0 dirDepth := 0 for i, b := range data { switch b { case dirStartMark: dirDepth++ case dirEndMark: dirDepth-- case dirElementSep: if dirDepth == 0 { chunks = append(chunks, data[start:i+1]) start = i + 1 } } } chunks = append(chunks, data[start:]) return chunks }
[ "func", "split", "(", "data", "[", "]", "byte", ")", "[", "]", "[", "]", "byte", "{", "chunks", ":=", "[", "]", "[", "]", "byte", "{", "}", "\n\n", "start", ":=", "0", "\n", "dirDepth", ":=", "0", "\n", "for", "i", ",", "b", ":=", "range", "data", "{", "switch", "b", "{", "case", "dirStartMark", ":", "dirDepth", "++", "\n", "case", "dirEndMark", ":", "dirDepth", "--", "\n", "case", "dirElementSep", ":", "if", "dirDepth", "==", "0", "{", "chunks", "=", "append", "(", "chunks", ",", "data", "[", "start", ":", "i", "+", "1", "]", ")", "\n", "start", "=", "i", "+", "1", "\n", "}", "\n", "}", "\n", "}", "\n", "chunks", "=", "append", "(", "chunks", ",", "data", "[", "start", ":", "]", ")", "\n\n", "return", "chunks", "\n", "}" ]
// returns the description of the elements of a dir. It is just looking // for spaces if they are not part of inner dirs.
[ "returns", "the", "description", "of", "the", "elements", "of", "a", "dir", ".", "It", "is", "just", "looking", "for", "spaces", "if", "they", "are", "not", "part", "of", "inner", "dirs", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/utils/merkletrie/internal/fsnoder/new.go#L93-L114
train
src-d/go-git
utils/merkletrie/internal/fsnoder/new.go
decodeChild
func decodeChild(data []byte) (noder.Noder, error) { clean := bytes.TrimSpace(data) if len(data) < 3 { return nil, fmt.Errorf("element too short: %s", clean) } fileNameEnd := bytes.IndexRune(data, fileStartMark) dirNameEnd := bytes.IndexRune(data, dirStartMark) switch { case fileNameEnd == -1 && dirNameEnd == -1: return nil, fmt.Errorf( "malformed child, no file or dir start mark found") case fileNameEnd == -1: return decodeDir(clean, nonRoot) case dirNameEnd == -1: return decodeFile(clean) case dirNameEnd < fileNameEnd: return decodeDir(clean, nonRoot) case dirNameEnd > fileNameEnd: return decodeFile(clean) } return nil, fmt.Errorf("unreachable") }
go
func decodeChild(data []byte) (noder.Noder, error) { clean := bytes.TrimSpace(data) if len(data) < 3 { return nil, fmt.Errorf("element too short: %s", clean) } fileNameEnd := bytes.IndexRune(data, fileStartMark) dirNameEnd := bytes.IndexRune(data, dirStartMark) switch { case fileNameEnd == -1 && dirNameEnd == -1: return nil, fmt.Errorf( "malformed child, no file or dir start mark found") case fileNameEnd == -1: return decodeDir(clean, nonRoot) case dirNameEnd == -1: return decodeFile(clean) case dirNameEnd < fileNameEnd: return decodeDir(clean, nonRoot) case dirNameEnd > fileNameEnd: return decodeFile(clean) } return nil, fmt.Errorf("unreachable") }
[ "func", "decodeChild", "(", "data", "[", "]", "byte", ")", "(", "noder", ".", "Noder", ",", "error", ")", "{", "clean", ":=", "bytes", ".", "TrimSpace", "(", "data", ")", "\n", "if", "len", "(", "data", ")", "<", "3", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "clean", ")", "\n", "}", "\n\n", "fileNameEnd", ":=", "bytes", ".", "IndexRune", "(", "data", ",", "fileStartMark", ")", "\n", "dirNameEnd", ":=", "bytes", ".", "IndexRune", "(", "data", ",", "dirStartMark", ")", "\n", "switch", "{", "case", "fileNameEnd", "==", "-", "1", "&&", "dirNameEnd", "==", "-", "1", ":", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "case", "fileNameEnd", "==", "-", "1", ":", "return", "decodeDir", "(", "clean", ",", "nonRoot", ")", "\n", "case", "dirNameEnd", "==", "-", "1", ":", "return", "decodeFile", "(", "clean", ")", "\n", "case", "dirNameEnd", "<", "fileNameEnd", ":", "return", "decodeDir", "(", "clean", ",", "nonRoot", ")", "\n", "case", "dirNameEnd", ">", "fileNameEnd", ":", "return", "decodeFile", "(", "clean", ")", "\n", "}", "\n\n", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}" ]
// A child can be a file or a dir.
[ "A", "child", "can", "be", "a", "file", "or", "a", "dir", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/utils/merkletrie/internal/fsnoder/new.go#L117-L140
train
src-d/go-git
utils/merkletrie/internal/fsnoder/new.go
HashEqual
func HashEqual(a, b noder.Hasher) bool { return bytes.Equal(a.Hash(), b.Hash()) }
go
func HashEqual(a, b noder.Hasher) bool { return bytes.Equal(a.Hash(), b.Hash()) }
[ "func", "HashEqual", "(", "a", ",", "b", "noder", ".", "Hasher", ")", "bool", "{", "return", "bytes", ".", "Equal", "(", "a", ".", "Hash", "(", ")", ",", "b", ".", "Hash", "(", ")", ")", "\n", "}" ]
// HashEqual returns if a and b have the same hash.
[ "HashEqual", "returns", "if", "a", "and", "b", "have", "the", "same", "hash", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/utils/merkletrie/internal/fsnoder/new.go#L197-L199
train
src-d/go-git
storage/filesystem/dotgit/writers.go
waitBuildIndex
func (w *PackWriter) waitBuildIndex() error { err := <-w.result if err == packfile.ErrEmptyPackfile { return nil } return err }
go
func (w *PackWriter) waitBuildIndex() error { err := <-w.result if err == packfile.ErrEmptyPackfile { return nil } return err }
[ "func", "(", "w", "*", "PackWriter", ")", "waitBuildIndex", "(", ")", "error", "{", "err", ":=", "<-", "w", ".", "result", "\n", "if", "err", "==", "packfile", ".", "ErrEmptyPackfile", "{", "return", "nil", "\n", "}", "\n\n", "return", "err", "\n", "}" ]
// waitBuildIndex waits until buildIndex function finishes, this can terminate // with a packfile.ErrEmptyPackfile, this means that nothing was written so we // ignore the error
[ "waitBuildIndex", "waits", "until", "buildIndex", "function", "finishes", "this", "can", "terminate", "with", "a", "packfile", ".", "ErrEmptyPackfile", "this", "means", "that", "nothing", "was", "written", "so", "we", "ignore", "the", "error" ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/storage/filesystem/dotgit/writers.go#L80-L87
train
src-d/go-git
storage/filesystem/dotgit/writers.go
Close
func (w *PackWriter) Close() error { defer func() { if w.Notify != nil && w.writer != nil && w.writer.Finished() { w.Notify(w.checksum, w.writer) } close(w.result) }() if err := w.synced.Close(); err != nil { return err } if err := w.waitBuildIndex(); err != nil { return err } if err := w.fr.Close(); err != nil { return err } if err := w.fw.Close(); err != nil { return err } if w.writer == nil || !w.writer.Finished() { return w.clean() } return w.save() }
go
func (w *PackWriter) Close() error { defer func() { if w.Notify != nil && w.writer != nil && w.writer.Finished() { w.Notify(w.checksum, w.writer) } close(w.result) }() if err := w.synced.Close(); err != nil { return err } if err := w.waitBuildIndex(); err != nil { return err } if err := w.fr.Close(); err != nil { return err } if err := w.fw.Close(); err != nil { return err } if w.writer == nil || !w.writer.Finished() { return w.clean() } return w.save() }
[ "func", "(", "w", "*", "PackWriter", ")", "Close", "(", ")", "error", "{", "defer", "func", "(", ")", "{", "if", "w", ".", "Notify", "!=", "nil", "&&", "w", ".", "writer", "!=", "nil", "&&", "w", ".", "writer", ".", "Finished", "(", ")", "{", "w", ".", "Notify", "(", "w", ".", "checksum", ",", "w", ".", "writer", ")", "\n", "}", "\n\n", "close", "(", "w", ".", "result", ")", "\n", "}", "(", ")", "\n\n", "if", "err", ":=", "w", ".", "synced", ".", "Close", "(", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "if", "err", ":=", "w", ".", "waitBuildIndex", "(", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "if", "err", ":=", "w", ".", "fr", ".", "Close", "(", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "if", "err", ":=", "w", ".", "fw", ".", "Close", "(", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "if", "w", ".", "writer", "==", "nil", "||", "!", "w", ".", "writer", ".", "Finished", "(", ")", "{", "return", "w", ".", "clean", "(", ")", "\n", "}", "\n\n", "return", "w", ".", "save", "(", ")", "\n", "}" ]
// Close closes all the file descriptors and save the final packfile, if nothing // was written, the tempfiles are deleted without writing a packfile.
[ "Close", "closes", "all", "the", "file", "descriptors", "and", "save", "the", "final", "packfile", "if", "nothing", "was", "written", "the", "tempfiles", "are", "deleted", "without", "writing", "a", "packfile", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/storage/filesystem/dotgit/writers.go#L95-L125
train
src-d/go-git
plumbing/storer/reference.go
NewReferenceFilteredIter
func NewReferenceFilteredIter( ff func(r *plumbing.Reference) bool, iter ReferenceIter) ReferenceIter { return &referenceFilteredIter{ff, iter} }
go
func NewReferenceFilteredIter( ff func(r *plumbing.Reference) bool, iter ReferenceIter) ReferenceIter { return &referenceFilteredIter{ff, iter} }
[ "func", "NewReferenceFilteredIter", "(", "ff", "func", "(", "r", "*", "plumbing", ".", "Reference", ")", "bool", ",", "iter", "ReferenceIter", ")", "ReferenceIter", "{", "return", "&", "referenceFilteredIter", "{", "ff", ",", "iter", "}", "\n", "}" ]
// NewReferenceFilteredIter returns a reference iterator for the given reference // Iterator. This iterator will iterate only references that accomplish the // provided function.
[ "NewReferenceFilteredIter", "returns", "a", "reference", "iterator", "for", "the", "given", "reference", "Iterator", ".", "This", "iterator", "will", "iterate", "only", "references", "that", "accomplish", "the", "provided", "function", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/storer/reference.go#L46-L49
train
src-d/go-git
plumbing/storer/reference.go
ForEach
func (iter *referenceFilteredIter) ForEach(cb func(*plumbing.Reference) error) error { defer iter.Close() for { r, err := iter.Next() if err == io.EOF { break } if err != nil { return err } if err := cb(r); err != nil { if err == ErrStop { break } return err } } return nil }
go
func (iter *referenceFilteredIter) ForEach(cb func(*plumbing.Reference) error) error { defer iter.Close() for { r, err := iter.Next() if err == io.EOF { break } if err != nil { return err } if err := cb(r); err != nil { if err == ErrStop { break } return err } } return nil }
[ "func", "(", "iter", "*", "referenceFilteredIter", ")", "ForEach", "(", "cb", "func", "(", "*", "plumbing", ".", "Reference", ")", "error", ")", "error", "{", "defer", "iter", ".", "Close", "(", ")", "\n", "for", "{", "r", ",", "err", ":=", "iter", ".", "Next", "(", ")", "\n", "if", "err", "==", "io", ".", "EOF", "{", "break", "\n", "}", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "if", "err", ":=", "cb", "(", "r", ")", ";", "err", "!=", "nil", "{", "if", "err", "==", "ErrStop", "{", "break", "\n", "}", "\n\n", "return", "err", "\n", "}", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// ForEach call the cb function for each reference contained on this iter until // an error happens or the end of the iter is reached. If ErrStop is sent // the iteration is stopped but no error is returned. The iterator is closed.
[ "ForEach", "call", "the", "cb", "function", "for", "each", "reference", "contained", "on", "this", "iter", "until", "an", "error", "happens", "or", "the", "end", "of", "the", "iter", "is", "reached", ".", "If", "ErrStop", "is", "sent", "the", "iteration", "is", "stopped", "but", "no", "error", "is", "returned", ".", "The", "iterator", "is", "closed", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/storer/reference.go#L71-L92
train
src-d/go-git
plumbing/storer/reference.go
Next
func (iter *MultiReferenceIter) Next() (*plumbing.Reference, error) { if len(iter.iters) == 0 { return nil, io.EOF } obj, err := iter.iters[0].Next() if err == io.EOF { iter.iters[0].Close() iter.iters = iter.iters[1:] return iter.Next() } return obj, err }
go
func (iter *MultiReferenceIter) Next() (*plumbing.Reference, error) { if len(iter.iters) == 0 { return nil, io.EOF } obj, err := iter.iters[0].Next() if err == io.EOF { iter.iters[0].Close() iter.iters = iter.iters[1:] return iter.Next() } return obj, err }
[ "func", "(", "iter", "*", "MultiReferenceIter", ")", "Next", "(", ")", "(", "*", "plumbing", ".", "Reference", ",", "error", ")", "{", "if", "len", "(", "iter", ".", "iters", ")", "==", "0", "{", "return", "nil", ",", "io", ".", "EOF", "\n", "}", "\n\n", "obj", ",", "err", ":=", "iter", ".", "iters", "[", "0", "]", ".", "Next", "(", ")", "\n", "if", "err", "==", "io", ".", "EOF", "{", "iter", ".", "iters", "[", "0", "]", ".", "Close", "(", ")", "\n", "iter", ".", "iters", "=", "iter", ".", "iters", "[", "1", ":", "]", "\n", "return", "iter", ".", "Next", "(", ")", "\n", "}", "\n\n", "return", "obj", ",", "err", "\n", "}" ]
// Next returns the next reference from the iterator, if one iterator reach // io.EOF is removed and the next one is used.
[ "Next", "returns", "the", "next", "reference", "from", "the", "iterator", "if", "one", "iterator", "reach", "io", ".", "EOF", "is", "removed", "and", "the", "next", "one", "is", "used", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/storer/reference.go#L186-L199
train
src-d/go-git
plumbing/storer/reference.go
ResolveReference
func ResolveReference(s ReferenceStorer, n plumbing.ReferenceName) (*plumbing.Reference, error) { r, err := s.Reference(n) if err != nil || r == nil { return r, err } return resolveReference(s, r, 0) }
go
func ResolveReference(s ReferenceStorer, n plumbing.ReferenceName) (*plumbing.Reference, error) { r, err := s.Reference(n) if err != nil || r == nil { return r, err } return resolveReference(s, r, 0) }
[ "func", "ResolveReference", "(", "s", "ReferenceStorer", ",", "n", "plumbing", ".", "ReferenceName", ")", "(", "*", "plumbing", ".", "Reference", ",", "error", ")", "{", "r", ",", "err", ":=", "s", ".", "Reference", "(", "n", ")", "\n", "if", "err", "!=", "nil", "||", "r", "==", "nil", "{", "return", "r", ",", "err", "\n", "}", "\n", "return", "resolveReference", "(", "s", ",", "r", ",", "0", ")", "\n", "}" ]
// ResolveReference resolves a SymbolicReference to a HashReference.
[ "ResolveReference", "resolves", "a", "SymbolicReference", "to", "a", "HashReference", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/storer/reference.go#L216-L222
train
src-d/go-git
plumbing/protocol/packp/sideband/common.go
WithPayload
func (ch Channel) WithPayload(payload []byte) []byte { return append([]byte{byte(ch)}, payload...) }
go
func (ch Channel) WithPayload(payload []byte) []byte { return append([]byte{byte(ch)}, payload...) }
[ "func", "(", "ch", "Channel", ")", "WithPayload", "(", "payload", "[", "]", "byte", ")", "[", "]", "byte", "{", "return", "append", "(", "[", "]", "byte", "{", "byte", "(", "ch", ")", "}", ",", "payload", "...", ")", "\n", "}" ]
// WithPayload encode the payload as a message
[ "WithPayload", "encode", "the", "payload", "as", "a", "message" ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/protocol/packp/sideband/common.go#L22-L24
train
src-d/go-git
_examples/common.go
CheckArgs
func CheckArgs(arg ...string) { if len(os.Args) < len(arg)+1 { Warning("Usage: %s %s", os.Args[0], strings.Join(arg, " ")) os.Exit(1) } }
go
func CheckArgs(arg ...string) { if len(os.Args) < len(arg)+1 { Warning("Usage: %s %s", os.Args[0], strings.Join(arg, " ")) os.Exit(1) } }
[ "func", "CheckArgs", "(", "arg", "...", "string", ")", "{", "if", "len", "(", "os", ".", "Args", ")", "<", "len", "(", "arg", ")", "+", "1", "{", "Warning", "(", "\"", "\"", ",", "os", ".", "Args", "[", "0", "]", ",", "strings", ".", "Join", "(", "arg", ",", "\"", "\"", ")", ")", "\n", "os", ".", "Exit", "(", "1", ")", "\n", "}", "\n", "}" ]
// CheckArgs should be used to ensure the right command line arguments are // passed before executing an example.
[ "CheckArgs", "should", "be", "used", "to", "ensure", "the", "right", "command", "line", "arguments", "are", "passed", "before", "executing", "an", "example", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/_examples/common.go#L11-L16
train
src-d/go-git
_examples/common.go
CheckIfError
func CheckIfError(err error) { if err == nil { return } fmt.Printf("\x1b[31;1m%s\x1b[0m\n", fmt.Sprintf("error: %s", err)) os.Exit(1) }
go
func CheckIfError(err error) { if err == nil { return } fmt.Printf("\x1b[31;1m%s\x1b[0m\n", fmt.Sprintf("error: %s", err)) os.Exit(1) }
[ "func", "CheckIfError", "(", "err", "error", ")", "{", "if", "err", "==", "nil", "{", "return", "\n", "}", "\n\n", "fmt", ".", "Printf", "(", "\"", "\\x1b", "\\x1b", "\\n", "\"", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "err", ")", ")", "\n", "os", ".", "Exit", "(", "1", ")", "\n", "}" ]
// CheckIfError should be used to naively panics if an error is not nil.
[ "CheckIfError", "should", "be", "used", "to", "naively", "panics", "if", "an", "error", "is", "not", "nil", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/_examples/common.go#L19-L26
train
src-d/go-git
_examples/common.go
Warning
func Warning(format string, args ...interface{}) { fmt.Printf("\x1b[36;1m%s\x1b[0m\n", fmt.Sprintf(format, args...)) }
go
func Warning(format string, args ...interface{}) { fmt.Printf("\x1b[36;1m%s\x1b[0m\n", fmt.Sprintf(format, args...)) }
[ "func", "Warning", "(", "format", "string", ",", "args", "...", "interface", "{", "}", ")", "{", "fmt", ".", "Printf", "(", "\"", "\\x1b", "\\x1b", "\\n", "\"", ",", "fmt", ".", "Sprintf", "(", "format", ",", "args", "...", ")", ")", "\n", "}" ]
// Warning should be used to display a warning
[ "Warning", "should", "be", "used", "to", "display", "a", "warning" ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/_examples/common.go#L34-L36
train
src-d/go-git
plumbing/object/change_adaptor.go
newChange
func newChange(c merkletrie.Change) (*Change, error) { ret := &Change{} var err error if ret.From, err = newChangeEntry(c.From); err != nil { return nil, fmt.Errorf("From field: %s", err) } if ret.To, err = newChangeEntry(c.To); err != nil { return nil, fmt.Errorf("To field: %s", err) } return ret, nil }
go
func newChange(c merkletrie.Change) (*Change, error) { ret := &Change{} var err error if ret.From, err = newChangeEntry(c.From); err != nil { return nil, fmt.Errorf("From field: %s", err) } if ret.To, err = newChangeEntry(c.To); err != nil { return nil, fmt.Errorf("To field: %s", err) } return ret, nil }
[ "func", "newChange", "(", "c", "merkletrie", ".", "Change", ")", "(", "*", "Change", ",", "error", ")", "{", "ret", ":=", "&", "Change", "{", "}", "\n\n", "var", "err", "error", "\n", "if", "ret", ".", "From", ",", "err", "=", "newChangeEntry", "(", "c", ".", "From", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "if", "ret", ".", "To", ",", "err", "=", "newChangeEntry", "(", "c", ".", "To", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "return", "ret", ",", "nil", "\n", "}" ]
// The following functions transform changes types form the merkletrie // package to changes types from this package.
[ "The", "following", "functions", "transform", "changes", "types", "form", "the", "merkletrie", "package", "to", "changes", "types", "from", "this", "package", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/object/change_adaptor.go#L14-L27
train
src-d/go-git
plumbing/protocol/packp/ulreq_encode.go
Encode
func (u *UploadRequest) Encode(w io.Writer) error { e := newUlReqEncoder(w) return e.Encode(u) }
go
func (u *UploadRequest) Encode(w io.Writer) error { e := newUlReqEncoder(w) return e.Encode(u) }
[ "func", "(", "u", "*", "UploadRequest", ")", "Encode", "(", "w", "io", ".", "Writer", ")", "error", "{", "e", ":=", "newUlReqEncoder", "(", "w", ")", "\n", "return", "e", ".", "Encode", "(", "u", ")", "\n", "}" ]
// Encode writes the UlReq encoding of u to the stream. // // All the payloads will end with a newline character. Wants and // shallows are sorted alphabetically. A depth of 0 means no depth // request is sent.
[ "Encode", "writes", "the", "UlReq", "encoding", "of", "u", "to", "the", "stream", ".", "All", "the", "payloads", "will", "end", "with", "a", "newline", "character", ".", "Wants", "and", "shallows", "are", "sorted", "alphabetically", ".", "A", "depth", "of", "0", "means", "no", "depth", "request", "is", "sent", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/protocol/packp/ulreq_encode.go#L18-L21
train
src-d/go-git
_examples/open/main.go
main
func main() { CheckArgs("<path>") path := os.Args[1] // We instanciate a new repository targeting the given path (the .git folder) r, err := git.PlainOpen(path) CheckIfError(err) // Length of the HEAD history Info("git rev-list HEAD --count") // ... retrieving the HEAD reference ref, err := r.Head() CheckIfError(err) // ... retrieves the commit history cIter, err := r.Log(&git.LogOptions{From: ref.Hash()}) CheckIfError(err) // ... just iterates over the commits var cCount int err = cIter.ForEach(func(c *object.Commit) error { cCount++ return nil }) CheckIfError(err) fmt.Println(cCount) }
go
func main() { CheckArgs("<path>") path := os.Args[1] // We instanciate a new repository targeting the given path (the .git folder) r, err := git.PlainOpen(path) CheckIfError(err) // Length of the HEAD history Info("git rev-list HEAD --count") // ... retrieving the HEAD reference ref, err := r.Head() CheckIfError(err) // ... retrieves the commit history cIter, err := r.Log(&git.LogOptions{From: ref.Hash()}) CheckIfError(err) // ... just iterates over the commits var cCount int err = cIter.ForEach(func(c *object.Commit) error { cCount++ return nil }) CheckIfError(err) fmt.Println(cCount) }
[ "func", "main", "(", ")", "{", "CheckArgs", "(", "\"", "\"", ")", "\n", "path", ":=", "os", ".", "Args", "[", "1", "]", "\n\n", "// We instanciate a new repository targeting the given path (the .git folder)", "r", ",", "err", ":=", "git", ".", "PlainOpen", "(", "path", ")", "\n", "CheckIfError", "(", "err", ")", "\n\n", "// Length of the HEAD history", "Info", "(", "\"", "\"", ")", "\n\n", "// ... retrieving the HEAD reference", "ref", ",", "err", ":=", "r", ".", "Head", "(", ")", "\n", "CheckIfError", "(", "err", ")", "\n\n", "// ... retrieves the commit history", "cIter", ",", "err", ":=", "r", ".", "Log", "(", "&", "git", ".", "LogOptions", "{", "From", ":", "ref", ".", "Hash", "(", ")", "}", ")", "\n", "CheckIfError", "(", "err", ")", "\n\n", "// ... just iterates over the commits", "var", "cCount", "int", "\n", "err", "=", "cIter", ".", "ForEach", "(", "func", "(", "c", "*", "object", ".", "Commit", ")", "error", "{", "cCount", "++", "\n\n", "return", "nil", "\n", "}", ")", "\n", "CheckIfError", "(", "err", ")", "\n\n", "fmt", ".", "Println", "(", "cCount", ")", "\n", "}" ]
// Open an existing repository in a specific folder.
[ "Open", "an", "existing", "repository", "in", "a", "specific", "folder", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/_examples/open/main.go#L13-L42
train