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
plumbing/memory.go
Reader
func (o *MemoryObject) Reader() (io.ReadCloser, error) { return ioutil.NopCloser(bytes.NewBuffer(o.cont)), nil }
go
func (o *MemoryObject) Reader() (io.ReadCloser, error) { return ioutil.NopCloser(bytes.NewBuffer(o.cont)), nil }
[ "func", "(", "o", "*", "MemoryObject", ")", "Reader", "(", ")", "(", "io", ".", "ReadCloser", ",", "error", ")", "{", "return", "ioutil", ".", "NopCloser", "(", "bytes", ".", "NewBuffer", "(", "o", ".", "cont", ")", ")", ",", "nil", "\n", "}" ]
// Reader returns a ObjectReader used to read the object's content.
[ "Reader", "returns", "a", "ObjectReader", "used", "to", "read", "the", "object", "s", "content", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/memory.go#L43-L45
train
src-d/go-git
config/config.go
NewConfig
func NewConfig() *Config { config := &Config{ Remotes: make(map[string]*RemoteConfig), Submodules: make(map[string]*Submodule), Branches: make(map[string]*Branch), Raw: format.New(), } config.Pack.Window = DefaultPackWindow return config }
go
func NewConfig() *Config { config := &Config{ Remotes: make(map[string]*RemoteConfig), Submodules: make(map[string]*Submodule), Branches: make(map[string]*Branch), Raw: format.New(), } config.Pack.Window = DefaultPackWindow return config }
[ "func", "NewConfig", "(", ")", "*", "Config", "{", "config", ":=", "&", "Config", "{", "Remotes", ":", "make", "(", "map", "[", "string", "]", "*", "RemoteConfig", ")", ",", "Submodules", ":", "make", "(", "map", "[", "string", "]", "*", "Submodule", ")", ",", "Branches", ":", "make", "(", "map", "[", "string", "]", "*", "Branch", ")", ",", "Raw", ":", "format", ".", "New", "(", ")", ",", "}", "\n\n", "config", ".", "Pack", ".", "Window", "=", "DefaultPackWindow", "\n\n", "return", "config", "\n", "}" ]
// NewConfig returns a new empty Config.
[ "NewConfig", "returns", "a", "new", "empty", "Config", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/config/config.go#L72-L83
train
src-d/go-git
config/config.go
Marshal
func (c *Config) Marshal() ([]byte, error) { c.marshalCore() c.marshalPack() c.marshalRemotes() c.marshalSubmodules() c.marshalBranches() buf := bytes.NewBuffer(nil) if err := format.NewEncoder(buf).Encode(c.Raw); err != nil { return nil, err } return buf.Bytes(), nil }
go
func (c *Config) Marshal() ([]byte, error) { c.marshalCore() c.marshalPack() c.marshalRemotes() c.marshalSubmodules() c.marshalBranches() buf := bytes.NewBuffer(nil) if err := format.NewEncoder(buf).Encode(c.Raw); err != nil { return nil, err } return buf.Bytes(), nil }
[ "func", "(", "c", "*", "Config", ")", "Marshal", "(", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "c", ".", "marshalCore", "(", ")", "\n", "c", ".", "marshalPack", "(", ")", "\n", "c", ".", "marshalRemotes", "(", ")", "\n", "c", ".", "marshalSubmodules", "(", ")", "\n", "c", ".", "marshalBranches", "(", ")", "\n\n", "buf", ":=", "bytes", ".", "NewBuffer", "(", "nil", ")", "\n", "if", "err", ":=", "format", ".", "NewEncoder", "(", "buf", ")", ".", "Encode", "(", "c", ".", "Raw", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "buf", ".", "Bytes", "(", ")", ",", "nil", "\n", "}" ]
// Marshal returns Config encoded as a git-config file.
[ "Marshal", "returns", "Config", "encoded", "as", "a", "git", "-", "config", "file", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/config/config.go#L220-L233
train
src-d/go-git
_examples/checkout/main.go
main
func main() { CheckArgs("<url>", "<directory>", "<commit>") url, directory, commit := os.Args[1], os.Args[2], os.Args[3] // Clone the given repository to the given directory Info("git clone %s %s", url, directory) r, err := git.PlainClone(directory, false, &git.CloneOptions{ URL: url, }) CheckIfError(err) // ... retrieving the commit being pointed by HEAD Info("git show-ref --head HEAD") ref, err := r.Head() CheckIfError(err) fmt.Println(ref.Hash()) w, err := r.Worktree() CheckIfError(err) // ... checking out to commit Info("git checkout %s", commit) err = w.Checkout(&git.CheckoutOptions{ Hash: plumbing.NewHash(commit), }) CheckIfError(err) // ... retrieving the commit being pointed by HEAD, it shows that the // repository is pointing to the giving commit in detached mode Info("git show-ref --head HEAD") ref, err = r.Head() CheckIfError(err) fmt.Println(ref.Hash()) }
go
func main() { CheckArgs("<url>", "<directory>", "<commit>") url, directory, commit := os.Args[1], os.Args[2], os.Args[3] // Clone the given repository to the given directory Info("git clone %s %s", url, directory) r, err := git.PlainClone(directory, false, &git.CloneOptions{ URL: url, }) CheckIfError(err) // ... retrieving the commit being pointed by HEAD Info("git show-ref --head HEAD") ref, err := r.Head() CheckIfError(err) fmt.Println(ref.Hash()) w, err := r.Worktree() CheckIfError(err) // ... checking out to commit Info("git checkout %s", commit) err = w.Checkout(&git.CheckoutOptions{ Hash: plumbing.NewHash(commit), }) CheckIfError(err) // ... retrieving the commit being pointed by HEAD, it shows that the // repository is pointing to the giving commit in detached mode Info("git show-ref --head HEAD") ref, err = r.Head() CheckIfError(err) fmt.Println(ref.Hash()) }
[ "func", "main", "(", ")", "{", "CheckArgs", "(", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ")", "\n", "url", ",", "directory", ",", "commit", ":=", "os", ".", "Args", "[", "1", "]", ",", "os", ".", "Args", "[", "2", "]", ",", "os", ".", "Args", "[", "3", "]", "\n\n", "// Clone the given repository to the given directory", "Info", "(", "\"", "\"", ",", "url", ",", "directory", ")", "\n", "r", ",", "err", ":=", "git", ".", "PlainClone", "(", "directory", ",", "false", ",", "&", "git", ".", "CloneOptions", "{", "URL", ":", "url", ",", "}", ")", "\n\n", "CheckIfError", "(", "err", ")", "\n\n", "// ... retrieving the commit being pointed by HEAD", "Info", "(", "\"", "\"", ")", "\n", "ref", ",", "err", ":=", "r", ".", "Head", "(", ")", "\n", "CheckIfError", "(", "err", ")", "\n", "fmt", ".", "Println", "(", "ref", ".", "Hash", "(", ")", ")", "\n\n", "w", ",", "err", ":=", "r", ".", "Worktree", "(", ")", "\n", "CheckIfError", "(", "err", ")", "\n\n", "// ... checking out to commit", "Info", "(", "\"", "\"", ",", "commit", ")", "\n", "err", "=", "w", ".", "Checkout", "(", "&", "git", ".", "CheckoutOptions", "{", "Hash", ":", "plumbing", ".", "NewHash", "(", "commit", ")", ",", "}", ")", "\n", "CheckIfError", "(", "err", ")", "\n\n", "// ... retrieving the commit being pointed by HEAD, it shows that the", "// repository is pointing to the giving commit in detached mode", "Info", "(", "\"", "\"", ")", "\n", "ref", ",", "err", "=", "r", ".", "Head", "(", ")", "\n", "CheckIfError", "(", "err", ")", "\n", "fmt", ".", "Println", "(", "ref", ".", "Hash", "(", ")", ")", "\n", "}" ]
// Basic example of how to checkout a specific commit.
[ "Basic", "example", "of", "how", "to", "checkout", "a", "specific", "commit", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/_examples/checkout/main.go#L13-L47
train
src-d/go-git
plumbing/format/objfile/reader.go
NewReader
func NewReader(r io.Reader) (*Reader, error) { zlib, err := zlib.NewReader(r) if err != nil { return nil, packfile.ErrZLib.AddDetails(err.Error()) } return &Reader{ zlib: zlib, }, nil }
go
func NewReader(r io.Reader) (*Reader, error) { zlib, err := zlib.NewReader(r) if err != nil { return nil, packfile.ErrZLib.AddDetails(err.Error()) } return &Reader{ zlib: zlib, }, nil }
[ "func", "NewReader", "(", "r", "io", ".", "Reader", ")", "(", "*", "Reader", ",", "error", ")", "{", "zlib", ",", "err", ":=", "zlib", ".", "NewReader", "(", "r", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "packfile", ".", "ErrZLib", ".", "AddDetails", "(", "err", ".", "Error", "(", ")", ")", "\n", "}", "\n\n", "return", "&", "Reader", "{", "zlib", ":", "zlib", ",", "}", ",", "nil", "\n", "}" ]
// NewReader returns a new Reader reading from r.
[ "NewReader", "returns", "a", "new", "Reader", "reading", "from", "r", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/format/objfile/reader.go#L29-L38
train
src-d/go-git
plumbing/format/objfile/reader.go
Header
func (r *Reader) Header() (t plumbing.ObjectType, size int64, err error) { var raw []byte raw, err = r.readUntil(' ') if err != nil { return } t, err = plumbing.ParseObjectType(string(raw)) if err != nil { return } raw, err = r.readUntil(0) if err != nil { return } size, err = strconv.ParseInt(string(raw), 10, 64) if err != nil { err = ErrHeader return } defer r.prepareForRead(t, size) return }
go
func (r *Reader) Header() (t plumbing.ObjectType, size int64, err error) { var raw []byte raw, err = r.readUntil(' ') if err != nil { return } t, err = plumbing.ParseObjectType(string(raw)) if err != nil { return } raw, err = r.readUntil(0) if err != nil { return } size, err = strconv.ParseInt(string(raw), 10, 64) if err != nil { err = ErrHeader return } defer r.prepareForRead(t, size) return }
[ "func", "(", "r", "*", "Reader", ")", "Header", "(", ")", "(", "t", "plumbing", ".", "ObjectType", ",", "size", "int64", ",", "err", "error", ")", "{", "var", "raw", "[", "]", "byte", "\n", "raw", ",", "err", "=", "r", ".", "readUntil", "(", "' '", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\n", "}", "\n\n", "t", ",", "err", "=", "plumbing", ".", "ParseObjectType", "(", "string", "(", "raw", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\n", "}", "\n\n", "raw", ",", "err", "=", "r", ".", "readUntil", "(", "0", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\n", "}", "\n\n", "size", ",", "err", "=", "strconv", ".", "ParseInt", "(", "string", "(", "raw", ")", ",", "10", ",", "64", ")", "\n", "if", "err", "!=", "nil", "{", "err", "=", "ErrHeader", "\n", "return", "\n", "}", "\n\n", "defer", "r", ".", "prepareForRead", "(", "t", ",", "size", ")", "\n", "return", "\n", "}" ]
// Header reads the type and the size of object, and prepares the reader for read
[ "Header", "reads", "the", "type", "and", "the", "size", "of", "object", "and", "prepares", "the", "reader", "for", "read" ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/format/objfile/reader.go#L41-L66
train
src-d/go-git
plumbing/format/objfile/reader.go
readUntil
func (r *Reader) readUntil(delim byte) ([]byte, error) { var buf [1]byte value := make([]byte, 0, 16) for { if n, err := r.zlib.Read(buf[:]); err != nil && (err != io.EOF || n == 0) { if err == io.EOF { return nil, ErrHeader } return nil, err } if buf[0] == delim { return value, nil } value = append(value, buf[0]) } }
go
func (r *Reader) readUntil(delim byte) ([]byte, error) { var buf [1]byte value := make([]byte, 0, 16) for { if n, err := r.zlib.Read(buf[:]); err != nil && (err != io.EOF || n == 0) { if err == io.EOF { return nil, ErrHeader } return nil, err } if buf[0] == delim { return value, nil } value = append(value, buf[0]) } }
[ "func", "(", "r", "*", "Reader", ")", "readUntil", "(", "delim", "byte", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "var", "buf", "[", "1", "]", "byte", "\n", "value", ":=", "make", "(", "[", "]", "byte", ",", "0", ",", "16", ")", "\n", "for", "{", "if", "n", ",", "err", ":=", "r", ".", "zlib", ".", "Read", "(", "buf", "[", ":", "]", ")", ";", "err", "!=", "nil", "&&", "(", "err", "!=", "io", ".", "EOF", "||", "n", "==", "0", ")", "{", "if", "err", "==", "io", ".", "EOF", "{", "return", "nil", ",", "ErrHeader", "\n", "}", "\n", "return", "nil", ",", "err", "\n", "}", "\n\n", "if", "buf", "[", "0", "]", "==", "delim", "{", "return", "value", ",", "nil", "\n", "}", "\n\n", "value", "=", "append", "(", "value", ",", "buf", "[", "0", "]", ")", "\n", "}", "\n", "}" ]
// readSlice reads one byte at a time from r until it encounters delim or an // error.
[ "readSlice", "reads", "one", "byte", "at", "a", "time", "from", "r", "until", "it", "encounters", "delim", "or", "an", "error", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/format/objfile/reader.go#L70-L87
train
src-d/go-git
plumbing/format/gitattributes/matcher.go
NewMatcher
func NewMatcher(stack []MatchAttribute) Matcher { m := &matcher{stack: stack} m.init() return m }
go
func NewMatcher(stack []MatchAttribute) Matcher { m := &matcher{stack: stack} m.init() return m }
[ "func", "NewMatcher", "(", "stack", "[", "]", "MatchAttribute", ")", "Matcher", "{", "m", ":=", "&", "matcher", "{", "stack", ":", "stack", "}", "\n", "m", ".", "init", "(", ")", "\n\n", "return", "m", "\n", "}" ]
// NewMatcher constructs a new matcher. Patterns must be given in the order of // increasing priority. That is the most generic settings files first, then the // content of the repo .gitattributes, then content of .gitattributes down the // path.
[ "NewMatcher", "constructs", "a", "new", "matcher", ".", "Patterns", "must", "be", "given", "in", "the", "order", "of", "increasing", "priority", ".", "That", "is", "the", "most", "generic", "settings", "files", "first", "then", "the", "content", "of", "the", "repo", ".", "gitattributes", "then", "content", "of", ".", "gitattributes", "down", "the", "path", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/format/gitattributes/matcher.go#L15-L20
train
src-d/go-git
plumbing/format/gitattributes/matcher.go
Match
func (m *matcher) Match(path []string, attributes []string) (results map[string]Attribute, matched bool) { results = make(map[string]Attribute, len(attributes)) n := len(m.stack) for i := n - 1; i >= 0; i-- { if len(attributes) > 0 && len(attributes) == len(results) { return } pattern := m.stack[i].Pattern if pattern == nil { continue } if match := pattern.Match(path); match { matched = true for _, attr := range m.stack[i].Attributes { if attr.IsSet() { m.expandMacro(attr.Name(), results) } results[attr.Name()] = attr } } } return }
go
func (m *matcher) Match(path []string, attributes []string) (results map[string]Attribute, matched bool) { results = make(map[string]Attribute, len(attributes)) n := len(m.stack) for i := n - 1; i >= 0; i-- { if len(attributes) > 0 && len(attributes) == len(results) { return } pattern := m.stack[i].Pattern if pattern == nil { continue } if match := pattern.Match(path); match { matched = true for _, attr := range m.stack[i].Attributes { if attr.IsSet() { m.expandMacro(attr.Name(), results) } results[attr.Name()] = attr } } } return }
[ "func", "(", "m", "*", "matcher", ")", "Match", "(", "path", "[", "]", "string", ",", "attributes", "[", "]", "string", ")", "(", "results", "map", "[", "string", "]", "Attribute", ",", "matched", "bool", ")", "{", "results", "=", "make", "(", "map", "[", "string", "]", "Attribute", ",", "len", "(", "attributes", ")", ")", "\n\n", "n", ":=", "len", "(", "m", ".", "stack", ")", "\n", "for", "i", ":=", "n", "-", "1", ";", "i", ">=", "0", ";", "i", "--", "{", "if", "len", "(", "attributes", ")", ">", "0", "&&", "len", "(", "attributes", ")", "==", "len", "(", "results", ")", "{", "return", "\n", "}", "\n\n", "pattern", ":=", "m", ".", "stack", "[", "i", "]", ".", "Pattern", "\n", "if", "pattern", "==", "nil", "{", "continue", "\n", "}", "\n\n", "if", "match", ":=", "pattern", ".", "Match", "(", "path", ")", ";", "match", "{", "matched", "=", "true", "\n", "for", "_", ",", "attr", ":=", "range", "m", ".", "stack", "[", "i", "]", ".", "Attributes", "{", "if", "attr", ".", "IsSet", "(", ")", "{", "m", ".", "expandMacro", "(", "attr", ".", "Name", "(", ")", ",", "results", ")", "\n", "}", "\n", "results", "[", "attr", ".", "Name", "(", ")", "]", "=", "attr", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "\n", "}" ]
// Match matches path against the patterns in gitattributes files and returns // the attributes associated with the path. // // Specific attributes can be specified otherwise all attributes are returned. // // Matched is true if any path was matched to a rule, even if the results map // is empty.
[ "Match", "matches", "path", "against", "the", "patterns", "in", "gitattributes", "files", "and", "returns", "the", "attributes", "associated", "with", "the", "path", ".", "Specific", "attributes", "can", "be", "specified", "otherwise", "all", "attributes", "are", "returned", ".", "Matched", "is", "true", "if", "any", "path", "was", "matched", "to", "a", "rule", "even", "if", "the", "results", "map", "is", "empty", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/format/gitattributes/matcher.go#L44-L69
train
src-d/go-git
plumbing/format/commitgraph/memory.go
GetIndexByHash
func (mi *MemoryIndex) GetIndexByHash(h plumbing.Hash) (int, error) { i, ok := mi.indexMap[h] if ok { return i, nil } return 0, plumbing.ErrObjectNotFound }
go
func (mi *MemoryIndex) GetIndexByHash(h plumbing.Hash) (int, error) { i, ok := mi.indexMap[h] if ok { return i, nil } return 0, plumbing.ErrObjectNotFound }
[ "func", "(", "mi", "*", "MemoryIndex", ")", "GetIndexByHash", "(", "h", "plumbing", ".", "Hash", ")", "(", "int", ",", "error", ")", "{", "i", ",", "ok", ":=", "mi", ".", "indexMap", "[", "h", "]", "\n", "if", "ok", "{", "return", "i", ",", "nil", "\n", "}", "\n", "return", "0", ",", "plumbing", ".", "ErrObjectNotFound", "\n", "}" ]
// GetIndexByHash gets the index in the commit graph from commit hash, if available
[ "GetIndexByHash", "gets", "the", "index", "in", "the", "commit", "graph", "from", "commit", "hash", "if", "available" ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/format/commitgraph/memory.go#L20-L27
train
src-d/go-git
plumbing/format/commitgraph/memory.go
GetCommitDataByIndex
func (mi *MemoryIndex) GetCommitDataByIndex(i int) (*CommitData, error) { if int(i) >= len(mi.commitData) { return nil, plumbing.ErrObjectNotFound } commitData := mi.commitData[i] // Map parent hashes to parent indexes if commitData.ParentIndexes == nil { parentIndexes := make([]int, len(commitData.ParentHashes)) for i, parentHash := range commitData.ParentHashes { var err error if parentIndexes[i], err = mi.GetIndexByHash(parentHash); err != nil { return nil, err } } commitData.ParentIndexes = parentIndexes } return commitData, nil }
go
func (mi *MemoryIndex) GetCommitDataByIndex(i int) (*CommitData, error) { if int(i) >= len(mi.commitData) { return nil, plumbing.ErrObjectNotFound } commitData := mi.commitData[i] // Map parent hashes to parent indexes if commitData.ParentIndexes == nil { parentIndexes := make([]int, len(commitData.ParentHashes)) for i, parentHash := range commitData.ParentHashes { var err error if parentIndexes[i], err = mi.GetIndexByHash(parentHash); err != nil { return nil, err } } commitData.ParentIndexes = parentIndexes } return commitData, nil }
[ "func", "(", "mi", "*", "MemoryIndex", ")", "GetCommitDataByIndex", "(", "i", "int", ")", "(", "*", "CommitData", ",", "error", ")", "{", "if", "int", "(", "i", ")", ">=", "len", "(", "mi", ".", "commitData", ")", "{", "return", "nil", ",", "plumbing", ".", "ErrObjectNotFound", "\n", "}", "\n", "commitData", ":=", "mi", ".", "commitData", "[", "i", "]", "\n", "// Map parent hashes to parent indexes\r", "if", "commitData", ".", "ParentIndexes", "==", "nil", "{", "parentIndexes", ":=", "make", "(", "[", "]", "int", ",", "len", "(", "commitData", ".", "ParentHashes", ")", ")", "\n", "for", "i", ",", "parentHash", ":=", "range", "commitData", ".", "ParentHashes", "{", "var", "err", "error", "\n", "if", "parentIndexes", "[", "i", "]", ",", "err", "=", "mi", ".", "GetIndexByHash", "(", "parentHash", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "}", "\n", "commitData", ".", "ParentIndexes", "=", "parentIndexes", "\n", "}", "\n", "return", "commitData", ",", "nil", "\n", "}" ]
// GetCommitDataByIndex gets the commit node from the commit graph using index // obtained from child node, if available
[ "GetCommitDataByIndex", "gets", "the", "commit", "node", "from", "the", "commit", "graph", "using", "index", "obtained", "from", "child", "node", "if", "available" ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/format/commitgraph/memory.go#L31-L51
train
src-d/go-git
plumbing/format/commitgraph/memory.go
Add
func (mi *MemoryIndex) Add(hash plumbing.Hash, commitData *CommitData) { // The parent indexes are calculated lazily in GetNodeByIndex // which allows adding nodes out of order as long as all parents // are eventually resolved commitData.ParentIndexes = nil mi.indexMap[hash] = len(mi.commitData) mi.commitData = append(mi.commitData, commitData) }
go
func (mi *MemoryIndex) Add(hash plumbing.Hash, commitData *CommitData) { // The parent indexes are calculated lazily in GetNodeByIndex // which allows adding nodes out of order as long as all parents // are eventually resolved commitData.ParentIndexes = nil mi.indexMap[hash] = len(mi.commitData) mi.commitData = append(mi.commitData, commitData) }
[ "func", "(", "mi", "*", "MemoryIndex", ")", "Add", "(", "hash", "plumbing", ".", "Hash", ",", "commitData", "*", "CommitData", ")", "{", "// The parent indexes are calculated lazily in GetNodeByIndex\r", "// which allows adding nodes out of order as long as all parents\r", "// are eventually resolved\r", "commitData", ".", "ParentIndexes", "=", "nil", "\n", "mi", ".", "indexMap", "[", "hash", "]", "=", "len", "(", "mi", ".", "commitData", ")", "\n", "mi", ".", "commitData", "=", "append", "(", "mi", ".", "commitData", ",", "commitData", ")", "\n", "}" ]
// Add adds new node to the memory index
[ "Add", "adds", "new", "node", "to", "the", "memory", "index" ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/format/commitgraph/memory.go#L63-L70
train
src-d/go-git
_examples/clone/main.go
main
func main() { CheckArgs("<url>", "<directory>") url := os.Args[1] directory := os.Args[2] // Clone the given repository to the given directory Info("git clone %s %s --recursive", url, directory) r, err := git.PlainClone(directory, false, &git.CloneOptions{ URL: url, RecurseSubmodules: git.DefaultSubmoduleRecursionDepth, }) CheckIfError(err) // ... retrieving the branch being pointed by HEAD ref, err := r.Head() CheckIfError(err) // ... retrieving the commit object commit, err := r.CommitObject(ref.Hash()) CheckIfError(err) fmt.Println(commit) }
go
func main() { CheckArgs("<url>", "<directory>") url := os.Args[1] directory := os.Args[2] // Clone the given repository to the given directory Info("git clone %s %s --recursive", url, directory) r, err := git.PlainClone(directory, false, &git.CloneOptions{ URL: url, RecurseSubmodules: git.DefaultSubmoduleRecursionDepth, }) CheckIfError(err) // ... retrieving the branch being pointed by HEAD ref, err := r.Head() CheckIfError(err) // ... retrieving the commit object commit, err := r.CommitObject(ref.Hash()) CheckIfError(err) fmt.Println(commit) }
[ "func", "main", "(", ")", "{", "CheckArgs", "(", "\"", "\"", ",", "\"", "\"", ")", "\n", "url", ":=", "os", ".", "Args", "[", "1", "]", "\n", "directory", ":=", "os", ".", "Args", "[", "2", "]", "\n\n", "// Clone the given repository to the given directory", "Info", "(", "\"", "\"", ",", "url", ",", "directory", ")", "\n\n", "r", ",", "err", ":=", "git", ".", "PlainClone", "(", "directory", ",", "false", ",", "&", "git", ".", "CloneOptions", "{", "URL", ":", "url", ",", "RecurseSubmodules", ":", "git", ".", "DefaultSubmoduleRecursionDepth", ",", "}", ")", "\n\n", "CheckIfError", "(", "err", ")", "\n\n", "// ... retrieving the branch being pointed by HEAD", "ref", ",", "err", ":=", "r", ".", "Head", "(", ")", "\n", "CheckIfError", "(", "err", ")", "\n", "// ... retrieving the commit object", "commit", ",", "err", ":=", "r", ".", "CommitObject", "(", "ref", ".", "Hash", "(", ")", ")", "\n", "CheckIfError", "(", "err", ")", "\n\n", "fmt", ".", "Println", "(", "commit", ")", "\n", "}" ]
// Basic example of how to clone a repository using clone options.
[ "Basic", "example", "of", "how", "to", "clone", "a", "repository", "using", "clone", "options", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/_examples/clone/main.go#L12-L35
train
src-d/go-git
plumbing/hash.go
ComputeHash
func ComputeHash(t ObjectType, content []byte) Hash { h := NewHasher(t, int64(len(content))) h.Write(content) return h.Sum() }
go
func ComputeHash(t ObjectType, content []byte) Hash { h := NewHasher(t, int64(len(content))) h.Write(content) return h.Sum() }
[ "func", "ComputeHash", "(", "t", "ObjectType", ",", "content", "[", "]", "byte", ")", "Hash", "{", "h", ":=", "NewHasher", "(", "t", ",", "int64", "(", "len", "(", "content", ")", ")", ")", "\n", "h", ".", "Write", "(", "content", ")", "\n", "return", "h", ".", "Sum", "(", ")", "\n", "}" ]
// ComputeHash compute the hash for a given ObjectType and content
[ "ComputeHash", "compute", "the", "hash", "for", "a", "given", "ObjectType", "and", "content" ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/hash.go#L19-L23
train
src-d/go-git
plumbing/hash.go
NewHash
func NewHash(s string) Hash { b, _ := hex.DecodeString(s) var h Hash copy(h[:], b) return h }
go
func NewHash(s string) Hash { b, _ := hex.DecodeString(s) var h Hash copy(h[:], b) return h }
[ "func", "NewHash", "(", "s", "string", ")", "Hash", "{", "b", ",", "_", ":=", "hex", ".", "DecodeString", "(", "s", ")", "\n\n", "var", "h", "Hash", "\n", "copy", "(", "h", "[", ":", "]", ",", "b", ")", "\n\n", "return", "h", "\n", "}" ]
// NewHash return a new Hash from a hexadecimal hash representation
[ "NewHash", "return", "a", "new", "Hash", "from", "a", "hexadecimal", "hash", "representation" ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/hash.go#L26-L33
train
src-d/go-git
plumbing/transport/ssh/auth_method.go
NewPublicKeysFromFile
func NewPublicKeysFromFile(user, pemFile, password string) (*PublicKeys, error) { bytes, err := ioutil.ReadFile(pemFile) if err != nil { return nil, err } return NewPublicKeys(user, bytes, password) }
go
func NewPublicKeysFromFile(user, pemFile, password string) (*PublicKeys, error) { bytes, err := ioutil.ReadFile(pemFile) if err != nil { return nil, err } return NewPublicKeys(user, bytes, password) }
[ "func", "NewPublicKeysFromFile", "(", "user", ",", "pemFile", ",", "password", "string", ")", "(", "*", "PublicKeys", ",", "error", ")", "{", "bytes", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "pemFile", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "NewPublicKeys", "(", "user", ",", "bytes", ",", "password", ")", "\n", "}" ]
// NewPublicKeysFromFile returns a PublicKeys from a file containing a PEM // encoded private key. An encryption password should be given if the pemBytes // contains a password encrypted PEM block otherwise password should be empty.
[ "NewPublicKeysFromFile", "returns", "a", "PublicKeys", "from", "a", "file", "containing", "a", "PEM", "encoded", "private", "key", ".", "An", "encryption", "password", "should", "be", "given", "if", "the", "pemBytes", "contains", "a", "password", "encrypted", "PEM", "block", "otherwise", "password", "should", "be", "empty", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/transport/ssh/auth_method.go#L151-L158
train
src-d/go-git
plumbing/transport/ssh/auth_method.go
NewSSHAgentAuth
func NewSSHAgentAuth(u string) (*PublicKeysCallback, error) { var err error if u == "" { u, err = username() if err != nil { return nil, err } } a, _, err := sshagent.New() if err != nil { return nil, fmt.Errorf("error creating SSH agent: %q", err) } return &PublicKeysCallback{ User: u, Callback: a.Signers, }, nil }
go
func NewSSHAgentAuth(u string) (*PublicKeysCallback, error) { var err error if u == "" { u, err = username() if err != nil { return nil, err } } a, _, err := sshagent.New() if err != nil { return nil, fmt.Errorf("error creating SSH agent: %q", err) } return &PublicKeysCallback{ User: u, Callback: a.Signers, }, nil }
[ "func", "NewSSHAgentAuth", "(", "u", "string", ")", "(", "*", "PublicKeysCallback", ",", "error", ")", "{", "var", "err", "error", "\n", "if", "u", "==", "\"", "\"", "{", "u", ",", "err", "=", "username", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "}", "\n\n", "a", ",", "_", ",", "err", ":=", "sshagent", ".", "New", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "return", "&", "PublicKeysCallback", "{", "User", ":", "u", ",", "Callback", ":", "a", ".", "Signers", ",", "}", ",", "nil", "\n", "}" ]
// NewSSHAgentAuth returns a PublicKeysCallback based on a SSH agent, it opens // a pipe with the SSH agent and uses the pipe as the implementer of the public // key callback function.
[ "NewSSHAgentAuth", "returns", "a", "PublicKeysCallback", "based", "on", "a", "SSH", "agent", "it", "opens", "a", "pipe", "with", "the", "SSH", "agent", "and", "uses", "the", "pipe", "as", "the", "implementer", "of", "the", "public", "key", "callback", "function", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/transport/ssh/auth_method.go#L201-L219
train
src-d/go-git
plumbing/transport/ssh/auth_method.go
SetHostKeyCallback
func (m *HostKeyCallbackHelper) SetHostKeyCallback(cfg *ssh.ClientConfig) (*ssh.ClientConfig, error) { var err error if m.HostKeyCallback == nil { if m.HostKeyCallback, err = NewKnownHostsCallback(); err != nil { return cfg, err } } cfg.HostKeyCallback = m.HostKeyCallback return cfg, nil }
go
func (m *HostKeyCallbackHelper) SetHostKeyCallback(cfg *ssh.ClientConfig) (*ssh.ClientConfig, error) { var err error if m.HostKeyCallback == nil { if m.HostKeyCallback, err = NewKnownHostsCallback(); err != nil { return cfg, err } } cfg.HostKeyCallback = m.HostKeyCallback return cfg, nil }
[ "func", "(", "m", "*", "HostKeyCallbackHelper", ")", "SetHostKeyCallback", "(", "cfg", "*", "ssh", ".", "ClientConfig", ")", "(", "*", "ssh", ".", "ClientConfig", ",", "error", ")", "{", "var", "err", "error", "\n", "if", "m", ".", "HostKeyCallback", "==", "nil", "{", "if", "m", ".", "HostKeyCallback", ",", "err", "=", "NewKnownHostsCallback", "(", ")", ";", "err", "!=", "nil", "{", "return", "cfg", ",", "err", "\n", "}", "\n", "}", "\n\n", "cfg", ".", "HostKeyCallback", "=", "m", ".", "HostKeyCallback", "\n", "return", "cfg", ",", "nil", "\n", "}" ]
// SetHostKeyCallback sets the field HostKeyCallback in the given cfg. If // HostKeyCallback is empty a default callback is created using // NewKnownHostsCallback.
[ "SetHostKeyCallback", "sets", "the", "field", "HostKeyCallback", "in", "the", "given", "cfg", ".", "If", "HostKeyCallback", "is", "empty", "a", "default", "callback", "is", "created", "using", "NewKnownHostsCallback", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/transport/ssh/auth_method.go#L312-L322
train
src-d/go-git
utils/merkletrie/doubleiter.go
newDoubleIter
func newDoubleIter(from, to noder.Noder, hashEqual noder.Equal) ( *doubleIter, error) { var ii doubleIter var err error if ii.from.iter, err = NewIter(from); err != nil { return nil, fmt.Errorf("from: %s", err) } if ii.from.current, err = ii.from.iter.Next(); turnEOFIntoNil(err) != nil { return nil, fmt.Errorf("from: %s", err) } if ii.to.iter, err = NewIter(to); err != nil { return nil, fmt.Errorf("to: %s", err) } if ii.to.current, err = ii.to.iter.Next(); turnEOFIntoNil(err) != nil { return nil, fmt.Errorf("to: %s", err) } ii.hashEqual = hashEqual return &ii, nil }
go
func newDoubleIter(from, to noder.Noder, hashEqual noder.Equal) ( *doubleIter, error) { var ii doubleIter var err error if ii.from.iter, err = NewIter(from); err != nil { return nil, fmt.Errorf("from: %s", err) } if ii.from.current, err = ii.from.iter.Next(); turnEOFIntoNil(err) != nil { return nil, fmt.Errorf("from: %s", err) } if ii.to.iter, err = NewIter(to); err != nil { return nil, fmt.Errorf("to: %s", err) } if ii.to.current, err = ii.to.iter.Next(); turnEOFIntoNil(err) != nil { return nil, fmt.Errorf("to: %s", err) } ii.hashEqual = hashEqual return &ii, nil }
[ "func", "newDoubleIter", "(", "from", ",", "to", "noder", ".", "Noder", ",", "hashEqual", "noder", ".", "Equal", ")", "(", "*", "doubleIter", ",", "error", ")", "{", "var", "ii", "doubleIter", "\n", "var", "err", "error", "\n\n", "if", "ii", ".", "from", ".", "iter", ",", "err", "=", "NewIter", "(", "from", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "if", "ii", ".", "from", ".", "current", ",", "err", "=", "ii", ".", "from", ".", "iter", ".", "Next", "(", ")", ";", "turnEOFIntoNil", "(", "err", ")", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "if", "ii", ".", "to", ".", "iter", ",", "err", "=", "NewIter", "(", "to", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "if", "ii", ".", "to", ".", "current", ",", "err", "=", "ii", ".", "to", ".", "iter", ".", "Next", "(", ")", ";", "turnEOFIntoNil", "(", "err", ")", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "ii", ".", "hashEqual", "=", "hashEqual", "\n\n", "return", "&", "ii", ",", "nil", "\n", "}" ]
// NewdoubleIter returns a new doubleIter for the merkletries "from" and // "to". The hashEqual callback function will be used by the doubleIter // to compare the hash of the noders in the merkletries. The doubleIter // will be initialized to the first elements in each merkletrie if any.
[ "NewdoubleIter", "returns", "a", "new", "doubleIter", "for", "the", "merkletries", "from", "and", "to", ".", "The", "hashEqual", "callback", "function", "will", "be", "used", "by", "the", "doubleIter", "to", "compare", "the", "hash", "of", "the", "noders", "in", "the", "merkletries", ".", "The", "doubleIter", "will", "be", "initialized", "to", "the", "first", "elements", "in", "each", "merkletrie", "if", "any", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/utils/merkletrie/doubleiter.go#L38-L60
train
src-d/go-git
utils/merkletrie/doubleiter.go
nextBoth
func (d *doubleIter) nextBoth() error { if err := d.nextFrom(); err != nil { return err } if err := d.nextTo(); err != nil { return err } return nil }
go
func (d *doubleIter) nextBoth() error { if err := d.nextFrom(); err != nil { return err } if err := d.nextTo(); err != nil { return err } return nil }
[ "func", "(", "d", "*", "doubleIter", ")", "nextBoth", "(", ")", "error", "{", "if", "err", ":=", "d", ".", "nextFrom", "(", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "err", ":=", "d", ".", "nextTo", "(", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// NextBoth makes d advance to the next noder in both merkletries. If // any of them is a directory, it skips its contents.
[ "NextBoth", "makes", "d", "advance", "to", "the", "next", "noder", "in", "both", "merkletries", ".", "If", "any", "of", "them", "is", "a", "directory", "it", "skips", "its", "contents", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/utils/merkletrie/doubleiter.go#L71-L80
train
src-d/go-git
utils/merkletrie/doubleiter.go
nextFrom
func (d *doubleIter) nextFrom() (err error) { d.from.current, err = d.from.iter.Next() return turnEOFIntoNil(err) }
go
func (d *doubleIter) nextFrom() (err error) { d.from.current, err = d.from.iter.Next() return turnEOFIntoNil(err) }
[ "func", "(", "d", "*", "doubleIter", ")", "nextFrom", "(", ")", "(", "err", "error", ")", "{", "d", ".", "from", ".", "current", ",", "err", "=", "d", ".", "from", ".", "iter", ".", "Next", "(", ")", "\n", "return", "turnEOFIntoNil", "(", "err", ")", "\n", "}" ]
// NextFrom makes d advance to the next noder in the "from" merkletrie, // skipping its contents if it is a directory.
[ "NextFrom", "makes", "d", "advance", "to", "the", "next", "noder", "in", "the", "from", "merkletrie", "skipping", "its", "contents", "if", "it", "is", "a", "directory", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/utils/merkletrie/doubleiter.go#L84-L87
train
src-d/go-git
utils/merkletrie/doubleiter.go
nextTo
func (d *doubleIter) nextTo() (err error) { d.to.current, err = d.to.iter.Next() return turnEOFIntoNil(err) }
go
func (d *doubleIter) nextTo() (err error) { d.to.current, err = d.to.iter.Next() return turnEOFIntoNil(err) }
[ "func", "(", "d", "*", "doubleIter", ")", "nextTo", "(", ")", "(", "err", "error", ")", "{", "d", ".", "to", ".", "current", ",", "err", "=", "d", ".", "to", ".", "iter", ".", "Next", "(", ")", "\n", "return", "turnEOFIntoNil", "(", "err", ")", "\n", "}" ]
// NextTo makes d advance to the next noder in the "to" merkletrie, // skipping its contents if it is a directory.
[ "NextTo", "makes", "d", "advance", "to", "the", "next", "noder", "in", "the", "to", "merkletrie", "skipping", "its", "contents", "if", "it", "is", "a", "directory", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/utils/merkletrie/doubleiter.go#L91-L94
train
src-d/go-git
utils/merkletrie/doubleiter.go
stepBoth
func (d *doubleIter) stepBoth() (err error) { if d.from.current, err = d.from.iter.Step(); turnEOFIntoNil(err) != nil { return err } if d.to.current, err = d.to.iter.Step(); turnEOFIntoNil(err) != nil { return err } return nil }
go
func (d *doubleIter) stepBoth() (err error) { if d.from.current, err = d.from.iter.Step(); turnEOFIntoNil(err) != nil { return err } if d.to.current, err = d.to.iter.Step(); turnEOFIntoNil(err) != nil { return err } return nil }
[ "func", "(", "d", "*", "doubleIter", ")", "stepBoth", "(", ")", "(", "err", "error", ")", "{", "if", "d", ".", "from", ".", "current", ",", "err", "=", "d", ".", "from", ".", "iter", ".", "Step", "(", ")", ";", "turnEOFIntoNil", "(", "err", ")", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "d", ".", "to", ".", "current", ",", "err", "=", "d", ".", "to", ".", "iter", ".", "Step", "(", ")", ";", "turnEOFIntoNil", "(", "err", ")", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// StepBoth makes d advance to the next noder in both merkletries, // getting deeper into directories if that is the case.
[ "StepBoth", "makes", "d", "advance", "to", "the", "next", "noder", "in", "both", "merkletries", "getting", "deeper", "into", "directories", "if", "that", "is", "the", "case", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/utils/merkletrie/doubleiter.go#L98-L106
train
src-d/go-git
utils/merkletrie/doubleiter.go
remaining
func (d *doubleIter) remaining() remaining { if d.from.current == nil && d.to.current == nil { return noMoreNoders } if d.from.current == nil && d.to.current != nil { return onlyToRemains } if d.from.current != nil && d.to.current == nil { return onlyFromRemains } return bothHaveNodes }
go
func (d *doubleIter) remaining() remaining { if d.from.current == nil && d.to.current == nil { return noMoreNoders } if d.from.current == nil && d.to.current != nil { return onlyToRemains } if d.from.current != nil && d.to.current == nil { return onlyFromRemains } return bothHaveNodes }
[ "func", "(", "d", "*", "doubleIter", ")", "remaining", "(", ")", "remaining", "{", "if", "d", ".", "from", ".", "current", "==", "nil", "&&", "d", ".", "to", ".", "current", "==", "nil", "{", "return", "noMoreNoders", "\n", "}", "\n\n", "if", "d", ".", "from", ".", "current", "==", "nil", "&&", "d", ".", "to", ".", "current", "!=", "nil", "{", "return", "onlyToRemains", "\n", "}", "\n\n", "if", "d", ".", "from", ".", "current", "!=", "nil", "&&", "d", ".", "to", ".", "current", "==", "nil", "{", "return", "onlyFromRemains", "\n", "}", "\n\n", "return", "bothHaveNodes", "\n", "}" ]
// Remaining returns if there are no more noders in the tree, if both // have noders or if one of them doesn't.
[ "Remaining", "returns", "if", "there", "are", "no", "more", "noders", "in", "the", "tree", "if", "both", "have", "noders", "or", "if", "one", "of", "them", "doesn", "t", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/utils/merkletrie/doubleiter.go#L110-L124
train
src-d/go-git
utils/merkletrie/doubleiter.go
compare
func (d *doubleIter) compare() (s comparison, err error) { s.sameHash = d.hashEqual(d.from.current, d.to.current) fromIsDir := d.from.current.IsDir() toIsDir := d.to.current.IsDir() s.bothAreDirs = fromIsDir && toIsDir s.bothAreFiles = !fromIsDir && !toIsDir s.fileAndDir = !s.bothAreDirs && !s.bothAreFiles fromNumChildren, err := d.from.current.NumChildren() if err != nil { return comparison{}, fmt.Errorf("from: %s", err) } toNumChildren, err := d.to.current.NumChildren() if err != nil { return comparison{}, fmt.Errorf("to: %s", err) } s.fromIsEmptyDir = fromIsDir && fromNumChildren == 0 s.toIsEmptyDir = toIsDir && toNumChildren == 0 return }
go
func (d *doubleIter) compare() (s comparison, err error) { s.sameHash = d.hashEqual(d.from.current, d.to.current) fromIsDir := d.from.current.IsDir() toIsDir := d.to.current.IsDir() s.bothAreDirs = fromIsDir && toIsDir s.bothAreFiles = !fromIsDir && !toIsDir s.fileAndDir = !s.bothAreDirs && !s.bothAreFiles fromNumChildren, err := d.from.current.NumChildren() if err != nil { return comparison{}, fmt.Errorf("from: %s", err) } toNumChildren, err := d.to.current.NumChildren() if err != nil { return comparison{}, fmt.Errorf("to: %s", err) } s.fromIsEmptyDir = fromIsDir && fromNumChildren == 0 s.toIsEmptyDir = toIsDir && toNumChildren == 0 return }
[ "func", "(", "d", "*", "doubleIter", ")", "compare", "(", ")", "(", "s", "comparison", ",", "err", "error", ")", "{", "s", ".", "sameHash", "=", "d", ".", "hashEqual", "(", "d", ".", "from", ".", "current", ",", "d", ".", "to", ".", "current", ")", "\n\n", "fromIsDir", ":=", "d", ".", "from", ".", "current", ".", "IsDir", "(", ")", "\n", "toIsDir", ":=", "d", ".", "to", ".", "current", ".", "IsDir", "(", ")", "\n\n", "s", ".", "bothAreDirs", "=", "fromIsDir", "&&", "toIsDir", "\n", "s", ".", "bothAreFiles", "=", "!", "fromIsDir", "&&", "!", "toIsDir", "\n", "s", ".", "fileAndDir", "=", "!", "s", ".", "bothAreDirs", "&&", "!", "s", ".", "bothAreFiles", "\n\n", "fromNumChildren", ",", "err", ":=", "d", ".", "from", ".", "current", ".", "NumChildren", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "comparison", "{", "}", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "toNumChildren", ",", "err", ":=", "d", ".", "to", ".", "current", ".", "NumChildren", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "comparison", "{", "}", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "s", ".", "fromIsEmptyDir", "=", "fromIsDir", "&&", "fromNumChildren", "==", "0", "\n", "s", ".", "toIsEmptyDir", "=", "toIsDir", "&&", "toNumChildren", "==", "0", "\n\n", "return", "\n", "}" ]
// Compare returns the comparison between the current elements in the // merkletries.
[ "Compare", "returns", "the", "comparison", "between", "the", "current", "elements", "in", "the", "merkletries", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/utils/merkletrie/doubleiter.go#L139-L163
train
src-d/go-git
plumbing/protocol/packp/report_status.go
Error
func (s *ReportStatus) Error() error { if s.UnpackStatus != ok { return fmt.Errorf("unpack error: %s", s.UnpackStatus) } for _, s := range s.CommandStatuses { if err := s.Error(); err != nil { return err } } return nil }
go
func (s *ReportStatus) Error() error { if s.UnpackStatus != ok { return fmt.Errorf("unpack error: %s", s.UnpackStatus) } for _, s := range s.CommandStatuses { if err := s.Error(); err != nil { return err } } return nil }
[ "func", "(", "s", "*", "ReportStatus", ")", "Error", "(", ")", "error", "{", "if", "s", ".", "UnpackStatus", "!=", "ok", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "s", ".", "UnpackStatus", ")", "\n", "}", "\n\n", "for", "_", ",", "s", ":=", "range", "s", ".", "CommandStatuses", "{", "if", "err", ":=", "s", ".", "Error", "(", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Error returns the first error if any.
[ "Error", "returns", "the", "first", "error", "if", "any", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/protocol/packp/report_status.go#L30-L42
train
src-d/go-git
plumbing/protocol/packp/report_status.go
Encode
func (s *ReportStatus) Encode(w io.Writer) error { e := pktline.NewEncoder(w) if err := e.Encodef("unpack %s\n", s.UnpackStatus); err != nil { return err } for _, cs := range s.CommandStatuses { if err := cs.encode(w); err != nil { return err } } return e.Flush() }
go
func (s *ReportStatus) Encode(w io.Writer) error { e := pktline.NewEncoder(w) if err := e.Encodef("unpack %s\n", s.UnpackStatus); err != nil { return err } for _, cs := range s.CommandStatuses { if err := cs.encode(w); err != nil { return err } } return e.Flush() }
[ "func", "(", "s", "*", "ReportStatus", ")", "Encode", "(", "w", "io", ".", "Writer", ")", "error", "{", "e", ":=", "pktline", ".", "NewEncoder", "(", "w", ")", "\n", "if", "err", ":=", "e", ".", "Encodef", "(", "\"", "\\n", "\"", ",", "s", ".", "UnpackStatus", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "for", "_", ",", "cs", ":=", "range", "s", ".", "CommandStatuses", "{", "if", "err", ":=", "cs", ".", "encode", "(", "w", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n\n", "return", "e", ".", "Flush", "(", ")", "\n", "}" ]
// Encode writes the report status to a writer.
[ "Encode", "writes", "the", "report", "status", "to", "a", "writer", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/protocol/packp/report_status.go#L45-L58
train
src-d/go-git
plumbing/protocol/packp/report_status.go
Decode
func (s *ReportStatus) Decode(r io.Reader) error { scan := pktline.NewScanner(r) if err := s.scanFirstLine(scan); err != nil { return err } if err := s.decodeReportStatus(scan.Bytes()); err != nil { return err } flushed := false for scan.Scan() { b := scan.Bytes() if isFlush(b) { flushed = true break } if err := s.decodeCommandStatus(b); err != nil { return err } } if !flushed { return fmt.Errorf("missing flush") } return scan.Err() }
go
func (s *ReportStatus) Decode(r io.Reader) error { scan := pktline.NewScanner(r) if err := s.scanFirstLine(scan); err != nil { return err } if err := s.decodeReportStatus(scan.Bytes()); err != nil { return err } flushed := false for scan.Scan() { b := scan.Bytes() if isFlush(b) { flushed = true break } if err := s.decodeCommandStatus(b); err != nil { return err } } if !flushed { return fmt.Errorf("missing flush") } return scan.Err() }
[ "func", "(", "s", "*", "ReportStatus", ")", "Decode", "(", "r", "io", ".", "Reader", ")", "error", "{", "scan", ":=", "pktline", ".", "NewScanner", "(", "r", ")", "\n", "if", "err", ":=", "s", ".", "scanFirstLine", "(", "scan", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "if", "err", ":=", "s", ".", "decodeReportStatus", "(", "scan", ".", "Bytes", "(", ")", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "flushed", ":=", "false", "\n", "for", "scan", ".", "Scan", "(", ")", "{", "b", ":=", "scan", ".", "Bytes", "(", ")", "\n", "if", "isFlush", "(", "b", ")", "{", "flushed", "=", "true", "\n", "break", "\n", "}", "\n\n", "if", "err", ":=", "s", ".", "decodeCommandStatus", "(", "b", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n\n", "if", "!", "flushed", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "return", "scan", ".", "Err", "(", ")", "\n", "}" ]
// Decode reads from the given reader and decodes a report-status message. It // does not read more input than what is needed to fill the report status.
[ "Decode", "reads", "from", "the", "given", "reader", "and", "decodes", "a", "report", "-", "status", "message", ".", "It", "does", "not", "read", "more", "input", "than", "what", "is", "needed", "to", "fill", "the", "report", "status", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/protocol/packp/report_status.go#L62-L90
train
src-d/go-git
plumbing/protocol/packp/report_status.go
Error
func (s *CommandStatus) Error() error { if s.Status == ok { return nil } return fmt.Errorf("command error on %s: %s", s.ReferenceName.String(), s.Status) }
go
func (s *CommandStatus) Error() error { if s.Status == ok { return nil } return fmt.Errorf("command error on %s: %s", s.ReferenceName.String(), s.Status) }
[ "func", "(", "s", "*", "CommandStatus", ")", "Error", "(", ")", "error", "{", "if", "s", ".", "Status", "==", "ok", "{", "return", "nil", "\n", "}", "\n\n", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "s", ".", "ReferenceName", ".", "String", "(", ")", ",", "s", ".", "Status", ")", "\n", "}" ]
// Error returns the error, if any.
[ "Error", "returns", "the", "error", "if", "any", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/protocol/packp/report_status.go#L149-L156
train
src-d/go-git
plumbing/format/gitattributes/attributes.go
ReadAttributes
func ReadAttributes(r io.Reader, domain []string, allowMacro bool) (attributes []MatchAttribute, err error) { data, err := ioutil.ReadAll(r) if err != nil { return nil, err } for _, line := range strings.Split(string(data), eol) { attribute, err := ParseAttributesLine(line, domain, allowMacro) if err != nil { return attributes, err } if len(attribute.Name) == 0 { continue } attributes = append(attributes, attribute) } return attributes, nil }
go
func ReadAttributes(r io.Reader, domain []string, allowMacro bool) (attributes []MatchAttribute, err error) { data, err := ioutil.ReadAll(r) if err != nil { return nil, err } for _, line := range strings.Split(string(data), eol) { attribute, err := ParseAttributesLine(line, domain, allowMacro) if err != nil { return attributes, err } if len(attribute.Name) == 0 { continue } attributes = append(attributes, attribute) } return attributes, nil }
[ "func", "ReadAttributes", "(", "r", "io", ".", "Reader", ",", "domain", "[", "]", "string", ",", "allowMacro", "bool", ")", "(", "attributes", "[", "]", "MatchAttribute", ",", "err", "error", ")", "{", "data", ",", "err", ":=", "ioutil", ".", "ReadAll", "(", "r", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "for", "_", ",", "line", ":=", "range", "strings", ".", "Split", "(", "string", "(", "data", ")", ",", "eol", ")", "{", "attribute", ",", "err", ":=", "ParseAttributesLine", "(", "line", ",", "domain", ",", "allowMacro", ")", "\n", "if", "err", "!=", "nil", "{", "return", "attributes", ",", "err", "\n", "}", "\n", "if", "len", "(", "attribute", ".", "Name", ")", "==", "0", "{", "continue", "\n", "}", "\n\n", "attributes", "=", "append", "(", "attributes", ",", "attribute", ")", "\n", "}", "\n\n", "return", "attributes", ",", "nil", "\n", "}" ]
// ReadAttributes reads patterns and attributes from the gitattributes format.
[ "ReadAttributes", "reads", "patterns", "and", "attributes", "from", "the", "gitattributes", "format", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/format/gitattributes/attributes.go#L91-L110
train
src-d/go-git
plumbing/format/gitattributes/attributes.go
ParseAttributesLine
func ParseAttributesLine(line string, domain []string, allowMacro bool) (m MatchAttribute, err error) { line = strings.TrimSpace(line) if strings.HasPrefix(line, commentPrefix) || len(line) == 0 { return } name, unquoted := unquote(line) attrs := strings.Fields(unquoted) if len(name) == 0 { name = attrs[0] attrs = attrs[1:] } var macro bool macro, name, err = checkMacro(name, allowMacro) if err != nil { return } m.Name = name m.Attributes = make([]Attribute, 0, len(attrs)) for _, attrName := range attrs { attr := attribute{ name: attrName, state: attributeSet, } // ! and - prefixes state := attributeState(attr.name[0]) if state == attributeUnspecified || state == attributeUnset { attr.state = state attr.name = attr.name[1:] } kv := strings.SplitN(attrName, "=", 2) if len(kv) == 2 { attr.name = kv[0] attr.value = kv[1] attr.state = attributeSetValue } if !validAttributeName(attr.name) { return m, ErrInvalidAttributeName } m.Attributes = append(m.Attributes, attr) } if !macro { m.Pattern = ParsePattern(name, domain) } return }
go
func ParseAttributesLine(line string, domain []string, allowMacro bool) (m MatchAttribute, err error) { line = strings.TrimSpace(line) if strings.HasPrefix(line, commentPrefix) || len(line) == 0 { return } name, unquoted := unquote(line) attrs := strings.Fields(unquoted) if len(name) == 0 { name = attrs[0] attrs = attrs[1:] } var macro bool macro, name, err = checkMacro(name, allowMacro) if err != nil { return } m.Name = name m.Attributes = make([]Attribute, 0, len(attrs)) for _, attrName := range attrs { attr := attribute{ name: attrName, state: attributeSet, } // ! and - prefixes state := attributeState(attr.name[0]) if state == attributeUnspecified || state == attributeUnset { attr.state = state attr.name = attr.name[1:] } kv := strings.SplitN(attrName, "=", 2) if len(kv) == 2 { attr.name = kv[0] attr.value = kv[1] attr.state = attributeSetValue } if !validAttributeName(attr.name) { return m, ErrInvalidAttributeName } m.Attributes = append(m.Attributes, attr) } if !macro { m.Pattern = ParsePattern(name, domain) } return }
[ "func", "ParseAttributesLine", "(", "line", "string", ",", "domain", "[", "]", "string", ",", "allowMacro", "bool", ")", "(", "m", "MatchAttribute", ",", "err", "error", ")", "{", "line", "=", "strings", ".", "TrimSpace", "(", "line", ")", "\n\n", "if", "strings", ".", "HasPrefix", "(", "line", ",", "commentPrefix", ")", "||", "len", "(", "line", ")", "==", "0", "{", "return", "\n", "}", "\n\n", "name", ",", "unquoted", ":=", "unquote", "(", "line", ")", "\n", "attrs", ":=", "strings", ".", "Fields", "(", "unquoted", ")", "\n", "if", "len", "(", "name", ")", "==", "0", "{", "name", "=", "attrs", "[", "0", "]", "\n", "attrs", "=", "attrs", "[", "1", ":", "]", "\n", "}", "\n\n", "var", "macro", "bool", "\n", "macro", ",", "name", ",", "err", "=", "checkMacro", "(", "name", ",", "allowMacro", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\n", "}", "\n\n", "m", ".", "Name", "=", "name", "\n", "m", ".", "Attributes", "=", "make", "(", "[", "]", "Attribute", ",", "0", ",", "len", "(", "attrs", ")", ")", "\n\n", "for", "_", ",", "attrName", ":=", "range", "attrs", "{", "attr", ":=", "attribute", "{", "name", ":", "attrName", ",", "state", ":", "attributeSet", ",", "}", "\n\n", "// ! and - prefixes", "state", ":=", "attributeState", "(", "attr", ".", "name", "[", "0", "]", ")", "\n", "if", "state", "==", "attributeUnspecified", "||", "state", "==", "attributeUnset", "{", "attr", ".", "state", "=", "state", "\n", "attr", ".", "name", "=", "attr", ".", "name", "[", "1", ":", "]", "\n", "}", "\n\n", "kv", ":=", "strings", ".", "SplitN", "(", "attrName", ",", "\"", "\"", ",", "2", ")", "\n", "if", "len", "(", "kv", ")", "==", "2", "{", "attr", ".", "name", "=", "kv", "[", "0", "]", "\n", "attr", ".", "value", "=", "kv", "[", "1", "]", "\n", "attr", ".", "state", "=", "attributeSetValue", "\n", "}", "\n\n", "if", "!", "validAttributeName", "(", "attr", ".", "name", ")", "{", "return", "m", ",", "ErrInvalidAttributeName", "\n", "}", "\n", "m", ".", "Attributes", "=", "append", "(", "m", ".", "Attributes", ",", "attr", ")", "\n", "}", "\n\n", "if", "!", "macro", "{", "m", ".", "Pattern", "=", "ParsePattern", "(", "name", ",", "domain", ")", "\n", "}", "\n", "return", "\n", "}" ]
// ParseAttributesLine parses a gitattribute line, extracting path pattern and // attributes.
[ "ParseAttributesLine", "parses", "a", "gitattribute", "line", "extracting", "path", "pattern", "and", "attributes", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/format/gitattributes/attributes.go#L114-L167
train
src-d/go-git
_examples/pull/main.go
main
func main() { CheckArgs("<path>") path := os.Args[1] // We instance\iate a new repository targeting the given path (the .git folder) r, err := git.PlainOpen(path) CheckIfError(err) // Get the working directory for the repository w, err := r.Worktree() CheckIfError(err) // Pull the latest changes from the origin remote and merge into the current branch Info("git pull origin") err = w.Pull(&git.PullOptions{RemoteName: "origin"}) CheckIfError(err) // Print the latest commit that was just pulled ref, err := r.Head() CheckIfError(err) commit, err := r.CommitObject(ref.Hash()) CheckIfError(err) fmt.Println(commit) }
go
func main() { CheckArgs("<path>") path := os.Args[1] // We instance\iate a new repository targeting the given path (the .git folder) r, err := git.PlainOpen(path) CheckIfError(err) // Get the working directory for the repository w, err := r.Worktree() CheckIfError(err) // Pull the latest changes from the origin remote and merge into the current branch Info("git pull origin") err = w.Pull(&git.PullOptions{RemoteName: "origin"}) CheckIfError(err) // Print the latest commit that was just pulled ref, err := r.Head() CheckIfError(err) commit, err := r.CommitObject(ref.Hash()) CheckIfError(err) fmt.Println(commit) }
[ "func", "main", "(", ")", "{", "CheckArgs", "(", "\"", "\"", ")", "\n", "path", ":=", "os", ".", "Args", "[", "1", "]", "\n\n", "// We instance\\iate a new repository targeting the given path (the .git folder)", "r", ",", "err", ":=", "git", ".", "PlainOpen", "(", "path", ")", "\n", "CheckIfError", "(", "err", ")", "\n\n", "// Get the working directory for the repository", "w", ",", "err", ":=", "r", ".", "Worktree", "(", ")", "\n", "CheckIfError", "(", "err", ")", "\n\n", "// Pull the latest changes from the origin remote and merge into the current branch", "Info", "(", "\"", "\"", ")", "\n", "err", "=", "w", ".", "Pull", "(", "&", "git", ".", "PullOptions", "{", "RemoteName", ":", "\"", "\"", "}", ")", "\n", "CheckIfError", "(", "err", ")", "\n\n", "// Print the latest commit that was just pulled", "ref", ",", "err", ":=", "r", ".", "Head", "(", ")", "\n", "CheckIfError", "(", "err", ")", "\n", "commit", ",", "err", ":=", "r", ".", "CommitObject", "(", "ref", ".", "Hash", "(", ")", ")", "\n", "CheckIfError", "(", "err", ")", "\n\n", "fmt", ".", "Println", "(", "commit", ")", "\n", "}" ]
// Pull changes from a remote repository
[ "Pull", "changes", "from", "a", "remote", "repository" ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/_examples/pull/main.go#L12-L36
train
src-d/go-git
plumbing/transport/file/client.go
NewClient
func NewClient(uploadPackBin, receivePackBin string) transport.Transport { return common.NewClient(&runner{ UploadPackBin: uploadPackBin, ReceivePackBin: receivePackBin, }) }
go
func NewClient(uploadPackBin, receivePackBin string) transport.Transport { return common.NewClient(&runner{ UploadPackBin: uploadPackBin, ReceivePackBin: receivePackBin, }) }
[ "func", "NewClient", "(", "uploadPackBin", ",", "receivePackBin", "string", ")", "transport", ".", "Transport", "{", "return", "common", ".", "NewClient", "(", "&", "runner", "{", "UploadPackBin", ":", "uploadPackBin", ",", "ReceivePackBin", ":", "receivePackBin", ",", "}", ")", "\n", "}" ]
// NewClient returns a new local client using the given git-upload-pack and // git-receive-pack binaries.
[ "NewClient", "returns", "a", "new", "local", "client", "using", "the", "given", "git", "-", "upload", "-", "pack", "and", "git", "-", "receive", "-", "pack", "binaries", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/transport/file/client.go#L30-L35
train
src-d/go-git
plumbing/transport/file/client.go
Close
func (c *command) Close() error { if c.closed { return nil } defer func() { c.closed = true _ = c.stderrCloser.Close() }() err := c.cmd.Wait() if _, ok := err.(*os.PathError); ok { return nil } // When a repository does not exist, the command exits with code 128. if _, ok := err.(*exec.ExitError); ok { return nil } return err }
go
func (c *command) Close() error { if c.closed { return nil } defer func() { c.closed = true _ = c.stderrCloser.Close() }() err := c.cmd.Wait() if _, ok := err.(*os.PathError); ok { return nil } // When a repository does not exist, the command exits with code 128. if _, ok := err.(*exec.ExitError); ok { return nil } return err }
[ "func", "(", "c", "*", "command", ")", "Close", "(", ")", "error", "{", "if", "c", ".", "closed", "{", "return", "nil", "\n", "}", "\n\n", "defer", "func", "(", ")", "{", "c", ".", "closed", "=", "true", "\n", "_", "=", "c", ".", "stderrCloser", ".", "Close", "(", ")", "\n\n", "}", "(", ")", "\n\n", "err", ":=", "c", ".", "cmd", ".", "Wait", "(", ")", "\n", "if", "_", ",", "ok", ":=", "err", ".", "(", "*", "os", ".", "PathError", ")", ";", "ok", "{", "return", "nil", "\n", "}", "\n\n", "// When a repository does not exist, the command exits with code 128.", "if", "_", ",", "ok", ":=", "err", ".", "(", "*", "exec", ".", "ExitError", ")", ";", "ok", "{", "return", "nil", "\n", "}", "\n\n", "return", "err", "\n", "}" ]
// Close waits for the command to exit.
[ "Close", "waits", "for", "the", "command", "to", "exit", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/transport/file/client.go#L134-L156
train
src-d/go-git
_examples/progress/main.go
main
func main() { CheckArgs("<url>", "<directory>") url := os.Args[1] directory := os.Args[2] // Clone the given repository to the given directory Info("git clone %s %s", url, directory) _, err := git.PlainClone(directory, false, &git.CloneOptions{ URL: url, Depth: 1, // as git does, when you make a clone, pull or some other operations the // server sends information via the sideband, this information can being // collected provinding a io.Writer to the CloneOptions options Progress: os.Stdout, }) CheckIfError(err) }
go
func main() { CheckArgs("<url>", "<directory>") url := os.Args[1] directory := os.Args[2] // Clone the given repository to the given directory Info("git clone %s %s", url, directory) _, err := git.PlainClone(directory, false, &git.CloneOptions{ URL: url, Depth: 1, // as git does, when you make a clone, pull or some other operations the // server sends information via the sideband, this information can being // collected provinding a io.Writer to the CloneOptions options Progress: os.Stdout, }) CheckIfError(err) }
[ "func", "main", "(", ")", "{", "CheckArgs", "(", "\"", "\"", ",", "\"", "\"", ")", "\n", "url", ":=", "os", ".", "Args", "[", "1", "]", "\n", "directory", ":=", "os", ".", "Args", "[", "2", "]", "\n\n", "// Clone the given repository to the given directory", "Info", "(", "\"", "\"", ",", "url", ",", "directory", ")", "\n\n", "_", ",", "err", ":=", "git", ".", "PlainClone", "(", "directory", ",", "false", ",", "&", "git", ".", "CloneOptions", "{", "URL", ":", "url", ",", "Depth", ":", "1", ",", "// as git does, when you make a clone, pull or some other operations the", "// server sends information via the sideband, this information can being", "// collected provinding a io.Writer to the CloneOptions options", "Progress", ":", "os", ".", "Stdout", ",", "}", ")", "\n\n", "CheckIfError", "(", "err", ")", "\n", "}" ]
// Example of how to show the progress when you do a basic clone operation.
[ "Example", "of", "how", "to", "show", "the", "progress", "when", "you", "do", "a", "basic", "clone", "operation", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/_examples/progress/main.go#L11-L30
train
src-d/go-git
object_walker.go
walkObjectTree
func (p *objectWalker) walkObjectTree(hash plumbing.Hash) error { // Check if we have already seen, and mark this object if p.isSeen(hash) { return nil } p.add(hash) // Fetch the object. obj, err := object.GetObject(p.Storer, hash) if err != nil { return fmt.Errorf("Getting object %s failed: %v", hash, err) } // Walk all children depending on object type. switch obj := obj.(type) { case *object.Commit: err = p.walkObjectTree(obj.TreeHash) if err != nil { return err } for _, h := range obj.ParentHashes { err = p.walkObjectTree(h) if err != nil { return err } } case *object.Tree: for i := range obj.Entries { // Shortcut for blob objects: // 'or' the lower bits of a mode and check that it // it matches a filemode.Executable. The type information // is in the higher bits, but this is the cleanest way // to handle plain files with different modes. // Other non-tree objects are somewhat rare, so they // are not special-cased. if obj.Entries[i].Mode|0755 == filemode.Executable { p.add(obj.Entries[i].Hash) continue } // Normal walk for sub-trees (and symlinks etc). err = p.walkObjectTree(obj.Entries[i].Hash) if err != nil { return err } } case *object.Tag: return p.walkObjectTree(obj.Target) default: // Error out on unhandled object types. return fmt.Errorf("Unknown object %X %s %T\n", obj.ID(), obj.Type(), obj) } return nil }
go
func (p *objectWalker) walkObjectTree(hash plumbing.Hash) error { // Check if we have already seen, and mark this object if p.isSeen(hash) { return nil } p.add(hash) // Fetch the object. obj, err := object.GetObject(p.Storer, hash) if err != nil { return fmt.Errorf("Getting object %s failed: %v", hash, err) } // Walk all children depending on object type. switch obj := obj.(type) { case *object.Commit: err = p.walkObjectTree(obj.TreeHash) if err != nil { return err } for _, h := range obj.ParentHashes { err = p.walkObjectTree(h) if err != nil { return err } } case *object.Tree: for i := range obj.Entries { // Shortcut for blob objects: // 'or' the lower bits of a mode and check that it // it matches a filemode.Executable. The type information // is in the higher bits, but this is the cleanest way // to handle plain files with different modes. // Other non-tree objects are somewhat rare, so they // are not special-cased. if obj.Entries[i].Mode|0755 == filemode.Executable { p.add(obj.Entries[i].Hash) continue } // Normal walk for sub-trees (and symlinks etc). err = p.walkObjectTree(obj.Entries[i].Hash) if err != nil { return err } } case *object.Tag: return p.walkObjectTree(obj.Target) default: // Error out on unhandled object types. return fmt.Errorf("Unknown object %X %s %T\n", obj.ID(), obj.Type(), obj) } return nil }
[ "func", "(", "p", "*", "objectWalker", ")", "walkObjectTree", "(", "hash", "plumbing", ".", "Hash", ")", "error", "{", "// Check if we have already seen, and mark this object", "if", "p", ".", "isSeen", "(", "hash", ")", "{", "return", "nil", "\n", "}", "\n", "p", ".", "add", "(", "hash", ")", "\n", "// Fetch the object.", "obj", ",", "err", ":=", "object", ".", "GetObject", "(", "p", ".", "Storer", ",", "hash", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "hash", ",", "err", ")", "\n", "}", "\n", "// Walk all children depending on object type.", "switch", "obj", ":=", "obj", ".", "(", "type", ")", "{", "case", "*", "object", ".", "Commit", ":", "err", "=", "p", ".", "walkObjectTree", "(", "obj", ".", "TreeHash", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "for", "_", ",", "h", ":=", "range", "obj", ".", "ParentHashes", "{", "err", "=", "p", ".", "walkObjectTree", "(", "h", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "case", "*", "object", ".", "Tree", ":", "for", "i", ":=", "range", "obj", ".", "Entries", "{", "// Shortcut for blob objects:", "// 'or' the lower bits of a mode and check that it", "// it matches a filemode.Executable. The type information", "// is in the higher bits, but this is the cleanest way", "// to handle plain files with different modes.", "// Other non-tree objects are somewhat rare, so they", "// are not special-cased.", "if", "obj", ".", "Entries", "[", "i", "]", ".", "Mode", "|", "0755", "==", "filemode", ".", "Executable", "{", "p", ".", "add", "(", "obj", ".", "Entries", "[", "i", "]", ".", "Hash", ")", "\n", "continue", "\n", "}", "\n", "// Normal walk for sub-trees (and symlinks etc).", "err", "=", "p", ".", "walkObjectTree", "(", "obj", ".", "Entries", "[", "i", "]", ".", "Hash", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "case", "*", "object", ".", "Tag", ":", "return", "p", ".", "walkObjectTree", "(", "obj", ".", "Target", ")", "\n", "default", ":", "// Error out on unhandled object types.", "return", "fmt", ".", "Errorf", "(", "\"", "\\n", "\"", ",", "obj", ".", "ID", "(", ")", ",", "obj", ".", "Type", "(", ")", ",", "obj", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// walkObjectTree walks over all objects and remembers references // to them in the objectWalker. This is used instead of the revlist // walks because memory usage is tight with huge repos.
[ "walkObjectTree", "walks", "over", "all", "objects", "and", "remembers", "references", "to", "them", "in", "the", "objectWalker", ".", "This", "is", "used", "instead", "of", "the", "revlist", "walks", "because", "memory", "usage", "is", "tight", "with", "huge", "repos", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/object_walker.go#L54-L104
train
src-d/go-git
plumbing/object.go
ParseObjectType
func ParseObjectType(value string) (typ ObjectType, err error) { switch value { case "commit": typ = CommitObject case "tree": typ = TreeObject case "blob": typ = BlobObject case "tag": typ = TagObject case "ofs-delta": typ = OFSDeltaObject case "ref-delta": typ = REFDeltaObject default: err = ErrInvalidType } return }
go
func ParseObjectType(value string) (typ ObjectType, err error) { switch value { case "commit": typ = CommitObject case "tree": typ = TreeObject case "blob": typ = BlobObject case "tag": typ = TagObject case "ofs-delta": typ = OFSDeltaObject case "ref-delta": typ = REFDeltaObject default: err = ErrInvalidType } return }
[ "func", "ParseObjectType", "(", "value", "string", ")", "(", "typ", "ObjectType", ",", "err", "error", ")", "{", "switch", "value", "{", "case", "\"", "\"", ":", "typ", "=", "CommitObject", "\n", "case", "\"", "\"", ":", "typ", "=", "TreeObject", "\n", "case", "\"", "\"", ":", "typ", "=", "BlobObject", "\n", "case", "\"", "\"", ":", "typ", "=", "TagObject", "\n", "case", "\"", "\"", ":", "typ", "=", "OFSDeltaObject", "\n", "case", "\"", "\"", ":", "typ", "=", "REFDeltaObject", "\n", "default", ":", "err", "=", "ErrInvalidType", "\n", "}", "\n", "return", "\n", "}" ]
// ParseObjectType parses a string representation of ObjectType. It returns an // error on parse failure.
[ "ParseObjectType", "parses", "a", "string", "representation", "of", "ObjectType", ".", "It", "returns", "an", "error", "on", "parse", "failure", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/object.go#L93-L111
train
src-d/go-git
plumbing/format/packfile/patch_delta.go
ApplyDelta
func ApplyDelta(target, base plumbing.EncodedObject, delta []byte) error { r, err := base.Reader() if err != nil { return err } w, err := target.Writer() if err != nil { return err } src, err := ioutil.ReadAll(r) if err != nil { return err } dst, err := PatchDelta(src, delta) if err != nil { return err } target.SetSize(int64(len(dst))) _, err = w.Write(dst) return err }
go
func ApplyDelta(target, base plumbing.EncodedObject, delta []byte) error { r, err := base.Reader() if err != nil { return err } w, err := target.Writer() if err != nil { return err } src, err := ioutil.ReadAll(r) if err != nil { return err } dst, err := PatchDelta(src, delta) if err != nil { return err } target.SetSize(int64(len(dst))) _, err = w.Write(dst) return err }
[ "func", "ApplyDelta", "(", "target", ",", "base", "plumbing", ".", "EncodedObject", ",", "delta", "[", "]", "byte", ")", "error", "{", "r", ",", "err", ":=", "base", ".", "Reader", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "w", ",", "err", ":=", "target", ".", "Writer", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "src", ",", "err", ":=", "ioutil", ".", "ReadAll", "(", "r", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "dst", ",", "err", ":=", "PatchDelta", "(", "src", ",", "delta", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "target", ".", "SetSize", "(", "int64", "(", "len", "(", "dst", ")", ")", ")", "\n\n", "_", ",", "err", "=", "w", ".", "Write", "(", "dst", ")", "\n", "return", "err", "\n", "}" ]
// ApplyDelta writes to target the result of applying the modification deltas in delta to base.
[ "ApplyDelta", "writes", "to", "target", "the", "result", "of", "applying", "the", "modification", "deltas", "in", "delta", "to", "base", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/format/packfile/patch_delta.go#L18-L43
train
src-d/go-git
plumbing/format/packfile/patch_delta.go
decodeLEB128
func decodeLEB128(input []byte) (uint, []byte) { var num, sz uint var b byte for { b = input[sz] num |= (uint(b) & payload) << (sz * 7) // concats 7 bits chunks sz++ if uint(b)&continuation == 0 || sz == uint(len(input)) { break } } return num, input[sz:] }
go
func decodeLEB128(input []byte) (uint, []byte) { var num, sz uint var b byte for { b = input[sz] num |= (uint(b) & payload) << (sz * 7) // concats 7 bits chunks sz++ if uint(b)&continuation == 0 || sz == uint(len(input)) { break } } return num, input[sz:] }
[ "func", "decodeLEB128", "(", "input", "[", "]", "byte", ")", "(", "uint", ",", "[", "]", "byte", ")", "{", "var", "num", ",", "sz", "uint", "\n", "var", "b", "byte", "\n", "for", "{", "b", "=", "input", "[", "sz", "]", "\n", "num", "|=", "(", "uint", "(", "b", ")", "&", "payload", ")", "<<", "(", "sz", "*", "7", ")", "// concats 7 bits chunks", "\n", "sz", "++", "\n\n", "if", "uint", "(", "b", ")", "&", "continuation", "==", "0", "||", "sz", "==", "uint", "(", "len", "(", "input", ")", ")", "{", "break", "\n", "}", "\n", "}", "\n\n", "return", "num", ",", "input", "[", "sz", ":", "]", "\n", "}" ]
// Decodes a number encoded as an unsigned LEB128 at the start of some // binary data and returns the decoded number and the rest of the // stream. // // This must be called twice on the delta data buffer, first to get the // expected source buffer size, and again to get the target buffer size.
[ "Decodes", "a", "number", "encoded", "as", "an", "unsigned", "LEB128", "at", "the", "start", "of", "some", "binary", "data", "and", "returns", "the", "decoded", "number", "and", "the", "rest", "of", "the", "stream", ".", "This", "must", "be", "called", "twice", "on", "the", "delta", "data", "buffer", "first", "to", "get", "the", "expected", "source", "buffer", "size", "and", "again", "to", "get", "the", "target", "buffer", "size", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/format/packfile/patch_delta.go#L125-L139
train
src-d/go-git
plumbing/format/idxfile/writer.go
Index
func (w *Writer) Index() (*MemoryIndex, error) { w.m.Lock() defer w.m.Unlock() if w.index == nil { return w.createIndex() } return w.index, nil }
go
func (w *Writer) Index() (*MemoryIndex, error) { w.m.Lock() defer w.m.Unlock() if w.index == nil { return w.createIndex() } return w.index, nil }
[ "func", "(", "w", "*", "Writer", ")", "Index", "(", ")", "(", "*", "MemoryIndex", ",", "error", ")", "{", "w", ".", "m", ".", "Lock", "(", ")", "\n", "defer", "w", ".", "m", ".", "Unlock", "(", ")", "\n\n", "if", "w", ".", "index", "==", "nil", "{", "return", "w", ".", "createIndex", "(", ")", "\n", "}", "\n\n", "return", "w", ".", "index", ",", "nil", "\n", "}" ]
// Index returns a previously created MemoryIndex or creates a new one if // needed.
[ "Index", "returns", "a", "previously", "created", "MemoryIndex", "or", "creates", "a", "new", "one", "if", "needed", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/format/idxfile/writer.go#L33-L42
train
src-d/go-git
plumbing/format/idxfile/writer.go
Add
func (w *Writer) Add(h plumbing.Hash, pos uint64, crc uint32) { w.m.Lock() defer w.m.Unlock() if w.added == nil { w.added = make(map[plumbing.Hash]struct{}) } if _, ok := w.added[h]; !ok { w.added[h] = struct{}{} w.objects = append(w.objects, Entry{h, crc, pos}) } }
go
func (w *Writer) Add(h plumbing.Hash, pos uint64, crc uint32) { w.m.Lock() defer w.m.Unlock() if w.added == nil { w.added = make(map[plumbing.Hash]struct{}) } if _, ok := w.added[h]; !ok { w.added[h] = struct{}{} w.objects = append(w.objects, Entry{h, crc, pos}) } }
[ "func", "(", "w", "*", "Writer", ")", "Add", "(", "h", "plumbing", ".", "Hash", ",", "pos", "uint64", ",", "crc", "uint32", ")", "{", "w", ".", "m", ".", "Lock", "(", ")", "\n", "defer", "w", ".", "m", ".", "Unlock", "(", ")", "\n\n", "if", "w", ".", "added", "==", "nil", "{", "w", ".", "added", "=", "make", "(", "map", "[", "plumbing", ".", "Hash", "]", "struct", "{", "}", ")", "\n", "}", "\n\n", "if", "_", ",", "ok", ":=", "w", ".", "added", "[", "h", "]", ";", "!", "ok", "{", "w", ".", "added", "[", "h", "]", "=", "struct", "{", "}", "{", "}", "\n", "w", ".", "objects", "=", "append", "(", "w", ".", "objects", ",", "Entry", "{", "h", ",", "crc", ",", "pos", "}", ")", "\n", "}", "\n\n", "}" ]
// Add appends new object data.
[ "Add", "appends", "new", "object", "data", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/format/idxfile/writer.go#L45-L58
train
src-d/go-git
plumbing/format/idxfile/writer.go
OnHeader
func (w *Writer) OnHeader(count uint32) error { w.count = count w.objects = make(objects, 0, count) return nil }
go
func (w *Writer) OnHeader(count uint32) error { w.count = count w.objects = make(objects, 0, count) return nil }
[ "func", "(", "w", "*", "Writer", ")", "OnHeader", "(", "count", "uint32", ")", "error", "{", "w", ".", "count", "=", "count", "\n", "w", ".", "objects", "=", "make", "(", "objects", ",", "0", ",", "count", ")", "\n", "return", "nil", "\n", "}" ]
// OnHeader implements packfile.Observer interface.
[ "OnHeader", "implements", "packfile", ".", "Observer", "interface", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/format/idxfile/writer.go#L65-L69
train
src-d/go-git
plumbing/format/idxfile/writer.go
OnInflatedObjectHeader
func (w *Writer) OnInflatedObjectHeader(t plumbing.ObjectType, objSize int64, pos int64) error { return nil }
go
func (w *Writer) OnInflatedObjectHeader(t plumbing.ObjectType, objSize int64, pos int64) error { return nil }
[ "func", "(", "w", "*", "Writer", ")", "OnInflatedObjectHeader", "(", "t", "plumbing", ".", "ObjectType", ",", "objSize", "int64", ",", "pos", "int64", ")", "error", "{", "return", "nil", "\n", "}" ]
// OnInflatedObjectHeader implements packfile.Observer interface.
[ "OnInflatedObjectHeader", "implements", "packfile", ".", "Observer", "interface", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/format/idxfile/writer.go#L72-L74
train
src-d/go-git
plumbing/format/idxfile/writer.go
OnInflatedObjectContent
func (w *Writer) OnInflatedObjectContent(h plumbing.Hash, pos int64, crc uint32, _ []byte) error { w.Add(h, uint64(pos), crc) return nil }
go
func (w *Writer) OnInflatedObjectContent(h plumbing.Hash, pos int64, crc uint32, _ []byte) error { w.Add(h, uint64(pos), crc) return nil }
[ "func", "(", "w", "*", "Writer", ")", "OnInflatedObjectContent", "(", "h", "plumbing", ".", "Hash", ",", "pos", "int64", ",", "crc", "uint32", ",", "_", "[", "]", "byte", ")", "error", "{", "w", ".", "Add", "(", "h", ",", "uint64", "(", "pos", ")", ",", "crc", ")", "\n", "return", "nil", "\n", "}" ]
// OnInflatedObjectContent implements packfile.Observer interface.
[ "OnInflatedObjectContent", "implements", "packfile", ".", "Observer", "interface", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/format/idxfile/writer.go#L77-L80
train
src-d/go-git
plumbing/format/idxfile/writer.go
OnFooter
func (w *Writer) OnFooter(h plumbing.Hash) error { w.checksum = h w.finished = true _, err := w.createIndex() if err != nil { return err } return nil }
go
func (w *Writer) OnFooter(h plumbing.Hash) error { w.checksum = h w.finished = true _, err := w.createIndex() if err != nil { return err } return nil }
[ "func", "(", "w", "*", "Writer", ")", "OnFooter", "(", "h", "plumbing", ".", "Hash", ")", "error", "{", "w", ".", "checksum", "=", "h", "\n", "w", ".", "finished", "=", "true", "\n", "_", ",", "err", ":=", "w", ".", "createIndex", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// OnFooter implements packfile.Observer interface.
[ "OnFooter", "implements", "packfile", ".", "Observer", "interface", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/format/idxfile/writer.go#L83-L92
train
src-d/go-git
plumbing/format/idxfile/writer.go
createIndex
func (w *Writer) createIndex() (*MemoryIndex, error) { if !w.finished { return nil, fmt.Errorf("the index still hasn't finished building") } idx := new(MemoryIndex) w.index = idx sort.Sort(w.objects) // unmap all fans by default for i := range idx.FanoutMapping { idx.FanoutMapping[i] = noMapping } buf := new(bytes.Buffer) last := -1 bucket := -1 for i, o := range w.objects { fan := o.Hash[0] // fill the gaps between fans for j := last + 1; j < int(fan); j++ { idx.Fanout[j] = uint32(i) } // update the number of objects for this position idx.Fanout[fan] = uint32(i + 1) // we move from one bucket to another, update counters and allocate // memory if last != int(fan) { bucket++ idx.FanoutMapping[fan] = bucket last = int(fan) idx.Names = append(idx.Names, make([]byte, 0)) idx.Offset32 = append(idx.Offset32, make([]byte, 0)) idx.CRC32 = append(idx.CRC32, make([]byte, 0)) } idx.Names[bucket] = append(idx.Names[bucket], o.Hash[:]...) offset := o.Offset if offset > math.MaxInt32 { offset = w.addOffset64(offset) } buf.Truncate(0) binary.WriteUint32(buf, uint32(offset)) idx.Offset32[bucket] = append(idx.Offset32[bucket], buf.Bytes()...) buf.Truncate(0) binary.WriteUint32(buf, uint32(o.CRC32)) idx.CRC32[bucket] = append(idx.CRC32[bucket], buf.Bytes()...) } for j := last + 1; j < 256; j++ { idx.Fanout[j] = uint32(len(w.objects)) } idx.Version = VersionSupported idx.PackfileChecksum = w.checksum return idx, nil }
go
func (w *Writer) createIndex() (*MemoryIndex, error) { if !w.finished { return nil, fmt.Errorf("the index still hasn't finished building") } idx := new(MemoryIndex) w.index = idx sort.Sort(w.objects) // unmap all fans by default for i := range idx.FanoutMapping { idx.FanoutMapping[i] = noMapping } buf := new(bytes.Buffer) last := -1 bucket := -1 for i, o := range w.objects { fan := o.Hash[0] // fill the gaps between fans for j := last + 1; j < int(fan); j++ { idx.Fanout[j] = uint32(i) } // update the number of objects for this position idx.Fanout[fan] = uint32(i + 1) // we move from one bucket to another, update counters and allocate // memory if last != int(fan) { bucket++ idx.FanoutMapping[fan] = bucket last = int(fan) idx.Names = append(idx.Names, make([]byte, 0)) idx.Offset32 = append(idx.Offset32, make([]byte, 0)) idx.CRC32 = append(idx.CRC32, make([]byte, 0)) } idx.Names[bucket] = append(idx.Names[bucket], o.Hash[:]...) offset := o.Offset if offset > math.MaxInt32 { offset = w.addOffset64(offset) } buf.Truncate(0) binary.WriteUint32(buf, uint32(offset)) idx.Offset32[bucket] = append(idx.Offset32[bucket], buf.Bytes()...) buf.Truncate(0) binary.WriteUint32(buf, uint32(o.CRC32)) idx.CRC32[bucket] = append(idx.CRC32[bucket], buf.Bytes()...) } for j := last + 1; j < 256; j++ { idx.Fanout[j] = uint32(len(w.objects)) } idx.Version = VersionSupported idx.PackfileChecksum = w.checksum return idx, nil }
[ "func", "(", "w", "*", "Writer", ")", "createIndex", "(", ")", "(", "*", "MemoryIndex", ",", "error", ")", "{", "if", "!", "w", ".", "finished", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "idx", ":=", "new", "(", "MemoryIndex", ")", "\n", "w", ".", "index", "=", "idx", "\n\n", "sort", ".", "Sort", "(", "w", ".", "objects", ")", "\n\n", "// unmap all fans by default", "for", "i", ":=", "range", "idx", ".", "FanoutMapping", "{", "idx", ".", "FanoutMapping", "[", "i", "]", "=", "noMapping", "\n", "}", "\n\n", "buf", ":=", "new", "(", "bytes", ".", "Buffer", ")", "\n\n", "last", ":=", "-", "1", "\n", "bucket", ":=", "-", "1", "\n", "for", "i", ",", "o", ":=", "range", "w", ".", "objects", "{", "fan", ":=", "o", ".", "Hash", "[", "0", "]", "\n\n", "// fill the gaps between fans", "for", "j", ":=", "last", "+", "1", ";", "j", "<", "int", "(", "fan", ")", ";", "j", "++", "{", "idx", ".", "Fanout", "[", "j", "]", "=", "uint32", "(", "i", ")", "\n", "}", "\n\n", "// update the number of objects for this position", "idx", ".", "Fanout", "[", "fan", "]", "=", "uint32", "(", "i", "+", "1", ")", "\n\n", "// we move from one bucket to another, update counters and allocate", "// memory", "if", "last", "!=", "int", "(", "fan", ")", "{", "bucket", "++", "\n", "idx", ".", "FanoutMapping", "[", "fan", "]", "=", "bucket", "\n", "last", "=", "int", "(", "fan", ")", "\n\n", "idx", ".", "Names", "=", "append", "(", "idx", ".", "Names", ",", "make", "(", "[", "]", "byte", ",", "0", ")", ")", "\n", "idx", ".", "Offset32", "=", "append", "(", "idx", ".", "Offset32", ",", "make", "(", "[", "]", "byte", ",", "0", ")", ")", "\n", "idx", ".", "CRC32", "=", "append", "(", "idx", ".", "CRC32", ",", "make", "(", "[", "]", "byte", ",", "0", ")", ")", "\n", "}", "\n\n", "idx", ".", "Names", "[", "bucket", "]", "=", "append", "(", "idx", ".", "Names", "[", "bucket", "]", ",", "o", ".", "Hash", "[", ":", "]", "...", ")", "\n\n", "offset", ":=", "o", ".", "Offset", "\n", "if", "offset", ">", "math", ".", "MaxInt32", "{", "offset", "=", "w", ".", "addOffset64", "(", "offset", ")", "\n", "}", "\n\n", "buf", ".", "Truncate", "(", "0", ")", "\n", "binary", ".", "WriteUint32", "(", "buf", ",", "uint32", "(", "offset", ")", ")", "\n", "idx", ".", "Offset32", "[", "bucket", "]", "=", "append", "(", "idx", ".", "Offset32", "[", "bucket", "]", ",", "buf", ".", "Bytes", "(", ")", "...", ")", "\n\n", "buf", ".", "Truncate", "(", "0", ")", "\n", "binary", ".", "WriteUint32", "(", "buf", ",", "uint32", "(", "o", ".", "CRC32", ")", ")", "\n", "idx", ".", "CRC32", "[", "bucket", "]", "=", "append", "(", "idx", ".", "CRC32", "[", "bucket", "]", ",", "buf", ".", "Bytes", "(", ")", "...", ")", "\n", "}", "\n\n", "for", "j", ":=", "last", "+", "1", ";", "j", "<", "256", ";", "j", "++", "{", "idx", ".", "Fanout", "[", "j", "]", "=", "uint32", "(", "len", "(", "w", ".", "objects", ")", ")", "\n", "}", "\n\n", "idx", ".", "Version", "=", "VersionSupported", "\n", "idx", ".", "PackfileChecksum", "=", "w", ".", "checksum", "\n\n", "return", "idx", ",", "nil", "\n", "}" ]
// creatIndex returns a filled MemoryIndex with the information filled by // the observer callbacks.
[ "creatIndex", "returns", "a", "filled", "MemoryIndex", "with", "the", "information", "filled", "by", "the", "observer", "callbacks", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/format/idxfile/writer.go#L96-L162
train
src-d/go-git
plumbing/format/config/section.go
IsName
func (s *Section) IsName(name string) bool { return strings.ToLower(s.Name) == strings.ToLower(name) }
go
func (s *Section) IsName(name string) bool { return strings.ToLower(s.Name) == strings.ToLower(name) }
[ "func", "(", "s", "*", "Section", ")", "IsName", "(", "name", "string", ")", "bool", "{", "return", "strings", ".", "ToLower", "(", "s", ".", "Name", ")", "==", "strings", ".", "ToLower", "(", "name", ")", "\n", "}" ]
// IsName checks if the name provided is equals to the Section name, case insensitive.
[ "IsName", "checks", "if", "the", "name", "provided", "is", "equals", "to", "the", "Section", "name", "case", "insensitive", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/format/config/section.go#L63-L65
train
src-d/go-git
plumbing/format/config/section.go
Option
func (s *Section) Option(key string) string { return s.Options.Get(key) }
go
func (s *Section) Option(key string) string { return s.Options.Get(key) }
[ "func", "(", "s", "*", "Section", ")", "Option", "(", "key", "string", ")", "string", "{", "return", "s", ".", "Options", ".", "Get", "(", "key", ")", "\n", "}" ]
// Option return the value for the specified key. Empty string is returned if // key does not exists.
[ "Option", "return", "the", "value", "for", "the", "specified", "key", ".", "Empty", "string", "is", "returned", "if", "key", "does", "not", "exists", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/format/config/section.go#L69-L71
train
src-d/go-git
plumbing/format/config/section.go
AddOption
func (s *Section) AddOption(key string, value string) *Section { s.Options = s.Options.withAddedOption(key, value) return s }
go
func (s *Section) AddOption(key string, value string) *Section { s.Options = s.Options.withAddedOption(key, value) return s }
[ "func", "(", "s", "*", "Section", ")", "AddOption", "(", "key", "string", ",", "value", "string", ")", "*", "Section", "{", "s", ".", "Options", "=", "s", ".", "Options", ".", "withAddedOption", "(", "key", ",", "value", ")", "\n", "return", "s", "\n", "}" ]
// AddOption adds a new Option to the Section. The updated Section is returned.
[ "AddOption", "adds", "a", "new", "Option", "to", "the", "Section", ".", "The", "updated", "Section", "is", "returned", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/format/config/section.go#L74-L77
train
src-d/go-git
plumbing/format/config/section.go
SetOption
func (s *Section) SetOption(key string, value string) *Section { s.Options = s.Options.withSettedOption(key, value) return s }
go
func (s *Section) SetOption(key string, value string) *Section { s.Options = s.Options.withSettedOption(key, value) return s }
[ "func", "(", "s", "*", "Section", ")", "SetOption", "(", "key", "string", ",", "value", "string", ")", "*", "Section", "{", "s", ".", "Options", "=", "s", ".", "Options", ".", "withSettedOption", "(", "key", ",", "value", ")", "\n", "return", "s", "\n", "}" ]
// SetOption adds a new Option to the Section. If the option already exists, is replaced. // The updated Section is returned.
[ "SetOption", "adds", "a", "new", "Option", "to", "the", "Section", ".", "If", "the", "option", "already", "exists", "is", "replaced", ".", "The", "updated", "Section", "is", "returned", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/format/config/section.go#L81-L84
train
src-d/go-git
plumbing/format/config/section.go
RemoveOption
func (s *Section) RemoveOption(key string) *Section { s.Options = s.Options.withoutOption(key) return s }
go
func (s *Section) RemoveOption(key string) *Section { s.Options = s.Options.withoutOption(key) return s }
[ "func", "(", "s", "*", "Section", ")", "RemoveOption", "(", "key", "string", ")", "*", "Section", "{", "s", ".", "Options", "=", "s", ".", "Options", ".", "withoutOption", "(", "key", ")", "\n", "return", "s", "\n", "}" ]
// Remove an option with the specified key. The updated Section is returned.
[ "Remove", "an", "option", "with", "the", "specified", "key", ".", "The", "updated", "Section", "is", "returned", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/format/config/section.go#L87-L90
train
src-d/go-git
plumbing/format/config/section.go
Subsection
func (s *Section) Subsection(name string) *Subsection { for i := len(s.Subsections) - 1; i >= 0; i-- { ss := s.Subsections[i] if ss.IsName(name) { return ss } } ss := &Subsection{Name: name} s.Subsections = append(s.Subsections, ss) return ss }
go
func (s *Section) Subsection(name string) *Subsection { for i := len(s.Subsections) - 1; i >= 0; i-- { ss := s.Subsections[i] if ss.IsName(name) { return ss } } ss := &Subsection{Name: name} s.Subsections = append(s.Subsections, ss) return ss }
[ "func", "(", "s", "*", "Section", ")", "Subsection", "(", "name", "string", ")", "*", "Subsection", "{", "for", "i", ":=", "len", "(", "s", ".", "Subsections", ")", "-", "1", ";", "i", ">=", "0", ";", "i", "--", "{", "ss", ":=", "s", ".", "Subsections", "[", "i", "]", "\n", "if", "ss", ".", "IsName", "(", "name", ")", "{", "return", "ss", "\n", "}", "\n", "}", "\n\n", "ss", ":=", "&", "Subsection", "{", "Name", ":", "name", "}", "\n", "s", ".", "Subsections", "=", "append", "(", "s", ".", "Subsections", ",", "ss", ")", "\n", "return", "ss", "\n", "}" ]
// Subsection returns a Subsection from the specified Section. If the // Subsection does not exists, new one is created and added to Section.
[ "Subsection", "returns", "a", "Subsection", "from", "the", "specified", "Section", ".", "If", "the", "Subsection", "does", "not", "exists", "new", "one", "is", "created", "and", "added", "to", "Section", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/format/config/section.go#L94-L105
train
src-d/go-git
plumbing/format/config/section.go
HasSubsection
func (s *Section) HasSubsection(name string) bool { for _, ss := range s.Subsections { if ss.IsName(name) { return true } } return false }
go
func (s *Section) HasSubsection(name string) bool { for _, ss := range s.Subsections { if ss.IsName(name) { return true } } return false }
[ "func", "(", "s", "*", "Section", ")", "HasSubsection", "(", "name", "string", ")", "bool", "{", "for", "_", ",", "ss", ":=", "range", "s", ".", "Subsections", "{", "if", "ss", ".", "IsName", "(", "name", ")", "{", "return", "true", "\n", "}", "\n", "}", "\n\n", "return", "false", "\n", "}" ]
// HasSubsection checks if the Section has a Subsection with the specified name.
[ "HasSubsection", "checks", "if", "the", "Section", "has", "a", "Subsection", "with", "the", "specified", "name", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/format/config/section.go#L108-L116
train
src-d/go-git
plumbing/format/config/section.go
Option
func (s *Subsection) Option(key string) string { return s.Options.Get(key) }
go
func (s *Subsection) Option(key string) string { return s.Options.Get(key) }
[ "func", "(", "s", "*", "Subsection", ")", "Option", "(", "key", "string", ")", "string", "{", "return", "s", ".", "Options", ".", "Get", "(", "key", ")", "\n", "}" ]
// Option returns an option with the specified key. If the option does not exists, // empty spring will be returned.
[ "Option", "returns", "an", "option", "with", "the", "specified", "key", ".", "If", "the", "option", "does", "not", "exists", "empty", "spring", "will", "be", "returned", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/format/config/section.go#L125-L127
train
src-d/go-git
plumbing/format/config/section.go
AddOption
func (s *Subsection) AddOption(key string, value string) *Subsection { s.Options = s.Options.withAddedOption(key, value) return s }
go
func (s *Subsection) AddOption(key string, value string) *Subsection { s.Options = s.Options.withAddedOption(key, value) return s }
[ "func", "(", "s", "*", "Subsection", ")", "AddOption", "(", "key", "string", ",", "value", "string", ")", "*", "Subsection", "{", "s", ".", "Options", "=", "s", ".", "Options", ".", "withAddedOption", "(", "key", ",", "value", ")", "\n", "return", "s", "\n", "}" ]
// AddOption adds a new Option to the Subsection. The updated Subsection is returned.
[ "AddOption", "adds", "a", "new", "Option", "to", "the", "Subsection", ".", "The", "updated", "Subsection", "is", "returned", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/format/config/section.go#L130-L133
train
src-d/go-git
plumbing/format/config/section.go
SetOption
func (s *Subsection) SetOption(key string, value ...string) *Subsection { s.Options = s.Options.withSettedOption(key, value...) return s }
go
func (s *Subsection) SetOption(key string, value ...string) *Subsection { s.Options = s.Options.withSettedOption(key, value...) return s }
[ "func", "(", "s", "*", "Subsection", ")", "SetOption", "(", "key", "string", ",", "value", "...", "string", ")", "*", "Subsection", "{", "s", ".", "Options", "=", "s", ".", "Options", ".", "withSettedOption", "(", "key", ",", "value", "...", ")", "\n", "return", "s", "\n", "}" ]
// SetOption adds a new Option to the Subsection. If the option already exists, is replaced. // The updated Subsection is returned.
[ "SetOption", "adds", "a", "new", "Option", "to", "the", "Subsection", ".", "If", "the", "option", "already", "exists", "is", "replaced", ".", "The", "updated", "Subsection", "is", "returned", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/format/config/section.go#L137-L140
train
src-d/go-git
plumbing/format/config/section.go
RemoveOption
func (s *Subsection) RemoveOption(key string) *Subsection { s.Options = s.Options.withoutOption(key) return s }
go
func (s *Subsection) RemoveOption(key string) *Subsection { s.Options = s.Options.withoutOption(key) return s }
[ "func", "(", "s", "*", "Subsection", ")", "RemoveOption", "(", "key", "string", ")", "*", "Subsection", "{", "s", ".", "Options", "=", "s", ".", "Options", ".", "withoutOption", "(", "key", ")", "\n", "return", "s", "\n", "}" ]
// RemoveOption removes the option with the specified key. The updated Subsection is returned.
[ "RemoveOption", "removes", "the", "option", "with", "the", "specified", "key", ".", "The", "updated", "Subsection", "is", "returned", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/format/config/section.go#L143-L146
train
src-d/go-git
plumbing/format/index/index.go
Add
func (i *Index) Add(path string) *Entry { e := &Entry{ Name: filepath.ToSlash(path), } i.Entries = append(i.Entries, e) return e }
go
func (i *Index) Add(path string) *Entry { e := &Entry{ Name: filepath.ToSlash(path), } i.Entries = append(i.Entries, e) return e }
[ "func", "(", "i", "*", "Index", ")", "Add", "(", "path", "string", ")", "*", "Entry", "{", "e", ":=", "&", "Entry", "{", "Name", ":", "filepath", ".", "ToSlash", "(", "path", ")", ",", "}", "\n\n", "i", ".", "Entries", "=", "append", "(", "i", ".", "Entries", ",", "e", ")", "\n", "return", "e", "\n", "}" ]
// Add creates a new Entry and returns it. The caller should first check that // another entry with the same path does not exist.
[ "Add", "creates", "a", "new", "Entry", "and", "returns", "it", ".", "The", "caller", "should", "first", "check", "that", "another", "entry", "with", "the", "same", "path", "does", "not", "exist", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/format/index/index.go#L60-L67
train
src-d/go-git
plumbing/format/index/index.go
Entry
func (i *Index) Entry(path string) (*Entry, error) { path = filepath.ToSlash(path) for _, e := range i.Entries { if e.Name == path { return e, nil } } return nil, ErrEntryNotFound }
go
func (i *Index) Entry(path string) (*Entry, error) { path = filepath.ToSlash(path) for _, e := range i.Entries { if e.Name == path { return e, nil } } return nil, ErrEntryNotFound }
[ "func", "(", "i", "*", "Index", ")", "Entry", "(", "path", "string", ")", "(", "*", "Entry", ",", "error", ")", "{", "path", "=", "filepath", ".", "ToSlash", "(", "path", ")", "\n", "for", "_", ",", "e", ":=", "range", "i", ".", "Entries", "{", "if", "e", ".", "Name", "==", "path", "{", "return", "e", ",", "nil", "\n", "}", "\n", "}", "\n\n", "return", "nil", ",", "ErrEntryNotFound", "\n", "}" ]
// Entry returns the entry that match the given path, if any.
[ "Entry", "returns", "the", "entry", "that", "match", "the", "given", "path", "if", "any", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/format/index/index.go#L70-L79
train
src-d/go-git
plumbing/format/index/index.go
Remove
func (i *Index) Remove(path string) (*Entry, error) { path = filepath.ToSlash(path) for index, e := range i.Entries { if e.Name == path { i.Entries = append(i.Entries[:index], i.Entries[index+1:]...) return e, nil } } return nil, ErrEntryNotFound }
go
func (i *Index) Remove(path string) (*Entry, error) { path = filepath.ToSlash(path) for index, e := range i.Entries { if e.Name == path { i.Entries = append(i.Entries[:index], i.Entries[index+1:]...) return e, nil } } return nil, ErrEntryNotFound }
[ "func", "(", "i", "*", "Index", ")", "Remove", "(", "path", "string", ")", "(", "*", "Entry", ",", "error", ")", "{", "path", "=", "filepath", ".", "ToSlash", "(", "path", ")", "\n", "for", "index", ",", "e", ":=", "range", "i", ".", "Entries", "{", "if", "e", ".", "Name", "==", "path", "{", "i", ".", "Entries", "=", "append", "(", "i", ".", "Entries", "[", ":", "index", "]", ",", "i", ".", "Entries", "[", "index", "+", "1", ":", "]", "...", ")", "\n", "return", "e", ",", "nil", "\n", "}", "\n", "}", "\n\n", "return", "nil", ",", "ErrEntryNotFound", "\n", "}" ]
// Remove remove the entry that match the give path and returns deleted entry.
[ "Remove", "remove", "the", "entry", "that", "match", "the", "give", "path", "and", "returns", "deleted", "entry", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/format/index/index.go#L82-L92
train
src-d/go-git
plumbing/format/index/index.go
Glob
func (i *Index) Glob(pattern string) (matches []*Entry, err error) { pattern = filepath.ToSlash(pattern) for _, e := range i.Entries { m, err := match(pattern, e.Name) if err != nil { return nil, err } if m { matches = append(matches, e) } } return }
go
func (i *Index) Glob(pattern string) (matches []*Entry, err error) { pattern = filepath.ToSlash(pattern) for _, e := range i.Entries { m, err := match(pattern, e.Name) if err != nil { return nil, err } if m { matches = append(matches, e) } } return }
[ "func", "(", "i", "*", "Index", ")", "Glob", "(", "pattern", "string", ")", "(", "matches", "[", "]", "*", "Entry", ",", "err", "error", ")", "{", "pattern", "=", "filepath", ".", "ToSlash", "(", "pattern", ")", "\n", "for", "_", ",", "e", ":=", "range", "i", ".", "Entries", "{", "m", ",", "err", ":=", "match", "(", "pattern", ",", "e", ".", "Name", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "if", "m", "{", "matches", "=", "append", "(", "matches", ",", "e", ")", "\n", "}", "\n", "}", "\n\n", "return", "\n", "}" ]
// Glob returns the all entries matching pattern or nil if there is no matching // entry. The syntax of patterns is the same as in filepath.Glob.
[ "Glob", "returns", "the", "all", "entries", "matching", "pattern", "or", "nil", "if", "there", "is", "no", "matching", "entry", ".", "The", "syntax", "of", "patterns", "is", "the", "same", "as", "in", "filepath", ".", "Glob", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/format/index/index.go#L96-L110
train
src-d/go-git
utils/merkletrie/iter.go
current
func (iter *Iter) current() (noder.Path, error) { if topFrame, ok := iter.top(); !ok { return nil, io.EOF } else if _, ok := topFrame.First(); !ok { return nil, io.EOF } ret := make(noder.Path, 0, len(iter.base)+len(iter.frameStack)) // concat the base... ret = append(ret, iter.base...) // ... and the current node and all its ancestors for i, f := range iter.frameStack { t, ok := f.First() if !ok { panic(fmt.Sprintf("frame %d is empty", i)) } ret = append(ret, t) } return ret, nil }
go
func (iter *Iter) current() (noder.Path, error) { if topFrame, ok := iter.top(); !ok { return nil, io.EOF } else if _, ok := topFrame.First(); !ok { return nil, io.EOF } ret := make(noder.Path, 0, len(iter.base)+len(iter.frameStack)) // concat the base... ret = append(ret, iter.base...) // ... and the current node and all its ancestors for i, f := range iter.frameStack { t, ok := f.First() if !ok { panic(fmt.Sprintf("frame %d is empty", i)) } ret = append(ret, t) } return ret, nil }
[ "func", "(", "iter", "*", "Iter", ")", "current", "(", ")", "(", "noder", ".", "Path", ",", "error", ")", "{", "if", "topFrame", ",", "ok", ":=", "iter", ".", "top", "(", ")", ";", "!", "ok", "{", "return", "nil", ",", "io", ".", "EOF", "\n", "}", "else", "if", "_", ",", "ok", ":=", "topFrame", ".", "First", "(", ")", ";", "!", "ok", "{", "return", "nil", ",", "io", ".", "EOF", "\n", "}", "\n\n", "ret", ":=", "make", "(", "noder", ".", "Path", ",", "0", ",", "len", "(", "iter", ".", "base", ")", "+", "len", "(", "iter", ".", "frameStack", ")", ")", "\n\n", "// concat the base...", "ret", "=", "append", "(", "ret", ",", "iter", ".", "base", "...", ")", "\n", "// ... and the current node and all its ancestors", "for", "i", ",", "f", ":=", "range", "iter", ".", "frameStack", "{", "t", ",", "ok", ":=", "f", ".", "First", "(", ")", "\n", "if", "!", "ok", "{", "panic", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "i", ")", ")", "\n", "}", "\n", "ret", "=", "append", "(", "ret", ",", "t", ")", "\n", "}", "\n\n", "return", "ret", ",", "nil", "\n", "}" ]
// Returns the path to the current node, adding the base if there was // one, and a nil error. If there were no noders left, it returns nil // and io.EOF. If an error occurred, it returns nil and the error.
[ "Returns", "the", "path", "to", "the", "current", "node", "adding", "the", "base", "if", "there", "was", "one", "and", "a", "nil", "error", ".", "If", "there", "were", "no", "noders", "left", "it", "returns", "nil", "and", "io", ".", "EOF", ".", "If", "an", "error", "occurred", "it", "returns", "nil", "and", "the", "error", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/utils/merkletrie/iter.go#L177-L198
train
src-d/go-git
utils/merkletrie/iter.go
drop
func (iter *Iter) drop() { frame, ok := iter.top() if !ok { return } frame.Drop() // if the frame is empty, remove it and its parent, recursively if frame.Len() == 0 { top := len(iter.frameStack) - 1 iter.frameStack[top] = nil iter.frameStack = iter.frameStack[:top] iter.drop() } }
go
func (iter *Iter) drop() { frame, ok := iter.top() if !ok { return } frame.Drop() // if the frame is empty, remove it and its parent, recursively if frame.Len() == 0 { top := len(iter.frameStack) - 1 iter.frameStack[top] = nil iter.frameStack = iter.frameStack[:top] iter.drop() } }
[ "func", "(", "iter", "*", "Iter", ")", "drop", "(", ")", "{", "frame", ",", "ok", ":=", "iter", ".", "top", "(", ")", "\n", "if", "!", "ok", "{", "return", "\n", "}", "\n\n", "frame", ".", "Drop", "(", ")", "\n", "// if the frame is empty, remove it and its parent, recursively", "if", "frame", ".", "Len", "(", ")", "==", "0", "{", "top", ":=", "len", "(", "iter", ".", "frameStack", ")", "-", "1", "\n", "iter", ".", "frameStack", "[", "top", "]", "=", "nil", "\n", "iter", ".", "frameStack", "=", "iter", ".", "frameStack", "[", ":", "top", "]", "\n", "iter", ".", "drop", "(", ")", "\n", "}", "\n", "}" ]
// removes the current node if any, and all the frames that become empty as a // consequence of this action.
[ "removes", "the", "current", "node", "if", "any", "and", "all", "the", "frames", "that", "become", "empty", "as", "a", "consequence", "of", "this", "action", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/utils/merkletrie/iter.go#L202-L216
train
src-d/go-git
storage/transactional/index.go
NewIndexStorage
func NewIndexStorage(s, temporal storer.IndexStorer) *IndexStorage { return &IndexStorage{ IndexStorer: s, temporal: temporal, } }
go
func NewIndexStorage(s, temporal storer.IndexStorer) *IndexStorage { return &IndexStorage{ IndexStorer: s, temporal: temporal, } }
[ "func", "NewIndexStorage", "(", "s", ",", "temporal", "storer", ".", "IndexStorer", ")", "*", "IndexStorage", "{", "return", "&", "IndexStorage", "{", "IndexStorer", ":", "s", ",", "temporal", ":", "temporal", ",", "}", "\n", "}" ]
// NewIndexStorage returns a new IndexStorer based on a base storer and a // temporal storer.
[ "NewIndexStorage", "returns", "a", "new", "IndexStorer", "based", "on", "a", "base", "storer", "and", "a", "temporal", "storer", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/storage/transactional/index.go#L18-L23
train
src-d/go-git
storage/transactional/index.go
SetIndex
func (s *IndexStorage) SetIndex(idx *index.Index) (err error) { if err := s.temporal.SetIndex(idx); err != nil { return err } s.set = true return nil }
go
func (s *IndexStorage) SetIndex(idx *index.Index) (err error) { if err := s.temporal.SetIndex(idx); err != nil { return err } s.set = true return nil }
[ "func", "(", "s", "*", "IndexStorage", ")", "SetIndex", "(", "idx", "*", "index", ".", "Index", ")", "(", "err", "error", ")", "{", "if", "err", ":=", "s", ".", "temporal", ".", "SetIndex", "(", "idx", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "s", ".", "set", "=", "true", "\n", "return", "nil", "\n", "}" ]
// SetIndex honors the storer.IndexStorer interface.
[ "SetIndex", "honors", "the", "storer", ".", "IndexStorer", "interface", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/storage/transactional/index.go#L26-L33
train
src-d/go-git
storage/transactional/index.go
Index
func (s *IndexStorage) Index() (*index.Index, error) { if !s.set { return s.IndexStorer.Index() } return s.temporal.Index() }
go
func (s *IndexStorage) Index() (*index.Index, error) { if !s.set { return s.IndexStorer.Index() } return s.temporal.Index() }
[ "func", "(", "s", "*", "IndexStorage", ")", "Index", "(", ")", "(", "*", "index", ".", "Index", ",", "error", ")", "{", "if", "!", "s", ".", "set", "{", "return", "s", ".", "IndexStorer", ".", "Index", "(", ")", "\n", "}", "\n\n", "return", "s", ".", "temporal", ".", "Index", "(", ")", "\n", "}" ]
// Index honors the storer.IndexStorer interface.
[ "Index", "honors", "the", "storer", ".", "IndexStorer", "interface", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/storage/transactional/index.go#L36-L42
train
src-d/go-git
storage/transactional/index.go
Commit
func (s *IndexStorage) Commit() error { if !s.set { return nil } idx, err := s.temporal.Index() if err != nil { return err } return s.IndexStorer.SetIndex(idx) }
go
func (s *IndexStorage) Commit() error { if !s.set { return nil } idx, err := s.temporal.Index() if err != nil { return err } return s.IndexStorer.SetIndex(idx) }
[ "func", "(", "s", "*", "IndexStorage", ")", "Commit", "(", ")", "error", "{", "if", "!", "s", ".", "set", "{", "return", "nil", "\n", "}", "\n\n", "idx", ",", "err", ":=", "s", ".", "temporal", ".", "Index", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "s", ".", "IndexStorer", ".", "SetIndex", "(", "idx", ")", "\n", "}" ]
// Commit it copies the index from the temporal storage into the base storage.
[ "Commit", "it", "copies", "the", "index", "from", "the", "temporal", "storage", "into", "the", "base", "storage", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/storage/transactional/index.go#L45-L56
train
src-d/go-git
plumbing/transport/ssh/common.go
Close
func (c *command) Close() error { if !c.connected { return nil } c.connected = false //XXX: If did read the full packfile, then the session might be already // closed. _ = c.Session.Close() return c.client.Close() }
go
func (c *command) Close() error { if !c.connected { return nil } c.connected = false //XXX: If did read the full packfile, then the session might be already // closed. _ = c.Session.Close() return c.client.Close() }
[ "func", "(", "c", "*", "command", ")", "Close", "(", ")", "error", "{", "if", "!", "c", ".", "connected", "{", "return", "nil", "\n", "}", "\n\n", "c", ".", "connected", "=", "false", "\n\n", "//XXX: If did read the full packfile, then the session might be already", "// closed.", "_", "=", "c", ".", "Session", ".", "Close", "(", ")", "\n\n", "return", "c", ".", "client", ".", "Close", "(", ")", "\n", "}" ]
// Close closes the SSH session and connection.
[ "Close", "closes", "the", "SSH", "session", "and", "connection", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/transport/ssh/common.go#L83-L95
train
src-d/go-git
plumbing/transport/ssh/common.go
connect
func (c *command) connect() error { if c.connected { return transport.ErrAlreadyConnected } if c.auth == nil { if err := c.setAuthFromEndpoint(); err != nil { return err } } var err error config, err := c.auth.ClientConfig() if err != nil { return err } overrideConfig(c.config, config) c.client, err = dial("tcp", c.getHostWithPort(), config) if err != nil { return err } c.Session, err = c.client.NewSession() if err != nil { _ = c.client.Close() return err } c.connected = true return nil }
go
func (c *command) connect() error { if c.connected { return transport.ErrAlreadyConnected } if c.auth == nil { if err := c.setAuthFromEndpoint(); err != nil { return err } } var err error config, err := c.auth.ClientConfig() if err != nil { return err } overrideConfig(c.config, config) c.client, err = dial("tcp", c.getHostWithPort(), config) if err != nil { return err } c.Session, err = c.client.NewSession() if err != nil { _ = c.client.Close() return err } c.connected = true return nil }
[ "func", "(", "c", "*", "command", ")", "connect", "(", ")", "error", "{", "if", "c", ".", "connected", "{", "return", "transport", ".", "ErrAlreadyConnected", "\n", "}", "\n\n", "if", "c", ".", "auth", "==", "nil", "{", "if", "err", ":=", "c", ".", "setAuthFromEndpoint", "(", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n\n", "var", "err", "error", "\n", "config", ",", "err", ":=", "c", ".", "auth", ".", "ClientConfig", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "overrideConfig", "(", "c", ".", "config", ",", "config", ")", "\n\n", "c", ".", "client", ",", "err", "=", "dial", "(", "\"", "\"", ",", "c", ".", "getHostWithPort", "(", ")", ",", "config", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "c", ".", "Session", ",", "err", "=", "c", ".", "client", ".", "NewSession", "(", ")", "\n", "if", "err", "!=", "nil", "{", "_", "=", "c", ".", "client", ".", "Close", "(", ")", "\n", "return", "err", "\n", "}", "\n\n", "c", ".", "connected", "=", "true", "\n", "return", "nil", "\n", "}" ]
// connect connects to the SSH server, unless a AuthMethod was set with // SetAuth method, by default uses an auth method based on PublicKeysCallback, // it connects to a SSH agent, using the address stored in the SSH_AUTH_SOCK // environment var.
[ "connect", "connects", "to", "the", "SSH", "server", "unless", "a", "AuthMethod", "was", "set", "with", "SetAuth", "method", "by", "default", "uses", "an", "auth", "method", "based", "on", "PublicKeysCallback", "it", "connects", "to", "a", "SSH", "agent", "using", "the", "address", "stored", "in", "the", "SSH_AUTH_SOCK", "environment", "var", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/transport/ssh/common.go#L101-L133
train
src-d/go-git
utils/merkletrie/index/node.go
NewRootNode
func NewRootNode(idx *index.Index) noder.Noder { const rootNode = "" m := map[string]*node{rootNode: {isDir: true}} for _, e := range idx.Entries { parts := strings.Split(e.Name, string("/")) var fullpath string for _, part := range parts { parent := fullpath fullpath = path.Join(fullpath, part) if _, ok := m[fullpath]; ok { continue } n := &node{path: fullpath} if fullpath == e.Name { n.entry = e } else { n.isDir = true } m[n.path] = n m[parent].children = append(m[parent].children, n) } } return m[rootNode] }
go
func NewRootNode(idx *index.Index) noder.Noder { const rootNode = "" m := map[string]*node{rootNode: {isDir: true}} for _, e := range idx.Entries { parts := strings.Split(e.Name, string("/")) var fullpath string for _, part := range parts { parent := fullpath fullpath = path.Join(fullpath, part) if _, ok := m[fullpath]; ok { continue } n := &node{path: fullpath} if fullpath == e.Name { n.entry = e } else { n.isDir = true } m[n.path] = n m[parent].children = append(m[parent].children, n) } } return m[rootNode] }
[ "func", "NewRootNode", "(", "idx", "*", "index", ".", "Index", ")", "noder", ".", "Noder", "{", "const", "rootNode", "=", "\"", "\"", "\n\n", "m", ":=", "map", "[", "string", "]", "*", "node", "{", "rootNode", ":", "{", "isDir", ":", "true", "}", "}", "\n\n", "for", "_", ",", "e", ":=", "range", "idx", ".", "Entries", "{", "parts", ":=", "strings", ".", "Split", "(", "e", ".", "Name", ",", "string", "(", "\"", "\"", ")", ")", "\n\n", "var", "fullpath", "string", "\n", "for", "_", ",", "part", ":=", "range", "parts", "{", "parent", ":=", "fullpath", "\n", "fullpath", "=", "path", ".", "Join", "(", "fullpath", ",", "part", ")", "\n\n", "if", "_", ",", "ok", ":=", "m", "[", "fullpath", "]", ";", "ok", "{", "continue", "\n", "}", "\n\n", "n", ":=", "&", "node", "{", "path", ":", "fullpath", "}", "\n", "if", "fullpath", "==", "e", ".", "Name", "{", "n", ".", "entry", "=", "e", "\n", "}", "else", "{", "n", ".", "isDir", "=", "true", "\n", "}", "\n\n", "m", "[", "n", ".", "path", "]", "=", "n", "\n", "m", "[", "parent", "]", ".", "children", "=", "append", "(", "m", "[", "parent", "]", ".", "children", ",", "n", ")", "\n", "}", "\n", "}", "\n\n", "return", "m", "[", "rootNode", "]", "\n", "}" ]
// NewRootNode returns the root node of a computed tree from a index.Index,
[ "NewRootNode", "returns", "the", "root", "node", "of", "a", "computed", "tree", "from", "a", "index", ".", "Index" ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/utils/merkletrie/index/node.go#L25-L55
train
src-d/go-git
utils/merkletrie/index/node.go
Hash
func (n *node) Hash() []byte { if n.entry == nil { return make([]byte, 24) } return append(n.entry.Hash[:], n.entry.Mode.Bytes()...) }
go
func (n *node) Hash() []byte { if n.entry == nil { return make([]byte, 24) } return append(n.entry.Hash[:], n.entry.Mode.Bytes()...) }
[ "func", "(", "n", "*", "node", ")", "Hash", "(", ")", "[", "]", "byte", "{", "if", "n", ".", "entry", "==", "nil", "{", "return", "make", "(", "[", "]", "byte", ",", "24", ")", "\n", "}", "\n\n", "return", "append", "(", "n", ".", "entry", ".", "Hash", "[", ":", "]", ",", "n", ".", "entry", ".", "Mode", ".", "Bytes", "(", ")", "...", ")", "\n", "}" ]
// Hash the hash of a filesystem is a 24-byte slice, is the result of // concatenating the computed plumbing.Hash of the file as a Blob and its // plumbing.FileMode; that way the difftree algorithm will detect changes in the // contents of files and also in their mode. // // If the node is computed and not based on a index.Entry the hash is equals // to a 24-bytes slices of zero values.
[ "Hash", "the", "hash", "of", "a", "filesystem", "is", "a", "24", "-", "byte", "slice", "is", "the", "result", "of", "concatenating", "the", "computed", "plumbing", ".", "Hash", "of", "the", "file", "as", "a", "Blob", "and", "its", "plumbing", ".", "FileMode", ";", "that", "way", "the", "difftree", "algorithm", "will", "detect", "changes", "in", "the", "contents", "of", "files", "and", "also", "in", "their", "mode", ".", "If", "the", "node", "is", "computed", "and", "not", "based", "on", "a", "index", ".", "Entry", "the", "hash", "is", "equals", "to", "a", "24", "-", "bytes", "slices", "of", "zero", "values", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/utils/merkletrie/index/node.go#L68-L74
train
src-d/go-git
plumbing/format/packfile/error.go
Error
func (e *Error) Error() string { if e.details == "" { return e.reason } return fmt.Sprintf("%s: %s", e.reason, e.details) }
go
func (e *Error) Error() string { if e.details == "" { return e.reason } return fmt.Sprintf("%s: %s", e.reason, e.details) }
[ "func", "(", "e", "*", "Error", ")", "Error", "(", ")", "string", "{", "if", "e", ".", "details", "==", "\"", "\"", "{", "return", "e", ".", "reason", "\n", "}", "\n\n", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "e", ".", "reason", ",", "e", ".", "details", ")", "\n", "}" ]
// Error returns a text representation of the error.
[ "Error", "returns", "a", "text", "representation", "of", "the", "error", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/format/packfile/error.go#L16-L22
train
src-d/go-git
plumbing/format/packfile/error.go
AddDetails
func (e *Error) AddDetails(format string, args ...interface{}) *Error { return &Error{ reason: e.reason, details: fmt.Sprintf(format, args...), } }
go
func (e *Error) AddDetails(format string, args ...interface{}) *Error { return &Error{ reason: e.reason, details: fmt.Sprintf(format, args...), } }
[ "func", "(", "e", "*", "Error", ")", "AddDetails", "(", "format", "string", ",", "args", "...", "interface", "{", "}", ")", "*", "Error", "{", "return", "&", "Error", "{", "reason", ":", "e", ".", "reason", ",", "details", ":", "fmt", ".", "Sprintf", "(", "format", ",", "args", "...", ")", ",", "}", "\n", "}" ]
// AddDetails adds details to an error, with additional text.
[ "AddDetails", "adds", "details", "to", "an", "error", "with", "additional", "text", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/format/packfile/error.go#L25-L30
train
src-d/go-git
plumbing/format/packfile/common.go
UpdateObjectStorage
func UpdateObjectStorage(s storer.Storer, packfile io.Reader) error { if pw, ok := s.(storer.PackfileWriter); ok { return WritePackfileToObjectStorage(pw, packfile) } p, err := NewParserWithStorage(NewScanner(packfile), s) if err != nil { return err } _, err = p.Parse() return err }
go
func UpdateObjectStorage(s storer.Storer, packfile io.Reader) error { if pw, ok := s.(storer.PackfileWriter); ok { return WritePackfileToObjectStorage(pw, packfile) } p, err := NewParserWithStorage(NewScanner(packfile), s) if err != nil { return err } _, err = p.Parse() return err }
[ "func", "UpdateObjectStorage", "(", "s", "storer", ".", "Storer", ",", "packfile", "io", ".", "Reader", ")", "error", "{", "if", "pw", ",", "ok", ":=", "s", ".", "(", "storer", ".", "PackfileWriter", ")", ";", "ok", "{", "return", "WritePackfileToObjectStorage", "(", "pw", ",", "packfile", ")", "\n", "}", "\n\n", "p", ",", "err", ":=", "NewParserWithStorage", "(", "NewScanner", "(", "packfile", ")", ",", "s", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "_", ",", "err", "=", "p", ".", "Parse", "(", ")", "\n", "return", "err", "\n", "}" ]
// UpdateObjectStorage updates the storer with the objects in the given // packfile.
[ "UpdateObjectStorage", "updates", "the", "storer", "with", "the", "objects", "in", "the", "given", "packfile", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/format/packfile/common.go#L29-L41
train
src-d/go-git
plumbing/format/packfile/common.go
WritePackfileToObjectStorage
func WritePackfileToObjectStorage( sw storer.PackfileWriter, packfile io.Reader, ) (err error) { w, err := sw.PackfileWriter() if err != nil { return err } defer ioutil.CheckClose(w, &err) var n int64 n, err = io.Copy(w, packfile) if err == nil && n == 0 { return ErrEmptyPackfile } return err }
go
func WritePackfileToObjectStorage( sw storer.PackfileWriter, packfile io.Reader, ) (err error) { w, err := sw.PackfileWriter() if err != nil { return err } defer ioutil.CheckClose(w, &err) var n int64 n, err = io.Copy(w, packfile) if err == nil && n == 0 { return ErrEmptyPackfile } return err }
[ "func", "WritePackfileToObjectStorage", "(", "sw", "storer", ".", "PackfileWriter", ",", "packfile", "io", ".", "Reader", ",", ")", "(", "err", "error", ")", "{", "w", ",", "err", ":=", "sw", ".", "PackfileWriter", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "defer", "ioutil", ".", "CheckClose", "(", "w", ",", "&", "err", ")", "\n\n", "var", "n", "int64", "\n", "n", ",", "err", "=", "io", ".", "Copy", "(", "w", ",", "packfile", ")", "\n", "if", "err", "==", "nil", "&&", "n", "==", "0", "{", "return", "ErrEmptyPackfile", "\n", "}", "\n\n", "return", "err", "\n", "}" ]
// WritePackfileToObjectStorage writes all the packfile objects into the given // object storage.
[ "WritePackfileToObjectStorage", "writes", "all", "the", "packfile", "objects", "into", "the", "given", "object", "storage", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/format/packfile/common.go#L45-L63
train
src-d/go-git
plumbing/format/packfile/object_pack.go
newObjectToPack
func newObjectToPack(o plumbing.EncodedObject) *ObjectToPack { return &ObjectToPack{ Object: o, Original: o, } }
go
func newObjectToPack(o plumbing.EncodedObject) *ObjectToPack { return &ObjectToPack{ Object: o, Original: o, } }
[ "func", "newObjectToPack", "(", "o", "plumbing", ".", "EncodedObject", ")", "*", "ObjectToPack", "{", "return", "&", "ObjectToPack", "{", "Object", ":", "o", ",", "Original", ":", "o", ",", "}", "\n", "}" ]
// newObjectToPack creates a correct ObjectToPack based on a non-delta object
[ "newObjectToPack", "creates", "a", "correct", "ObjectToPack", "based", "on", "a", "non", "-", "delta", "object" ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/format/packfile/object_pack.go#L35-L40
train
src-d/go-git
plumbing/format/packfile/object_pack.go
BackToOriginal
func (o *ObjectToPack) BackToOriginal() { if o.IsDelta() && o.Original != nil { o.Object = o.Original o.Base = nil o.Depth = 0 } }
go
func (o *ObjectToPack) BackToOriginal() { if o.IsDelta() && o.Original != nil { o.Object = o.Original o.Base = nil o.Depth = 0 } }
[ "func", "(", "o", "*", "ObjectToPack", ")", "BackToOriginal", "(", ")", "{", "if", "o", ".", "IsDelta", "(", ")", "&&", "o", ".", "Original", "!=", "nil", "{", "o", ".", "Object", "=", "o", ".", "Original", "\n", "o", ".", "Base", "=", "nil", "\n", "o", ".", "Depth", "=", "0", "\n", "}", "\n", "}" ]
// BackToOriginal converts that ObjectToPack to a non-deltified object if it was one
[ "BackToOriginal", "converts", "that", "ObjectToPack", "to", "a", "non", "-", "deltified", "object", "if", "it", "was", "one" ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/format/packfile/object_pack.go#L55-L61
train
src-d/go-git
plumbing/format/packfile/object_pack.go
SetOriginal
func (o *ObjectToPack) SetOriginal(obj plumbing.EncodedObject) { o.Original = obj o.SaveOriginalMetadata() }
go
func (o *ObjectToPack) SetOriginal(obj plumbing.EncodedObject) { o.Original = obj o.SaveOriginalMetadata() }
[ "func", "(", "o", "*", "ObjectToPack", ")", "SetOriginal", "(", "obj", "plumbing", ".", "EncodedObject", ")", "{", "o", ".", "Original", "=", "obj", "\n", "o", ".", "SaveOriginalMetadata", "(", ")", "\n", "}" ]
// SetOriginal sets both Original and saves size, type and hash. If object // is nil Original is set but previous resolved values are kept
[ "SetOriginal", "sets", "both", "Original", "and", "saves", "size", "type", "and", "hash", ".", "If", "object", "is", "nil", "Original", "is", "set", "but", "previous", "resolved", "values", "are", "kept" ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/format/packfile/object_pack.go#L82-L85
train
src-d/go-git
plumbing/format/packfile/object_pack.go
SaveOriginalMetadata
func (o *ObjectToPack) SaveOriginalMetadata() { if o.Original != nil { o.originalSize = o.Original.Size() o.originalType = o.Original.Type() o.originalHash = o.Original.Hash() o.resolvedOriginal = true } }
go
func (o *ObjectToPack) SaveOriginalMetadata() { if o.Original != nil { o.originalSize = o.Original.Size() o.originalType = o.Original.Type() o.originalHash = o.Original.Hash() o.resolvedOriginal = true } }
[ "func", "(", "o", "*", "ObjectToPack", ")", "SaveOriginalMetadata", "(", ")", "{", "if", "o", ".", "Original", "!=", "nil", "{", "o", ".", "originalSize", "=", "o", ".", "Original", ".", "Size", "(", ")", "\n", "o", ".", "originalType", "=", "o", ".", "Original", ".", "Type", "(", ")", "\n", "o", ".", "originalHash", "=", "o", ".", "Original", ".", "Hash", "(", ")", "\n", "o", ".", "resolvedOriginal", "=", "true", "\n", "}", "\n", "}" ]
// SaveOriginalMetadata saves size, type and hash of Original object
[ "SaveOriginalMetadata", "saves", "size", "type", "and", "hash", "of", "Original", "object" ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/format/packfile/object_pack.go#L88-L95
train
src-d/go-git
plumbing/format/gitignore/pattern.go
ParsePattern
func ParsePattern(p string, domain []string) Pattern { res := pattern{domain: domain} if strings.HasPrefix(p, inclusionPrefix) { res.inclusion = true p = p[1:] } if !strings.HasSuffix(p, "\\ ") { p = strings.TrimRight(p, " ") } if strings.HasSuffix(p, patternDirSep) { res.dirOnly = true p = p[:len(p)-1] } if strings.Contains(p, patternDirSep) { res.isGlob = true } res.pattern = strings.Split(p, patternDirSep) return &res }
go
func ParsePattern(p string, domain []string) Pattern { res := pattern{domain: domain} if strings.HasPrefix(p, inclusionPrefix) { res.inclusion = true p = p[1:] } if !strings.HasSuffix(p, "\\ ") { p = strings.TrimRight(p, " ") } if strings.HasSuffix(p, patternDirSep) { res.dirOnly = true p = p[:len(p)-1] } if strings.Contains(p, patternDirSep) { res.isGlob = true } res.pattern = strings.Split(p, patternDirSep) return &res }
[ "func", "ParsePattern", "(", "p", "string", ",", "domain", "[", "]", "string", ")", "Pattern", "{", "res", ":=", "pattern", "{", "domain", ":", "domain", "}", "\n\n", "if", "strings", ".", "HasPrefix", "(", "p", ",", "inclusionPrefix", ")", "{", "res", ".", "inclusion", "=", "true", "\n", "p", "=", "p", "[", "1", ":", "]", "\n", "}", "\n\n", "if", "!", "strings", ".", "HasSuffix", "(", "p", ",", "\"", "\\\\", "\"", ")", "{", "p", "=", "strings", ".", "TrimRight", "(", "p", ",", "\"", "\"", ")", "\n", "}", "\n\n", "if", "strings", ".", "HasSuffix", "(", "p", ",", "patternDirSep", ")", "{", "res", ".", "dirOnly", "=", "true", "\n", "p", "=", "p", "[", ":", "len", "(", "p", ")", "-", "1", "]", "\n", "}", "\n\n", "if", "strings", ".", "Contains", "(", "p", ",", "patternDirSep", ")", "{", "res", ".", "isGlob", "=", "true", "\n", "}", "\n\n", "res", ".", "pattern", "=", "strings", ".", "Split", "(", "p", ",", "patternDirSep", ")", "\n", "return", "&", "res", "\n", "}" ]
// ParsePattern parses a gitignore pattern string into the Pattern structure.
[ "ParsePattern", "parses", "a", "gitignore", "pattern", "string", "into", "the", "Pattern", "structure", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/format/gitignore/pattern.go#L41-L64
train
src-d/go-git
plumbing/format/index/encoder.go
Encode
func (e *Encoder) Encode(idx *Index) error { // TODO: support versions v3 and v4 // TODO: support extensions if idx.Version != EncodeVersionSupported { return ErrUnsupportedVersion } if err := e.encodeHeader(idx); err != nil { return err } if err := e.encodeEntries(idx); err != nil { return err } return e.encodeFooter() }
go
func (e *Encoder) Encode(idx *Index) error { // TODO: support versions v3 and v4 // TODO: support extensions if idx.Version != EncodeVersionSupported { return ErrUnsupportedVersion } if err := e.encodeHeader(idx); err != nil { return err } if err := e.encodeEntries(idx); err != nil { return err } return e.encodeFooter() }
[ "func", "(", "e", "*", "Encoder", ")", "Encode", "(", "idx", "*", "Index", ")", "error", "{", "// TODO: support versions v3 and v4", "// TODO: support extensions", "if", "idx", ".", "Version", "!=", "EncodeVersionSupported", "{", "return", "ErrUnsupportedVersion", "\n", "}", "\n\n", "if", "err", ":=", "e", ".", "encodeHeader", "(", "idx", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "if", "err", ":=", "e", ".", "encodeEntries", "(", "idx", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "e", ".", "encodeFooter", "(", ")", "\n", "}" ]
// Encode writes the Index to the stream of the encoder.
[ "Encode", "writes", "the", "Index", "to", "the", "stream", "of", "the", "encoder", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/format/index/encoder.go#L38-L54
train
src-d/go-git
plumbing/format/index/match.go
scanChunk
func scanChunk(pattern string) (star bool, chunk, rest string) { for len(pattern) > 0 && pattern[0] == '*' { pattern = pattern[1:] star = true } inrange := false var i int Scan: for i = 0; i < len(pattern); i++ { switch pattern[i] { case '\\': if runtime.GOOS != "windows" { // error check handled in matchChunk: bad pattern. if i+1 < len(pattern) { i++ } } case '[': inrange = true case ']': inrange = false case '*': if !inrange { break Scan } } } return star, pattern[0:i], pattern[i:] }
go
func scanChunk(pattern string) (star bool, chunk, rest string) { for len(pattern) > 0 && pattern[0] == '*' { pattern = pattern[1:] star = true } inrange := false var i int Scan: for i = 0; i < len(pattern); i++ { switch pattern[i] { case '\\': if runtime.GOOS != "windows" { // error check handled in matchChunk: bad pattern. if i+1 < len(pattern) { i++ } } case '[': inrange = true case ']': inrange = false case '*': if !inrange { break Scan } } } return star, pattern[0:i], pattern[i:] }
[ "func", "scanChunk", "(", "pattern", "string", ")", "(", "star", "bool", ",", "chunk", ",", "rest", "string", ")", "{", "for", "len", "(", "pattern", ")", ">", "0", "&&", "pattern", "[", "0", "]", "==", "'*'", "{", "pattern", "=", "pattern", "[", "1", ":", "]", "\n", "star", "=", "true", "\n", "}", "\n", "inrange", ":=", "false", "\n", "var", "i", "int", "\n", "Scan", ":", "for", "i", "=", "0", ";", "i", "<", "len", "(", "pattern", ")", ";", "i", "++", "{", "switch", "pattern", "[", "i", "]", "{", "case", "'\\\\'", ":", "if", "runtime", ".", "GOOS", "!=", "\"", "\"", "{", "// error check handled in matchChunk: bad pattern.", "if", "i", "+", "1", "<", "len", "(", "pattern", ")", "{", "i", "++", "\n", "}", "\n", "}", "\n", "case", "'['", ":", "inrange", "=", "true", "\n", "case", "']'", ":", "inrange", "=", "false", "\n", "case", "'*'", ":", "if", "!", "inrange", "{", "break", "Scan", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "star", ",", "pattern", "[", "0", ":", "i", "]", ",", "pattern", "[", "i", ":", "]", "\n", "}" ]
// scanChunk gets the next segment of pattern, which is a non-star string // possibly preceded by a star.
[ "scanChunk", "gets", "the", "next", "segment", "of", "pattern", "which", "is", "a", "non", "-", "star", "string", "possibly", "preceded", "by", "a", "star", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/format/index/match.go#L56-L84
train
src-d/go-git
submodule.go
Init
func (s *Submodule) Init() error { cfg, err := s.w.r.Storer.Config() if err != nil { return err } _, ok := cfg.Submodules[s.c.Name] if ok { return ErrSubmoduleAlreadyInitialized } s.initialized = true cfg.Submodules[s.c.Name] = s.c return s.w.r.Storer.SetConfig(cfg) }
go
func (s *Submodule) Init() error { cfg, err := s.w.r.Storer.Config() if err != nil { return err } _, ok := cfg.Submodules[s.c.Name] if ok { return ErrSubmoduleAlreadyInitialized } s.initialized = true cfg.Submodules[s.c.Name] = s.c return s.w.r.Storer.SetConfig(cfg) }
[ "func", "(", "s", "*", "Submodule", ")", "Init", "(", ")", "error", "{", "cfg", ",", "err", ":=", "s", ".", "w", ".", "r", ".", "Storer", ".", "Config", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "_", ",", "ok", ":=", "cfg", ".", "Submodules", "[", "s", ".", "c", ".", "Name", "]", "\n", "if", "ok", "{", "return", "ErrSubmoduleAlreadyInitialized", "\n", "}", "\n\n", "s", ".", "initialized", "=", "true", "\n\n", "cfg", ".", "Submodules", "[", "s", ".", "c", ".", "Name", "]", "=", "s", ".", "c", "\n", "return", "s", ".", "w", ".", "r", ".", "Storer", ".", "SetConfig", "(", "cfg", ")", "\n", "}" ]
// Init initialize the submodule reading the recorded Entry in the index for // the given submodule
[ "Init", "initialize", "the", "submodule", "reading", "the", "recorded", "Entry", "in", "the", "index", "for", "the", "given", "submodule" ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/submodule.go#L37-L52
train
src-d/go-git
submodule.go
Status
func (s *Submodule) Status() (*SubmoduleStatus, error) { idx, err := s.w.r.Storer.Index() if err != nil { return nil, err } return s.status(idx) }
go
func (s *Submodule) Status() (*SubmoduleStatus, error) { idx, err := s.w.r.Storer.Index() if err != nil { return nil, err } return s.status(idx) }
[ "func", "(", "s", "*", "Submodule", ")", "Status", "(", ")", "(", "*", "SubmoduleStatus", ",", "error", ")", "{", "idx", ",", "err", ":=", "s", ".", "w", ".", "r", ".", "Storer", ".", "Index", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "s", ".", "status", "(", "idx", ")", "\n", "}" ]
// Status returns the status of the submodule.
[ "Status", "returns", "the", "status", "of", "the", "submodule", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/submodule.go#L55-L62
train
src-d/go-git
submodule.go
Repository
func (s *Submodule) Repository() (*Repository, error) { if !s.initialized { return nil, ErrSubmoduleNotInitialized } storer, err := s.w.r.Storer.Module(s.c.Name) if err != nil { return nil, err } _, err = storer.Reference(plumbing.HEAD) if err != nil && err != plumbing.ErrReferenceNotFound { return nil, err } var exists bool if err == nil { exists = true } var worktree billy.Filesystem if worktree, err = s.w.Filesystem.Chroot(s.c.Path); err != nil { return nil, err } if exists { return Open(storer, worktree) } r, err := Init(storer, worktree) if err != nil { return nil, err } _, err = r.CreateRemote(&config.RemoteConfig{ Name: DefaultRemoteName, URLs: []string{s.c.URL}, }) return r, err }
go
func (s *Submodule) Repository() (*Repository, error) { if !s.initialized { return nil, ErrSubmoduleNotInitialized } storer, err := s.w.r.Storer.Module(s.c.Name) if err != nil { return nil, err } _, err = storer.Reference(plumbing.HEAD) if err != nil && err != plumbing.ErrReferenceNotFound { return nil, err } var exists bool if err == nil { exists = true } var worktree billy.Filesystem if worktree, err = s.w.Filesystem.Chroot(s.c.Path); err != nil { return nil, err } if exists { return Open(storer, worktree) } r, err := Init(storer, worktree) if err != nil { return nil, err } _, err = r.CreateRemote(&config.RemoteConfig{ Name: DefaultRemoteName, URLs: []string{s.c.URL}, }) return r, err }
[ "func", "(", "s", "*", "Submodule", ")", "Repository", "(", ")", "(", "*", "Repository", ",", "error", ")", "{", "if", "!", "s", ".", "initialized", "{", "return", "nil", ",", "ErrSubmoduleNotInitialized", "\n", "}", "\n\n", "storer", ",", "err", ":=", "s", ".", "w", ".", "r", ".", "Storer", ".", "Module", "(", "s", ".", "c", ".", "Name", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "_", ",", "err", "=", "storer", ".", "Reference", "(", "plumbing", ".", "HEAD", ")", "\n", "if", "err", "!=", "nil", "&&", "err", "!=", "plumbing", ".", "ErrReferenceNotFound", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "var", "exists", "bool", "\n", "if", "err", "==", "nil", "{", "exists", "=", "true", "\n", "}", "\n\n", "var", "worktree", "billy", ".", "Filesystem", "\n", "if", "worktree", ",", "err", "=", "s", ".", "w", ".", "Filesystem", ".", "Chroot", "(", "s", ".", "c", ".", "Path", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "if", "exists", "{", "return", "Open", "(", "storer", ",", "worktree", ")", "\n", "}", "\n\n", "r", ",", "err", ":=", "Init", "(", "storer", ",", "worktree", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "_", ",", "err", "=", "r", ".", "CreateRemote", "(", "&", "config", ".", "RemoteConfig", "{", "Name", ":", "DefaultRemoteName", ",", "URLs", ":", "[", "]", "string", "{", "s", ".", "c", ".", "URL", "}", ",", "}", ")", "\n\n", "return", "r", ",", "err", "\n", "}" ]
// Repository returns the Repository represented by this submodule
[ "Repository", "returns", "the", "Repository", "represented", "by", "this", "submodule" ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/submodule.go#L100-L140
train
src-d/go-git
submodule.go
UpdateContext
func (s *Submodule) UpdateContext(ctx context.Context, o *SubmoduleUpdateOptions) error { return s.update(ctx, o, plumbing.ZeroHash) }
go
func (s *Submodule) UpdateContext(ctx context.Context, o *SubmoduleUpdateOptions) error { return s.update(ctx, o, plumbing.ZeroHash) }
[ "func", "(", "s", "*", "Submodule", ")", "UpdateContext", "(", "ctx", "context", ".", "Context", ",", "o", "*", "SubmoduleUpdateOptions", ")", "error", "{", "return", "s", ".", "update", "(", "ctx", ",", "o", ",", "plumbing", ".", "ZeroHash", ")", "\n", "}" ]
// UpdateContext the registered submodule to match what the superproject // expects, the submodule should be initialized first calling the Init method or // setting in the options SubmoduleUpdateOptions.Init equals true. // // The provided Context must be non-nil. If the context expires before the // operation is complete, an error is returned. The context only affects to the // transport operations.
[ "UpdateContext", "the", "registered", "submodule", "to", "match", "what", "the", "superproject", "expects", "the", "submodule", "should", "be", "initialized", "first", "calling", "the", "Init", "method", "or", "setting", "in", "the", "options", "SubmoduleUpdateOptions", ".", "Init", "equals", "true", ".", "The", "provided", "Context", "must", "be", "non", "-", "nil", ".", "If", "the", "context", "expires", "before", "the", "operation", "is", "complete", "an", "error", "is", "returned", ".", "The", "context", "only", "affects", "to", "the", "transport", "operations", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/submodule.go#L156-L158
train
src-d/go-git
submodule.go
Init
func (s Submodules) Init() error { for _, sub := range s { if err := sub.Init(); err != nil { return err } } return nil }
go
func (s Submodules) Init() error { for _, sub := range s { if err := sub.Init(); err != nil { return err } } return nil }
[ "func", "(", "s", "Submodules", ")", "Init", "(", ")", "error", "{", "for", "_", ",", "sub", ":=", "range", "s", "{", "if", "err", ":=", "sub", ".", "Init", "(", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Init initializes the submodules in this list.
[ "Init", "initializes", "the", "submodules", "in", "this", "list", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/submodule.go#L247-L255
train
src-d/go-git
submodule.go
Update
func (s Submodules) Update(o *SubmoduleUpdateOptions) error { return s.UpdateContext(context.Background(), o) }
go
func (s Submodules) Update(o *SubmoduleUpdateOptions) error { return s.UpdateContext(context.Background(), o) }
[ "func", "(", "s", "Submodules", ")", "Update", "(", "o", "*", "SubmoduleUpdateOptions", ")", "error", "{", "return", "s", ".", "UpdateContext", "(", "context", ".", "Background", "(", ")", ",", "o", ")", "\n", "}" ]
// Update updates all the submodules in this list.
[ "Update", "updates", "all", "the", "submodules", "in", "this", "list", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/submodule.go#L258-L260
train
src-d/go-git
submodule.go
UpdateContext
func (s Submodules) UpdateContext(ctx context.Context, o *SubmoduleUpdateOptions) error { for _, sub := range s { if err := sub.UpdateContext(ctx, o); err != nil { return err } } return nil }
go
func (s Submodules) UpdateContext(ctx context.Context, o *SubmoduleUpdateOptions) error { for _, sub := range s { if err := sub.UpdateContext(ctx, o); err != nil { return err } } return nil }
[ "func", "(", "s", "Submodules", ")", "UpdateContext", "(", "ctx", "context", ".", "Context", ",", "o", "*", "SubmoduleUpdateOptions", ")", "error", "{", "for", "_", ",", "sub", ":=", "range", "s", "{", "if", "err", ":=", "sub", ".", "UpdateContext", "(", "ctx", ",", "o", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// UpdateContext updates all the submodules in this list. // // The provided Context must be non-nil. If the context expires before the // operation is complete, an error is returned. The context only affects to the // transport operations.
[ "UpdateContext", "updates", "all", "the", "submodules", "in", "this", "list", ".", "The", "provided", "Context", "must", "be", "non", "-", "nil", ".", "If", "the", "context", "expires", "before", "the", "operation", "is", "complete", "an", "error", "is", "returned", ".", "The", "context", "only", "affects", "to", "the", "transport", "operations", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/submodule.go#L267-L275
train
src-d/go-git
submodule.go
Status
func (s Submodules) Status() (SubmodulesStatus, error) { var list SubmodulesStatus var r *Repository for _, sub := range s { if r == nil { r = sub.w.r } idx, err := r.Storer.Index() if err != nil { return nil, err } status, err := sub.status(idx) if err != nil { return nil, err } list = append(list, status) } return list, nil }
go
func (s Submodules) Status() (SubmodulesStatus, error) { var list SubmodulesStatus var r *Repository for _, sub := range s { if r == nil { r = sub.w.r } idx, err := r.Storer.Index() if err != nil { return nil, err } status, err := sub.status(idx) if err != nil { return nil, err } list = append(list, status) } return list, nil }
[ "func", "(", "s", "Submodules", ")", "Status", "(", ")", "(", "SubmodulesStatus", ",", "error", ")", "{", "var", "list", "SubmodulesStatus", "\n\n", "var", "r", "*", "Repository", "\n", "for", "_", ",", "sub", ":=", "range", "s", "{", "if", "r", "==", "nil", "{", "r", "=", "sub", ".", "w", ".", "r", "\n", "}", "\n\n", "idx", ",", "err", ":=", "r", ".", "Storer", ".", "Index", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "status", ",", "err", ":=", "sub", ".", "status", "(", "idx", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "list", "=", "append", "(", "list", ",", "status", ")", "\n", "}", "\n\n", "return", "list", ",", "nil", "\n", "}" ]
// Status returns the status of the submodules.
[ "Status", "returns", "the", "status", "of", "the", "submodules", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/submodule.go#L278-L301
train
src-d/go-git
submodule.go
String
func (s SubmodulesStatus) String() string { buf := bytes.NewBuffer(nil) for _, sub := range s { fmt.Fprintln(buf, sub) } return buf.String() }
go
func (s SubmodulesStatus) String() string { buf := bytes.NewBuffer(nil) for _, sub := range s { fmt.Fprintln(buf, sub) } return buf.String() }
[ "func", "(", "s", "SubmodulesStatus", ")", "String", "(", ")", "string", "{", "buf", ":=", "bytes", ".", "NewBuffer", "(", "nil", ")", "\n", "for", "_", ",", "sub", ":=", "range", "s", "{", "fmt", ".", "Fprintln", "(", "buf", ",", "sub", ")", "\n", "}", "\n\n", "return", "buf", ".", "String", "(", ")", "\n", "}" ]
// String is equivalent to `git submodule status`
[ "String", "is", "equivalent", "to", "git", "submodule", "status" ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/submodule.go#L307-L314
train
src-d/go-git
storage/filesystem/dotgit/dotgit.go
NewWithOptions
func NewWithOptions(fs billy.Filesystem, o Options) *DotGit { return &DotGit{ options: o, fs: fs, } }
go
func NewWithOptions(fs billy.Filesystem, o Options) *DotGit { return &DotGit{ options: o, fs: fs, } }
[ "func", "NewWithOptions", "(", "fs", "billy", ".", "Filesystem", ",", "o", "Options", ")", "*", "DotGit", "{", "return", "&", "DotGit", "{", "options", ":", "o", ",", "fs", ":", "fs", ",", "}", "\n", "}" ]
// NewWithOptions sets non default configuration options. // See New for complete help.
[ "NewWithOptions", "sets", "non", "default", "configuration", "options", ".", "See", "New", "for", "complete", "help", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/storage/filesystem/dotgit/dotgit.go#L98-L103
train
src-d/go-git
storage/filesystem/dotgit/dotgit.go
Initialize
func (d *DotGit) Initialize() error { mustExists := []string{ d.fs.Join("objects", "info"), d.fs.Join("objects", "pack"), d.fs.Join("refs", "heads"), d.fs.Join("refs", "tags"), } for _, path := range mustExists { _, err := d.fs.Stat(path) if err == nil { continue } if !os.IsNotExist(err) { return err } if err := d.fs.MkdirAll(path, os.ModeDir|os.ModePerm); err != nil { return err } } return nil }
go
func (d *DotGit) Initialize() error { mustExists := []string{ d.fs.Join("objects", "info"), d.fs.Join("objects", "pack"), d.fs.Join("refs", "heads"), d.fs.Join("refs", "tags"), } for _, path := range mustExists { _, err := d.fs.Stat(path) if err == nil { continue } if !os.IsNotExist(err) { return err } if err := d.fs.MkdirAll(path, os.ModeDir|os.ModePerm); err != nil { return err } } return nil }
[ "func", "(", "d", "*", "DotGit", ")", "Initialize", "(", ")", "error", "{", "mustExists", ":=", "[", "]", "string", "{", "d", ".", "fs", ".", "Join", "(", "\"", "\"", ",", "\"", "\"", ")", ",", "d", ".", "fs", ".", "Join", "(", "\"", "\"", ",", "\"", "\"", ")", ",", "d", ".", "fs", ".", "Join", "(", "\"", "\"", ",", "\"", "\"", ")", ",", "d", ".", "fs", ".", "Join", "(", "\"", "\"", ",", "\"", "\"", ")", ",", "}", "\n\n", "for", "_", ",", "path", ":=", "range", "mustExists", "{", "_", ",", "err", ":=", "d", ".", "fs", ".", "Stat", "(", "path", ")", "\n", "if", "err", "==", "nil", "{", "continue", "\n", "}", "\n\n", "if", "!", "os", ".", "IsNotExist", "(", "err", ")", "{", "return", "err", "\n", "}", "\n\n", "if", "err", ":=", "d", ".", "fs", ".", "MkdirAll", "(", "path", ",", "os", ".", "ModeDir", "|", "os", ".", "ModePerm", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Initialize creates all the folder scaffolding.
[ "Initialize", "creates", "all", "the", "folder", "scaffolding", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/storage/filesystem/dotgit/dotgit.go#L106-L130
train
src-d/go-git
storage/filesystem/dotgit/dotgit.go
ConfigWriter
func (d *DotGit) ConfigWriter() (billy.File, error) { return d.fs.Create(configPath) }
go
func (d *DotGit) ConfigWriter() (billy.File, error) { return d.fs.Create(configPath) }
[ "func", "(", "d", "*", "DotGit", ")", "ConfigWriter", "(", ")", "(", "billy", ".", "File", ",", "error", ")", "{", "return", "d", ".", "fs", ".", "Create", "(", "configPath", ")", "\n", "}" ]
// ConfigWriter returns a file pointer for write to the config file
[ "ConfigWriter", "returns", "a", "file", "pointer", "for", "write", "to", "the", "config", "file" ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/storage/filesystem/dotgit/dotgit.go#L155-L157
train
src-d/go-git
storage/filesystem/dotgit/dotgit.go
Config
func (d *DotGit) Config() (billy.File, error) { return d.fs.Open(configPath) }
go
func (d *DotGit) Config() (billy.File, error) { return d.fs.Open(configPath) }
[ "func", "(", "d", "*", "DotGit", ")", "Config", "(", ")", "(", "billy", ".", "File", ",", "error", ")", "{", "return", "d", ".", "fs", ".", "Open", "(", "configPath", ")", "\n", "}" ]
// Config returns a file pointer for read to the config file
[ "Config", "returns", "a", "file", "pointer", "for", "read", "to", "the", "config", "file" ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/storage/filesystem/dotgit/dotgit.go#L160-L162
train
src-d/go-git
storage/filesystem/dotgit/dotgit.go
IndexWriter
func (d *DotGit) IndexWriter() (billy.File, error) { return d.fs.Create(indexPath) }
go
func (d *DotGit) IndexWriter() (billy.File, error) { return d.fs.Create(indexPath) }
[ "func", "(", "d", "*", "DotGit", ")", "IndexWriter", "(", ")", "(", "billy", ".", "File", ",", "error", ")", "{", "return", "d", ".", "fs", ".", "Create", "(", "indexPath", ")", "\n", "}" ]
// IndexWriter returns a file pointer for write to the index file
[ "IndexWriter", "returns", "a", "file", "pointer", "for", "write", "to", "the", "index", "file" ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/storage/filesystem/dotgit/dotgit.go#L165-L167
train
src-d/go-git
storage/filesystem/dotgit/dotgit.go
Index
func (d *DotGit) Index() (billy.File, error) { return d.fs.Open(indexPath) }
go
func (d *DotGit) Index() (billy.File, error) { return d.fs.Open(indexPath) }
[ "func", "(", "d", "*", "DotGit", ")", "Index", "(", ")", "(", "billy", ".", "File", ",", "error", ")", "{", "return", "d", ".", "fs", ".", "Open", "(", "indexPath", ")", "\n", "}" ]
// Index returns a file pointer for read to the index file
[ "Index", "returns", "a", "file", "pointer", "for", "read", "to", "the", "index", "file" ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/storage/filesystem/dotgit/dotgit.go#L170-L172
train
src-d/go-git
storage/filesystem/dotgit/dotgit.go
ShallowWriter
func (d *DotGit) ShallowWriter() (billy.File, error) { return d.fs.Create(shallowPath) }
go
func (d *DotGit) ShallowWriter() (billy.File, error) { return d.fs.Create(shallowPath) }
[ "func", "(", "d", "*", "DotGit", ")", "ShallowWriter", "(", ")", "(", "billy", ".", "File", ",", "error", ")", "{", "return", "d", ".", "fs", ".", "Create", "(", "shallowPath", ")", "\n", "}" ]
// ShallowWriter returns a file pointer for write to the shallow file
[ "ShallowWriter", "returns", "a", "file", "pointer", "for", "write", "to", "the", "shallow", "file" ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/storage/filesystem/dotgit/dotgit.go#L175-L177
train
src-d/go-git
storage/filesystem/dotgit/dotgit.go
Shallow
func (d *DotGit) Shallow() (billy.File, error) { f, err := d.fs.Open(shallowPath) if err != nil { if os.IsNotExist(err) { return nil, nil } return nil, err } return f, nil }
go
func (d *DotGit) Shallow() (billy.File, error) { f, err := d.fs.Open(shallowPath) if err != nil { if os.IsNotExist(err) { return nil, nil } return nil, err } return f, nil }
[ "func", "(", "d", "*", "DotGit", ")", "Shallow", "(", ")", "(", "billy", ".", "File", ",", "error", ")", "{", "f", ",", "err", ":=", "d", ".", "fs", ".", "Open", "(", "shallowPath", ")", "\n", "if", "err", "!=", "nil", "{", "if", "os", ".", "IsNotExist", "(", "err", ")", "{", "return", "nil", ",", "nil", "\n", "}", "\n\n", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "f", ",", "nil", "\n", "}" ]
// Shallow returns a file pointer for read to the shallow file
[ "Shallow", "returns", "a", "file", "pointer", "for", "read", "to", "the", "shallow", "file" ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/storage/filesystem/dotgit/dotgit.go#L180-L191
train
src-d/go-git
storage/filesystem/dotgit/dotgit.go
NewObjectPack
func (d *DotGit) NewObjectPack() (*PackWriter, error) { d.cleanPackList() return newPackWrite(d.fs) }
go
func (d *DotGit) NewObjectPack() (*PackWriter, error) { d.cleanPackList() return newPackWrite(d.fs) }
[ "func", "(", "d", "*", "DotGit", ")", "NewObjectPack", "(", ")", "(", "*", "PackWriter", ",", "error", ")", "{", "d", ".", "cleanPackList", "(", ")", "\n", "return", "newPackWrite", "(", "d", ".", "fs", ")", "\n", "}" ]
// NewObjectPack return a writer for a new packfile, it saves the packfile to // disk and also generates and save the index for the given packfile.
[ "NewObjectPack", "return", "a", "writer", "for", "a", "new", "packfile", "it", "saves", "the", "packfile", "to", "disk", "and", "also", "generates", "and", "save", "the", "index", "for", "the", "given", "packfile", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/storage/filesystem/dotgit/dotgit.go#L195-L198
train