id
int32
0
167k
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
listlengths
21
1.41k
docstring
stringlengths
6
2.61k
docstring_tokens
listlengths
3
215
sha
stringlengths
40
40
url
stringlengths
85
252
11,600
hashicorp/go-checkpoint
telemetry.go
ReportRequest
func ReportRequest(r *ReportParams) (*http.Request, error) { // Populate some fields automatically if we can if r.RunID == "" { uuid, err := uuid.GenerateUUID() if err != nil { return nil, err } r.RunID = uuid } if r.Arch == "" { r.Arch = runtime.GOARCH } if r.OS == "" { r.OS = runtime.GOOS } if r.Signature == "" { r.Signature = r.signature() } b, err := json.Marshal(r) if err != nil { return nil, err } u := &url.URL{ Scheme: "https", Host: "checkpoint-api.hashicorp.com", Path: fmt.Sprintf("/v1/telemetry/%s", r.Product), } req, err := http.NewRequest("POST", u.String(), bytes.NewReader(b)) if err != nil { return nil, err } req.Header.Set("Accept", "application/json") req.Header.Set("User-Agent", "HashiCorp/go-checkpoint") return req, nil }
go
func ReportRequest(r *ReportParams) (*http.Request, error) { // Populate some fields automatically if we can if r.RunID == "" { uuid, err := uuid.GenerateUUID() if err != nil { return nil, err } r.RunID = uuid } if r.Arch == "" { r.Arch = runtime.GOARCH } if r.OS == "" { r.OS = runtime.GOOS } if r.Signature == "" { r.Signature = r.signature() } b, err := json.Marshal(r) if err != nil { return nil, err } u := &url.URL{ Scheme: "https", Host: "checkpoint-api.hashicorp.com", Path: fmt.Sprintf("/v1/telemetry/%s", r.Product), } req, err := http.NewRequest("POST", u.String(), bytes.NewReader(b)) if err != nil { return nil, err } req.Header.Set("Accept", "application/json") req.Header.Set("User-Agent", "HashiCorp/go-checkpoint") return req, nil }
[ "func", "ReportRequest", "(", "r", "*", "ReportParams", ")", "(", "*", "http", ".", "Request", ",", "error", ")", "{", "// Populate some fields automatically if we can", "if", "r", ".", "RunID", "==", "\"", "\"", "{", "uuid", ",", "err", ":=", "uuid", ".", "GenerateUUID", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "r", ".", "RunID", "=", "uuid", "\n", "}", "\n", "if", "r", ".", "Arch", "==", "\"", "\"", "{", "r", ".", "Arch", "=", "runtime", ".", "GOARCH", "\n", "}", "\n", "if", "r", ".", "OS", "==", "\"", "\"", "{", "r", ".", "OS", "=", "runtime", ".", "GOOS", "\n", "}", "\n", "if", "r", ".", "Signature", "==", "\"", "\"", "{", "r", ".", "Signature", "=", "r", ".", "signature", "(", ")", "\n", "}", "\n\n", "b", ",", "err", ":=", "json", ".", "Marshal", "(", "r", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "u", ":=", "&", "url", ".", "URL", "{", "Scheme", ":", "\"", "\"", ",", "Host", ":", "\"", "\"", ",", "Path", ":", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "r", ".", "Product", ")", ",", "}", "\n\n", "req", ",", "err", ":=", "http", ".", "NewRequest", "(", "\"", "\"", ",", "u", ".", "String", "(", ")", ",", "bytes", ".", "NewReader", "(", "b", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "req", ".", "Header", ".", "Set", "(", "\"", "\"", ",", "\"", "\"", ")", "\n", "req", ".", "Header", ".", "Set", "(", "\"", "\"", ",", "\"", "\"", ")", "\n\n", "return", "req", ",", "nil", "\n", "}" ]
// ReportRequest creates a request object for making a report
[ "ReportRequest", "creates", "a", "request", "object", "for", "making", "a", "report" ]
bbe6c410aa4be4194cb490a2bde8c3c33f295541
https://github.com/hashicorp/go-checkpoint/blob/bbe6c410aa4be4194cb490a2bde8c3c33f295541/telemetry.go#L80-L118
11,601
hashicorp/go-checkpoint
check.go
CheckInterval
func CheckInterval(p *CheckParams, interval time.Duration, cb func(*CheckResponse, error)) chan struct{} { doneCh := make(chan struct{}) if disabled := os.Getenv("CHECKPOINT_DISABLE"); disabled != "" { return doneCh } go func() { for { select { case <-time.After(randomStagger(interval)): resp, err := Check(p) cb(resp, err) case <-doneCh: return } } }() return doneCh }
go
func CheckInterval(p *CheckParams, interval time.Duration, cb func(*CheckResponse, error)) chan struct{} { doneCh := make(chan struct{}) if disabled := os.Getenv("CHECKPOINT_DISABLE"); disabled != "" { return doneCh } go func() { for { select { case <-time.After(randomStagger(interval)): resp, err := Check(p) cb(resp, err) case <-doneCh: return } } }() return doneCh }
[ "func", "CheckInterval", "(", "p", "*", "CheckParams", ",", "interval", "time", ".", "Duration", ",", "cb", "func", "(", "*", "CheckResponse", ",", "error", ")", ")", "chan", "struct", "{", "}", "{", "doneCh", ":=", "make", "(", "chan", "struct", "{", "}", ")", "\n\n", "if", "disabled", ":=", "os", ".", "Getenv", "(", "\"", "\"", ")", ";", "disabled", "!=", "\"", "\"", "{", "return", "doneCh", "\n", "}", "\n\n", "go", "func", "(", ")", "{", "for", "{", "select", "{", "case", "<-", "time", ".", "After", "(", "randomStagger", "(", "interval", ")", ")", ":", "resp", ",", "err", ":=", "Check", "(", "p", ")", "\n", "cb", "(", "resp", ",", "err", ")", "\n", "case", "<-", "doneCh", ":", "return", "\n", "}", "\n", "}", "\n", "}", "(", ")", "\n\n", "return", "doneCh", "\n", "}" ]
// CheckInterval is used to check for a response on a given interval duration. // The interval is not exact, and checks are randomized to prevent a thundering // herd. However, it is expected that on average one check is performed per // interval. The returned channel may be closed to stop background checks.
[ "CheckInterval", "is", "used", "to", "check", "for", "a", "response", "on", "a", "given", "interval", "duration", ".", "The", "interval", "is", "not", "exact", "and", "checks", "are", "randomized", "to", "prevent", "a", "thundering", "herd", ".", "However", "it", "is", "expected", "that", "on", "average", "one", "check", "is", "performed", "per", "interval", ".", "The", "returned", "channel", "may", "be", "closed", "to", "stop", "background", "checks", "." ]
bbe6c410aa4be4194cb490a2bde8c3c33f295541
https://github.com/hashicorp/go-checkpoint/blob/bbe6c410aa4be4194cb490a2bde8c3c33f295541/check.go#L200-L220
11,602
hashicorp/go-checkpoint
versions.go
Versions
func Versions(p *VersionsParams) (*VersionsResponse, error) { if disabled := os.Getenv("CHECKPOINT_DISABLE"); disabled != "" && !p.Force { return &VersionsResponse{}, nil } // Set a default timeout of 1 sec for the versions request (in milliseconds) timeout := 1000 if _, err := strconv.Atoi(os.Getenv("CHECKPOINT_TIMEOUT")); err == nil { timeout, _ = strconv.Atoi(os.Getenv("CHECKPOINT_TIMEOUT")) } v := url.Values{} v.Set("product", p.Product) u := &url.URL{ Scheme: "https", Host: "checkpoint-api.hashicorp.com", Path: fmt.Sprintf("/v1/versions/%s", p.Service), RawQuery: v.Encode(), } req, err := http.NewRequest("GET", u.String(), nil) if err != nil { return nil, err } req.Header.Set("Accept", "application/json") req.Header.Set("User-Agent", "HashiCorp/go-checkpoint") client := cleanhttp.DefaultClient() // We use a short timeout since checking for new versions is not critical // enough to block on if checkpoint is broken/slow. client.Timeout = time.Duration(timeout) * time.Millisecond resp, err := client.Do(req) if err != nil { return nil, err } defer resp.Body.Close() if resp.StatusCode != 200 { return nil, fmt.Errorf("Unknown status: %d", resp.StatusCode) } result := &VersionsResponse{} if err := json.NewDecoder(resp.Body).Decode(result); err != nil { return nil, err } return result, nil }
go
func Versions(p *VersionsParams) (*VersionsResponse, error) { if disabled := os.Getenv("CHECKPOINT_DISABLE"); disabled != "" && !p.Force { return &VersionsResponse{}, nil } // Set a default timeout of 1 sec for the versions request (in milliseconds) timeout := 1000 if _, err := strconv.Atoi(os.Getenv("CHECKPOINT_TIMEOUT")); err == nil { timeout, _ = strconv.Atoi(os.Getenv("CHECKPOINT_TIMEOUT")) } v := url.Values{} v.Set("product", p.Product) u := &url.URL{ Scheme: "https", Host: "checkpoint-api.hashicorp.com", Path: fmt.Sprintf("/v1/versions/%s", p.Service), RawQuery: v.Encode(), } req, err := http.NewRequest("GET", u.String(), nil) if err != nil { return nil, err } req.Header.Set("Accept", "application/json") req.Header.Set("User-Agent", "HashiCorp/go-checkpoint") client := cleanhttp.DefaultClient() // We use a short timeout since checking for new versions is not critical // enough to block on if checkpoint is broken/slow. client.Timeout = time.Duration(timeout) * time.Millisecond resp, err := client.Do(req) if err != nil { return nil, err } defer resp.Body.Close() if resp.StatusCode != 200 { return nil, fmt.Errorf("Unknown status: %d", resp.StatusCode) } result := &VersionsResponse{} if err := json.NewDecoder(resp.Body).Decode(result); err != nil { return nil, err } return result, nil }
[ "func", "Versions", "(", "p", "*", "VersionsParams", ")", "(", "*", "VersionsResponse", ",", "error", ")", "{", "if", "disabled", ":=", "os", ".", "Getenv", "(", "\"", "\"", ")", ";", "disabled", "!=", "\"", "\"", "&&", "!", "p", ".", "Force", "{", "return", "&", "VersionsResponse", "{", "}", ",", "nil", "\n", "}", "\n\n", "// Set a default timeout of 1 sec for the versions request (in milliseconds)", "timeout", ":=", "1000", "\n", "if", "_", ",", "err", ":=", "strconv", ".", "Atoi", "(", "os", ".", "Getenv", "(", "\"", "\"", ")", ")", ";", "err", "==", "nil", "{", "timeout", ",", "_", "=", "strconv", ".", "Atoi", "(", "os", ".", "Getenv", "(", "\"", "\"", ")", ")", "\n", "}", "\n\n", "v", ":=", "url", ".", "Values", "{", "}", "\n", "v", ".", "Set", "(", "\"", "\"", ",", "p", ".", "Product", ")", "\n\n", "u", ":=", "&", "url", ".", "URL", "{", "Scheme", ":", "\"", "\"", ",", "Host", ":", "\"", "\"", ",", "Path", ":", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "p", ".", "Service", ")", ",", "RawQuery", ":", "v", ".", "Encode", "(", ")", ",", "}", "\n\n", "req", ",", "err", ":=", "http", ".", "NewRequest", "(", "\"", "\"", ",", "u", ".", "String", "(", ")", ",", "nil", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "req", ".", "Header", ".", "Set", "(", "\"", "\"", ",", "\"", "\"", ")", "\n", "req", ".", "Header", ".", "Set", "(", "\"", "\"", ",", "\"", "\"", ")", "\n\n", "client", ":=", "cleanhttp", ".", "DefaultClient", "(", ")", "\n\n", "// We use a short timeout since checking for new versions is not critical", "// enough to block on if checkpoint is broken/slow.", "client", ".", "Timeout", "=", "time", ".", "Duration", "(", "timeout", ")", "*", "time", ".", "Millisecond", "\n\n", "resp", ",", "err", ":=", "client", ".", "Do", "(", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "defer", "resp", ".", "Body", ".", "Close", "(", ")", "\n\n", "if", "resp", ".", "StatusCode", "!=", "200", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "resp", ".", "StatusCode", ")", "\n", "}", "\n\n", "result", ":=", "&", "VersionsResponse", "{", "}", "\n", "if", "err", ":=", "json", ".", "NewDecoder", "(", "resp", ".", "Body", ")", ".", "Decode", "(", "result", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "result", ",", "nil", "\n", "}" ]
// Versions returns the version constrains for a given service and product.
[ "Versions", "returns", "the", "version", "constrains", "for", "a", "given", "service", "and", "product", "." ]
bbe6c410aa4be4194cb490a2bde8c3c33f295541
https://github.com/hashicorp/go-checkpoint/blob/bbe6c410aa4be4194cb490a2bde8c3c33f295541/versions.go#L40-L90
11,603
mcuadros/go-version
constraint.go
NewConstrain
func NewConstrain(operator, version string) *Constraint { constraint := new(Constraint) constraint.SetOperator(operator) constraint.SetVersion(version) return constraint }
go
func NewConstrain(operator, version string) *Constraint { constraint := new(Constraint) constraint.SetOperator(operator) constraint.SetVersion(version) return constraint }
[ "func", "NewConstrain", "(", "operator", ",", "version", "string", ")", "*", "Constraint", "{", "constraint", ":=", "new", "(", "Constraint", ")", "\n", "constraint", ".", "SetOperator", "(", "operator", ")", "\n", "constraint", ".", "SetVersion", "(", "version", ")", "\n\n", "return", "constraint", "\n", "}" ]
// Return a new Constrain and sets operator and version to compare
[ "Return", "a", "new", "Constrain", "and", "sets", "operator", "and", "version", "to", "compare" ]
92cdf37c5b7579ebaf7a036da94b40995972088d
https://github.com/mcuadros/go-version/blob/92cdf37c5b7579ebaf7a036da94b40995972088d/constraint.go#L13-L19
11,604
mcuadros/go-version
constraint.go
Match
func (self *Constraint) Match(version string) bool { return Compare(version, self.version, self.operator) }
go
func (self *Constraint) Match(version string) bool { return Compare(version, self.version, self.operator) }
[ "func", "(", "self", "*", "Constraint", ")", "Match", "(", "version", "string", ")", "bool", "{", "return", "Compare", "(", "version", ",", "self", ".", "version", ",", "self", ".", "operator", ")", "\n", "}" ]
// Match a given version againts the constraint
[ "Match", "a", "given", "version", "againts", "the", "constraint" ]
92cdf37c5b7579ebaf7a036da94b40995972088d
https://github.com/mcuadros/go-version/blob/92cdf37c5b7579ebaf7a036da94b40995972088d/constraint.go#L42-L44
11,605
mcuadros/go-version
constraint.go
String
func (self *Constraint) String() string { return strings.Trim(self.operator+" "+self.version, " ") }
go
func (self *Constraint) String() string { return strings.Trim(self.operator+" "+self.version, " ") }
[ "func", "(", "self", "*", "Constraint", ")", "String", "(", ")", "string", "{", "return", "strings", ".", "Trim", "(", "self", ".", "operator", "+", "\"", "\"", "+", "self", ".", "version", ",", "\"", "\"", ")", "\n", "}" ]
// Return a string representation
[ "Return", "a", "string", "representation" ]
92cdf37c5b7579ebaf7a036da94b40995972088d
https://github.com/mcuadros/go-version/blob/92cdf37c5b7579ebaf7a036da94b40995972088d/constraint.go#L47-L49
11,606
mcuadros/go-version
group.go
AddConstraint
func (self *ConstraintGroup) AddConstraint(constraint ...*Constraint) { if self.constraints == nil { self.constraints = make([]*Constraint, 0) } self.constraints = append(self.constraints, constraint...) }
go
func (self *ConstraintGroup) AddConstraint(constraint ...*Constraint) { if self.constraints == nil { self.constraints = make([]*Constraint, 0) } self.constraints = append(self.constraints, constraint...) }
[ "func", "(", "self", "*", "ConstraintGroup", ")", "AddConstraint", "(", "constraint", "...", "*", "Constraint", ")", "{", "if", "self", ".", "constraints", "==", "nil", "{", "self", ".", "constraints", "=", "make", "(", "[", "]", "*", "Constraint", ",", "0", ")", "\n", "}", "\n\n", "self", ".", "constraints", "=", "append", "(", "self", ".", "constraints", ",", "constraint", "...", ")", "\n", "}" ]
// Adds a Contraint to the group
[ "Adds", "a", "Contraint", "to", "the", "group" ]
92cdf37c5b7579ebaf7a036da94b40995972088d
https://github.com/mcuadros/go-version/blob/92cdf37c5b7579ebaf7a036da94b40995972088d/group.go#L59-L65
11,607
vjeantet/grok
grok.go
NewWithConfig
func NewWithConfig(config *Config) (*Grok, error) { g := &Grok{ config: config, aliases: map[string]string{}, compiledPatterns: map[string]*gRegexp{}, patterns: map[string]*gPattern{}, rawPattern: map[string]string{}, patternsGuard: new(sync.RWMutex), compiledGuard: new(sync.RWMutex), } if !config.SkipDefaultPatterns { g.AddPatternsFromMap(patterns) } if len(config.PatternsDir) > 0 { for _, path := range config.PatternsDir { err := g.AddPatternsFromPath(path) if err != nil { return nil, err } } } if err := g.AddPatternsFromMap(config.Patterns); err != nil { return nil, err } return g, nil }
go
func NewWithConfig(config *Config) (*Grok, error) { g := &Grok{ config: config, aliases: map[string]string{}, compiledPatterns: map[string]*gRegexp{}, patterns: map[string]*gPattern{}, rawPattern: map[string]string{}, patternsGuard: new(sync.RWMutex), compiledGuard: new(sync.RWMutex), } if !config.SkipDefaultPatterns { g.AddPatternsFromMap(patterns) } if len(config.PatternsDir) > 0 { for _, path := range config.PatternsDir { err := g.AddPatternsFromPath(path) if err != nil { return nil, err } } } if err := g.AddPatternsFromMap(config.Patterns); err != nil { return nil, err } return g, nil }
[ "func", "NewWithConfig", "(", "config", "*", "Config", ")", "(", "*", "Grok", ",", "error", ")", "{", "g", ":=", "&", "Grok", "{", "config", ":", "config", ",", "aliases", ":", "map", "[", "string", "]", "string", "{", "}", ",", "compiledPatterns", ":", "map", "[", "string", "]", "*", "gRegexp", "{", "}", ",", "patterns", ":", "map", "[", "string", "]", "*", "gPattern", "{", "}", ",", "rawPattern", ":", "map", "[", "string", "]", "string", "{", "}", ",", "patternsGuard", ":", "new", "(", "sync", ".", "RWMutex", ")", ",", "compiledGuard", ":", "new", "(", "sync", ".", "RWMutex", ")", ",", "}", "\n\n", "if", "!", "config", ".", "SkipDefaultPatterns", "{", "g", ".", "AddPatternsFromMap", "(", "patterns", ")", "\n", "}", "\n\n", "if", "len", "(", "config", ".", "PatternsDir", ")", ">", "0", "{", "for", "_", ",", "path", ":=", "range", "config", ".", "PatternsDir", "{", "err", ":=", "g", ".", "AddPatternsFromPath", "(", "path", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "}", "\n\n", "}", "\n\n", "if", "err", ":=", "g", ".", "AddPatternsFromMap", "(", "config", ".", "Patterns", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "g", ",", "nil", "\n", "}" ]
// NewWithConfig returns a Grok object that is configured to behave according // to the supplied Config structure.
[ "NewWithConfig", "returns", "a", "Grok", "object", "that", "is", "configured", "to", "behave", "according", "to", "the", "supplied", "Config", "structure", "." ]
5a86c829f3c347ec23dbd632af2db0d3508c11ce
https://github.com/vjeantet/grok/blob/5a86c829f3c347ec23dbd632af2db0d3508c11ce/grok.go#L62-L92
11,608
vjeantet/grok
grok.go
addPattern
func (g *Grok) addPattern(name, pattern string) error { dnPattern, ti, err := g.denormalizePattern(pattern, g.patterns) if err != nil { return err } g.patterns[name] = &gPattern{expression: dnPattern, typeInfo: ti} return nil }
go
func (g *Grok) addPattern(name, pattern string) error { dnPattern, ti, err := g.denormalizePattern(pattern, g.patterns) if err != nil { return err } g.patterns[name] = &gPattern{expression: dnPattern, typeInfo: ti} return nil }
[ "func", "(", "g", "*", "Grok", ")", "addPattern", "(", "name", ",", "pattern", "string", ")", "error", "{", "dnPattern", ",", "ti", ",", "err", ":=", "g", ".", "denormalizePattern", "(", "pattern", ",", "g", ".", "patterns", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "g", ".", "patterns", "[", "name", "]", "=", "&", "gPattern", "{", "expression", ":", "dnPattern", ",", "typeInfo", ":", "ti", "}", "\n", "return", "nil", "\n", "}" ]
// AddPattern adds a new pattern to the list of loaded patterns.
[ "AddPattern", "adds", "a", "new", "pattern", "to", "the", "list", "of", "loaded", "patterns", "." ]
5a86c829f3c347ec23dbd632af2db0d3508c11ce
https://github.com/vjeantet/grok/blob/5a86c829f3c347ec23dbd632af2db0d3508c11ce/grok.go#L95-L103
11,609
vjeantet/grok
grok.go
AddPattern
func (g *Grok) AddPattern(name, pattern string) error { g.patternsGuard.Lock() defer g.patternsGuard.Unlock() g.rawPattern[name] = pattern g.buildPatterns() return nil }
go
func (g *Grok) AddPattern(name, pattern string) error { g.patternsGuard.Lock() defer g.patternsGuard.Unlock() g.rawPattern[name] = pattern g.buildPatterns() return nil }
[ "func", "(", "g", "*", "Grok", ")", "AddPattern", "(", "name", ",", "pattern", "string", ")", "error", "{", "g", ".", "patternsGuard", ".", "Lock", "(", ")", "\n", "defer", "g", ".", "patternsGuard", ".", "Unlock", "(", ")", "\n\n", "g", ".", "rawPattern", "[", "name", "]", "=", "pattern", "\n", "g", ".", "buildPatterns", "(", ")", "\n", "return", "nil", "\n", "}" ]
// AddPattern adds a named pattern to grok
[ "AddPattern", "adds", "a", "named", "pattern", "to", "grok" ]
5a86c829f3c347ec23dbd632af2db0d3508c11ce
https://github.com/vjeantet/grok/blob/5a86c829f3c347ec23dbd632af2db0d3508c11ce/grok.go#L106-L113
11,610
vjeantet/grok
grok.go
AddPatternsFromMap
func (g *Grok) AddPatternsFromMap(m map[string]string) error { g.patternsGuard.Lock() defer g.patternsGuard.Unlock() for name, pattern := range m { g.rawPattern[name] = pattern } return g.buildPatterns() }
go
func (g *Grok) AddPatternsFromMap(m map[string]string) error { g.patternsGuard.Lock() defer g.patternsGuard.Unlock() for name, pattern := range m { g.rawPattern[name] = pattern } return g.buildPatterns() }
[ "func", "(", "g", "*", "Grok", ")", "AddPatternsFromMap", "(", "m", "map", "[", "string", "]", "string", ")", "error", "{", "g", ".", "patternsGuard", ".", "Lock", "(", ")", "\n", "defer", "g", ".", "patternsGuard", ".", "Unlock", "(", ")", "\n\n", "for", "name", ",", "pattern", ":=", "range", "m", "{", "g", ".", "rawPattern", "[", "name", "]", "=", "pattern", "\n", "}", "\n", "return", "g", ".", "buildPatterns", "(", ")", "\n", "}" ]
// AddPatternsFromMap loads a map of named patterns
[ "AddPatternsFromMap", "loads", "a", "map", "of", "named", "patterns" ]
5a86c829f3c347ec23dbd632af2db0d3508c11ce
https://github.com/vjeantet/grok/blob/5a86c829f3c347ec23dbd632af2db0d3508c11ce/grok.go#L116-L124
11,611
vjeantet/grok
grok.go
addPatternsFromMap
func (g *Grok) addPatternsFromMap(m map[string]string) error { patternDeps := graph{} for k, v := range m { keys := []string{} for _, key := range canonical.FindAllStringSubmatch(v, -1) { names := strings.Split(key[1], ":") syntax := names[0] if g.patterns[syntax] == nil { if _, ok := m[syntax]; !ok { return fmt.Errorf("no pattern found for %%{%s}", syntax) } } keys = append(keys, syntax) } patternDeps[k] = keys } order, _ := sortGraph(patternDeps) for _, key := range reverseList(order) { g.addPattern(key, m[key]) } return nil }
go
func (g *Grok) addPatternsFromMap(m map[string]string) error { patternDeps := graph{} for k, v := range m { keys := []string{} for _, key := range canonical.FindAllStringSubmatch(v, -1) { names := strings.Split(key[1], ":") syntax := names[0] if g.patterns[syntax] == nil { if _, ok := m[syntax]; !ok { return fmt.Errorf("no pattern found for %%{%s}", syntax) } } keys = append(keys, syntax) } patternDeps[k] = keys } order, _ := sortGraph(patternDeps) for _, key := range reverseList(order) { g.addPattern(key, m[key]) } return nil }
[ "func", "(", "g", "*", "Grok", ")", "addPatternsFromMap", "(", "m", "map", "[", "string", "]", "string", ")", "error", "{", "patternDeps", ":=", "graph", "{", "}", "\n", "for", "k", ",", "v", ":=", "range", "m", "{", "keys", ":=", "[", "]", "string", "{", "}", "\n", "for", "_", ",", "key", ":=", "range", "canonical", ".", "FindAllStringSubmatch", "(", "v", ",", "-", "1", ")", "{", "names", ":=", "strings", ".", "Split", "(", "key", "[", "1", "]", ",", "\"", "\"", ")", "\n", "syntax", ":=", "names", "[", "0", "]", "\n", "if", "g", ".", "patterns", "[", "syntax", "]", "==", "nil", "{", "if", "_", ",", "ok", ":=", "m", "[", "syntax", "]", ";", "!", "ok", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "syntax", ")", "\n", "}", "\n", "}", "\n", "keys", "=", "append", "(", "keys", ",", "syntax", ")", "\n", "}", "\n", "patternDeps", "[", "k", "]", "=", "keys", "\n", "}", "\n", "order", ",", "_", ":=", "sortGraph", "(", "patternDeps", ")", "\n", "for", "_", ",", "key", ":=", "range", "reverseList", "(", "order", ")", "{", "g", ".", "addPattern", "(", "key", ",", "m", "[", "key", "]", ")", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// AddPatternsFromMap adds new patterns from the specified map to the list of // loaded patterns.
[ "AddPatternsFromMap", "adds", "new", "patterns", "from", "the", "specified", "map", "to", "the", "list", "of", "loaded", "patterns", "." ]
5a86c829f3c347ec23dbd632af2db0d3508c11ce
https://github.com/vjeantet/grok/blob/5a86c829f3c347ec23dbd632af2db0d3508c11ce/grok.go#L128-L150
11,612
vjeantet/grok
grok.go
AddPatternsFromPath
func (g *Grok) AddPatternsFromPath(path string) error { if fi, err := os.Stat(path); err == nil { if fi.IsDir() { path = path + "/*" } } else { return fmt.Errorf("invalid path : %s", path) } // only one error can be raised, when pattern is malformed // pattern is hard-coded "/*" so we ignore err files, _ := filepath.Glob(path) var filePatterns = map[string]string{} for _, fileName := range files { file, err := os.Open(fileName) if err != nil { return err } scanner := bufio.NewScanner(bufio.NewReader(file)) for scanner.Scan() { l := scanner.Text() if len(l) > 0 && l[0] != '#' { names := strings.SplitN(l, " ", 2) filePatterns[names[0]] = names[1] } } file.Close() } return g.AddPatternsFromMap(filePatterns) }
go
func (g *Grok) AddPatternsFromPath(path string) error { if fi, err := os.Stat(path); err == nil { if fi.IsDir() { path = path + "/*" } } else { return fmt.Errorf("invalid path : %s", path) } // only one error can be raised, when pattern is malformed // pattern is hard-coded "/*" so we ignore err files, _ := filepath.Glob(path) var filePatterns = map[string]string{} for _, fileName := range files { file, err := os.Open(fileName) if err != nil { return err } scanner := bufio.NewScanner(bufio.NewReader(file)) for scanner.Scan() { l := scanner.Text() if len(l) > 0 && l[0] != '#' { names := strings.SplitN(l, " ", 2) filePatterns[names[0]] = names[1] } } file.Close() } return g.AddPatternsFromMap(filePatterns) }
[ "func", "(", "g", "*", "Grok", ")", "AddPatternsFromPath", "(", "path", "string", ")", "error", "{", "if", "fi", ",", "err", ":=", "os", ".", "Stat", "(", "path", ")", ";", "err", "==", "nil", "{", "if", "fi", ".", "IsDir", "(", ")", "{", "path", "=", "path", "+", "\"", "\"", "\n", "}", "\n", "}", "else", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "path", ")", "\n", "}", "\n\n", "// only one error can be raised, when pattern is malformed", "// pattern is hard-coded \"/*\" so we ignore err", "files", ",", "_", ":=", "filepath", ".", "Glob", "(", "path", ")", "\n\n", "var", "filePatterns", "=", "map", "[", "string", "]", "string", "{", "}", "\n", "for", "_", ",", "fileName", ":=", "range", "files", "{", "file", ",", "err", ":=", "os", ".", "Open", "(", "fileName", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "scanner", ":=", "bufio", ".", "NewScanner", "(", "bufio", ".", "NewReader", "(", "file", ")", ")", "\n\n", "for", "scanner", ".", "Scan", "(", ")", "{", "l", ":=", "scanner", ".", "Text", "(", ")", "\n", "if", "len", "(", "l", ")", ">", "0", "&&", "l", "[", "0", "]", "!=", "'#'", "{", "names", ":=", "strings", ".", "SplitN", "(", "l", ",", "\"", "\"", ",", "2", ")", "\n", "filePatterns", "[", "names", "[", "0", "]", "]", "=", "names", "[", "1", "]", "\n", "}", "\n", "}", "\n\n", "file", ".", "Close", "(", ")", "\n", "}", "\n\n", "return", "g", ".", "AddPatternsFromMap", "(", "filePatterns", ")", "\n", "}" ]
// AddPatternsFromPath adds new patterns from the files in the specified // directory to the list of loaded patterns.
[ "AddPatternsFromPath", "adds", "new", "patterns", "from", "the", "files", "in", "the", "specified", "directory", "to", "the", "list", "of", "loaded", "patterns", "." ]
5a86c829f3c347ec23dbd632af2db0d3508c11ce
https://github.com/vjeantet/grok/blob/5a86c829f3c347ec23dbd632af2db0d3508c11ce/grok.go#L154-L188
11,613
vjeantet/grok
grok.go
Match
func (g *Grok) Match(pattern, text string) (bool, error) { gr, err := g.compile(pattern) if err != nil { return false, err } if ok := gr.regexp.MatchString(text); !ok { return false, nil } return true, nil }
go
func (g *Grok) Match(pattern, text string) (bool, error) { gr, err := g.compile(pattern) if err != nil { return false, err } if ok := gr.regexp.MatchString(text); !ok { return false, nil } return true, nil }
[ "func", "(", "g", "*", "Grok", ")", "Match", "(", "pattern", ",", "text", "string", ")", "(", "bool", ",", "error", ")", "{", "gr", ",", "err", ":=", "g", ".", "compile", "(", "pattern", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", ",", "err", "\n", "}", "\n\n", "if", "ok", ":=", "gr", ".", "regexp", ".", "MatchString", "(", "text", ")", ";", "!", "ok", "{", "return", "false", ",", "nil", "\n", "}", "\n\n", "return", "true", ",", "nil", "\n", "}" ]
// Match returns true if the specified text matches the pattern.
[ "Match", "returns", "true", "if", "the", "specified", "text", "matches", "the", "pattern", "." ]
5a86c829f3c347ec23dbd632af2db0d3508c11ce
https://github.com/vjeantet/grok/blob/5a86c829f3c347ec23dbd632af2db0d3508c11ce/grok.go#L191-L202
11,614
vjeantet/grok
grok.go
compiledParse
func (g *Grok) compiledParse(gr *gRegexp, text string) (map[string]string, error) { captures := make(map[string]string) if match := gr.regexp.FindStringSubmatch(text); len(match) > 0 { for i, name := range gr.regexp.SubexpNames() { if name != "" { if g.config.RemoveEmptyValues && match[i] == "" { continue } name = g.nameToAlias(name) captures[name] = match[i] } } } return captures, nil }
go
func (g *Grok) compiledParse(gr *gRegexp, text string) (map[string]string, error) { captures := make(map[string]string) if match := gr.regexp.FindStringSubmatch(text); len(match) > 0 { for i, name := range gr.regexp.SubexpNames() { if name != "" { if g.config.RemoveEmptyValues && match[i] == "" { continue } name = g.nameToAlias(name) captures[name] = match[i] } } } return captures, nil }
[ "func", "(", "g", "*", "Grok", ")", "compiledParse", "(", "gr", "*", "gRegexp", ",", "text", "string", ")", "(", "map", "[", "string", "]", "string", ",", "error", ")", "{", "captures", ":=", "make", "(", "map", "[", "string", "]", "string", ")", "\n", "if", "match", ":=", "gr", ".", "regexp", ".", "FindStringSubmatch", "(", "text", ")", ";", "len", "(", "match", ")", ">", "0", "{", "for", "i", ",", "name", ":=", "range", "gr", ".", "regexp", ".", "SubexpNames", "(", ")", "{", "if", "name", "!=", "\"", "\"", "{", "if", "g", ".", "config", ".", "RemoveEmptyValues", "&&", "match", "[", "i", "]", "==", "\"", "\"", "{", "continue", "\n", "}", "\n", "name", "=", "g", ".", "nameToAlias", "(", "name", ")", "\n", "captures", "[", "name", "]", "=", "match", "[", "i", "]", "\n", "}", "\n", "}", "\n", "}", "\n\n", "return", "captures", ",", "nil", "\n", "}" ]
// compiledParse parses the specified text and returns a map with the results.
[ "compiledParse", "parses", "the", "specified", "text", "and", "returns", "a", "map", "with", "the", "results", "." ]
5a86c829f3c347ec23dbd632af2db0d3508c11ce
https://github.com/vjeantet/grok/blob/5a86c829f3c347ec23dbd632af2db0d3508c11ce/grok.go#L205-L220
11,615
vjeantet/grok
grok.go
Parse
func (g *Grok) Parse(pattern, text string) (map[string]string, error) { gr, err := g.compile(pattern) if err != nil { return nil, err } return g.compiledParse(gr, text) }
go
func (g *Grok) Parse(pattern, text string) (map[string]string, error) { gr, err := g.compile(pattern) if err != nil { return nil, err } return g.compiledParse(gr, text) }
[ "func", "(", "g", "*", "Grok", ")", "Parse", "(", "pattern", ",", "text", "string", ")", "(", "map", "[", "string", "]", "string", ",", "error", ")", "{", "gr", ",", "err", ":=", "g", ".", "compile", "(", "pattern", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "g", ".", "compiledParse", "(", "gr", ",", "text", ")", "\n", "}" ]
// Parse the specified text and return a map with the results.
[ "Parse", "the", "specified", "text", "and", "return", "a", "map", "with", "the", "results", "." ]
5a86c829f3c347ec23dbd632af2db0d3508c11ce
https://github.com/vjeantet/grok/blob/5a86c829f3c347ec23dbd632af2db0d3508c11ce/grok.go#L223-L230
11,616
vjeantet/grok
grok.go
ParseToMultiMap
func (g *Grok) ParseToMultiMap(pattern, text string) (map[string][]string, error) { gr, err := g.compile(pattern) if err != nil { return nil, err } captures := make(map[string][]string) if match := gr.regexp.FindStringSubmatch(text); len(match) > 0 { for i, name := range gr.regexp.SubexpNames() { if name != "" { if g.config.RemoveEmptyValues == true && match[i] == "" { continue } name = g.nameToAlias(name) captures[name] = append(captures[name], match[i]) } } } return captures, nil }
go
func (g *Grok) ParseToMultiMap(pattern, text string) (map[string][]string, error) { gr, err := g.compile(pattern) if err != nil { return nil, err } captures := make(map[string][]string) if match := gr.regexp.FindStringSubmatch(text); len(match) > 0 { for i, name := range gr.regexp.SubexpNames() { if name != "" { if g.config.RemoveEmptyValues == true && match[i] == "" { continue } name = g.nameToAlias(name) captures[name] = append(captures[name], match[i]) } } } return captures, nil }
[ "func", "(", "g", "*", "Grok", ")", "ParseToMultiMap", "(", "pattern", ",", "text", "string", ")", "(", "map", "[", "string", "]", "[", "]", "string", ",", "error", ")", "{", "gr", ",", "err", ":=", "g", ".", "compile", "(", "pattern", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "captures", ":=", "make", "(", "map", "[", "string", "]", "[", "]", "string", ")", "\n", "if", "match", ":=", "gr", ".", "regexp", ".", "FindStringSubmatch", "(", "text", ")", ";", "len", "(", "match", ")", ">", "0", "{", "for", "i", ",", "name", ":=", "range", "gr", ".", "regexp", ".", "SubexpNames", "(", ")", "{", "if", "name", "!=", "\"", "\"", "{", "if", "g", ".", "config", ".", "RemoveEmptyValues", "==", "true", "&&", "match", "[", "i", "]", "==", "\"", "\"", "{", "continue", "\n", "}", "\n", "name", "=", "g", ".", "nameToAlias", "(", "name", ")", "\n", "captures", "[", "name", "]", "=", "append", "(", "captures", "[", "name", "]", ",", "match", "[", "i", "]", ")", "\n", "}", "\n", "}", "\n", "}", "\n\n", "return", "captures", ",", "nil", "\n", "}" ]
// ParseToMultiMap parses the specified text and returns a map with the // results. Values are stored in an string slice, so values from captures with // the same name don't get overridden.
[ "ParseToMultiMap", "parses", "the", "specified", "text", "and", "returns", "a", "map", "with", "the", "results", ".", "Values", "are", "stored", "in", "an", "string", "slice", "so", "values", "from", "captures", "with", "the", "same", "name", "don", "t", "get", "overridden", "." ]
5a86c829f3c347ec23dbd632af2db0d3508c11ce
https://github.com/vjeantet/grok/blob/5a86c829f3c347ec23dbd632af2db0d3508c11ce/grok.go#L270-L290
11,617
vjeantet/grok
grok.go
ParseStream
func (g *Grok) ParseStream(reader *bufio.Reader, pattern string, process func(map[string]string) error) error { gr, err := g.compile(pattern) if err != nil { return err } for { line, err := reader.ReadString('\n') if err == io.EOF { return nil } if err != nil { return err } values, err := g.compiledParse(gr, line) if err != nil { return err } if err = process(values); err != nil { return err } } }
go
func (g *Grok) ParseStream(reader *bufio.Reader, pattern string, process func(map[string]string) error) error { gr, err := g.compile(pattern) if err != nil { return err } for { line, err := reader.ReadString('\n') if err == io.EOF { return nil } if err != nil { return err } values, err := g.compiledParse(gr, line) if err != nil { return err } if err = process(values); err != nil { return err } } }
[ "func", "(", "g", "*", "Grok", ")", "ParseStream", "(", "reader", "*", "bufio", ".", "Reader", ",", "pattern", "string", ",", "process", "func", "(", "map", "[", "string", "]", "string", ")", "error", ")", "error", "{", "gr", ",", "err", ":=", "g", ".", "compile", "(", "pattern", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "for", "{", "line", ",", "err", ":=", "reader", ".", "ReadString", "(", "'\\n'", ")", "\n", "if", "err", "==", "io", ".", "EOF", "{", "return", "nil", "\n", "}", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "values", ",", "err", ":=", "g", ".", "compiledParse", "(", "gr", ",", "line", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "err", "=", "process", "(", "values", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "}" ]
// ParseStream will match the given pattern on a line by line basis from the reader // and apply the results to the process function
[ "ParseStream", "will", "match", "the", "given", "pattern", "on", "a", "line", "by", "line", "basis", "from", "the", "reader", "and", "apply", "the", "results", "to", "the", "process", "function" ]
5a86c829f3c347ec23dbd632af2db0d3508c11ce
https://github.com/vjeantet/grok/blob/5a86c829f3c347ec23dbd632af2db0d3508c11ce/grok.go#L393-L414
11,618
ipfs/go-cid
_rsrch/cidiface/cidStruct.go
Bytes
func (c CidStruct) Bytes() []byte { switch c.version { case 0: return []byte(c.hash) case 1: // two 8 bytes (max) numbers plus hash buf := make([]byte, 2*binary.MaxVarintLen64+len(c.hash)) n := binary.PutUvarint(buf, c.version) n += binary.PutUvarint(buf[n:], c.codec) cn := copy(buf[n:], c.hash) if cn != len(c.hash) { panic("copy hash length is inconsistent") } return buf[:n+len(c.hash)] default: panic("not possible to reach this point") } }
go
func (c CidStruct) Bytes() []byte { switch c.version { case 0: return []byte(c.hash) case 1: // two 8 bytes (max) numbers plus hash buf := make([]byte, 2*binary.MaxVarintLen64+len(c.hash)) n := binary.PutUvarint(buf, c.version) n += binary.PutUvarint(buf[n:], c.codec) cn := copy(buf[n:], c.hash) if cn != len(c.hash) { panic("copy hash length is inconsistent") } return buf[:n+len(c.hash)] default: panic("not possible to reach this point") } }
[ "func", "(", "c", "CidStruct", ")", "Bytes", "(", ")", "[", "]", "byte", "{", "switch", "c", ".", "version", "{", "case", "0", ":", "return", "[", "]", "byte", "(", "c", ".", "hash", ")", "\n", "case", "1", ":", "// two 8 bytes (max) numbers plus hash", "buf", ":=", "make", "(", "[", "]", "byte", ",", "2", "*", "binary", ".", "MaxVarintLen64", "+", "len", "(", "c", ".", "hash", ")", ")", "\n", "n", ":=", "binary", ".", "PutUvarint", "(", "buf", ",", "c", ".", "version", ")", "\n", "n", "+=", "binary", ".", "PutUvarint", "(", "buf", "[", "n", ":", "]", ",", "c", ".", "codec", ")", "\n", "cn", ":=", "copy", "(", "buf", "[", "n", ":", "]", ",", "c", ".", "hash", ")", "\n", "if", "cn", "!=", "len", "(", "c", ".", "hash", ")", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n", "return", "buf", "[", ":", "n", "+", "len", "(", "c", ".", "hash", ")", "]", "\n", "default", ":", "panic", "(", "\"", "\"", ")", "\n", "}", "\n", "}" ]
// Bytes produces a raw binary format of the CID.
[ "Bytes", "produces", "a", "raw", "binary", "format", "of", "the", "CID", "." ]
e7e67e08cfba888a4297224402e12832bdc15ea0
https://github.com/ipfs/go-cid/blob/e7e67e08cfba888a4297224402e12832bdc15ea0/_rsrch/cidiface/cidStruct.go#L74-L91
11,619
ipfs/go-cid
set.go
Has
func (s *Set) Has(c Cid) bool { _, ok := s.set[c] return ok }
go
func (s *Set) Has(c Cid) bool { _, ok := s.set[c] return ok }
[ "func", "(", "s", "*", "Set", ")", "Has", "(", "c", "Cid", ")", "bool", "{", "_", ",", "ok", ":=", "s", ".", "set", "[", "c", "]", "\n", "return", "ok", "\n", "}" ]
// Has returns if the Set contains a given Cid.
[ "Has", "returns", "if", "the", "Set", "contains", "a", "given", "Cid", "." ]
e7e67e08cfba888a4297224402e12832bdc15ea0
https://github.com/ipfs/go-cid/blob/e7e67e08cfba888a4297224402e12832bdc15ea0/set.go#L20-L23
11,620
ipfs/go-cid
set.go
Keys
func (s *Set) Keys() []Cid { out := make([]Cid, 0, len(s.set)) for k := range s.set { out = append(out, k) } return out }
go
func (s *Set) Keys() []Cid { out := make([]Cid, 0, len(s.set)) for k := range s.set { out = append(out, k) } return out }
[ "func", "(", "s", "*", "Set", ")", "Keys", "(", ")", "[", "]", "Cid", "{", "out", ":=", "make", "(", "[", "]", "Cid", ",", "0", ",", "len", "(", "s", ".", "set", ")", ")", "\n", "for", "k", ":=", "range", "s", ".", "set", "{", "out", "=", "append", "(", "out", ",", "k", ")", "\n", "}", "\n", "return", "out", "\n", "}" ]
// Keys returns the Cids in the set.
[ "Keys", "returns", "the", "Cids", "in", "the", "set", "." ]
e7e67e08cfba888a4297224402e12832bdc15ea0
https://github.com/ipfs/go-cid/blob/e7e67e08cfba888a4297224402e12832bdc15ea0/set.go#L36-L42
11,621
ipfs/go-cid
set.go
Visit
func (s *Set) Visit(c Cid) bool { if !s.Has(c) { s.Add(c) return true } return false }
go
func (s *Set) Visit(c Cid) bool { if !s.Has(c) { s.Add(c) return true } return false }
[ "func", "(", "s", "*", "Set", ")", "Visit", "(", "c", "Cid", ")", "bool", "{", "if", "!", "s", ".", "Has", "(", "c", ")", "{", "s", ".", "Add", "(", "c", ")", "\n", "return", "true", "\n", "}", "\n\n", "return", "false", "\n", "}" ]
// Visit adds a Cid to the set only if it is // not in it already.
[ "Visit", "adds", "a", "Cid", "to", "the", "set", "only", "if", "it", "is", "not", "in", "it", "already", "." ]
e7e67e08cfba888a4297224402e12832bdc15ea0
https://github.com/ipfs/go-cid/blob/e7e67e08cfba888a4297224402e12832bdc15ea0/set.go#L46-L53
11,622
ipfs/go-cid
set.go
ForEach
func (s *Set) ForEach(f func(c Cid) error) error { for c := range s.set { err := f(c) if err != nil { return err } } return nil }
go
func (s *Set) ForEach(f func(c Cid) error) error { for c := range s.set { err := f(c) if err != nil { return err } } return nil }
[ "func", "(", "s", "*", "Set", ")", "ForEach", "(", "f", "func", "(", "c", "Cid", ")", "error", ")", "error", "{", "for", "c", ":=", "range", "s", ".", "set", "{", "err", ":=", "f", "(", "c", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// ForEach allows to run a custom function on each // Cid in the set.
[ "ForEach", "allows", "to", "run", "a", "custom", "function", "on", "each", "Cid", "in", "the", "set", "." ]
e7e67e08cfba888a4297224402e12832bdc15ea0
https://github.com/ipfs/go-cid/blob/e7e67e08cfba888a4297224402e12832bdc15ea0/set.go#L57-L65
11,623
ipfs/go-cid
cid.go
NewCidV0
func NewCidV0(mhash mh.Multihash) Cid { // Need to make sure hash is valid for CidV0 otherwise we will // incorrectly detect it as CidV1 in the Version() method dec, err := mh.Decode(mhash) if err != nil { panic(err) } if dec.Code != mh.SHA2_256 || dec.Length != 32 { panic("invalid hash for cidv0") } return Cid{string(mhash)} }
go
func NewCidV0(mhash mh.Multihash) Cid { // Need to make sure hash is valid for CidV0 otherwise we will // incorrectly detect it as CidV1 in the Version() method dec, err := mh.Decode(mhash) if err != nil { panic(err) } if dec.Code != mh.SHA2_256 || dec.Length != 32 { panic("invalid hash for cidv0") } return Cid{string(mhash)} }
[ "func", "NewCidV0", "(", "mhash", "mh", ".", "Multihash", ")", "Cid", "{", "// Need to make sure hash is valid for CidV0 otherwise we will", "// incorrectly detect it as CidV1 in the Version() method", "dec", ",", "err", ":=", "mh", ".", "Decode", "(", "mhash", ")", "\n", "if", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n", "if", "dec", ".", "Code", "!=", "mh", ".", "SHA2_256", "||", "dec", ".", "Length", "!=", "32", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n", "return", "Cid", "{", "string", "(", "mhash", ")", "}", "\n", "}" ]
// NewCidV0 returns a Cid-wrapped multihash. // They exist to allow IPFS to work with Cids while keeping // compatibility with the plain-multihash format used used in IPFS. // NewCidV1 should be used preferentially.
[ "NewCidV0", "returns", "a", "Cid", "-", "wrapped", "multihash", ".", "They", "exist", "to", "allow", "IPFS", "to", "work", "with", "Cids", "while", "keeping", "compatibility", "with", "the", "plain", "-", "multihash", "format", "used", "used", "in", "IPFS", ".", "NewCidV1", "should", "be", "used", "preferentially", "." ]
e7e67e08cfba888a4297224402e12832bdc15ea0
https://github.com/ipfs/go-cid/blob/e7e67e08cfba888a4297224402e12832bdc15ea0/cid.go#L142-L153
11,624
ipfs/go-cid
cid.go
NewCidV1
func NewCidV1(codecType uint64, mhash mh.Multihash) Cid { hashlen := len(mhash) // two 8 bytes (max) numbers plus hash buf := make([]byte, 2*binary.MaxVarintLen64+hashlen) n := binary.PutUvarint(buf, 1) n += binary.PutUvarint(buf[n:], codecType) cn := copy(buf[n:], mhash) if cn != hashlen { panic("copy hash length is inconsistent") } return Cid{string(buf[:n+hashlen])} }
go
func NewCidV1(codecType uint64, mhash mh.Multihash) Cid { hashlen := len(mhash) // two 8 bytes (max) numbers plus hash buf := make([]byte, 2*binary.MaxVarintLen64+hashlen) n := binary.PutUvarint(buf, 1) n += binary.PutUvarint(buf[n:], codecType) cn := copy(buf[n:], mhash) if cn != hashlen { panic("copy hash length is inconsistent") } return Cid{string(buf[:n+hashlen])} }
[ "func", "NewCidV1", "(", "codecType", "uint64", ",", "mhash", "mh", ".", "Multihash", ")", "Cid", "{", "hashlen", ":=", "len", "(", "mhash", ")", "\n", "// two 8 bytes (max) numbers plus hash", "buf", ":=", "make", "(", "[", "]", "byte", ",", "2", "*", "binary", ".", "MaxVarintLen64", "+", "hashlen", ")", "\n", "n", ":=", "binary", ".", "PutUvarint", "(", "buf", ",", "1", ")", "\n", "n", "+=", "binary", ".", "PutUvarint", "(", "buf", "[", "n", ":", "]", ",", "codecType", ")", "\n", "cn", ":=", "copy", "(", "buf", "[", "n", ":", "]", ",", "mhash", ")", "\n", "if", "cn", "!=", "hashlen", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n\n", "return", "Cid", "{", "string", "(", "buf", "[", ":", "n", "+", "hashlen", "]", ")", "}", "\n", "}" ]
// NewCidV1 returns a new Cid using the given multicodec-packed // content type.
[ "NewCidV1", "returns", "a", "new", "Cid", "using", "the", "given", "multicodec", "-", "packed", "content", "type", "." ]
e7e67e08cfba888a4297224402e12832bdc15ea0
https://github.com/ipfs/go-cid/blob/e7e67e08cfba888a4297224402e12832bdc15ea0/cid.go#L157-L169
11,625
ipfs/go-cid
cid.go
ExtractEncoding
func ExtractEncoding(v string) (mbase.Encoding, error) { if len(v) < 2 { return -1, ErrCidTooShort } if len(v) == 46 && v[:2] == "Qm" { return mbase.Base58BTC, nil } encoding := mbase.Encoding(v[0]) // check encoding is valid _, err := mbase.NewEncoder(encoding) if err != nil { return -1, err } return encoding, nil }
go
func ExtractEncoding(v string) (mbase.Encoding, error) { if len(v) < 2 { return -1, ErrCidTooShort } if len(v) == 46 && v[:2] == "Qm" { return mbase.Base58BTC, nil } encoding := mbase.Encoding(v[0]) // check encoding is valid _, err := mbase.NewEncoder(encoding) if err != nil { return -1, err } return encoding, nil }
[ "func", "ExtractEncoding", "(", "v", "string", ")", "(", "mbase", ".", "Encoding", ",", "error", ")", "{", "if", "len", "(", "v", ")", "<", "2", "{", "return", "-", "1", ",", "ErrCidTooShort", "\n", "}", "\n\n", "if", "len", "(", "v", ")", "==", "46", "&&", "v", "[", ":", "2", "]", "==", "\"", "\"", "{", "return", "mbase", ".", "Base58BTC", ",", "nil", "\n", "}", "\n\n", "encoding", ":=", "mbase", ".", "Encoding", "(", "v", "[", "0", "]", ")", "\n\n", "// check encoding is valid", "_", ",", "err", ":=", "mbase", ".", "NewEncoder", "(", "encoding", ")", "\n", "if", "err", "!=", "nil", "{", "return", "-", "1", ",", "err", "\n", "}", "\n\n", "return", "encoding", ",", "nil", "\n", "}" ]
// Extract the encoding from a Cid. If Decode on the same string did // not return an error neither will this function.
[ "Extract", "the", "encoding", "from", "a", "Cid", ".", "If", "Decode", "on", "the", "same", "string", "did", "not", "return", "an", "error", "neither", "will", "this", "function", "." ]
e7e67e08cfba888a4297224402e12832bdc15ea0
https://github.com/ipfs/go-cid/blob/e7e67e08cfba888a4297224402e12832bdc15ea0/cid.go#L248-L266
11,626
ipfs/go-cid
cid.go
Version
func (c Cid) Version() uint64 { if len(c.str) == 34 && c.str[0] == 18 && c.str[1] == 32 { return 0 } return 1 }
go
func (c Cid) Version() uint64 { if len(c.str) == 34 && c.str[0] == 18 && c.str[1] == 32 { return 0 } return 1 }
[ "func", "(", "c", "Cid", ")", "Version", "(", ")", "uint64", "{", "if", "len", "(", "c", ".", "str", ")", "==", "34", "&&", "c", ".", "str", "[", "0", "]", "==", "18", "&&", "c", ".", "str", "[", "1", "]", "==", "32", "{", "return", "0", "\n", "}", "\n", "return", "1", "\n", "}" ]
// Version returns the Cid version.
[ "Version", "returns", "the", "Cid", "version", "." ]
e7e67e08cfba888a4297224402e12832bdc15ea0
https://github.com/ipfs/go-cid/blob/e7e67e08cfba888a4297224402e12832bdc15ea0/cid.go#L346-L351
11,627
ipfs/go-cid
cid.go
Type
func (c Cid) Type() uint64 { if c.Version() == 0 { return DagProtobuf } _, n := uvarint(c.str) codec, _ := uvarint(c.str[n:]) return codec }
go
func (c Cid) Type() uint64 { if c.Version() == 0 { return DagProtobuf } _, n := uvarint(c.str) codec, _ := uvarint(c.str[n:]) return codec }
[ "func", "(", "c", "Cid", ")", "Type", "(", ")", "uint64", "{", "if", "c", ".", "Version", "(", ")", "==", "0", "{", "return", "DagProtobuf", "\n", "}", "\n", "_", ",", "n", ":=", "uvarint", "(", "c", ".", "str", ")", "\n", "codec", ",", "_", ":=", "uvarint", "(", "c", ".", "str", "[", "n", ":", "]", ")", "\n", "return", "codec", "\n", "}" ]
// Type returns the multicodec-packed content type of a Cid.
[ "Type", "returns", "the", "multicodec", "-", "packed", "content", "type", "of", "a", "Cid", "." ]
e7e67e08cfba888a4297224402e12832bdc15ea0
https://github.com/ipfs/go-cid/blob/e7e67e08cfba888a4297224402e12832bdc15ea0/cid.go#L354-L361
11,628
ipfs/go-cid
cid.go
StringOfBase
func (c Cid) StringOfBase(base mbase.Encoding) (string, error) { switch c.Version() { case 0: if base != mbase.Base58BTC { return "", ErrInvalidEncoding } return c.Hash().B58String(), nil case 1: return mbase.Encode(base, c.Bytes()) default: panic("not possible to reach this point") } }
go
func (c Cid) StringOfBase(base mbase.Encoding) (string, error) { switch c.Version() { case 0: if base != mbase.Base58BTC { return "", ErrInvalidEncoding } return c.Hash().B58String(), nil case 1: return mbase.Encode(base, c.Bytes()) default: panic("not possible to reach this point") } }
[ "func", "(", "c", "Cid", ")", "StringOfBase", "(", "base", "mbase", ".", "Encoding", ")", "(", "string", ",", "error", ")", "{", "switch", "c", ".", "Version", "(", ")", "{", "case", "0", ":", "if", "base", "!=", "mbase", ".", "Base58BTC", "{", "return", "\"", "\"", ",", "ErrInvalidEncoding", "\n", "}", "\n", "return", "c", ".", "Hash", "(", ")", ".", "B58String", "(", ")", ",", "nil", "\n", "case", "1", ":", "return", "mbase", ".", "Encode", "(", "base", ",", "c", ".", "Bytes", "(", ")", ")", "\n", "default", ":", "panic", "(", "\"", "\"", ")", "\n", "}", "\n", "}" ]
// String returns the string representation of a Cid // encoded is selected base
[ "String", "returns", "the", "string", "representation", "of", "a", "Cid", "encoded", "is", "selected", "base" ]
e7e67e08cfba888a4297224402e12832bdc15ea0
https://github.com/ipfs/go-cid/blob/e7e67e08cfba888a4297224402e12832bdc15ea0/cid.go#L384-L396
11,629
ipfs/go-cid
cid.go
Encode
func (c Cid) Encode(base mbase.Encoder) string { switch c.Version() { case 0: return c.Hash().B58String() case 1: return base.Encode(c.Bytes()) default: panic("not possible to reach this point") } }
go
func (c Cid) Encode(base mbase.Encoder) string { switch c.Version() { case 0: return c.Hash().B58String() case 1: return base.Encode(c.Bytes()) default: panic("not possible to reach this point") } }
[ "func", "(", "c", "Cid", ")", "Encode", "(", "base", "mbase", ".", "Encoder", ")", "string", "{", "switch", "c", ".", "Version", "(", ")", "{", "case", "0", ":", "return", "c", ".", "Hash", "(", ")", ".", "B58String", "(", ")", "\n", "case", "1", ":", "return", "base", ".", "Encode", "(", "c", ".", "Bytes", "(", ")", ")", "\n", "default", ":", "panic", "(", "\"", "\"", ")", "\n", "}", "\n", "}" ]
// Encode return the string representation of a Cid in a given base // when applicable. Version 0 Cid's are always in Base58 as they do // not take a multibase prefix.
[ "Encode", "return", "the", "string", "representation", "of", "a", "Cid", "in", "a", "given", "base", "when", "applicable", ".", "Version", "0", "Cid", "s", "are", "always", "in", "Base58", "as", "they", "do", "not", "take", "a", "multibase", "prefix", "." ]
e7e67e08cfba888a4297224402e12832bdc15ea0
https://github.com/ipfs/go-cid/blob/e7e67e08cfba888a4297224402e12832bdc15ea0/cid.go#L401-L410
11,630
ipfs/go-cid
cid.go
Hash
func (c Cid) Hash() mh.Multihash { bytes := c.Bytes() if c.Version() == 0 { return mh.Multihash(bytes) } // skip version length _, n1 := binary.Uvarint(bytes) // skip codec length _, n2 := binary.Uvarint(bytes[n1:]) return mh.Multihash(bytes[n1+n2:]) }
go
func (c Cid) Hash() mh.Multihash { bytes := c.Bytes() if c.Version() == 0 { return mh.Multihash(bytes) } // skip version length _, n1 := binary.Uvarint(bytes) // skip codec length _, n2 := binary.Uvarint(bytes[n1:]) return mh.Multihash(bytes[n1+n2:]) }
[ "func", "(", "c", "Cid", ")", "Hash", "(", ")", "mh", ".", "Multihash", "{", "bytes", ":=", "c", ".", "Bytes", "(", ")", "\n\n", "if", "c", ".", "Version", "(", ")", "==", "0", "{", "return", "mh", ".", "Multihash", "(", "bytes", ")", "\n", "}", "\n\n", "// skip version length", "_", ",", "n1", ":=", "binary", ".", "Uvarint", "(", "bytes", ")", "\n", "// skip codec length", "_", ",", "n2", ":=", "binary", ".", "Uvarint", "(", "bytes", "[", "n1", ":", "]", ")", "\n\n", "return", "mh", ".", "Multihash", "(", "bytes", "[", "n1", "+", "n2", ":", "]", ")", "\n", "}" ]
// Hash returns the multihash contained by a Cid.
[ "Hash", "returns", "the", "multihash", "contained", "by", "a", "Cid", "." ]
e7e67e08cfba888a4297224402e12832bdc15ea0
https://github.com/ipfs/go-cid/blob/e7e67e08cfba888a4297224402e12832bdc15ea0/cid.go#L413-L426
11,631
ipfs/go-cid
cid.go
UnmarshalJSON
func (c *Cid) UnmarshalJSON(b []byte) error { if len(b) < 2 { return fmt.Errorf("invalid cid json blob") } obj := struct { CidTarget string `json:"/"` }{} objptr := &obj err := json.Unmarshal(b, &objptr) if err != nil { return err } if objptr == nil { *c = Cid{} return nil } if obj.CidTarget == "" { return fmt.Errorf("cid was incorrectly formatted") } out, err := Decode(obj.CidTarget) if err != nil { return err } *c = out return nil }
go
func (c *Cid) UnmarshalJSON(b []byte) error { if len(b) < 2 { return fmt.Errorf("invalid cid json blob") } obj := struct { CidTarget string `json:"/"` }{} objptr := &obj err := json.Unmarshal(b, &objptr) if err != nil { return err } if objptr == nil { *c = Cid{} return nil } if obj.CidTarget == "" { return fmt.Errorf("cid was incorrectly formatted") } out, err := Decode(obj.CidTarget) if err != nil { return err } *c = out return nil }
[ "func", "(", "c", "*", "Cid", ")", "UnmarshalJSON", "(", "b", "[", "]", "byte", ")", "error", "{", "if", "len", "(", "b", ")", "<", "2", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "obj", ":=", "struct", "{", "CidTarget", "string", "`json:\"/\"`", "\n", "}", "{", "}", "\n", "objptr", ":=", "&", "obj", "\n", "err", ":=", "json", ".", "Unmarshal", "(", "b", ",", "&", "objptr", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "objptr", "==", "nil", "{", "*", "c", "=", "Cid", "{", "}", "\n", "return", "nil", "\n", "}", "\n\n", "if", "obj", ".", "CidTarget", "==", "\"", "\"", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "out", ",", "err", ":=", "Decode", "(", "obj", ".", "CidTarget", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "*", "c", "=", "out", "\n\n", "return", "nil", "\n", "}" ]
// UnmarshalJSON parses the JSON representation of a Cid.
[ "UnmarshalJSON", "parses", "the", "JSON", "representation", "of", "a", "Cid", "." ]
e7e67e08cfba888a4297224402e12832bdc15ea0
https://github.com/ipfs/go-cid/blob/e7e67e08cfba888a4297224402e12832bdc15ea0/cid.go#L455-L484
11,632
ipfs/go-cid
cid.go
PrefixFromBytes
func PrefixFromBytes(buf []byte) (Prefix, error) { r := bytes.NewReader(buf) vers, err := binary.ReadUvarint(r) if err != nil { return Prefix{}, err } codec, err := binary.ReadUvarint(r) if err != nil { return Prefix{}, err } mhtype, err := binary.ReadUvarint(r) if err != nil { return Prefix{}, err } mhlen, err := binary.ReadUvarint(r) if err != nil { return Prefix{}, err } return Prefix{ Version: vers, Codec: codec, MhType: mhtype, MhLength: int(mhlen), }, nil }
go
func PrefixFromBytes(buf []byte) (Prefix, error) { r := bytes.NewReader(buf) vers, err := binary.ReadUvarint(r) if err != nil { return Prefix{}, err } codec, err := binary.ReadUvarint(r) if err != nil { return Prefix{}, err } mhtype, err := binary.ReadUvarint(r) if err != nil { return Prefix{}, err } mhlen, err := binary.ReadUvarint(r) if err != nil { return Prefix{}, err } return Prefix{ Version: vers, Codec: codec, MhType: mhtype, MhLength: int(mhlen), }, nil }
[ "func", "PrefixFromBytes", "(", "buf", "[", "]", "byte", ")", "(", "Prefix", ",", "error", ")", "{", "r", ":=", "bytes", ".", "NewReader", "(", "buf", ")", "\n", "vers", ",", "err", ":=", "binary", ".", "ReadUvarint", "(", "r", ")", "\n", "if", "err", "!=", "nil", "{", "return", "Prefix", "{", "}", ",", "err", "\n", "}", "\n\n", "codec", ",", "err", ":=", "binary", ".", "ReadUvarint", "(", "r", ")", "\n", "if", "err", "!=", "nil", "{", "return", "Prefix", "{", "}", ",", "err", "\n", "}", "\n\n", "mhtype", ",", "err", ":=", "binary", ".", "ReadUvarint", "(", "r", ")", "\n", "if", "err", "!=", "nil", "{", "return", "Prefix", "{", "}", ",", "err", "\n", "}", "\n\n", "mhlen", ",", "err", ":=", "binary", ".", "ReadUvarint", "(", "r", ")", "\n", "if", "err", "!=", "nil", "{", "return", "Prefix", "{", "}", ",", "err", "\n", "}", "\n\n", "return", "Prefix", "{", "Version", ":", "vers", ",", "Codec", ":", "codec", ",", "MhType", ":", "mhtype", ",", "MhLength", ":", "int", "(", "mhlen", ")", ",", "}", ",", "nil", "\n", "}" ]
// PrefixFromBytes parses a Prefix-byte representation onto a // Prefix.
[ "PrefixFromBytes", "parses", "a", "Prefix", "-", "byte", "representation", "onto", "a", "Prefix", "." ]
e7e67e08cfba888a4297224402e12832bdc15ea0
https://github.com/ipfs/go-cid/blob/e7e67e08cfba888a4297224402e12832bdc15ea0/cid.go#L573-L601
11,633
gobuffalo/tags
pagination.go
Tag
func (p Paginator) Tag(opts Options) (*Tag, error) { // return an empty div if there is only 1 page if p.TotalPages <= 1 { return New("div", Options{}), nil } path, class, wing := extractBaseOptions(opts) opts["class"] = strings.Join([]string{class, "pagination"}, " ") t := New("ul", opts) barLength := wing*2 + 1 center := wing + 1 loopStart := 1 loopEnd := p.TotalPages li, err := p.addPrev(opts, path) if err != nil { return t, errors.WithStack(err) } t.Append(li) if p.TotalPages > barLength { loopEnd = barLength - 2 // range 1 ~ center if p.Page > center { /// range center loopStart = p.Page - wing + 2 loopEnd = loopStart + barLength - 5 li, err := pageLI("1", 1, path, p) if err != nil { return t, errors.WithStack(err) } t.Append(li) t.Append(pageLIDummy()) } if p.Page > (p.TotalPages - wing - 1) { loopEnd = p.TotalPages loopStart = p.TotalPages - barLength + 3 } } for i := loopStart; i <= loopEnd; i++ { li, err := pageLI(strconv.Itoa(i), i, path, p) if err != nil { return t, errors.WithStack(err) } t.Append(li) } if p.TotalPages > loopEnd { t.Append(pageLIDummy()) label := strconv.Itoa(p.TotalPages) li, err := pageLI(label, p.TotalPages, path, p) if err != nil { return t, errors.WithStack(err) } t.Append(li) } li, err = p.addNext(opts, path) if err != nil { return t, errors.WithStack(err) } t.Append(li) return t, nil }
go
func (p Paginator) Tag(opts Options) (*Tag, error) { // return an empty div if there is only 1 page if p.TotalPages <= 1 { return New("div", Options{}), nil } path, class, wing := extractBaseOptions(opts) opts["class"] = strings.Join([]string{class, "pagination"}, " ") t := New("ul", opts) barLength := wing*2 + 1 center := wing + 1 loopStart := 1 loopEnd := p.TotalPages li, err := p.addPrev(opts, path) if err != nil { return t, errors.WithStack(err) } t.Append(li) if p.TotalPages > barLength { loopEnd = barLength - 2 // range 1 ~ center if p.Page > center { /// range center loopStart = p.Page - wing + 2 loopEnd = loopStart + barLength - 5 li, err := pageLI("1", 1, path, p) if err != nil { return t, errors.WithStack(err) } t.Append(li) t.Append(pageLIDummy()) } if p.Page > (p.TotalPages - wing - 1) { loopEnd = p.TotalPages loopStart = p.TotalPages - barLength + 3 } } for i := loopStart; i <= loopEnd; i++ { li, err := pageLI(strconv.Itoa(i), i, path, p) if err != nil { return t, errors.WithStack(err) } t.Append(li) } if p.TotalPages > loopEnd { t.Append(pageLIDummy()) label := strconv.Itoa(p.TotalPages) li, err := pageLI(label, p.TotalPages, path, p) if err != nil { return t, errors.WithStack(err) } t.Append(li) } li, err = p.addNext(opts, path) if err != nil { return t, errors.WithStack(err) } t.Append(li) return t, nil }
[ "func", "(", "p", "Paginator", ")", "Tag", "(", "opts", "Options", ")", "(", "*", "Tag", ",", "error", ")", "{", "// return an empty div if there is only 1 page", "if", "p", ".", "TotalPages", "<=", "1", "{", "return", "New", "(", "\"", "\"", ",", "Options", "{", "}", ")", ",", "nil", "\n", "}", "\n\n", "path", ",", "class", ",", "wing", ":=", "extractBaseOptions", "(", "opts", ")", "\n", "opts", "[", "\"", "\"", "]", "=", "strings", ".", "Join", "(", "[", "]", "string", "{", "class", ",", "\"", "\"", "}", ",", "\"", "\"", ")", "\n\n", "t", ":=", "New", "(", "\"", "\"", ",", "opts", ")", "\n\n", "barLength", ":=", "wing", "*", "2", "+", "1", "\n", "center", ":=", "wing", "+", "1", "\n", "loopStart", ":=", "1", "\n", "loopEnd", ":=", "p", ".", "TotalPages", "\n\n", "li", ",", "err", ":=", "p", ".", "addPrev", "(", "opts", ",", "path", ")", "\n", "if", "err", "!=", "nil", "{", "return", "t", ",", "errors", ".", "WithStack", "(", "err", ")", "\n", "}", "\n", "t", ".", "Append", "(", "li", ")", "\n\n", "if", "p", ".", "TotalPages", ">", "barLength", "{", "loopEnd", "=", "barLength", "-", "2", "// range 1 ~ center", "\n", "if", "p", ".", "Page", ">", "center", "{", "/// range center", "loopStart", "=", "p", ".", "Page", "-", "wing", "+", "2", "\n", "loopEnd", "=", "loopStart", "+", "barLength", "-", "5", "\n", "li", ",", "err", ":=", "pageLI", "(", "\"", "\"", ",", "1", ",", "path", ",", "p", ")", "\n", "if", "err", "!=", "nil", "{", "return", "t", ",", "errors", ".", "WithStack", "(", "err", ")", "\n", "}", "\n", "t", ".", "Append", "(", "li", ")", "\n", "t", ".", "Append", "(", "pageLIDummy", "(", ")", ")", "\n", "}", "\n", "if", "p", ".", "Page", ">", "(", "p", ".", "TotalPages", "-", "wing", "-", "1", ")", "{", "loopEnd", "=", "p", ".", "TotalPages", "\n", "loopStart", "=", "p", ".", "TotalPages", "-", "barLength", "+", "3", "\n", "}", "\n", "}", "\n\n", "for", "i", ":=", "loopStart", ";", "i", "<=", "loopEnd", ";", "i", "++", "{", "li", ",", "err", ":=", "pageLI", "(", "strconv", ".", "Itoa", "(", "i", ")", ",", "i", ",", "path", ",", "p", ")", "\n", "if", "err", "!=", "nil", "{", "return", "t", ",", "errors", ".", "WithStack", "(", "err", ")", "\n", "}", "\n", "t", ".", "Append", "(", "li", ")", "\n", "}", "\n\n", "if", "p", ".", "TotalPages", ">", "loopEnd", "{", "t", ".", "Append", "(", "pageLIDummy", "(", ")", ")", "\n", "label", ":=", "strconv", ".", "Itoa", "(", "p", ".", "TotalPages", ")", "\n", "li", ",", "err", ":=", "pageLI", "(", "label", ",", "p", ".", "TotalPages", ",", "path", ",", "p", ")", "\n", "if", "err", "!=", "nil", "{", "return", "t", ",", "errors", ".", "WithStack", "(", "err", ")", "\n", "}", "\n", "t", ".", "Append", "(", "li", ")", "\n", "}", "\n\n", "li", ",", "err", "=", "p", ".", "addNext", "(", "opts", ",", "path", ")", "\n", "if", "err", "!=", "nil", "{", "return", "t", ",", "errors", ".", "WithStack", "(", "err", ")", "\n", "}", "\n", "t", ".", "Append", "(", "li", ")", "\n\n", "return", "t", ",", "nil", "\n", "}" ]
//Tag generates the pagination html Tag
[ "Tag", "generates", "the", "pagination", "html", "Tag" ]
d6e385822d0c8df9824d5bd173cad0576c45a6de
https://github.com/gobuffalo/tags/blob/d6e385822d0c8df9824d5bd173cad0576c45a6de/pagination.go#L75-L140
11,634
gobuffalo/tags
pagination.go
Pagination
func Pagination(pagination interface{}, opts Options) (*Tag, error) { if p, ok := pagination.(Paginator); ok { return p.Tag(opts) } p := Paginator{ Page: 1, PerPage: 20, } return p.TagFromPagination(pagination, opts) }
go
func Pagination(pagination interface{}, opts Options) (*Tag, error) { if p, ok := pagination.(Paginator); ok { return p.Tag(opts) } p := Paginator{ Page: 1, PerPage: 20, } return p.TagFromPagination(pagination, opts) }
[ "func", "Pagination", "(", "pagination", "interface", "{", "}", ",", "opts", "Options", ")", "(", "*", "Tag", ",", "error", ")", "{", "if", "p", ",", "ok", ":=", "pagination", ".", "(", "Paginator", ")", ";", "ok", "{", "return", "p", ".", "Tag", "(", "opts", ")", "\n", "}", "\n\n", "p", ":=", "Paginator", "{", "Page", ":", "1", ",", "PerPage", ":", "20", ",", "}", "\n\n", "return", "p", ".", "TagFromPagination", "(", "pagination", ",", "opts", ")", "\n", "}" ]
//Pagination builds pagination Tag based on a passed pagintation interface
[ "Pagination", "builds", "pagination", "Tag", "based", "on", "a", "passed", "pagintation", "interface" ]
d6e385822d0c8df9824d5bd173cad0576c45a6de
https://github.com/gobuffalo/tags/blob/d6e385822d0c8df9824d5bd173cad0576c45a6de/pagination.go#L143-L154
11,635
gobuffalo/tags
form/form.go
SetAuthenticityToken
func (f *Form) SetAuthenticityToken(s string) { f.Prepend(tags.New("input", tags.Options{ "value": s, "type": "hidden", "name": "authenticity_token", })) }
go
func (f *Form) SetAuthenticityToken(s string) { f.Prepend(tags.New("input", tags.Options{ "value": s, "type": "hidden", "name": "authenticity_token", })) }
[ "func", "(", "f", "*", "Form", ")", "SetAuthenticityToken", "(", "s", "string", ")", "{", "f", ".", "Prepend", "(", "tags", ".", "New", "(", "\"", "\"", ",", "tags", ".", "Options", "{", "\"", "\"", ":", "s", ",", "\"", "\"", ":", "\"", "\"", ",", "\"", "\"", ":", "\"", "\"", ",", "}", ")", ")", "\n", "}" ]
//SetAuthenticityToken allows tags to work smoothly with Buffalo, it receives the auth token and creates an input hidden with it.
[ "SetAuthenticityToken", "allows", "tags", "to", "work", "smoothly", "with", "Buffalo", "it", "receives", "the", "auth", "token", "and", "creates", "an", "input", "hidden", "with", "it", "." ]
d6e385822d0c8df9824d5bd173cad0576c45a6de
https://github.com/gobuffalo/tags/blob/d6e385822d0c8df9824d5bd173cad0576c45a6de/form/form.go#L15-L21
11,636
gobuffalo/tags
form/form.go
Label
func (f Form) Label(value string, opts tags.Options) *tags.Tag { opts["body"] = value return tags.New("label", opts) }
go
func (f Form) Label(value string, opts tags.Options) *tags.Tag { opts["body"] = value return tags.New("label", opts) }
[ "func", "(", "f", "Form", ")", "Label", "(", "value", "string", ",", "opts", "tags", ".", "Options", ")", "*", "tags", ".", "Tag", "{", "opts", "[", "\"", "\"", "]", "=", "value", "\n", "return", "tags", ".", "New", "(", "\"", "\"", ",", "opts", ")", "\n", "}" ]
//Label permits to create a label inside a Form
[ "Label", "permits", "to", "create", "a", "label", "inside", "a", "Form" ]
d6e385822d0c8df9824d5bd173cad0576c45a6de
https://github.com/gobuffalo/tags/blob/d6e385822d0c8df9824d5bd173cad0576c45a6de/form/form.go#L24-L27
11,637
gobuffalo/tags
form/form.go
New
func New(opts tags.Options) *Form { if opts["method"] == nil { opts["method"] = "POST" } if opts["multipart"] != nil { opts["enctype"] = "multipart/form-data" delete(opts, "multipart") } form := &Form{ Tag: tags.New("form", opts), } m := strings.ToUpper(form.Options["method"].(string)) if m != "POST" && m != "GET" { form.Options["method"] = "POST" form.Prepend(tags.New("input", tags.Options{ "value": m, "type": "hidden", "name": "_method", })) } return form }
go
func New(opts tags.Options) *Form { if opts["method"] == nil { opts["method"] = "POST" } if opts["multipart"] != nil { opts["enctype"] = "multipart/form-data" delete(opts, "multipart") } form := &Form{ Tag: tags.New("form", opts), } m := strings.ToUpper(form.Options["method"].(string)) if m != "POST" && m != "GET" { form.Options["method"] = "POST" form.Prepend(tags.New("input", tags.Options{ "value": m, "type": "hidden", "name": "_method", })) } return form }
[ "func", "New", "(", "opts", "tags", ".", "Options", ")", "*", "Form", "{", "if", "opts", "[", "\"", "\"", "]", "==", "nil", "{", "opts", "[", "\"", "\"", "]", "=", "\"", "\"", "\n", "}", "\n\n", "if", "opts", "[", "\"", "\"", "]", "!=", "nil", "{", "opts", "[", "\"", "\"", "]", "=", "\"", "\"", "\n", "delete", "(", "opts", ",", "\"", "\"", ")", "\n", "}", "\n\n", "form", ":=", "&", "Form", "{", "Tag", ":", "tags", ".", "New", "(", "\"", "\"", ",", "opts", ")", ",", "}", "\n\n", "m", ":=", "strings", ".", "ToUpper", "(", "form", ".", "Options", "[", "\"", "\"", "]", ".", "(", "string", ")", ")", "\n", "if", "m", "!=", "\"", "\"", "&&", "m", "!=", "\"", "\"", "{", "form", ".", "Options", "[", "\"", "\"", "]", "=", "\"", "\"", "\n", "form", ".", "Prepend", "(", "tags", ".", "New", "(", "\"", "\"", ",", "tags", ".", "Options", "{", "\"", "\"", ":", "m", ",", "\"", "\"", ":", "\"", "\"", ",", "\"", "\"", ":", "\"", "\"", ",", "}", ")", ")", "\n", "}", "\n\n", "return", "form", "\n", "}" ]
//New creates a new form from passed options, it sets defaults for method and also handles other methods as PUT by adding _method hidden input.
[ "New", "creates", "a", "new", "form", "from", "passed", "options", "it", "sets", "defaults", "for", "method", "and", "also", "handles", "other", "methods", "as", "PUT", "by", "adding", "_method", "hidden", "input", "." ]
d6e385822d0c8df9824d5bd173cad0576c45a6de
https://github.com/gobuffalo/tags/blob/d6e385822d0c8df9824d5bd173cad0576c45a6de/form/form.go#L30-L55
11,638
gobuffalo/tags
form/checkbox_tag.go
CheckboxTag
func (f Form) CheckboxTag(opts tags.Options) *tags.Tag { opts["type"] = "checkbox" value := opts["value"] delete(opts, "value") checked := opts["checked"] delete(opts, "checked") if checked == nil { checked = "true" } opts["value"] = checked unchecked := opts["unchecked"] delete(opts, "unchecked") hl := opts["hide_label"] delete(opts, "hide_label") if opts["tag_only"] == true { delete(opts, "label") ct := f.InputTag(opts) ct.Checked = template.HTMLEscaper(value) == template.HTMLEscaper(checked) return ct } tag := tags.New("label", tags.Options{}) ct := f.InputTag(opts) ct.Checked = template.HTMLEscaper(value) == template.HTMLEscaper(checked) tag.Append(ct) if opts["name"] != nil && unchecked != nil { tag.Append(tags.New("input", tags.Options{ "type": "hidden", "name": opts["name"], "value": unchecked, })) } if opts["label"] != nil && hl == nil { label := fmt.Sprint(opts["label"]) delete(opts, "label") tag.Append(" " + label) } return tag }
go
func (f Form) CheckboxTag(opts tags.Options) *tags.Tag { opts["type"] = "checkbox" value := opts["value"] delete(opts, "value") checked := opts["checked"] delete(opts, "checked") if checked == nil { checked = "true" } opts["value"] = checked unchecked := opts["unchecked"] delete(opts, "unchecked") hl := opts["hide_label"] delete(opts, "hide_label") if opts["tag_only"] == true { delete(opts, "label") ct := f.InputTag(opts) ct.Checked = template.HTMLEscaper(value) == template.HTMLEscaper(checked) return ct } tag := tags.New("label", tags.Options{}) ct := f.InputTag(opts) ct.Checked = template.HTMLEscaper(value) == template.HTMLEscaper(checked) tag.Append(ct) if opts["name"] != nil && unchecked != nil { tag.Append(tags.New("input", tags.Options{ "type": "hidden", "name": opts["name"], "value": unchecked, })) } if opts["label"] != nil && hl == nil { label := fmt.Sprint(opts["label"]) delete(opts, "label") tag.Append(" " + label) } return tag }
[ "func", "(", "f", "Form", ")", "CheckboxTag", "(", "opts", "tags", ".", "Options", ")", "*", "tags", ".", "Tag", "{", "opts", "[", "\"", "\"", "]", "=", "\"", "\"", "\n\n", "value", ":=", "opts", "[", "\"", "\"", "]", "\n", "delete", "(", "opts", ",", "\"", "\"", ")", "\n\n", "checked", ":=", "opts", "[", "\"", "\"", "]", "\n", "delete", "(", "opts", ",", "\"", "\"", ")", "\n", "if", "checked", "==", "nil", "{", "checked", "=", "\"", "\"", "\n", "}", "\n", "opts", "[", "\"", "\"", "]", "=", "checked", "\n\n", "unchecked", ":=", "opts", "[", "\"", "\"", "]", "\n", "delete", "(", "opts", ",", "\"", "\"", ")", "\n\n", "hl", ":=", "opts", "[", "\"", "\"", "]", "\n", "delete", "(", "opts", ",", "\"", "\"", ")", "\n\n", "if", "opts", "[", "\"", "\"", "]", "==", "true", "{", "delete", "(", "opts", ",", "\"", "\"", ")", "\n", "ct", ":=", "f", ".", "InputTag", "(", "opts", ")", "\n", "ct", ".", "Checked", "=", "template", ".", "HTMLEscaper", "(", "value", ")", "==", "template", ".", "HTMLEscaper", "(", "checked", ")", "\n", "return", "ct", "\n", "}", "\n\n", "tag", ":=", "tags", ".", "New", "(", "\"", "\"", ",", "tags", ".", "Options", "{", "}", ")", "\n", "ct", ":=", "f", ".", "InputTag", "(", "opts", ")", "\n", "ct", ".", "Checked", "=", "template", ".", "HTMLEscaper", "(", "value", ")", "==", "template", ".", "HTMLEscaper", "(", "checked", ")", "\n", "tag", ".", "Append", "(", "ct", ")", "\n\n", "if", "opts", "[", "\"", "\"", "]", "!=", "nil", "&&", "unchecked", "!=", "nil", "{", "tag", ".", "Append", "(", "tags", ".", "New", "(", "\"", "\"", ",", "tags", ".", "Options", "{", "\"", "\"", ":", "\"", "\"", ",", "\"", "\"", ":", "opts", "[", "\"", "\"", "]", ",", "\"", "\"", ":", "unchecked", ",", "}", ")", ")", "\n", "}", "\n\n", "if", "opts", "[", "\"", "\"", "]", "!=", "nil", "&&", "hl", "==", "nil", "{", "label", ":=", "fmt", ".", "Sprint", "(", "opts", "[", "\"", "\"", "]", ")", "\n", "delete", "(", "opts", ",", "\"", "\"", ")", "\n", "tag", ".", "Append", "(", "\"", "\"", "+", "label", ")", "\n", "}", "\n", "return", "tag", "\n", "}" ]
//CheckboxTag builds a checkbox from the options passed
[ "CheckboxTag", "builds", "a", "checkbox", "from", "the", "options", "passed" ]
d6e385822d0c8df9824d5bd173cad0576c45a6de
https://github.com/gobuffalo/tags/blob/d6e385822d0c8df9824d5bd173cad0576c45a6de/form/checkbox_tag.go#L11-L56
11,639
gobuffalo/tags
form/radio_button_tag.go
RadioButton
func (f Form) RadioButton(opts tags.Options) *tags.Tag { return f.RadioButtonTag(opts) }
go
func (f Form) RadioButton(opts tags.Options) *tags.Tag { return f.RadioButtonTag(opts) }
[ "func", "(", "f", "Form", ")", "RadioButton", "(", "opts", "tags", ".", "Options", ")", "*", "tags", ".", "Tag", "{", "return", "f", ".", "RadioButtonTag", "(", "opts", ")", "\n", "}" ]
//RadioButton creates a radio button for a form with the passed options
[ "RadioButton", "creates", "a", "radio", "button", "for", "a", "form", "with", "the", "passed", "options" ]
d6e385822d0c8df9824d5bd173cad0576c45a6de
https://github.com/gobuffalo/tags/blob/d6e385822d0c8df9824d5bd173cad0576c45a6de/form/radio_button_tag.go#L12-L14
11,640
gobuffalo/tags
form/radio_button_tag.go
RadioButtonTag
func (f Form) RadioButtonTag(opts tags.Options) *tags.Tag { opts["type"] = "radio" var label string if opts["label"] != nil { label = fmt.Sprint(opts["label"]) delete(opts, "label") } var ID string if opts["id"] != nil { ID = fmt.Sprint(opts["id"]) } value := opts["value"] checked := opts["checked"] delete(opts, "checked") if opts["tag_only"] == true { ct := f.InputTag(opts) ct.Checked = template.HTMLEscaper(value) == template.HTMLEscaper(checked) return ct } ct := f.InputTag(opts) ct.Checked = template.HTMLEscaper(value) == template.HTMLEscaper(checked) labelOptions := tags.Options{ "body": strings.Join([]string{ct.String(), label}, " "), } // If the ID is provided, give it to the label's for attribute if ID != "" { labelOptions["for"] = ID } tag := tags.New("label", labelOptions) return tag }
go
func (f Form) RadioButtonTag(opts tags.Options) *tags.Tag { opts["type"] = "radio" var label string if opts["label"] != nil { label = fmt.Sprint(opts["label"]) delete(opts, "label") } var ID string if opts["id"] != nil { ID = fmt.Sprint(opts["id"]) } value := opts["value"] checked := opts["checked"] delete(opts, "checked") if opts["tag_only"] == true { ct := f.InputTag(opts) ct.Checked = template.HTMLEscaper(value) == template.HTMLEscaper(checked) return ct } ct := f.InputTag(opts) ct.Checked = template.HTMLEscaper(value) == template.HTMLEscaper(checked) labelOptions := tags.Options{ "body": strings.Join([]string{ct.String(), label}, " "), } // If the ID is provided, give it to the label's for attribute if ID != "" { labelOptions["for"] = ID } tag := tags.New("label", labelOptions) return tag }
[ "func", "(", "f", "Form", ")", "RadioButtonTag", "(", "opts", "tags", ".", "Options", ")", "*", "tags", ".", "Tag", "{", "opts", "[", "\"", "\"", "]", "=", "\"", "\"", "\n\n", "var", "label", "string", "\n", "if", "opts", "[", "\"", "\"", "]", "!=", "nil", "{", "label", "=", "fmt", ".", "Sprint", "(", "opts", "[", "\"", "\"", "]", ")", "\n", "delete", "(", "opts", ",", "\"", "\"", ")", "\n", "}", "\n", "var", "ID", "string", "\n", "if", "opts", "[", "\"", "\"", "]", "!=", "nil", "{", "ID", "=", "fmt", ".", "Sprint", "(", "opts", "[", "\"", "\"", "]", ")", "\n", "}", "\n\n", "value", ":=", "opts", "[", "\"", "\"", "]", "\n", "checked", ":=", "opts", "[", "\"", "\"", "]", "\n", "delete", "(", "opts", ",", "\"", "\"", ")", "\n\n", "if", "opts", "[", "\"", "\"", "]", "==", "true", "{", "ct", ":=", "f", ".", "InputTag", "(", "opts", ")", "\n", "ct", ".", "Checked", "=", "template", ".", "HTMLEscaper", "(", "value", ")", "==", "template", ".", "HTMLEscaper", "(", "checked", ")", "\n", "return", "ct", "\n", "}", "\n\n", "ct", ":=", "f", ".", "InputTag", "(", "opts", ")", "\n", "ct", ".", "Checked", "=", "template", ".", "HTMLEscaper", "(", "value", ")", "==", "template", ".", "HTMLEscaper", "(", "checked", ")", "\n", "labelOptions", ":=", "tags", ".", "Options", "{", "\"", "\"", ":", "strings", ".", "Join", "(", "[", "]", "string", "{", "ct", ".", "String", "(", ")", ",", "label", "}", ",", "\"", "\"", ")", ",", "}", "\n", "// If the ID is provided, give it to the label's for attribute", "if", "ID", "!=", "\"", "\"", "{", "labelOptions", "[", "\"", "\"", "]", "=", "ID", "\n", "}", "\n", "tag", ":=", "tags", ".", "New", "(", "\"", "\"", ",", "labelOptions", ")", "\n", "return", "tag", "\n", "}" ]
//RadioButtonTag creates a radio button for a form with the passed options
[ "RadioButtonTag", "creates", "a", "radio", "button", "for", "a", "form", "with", "the", "passed", "options" ]
d6e385822d0c8df9824d5bd173cad0576c45a6de
https://github.com/gobuffalo/tags/blob/d6e385822d0c8df9824d5bd173cad0576c45a6de/form/radio_button_tag.go#L17-L51
11,641
gobuffalo/tags
form/bootstrap/form.go
CheckboxTag
func (f Form) CheckboxTag(opts tags.Options) *tags.Tag { return divWrapper(opts, func(o tags.Options) tags.Body { return f.Form.CheckboxTag(o) }) }
go
func (f Form) CheckboxTag(opts tags.Options) *tags.Tag { return divWrapper(opts, func(o tags.Options) tags.Body { return f.Form.CheckboxTag(o) }) }
[ "func", "(", "f", "Form", ")", "CheckboxTag", "(", "opts", "tags", ".", "Options", ")", "*", "tags", ".", "Tag", "{", "return", "divWrapper", "(", "opts", ",", "func", "(", "o", "tags", ".", "Options", ")", "tags", ".", "Body", "{", "return", "f", ".", "Form", ".", "CheckboxTag", "(", "o", ")", "\n", "}", ")", "\n", "}" ]
//CheckboxTag builds a bootstrap checkbox with passed options
[ "CheckboxTag", "builds", "a", "bootstrap", "checkbox", "with", "passed", "options" ]
d6e385822d0c8df9824d5bd173cad0576c45a6de
https://github.com/gobuffalo/tags/blob/d6e385822d0c8df9824d5bd173cad0576c45a6de/form/bootstrap/form.go#L19-L23
11,642
gobuffalo/tags
form/bootstrap/form.go
TextArea
func (f Form) TextArea(opts tags.Options) *tags.Tag { return f.TextAreaTag(opts) }
go
func (f Form) TextArea(opts tags.Options) *tags.Tag { return f.TextAreaTag(opts) }
[ "func", "(", "f", "Form", ")", "TextArea", "(", "opts", "tags", ".", "Options", ")", "*", "tags", ".", "Tag", "{", "return", "f", ".", "TextAreaTag", "(", "opts", ")", "\n", "}" ]
//TextArea builds a bootstrap textarea with passed options
[ "TextArea", "builds", "a", "bootstrap", "textarea", "with", "passed", "options" ]
d6e385822d0c8df9824d5bd173cad0576c45a6de
https://github.com/gobuffalo/tags/blob/d6e385822d0c8df9824d5bd173cad0576c45a6de/form/bootstrap/form.go#L59-L61
11,643
gobuffalo/tags
form/bootstrap/form.go
HiddenTag
func (f Form) HiddenTag(opts tags.Options) *tags.Tag { return f.Form.HiddenTag(opts) }
go
func (f Form) HiddenTag(opts tags.Options) *tags.Tag { return f.Form.HiddenTag(opts) }
[ "func", "(", "f", "Form", ")", "HiddenTag", "(", "opts", "tags", ".", "Options", ")", "*", "tags", ".", "Tag", "{", "return", "f", ".", "Form", ".", "HiddenTag", "(", "opts", ")", "\n", "}" ]
//HiddenTag adds a hidden input to the form
[ "HiddenTag", "adds", "a", "hidden", "input", "to", "the", "form" ]
d6e385822d0c8df9824d5bd173cad0576c45a6de
https://github.com/gobuffalo/tags/blob/d6e385822d0c8df9824d5bd173cad0576c45a6de/form/bootstrap/form.go#L71-L73
11,644
gobuffalo/tags
form/text_area_tag.go
TextAreaTag
func (f Form) TextAreaTag(opts tags.Options) *tags.Tag { if opts["value"] != nil { opts["body"] = opts["value"] delete(opts, "value") } delete(opts, "tag_only") return tags.New("textarea", opts) }
go
func (f Form) TextAreaTag(opts tags.Options) *tags.Tag { if opts["value"] != nil { opts["body"] = opts["value"] delete(opts, "value") } delete(opts, "tag_only") return tags.New("textarea", opts) }
[ "func", "(", "f", "Form", ")", "TextAreaTag", "(", "opts", "tags", ".", "Options", ")", "*", "tags", ".", "Tag", "{", "if", "opts", "[", "\"", "\"", "]", "!=", "nil", "{", "opts", "[", "\"", "\"", "]", "=", "opts", "[", "\"", "\"", "]", "\n", "delete", "(", "opts", ",", "\"", "\"", ")", "\n", "}", "\n\n", "delete", "(", "opts", ",", "\"", "\"", ")", "\n", "return", "tags", ".", "New", "(", "\"", "\"", ",", "opts", ")", "\n", "}" ]
//TextAreaTag creates a textarea for a form with passed options
[ "TextAreaTag", "creates", "a", "textarea", "for", "a", "form", "with", "passed", "options" ]
d6e385822d0c8df9824d5bd173cad0576c45a6de
https://github.com/gobuffalo/tags/blob/d6e385822d0c8df9824d5bd173cad0576c45a6de/form/text_area_tag.go#L13-L21
11,645
gobuffalo/tags
form/input_tag.go
InputTag
func (f Form) InputTag(opts tags.Options) *tags.Tag { if opts["type"] == "hidden" { return f.HiddenTag(opts) } if opts["type"] == nil { opts["type"] = "text" } if opts["type"] == "file" { f.Options["enctype"] = "multipart/form-data" } delete(opts, "tag_only") return tags.New("input", opts) }
go
func (f Form) InputTag(opts tags.Options) *tags.Tag { if opts["type"] == "hidden" { return f.HiddenTag(opts) } if opts["type"] == nil { opts["type"] = "text" } if opts["type"] == "file" { f.Options["enctype"] = "multipart/form-data" } delete(opts, "tag_only") return tags.New("input", opts) }
[ "func", "(", "f", "Form", ")", "InputTag", "(", "opts", "tags", ".", "Options", ")", "*", "tags", ".", "Tag", "{", "if", "opts", "[", "\"", "\"", "]", "==", "\"", "\"", "{", "return", "f", ".", "HiddenTag", "(", "opts", ")", "\n", "}", "\n\n", "if", "opts", "[", "\"", "\"", "]", "==", "nil", "{", "opts", "[", "\"", "\"", "]", "=", "\"", "\"", "\n", "}", "\n\n", "if", "opts", "[", "\"", "\"", "]", "==", "\"", "\"", "{", "f", ".", "Options", "[", "\"", "\"", "]", "=", "\"", "\"", "\n", "}", "\n\n", "delete", "(", "opts", ",", "\"", "\"", ")", "\n", "return", "tags", ".", "New", "(", "\"", "\"", ",", "opts", ")", "\n", "}" ]
//InputTag generates an input tag with passed options, by default will be type=text.
[ "InputTag", "generates", "an", "input", "tag", "with", "passed", "options", "by", "default", "will", "be", "type", "=", "text", "." ]
d6e385822d0c8df9824d5bd173cad0576c45a6de
https://github.com/gobuffalo/tags/blob/d6e385822d0c8df9824d5bd173cad0576c45a6de/form/input_tag.go#L6-L21
11,646
gobuffalo/tags
form/input_tag.go
HiddenTag
func (f Form) HiddenTag(opts tags.Options) *tags.Tag { opts["type"] = "hidden" return tags.New("input", opts) }
go
func (f Form) HiddenTag(opts tags.Options) *tags.Tag { opts["type"] = "hidden" return tags.New("input", opts) }
[ "func", "(", "f", "Form", ")", "HiddenTag", "(", "opts", "tags", ".", "Options", ")", "*", "tags", ".", "Tag", "{", "opts", "[", "\"", "\"", "]", "=", "\"", "\"", "\n", "return", "tags", ".", "New", "(", "\"", "\"", ",", "opts", ")", "\n", "}" ]
//HiddenTag generates and input tag with type hidden
[ "HiddenTag", "generates", "and", "input", "tag", "with", "type", "hidden" ]
d6e385822d0c8df9824d5bd173cad0576c45a6de
https://github.com/gobuffalo/tags/blob/d6e385822d0c8df9824d5bd173cad0576c45a6de/form/input_tag.go#L37-L40
11,647
gobuffalo/tags
form/form_for.go
NewFormFor
func NewFormFor(model interface{}, opts tags.Options) *FormFor { rv := reflect.ValueOf(model) if rv.Kind() == reflect.Ptr { rv = rv.Elem() } name := rv.Type().Name() dashedName := flect.Dasherize(name) if opts["id"] == nil { opts["id"] = fmt.Sprintf("%s-form", dashedName) } errors := loadErrors(opts) delete(opts, "errors") return &FormFor{ Form: New(opts), Model: model, name: name, dashedName: dashedName, reflection: rv, Errors: errors, } }
go
func NewFormFor(model interface{}, opts tags.Options) *FormFor { rv := reflect.ValueOf(model) if rv.Kind() == reflect.Ptr { rv = rv.Elem() } name := rv.Type().Name() dashedName := flect.Dasherize(name) if opts["id"] == nil { opts["id"] = fmt.Sprintf("%s-form", dashedName) } errors := loadErrors(opts) delete(opts, "errors") return &FormFor{ Form: New(opts), Model: model, name: name, dashedName: dashedName, reflection: rv, Errors: errors, } }
[ "func", "NewFormFor", "(", "model", "interface", "{", "}", ",", "opts", "tags", ".", "Options", ")", "*", "FormFor", "{", "rv", ":=", "reflect", ".", "ValueOf", "(", "model", ")", "\n", "if", "rv", ".", "Kind", "(", ")", "==", "reflect", ".", "Ptr", "{", "rv", "=", "rv", ".", "Elem", "(", ")", "\n", "}", "\n", "name", ":=", "rv", ".", "Type", "(", ")", ".", "Name", "(", ")", "\n", "dashedName", ":=", "flect", ".", "Dasherize", "(", "name", ")", "\n\n", "if", "opts", "[", "\"", "\"", "]", "==", "nil", "{", "opts", "[", "\"", "\"", "]", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "dashedName", ")", "\n", "}", "\n\n", "errors", ":=", "loadErrors", "(", "opts", ")", "\n", "delete", "(", "opts", ",", "\"", "\"", ")", "\n\n", "return", "&", "FormFor", "{", "Form", ":", "New", "(", "opts", ")", ",", "Model", ":", "model", ",", "name", ":", "name", ",", "dashedName", ":", "dashedName", ",", "reflection", ":", "rv", ",", "Errors", ":", "errors", ",", "}", "\n", "}" ]
// NewFormFor creates a new Formfor with passed options, it also creates the id of the form from the struct name and adds errors if present.
[ "NewFormFor", "creates", "a", "new", "Formfor", "with", "passed", "options", "it", "also", "creates", "the", "id", "of", "the", "form", "from", "the", "struct", "name", "and", "adds", "errors", "if", "present", "." ]
d6e385822d0c8df9824d5bd173cad0576c45a6de
https://github.com/gobuffalo/tags/blob/d6e385822d0c8df9824d5bd173cad0576c45a6de/form/form_for.go#L31-L54
11,648
gobuffalo/tags
form/form_for.go
InputTag
func (f FormFor) InputTag(field string, opts tags.Options) *tags.Tag { f.buildOptions(field, opts) f.addFormatTag(field, opts) return f.Form.InputTag(opts) }
go
func (f FormFor) InputTag(field string, opts tags.Options) *tags.Tag { f.buildOptions(field, opts) f.addFormatTag(field, opts) return f.Form.InputTag(opts) }
[ "func", "(", "f", "FormFor", ")", "InputTag", "(", "field", "string", ",", "opts", "tags", ".", "Options", ")", "*", "tags", ".", "Tag", "{", "f", ".", "buildOptions", "(", "field", ",", "opts", ")", "\n", "f", ".", "addFormatTag", "(", "field", ",", "opts", ")", "\n", "return", "f", ".", "Form", ".", "InputTag", "(", "opts", ")", "\n", "}" ]
// InputTag creates an input for a field on the form Struct
[ "InputTag", "creates", "an", "input", "for", "a", "field", "on", "the", "form", "Struct" ]
d6e385822d0c8df9824d5bd173cad0576c45a6de
https://github.com/gobuffalo/tags/blob/d6e385822d0c8df9824d5bd173cad0576c45a6de/form/form_for.go#L82-L86
11,649
gobuffalo/tags
form/form_for.go
HiddenTag
func (f FormFor) HiddenTag(field string, opts tags.Options) *tags.Tag { f.buildOptions(field, opts) return f.Form.HiddenTag(opts) }
go
func (f FormFor) HiddenTag(field string, opts tags.Options) *tags.Tag { f.buildOptions(field, opts) return f.Form.HiddenTag(opts) }
[ "func", "(", "f", "FormFor", ")", "HiddenTag", "(", "field", "string", ",", "opts", "tags", ".", "Options", ")", "*", "tags", ".", "Tag", "{", "f", ".", "buildOptions", "(", "field", ",", "opts", ")", "\n", "return", "f", ".", "Form", ".", "HiddenTag", "(", "opts", ")", "\n", "}" ]
// HiddenTag adds a wrappter for input type hidden on the form
[ "HiddenTag", "adds", "a", "wrappter", "for", "input", "type", "hidden", "on", "the", "form" ]
d6e385822d0c8df9824d5bd173cad0576c45a6de
https://github.com/gobuffalo/tags/blob/d6e385822d0c8df9824d5bd173cad0576c45a6de/form/form_for.go#L89-L92
11,650
gobuffalo/tags
form/form_for.go
RadioButton
func (f FormFor) RadioButton(field string, opts tags.Options) *tags.Tag { return f.RadioButtonTag(field, opts) }
go
func (f FormFor) RadioButton(field string, opts tags.Options) *tags.Tag { return f.RadioButtonTag(field, opts) }
[ "func", "(", "f", "FormFor", ")", "RadioButton", "(", "field", "string", ",", "opts", "tags", ".", "Options", ")", "*", "tags", ".", "Tag", "{", "return", "f", ".", "RadioButtonTag", "(", "field", ",", "opts", ")", "\n", "}" ]
// RadioButton creates a radio button for a struct field
[ "RadioButton", "creates", "a", "radio", "button", "for", "a", "struct", "field" ]
d6e385822d0c8df9824d5bd173cad0576c45a6de
https://github.com/gobuffalo/tags/blob/d6e385822d0c8df9824d5bd173cad0576c45a6de/form/form_for.go#L132-L134
11,651
gobuffalo/tags
form/form_for.go
TextArea
func (f FormFor) TextArea(field string, opts tags.Options) *tags.Tag { return f.TextAreaTag(field, opts) }
go
func (f FormFor) TextArea(field string, opts tags.Options) *tags.Tag { return f.TextAreaTag(field, opts) }
[ "func", "(", "f", "FormFor", ")", "TextArea", "(", "field", "string", ",", "opts", "tags", ".", "Options", ")", "*", "tags", ".", "Tag", "{", "return", "f", ".", "TextAreaTag", "(", "field", ",", "opts", ")", "\n", "}" ]
// TextArea creates text area for the specified struct field
[ "TextArea", "creates", "text", "area", "for", "the", "specified", "struct", "field" ]
d6e385822d0c8df9824d5bd173cad0576c45a6de
https://github.com/gobuffalo/tags/blob/d6e385822d0c8df9824d5bd173cad0576c45a6de/form/form_for.go#L149-L151
11,652
gobuffalo/tags
form/form_for.go
SubmitTag
func (f FormFor) SubmitTag(value string, opts tags.Options) *tags.Tag { return f.Form.SubmitTag(value, opts) }
go
func (f FormFor) SubmitTag(value string, opts tags.Options) *tags.Tag { return f.Form.SubmitTag(value, opts) }
[ "func", "(", "f", "FormFor", ")", "SubmitTag", "(", "value", "string", ",", "opts", "tags", ".", "Options", ")", "*", "tags", ".", "Tag", "{", "return", "f", ".", "Form", ".", "SubmitTag", "(", "value", ",", "opts", ")", "\n", "}" ]
// SubmitTag adds a submit button to the form
[ "SubmitTag", "adds", "a", "submit", "button", "to", "the", "form" ]
d6e385822d0c8df9824d5bd173cad0576c45a6de
https://github.com/gobuffalo/tags/blob/d6e385822d0c8df9824d5bd173cad0576c45a6de/form/form_for.go#L160-L162
11,653
gobuffalo/tags
tag.go
New
func New(name string, opts Options) *Tag { tag := &Tag{ Name: name, Options: opts, } if tag.Options["body"] != nil { tag.Body = []Body{tag.Options["body"]} delete(tag.Options, "body") } if tag.Options["before_tag"] != nil { tag.BeforeTag = []BeforeTag{tag.Options["before_tag"]} delete(tag.Options, "before_tag") } if tag.Options["after_tag"] != nil { tag.AfterTag = []AfterTag{tag.Options["after_tag"]} delete(tag.Options, "after_tag") } if tag.Options["value"] != nil { val := tag.Options["value"] switch val.(type) { case time.Time: format := tag.Options["format"] if format == nil || format.(string) == "" { format = "2006-01-02" } delete(tag.Options, "format") tag.Options["value"] = val.(time.Time).Format(format.(string)) default: r := reflect.ValueOf(val) if r.IsValid() == false { tag.Options["value"] = "" } i := r.Interface() if dv, ok := i.(driver.Valuer); ok { value, _ := dv.Value() if value == nil { tag.Options["value"] = "" } tag.Options["value"] = fmt.Sprintf("%v", value) } } } if tag.Options["selected"] != nil { tag.Selected = template.HTMLEscaper(opts["value"]) == template.HTMLEscaper(opts["selected"]) delete(tag.Options, "selected") } return tag }
go
func New(name string, opts Options) *Tag { tag := &Tag{ Name: name, Options: opts, } if tag.Options["body"] != nil { tag.Body = []Body{tag.Options["body"]} delete(tag.Options, "body") } if tag.Options["before_tag"] != nil { tag.BeforeTag = []BeforeTag{tag.Options["before_tag"]} delete(tag.Options, "before_tag") } if tag.Options["after_tag"] != nil { tag.AfterTag = []AfterTag{tag.Options["after_tag"]} delete(tag.Options, "after_tag") } if tag.Options["value"] != nil { val := tag.Options["value"] switch val.(type) { case time.Time: format := tag.Options["format"] if format == nil || format.(string) == "" { format = "2006-01-02" } delete(tag.Options, "format") tag.Options["value"] = val.(time.Time).Format(format.(string)) default: r := reflect.ValueOf(val) if r.IsValid() == false { tag.Options["value"] = "" } i := r.Interface() if dv, ok := i.(driver.Valuer); ok { value, _ := dv.Value() if value == nil { tag.Options["value"] = "" } tag.Options["value"] = fmt.Sprintf("%v", value) } } } if tag.Options["selected"] != nil { tag.Selected = template.HTMLEscaper(opts["value"]) == template.HTMLEscaper(opts["selected"]) delete(tag.Options, "selected") } return tag }
[ "func", "New", "(", "name", "string", ",", "opts", "Options", ")", "*", "Tag", "{", "tag", ":=", "&", "Tag", "{", "Name", ":", "name", ",", "Options", ":", "opts", ",", "}", "\n", "if", "tag", ".", "Options", "[", "\"", "\"", "]", "!=", "nil", "{", "tag", ".", "Body", "=", "[", "]", "Body", "{", "tag", ".", "Options", "[", "\"", "\"", "]", "}", "\n", "delete", "(", "tag", ".", "Options", ",", "\"", "\"", ")", "\n", "}", "\n", "if", "tag", ".", "Options", "[", "\"", "\"", "]", "!=", "nil", "{", "tag", ".", "BeforeTag", "=", "[", "]", "BeforeTag", "{", "tag", ".", "Options", "[", "\"", "\"", "]", "}", "\n", "delete", "(", "tag", ".", "Options", ",", "\"", "\"", ")", "\n", "}", "\n\n", "if", "tag", ".", "Options", "[", "\"", "\"", "]", "!=", "nil", "{", "tag", ".", "AfterTag", "=", "[", "]", "AfterTag", "{", "tag", ".", "Options", "[", "\"", "\"", "]", "}", "\n", "delete", "(", "tag", ".", "Options", ",", "\"", "\"", ")", "\n", "}", "\n\n", "if", "tag", ".", "Options", "[", "\"", "\"", "]", "!=", "nil", "{", "val", ":=", "tag", ".", "Options", "[", "\"", "\"", "]", "\n\n", "switch", "val", ".", "(", "type", ")", "{", "case", "time", ".", "Time", ":", "format", ":=", "tag", ".", "Options", "[", "\"", "\"", "]", "\n", "if", "format", "==", "nil", "||", "format", ".", "(", "string", ")", "==", "\"", "\"", "{", "format", "=", "\"", "\"", "\n", "}", "\n\n", "delete", "(", "tag", ".", "Options", ",", "\"", "\"", ")", "\n", "tag", ".", "Options", "[", "\"", "\"", "]", "=", "val", ".", "(", "time", ".", "Time", ")", ".", "Format", "(", "format", ".", "(", "string", ")", ")", "\n", "default", ":", "r", ":=", "reflect", ".", "ValueOf", "(", "val", ")", "\n", "if", "r", ".", "IsValid", "(", ")", "==", "false", "{", "tag", ".", "Options", "[", "\"", "\"", "]", "=", "\"", "\"", "\n", "}", "\n\n", "i", ":=", "r", ".", "Interface", "(", ")", "\n", "if", "dv", ",", "ok", ":=", "i", ".", "(", "driver", ".", "Valuer", ")", ";", "ok", "{", "value", ",", "_", ":=", "dv", ".", "Value", "(", ")", "\n\n", "if", "value", "==", "nil", "{", "tag", ".", "Options", "[", "\"", "\"", "]", "=", "\"", "\"", "\n", "}", "\n\n", "tag", ".", "Options", "[", "\"", "\"", "]", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "value", ")", "\n", "}", "\n\n", "}", "\n", "}", "\n\n", "if", "tag", ".", "Options", "[", "\"", "\"", "]", "!=", "nil", "{", "tag", ".", "Selected", "=", "template", ".", "HTMLEscaper", "(", "opts", "[", "\"", "\"", "]", ")", "==", "template", ".", "HTMLEscaper", "(", "opts", "[", "\"", "\"", "]", ")", "\n", "delete", "(", "tag", ".", "Options", ",", "\"", "\"", ")", "\n", "}", "\n\n", "return", "tag", "\n", "}" ]
// New creates a new Tag with given name and options.
[ "New", "creates", "a", "new", "Tag", "with", "given", "name", "and", "options", "." ]
d6e385822d0c8df9824d5bd173cad0576c45a6de
https://github.com/gobuffalo/tags/blob/d6e385822d0c8df9824d5bd173cad0576c45a6de/tag.go#L134-L192
11,654
gobuffalo/tags
form/bootstrap/form_for.go
CheckboxTag
func (f FormFor) CheckboxTag(field string, opts tags.Options) *tags.Tag { label := field if opts["label"] != nil { label = fmt.Sprint(opts["label"]) } hl := opts["hide_label"] delete(opts, "label") fieldKey := validators.GenerateKey(field) if err := f.Errors.Get(fieldKey); err != nil { opts["errors"] = err } return divWrapper(opts, func(o tags.Options) tags.Body { if o["class"] != nil { cls := strings.Split(o["class"].(string), " ") ncls := make([]string, 0, len(cls)) for _, c := range cls { if c != "form-control" { ncls = append(ncls, c) } } o["class"] = strings.Join(ncls, " ") } if label != "" { o["label"] = label } if hl != nil { o["hide_label"] = hl } return f.FormFor.CheckboxTag(field, o) }) }
go
func (f FormFor) CheckboxTag(field string, opts tags.Options) *tags.Tag { label := field if opts["label"] != nil { label = fmt.Sprint(opts["label"]) } hl := opts["hide_label"] delete(opts, "label") fieldKey := validators.GenerateKey(field) if err := f.Errors.Get(fieldKey); err != nil { opts["errors"] = err } return divWrapper(opts, func(o tags.Options) tags.Body { if o["class"] != nil { cls := strings.Split(o["class"].(string), " ") ncls := make([]string, 0, len(cls)) for _, c := range cls { if c != "form-control" { ncls = append(ncls, c) } } o["class"] = strings.Join(ncls, " ") } if label != "" { o["label"] = label } if hl != nil { o["hide_label"] = hl } return f.FormFor.CheckboxTag(field, o) }) }
[ "func", "(", "f", "FormFor", ")", "CheckboxTag", "(", "field", "string", ",", "opts", "tags", ".", "Options", ")", "*", "tags", ".", "Tag", "{", "label", ":=", "field", "\n", "if", "opts", "[", "\"", "\"", "]", "!=", "nil", "{", "label", "=", "fmt", ".", "Sprint", "(", "opts", "[", "\"", "\"", "]", ")", "\n", "}", "\n", "hl", ":=", "opts", "[", "\"", "\"", "]", "\n", "delete", "(", "opts", ",", "\"", "\"", ")", "\n\n", "fieldKey", ":=", "validators", ".", "GenerateKey", "(", "field", ")", "\n", "if", "err", ":=", "f", ".", "Errors", ".", "Get", "(", "fieldKey", ")", ";", "err", "!=", "nil", "{", "opts", "[", "\"", "\"", "]", "=", "err", "\n", "}", "\n\n", "return", "divWrapper", "(", "opts", ",", "func", "(", "o", "tags", ".", "Options", ")", "tags", ".", "Body", "{", "if", "o", "[", "\"", "\"", "]", "!=", "nil", "{", "cls", ":=", "strings", ".", "Split", "(", "o", "[", "\"", "\"", "]", ".", "(", "string", ")", ",", "\"", "\"", ")", "\n", "ncls", ":=", "make", "(", "[", "]", "string", ",", "0", ",", "len", "(", "cls", ")", ")", "\n", "for", "_", ",", "c", ":=", "range", "cls", "{", "if", "c", "!=", "\"", "\"", "{", "ncls", "=", "append", "(", "ncls", ",", "c", ")", "\n", "}", "\n", "}", "\n", "o", "[", "\"", "\"", "]", "=", "strings", ".", "Join", "(", "ncls", ",", "\"", "\"", ")", "\n", "}", "\n", "if", "label", "!=", "\"", "\"", "{", "o", "[", "\"", "\"", "]", "=", "label", "\n", "}", "\n", "if", "hl", "!=", "nil", "{", "o", "[", "\"", "\"", "]", "=", "hl", "\n", "}", "\n", "return", "f", ".", "FormFor", ".", "CheckboxTag", "(", "field", ",", "o", ")", "\n", "}", ")", "\n", "}" ]
//CheckboxTag adds a checkbox to a form wrapped with a form-control and a label
[ "CheckboxTag", "adds", "a", "checkbox", "to", "a", "form", "wrapped", "with", "a", "form", "-", "control", "and", "a", "label" ]
d6e385822d0c8df9824d5bd173cad0576c45a6de
https://github.com/gobuffalo/tags/blob/d6e385822d0c8df9824d5bd173cad0576c45a6de/form/bootstrap/form_for.go#L18-L51
11,655
gobuffalo/tags
form/bootstrap/form_for.go
NewFormFor
func NewFormFor(model interface{}, opts tags.Options) *FormFor { return &FormFor{form.NewFormFor(model, opts)} }
go
func NewFormFor(model interface{}, opts tags.Options) *FormFor { return &FormFor{form.NewFormFor(model, opts)} }
[ "func", "NewFormFor", "(", "model", "interface", "{", "}", ",", "opts", "tags", ".", "Options", ")", "*", "FormFor", "{", "return", "&", "FormFor", "{", "form", ".", "NewFormFor", "(", "model", ",", "opts", ")", "}", "\n", "}" ]
//NewFormFor builds a form for a passed model
[ "NewFormFor", "builds", "a", "form", "for", "a", "passed", "model" ]
d6e385822d0c8df9824d5bd173cad0576c45a6de
https://github.com/gobuffalo/tags/blob/d6e385822d0c8df9824d5bd173cad0576c45a6de/form/bootstrap/form_for.go#L119-L121
11,656
gobuffalo/tags
misc.go
JavascriptTag
func JavascriptTag(opts Options) *Tag { if opts["src"] != nil { delete(opts, "body") } return New("script", opts) }
go
func JavascriptTag(opts Options) *Tag { if opts["src"] != nil { delete(opts, "body") } return New("script", opts) }
[ "func", "JavascriptTag", "(", "opts", "Options", ")", "*", "Tag", "{", "if", "opts", "[", "\"", "\"", "]", "!=", "nil", "{", "delete", "(", "opts", ",", "\"", "\"", ")", "\n", "}", "\n\n", "return", "New", "(", "\"", "\"", ",", "opts", ")", "\n", "}" ]
//JavascriptTag builds JS tags based in passed options
[ "JavascriptTag", "builds", "JS", "tags", "based", "in", "passed", "options" ]
d6e385822d0c8df9824d5bd173cad0576c45a6de
https://github.com/gobuffalo/tags/blob/d6e385822d0c8df9824d5bd173cad0576c45a6de/misc.go#L13-L19
11,657
gogs/git-module
repo_pull.go
GetMergeBase
func (repo *Repository) GetMergeBase(base, head string) (string, error) { stdout, err := NewCommand("merge-base", base, head).RunInDir(repo.Path) if err != nil { if strings.Contains(err.Error(), "exit status 1") { return "", ErrNoMergeBase{} } return "", err } return strings.TrimSpace(stdout), nil }
go
func (repo *Repository) GetMergeBase(base, head string) (string, error) { stdout, err := NewCommand("merge-base", base, head).RunInDir(repo.Path) if err != nil { if strings.Contains(err.Error(), "exit status 1") { return "", ErrNoMergeBase{} } return "", err } return strings.TrimSpace(stdout), nil }
[ "func", "(", "repo", "*", "Repository", ")", "GetMergeBase", "(", "base", ",", "head", "string", ")", "(", "string", ",", "error", ")", "{", "stdout", ",", "err", ":=", "NewCommand", "(", "\"", "\"", ",", "base", ",", "head", ")", ".", "RunInDir", "(", "repo", ".", "Path", ")", "\n", "if", "err", "!=", "nil", "{", "if", "strings", ".", "Contains", "(", "err", ".", "Error", "(", ")", ",", "\"", "\"", ")", "{", "return", "\"", "\"", ",", "ErrNoMergeBase", "{", "}", "\n", "}", "\n", "return", "\"", "\"", ",", "err", "\n", "}", "\n", "return", "strings", ".", "TrimSpace", "(", "stdout", ")", ",", "nil", "\n", "}" ]
// GetMergeBase checks and returns merge base of two branches.
[ "GetMergeBase", "checks", "and", "returns", "merge", "base", "of", "two", "branches", "." ]
d1773fe06f37f5e2c92d0ed6dd50c11bf1a17164
https://github.com/gogs/git-module/blob/d1773fe06f37f5e2c92d0ed6dd50c11bf1a17164/repo_pull.go#L23-L32
11,658
gogs/git-module
repo_pull.go
GetPullRequestInfo
func (repo *Repository) GetPullRequestInfo(basePath, baseBranch, headBranch string) (_ *PullRequestInfo, err error) { var remoteBranch string // We don't need a temporary remote for same repository. if repo.Path != basePath { // Add a temporary remote tmpRemote := strconv.FormatInt(time.Now().UnixNano(), 10) if err = repo.AddRemote(tmpRemote, basePath, true); err != nil { return nil, fmt.Errorf("AddRemote: %v", err) } defer repo.RemoveRemote(tmpRemote) remoteBranch = "remotes/" + tmpRemote + "/" + baseBranch } else { remoteBranch = baseBranch } prInfo := new(PullRequestInfo) prInfo.MergeBase, err = repo.GetMergeBase(remoteBranch, headBranch) if err != nil { return nil, err } logs, err := NewCommand("log", prInfo.MergeBase+"..."+headBranch, _PRETTY_LOG_FORMAT).RunInDirBytes(repo.Path) if err != nil { return nil, err } prInfo.Commits, err = repo.parsePrettyFormatLogToList(logs) if err != nil { return nil, fmt.Errorf("parsePrettyFormatLogToList: %v", err) } // Count number of changed files. stdout, err := NewCommand("diff", "--name-only", remoteBranch+"..."+headBranch).RunInDir(repo.Path) if err != nil { return nil, err } prInfo.NumFiles = len(strings.Split(stdout, "\n")) - 1 return prInfo, nil }
go
func (repo *Repository) GetPullRequestInfo(basePath, baseBranch, headBranch string) (_ *PullRequestInfo, err error) { var remoteBranch string // We don't need a temporary remote for same repository. if repo.Path != basePath { // Add a temporary remote tmpRemote := strconv.FormatInt(time.Now().UnixNano(), 10) if err = repo.AddRemote(tmpRemote, basePath, true); err != nil { return nil, fmt.Errorf("AddRemote: %v", err) } defer repo.RemoveRemote(tmpRemote) remoteBranch = "remotes/" + tmpRemote + "/" + baseBranch } else { remoteBranch = baseBranch } prInfo := new(PullRequestInfo) prInfo.MergeBase, err = repo.GetMergeBase(remoteBranch, headBranch) if err != nil { return nil, err } logs, err := NewCommand("log", prInfo.MergeBase+"..."+headBranch, _PRETTY_LOG_FORMAT).RunInDirBytes(repo.Path) if err != nil { return nil, err } prInfo.Commits, err = repo.parsePrettyFormatLogToList(logs) if err != nil { return nil, fmt.Errorf("parsePrettyFormatLogToList: %v", err) } // Count number of changed files. stdout, err := NewCommand("diff", "--name-only", remoteBranch+"..."+headBranch).RunInDir(repo.Path) if err != nil { return nil, err } prInfo.NumFiles = len(strings.Split(stdout, "\n")) - 1 return prInfo, nil }
[ "func", "(", "repo", "*", "Repository", ")", "GetPullRequestInfo", "(", "basePath", ",", "baseBranch", ",", "headBranch", "string", ")", "(", "_", "*", "PullRequestInfo", ",", "err", "error", ")", "{", "var", "remoteBranch", "string", "\n\n", "// We don't need a temporary remote for same repository.", "if", "repo", ".", "Path", "!=", "basePath", "{", "// Add a temporary remote", "tmpRemote", ":=", "strconv", ".", "FormatInt", "(", "time", ".", "Now", "(", ")", ".", "UnixNano", "(", ")", ",", "10", ")", "\n", "if", "err", "=", "repo", ".", "AddRemote", "(", "tmpRemote", ",", "basePath", ",", "true", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "defer", "repo", ".", "RemoveRemote", "(", "tmpRemote", ")", "\n\n", "remoteBranch", "=", "\"", "\"", "+", "tmpRemote", "+", "\"", "\"", "+", "baseBranch", "\n", "}", "else", "{", "remoteBranch", "=", "baseBranch", "\n", "}", "\n\n", "prInfo", ":=", "new", "(", "PullRequestInfo", ")", "\n", "prInfo", ".", "MergeBase", ",", "err", "=", "repo", ".", "GetMergeBase", "(", "remoteBranch", ",", "headBranch", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "logs", ",", "err", ":=", "NewCommand", "(", "\"", "\"", ",", "prInfo", ".", "MergeBase", "+", "\"", "\"", "+", "headBranch", ",", "_PRETTY_LOG_FORMAT", ")", ".", "RunInDirBytes", "(", "repo", ".", "Path", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "prInfo", ".", "Commits", ",", "err", "=", "repo", ".", "parsePrettyFormatLogToList", "(", "logs", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "// Count number of changed files.", "stdout", ",", "err", ":=", "NewCommand", "(", "\"", "\"", ",", "\"", "\"", ",", "remoteBranch", "+", "\"", "\"", "+", "headBranch", ")", ".", "RunInDir", "(", "repo", ".", "Path", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "prInfo", ".", "NumFiles", "=", "len", "(", "strings", ".", "Split", "(", "stdout", ",", "\"", "\\n", "\"", ")", ")", "-", "1", "\n\n", "return", "prInfo", ",", "nil", "\n", "}" ]
// GetPullRequestInfo generates and returns pull request information // between base and head branches of repositories.
[ "GetPullRequestInfo", "generates", "and", "returns", "pull", "request", "information", "between", "base", "and", "head", "branches", "of", "repositories", "." ]
d1773fe06f37f5e2c92d0ed6dd50c11bf1a17164
https://github.com/gogs/git-module/blob/d1773fe06f37f5e2c92d0ed6dd50c11bf1a17164/repo_pull.go#L36-L76
11,659
gogs/git-module
repo_pull.go
GetPatch
func (repo *Repository) GetPatch(base, head string) ([]byte, error) { return NewCommand("diff", "-p", "--binary", base, head).RunInDirBytes(repo.Path) }
go
func (repo *Repository) GetPatch(base, head string) ([]byte, error) { return NewCommand("diff", "-p", "--binary", base, head).RunInDirBytes(repo.Path) }
[ "func", "(", "repo", "*", "Repository", ")", "GetPatch", "(", "base", ",", "head", "string", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "return", "NewCommand", "(", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "base", ",", "head", ")", ".", "RunInDirBytes", "(", "repo", ".", "Path", ")", "\n", "}" ]
// GetPatch generates and returns patch data between given revisions.
[ "GetPatch", "generates", "and", "returns", "patch", "data", "between", "given", "revisions", "." ]
d1773fe06f37f5e2c92d0ed6dd50c11bf1a17164
https://github.com/gogs/git-module/blob/d1773fe06f37f5e2c92d0ed6dd50c11bf1a17164/repo_pull.go#L79-L81
11,660
gogs/git-module
hook.go
IsValidHookName
func IsValidHookName(name string) bool { for _, hn := range HookNames { if hn == name { return true } } return false }
go
func IsValidHookName(name string) bool { for _, hn := range HookNames { if hn == name { return true } } return false }
[ "func", "IsValidHookName", "(", "name", "string", ")", "bool", "{", "for", "_", ",", "hn", ":=", "range", "HookNames", "{", "if", "hn", "==", "name", "{", "return", "true", "\n", "}", "\n", "}", "\n", "return", "false", "\n", "}" ]
// IsValidHookName returns true if given name is a valid Git hook.
[ "IsValidHookName", "returns", "true", "if", "given", "name", "is", "a", "valid", "Git", "hook", "." ]
d1773fe06f37f5e2c92d0ed6dd50c11bf1a17164
https://github.com/gogs/git-module/blob/d1773fe06f37f5e2c92d0ed6dd50c11bf1a17164/hook.go#L32-L39
11,661
gogs/git-module
hook.go
GetHook
func GetHook(repoPath, name string) (*Hook, error) { if !IsValidHookName(name) { return nil, ErrNotValidHook } h := &Hook{ name: name, path: path.Join(repoPath, HookDir, name), } if isFile(h.path) { data, err := ioutil.ReadFile(h.path) if err != nil { return nil, err } h.IsActive = true h.Content = string(data) return h, nil } // Check sample file samplePath := path.Join(repoPath, HookSampleDir, h.name) + ".sample" if isFile(samplePath) { data, err := ioutil.ReadFile(samplePath) if err != nil { return nil, err } h.Sample = string(data) } return h, nil }
go
func GetHook(repoPath, name string) (*Hook, error) { if !IsValidHookName(name) { return nil, ErrNotValidHook } h := &Hook{ name: name, path: path.Join(repoPath, HookDir, name), } if isFile(h.path) { data, err := ioutil.ReadFile(h.path) if err != nil { return nil, err } h.IsActive = true h.Content = string(data) return h, nil } // Check sample file samplePath := path.Join(repoPath, HookSampleDir, h.name) + ".sample" if isFile(samplePath) { data, err := ioutil.ReadFile(samplePath) if err != nil { return nil, err } h.Sample = string(data) } return h, nil }
[ "func", "GetHook", "(", "repoPath", ",", "name", "string", ")", "(", "*", "Hook", ",", "error", ")", "{", "if", "!", "IsValidHookName", "(", "name", ")", "{", "return", "nil", ",", "ErrNotValidHook", "\n", "}", "\n", "h", ":=", "&", "Hook", "{", "name", ":", "name", ",", "path", ":", "path", ".", "Join", "(", "repoPath", ",", "HookDir", ",", "name", ")", ",", "}", "\n", "if", "isFile", "(", "h", ".", "path", ")", "{", "data", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "h", ".", "path", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "h", ".", "IsActive", "=", "true", "\n", "h", ".", "Content", "=", "string", "(", "data", ")", "\n", "return", "h", ",", "nil", "\n", "}", "\n\n", "// Check sample file", "samplePath", ":=", "path", ".", "Join", "(", "repoPath", ",", "HookSampleDir", ",", "h", ".", "name", ")", "+", "\"", "\"", "\n", "if", "isFile", "(", "samplePath", ")", "{", "data", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "samplePath", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "h", ".", "Sample", "=", "string", "(", "data", ")", "\n", "}", "\n", "return", "h", ",", "nil", "\n", "}" ]
// GetHook returns a Git hook by given name and repository.
[ "GetHook", "returns", "a", "Git", "hook", "by", "given", "name", "and", "repository", "." ]
d1773fe06f37f5e2c92d0ed6dd50c11bf1a17164
https://github.com/gogs/git-module/blob/d1773fe06f37f5e2c92d0ed6dd50c11bf1a17164/hook.go#L51-L79
11,662
gogs/git-module
hook.go
Update
func (h *Hook) Update() error { if len(strings.TrimSpace(h.Content)) == 0 { if isExist(h.path) { return os.Remove(h.path) } return nil } os.MkdirAll(path.Dir(h.path), os.ModePerm) return ioutil.WriteFile(h.path, []byte(strings.Replace(h.Content, "\r", "", -1)), os.ModePerm) }
go
func (h *Hook) Update() error { if len(strings.TrimSpace(h.Content)) == 0 { if isExist(h.path) { return os.Remove(h.path) } return nil } os.MkdirAll(path.Dir(h.path), os.ModePerm) return ioutil.WriteFile(h.path, []byte(strings.Replace(h.Content, "\r", "", -1)), os.ModePerm) }
[ "func", "(", "h", "*", "Hook", ")", "Update", "(", ")", "error", "{", "if", "len", "(", "strings", ".", "TrimSpace", "(", "h", ".", "Content", ")", ")", "==", "0", "{", "if", "isExist", "(", "h", ".", "path", ")", "{", "return", "os", ".", "Remove", "(", "h", ".", "path", ")", "\n", "}", "\n", "return", "nil", "\n", "}", "\n", "os", ".", "MkdirAll", "(", "path", ".", "Dir", "(", "h", ".", "path", ")", ",", "os", ".", "ModePerm", ")", "\n", "return", "ioutil", ".", "WriteFile", "(", "h", ".", "path", ",", "[", "]", "byte", "(", "strings", ".", "Replace", "(", "h", ".", "Content", ",", "\"", "\\r", "\"", ",", "\"", "\"", ",", "-", "1", ")", ")", ",", "os", ".", "ModePerm", ")", "\n", "}" ]
// Update updates content hook file.
[ "Update", "updates", "content", "hook", "file", "." ]
d1773fe06f37f5e2c92d0ed6dd50c11bf1a17164
https://github.com/gogs/git-module/blob/d1773fe06f37f5e2c92d0ed6dd50c11bf1a17164/hook.go#L86-L95
11,663
gogs/git-module
hook.go
ListHooks
func ListHooks(repoPath string) (_ []*Hook, err error) { if !isDir(path.Join(repoPath, "hooks")) { return nil, errors.New("hooks path does not exist") } hooks := make([]*Hook, len(HookNames)) for i, name := range HookNames { hooks[i], err = GetHook(repoPath, name) if err != nil { return nil, err } } return hooks, nil }
go
func ListHooks(repoPath string) (_ []*Hook, err error) { if !isDir(path.Join(repoPath, "hooks")) { return nil, errors.New("hooks path does not exist") } hooks := make([]*Hook, len(HookNames)) for i, name := range HookNames { hooks[i], err = GetHook(repoPath, name) if err != nil { return nil, err } } return hooks, nil }
[ "func", "ListHooks", "(", "repoPath", "string", ")", "(", "_", "[", "]", "*", "Hook", ",", "err", "error", ")", "{", "if", "!", "isDir", "(", "path", ".", "Join", "(", "repoPath", ",", "\"", "\"", ")", ")", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "hooks", ":=", "make", "(", "[", "]", "*", "Hook", ",", "len", "(", "HookNames", ")", ")", "\n", "for", "i", ",", "name", ":=", "range", "HookNames", "{", "hooks", "[", "i", "]", ",", "err", "=", "GetHook", "(", "repoPath", ",", "name", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "}", "\n", "return", "hooks", ",", "nil", "\n", "}" ]
// ListHooks returns a list of Git hooks of given repository.
[ "ListHooks", "returns", "a", "list", "of", "Git", "hooks", "of", "given", "repository", "." ]
d1773fe06f37f5e2c92d0ed6dd50c11bf1a17164
https://github.com/gogs/git-module/blob/d1773fe06f37f5e2c92d0ed6dd50c11bf1a17164/hook.go#L98-L111
11,664
gogs/git-module
submodule.go
RefURL
func (sf *SubModuleFile) RefURL(urlPrefix string, parentPath string) string { if sf.refURL == "" { return "" } url := strings.TrimSuffix(sf.refURL, ".git") // git://xxx/user/repo if strings.HasPrefix(url, "git://") { return "http://" + strings.TrimPrefix(url, "git://") } // http[s]://xxx/user/repo if strings.HasPrefix(url, "http://") || strings.HasPrefix(url, "https://") { return url } // Relative url prefix check (according to git submodule documentation) if strings.HasPrefix(url, "./") || strings.HasPrefix(url, "../") { // ...construct and return correct submodule url here... idx := strings.Index(parentPath, "/src/") if idx == -1 { return url } return strings.TrimSuffix(urlPrefix, "/") + parentPath[:idx] + "/" + url } // sysuser@xxx:user/repo i := strings.Index(url, "@") j := strings.LastIndex(url, ":") // Only process when i < j because git+ssh://[email protected]/npploader.git if i > -1 && j > -1 && i < j { // fix problem with reverse proxy works only with local server if strings.Contains(urlPrefix, url[i+1:j]) { return urlPrefix + url[j+1:] } else { return "http://" + url[i+1:j] + "/" + url[j+1:] } } return url }
go
func (sf *SubModuleFile) RefURL(urlPrefix string, parentPath string) string { if sf.refURL == "" { return "" } url := strings.TrimSuffix(sf.refURL, ".git") // git://xxx/user/repo if strings.HasPrefix(url, "git://") { return "http://" + strings.TrimPrefix(url, "git://") } // http[s]://xxx/user/repo if strings.HasPrefix(url, "http://") || strings.HasPrefix(url, "https://") { return url } // Relative url prefix check (according to git submodule documentation) if strings.HasPrefix(url, "./") || strings.HasPrefix(url, "../") { // ...construct and return correct submodule url here... idx := strings.Index(parentPath, "/src/") if idx == -1 { return url } return strings.TrimSuffix(urlPrefix, "/") + parentPath[:idx] + "/" + url } // sysuser@xxx:user/repo i := strings.Index(url, "@") j := strings.LastIndex(url, ":") // Only process when i < j because git+ssh://[email protected]/npploader.git if i > -1 && j > -1 && i < j { // fix problem with reverse proxy works only with local server if strings.Contains(urlPrefix, url[i+1:j]) { return urlPrefix + url[j+1:] } else { return "http://" + url[i+1:j] + "/" + url[j+1:] } } return url }
[ "func", "(", "sf", "*", "SubModuleFile", ")", "RefURL", "(", "urlPrefix", "string", ",", "parentPath", "string", ")", "string", "{", "if", "sf", ".", "refURL", "==", "\"", "\"", "{", "return", "\"", "\"", "\n", "}", "\n\n", "url", ":=", "strings", ".", "TrimSuffix", "(", "sf", ".", "refURL", ",", "\"", "\"", ")", "\n\n", "// git://xxx/user/repo", "if", "strings", ".", "HasPrefix", "(", "url", ",", "\"", "\"", ")", "{", "return", "\"", "\"", "+", "strings", ".", "TrimPrefix", "(", "url", ",", "\"", "\"", ")", "\n", "}", "\n\n", "// http[s]://xxx/user/repo", "if", "strings", ".", "HasPrefix", "(", "url", ",", "\"", "\"", ")", "||", "strings", ".", "HasPrefix", "(", "url", ",", "\"", "\"", ")", "{", "return", "url", "\n", "}", "\n\n", "// Relative url prefix check (according to git submodule documentation)", "if", "strings", ".", "HasPrefix", "(", "url", ",", "\"", "\"", ")", "||", "strings", ".", "HasPrefix", "(", "url", ",", "\"", "\"", ")", "{", "// ...construct and return correct submodule url here...", "idx", ":=", "strings", ".", "Index", "(", "parentPath", ",", "\"", "\"", ")", "\n", "if", "idx", "==", "-", "1", "{", "return", "url", "\n", "}", "\n", "return", "strings", ".", "TrimSuffix", "(", "urlPrefix", ",", "\"", "\"", ")", "+", "parentPath", "[", ":", "idx", "]", "+", "\"", "\"", "+", "url", "\n", "}", "\n\n", "// sysuser@xxx:user/repo", "i", ":=", "strings", ".", "Index", "(", "url", ",", "\"", "\"", ")", "\n", "j", ":=", "strings", ".", "LastIndex", "(", "url", ",", "\"", "\"", ")", "\n\n", "// Only process when i < j because git+ssh://[email protected]/npploader.git", "if", "i", ">", "-", "1", "&&", "j", ">", "-", "1", "&&", "i", "<", "j", "{", "// fix problem with reverse proxy works only with local server", "if", "strings", ".", "Contains", "(", "urlPrefix", ",", "url", "[", "i", "+", "1", ":", "j", "]", ")", "{", "return", "urlPrefix", "+", "url", "[", "j", "+", "1", ":", "]", "\n", "}", "else", "{", "return", "\"", "\"", "+", "url", "[", "i", "+", "1", ":", "j", "]", "+", "\"", "\"", "+", "url", "[", "j", "+", "1", ":", "]", "\n", "}", "\n", "}", "\n\n", "return", "url", "\n", "}" ]
// RefURL guesses and returns reference URL.
[ "RefURL", "guesses", "and", "returns", "reference", "URL", "." ]
d1773fe06f37f5e2c92d0ed6dd50c11bf1a17164
https://github.com/gogs/git-module/blob/d1773fe06f37f5e2c92d0ed6dd50c11bf1a17164/submodule.go#L31-L73
11,665
gogs/git-module
git.go
BinVersion
func BinVersion() (string, error) { if len(gitVersion) > 0 { return gitVersion, nil } stdout, err := NewCommand("version").Run() if err != nil { return "", err } fields := strings.Fields(stdout) if len(fields) < 3 { return "", fmt.Errorf("not enough output: %s", stdout) } // Handle special case on Windows. i := strings.Index(fields[2], "windows") if i >= 1 { gitVersion = fields[2][:i-1] return gitVersion, nil } gitVersion = fields[2] return gitVersion, nil }
go
func BinVersion() (string, error) { if len(gitVersion) > 0 { return gitVersion, nil } stdout, err := NewCommand("version").Run() if err != nil { return "", err } fields := strings.Fields(stdout) if len(fields) < 3 { return "", fmt.Errorf("not enough output: %s", stdout) } // Handle special case on Windows. i := strings.Index(fields[2], "windows") if i >= 1 { gitVersion = fields[2][:i-1] return gitVersion, nil } gitVersion = fields[2] return gitVersion, nil }
[ "func", "BinVersion", "(", ")", "(", "string", ",", "error", ")", "{", "if", "len", "(", "gitVersion", ")", ">", "0", "{", "return", "gitVersion", ",", "nil", "\n", "}", "\n\n", "stdout", ",", "err", ":=", "NewCommand", "(", "\"", "\"", ")", ".", "Run", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n\n", "fields", ":=", "strings", ".", "Fields", "(", "stdout", ")", "\n", "if", "len", "(", "fields", ")", "<", "3", "{", "return", "\"", "\"", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "stdout", ")", "\n", "}", "\n\n", "// Handle special case on Windows.", "i", ":=", "strings", ".", "Index", "(", "fields", "[", "2", "]", ",", "\"", "\"", ")", "\n", "if", "i", ">=", "1", "{", "gitVersion", "=", "fields", "[", "2", "]", "[", ":", "i", "-", "1", "]", "\n", "return", "gitVersion", ",", "nil", "\n", "}", "\n\n", "gitVersion", "=", "fields", "[", "2", "]", "\n", "return", "gitVersion", ",", "nil", "\n", "}" ]
// Version returns current Git version from shell.
[ "Version", "returns", "current", "Git", "version", "from", "shell", "." ]
d1773fe06f37f5e2c92d0ed6dd50c11bf1a17164
https://github.com/gogs/git-module/blob/d1773fe06f37f5e2c92d0ed6dd50c11bf1a17164/git.go#L42-L66
11,666
gogs/git-module
git.go
Fsck
func Fsck(repoPath string, timeout time.Duration, args ...string) error { // Make sure timeout makes sense. if timeout <= 0 { timeout = -1 } _, err := NewCommand("fsck").AddArguments(args...).RunInDirTimeout(timeout, repoPath) return err }
go
func Fsck(repoPath string, timeout time.Duration, args ...string) error { // Make sure timeout makes sense. if timeout <= 0 { timeout = -1 } _, err := NewCommand("fsck").AddArguments(args...).RunInDirTimeout(timeout, repoPath) return err }
[ "func", "Fsck", "(", "repoPath", "string", ",", "timeout", "time", ".", "Duration", ",", "args", "...", "string", ")", "error", "{", "// Make sure timeout makes sense.", "if", "timeout", "<=", "0", "{", "timeout", "=", "-", "1", "\n", "}", "\n", "_", ",", "err", ":=", "NewCommand", "(", "\"", "\"", ")", ".", "AddArguments", "(", "args", "...", ")", ".", "RunInDirTimeout", "(", "timeout", ",", "repoPath", ")", "\n", "return", "err", "\n", "}" ]
// Fsck verifies the connectivity and validity of the objects in the database
[ "Fsck", "verifies", "the", "connectivity", "and", "validity", "of", "the", "objects", "in", "the", "database" ]
d1773fe06f37f5e2c92d0ed6dd50c11bf1a17164
https://github.com/gogs/git-module/blob/d1773fe06f37f5e2c92d0ed6dd50c11bf1a17164/git.go#L73-L80
11,667
gogs/git-module
repo_tree.go
GetTree
func (repo *Repository) GetTree(idStr string) (*Tree, error) { id, err := NewIDFromString(idStr) if err != nil { return nil, err } return repo.getTree(id) }
go
func (repo *Repository) GetTree(idStr string) (*Tree, error) { id, err := NewIDFromString(idStr) if err != nil { return nil, err } return repo.getTree(id) }
[ "func", "(", "repo", "*", "Repository", ")", "GetTree", "(", "idStr", "string", ")", "(", "*", "Tree", ",", "error", ")", "{", "id", ",", "err", ":=", "NewIDFromString", "(", "idStr", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "repo", ".", "getTree", "(", "id", ")", "\n", "}" ]
// Find the tree object in the repository.
[ "Find", "the", "tree", "object", "in", "the", "repository", "." ]
d1773fe06f37f5e2c92d0ed6dd50c11bf1a17164
https://github.com/gogs/git-module/blob/d1773fe06f37f5e2c92d0ed6dd50c11bf1a17164/repo_tree.go#L20-L26
11,668
gogs/git-module
command.go
AddEnvs
func (c *Command) AddEnvs(envs ...string) *Command { c.envs = append(c.envs, envs...) return c }
go
func (c *Command) AddEnvs(envs ...string) *Command { c.envs = append(c.envs, envs...) return c }
[ "func", "(", "c", "*", "Command", ")", "AddEnvs", "(", "envs", "...", "string", ")", "*", "Command", "{", "c", ".", "envs", "=", "append", "(", "c", ".", "envs", ",", "envs", "...", ")", "\n", "return", "c", "\n", "}" ]
// AddEnvs adds new environment variables to the command.
[ "AddEnvs", "adds", "new", "environment", "variables", "to", "the", "command", "." ]
d1773fe06f37f5e2c92d0ed6dd50c11bf1a17164
https://github.com/gogs/git-module/blob/d1773fe06f37f5e2c92d0ed6dd50c11bf1a17164/command.go#L46-L49
11,669
gogs/git-module
command.go
RunInDirTimeoutPipeline
func (c *Command) RunInDirTimeoutPipeline(timeout time.Duration, dir string, stdout, stderr io.Writer) error { if timeout == -1 { timeout = DEFAULT_TIMEOUT } if len(dir) == 0 { log(c.String()) } else { log("%s: %v", dir, c) } cmd := exec.Command(c.name, c.args...) if c.envs != nil { cmd.Env = append(os.Environ(), c.envs...) } cmd.Dir = dir cmd.Stdout = stdout cmd.Stderr = stderr if err := cmd.Start(); err != nil { return err } done := make(chan error) go func() { done <- cmd.Wait() }() var err error select { case <-time.After(timeout): if cmd.Process != nil && cmd.ProcessState != nil && !cmd.ProcessState.Exited() { if err := cmd.Process.Kill(); err != nil { return fmt.Errorf("fail to kill process: %v", err) } } <-done return ErrExecTimeout{timeout} case err = <-done: } return err }
go
func (c *Command) RunInDirTimeoutPipeline(timeout time.Duration, dir string, stdout, stderr io.Writer) error { if timeout == -1 { timeout = DEFAULT_TIMEOUT } if len(dir) == 0 { log(c.String()) } else { log("%s: %v", dir, c) } cmd := exec.Command(c.name, c.args...) if c.envs != nil { cmd.Env = append(os.Environ(), c.envs...) } cmd.Dir = dir cmd.Stdout = stdout cmd.Stderr = stderr if err := cmd.Start(); err != nil { return err } done := make(chan error) go func() { done <- cmd.Wait() }() var err error select { case <-time.After(timeout): if cmd.Process != nil && cmd.ProcessState != nil && !cmd.ProcessState.Exited() { if err := cmd.Process.Kill(); err != nil { return fmt.Errorf("fail to kill process: %v", err) } } <-done return ErrExecTimeout{timeout} case err = <-done: } return err }
[ "func", "(", "c", "*", "Command", ")", "RunInDirTimeoutPipeline", "(", "timeout", "time", ".", "Duration", ",", "dir", "string", ",", "stdout", ",", "stderr", "io", ".", "Writer", ")", "error", "{", "if", "timeout", "==", "-", "1", "{", "timeout", "=", "DEFAULT_TIMEOUT", "\n", "}", "\n\n", "if", "len", "(", "dir", ")", "==", "0", "{", "log", "(", "c", ".", "String", "(", ")", ")", "\n", "}", "else", "{", "log", "(", "\"", "\"", ",", "dir", ",", "c", ")", "\n", "}", "\n\n", "cmd", ":=", "exec", ".", "Command", "(", "c", ".", "name", ",", "c", ".", "args", "...", ")", "\n", "if", "c", ".", "envs", "!=", "nil", "{", "cmd", ".", "Env", "=", "append", "(", "os", ".", "Environ", "(", ")", ",", "c", ".", "envs", "...", ")", "\n", "}", "\n", "cmd", ".", "Dir", "=", "dir", "\n", "cmd", ".", "Stdout", "=", "stdout", "\n", "cmd", ".", "Stderr", "=", "stderr", "\n", "if", "err", ":=", "cmd", ".", "Start", "(", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "done", ":=", "make", "(", "chan", "error", ")", "\n", "go", "func", "(", ")", "{", "done", "<-", "cmd", ".", "Wait", "(", ")", "\n", "}", "(", ")", "\n\n", "var", "err", "error", "\n", "select", "{", "case", "<-", "time", ".", "After", "(", "timeout", ")", ":", "if", "cmd", ".", "Process", "!=", "nil", "&&", "cmd", ".", "ProcessState", "!=", "nil", "&&", "!", "cmd", ".", "ProcessState", ".", "Exited", "(", ")", "{", "if", "err", ":=", "cmd", ".", "Process", ".", "Kill", "(", ")", ";", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "}", "\n\n", "<-", "done", "\n", "return", "ErrExecTimeout", "{", "timeout", "}", "\n", "case", "err", "=", "<-", "done", ":", "}", "\n\n", "return", "err", "\n", "}" ]
// RunInDirTimeoutPipeline executes the command in given directory with given timeout, // it pipes stdout and stderr to given io.Writer.
[ "RunInDirTimeoutPipeline", "executes", "the", "command", "in", "given", "directory", "with", "given", "timeout", "it", "pipes", "stdout", "and", "stderr", "to", "given", "io", ".", "Writer", "." ]
d1773fe06f37f5e2c92d0ed6dd50c11bf1a17164
https://github.com/gogs/git-module/blob/d1773fe06f37f5e2c92d0ed6dd50c11bf1a17164/command.go#L55-L97
11,670
gogs/git-module
command.go
RunInDirPipeline
func (c *Command) RunInDirPipeline(dir string, stdout, stderr io.Writer) error { return c.RunInDirTimeoutPipeline(-1, dir, stdout, stderr) }
go
func (c *Command) RunInDirPipeline(dir string, stdout, stderr io.Writer) error { return c.RunInDirTimeoutPipeline(-1, dir, stdout, stderr) }
[ "func", "(", "c", "*", "Command", ")", "RunInDirPipeline", "(", "dir", "string", ",", "stdout", ",", "stderr", "io", ".", "Writer", ")", "error", "{", "return", "c", ".", "RunInDirTimeoutPipeline", "(", "-", "1", ",", "dir", ",", "stdout", ",", "stderr", ")", "\n", "}" ]
// RunInDirPipeline executes the command in given directory, // it pipes stdout and stderr to given io.Writer.
[ "RunInDirPipeline", "executes", "the", "command", "in", "given", "directory", "it", "pipes", "stdout", "and", "stderr", "to", "given", "io", ".", "Writer", "." ]
d1773fe06f37f5e2c92d0ed6dd50c11bf1a17164
https://github.com/gogs/git-module/blob/d1773fe06f37f5e2c92d0ed6dd50c11bf1a17164/command.go#L116-L118
11,671
gogs/git-module
repo_branch.go
IsReferenceExist
func IsReferenceExist(repoPath, name string) bool { _, err := NewCommand("show-ref", "--verify", name).RunInDir(repoPath) return err == nil }
go
func IsReferenceExist(repoPath, name string) bool { _, err := NewCommand("show-ref", "--verify", name).RunInDir(repoPath) return err == nil }
[ "func", "IsReferenceExist", "(", "repoPath", ",", "name", "string", ")", "bool", "{", "_", ",", "err", ":=", "NewCommand", "(", "\"", "\"", ",", "\"", "\"", ",", "name", ")", ".", "RunInDir", "(", "repoPath", ")", "\n", "return", "err", "==", "nil", "\n", "}" ]
// IsReferenceExist returns true if given reference exists in the repository.
[ "IsReferenceExist", "returns", "true", "if", "given", "reference", "exists", "in", "the", "repository", "." ]
d1773fe06f37f5e2c92d0ed6dd50c11bf1a17164
https://github.com/gogs/git-module/blob/d1773fe06f37f5e2c92d0ed6dd50c11bf1a17164/repo_branch.go#L17-L20
11,672
gogs/git-module
repo_branch.go
GetHEADBranch
func (repo *Repository) GetHEADBranch() (*Branch, error) { stdout, err := NewCommand("symbolic-ref", "HEAD").RunInDir(repo.Path) if err != nil { return nil, err } stdout = strings.TrimSpace(stdout) if !strings.HasPrefix(stdout, BRANCH_PREFIX) { return nil, fmt.Errorf("invalid HEAD branch: %v", stdout) } return &Branch{ Name: stdout[len(BRANCH_PREFIX):], Path: stdout, }, nil }
go
func (repo *Repository) GetHEADBranch() (*Branch, error) { stdout, err := NewCommand("symbolic-ref", "HEAD").RunInDir(repo.Path) if err != nil { return nil, err } stdout = strings.TrimSpace(stdout) if !strings.HasPrefix(stdout, BRANCH_PREFIX) { return nil, fmt.Errorf("invalid HEAD branch: %v", stdout) } return &Branch{ Name: stdout[len(BRANCH_PREFIX):], Path: stdout, }, nil }
[ "func", "(", "repo", "*", "Repository", ")", "GetHEADBranch", "(", ")", "(", "*", "Branch", ",", "error", ")", "{", "stdout", ",", "err", ":=", "NewCommand", "(", "\"", "\"", ",", "\"", "\"", ")", ".", "RunInDir", "(", "repo", ".", "Path", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "stdout", "=", "strings", ".", "TrimSpace", "(", "stdout", ")", "\n\n", "if", "!", "strings", ".", "HasPrefix", "(", "stdout", ",", "BRANCH_PREFIX", ")", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "stdout", ")", "\n", "}", "\n\n", "return", "&", "Branch", "{", "Name", ":", "stdout", "[", "len", "(", "BRANCH_PREFIX", ")", ":", "]", ",", "Path", ":", "stdout", ",", "}", ",", "nil", "\n", "}" ]
// GetHEADBranch returns corresponding branch of HEAD.
[ "GetHEADBranch", "returns", "corresponding", "branch", "of", "HEAD", "." ]
d1773fe06f37f5e2c92d0ed6dd50c11bf1a17164
https://github.com/gogs/git-module/blob/d1773fe06f37f5e2c92d0ed6dd50c11bf1a17164/repo_branch.go#L38-L53
11,673
gogs/git-module
repo_branch.go
SetDefaultBranch
func (repo *Repository) SetDefaultBranch(name string) error { if version.Compare(gitVersion, "1.7.10", "<") { return ErrUnsupportedVersion{"1.7.10"} } _, err := NewCommand("symbolic-ref", "HEAD", BRANCH_PREFIX+name).RunInDir(repo.Path) return err }
go
func (repo *Repository) SetDefaultBranch(name string) error { if version.Compare(gitVersion, "1.7.10", "<") { return ErrUnsupportedVersion{"1.7.10"} } _, err := NewCommand("symbolic-ref", "HEAD", BRANCH_PREFIX+name).RunInDir(repo.Path) return err }
[ "func", "(", "repo", "*", "Repository", ")", "SetDefaultBranch", "(", "name", "string", ")", "error", "{", "if", "version", ".", "Compare", "(", "gitVersion", ",", "\"", "\"", ",", "\"", "\"", ")", "{", "return", "ErrUnsupportedVersion", "{", "\"", "\"", "}", "\n", "}", "\n\n", "_", ",", "err", ":=", "NewCommand", "(", "\"", "\"", ",", "\"", "\"", ",", "BRANCH_PREFIX", "+", "name", ")", ".", "RunInDir", "(", "repo", ".", "Path", ")", "\n", "return", "err", "\n", "}" ]
// SetDefaultBranch sets default branch of repository.
[ "SetDefaultBranch", "sets", "default", "branch", "of", "repository", "." ]
d1773fe06f37f5e2c92d0ed6dd50c11bf1a17164
https://github.com/gogs/git-module/blob/d1773fe06f37f5e2c92d0ed6dd50c11bf1a17164/repo_branch.go#L56-L63
11,674
gogs/git-module
repo_branch.go
GetBranches
func (repo *Repository) GetBranches() ([]string, error) { stdout, err := NewCommand("show-ref", "--heads").RunInDir(repo.Path) if err != nil { return nil, err } infos := strings.Split(stdout, "\n") branches := make([]string, len(infos)-1) for i, info := range infos[:len(infos)-1] { fields := strings.Fields(info) if len(fields) != 2 { continue // NOTE: I should believe git will not give me wrong string. } branches[i] = strings.TrimPrefix(fields[1], BRANCH_PREFIX) } return branches, nil }
go
func (repo *Repository) GetBranches() ([]string, error) { stdout, err := NewCommand("show-ref", "--heads").RunInDir(repo.Path) if err != nil { return nil, err } infos := strings.Split(stdout, "\n") branches := make([]string, len(infos)-1) for i, info := range infos[:len(infos)-1] { fields := strings.Fields(info) if len(fields) != 2 { continue // NOTE: I should believe git will not give me wrong string. } branches[i] = strings.TrimPrefix(fields[1], BRANCH_PREFIX) } return branches, nil }
[ "func", "(", "repo", "*", "Repository", ")", "GetBranches", "(", ")", "(", "[", "]", "string", ",", "error", ")", "{", "stdout", ",", "err", ":=", "NewCommand", "(", "\"", "\"", ",", "\"", "\"", ")", ".", "RunInDir", "(", "repo", ".", "Path", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "infos", ":=", "strings", ".", "Split", "(", "stdout", ",", "\"", "\\n", "\"", ")", "\n", "branches", ":=", "make", "(", "[", "]", "string", ",", "len", "(", "infos", ")", "-", "1", ")", "\n", "for", "i", ",", "info", ":=", "range", "infos", "[", ":", "len", "(", "infos", ")", "-", "1", "]", "{", "fields", ":=", "strings", ".", "Fields", "(", "info", ")", "\n", "if", "len", "(", "fields", ")", "!=", "2", "{", "continue", "// NOTE: I should believe git will not give me wrong string.", "\n", "}", "\n", "branches", "[", "i", "]", "=", "strings", ".", "TrimPrefix", "(", "fields", "[", "1", "]", ",", "BRANCH_PREFIX", ")", "\n", "}", "\n", "return", "branches", ",", "nil", "\n", "}" ]
// GetBranches returns all branches of the repository.
[ "GetBranches", "returns", "all", "branches", "of", "the", "repository", "." ]
d1773fe06f37f5e2c92d0ed6dd50c11bf1a17164
https://github.com/gogs/git-module/blob/d1773fe06f37f5e2c92d0ed6dd50c11bf1a17164/repo_branch.go#L66-L82
11,675
gogs/git-module
repo_branch.go
DeleteBranch
func DeleteBranch(repoPath, name string, opts DeleteBranchOptions) error { cmd := NewCommand("branch") if opts.Force { cmd.AddArguments("-D") } else { cmd.AddArguments("-d") } cmd.AddArguments(name) _, err := cmd.RunInDir(repoPath) return err }
go
func DeleteBranch(repoPath, name string, opts DeleteBranchOptions) error { cmd := NewCommand("branch") if opts.Force { cmd.AddArguments("-D") } else { cmd.AddArguments("-d") } cmd.AddArguments(name) _, err := cmd.RunInDir(repoPath) return err }
[ "func", "DeleteBranch", "(", "repoPath", ",", "name", "string", ",", "opts", "DeleteBranchOptions", ")", "error", "{", "cmd", ":=", "NewCommand", "(", "\"", "\"", ")", "\n\n", "if", "opts", ".", "Force", "{", "cmd", ".", "AddArguments", "(", "\"", "\"", ")", "\n", "}", "else", "{", "cmd", ".", "AddArguments", "(", "\"", "\"", ")", "\n", "}", "\n\n", "cmd", ".", "AddArguments", "(", "name", ")", "\n", "_", ",", "err", ":=", "cmd", ".", "RunInDir", "(", "repoPath", ")", "\n\n", "return", "err", "\n", "}" ]
// DeleteBranch deletes a branch from given repository path.
[ "DeleteBranch", "deletes", "a", "branch", "from", "given", "repository", "path", "." ]
d1773fe06f37f5e2c92d0ed6dd50c11bf1a17164
https://github.com/gogs/git-module/blob/d1773fe06f37f5e2c92d0ed6dd50c11bf1a17164/repo_branch.go#L90-L103
11,676
gogs/git-module
repo_branch.go
DeleteBranch
func (repo *Repository) DeleteBranch(name string, opts DeleteBranchOptions) error { return DeleteBranch(repo.Path, name, opts) }
go
func (repo *Repository) DeleteBranch(name string, opts DeleteBranchOptions) error { return DeleteBranch(repo.Path, name, opts) }
[ "func", "(", "repo", "*", "Repository", ")", "DeleteBranch", "(", "name", "string", ",", "opts", "DeleteBranchOptions", ")", "error", "{", "return", "DeleteBranch", "(", "repo", ".", "Path", ",", "name", ",", "opts", ")", "\n", "}" ]
// DeleteBranch deletes a branch from repository.
[ "DeleteBranch", "deletes", "a", "branch", "from", "repository", "." ]
d1773fe06f37f5e2c92d0ed6dd50c11bf1a17164
https://github.com/gogs/git-module/blob/d1773fe06f37f5e2c92d0ed6dd50c11bf1a17164/repo_branch.go#L106-L108
11,677
gogs/git-module
repo_branch.go
AddRemote
func (repo *Repository) AddRemote(name, url string, fetch bool) error { cmd := NewCommand("remote", "add") if fetch { cmd.AddArguments("-f") } cmd.AddArguments(name, url) _, err := cmd.RunInDir(repo.Path) return err }
go
func (repo *Repository) AddRemote(name, url string, fetch bool) error { cmd := NewCommand("remote", "add") if fetch { cmd.AddArguments("-f") } cmd.AddArguments(name, url) _, err := cmd.RunInDir(repo.Path) return err }
[ "func", "(", "repo", "*", "Repository", ")", "AddRemote", "(", "name", ",", "url", "string", ",", "fetch", "bool", ")", "error", "{", "cmd", ":=", "NewCommand", "(", "\"", "\"", ",", "\"", "\"", ")", "\n", "if", "fetch", "{", "cmd", ".", "AddArguments", "(", "\"", "\"", ")", "\n", "}", "\n", "cmd", ".", "AddArguments", "(", "name", ",", "url", ")", "\n\n", "_", ",", "err", ":=", "cmd", ".", "RunInDir", "(", "repo", ".", "Path", ")", "\n", "return", "err", "\n", "}" ]
// AddRemote adds a new remote to repository.
[ "AddRemote", "adds", "a", "new", "remote", "to", "repository", "." ]
d1773fe06f37f5e2c92d0ed6dd50c11bf1a17164
https://github.com/gogs/git-module/blob/d1773fe06f37f5e2c92d0ed6dd50c11bf1a17164/repo_branch.go#L111-L120
11,678
gogs/git-module
repo_branch.go
RemoveRemote
func (repo *Repository) RemoveRemote(name string) error { _, err := NewCommand("remote", "remove", name).RunInDir(repo.Path) return err }
go
func (repo *Repository) RemoveRemote(name string) error { _, err := NewCommand("remote", "remove", name).RunInDir(repo.Path) return err }
[ "func", "(", "repo", "*", "Repository", ")", "RemoveRemote", "(", "name", "string", ")", "error", "{", "_", ",", "err", ":=", "NewCommand", "(", "\"", "\"", ",", "\"", "\"", ",", "name", ")", ".", "RunInDir", "(", "repo", ".", "Path", ")", "\n", "return", "err", "\n", "}" ]
// RemoveRemote removes a remote from repository.
[ "RemoveRemote", "removes", "a", "remote", "from", "repository", "." ]
d1773fe06f37f5e2c92d0ed6dd50c11bf1a17164
https://github.com/gogs/git-module/blob/d1773fe06f37f5e2c92d0ed6dd50c11bf1a17164/repo_branch.go#L123-L126
11,679
gogs/git-module
blob.go
Data
func (b *Blob) Data() (io.Reader, error) { stdout := new(bytes.Buffer) stderr := new(bytes.Buffer) // Preallocate memory to save ~50% memory usage on big files. stdout.Grow(int(b.Size() + 2048)) if err := b.DataPipeline(stdout, stderr); err != nil { return nil, concatenateError(err, stderr.String()) } return stdout, nil }
go
func (b *Blob) Data() (io.Reader, error) { stdout := new(bytes.Buffer) stderr := new(bytes.Buffer) // Preallocate memory to save ~50% memory usage on big files. stdout.Grow(int(b.Size() + 2048)) if err := b.DataPipeline(stdout, stderr); err != nil { return nil, concatenateError(err, stderr.String()) } return stdout, nil }
[ "func", "(", "b", "*", "Blob", ")", "Data", "(", ")", "(", "io", ".", "Reader", ",", "error", ")", "{", "stdout", ":=", "new", "(", "bytes", ".", "Buffer", ")", "\n", "stderr", ":=", "new", "(", "bytes", ".", "Buffer", ")", "\n\n", "// Preallocate memory to save ~50% memory usage on big files.", "stdout", ".", "Grow", "(", "int", "(", "b", ".", "Size", "(", ")", "+", "2048", ")", ")", "\n\n", "if", "err", ":=", "b", ".", "DataPipeline", "(", "stdout", ",", "stderr", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "concatenateError", "(", "err", ",", "stderr", ".", "String", "(", ")", ")", "\n", "}", "\n", "return", "stdout", ",", "nil", "\n", "}" ]
// Data gets content of blob all at once and wrap it as io.Reader. // This can be very slow and memory consuming for huge content.
[ "Data", "gets", "content", "of", "blob", "all", "at", "once", "and", "wrap", "it", "as", "io", ".", "Reader", ".", "This", "can", "be", "very", "slow", "and", "memory", "consuming", "for", "huge", "content", "." ]
d1773fe06f37f5e2c92d0ed6dd50c11bf1a17164
https://github.com/gogs/git-module/blob/d1773fe06f37f5e2c92d0ed6dd50c11bf1a17164/blob.go#L20-L31
11,680
gogs/git-module
sha1.go
MustIDFromString
func MustIDFromString(s string) sha1 { b, _ := hex.DecodeString(s) return MustID(b) }
go
func MustIDFromString(s string) sha1 { b, _ := hex.DecodeString(s) return MustID(b) }
[ "func", "MustIDFromString", "(", "s", "string", ")", "sha1", "{", "b", ",", "_", ":=", "hex", ".", "DecodeString", "(", "s", ")", "\n", "return", "MustID", "(", "b", ")", "\n", "}" ]
// MustIDFromString always creates a new sha from a ID with no validation of input.
[ "MustIDFromString", "always", "creates", "a", "new", "sha", "from", "a", "ID", "with", "no", "validation", "of", "input", "." ]
d1773fe06f37f5e2c92d0ed6dd50c11bf1a17164
https://github.com/gogs/git-module/blob/d1773fe06f37f5e2c92d0ed6dd50c11bf1a17164/sha1.go#L76-L79
11,681
gogs/git-module
sha1.go
NewIDFromString
func NewIDFromString(s string) (sha1, error) { var id sha1 s = strings.TrimSpace(s) if len(s) != 40 { return id, fmt.Errorf("Length must be 40: %s", s) } b, err := hex.DecodeString(s) if err != nil { return id, err } return NewID(b) }
go
func NewIDFromString(s string) (sha1, error) { var id sha1 s = strings.TrimSpace(s) if len(s) != 40 { return id, fmt.Errorf("Length must be 40: %s", s) } b, err := hex.DecodeString(s) if err != nil { return id, err } return NewID(b) }
[ "func", "NewIDFromString", "(", "s", "string", ")", "(", "sha1", ",", "error", ")", "{", "var", "id", "sha1", "\n", "s", "=", "strings", ".", "TrimSpace", "(", "s", ")", "\n", "if", "len", "(", "s", ")", "!=", "40", "{", "return", "id", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "s", ")", "\n", "}", "\n", "b", ",", "err", ":=", "hex", ".", "DecodeString", "(", "s", ")", "\n", "if", "err", "!=", "nil", "{", "return", "id", ",", "err", "\n", "}", "\n", "return", "NewID", "(", "b", ")", "\n", "}" ]
// NewIDFromString creates a new sha1 from a ID string of length 40.
[ "NewIDFromString", "creates", "a", "new", "sha1", "from", "a", "ID", "string", "of", "length", "40", "." ]
d1773fe06f37f5e2c92d0ed6dd50c11bf1a17164
https://github.com/gogs/git-module/blob/d1773fe06f37f5e2c92d0ed6dd50c11bf1a17164/sha1.go#L82-L93
11,682
gogs/git-module
repo_diff.go
GetDiffRange
func GetDiffRange(repoPath, beforeCommitID, afterCommitID string, maxLines, maxLineCharacteres, maxFiles int) (*Diff, error) { repo, err := OpenRepository(repoPath) if err != nil { return nil, err } commit, err := repo.GetCommit(afterCommitID) if err != nil { return nil, err } cmd := NewCommand() if len(beforeCommitID) == 0 { // First commit of repository if commit.ParentCount() == 0 { cmd.AddArguments("show", "--full-index", afterCommitID) } else { c, _ := commit.Parent(0) cmd.AddArguments("diff", "--full-index", "-M", c.ID.String(), afterCommitID) } } else { cmd.AddArguments("diff", "--full-index", "-M", beforeCommitID, afterCommitID) } stdout, w := io.Pipe() done := make(chan error) var diff *Diff go func() { diff = ParsePatch(done, maxLines, maxLineCharacteres, maxFiles, stdout) }() stderr := new(bytes.Buffer) err = cmd.RunInDirTimeoutPipeline(2*time.Minute, repoPath, w, stderr) w.Close() // Close writer to exit parsing goroutine if err != nil { return nil, concatenateError(err, stderr.String()) } return diff, <-done }
go
func GetDiffRange(repoPath, beforeCommitID, afterCommitID string, maxLines, maxLineCharacteres, maxFiles int) (*Diff, error) { repo, err := OpenRepository(repoPath) if err != nil { return nil, err } commit, err := repo.GetCommit(afterCommitID) if err != nil { return nil, err } cmd := NewCommand() if len(beforeCommitID) == 0 { // First commit of repository if commit.ParentCount() == 0 { cmd.AddArguments("show", "--full-index", afterCommitID) } else { c, _ := commit.Parent(0) cmd.AddArguments("diff", "--full-index", "-M", c.ID.String(), afterCommitID) } } else { cmd.AddArguments("diff", "--full-index", "-M", beforeCommitID, afterCommitID) } stdout, w := io.Pipe() done := make(chan error) var diff *Diff go func() { diff = ParsePatch(done, maxLines, maxLineCharacteres, maxFiles, stdout) }() stderr := new(bytes.Buffer) err = cmd.RunInDirTimeoutPipeline(2*time.Minute, repoPath, w, stderr) w.Close() // Close writer to exit parsing goroutine if err != nil { return nil, concatenateError(err, stderr.String()) } return diff, <-done }
[ "func", "GetDiffRange", "(", "repoPath", ",", "beforeCommitID", ",", "afterCommitID", "string", ",", "maxLines", ",", "maxLineCharacteres", ",", "maxFiles", "int", ")", "(", "*", "Diff", ",", "error", ")", "{", "repo", ",", "err", ":=", "OpenRepository", "(", "repoPath", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "commit", ",", "err", ":=", "repo", ".", "GetCommit", "(", "afterCommitID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "cmd", ":=", "NewCommand", "(", ")", "\n", "if", "len", "(", "beforeCommitID", ")", "==", "0", "{", "// First commit of repository", "if", "commit", ".", "ParentCount", "(", ")", "==", "0", "{", "cmd", ".", "AddArguments", "(", "\"", "\"", ",", "\"", "\"", ",", "afterCommitID", ")", "\n", "}", "else", "{", "c", ",", "_", ":=", "commit", ".", "Parent", "(", "0", ")", "\n", "cmd", ".", "AddArguments", "(", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "c", ".", "ID", ".", "String", "(", ")", ",", "afterCommitID", ")", "\n", "}", "\n", "}", "else", "{", "cmd", ".", "AddArguments", "(", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "beforeCommitID", ",", "afterCommitID", ")", "\n", "}", "\n\n", "stdout", ",", "w", ":=", "io", ".", "Pipe", "(", ")", "\n", "done", ":=", "make", "(", "chan", "error", ")", "\n", "var", "diff", "*", "Diff", "\n", "go", "func", "(", ")", "{", "diff", "=", "ParsePatch", "(", "done", ",", "maxLines", ",", "maxLineCharacteres", ",", "maxFiles", ",", "stdout", ")", "\n", "}", "(", ")", "\n\n", "stderr", ":=", "new", "(", "bytes", ".", "Buffer", ")", "\n", "err", "=", "cmd", ".", "RunInDirTimeoutPipeline", "(", "2", "*", "time", ".", "Minute", ",", "repoPath", ",", "w", ",", "stderr", ")", "\n", "w", ".", "Close", "(", ")", "// Close writer to exit parsing goroutine", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "concatenateError", "(", "err", ",", "stderr", ".", "String", "(", ")", ")", "\n", "}", "\n\n", "return", "diff", ",", "<-", "done", "\n", "}" ]
// GetDiffRange returns a parsed diff object between given commits.
[ "GetDiffRange", "returns", "a", "parsed", "diff", "object", "between", "given", "commits", "." ]
d1773fe06f37f5e2c92d0ed6dd50c11bf1a17164
https://github.com/gogs/git-module/blob/d1773fe06f37f5e2c92d0ed6dd50c11bf1a17164/repo_diff.go#L308-L347
11,683
gogs/git-module
repo_diff.go
GetRawDiff
func GetRawDiff(repoPath, commitID string, diffType RawDiffType, writer io.Writer) error { repo, err := OpenRepository(repoPath) if err != nil { return fmt.Errorf("OpenRepository: %v", err) } commit, err := repo.GetCommit(commitID) if err != nil { return err } cmd := NewCommand() switch diffType { case RAW_DIFF_NORMAL: if commit.ParentCount() == 0 { cmd.AddArguments("show", commitID) } else { c, _ := commit.Parent(0) cmd.AddArguments("diff", "-M", c.ID.String(), commitID) } case RAW_DIFF_PATCH: if commit.ParentCount() == 0 { cmd.AddArguments("format-patch", "--no-signature", "--stdout", "--root", commitID) } else { c, _ := commit.Parent(0) query := fmt.Sprintf("%s...%s", commitID, c.ID.String()) cmd.AddArguments("format-patch", "--no-signature", "--stdout", query) } default: return fmt.Errorf("invalid diffType: %s", diffType) } stderr := new(bytes.Buffer) if err = cmd.RunInDirPipeline(repoPath, writer, stderr); err != nil { return concatenateError(err, stderr.String()) } return nil }
go
func GetRawDiff(repoPath, commitID string, diffType RawDiffType, writer io.Writer) error { repo, err := OpenRepository(repoPath) if err != nil { return fmt.Errorf("OpenRepository: %v", err) } commit, err := repo.GetCommit(commitID) if err != nil { return err } cmd := NewCommand() switch diffType { case RAW_DIFF_NORMAL: if commit.ParentCount() == 0 { cmd.AddArguments("show", commitID) } else { c, _ := commit.Parent(0) cmd.AddArguments("diff", "-M", c.ID.String(), commitID) } case RAW_DIFF_PATCH: if commit.ParentCount() == 0 { cmd.AddArguments("format-patch", "--no-signature", "--stdout", "--root", commitID) } else { c, _ := commit.Parent(0) query := fmt.Sprintf("%s...%s", commitID, c.ID.String()) cmd.AddArguments("format-patch", "--no-signature", "--stdout", query) } default: return fmt.Errorf("invalid diffType: %s", diffType) } stderr := new(bytes.Buffer) if err = cmd.RunInDirPipeline(repoPath, writer, stderr); err != nil { return concatenateError(err, stderr.String()) } return nil }
[ "func", "GetRawDiff", "(", "repoPath", ",", "commitID", "string", ",", "diffType", "RawDiffType", ",", "writer", "io", ".", "Writer", ")", "error", "{", "repo", ",", "err", ":=", "OpenRepository", "(", "repoPath", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "commit", ",", "err", ":=", "repo", ".", "GetCommit", "(", "commitID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "cmd", ":=", "NewCommand", "(", ")", "\n", "switch", "diffType", "{", "case", "RAW_DIFF_NORMAL", ":", "if", "commit", ".", "ParentCount", "(", ")", "==", "0", "{", "cmd", ".", "AddArguments", "(", "\"", "\"", ",", "commitID", ")", "\n", "}", "else", "{", "c", ",", "_", ":=", "commit", ".", "Parent", "(", "0", ")", "\n", "cmd", ".", "AddArguments", "(", "\"", "\"", ",", "\"", "\"", ",", "c", ".", "ID", ".", "String", "(", ")", ",", "commitID", ")", "\n", "}", "\n", "case", "RAW_DIFF_PATCH", ":", "if", "commit", ".", "ParentCount", "(", ")", "==", "0", "{", "cmd", ".", "AddArguments", "(", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "commitID", ")", "\n", "}", "else", "{", "c", ",", "_", ":=", "commit", ".", "Parent", "(", "0", ")", "\n", "query", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "commitID", ",", "c", ".", "ID", ".", "String", "(", ")", ")", "\n", "cmd", ".", "AddArguments", "(", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "query", ")", "\n", "}", "\n", "default", ":", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "diffType", ")", "\n", "}", "\n\n", "stderr", ":=", "new", "(", "bytes", ".", "Buffer", ")", "\n", "if", "err", "=", "cmd", ".", "RunInDirPipeline", "(", "repoPath", ",", "writer", ",", "stderr", ")", ";", "err", "!=", "nil", "{", "return", "concatenateError", "(", "err", ",", "stderr", ".", "String", "(", ")", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// GetRawDiff dumps diff results of repository in given commit ID to io.Writer.
[ "GetRawDiff", "dumps", "diff", "results", "of", "repository", "in", "given", "commit", "ID", "to", "io", ".", "Writer", "." ]
d1773fe06f37f5e2c92d0ed6dd50c11bf1a17164
https://github.com/gogs/git-module/blob/d1773fe06f37f5e2c92d0ed6dd50c11bf1a17164/repo_diff.go#L358-L395
11,684
gogs/git-module
repo_diff.go
GetDiffCommit
func GetDiffCommit(repoPath, commitID string, maxLines, maxLineCharacteres, maxFiles int) (*Diff, error) { return GetDiffRange(repoPath, "", commitID, maxLines, maxLineCharacteres, maxFiles) }
go
func GetDiffCommit(repoPath, commitID string, maxLines, maxLineCharacteres, maxFiles int) (*Diff, error) { return GetDiffRange(repoPath, "", commitID, maxLines, maxLineCharacteres, maxFiles) }
[ "func", "GetDiffCommit", "(", "repoPath", ",", "commitID", "string", ",", "maxLines", ",", "maxLineCharacteres", ",", "maxFiles", "int", ")", "(", "*", "Diff", ",", "error", ")", "{", "return", "GetDiffRange", "(", "repoPath", ",", "\"", "\"", ",", "commitID", ",", "maxLines", ",", "maxLineCharacteres", ",", "maxFiles", ")", "\n", "}" ]
// GetDiffCommit returns a parsed diff object of given commit.
[ "GetDiffCommit", "returns", "a", "parsed", "diff", "object", "of", "given", "commit", "." ]
d1773fe06f37f5e2c92d0ed6dd50c11bf1a17164
https://github.com/gogs/git-module/blob/d1773fe06f37f5e2c92d0ed6dd50c11bf1a17164/repo_diff.go#L398-L400
11,685
gogs/git-module
commit.go
GetCommitByPath
func (c *Commit) GetCommitByPath(relpath string) (*Commit, error) { return c.repo.getCommitByPathWithID(c.ID, relpath) }
go
func (c *Commit) GetCommitByPath(relpath string) (*Commit, error) { return c.repo.getCommitByPathWithID(c.ID, relpath) }
[ "func", "(", "c", "*", "Commit", ")", "GetCommitByPath", "(", "relpath", "string", ")", "(", "*", "Commit", ",", "error", ")", "{", "return", "c", ".", "repo", ".", "getCommitByPathWithID", "(", "c", ".", "ID", ",", "relpath", ")", "\n", "}" ]
// GetCommitByPath return the commit of relative path object.
[ "GetCommitByPath", "return", "the", "commit", "of", "relative", "path", "object", "." ]
d1773fe06f37f5e2c92d0ed6dd50c11bf1a17164
https://github.com/gogs/git-module/blob/d1773fe06f37f5e2c92d0ed6dd50c11bf1a17164/commit.go#L96-L98
11,686
gogs/git-module
commit.go
AddChanges
func AddChanges(repoPath string, all bool, files ...string) error { cmd := NewCommand("add") if all { cmd.AddArguments("--all") } _, err := cmd.AddArguments(files...).RunInDir(repoPath) return err }
go
func AddChanges(repoPath string, all bool, files ...string) error { cmd := NewCommand("add") if all { cmd.AddArguments("--all") } _, err := cmd.AddArguments(files...).RunInDir(repoPath) return err }
[ "func", "AddChanges", "(", "repoPath", "string", ",", "all", "bool", ",", "files", "...", "string", ")", "error", "{", "cmd", ":=", "NewCommand", "(", "\"", "\"", ")", "\n", "if", "all", "{", "cmd", ".", "AddArguments", "(", "\"", "\"", ")", "\n", "}", "\n", "_", ",", "err", ":=", "cmd", ".", "AddArguments", "(", "files", "...", ")", ".", "RunInDir", "(", "repoPath", ")", "\n", "return", "err", "\n", "}" ]
// AddChanges marks local changes to be ready for commit.
[ "AddChanges", "marks", "local", "changes", "to", "be", "ready", "for", "commit", "." ]
d1773fe06f37f5e2c92d0ed6dd50c11bf1a17164
https://github.com/gogs/git-module/blob/d1773fe06f37f5e2c92d0ed6dd50c11bf1a17164/commit.go#L101-L108
11,687
gogs/git-module
commit.go
CommitChanges
func CommitChanges(repoPath string, opts CommitChangesOptions) error { cmd := NewCommand() if opts.Committer != nil { cmd.AddEnvs("GIT_COMMITTER_NAME="+opts.Committer.Name, "GIT_COMMITTER_EMAIL="+opts.Committer.Email) } cmd.AddArguments("commit") if opts.Author == nil { opts.Author = opts.Committer } if opts.Author != nil { cmd.AddArguments(fmt.Sprintf("--author='%s <%s>'", opts.Author.Name, opts.Author.Email)) } cmd.AddArguments("-m", opts.Message) _, err := cmd.RunInDir(repoPath) // No stderr but exit status 1 means nothing to commit. if err != nil && err.Error() == "exit status 1" { return nil } return err }
go
func CommitChanges(repoPath string, opts CommitChangesOptions) error { cmd := NewCommand() if opts.Committer != nil { cmd.AddEnvs("GIT_COMMITTER_NAME="+opts.Committer.Name, "GIT_COMMITTER_EMAIL="+opts.Committer.Email) } cmd.AddArguments("commit") if opts.Author == nil { opts.Author = opts.Committer } if opts.Author != nil { cmd.AddArguments(fmt.Sprintf("--author='%s <%s>'", opts.Author.Name, opts.Author.Email)) } cmd.AddArguments("-m", opts.Message) _, err := cmd.RunInDir(repoPath) // No stderr but exit status 1 means nothing to commit. if err != nil && err.Error() == "exit status 1" { return nil } return err }
[ "func", "CommitChanges", "(", "repoPath", "string", ",", "opts", "CommitChangesOptions", ")", "error", "{", "cmd", ":=", "NewCommand", "(", ")", "\n", "if", "opts", ".", "Committer", "!=", "nil", "{", "cmd", ".", "AddEnvs", "(", "\"", "\"", "+", "opts", ".", "Committer", ".", "Name", ",", "\"", "\"", "+", "opts", ".", "Committer", ".", "Email", ")", "\n", "}", "\n", "cmd", ".", "AddArguments", "(", "\"", "\"", ")", "\n\n", "if", "opts", ".", "Author", "==", "nil", "{", "opts", ".", "Author", "=", "opts", ".", "Committer", "\n", "}", "\n", "if", "opts", ".", "Author", "!=", "nil", "{", "cmd", ".", "AddArguments", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "opts", ".", "Author", ".", "Name", ",", "opts", ".", "Author", ".", "Email", ")", ")", "\n", "}", "\n", "cmd", ".", "AddArguments", "(", "\"", "\"", ",", "opts", ".", "Message", ")", "\n\n", "_", ",", "err", ":=", "cmd", ".", "RunInDir", "(", "repoPath", ")", "\n", "// No stderr but exit status 1 means nothing to commit.", "if", "err", "!=", "nil", "&&", "err", ".", "Error", "(", ")", "==", "\"", "\"", "{", "return", "nil", "\n", "}", "\n", "return", "err", "\n", "}" ]
// CommitChanges commits local changes with given committer, author and message. // If author is nil, it will be the same as committer.
[ "CommitChanges", "commits", "local", "changes", "with", "given", "committer", "author", "and", "message", ".", "If", "author", "is", "nil", "it", "will", "be", "the", "same", "as", "committer", "." ]
d1773fe06f37f5e2c92d0ed6dd50c11bf1a17164
https://github.com/gogs/git-module/blob/d1773fe06f37f5e2c92d0ed6dd50c11bf1a17164/commit.go#L118-L139
11,688
gogs/git-module
commit.go
GetCommitFileStatus
func GetCommitFileStatus(repoPath, commitID string) (*CommitFileStatus, error) { stdout, w := io.Pipe() done := make(chan struct{}) fileStatus := NewCommitFileStatus() go func() { scanner := bufio.NewScanner(stdout) for scanner.Scan() { fields := strings.Fields(scanner.Text()) if len(fields) < 2 { continue } switch fields[0][0] { case 'A': fileStatus.Added = append(fileStatus.Added, fields[1]) case 'D': fileStatus.Removed = append(fileStatus.Removed, fields[1]) case 'M': fileStatus.Modified = append(fileStatus.Modified, fields[1]) } } done <- struct{}{} }() stderr := new(bytes.Buffer) err := NewCommand("show", "--name-status", "--pretty=format:''", commitID).RunInDirPipeline(repoPath, w, stderr) w.Close() // Close writer to exit parsing goroutine if err != nil { return nil, concatenateError(err, stderr.String()) } <-done return fileStatus, nil }
go
func GetCommitFileStatus(repoPath, commitID string) (*CommitFileStatus, error) { stdout, w := io.Pipe() done := make(chan struct{}) fileStatus := NewCommitFileStatus() go func() { scanner := bufio.NewScanner(stdout) for scanner.Scan() { fields := strings.Fields(scanner.Text()) if len(fields) < 2 { continue } switch fields[0][0] { case 'A': fileStatus.Added = append(fileStatus.Added, fields[1]) case 'D': fileStatus.Removed = append(fileStatus.Removed, fields[1]) case 'M': fileStatus.Modified = append(fileStatus.Modified, fields[1]) } } done <- struct{}{} }() stderr := new(bytes.Buffer) err := NewCommand("show", "--name-status", "--pretty=format:''", commitID).RunInDirPipeline(repoPath, w, stderr) w.Close() // Close writer to exit parsing goroutine if err != nil { return nil, concatenateError(err, stderr.String()) } <-done return fileStatus, nil }
[ "func", "GetCommitFileStatus", "(", "repoPath", ",", "commitID", "string", ")", "(", "*", "CommitFileStatus", ",", "error", ")", "{", "stdout", ",", "w", ":=", "io", ".", "Pipe", "(", ")", "\n", "done", ":=", "make", "(", "chan", "struct", "{", "}", ")", "\n", "fileStatus", ":=", "NewCommitFileStatus", "(", ")", "\n", "go", "func", "(", ")", "{", "scanner", ":=", "bufio", ".", "NewScanner", "(", "stdout", ")", "\n", "for", "scanner", ".", "Scan", "(", ")", "{", "fields", ":=", "strings", ".", "Fields", "(", "scanner", ".", "Text", "(", ")", ")", "\n", "if", "len", "(", "fields", ")", "<", "2", "{", "continue", "\n", "}", "\n\n", "switch", "fields", "[", "0", "]", "[", "0", "]", "{", "case", "'A'", ":", "fileStatus", ".", "Added", "=", "append", "(", "fileStatus", ".", "Added", ",", "fields", "[", "1", "]", ")", "\n", "case", "'D'", ":", "fileStatus", ".", "Removed", "=", "append", "(", "fileStatus", ".", "Removed", ",", "fields", "[", "1", "]", ")", "\n", "case", "'M'", ":", "fileStatus", ".", "Modified", "=", "append", "(", "fileStatus", ".", "Modified", ",", "fields", "[", "1", "]", ")", "\n", "}", "\n", "}", "\n", "done", "<-", "struct", "{", "}", "{", "}", "\n", "}", "(", ")", "\n\n", "stderr", ":=", "new", "(", "bytes", ".", "Buffer", ")", "\n", "err", ":=", "NewCommand", "(", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "commitID", ")", ".", "RunInDirPipeline", "(", "repoPath", ",", "w", ",", "stderr", ")", "\n", "w", ".", "Close", "(", ")", "// Close writer to exit parsing goroutine", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "concatenateError", "(", "err", ",", "stderr", ".", "String", "(", ")", ")", "\n", "}", "\n\n", "<-", "done", "\n", "return", "fileStatus", ",", "nil", "\n", "}" ]
// GetCommitFileStatus returns file status of commit in given repository.
[ "GetCommitFileStatus", "returns", "file", "status", "of", "commit", "in", "given", "repository", "." ]
d1773fe06f37f5e2c92d0ed6dd50c11bf1a17164
https://github.com/gogs/git-module/blob/d1773fe06f37f5e2c92d0ed6dd50c11bf1a17164/commit.go#L267-L300
11,689
gogs/git-module
commit.go
FileStatus
func (c *Commit) FileStatus() (*CommitFileStatus, error) { return GetCommitFileStatus(c.repo.Path, c.ID.String()) }
go
func (c *Commit) FileStatus() (*CommitFileStatus, error) { return GetCommitFileStatus(c.repo.Path, c.ID.String()) }
[ "func", "(", "c", "*", "Commit", ")", "FileStatus", "(", ")", "(", "*", "CommitFileStatus", ",", "error", ")", "{", "return", "GetCommitFileStatus", "(", "c", ".", "repo", ".", "Path", ",", "c", ".", "ID", ".", "String", "(", ")", ")", "\n", "}" ]
// FileStatus returns file status of commit.
[ "FileStatus", "returns", "file", "status", "of", "commit", "." ]
d1773fe06f37f5e2c92d0ed6dd50c11bf1a17164
https://github.com/gogs/git-module/blob/d1773fe06f37f5e2c92d0ed6dd50c11bf1a17164/commit.go#L303-L305
11,690
gogs/git-module
repo_commit.go
GetBranchCommitID
func (repo *Repository) GetBranchCommitID(name string) (string, error) { return repo.getRefCommitID(BRANCH_PREFIX + name) }
go
func (repo *Repository) GetBranchCommitID(name string) (string, error) { return repo.getRefCommitID(BRANCH_PREFIX + name) }
[ "func", "(", "repo", "*", "Repository", ")", "GetBranchCommitID", "(", "name", "string", ")", "(", "string", ",", "error", ")", "{", "return", "repo", ".", "getRefCommitID", "(", "BRANCH_PREFIX", "+", "name", ")", "\n", "}" ]
// GetBranchCommitID returns last commit ID string of given branch.
[ "GetBranchCommitID", "returns", "last", "commit", "ID", "string", "of", "given", "branch", "." ]
d1773fe06f37f5e2c92d0ed6dd50c11bf1a17164
https://github.com/gogs/git-module/blob/d1773fe06f37f5e2c92d0ed6dd50c11bf1a17164/repo_commit.go#L33-L35
11,691
gogs/git-module
repo_commit.go
GetTagCommitID
func (repo *Repository) GetTagCommitID(name string) (string, error) { return repo.getRefCommitID(TAG_PREFIX + name) }
go
func (repo *Repository) GetTagCommitID(name string) (string, error) { return repo.getRefCommitID(TAG_PREFIX + name) }
[ "func", "(", "repo", "*", "Repository", ")", "GetTagCommitID", "(", "name", "string", ")", "(", "string", ",", "error", ")", "{", "return", "repo", ".", "getRefCommitID", "(", "TAG_PREFIX", "+", "name", ")", "\n", "}" ]
// GetTagCommitID returns last commit ID string of given tag.
[ "GetTagCommitID", "returns", "last", "commit", "ID", "string", "of", "given", "tag", "." ]
d1773fe06f37f5e2c92d0ed6dd50c11bf1a17164
https://github.com/gogs/git-module/blob/d1773fe06f37f5e2c92d0ed6dd50c11bf1a17164/repo_commit.go#L38-L40
11,692
gogs/git-module
repo_commit.go
GetRemoteBranchCommitID
func (repo *Repository) GetRemoteBranchCommitID(name string) (string, error) { return repo.getRefCommitID(REMOTE_PREFIX + name) }
go
func (repo *Repository) GetRemoteBranchCommitID(name string) (string, error) { return repo.getRefCommitID(REMOTE_PREFIX + name) }
[ "func", "(", "repo", "*", "Repository", ")", "GetRemoteBranchCommitID", "(", "name", "string", ")", "(", "string", ",", "error", ")", "{", "return", "repo", ".", "getRefCommitID", "(", "REMOTE_PREFIX", "+", "name", ")", "\n", "}" ]
// GetRemoteBranchCommitID returns last commit ID string of given remote branch.
[ "GetRemoteBranchCommitID", "returns", "last", "commit", "ID", "string", "of", "given", "remote", "branch", "." ]
d1773fe06f37f5e2c92d0ed6dd50c11bf1a17164
https://github.com/gogs/git-module/blob/d1773fe06f37f5e2c92d0ed6dd50c11bf1a17164/repo_commit.go#L43-L45
11,693
gogs/git-module
repo_commit.go
GetCommit
func (repo *Repository) GetCommit(commitID string) (*Commit, error) { var err error commitID, err = GetFullCommitID(repo.Path, commitID) if err != nil { return nil, err } id, err := NewIDFromString(commitID) if err != nil { return nil, err } return repo.getCommit(id) }
go
func (repo *Repository) GetCommit(commitID string) (*Commit, error) { var err error commitID, err = GetFullCommitID(repo.Path, commitID) if err != nil { return nil, err } id, err := NewIDFromString(commitID) if err != nil { return nil, err } return repo.getCommit(id) }
[ "func", "(", "repo", "*", "Repository", ")", "GetCommit", "(", "commitID", "string", ")", "(", "*", "Commit", ",", "error", ")", "{", "var", "err", "error", "\n", "commitID", ",", "err", "=", "GetFullCommitID", "(", "repo", ".", "Path", ",", "commitID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "id", ",", "err", ":=", "NewIDFromString", "(", "commitID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "repo", ".", "getCommit", "(", "id", ")", "\n", "}" ]
// GetCommit returns commit object of by ID string.
[ "GetCommit", "returns", "commit", "object", "of", "by", "ID", "string", "." ]
d1773fe06f37f5e2c92d0ed6dd50c11bf1a17164
https://github.com/gogs/git-module/blob/d1773fe06f37f5e2c92d0ed6dd50c11bf1a17164/repo_commit.go#L128-L140
11,694
gogs/git-module
repo_commit.go
GetBranchCommit
func (repo *Repository) GetBranchCommit(name string) (*Commit, error) { commitID, err := repo.GetBranchCommitID(name) if err != nil { return nil, err } return repo.GetCommit(commitID) }
go
func (repo *Repository) GetBranchCommit(name string) (*Commit, error) { commitID, err := repo.GetBranchCommitID(name) if err != nil { return nil, err } return repo.GetCommit(commitID) }
[ "func", "(", "repo", "*", "Repository", ")", "GetBranchCommit", "(", "name", "string", ")", "(", "*", "Commit", ",", "error", ")", "{", "commitID", ",", "err", ":=", "repo", ".", "GetBranchCommitID", "(", "name", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "repo", ".", "GetCommit", "(", "commitID", ")", "\n", "}" ]
// GetBranchCommit returns the last commit of given branch.
[ "GetBranchCommit", "returns", "the", "last", "commit", "of", "given", "branch", "." ]
d1773fe06f37f5e2c92d0ed6dd50c11bf1a17164
https://github.com/gogs/git-module/blob/d1773fe06f37f5e2c92d0ed6dd50c11bf1a17164/repo_commit.go#L143-L149
11,695
gogs/git-module
repo_commit.go
GetTagCommit
func (repo *Repository) GetTagCommit(name string) (*Commit, error) { commitID, err := repo.GetTagCommitID(name) if err != nil { return nil, err } return repo.GetCommit(commitID) }
go
func (repo *Repository) GetTagCommit(name string) (*Commit, error) { commitID, err := repo.GetTagCommitID(name) if err != nil { return nil, err } return repo.GetCommit(commitID) }
[ "func", "(", "repo", "*", "Repository", ")", "GetTagCommit", "(", "name", "string", ")", "(", "*", "Commit", ",", "error", ")", "{", "commitID", ",", "err", ":=", "repo", ".", "GetTagCommitID", "(", "name", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "repo", ".", "GetCommit", "(", "commitID", ")", "\n", "}" ]
// GetTagCommit returns the commit of given tag.
[ "GetTagCommit", "returns", "the", "commit", "of", "given", "tag", "." ]
d1773fe06f37f5e2c92d0ed6dd50c11bf1a17164
https://github.com/gogs/git-module/blob/d1773fe06f37f5e2c92d0ed6dd50c11bf1a17164/repo_commit.go#L152-L158
11,696
gogs/git-module
repo_commit.go
GetRemoteBranchCommit
func (repo *Repository) GetRemoteBranchCommit(name string) (*Commit, error) { commitID, err := repo.GetRemoteBranchCommitID(name) if err != nil { return nil, err } return repo.GetCommit(commitID) }
go
func (repo *Repository) GetRemoteBranchCommit(name string) (*Commit, error) { commitID, err := repo.GetRemoteBranchCommitID(name) if err != nil { return nil, err } return repo.GetCommit(commitID) }
[ "func", "(", "repo", "*", "Repository", ")", "GetRemoteBranchCommit", "(", "name", "string", ")", "(", "*", "Commit", ",", "error", ")", "{", "commitID", ",", "err", ":=", "repo", ".", "GetRemoteBranchCommitID", "(", "name", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "repo", ".", "GetCommit", "(", "commitID", ")", "\n", "}" ]
// GetRemoteBranchCommit returns the last commit of given remote branch.
[ "GetRemoteBranchCommit", "returns", "the", "last", "commit", "of", "given", "remote", "branch", "." ]
d1773fe06f37f5e2c92d0ed6dd50c11bf1a17164
https://github.com/gogs/git-module/blob/d1773fe06f37f5e2c92d0ed6dd50c11bf1a17164/repo_commit.go#L161-L167
11,697
gogs/git-module
repo_commit.go
GetCommitByPath
func (repo *Repository) GetCommitByPath(relpath string) (*Commit, error) { stdout, err := NewCommand("log", "-1", _PRETTY_LOG_FORMAT, "--", relpath).RunInDirBytes(repo.Path) if err != nil { return nil, err } commits, err := repo.parsePrettyFormatLogToList(stdout) if err != nil { return nil, err } return commits.Front().Value.(*Commit), nil }
go
func (repo *Repository) GetCommitByPath(relpath string) (*Commit, error) { stdout, err := NewCommand("log", "-1", _PRETTY_LOG_FORMAT, "--", relpath).RunInDirBytes(repo.Path) if err != nil { return nil, err } commits, err := repo.parsePrettyFormatLogToList(stdout) if err != nil { return nil, err } return commits.Front().Value.(*Commit), nil }
[ "func", "(", "repo", "*", "Repository", ")", "GetCommitByPath", "(", "relpath", "string", ")", "(", "*", "Commit", ",", "error", ")", "{", "stdout", ",", "err", ":=", "NewCommand", "(", "\"", "\"", ",", "\"", "\"", ",", "_PRETTY_LOG_FORMAT", ",", "\"", "\"", ",", "relpath", ")", ".", "RunInDirBytes", "(", "repo", ".", "Path", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "commits", ",", "err", ":=", "repo", ".", "parsePrettyFormatLogToList", "(", "stdout", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "commits", ".", "Front", "(", ")", ".", "Value", ".", "(", "*", "Commit", ")", ",", "nil", "\n", "}" ]
// GetCommitByPath returns the last commit of relative path.
[ "GetCommitByPath", "returns", "the", "last", "commit", "of", "relative", "path", "." ]
d1773fe06f37f5e2c92d0ed6dd50c11bf1a17164
https://github.com/gogs/git-module/blob/d1773fe06f37f5e2c92d0ed6dd50c11bf1a17164/repo_commit.go#L189-L200
11,698
gogs/git-module
repo_commit.go
CommitsBetween
func (repo *Repository) CommitsBetween(last *Commit, before *Commit) (*list.List, error) { if version.Compare(gitVersion, "1.8.0", ">=") { stdout, err := NewCommand("rev-list", before.ID.String()+"..."+last.ID.String()).RunInDirBytes(repo.Path) if err != nil { return nil, err } return repo.parsePrettyFormatLogToList(bytes.TrimSpace(stdout)) } // Fallback to stupid solution, which iterates all commits of the repository // if before is not an ancestor of last. l := list.New() if last == nil || last.ParentCount() == 0 { return l, nil } var err error cur := last for { if cur.ID.Equal(before.ID) { break } l.PushBack(cur) if cur.ParentCount() == 0 { break } cur, err = cur.Parent(0) if err != nil { return nil, err } } return l, nil }
go
func (repo *Repository) CommitsBetween(last *Commit, before *Commit) (*list.List, error) { if version.Compare(gitVersion, "1.8.0", ">=") { stdout, err := NewCommand("rev-list", before.ID.String()+"..."+last.ID.String()).RunInDirBytes(repo.Path) if err != nil { return nil, err } return repo.parsePrettyFormatLogToList(bytes.TrimSpace(stdout)) } // Fallback to stupid solution, which iterates all commits of the repository // if before is not an ancestor of last. l := list.New() if last == nil || last.ParentCount() == 0 { return l, nil } var err error cur := last for { if cur.ID.Equal(before.ID) { break } l.PushBack(cur) if cur.ParentCount() == 0 { break } cur, err = cur.Parent(0) if err != nil { return nil, err } } return l, nil }
[ "func", "(", "repo", "*", "Repository", ")", "CommitsBetween", "(", "last", "*", "Commit", ",", "before", "*", "Commit", ")", "(", "*", "list", ".", "List", ",", "error", ")", "{", "if", "version", ".", "Compare", "(", "gitVersion", ",", "\"", "\"", ",", "\"", "\"", ")", "{", "stdout", ",", "err", ":=", "NewCommand", "(", "\"", "\"", ",", "before", ".", "ID", ".", "String", "(", ")", "+", "\"", "\"", "+", "last", ".", "ID", ".", "String", "(", ")", ")", ".", "RunInDirBytes", "(", "repo", ".", "Path", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "repo", ".", "parsePrettyFormatLogToList", "(", "bytes", ".", "TrimSpace", "(", "stdout", ")", ")", "\n", "}", "\n\n", "// Fallback to stupid solution, which iterates all commits of the repository", "// if before is not an ancestor of last.", "l", ":=", "list", ".", "New", "(", ")", "\n", "if", "last", "==", "nil", "||", "last", ".", "ParentCount", "(", ")", "==", "0", "{", "return", "l", ",", "nil", "\n", "}", "\n\n", "var", "err", "error", "\n", "cur", ":=", "last", "\n", "for", "{", "if", "cur", ".", "ID", ".", "Equal", "(", "before", ".", "ID", ")", "{", "break", "\n", "}", "\n", "l", ".", "PushBack", "(", "cur", ")", "\n", "if", "cur", ".", "ParentCount", "(", ")", "==", "0", "{", "break", "\n", "}", "\n", "cur", ",", "err", "=", "cur", ".", "Parent", "(", "0", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "}", "\n", "return", "l", ",", "nil", "\n", "}" ]
// CommitsBetween returns a list that contains commits between [last, before).
[ "CommitsBetween", "returns", "a", "list", "that", "contains", "commits", "between", "[", "last", "before", ")", "." ]
d1773fe06f37f5e2c92d0ed6dd50c11bf1a17164
https://github.com/gogs/git-module/blob/d1773fe06f37f5e2c92d0ed6dd50c11bf1a17164/repo_commit.go#L259-L291
11,699
gogs/git-module
repo_commit.go
commitsBefore
func (repo *Repository) commitsBefore(l *list.List, parent *list.Element, id sha1, current, limit int) error { // Reach the limit if limit > 0 && current > limit { return nil } commit, err := repo.getCommit(id) if err != nil { return fmt.Errorf("getCommit: %v", err) } var e *list.Element if parent == nil { e = l.PushBack(commit) } else { var in = parent for { if in == nil { break } else if in.Value.(*Commit).ID.Equal(commit.ID) { return nil } else if in.Next() == nil { break } if in.Value.(*Commit).Committer.When.Equal(commit.Committer.When) { break } if in.Value.(*Commit).Committer.When.After(commit.Committer.When) && in.Next().Value.(*Commit).Committer.When.Before(commit.Committer.When) { break } in = in.Next() } e = l.InsertAfter(commit, in) } pr := parent if commit.ParentCount() > 1 { pr = e } for i := 0; i < commit.ParentCount(); i++ { id, err := commit.ParentID(i) if err != nil { return err } err = repo.commitsBefore(l, pr, id, current+1, limit) if err != nil { return err } } return nil }
go
func (repo *Repository) commitsBefore(l *list.List, parent *list.Element, id sha1, current, limit int) error { // Reach the limit if limit > 0 && current > limit { return nil } commit, err := repo.getCommit(id) if err != nil { return fmt.Errorf("getCommit: %v", err) } var e *list.Element if parent == nil { e = l.PushBack(commit) } else { var in = parent for { if in == nil { break } else if in.Value.(*Commit).ID.Equal(commit.ID) { return nil } else if in.Next() == nil { break } if in.Value.(*Commit).Committer.When.Equal(commit.Committer.When) { break } if in.Value.(*Commit).Committer.When.After(commit.Committer.When) && in.Next().Value.(*Commit).Committer.When.Before(commit.Committer.When) { break } in = in.Next() } e = l.InsertAfter(commit, in) } pr := parent if commit.ParentCount() > 1 { pr = e } for i := 0; i < commit.ParentCount(); i++ { id, err := commit.ParentID(i) if err != nil { return err } err = repo.commitsBefore(l, pr, id, current+1, limit) if err != nil { return err } } return nil }
[ "func", "(", "repo", "*", "Repository", ")", "commitsBefore", "(", "l", "*", "list", ".", "List", ",", "parent", "*", "list", ".", "Element", ",", "id", "sha1", ",", "current", ",", "limit", "int", ")", "error", "{", "// Reach the limit", "if", "limit", ">", "0", "&&", "current", ">", "limit", "{", "return", "nil", "\n", "}", "\n\n", "commit", ",", "err", ":=", "repo", ".", "getCommit", "(", "id", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "var", "e", "*", "list", ".", "Element", "\n", "if", "parent", "==", "nil", "{", "e", "=", "l", ".", "PushBack", "(", "commit", ")", "\n", "}", "else", "{", "var", "in", "=", "parent", "\n", "for", "{", "if", "in", "==", "nil", "{", "break", "\n", "}", "else", "if", "in", ".", "Value", ".", "(", "*", "Commit", ")", ".", "ID", ".", "Equal", "(", "commit", ".", "ID", ")", "{", "return", "nil", "\n", "}", "else", "if", "in", ".", "Next", "(", ")", "==", "nil", "{", "break", "\n", "}", "\n\n", "if", "in", ".", "Value", ".", "(", "*", "Commit", ")", ".", "Committer", ".", "When", ".", "Equal", "(", "commit", ".", "Committer", ".", "When", ")", "{", "break", "\n", "}", "\n\n", "if", "in", ".", "Value", ".", "(", "*", "Commit", ")", ".", "Committer", ".", "When", ".", "After", "(", "commit", ".", "Committer", ".", "When", ")", "&&", "in", ".", "Next", "(", ")", ".", "Value", ".", "(", "*", "Commit", ")", ".", "Committer", ".", "When", ".", "Before", "(", "commit", ".", "Committer", ".", "When", ")", "{", "break", "\n", "}", "\n\n", "in", "=", "in", ".", "Next", "(", ")", "\n", "}", "\n\n", "e", "=", "l", ".", "InsertAfter", "(", "commit", ",", "in", ")", "\n", "}", "\n\n", "pr", ":=", "parent", "\n", "if", "commit", ".", "ParentCount", "(", ")", ">", "1", "{", "pr", "=", "e", "\n", "}", "\n\n", "for", "i", ":=", "0", ";", "i", "<", "commit", ".", "ParentCount", "(", ")", ";", "i", "++", "{", "id", ",", "err", ":=", "commit", ".", "ParentID", "(", "i", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "err", "=", "repo", ".", "commitsBefore", "(", "l", ",", "pr", ",", "id", ",", "current", "+", "1", ",", "limit", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// The limit is depth, not total number of returned commits.
[ "The", "limit", "is", "depth", "not", "total", "number", "of", "returned", "commits", "." ]
d1773fe06f37f5e2c92d0ed6dd50c11bf1a17164
https://github.com/gogs/git-module/blob/d1773fe06f37f5e2c92d0ed6dd50c11bf1a17164/repo_commit.go#L310-L367