repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
sequence
docstring
stringlengths
6
2.61k
docstring_tokens
sequence
sha
stringlengths
40
40
url
stringlengths
85
252
partition
stringclasses
1 value
graphql-go/graphql
language/lexer/lexer.go
char2hex
func char2hex(a rune) int { if a >= 48 && a <= 57 { // 0-9 return int(a) - 48 } else if a >= 65 && a <= 70 { // A-F return int(a) - 55 } else if a >= 97 && a <= 102 { // a-f return int(a) - 87 } return -1 }
go
func char2hex(a rune) int { if a >= 48 && a <= 57 { // 0-9 return int(a) - 48 } else if a >= 65 && a <= 70 { // A-F return int(a) - 55 } else if a >= 97 && a <= 102 { // a-f return int(a) - 87 } return -1 }
[ "func", "char2hex", "(", "a", "rune", ")", "int", "{", "if", "a", ">=", "48", "&&", "a", "<=", "57", "{", "// 0-9", "return", "int", "(", "a", ")", "-", "48", "\n", "}", "else", "if", "a", ">=", "65", "&&", "a", "<=", "70", "{", "// A-F", "return", "int", "(", "a", ")", "-", "55", "\n", "}", "else", "if", "a", ">=", "97", "&&", "a", "<=", "102", "{", "// a-f", "return", "int", "(", "a", ")", "-", "87", "\n", "}", "\n", "return", "-", "1", "\n", "}" ]
// Converts a hex character to its integer value. // '0' becomes 0, '9' becomes 9 // 'A' becomes 10, 'F' becomes 15 // 'a' becomes 10, 'f' becomes 15 // Returns -1 on error.
[ "Converts", "a", "hex", "character", "to", "its", "integer", "value", ".", "0", "becomes", "0", "9", "becomes", "9", "A", "becomes", "10", "F", "becomes", "15", "a", "becomes", "10", "f", "becomes", "15", "Returns", "-", "1", "on", "error", "." ]
199d20bbfed70dae8c7d4619d4e0d339ce738b43
https://github.com/graphql-go/graphql/blob/199d20bbfed70dae8c7d4619d4e0d339ce738b43/language/lexer/lexer.go#L453-L463
train
graphql-go/graphql
language/lexer/lexer.go
runeAt
func runeAt(body []byte, position int) (code rune, charWidth int) { if len(body) <= position { // <EOF> return -1, utf8.RuneError } c := body[position] if c < utf8.RuneSelf { return rune(c), 1 } r, n := utf8.DecodeRune(body[position:]) return r, n }
go
func runeAt(body []byte, position int) (code rune, charWidth int) { if len(body) <= position { // <EOF> return -1, utf8.RuneError } c := body[position] if c < utf8.RuneSelf { return rune(c), 1 } r, n := utf8.DecodeRune(body[position:]) return r, n }
[ "func", "runeAt", "(", "body", "[", "]", "byte", ",", "position", "int", ")", "(", "code", "rune", ",", "charWidth", "int", ")", "{", "if", "len", "(", "body", ")", "<=", "position", "{", "// <EOF>", "return", "-", "1", ",", "utf8", ".", "RuneError", "\n", "}", "\n\n", "c", ":=", "body", "[", "position", "]", "\n", "if", "c", "<", "utf8", ".", "RuneSelf", "{", "return", "rune", "(", "c", ")", ",", "1", "\n", "}", "\n\n", "r", ",", "n", ":=", "utf8", ".", "DecodeRune", "(", "body", "[", "position", ":", "]", ")", "\n", "return", "r", ",", "n", "\n", "}" ]
// Gets the rune from the byte array at given byte position and it's width in bytes
[ "Gets", "the", "rune", "from", "the", "byte", "array", "at", "given", "byte", "position", "and", "it", "s", "width", "in", "bytes" ]
199d20bbfed70dae8c7d4619d4e0d339ce738b43
https://github.com/graphql-go/graphql/blob/199d20bbfed70dae8c7d4619d4e0d339ce738b43/language/lexer/lexer.go#L579-L592
train
graphql-go/graphql
language/lexer/lexer.go
positionAfterWhitespace
func positionAfterWhitespace(body []byte, startPosition int) (position int, runePosition int) { bodyLength := len(body) position = startPosition runePosition = startPosition for { if position < bodyLength { code, n := runeAt(body, position) // Skip Ignored if code == 0xFEFF || // BOM // White Space code == 0x0009 || // tab code == 0x0020 || // space // Line Terminator code == 0x000A || // new line code == 0x000D || // carriage return // Comma code == 0x002C { position += n runePosition++ } else if code == 35 { // # position += n runePosition++ for { code, n := runeAt(body, position) if position < bodyLength && code != 0 && // SourceCharacter but not LineTerminator (code > 0x001F || code == 0x0009) && code != 0x000A && code != 0x000D { position += n runePosition++ continue } else { break } } } else { break } continue } else { break } } return position, runePosition }
go
func positionAfterWhitespace(body []byte, startPosition int) (position int, runePosition int) { bodyLength := len(body) position = startPosition runePosition = startPosition for { if position < bodyLength { code, n := runeAt(body, position) // Skip Ignored if code == 0xFEFF || // BOM // White Space code == 0x0009 || // tab code == 0x0020 || // space // Line Terminator code == 0x000A || // new line code == 0x000D || // carriage return // Comma code == 0x002C { position += n runePosition++ } else if code == 35 { // # position += n runePosition++ for { code, n := runeAt(body, position) if position < bodyLength && code != 0 && // SourceCharacter but not LineTerminator (code > 0x001F || code == 0x0009) && code != 0x000A && code != 0x000D { position += n runePosition++ continue } else { break } } } else { break } continue } else { break } } return position, runePosition }
[ "func", "positionAfterWhitespace", "(", "body", "[", "]", "byte", ",", "startPosition", "int", ")", "(", "position", "int", ",", "runePosition", "int", ")", "{", "bodyLength", ":=", "len", "(", "body", ")", "\n", "position", "=", "startPosition", "\n", "runePosition", "=", "startPosition", "\n", "for", "{", "if", "position", "<", "bodyLength", "{", "code", ",", "n", ":=", "runeAt", "(", "body", ",", "position", ")", "\n\n", "// Skip Ignored", "if", "code", "==", "0xFEFF", "||", "// BOM", "// White Space", "code", "==", "0x0009", "||", "// tab", "code", "==", "0x0020", "||", "// space", "// Line Terminator", "code", "==", "0x000A", "||", "// new line", "code", "==", "0x000D", "||", "// carriage return", "// Comma", "code", "==", "0x002C", "{", "position", "+=", "n", "\n", "runePosition", "++", "\n", "}", "else", "if", "code", "==", "35", "{", "// #", "position", "+=", "n", "\n", "runePosition", "++", "\n", "for", "{", "code", ",", "n", ":=", "runeAt", "(", "body", ",", "position", ")", "\n", "if", "position", "<", "bodyLength", "&&", "code", "!=", "0", "&&", "// SourceCharacter but not LineTerminator", "(", "code", ">", "0x001F", "||", "code", "==", "0x0009", ")", "&&", "code", "!=", "0x000A", "&&", "code", "!=", "0x000D", "{", "position", "+=", "n", "\n", "runePosition", "++", "\n", "continue", "\n", "}", "else", "{", "break", "\n", "}", "\n", "}", "\n", "}", "else", "{", "break", "\n", "}", "\n", "continue", "\n", "}", "else", "{", "break", "\n", "}", "\n", "}", "\n", "return", "position", ",", "runePosition", "\n", "}" ]
// Reads from body starting at startPosition until it finds a non-whitespace // or commented character, then returns the position of that character for lexing. // lexing. // Returns both byte positions and rune position
[ "Reads", "from", "body", "starting", "at", "startPosition", "until", "it", "finds", "a", "non", "-", "whitespace", "or", "commented", "character", "then", "returns", "the", "position", "of", "that", "character", "for", "lexing", ".", "lexing", ".", "Returns", "both", "byte", "positions", "and", "rune", "position" ]
199d20bbfed70dae8c7d4619d4e0d339ce738b43
https://github.com/graphql-go/graphql/blob/199d20bbfed70dae8c7d4619d4e0d339ce738b43/language/lexer/lexer.go#L598-L643
train
graphql-go/graphql
values.go
getVariableValues
func getVariableValues( schema Schema, definitionASTs []*ast.VariableDefinition, inputs map[string]interface{}) (map[string]interface{}, error) { values := map[string]interface{}{} for _, defAST := range definitionASTs { if defAST == nil || defAST.Variable == nil || defAST.Variable.Name == nil { continue } varName := defAST.Variable.Name.Value if varValue, err := getVariableValue(schema, defAST, inputs[varName]); err != nil { return values, err } else { values[varName] = varValue } } return values, nil }
go
func getVariableValues( schema Schema, definitionASTs []*ast.VariableDefinition, inputs map[string]interface{}) (map[string]interface{}, error) { values := map[string]interface{}{} for _, defAST := range definitionASTs { if defAST == nil || defAST.Variable == nil || defAST.Variable.Name == nil { continue } varName := defAST.Variable.Name.Value if varValue, err := getVariableValue(schema, defAST, inputs[varName]); err != nil { return values, err } else { values[varName] = varValue } } return values, nil }
[ "func", "getVariableValues", "(", "schema", "Schema", ",", "definitionASTs", "[", "]", "*", "ast", ".", "VariableDefinition", ",", "inputs", "map", "[", "string", "]", "interface", "{", "}", ")", "(", "map", "[", "string", "]", "interface", "{", "}", ",", "error", ")", "{", "values", ":=", "map", "[", "string", "]", "interface", "{", "}", "{", "}", "\n", "for", "_", ",", "defAST", ":=", "range", "definitionASTs", "{", "if", "defAST", "==", "nil", "||", "defAST", ".", "Variable", "==", "nil", "||", "defAST", ".", "Variable", ".", "Name", "==", "nil", "{", "continue", "\n", "}", "\n", "varName", ":=", "defAST", ".", "Variable", ".", "Name", ".", "Value", "\n", "if", "varValue", ",", "err", ":=", "getVariableValue", "(", "schema", ",", "defAST", ",", "inputs", "[", "varName", "]", ")", ";", "err", "!=", "nil", "{", "return", "values", ",", "err", "\n", "}", "else", "{", "values", "[", "varName", "]", "=", "varValue", "\n", "}", "\n", "}", "\n", "return", "values", ",", "nil", "\n", "}" ]
// Prepares an object map of variableValues of the correct type based on the // provided variable definitions and arbitrary input. If the input cannot be // parsed to match the variable definitions, a GraphQLError will be returned.
[ "Prepares", "an", "object", "map", "of", "variableValues", "of", "the", "correct", "type", "based", "on", "the", "provided", "variable", "definitions", "and", "arbitrary", "input", ".", "If", "the", "input", "cannot", "be", "parsed", "to", "match", "the", "variable", "definitions", "a", "GraphQLError", "will", "be", "returned", "." ]
199d20bbfed70dae8c7d4619d4e0d339ce738b43
https://github.com/graphql-go/graphql/blob/199d20bbfed70dae8c7d4619d4e0d339ce738b43/values.go#L20-L37
train
graphql-go/graphql
values.go
getArgumentValues
func getArgumentValues( argDefs []*Argument, argASTs []*ast.Argument, variableValues map[string]interface{}) map[string]interface{} { argASTMap := map[string]*ast.Argument{} for _, argAST := range argASTs { if argAST.Name != nil { argASTMap[argAST.Name.Value] = argAST } } results := map[string]interface{}{} for _, argDef := range argDefs { var ( tmp interface{} value ast.Value ) if tmpValue, ok := argASTMap[argDef.PrivateName]; ok { value = tmpValue.Value } if tmp = valueFromAST(value, argDef.Type, variableValues); isNullish(tmp) { tmp = argDef.DefaultValue } if !isNullish(tmp) { results[argDef.PrivateName] = tmp } } return results }
go
func getArgumentValues( argDefs []*Argument, argASTs []*ast.Argument, variableValues map[string]interface{}) map[string]interface{} { argASTMap := map[string]*ast.Argument{} for _, argAST := range argASTs { if argAST.Name != nil { argASTMap[argAST.Name.Value] = argAST } } results := map[string]interface{}{} for _, argDef := range argDefs { var ( tmp interface{} value ast.Value ) if tmpValue, ok := argASTMap[argDef.PrivateName]; ok { value = tmpValue.Value } if tmp = valueFromAST(value, argDef.Type, variableValues); isNullish(tmp) { tmp = argDef.DefaultValue } if !isNullish(tmp) { results[argDef.PrivateName] = tmp } } return results }
[ "func", "getArgumentValues", "(", "argDefs", "[", "]", "*", "Argument", ",", "argASTs", "[", "]", "*", "ast", ".", "Argument", ",", "variableValues", "map", "[", "string", "]", "interface", "{", "}", ")", "map", "[", "string", "]", "interface", "{", "}", "{", "argASTMap", ":=", "map", "[", "string", "]", "*", "ast", ".", "Argument", "{", "}", "\n", "for", "_", ",", "argAST", ":=", "range", "argASTs", "{", "if", "argAST", ".", "Name", "!=", "nil", "{", "argASTMap", "[", "argAST", ".", "Name", ".", "Value", "]", "=", "argAST", "\n", "}", "\n", "}", "\n", "results", ":=", "map", "[", "string", "]", "interface", "{", "}", "{", "}", "\n", "for", "_", ",", "argDef", ":=", "range", "argDefs", "{", "var", "(", "tmp", "interface", "{", "}", "\n", "value", "ast", ".", "Value", "\n", ")", "\n", "if", "tmpValue", ",", "ok", ":=", "argASTMap", "[", "argDef", ".", "PrivateName", "]", ";", "ok", "{", "value", "=", "tmpValue", ".", "Value", "\n", "}", "\n", "if", "tmp", "=", "valueFromAST", "(", "value", ",", "argDef", ".", "Type", ",", "variableValues", ")", ";", "isNullish", "(", "tmp", ")", "{", "tmp", "=", "argDef", ".", "DefaultValue", "\n", "}", "\n", "if", "!", "isNullish", "(", "tmp", ")", "{", "results", "[", "argDef", ".", "PrivateName", "]", "=", "tmp", "\n", "}", "\n", "}", "\n", "return", "results", "\n", "}" ]
// Prepares an object map of argument values given a list of argument // definitions and list of argument AST nodes.
[ "Prepares", "an", "object", "map", "of", "argument", "values", "given", "a", "list", "of", "argument", "definitions", "and", "list", "of", "argument", "AST", "nodes", "." ]
199d20bbfed70dae8c7d4619d4e0d339ce738b43
https://github.com/graphql-go/graphql/blob/199d20bbfed70dae8c7d4619d4e0d339ce738b43/values.go#L41-L68
train
graphql-go/graphql
values.go
getVariableValue
func getVariableValue(schema Schema, definitionAST *ast.VariableDefinition, input interface{}) (interface{}, error) { ttype, err := typeFromAST(schema, definitionAST.Type) if err != nil { return nil, err } variable := definitionAST.Variable if ttype == nil || !IsInputType(ttype) { return "", gqlerrors.NewError( fmt.Sprintf(`Variable "$%v" expected value of type `+ `"%v" which cannot be used as an input type.`, variable.Name.Value, printer.Print(definitionAST.Type)), []ast.Node{definitionAST}, "", nil, []int{}, nil, ) } isValid, messages := isValidInputValue(input, ttype) if isValid { if isNullish(input) { if definitionAST.DefaultValue != nil { return valueFromAST(definitionAST.DefaultValue, ttype, nil), nil } } return coerceValue(ttype, input), nil } if isNullish(input) { return "", gqlerrors.NewError( fmt.Sprintf(`Variable "$%v" of required type `+ `"%v" was not provided.`, variable.Name.Value, printer.Print(definitionAST.Type)), []ast.Node{definitionAST}, "", nil, []int{}, nil, ) } // convert input interface into string for error message bts, _ := json.Marshal(input) var ( inputStr = string(bts) msg string ) if len(messages) > 0 { msg = "\n" + strings.Join(messages, "\n") } return "", gqlerrors.NewError( fmt.Sprintf(`Variable "$%v" got invalid value `+ `%v.%v`, variable.Name.Value, inputStr, msg), []ast.Node{definitionAST}, "", nil, []int{}, nil, ) }
go
func getVariableValue(schema Schema, definitionAST *ast.VariableDefinition, input interface{}) (interface{}, error) { ttype, err := typeFromAST(schema, definitionAST.Type) if err != nil { return nil, err } variable := definitionAST.Variable if ttype == nil || !IsInputType(ttype) { return "", gqlerrors.NewError( fmt.Sprintf(`Variable "$%v" expected value of type `+ `"%v" which cannot be used as an input type.`, variable.Name.Value, printer.Print(definitionAST.Type)), []ast.Node{definitionAST}, "", nil, []int{}, nil, ) } isValid, messages := isValidInputValue(input, ttype) if isValid { if isNullish(input) { if definitionAST.DefaultValue != nil { return valueFromAST(definitionAST.DefaultValue, ttype, nil), nil } } return coerceValue(ttype, input), nil } if isNullish(input) { return "", gqlerrors.NewError( fmt.Sprintf(`Variable "$%v" of required type `+ `"%v" was not provided.`, variable.Name.Value, printer.Print(definitionAST.Type)), []ast.Node{definitionAST}, "", nil, []int{}, nil, ) } // convert input interface into string for error message bts, _ := json.Marshal(input) var ( inputStr = string(bts) msg string ) if len(messages) > 0 { msg = "\n" + strings.Join(messages, "\n") } return "", gqlerrors.NewError( fmt.Sprintf(`Variable "$%v" got invalid value `+ `%v.%v`, variable.Name.Value, inputStr, msg), []ast.Node{definitionAST}, "", nil, []int{}, nil, ) }
[ "func", "getVariableValue", "(", "schema", "Schema", ",", "definitionAST", "*", "ast", ".", "VariableDefinition", ",", "input", "interface", "{", "}", ")", "(", "interface", "{", "}", ",", "error", ")", "{", "ttype", ",", "err", ":=", "typeFromAST", "(", "schema", ",", "definitionAST", ".", "Type", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "variable", ":=", "definitionAST", ".", "Variable", "\n\n", "if", "ttype", "==", "nil", "||", "!", "IsInputType", "(", "ttype", ")", "{", "return", "\"", "\"", ",", "gqlerrors", ".", "NewError", "(", "fmt", ".", "Sprintf", "(", "`Variable \"$%v\" expected value of type `", "+", "`\"%v\" which cannot be used as an input type.`", ",", "variable", ".", "Name", ".", "Value", ",", "printer", ".", "Print", "(", "definitionAST", ".", "Type", ")", ")", ",", "[", "]", "ast", ".", "Node", "{", "definitionAST", "}", ",", "\"", "\"", ",", "nil", ",", "[", "]", "int", "{", "}", ",", "nil", ",", ")", "\n", "}", "\n\n", "isValid", ",", "messages", ":=", "isValidInputValue", "(", "input", ",", "ttype", ")", "\n", "if", "isValid", "{", "if", "isNullish", "(", "input", ")", "{", "if", "definitionAST", ".", "DefaultValue", "!=", "nil", "{", "return", "valueFromAST", "(", "definitionAST", ".", "DefaultValue", ",", "ttype", ",", "nil", ")", ",", "nil", "\n", "}", "\n", "}", "\n", "return", "coerceValue", "(", "ttype", ",", "input", ")", ",", "nil", "\n", "}", "\n", "if", "isNullish", "(", "input", ")", "{", "return", "\"", "\"", ",", "gqlerrors", ".", "NewError", "(", "fmt", ".", "Sprintf", "(", "`Variable \"$%v\" of required type `", "+", "`\"%v\" was not provided.`", ",", "variable", ".", "Name", ".", "Value", ",", "printer", ".", "Print", "(", "definitionAST", ".", "Type", ")", ")", ",", "[", "]", "ast", ".", "Node", "{", "definitionAST", "}", ",", "\"", "\"", ",", "nil", ",", "[", "]", "int", "{", "}", ",", "nil", ",", ")", "\n", "}", "\n", "// convert input interface into string for error message", "bts", ",", "_", ":=", "json", ".", "Marshal", "(", "input", ")", "\n", "var", "(", "inputStr", "=", "string", "(", "bts", ")", "\n", "msg", "string", "\n", ")", "\n", "if", "len", "(", "messages", ")", ">", "0", "{", "msg", "=", "\"", "\\n", "\"", "+", "strings", ".", "Join", "(", "messages", ",", "\"", "\\n", "\"", ")", "\n", "}", "\n\n", "return", "\"", "\"", ",", "gqlerrors", ".", "NewError", "(", "fmt", ".", "Sprintf", "(", "`Variable \"$%v\" got invalid value `", "+", "`%v.%v`", ",", "variable", ".", "Name", ".", "Value", ",", "inputStr", ",", "msg", ")", ",", "[", "]", "ast", ".", "Node", "{", "definitionAST", "}", ",", "\"", "\"", ",", "nil", ",", "[", "]", "int", "{", "}", ",", "nil", ",", ")", "\n", "}" ]
// Given a variable definition, and any value of input, return a value which // adheres to the variable definition, or throw an error.
[ "Given", "a", "variable", "definition", "and", "any", "value", "of", "input", "return", "a", "value", "which", "adheres", "to", "the", "variable", "definition", "or", "throw", "an", "error", "." ]
199d20bbfed70dae8c7d4619d4e0d339ce738b43
https://github.com/graphql-go/graphql/blob/199d20bbfed70dae8c7d4619d4e0d339ce738b43/values.go#L72-L130
train
graphql-go/graphql
values.go
coerceValue
func coerceValue(ttype Input, value interface{}) interface{} { if isNullish(value) { return nil } switch ttype := ttype.(type) { case *NonNull: return coerceValue(ttype.OfType, value) case *List: var values = []interface{}{} valType := reflect.ValueOf(value) if valType.Kind() == reflect.Slice { for i := 0; i < valType.Len(); i++ { val := valType.Index(i).Interface() values = append(values, coerceValue(ttype.OfType, val)) } return values } return append(values, coerceValue(ttype.OfType, value)) case *InputObject: var obj = map[string]interface{}{} valueMap, _ := value.(map[string]interface{}) if valueMap == nil { valueMap = map[string]interface{}{} } for name, field := range ttype.Fields() { fieldValue := coerceValue(field.Type, valueMap[name]) if isNullish(fieldValue) { fieldValue = field.DefaultValue } if !isNullish(fieldValue) { obj[name] = fieldValue } } return obj case *Scalar: if parsed := ttype.ParseValue(value); !isNullish(parsed) { return parsed } case *Enum: if parsed := ttype.ParseValue(value); !isNullish(parsed) { return parsed } } return nil }
go
func coerceValue(ttype Input, value interface{}) interface{} { if isNullish(value) { return nil } switch ttype := ttype.(type) { case *NonNull: return coerceValue(ttype.OfType, value) case *List: var values = []interface{}{} valType := reflect.ValueOf(value) if valType.Kind() == reflect.Slice { for i := 0; i < valType.Len(); i++ { val := valType.Index(i).Interface() values = append(values, coerceValue(ttype.OfType, val)) } return values } return append(values, coerceValue(ttype.OfType, value)) case *InputObject: var obj = map[string]interface{}{} valueMap, _ := value.(map[string]interface{}) if valueMap == nil { valueMap = map[string]interface{}{} } for name, field := range ttype.Fields() { fieldValue := coerceValue(field.Type, valueMap[name]) if isNullish(fieldValue) { fieldValue = field.DefaultValue } if !isNullish(fieldValue) { obj[name] = fieldValue } } return obj case *Scalar: if parsed := ttype.ParseValue(value); !isNullish(parsed) { return parsed } case *Enum: if parsed := ttype.ParseValue(value); !isNullish(parsed) { return parsed } } return nil }
[ "func", "coerceValue", "(", "ttype", "Input", ",", "value", "interface", "{", "}", ")", "interface", "{", "}", "{", "if", "isNullish", "(", "value", ")", "{", "return", "nil", "\n", "}", "\n", "switch", "ttype", ":=", "ttype", ".", "(", "type", ")", "{", "case", "*", "NonNull", ":", "return", "coerceValue", "(", "ttype", ".", "OfType", ",", "value", ")", "\n", "case", "*", "List", ":", "var", "values", "=", "[", "]", "interface", "{", "}", "{", "}", "\n", "valType", ":=", "reflect", ".", "ValueOf", "(", "value", ")", "\n", "if", "valType", ".", "Kind", "(", ")", "==", "reflect", ".", "Slice", "{", "for", "i", ":=", "0", ";", "i", "<", "valType", ".", "Len", "(", ")", ";", "i", "++", "{", "val", ":=", "valType", ".", "Index", "(", "i", ")", ".", "Interface", "(", ")", "\n", "values", "=", "append", "(", "values", ",", "coerceValue", "(", "ttype", ".", "OfType", ",", "val", ")", ")", "\n", "}", "\n", "return", "values", "\n", "}", "\n", "return", "append", "(", "values", ",", "coerceValue", "(", "ttype", ".", "OfType", ",", "value", ")", ")", "\n", "case", "*", "InputObject", ":", "var", "obj", "=", "map", "[", "string", "]", "interface", "{", "}", "{", "}", "\n", "valueMap", ",", "_", ":=", "value", ".", "(", "map", "[", "string", "]", "interface", "{", "}", ")", "\n", "if", "valueMap", "==", "nil", "{", "valueMap", "=", "map", "[", "string", "]", "interface", "{", "}", "{", "}", "\n", "}", "\n\n", "for", "name", ",", "field", ":=", "range", "ttype", ".", "Fields", "(", ")", "{", "fieldValue", ":=", "coerceValue", "(", "field", ".", "Type", ",", "valueMap", "[", "name", "]", ")", "\n", "if", "isNullish", "(", "fieldValue", ")", "{", "fieldValue", "=", "field", ".", "DefaultValue", "\n", "}", "\n", "if", "!", "isNullish", "(", "fieldValue", ")", "{", "obj", "[", "name", "]", "=", "fieldValue", "\n", "}", "\n", "}", "\n", "return", "obj", "\n", "case", "*", "Scalar", ":", "if", "parsed", ":=", "ttype", ".", "ParseValue", "(", "value", ")", ";", "!", "isNullish", "(", "parsed", ")", "{", "return", "parsed", "\n", "}", "\n", "case", "*", "Enum", ":", "if", "parsed", ":=", "ttype", ".", "ParseValue", "(", "value", ")", ";", "!", "isNullish", "(", "parsed", ")", "{", "return", "parsed", "\n", "}", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Given a type and any value, return a runtime value coerced to match the type.
[ "Given", "a", "type", "and", "any", "value", "return", "a", "runtime", "value", "coerced", "to", "match", "the", "type", "." ]
199d20bbfed70dae8c7d4619d4e0d339ce738b43
https://github.com/graphql-go/graphql/blob/199d20bbfed70dae8c7d4619d4e0d339ce738b43/values.go#L133-L179
train
graphql-go/graphql
values.go
isNullish
func isNullish(src interface{}) bool { if src == nil { return true } value := reflect.ValueOf(src) if value.Kind() == reflect.Ptr { if value.IsNil() { return true } value = value.Elem() } switch value.Kind() { case reflect.String: // if src is ptr type and len(string)=0, it returns false if !value.IsValid() { return true } case reflect.Int: return math.IsNaN(float64(value.Int())) case reflect.Float32, reflect.Float64: return math.IsNaN(float64(value.Float())) } return false }
go
func isNullish(src interface{}) bool { if src == nil { return true } value := reflect.ValueOf(src) if value.Kind() == reflect.Ptr { if value.IsNil() { return true } value = value.Elem() } switch value.Kind() { case reflect.String: // if src is ptr type and len(string)=0, it returns false if !value.IsValid() { return true } case reflect.Int: return math.IsNaN(float64(value.Int())) case reflect.Float32, reflect.Float64: return math.IsNaN(float64(value.Float())) } return false }
[ "func", "isNullish", "(", "src", "interface", "{", "}", ")", "bool", "{", "if", "src", "==", "nil", "{", "return", "true", "\n", "}", "\n", "value", ":=", "reflect", ".", "ValueOf", "(", "src", ")", "\n", "if", "value", ".", "Kind", "(", ")", "==", "reflect", ".", "Ptr", "{", "if", "value", ".", "IsNil", "(", ")", "{", "return", "true", "\n", "}", "\n", "value", "=", "value", ".", "Elem", "(", ")", "\n", "}", "\n", "switch", "value", ".", "Kind", "(", ")", "{", "case", "reflect", ".", "String", ":", "// if src is ptr type and len(string)=0, it returns false", "if", "!", "value", ".", "IsValid", "(", ")", "{", "return", "true", "\n", "}", "\n", "case", "reflect", ".", "Int", ":", "return", "math", ".", "IsNaN", "(", "float64", "(", "value", ".", "Int", "(", ")", ")", ")", "\n", "case", "reflect", ".", "Float32", ",", "reflect", ".", "Float64", ":", "return", "math", ".", "IsNaN", "(", "float64", "(", "value", ".", "Float", "(", ")", ")", ")", "\n", "}", "\n", "return", "false", "\n", "}" ]
// Returns true if a value is null, undefined, or NaN.
[ "Returns", "true", "if", "a", "value", "is", "null", "undefined", "or", "NaN", "." ]
199d20bbfed70dae8c7d4619d4e0d339ce738b43
https://github.com/graphql-go/graphql/blob/199d20bbfed70dae8c7d4619d4e0d339ce738b43/values.go#L299-L322
train
graphql-go/graphql
values.go
isIterable
func isIterable(src interface{}) bool { if src == nil { return false } t := reflect.TypeOf(src) if t.Kind() == reflect.Ptr { t = t.Elem() } return t.Kind() == reflect.Slice || t.Kind() == reflect.Array }
go
func isIterable(src interface{}) bool { if src == nil { return false } t := reflect.TypeOf(src) if t.Kind() == reflect.Ptr { t = t.Elem() } return t.Kind() == reflect.Slice || t.Kind() == reflect.Array }
[ "func", "isIterable", "(", "src", "interface", "{", "}", ")", "bool", "{", "if", "src", "==", "nil", "{", "return", "false", "\n", "}", "\n", "t", ":=", "reflect", ".", "TypeOf", "(", "src", ")", "\n", "if", "t", ".", "Kind", "(", ")", "==", "reflect", ".", "Ptr", "{", "t", "=", "t", ".", "Elem", "(", ")", "\n", "}", "\n", "return", "t", ".", "Kind", "(", ")", "==", "reflect", ".", "Slice", "||", "t", ".", "Kind", "(", ")", "==", "reflect", ".", "Array", "\n", "}" ]
// Returns true if src is a slice or an array
[ "Returns", "true", "if", "src", "is", "a", "slice", "or", "an", "array" ]
199d20bbfed70dae8c7d4619d4e0d339ce738b43
https://github.com/graphql-go/graphql/blob/199d20bbfed70dae8c7d4619d4e0d339ce738b43/values.go#L325-L334
train
src-d/go-git
plumbing/format/packfile/encoder.go
NewEncoder
func NewEncoder(w io.Writer, s storer.EncodedObjectStorer, useRefDeltas bool) *Encoder { h := plumbing.Hasher{ Hash: sha1.New(), } mw := io.MultiWriter(w, h) ow := newOffsetWriter(mw) zw := zlib.NewWriter(mw) return &Encoder{ selector: newDeltaSelector(s), w: ow, zw: zw, hasher: h, useRefDeltas: useRefDeltas, } }
go
func NewEncoder(w io.Writer, s storer.EncodedObjectStorer, useRefDeltas bool) *Encoder { h := plumbing.Hasher{ Hash: sha1.New(), } mw := io.MultiWriter(w, h) ow := newOffsetWriter(mw) zw := zlib.NewWriter(mw) return &Encoder{ selector: newDeltaSelector(s), w: ow, zw: zw, hasher: h, useRefDeltas: useRefDeltas, } }
[ "func", "NewEncoder", "(", "w", "io", ".", "Writer", ",", "s", "storer", ".", "EncodedObjectStorer", ",", "useRefDeltas", "bool", ")", "*", "Encoder", "{", "h", ":=", "plumbing", ".", "Hasher", "{", "Hash", ":", "sha1", ".", "New", "(", ")", ",", "}", "\n", "mw", ":=", "io", ".", "MultiWriter", "(", "w", ",", "h", ")", "\n", "ow", ":=", "newOffsetWriter", "(", "mw", ")", "\n", "zw", ":=", "zlib", ".", "NewWriter", "(", "mw", ")", "\n", "return", "&", "Encoder", "{", "selector", ":", "newDeltaSelector", "(", "s", ")", ",", "w", ":", "ow", ",", "zw", ":", "zw", ",", "hasher", ":", "h", ",", "useRefDeltas", ":", "useRefDeltas", ",", "}", "\n", "}" ]
// NewEncoder creates a new packfile encoder using a specific Writer and // EncodedObjectStorer. By default deltas used to generate the packfile will be // OFSDeltaObject. To use Reference deltas, set useRefDeltas to true.
[ "NewEncoder", "creates", "a", "new", "packfile", "encoder", "using", "a", "specific", "Writer", "and", "EncodedObjectStorer", ".", "By", "default", "deltas", "used", "to", "generate", "the", "packfile", "will", "be", "OFSDeltaObject", ".", "To", "use", "Reference", "deltas", "set", "useRefDeltas", "to", "true", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/format/packfile/encoder.go#L28-L42
train
src-d/go-git
plumbing/format/packfile/encoder.go
Encode
func (e *Encoder) Encode( hashes []plumbing.Hash, packWindow uint, ) (plumbing.Hash, error) { objects, err := e.selector.ObjectsToPack(hashes, packWindow) if err != nil { return plumbing.ZeroHash, err } return e.encode(objects) }
go
func (e *Encoder) Encode( hashes []plumbing.Hash, packWindow uint, ) (plumbing.Hash, error) { objects, err := e.selector.ObjectsToPack(hashes, packWindow) if err != nil { return plumbing.ZeroHash, err } return e.encode(objects) }
[ "func", "(", "e", "*", "Encoder", ")", "Encode", "(", "hashes", "[", "]", "plumbing", ".", "Hash", ",", "packWindow", "uint", ",", ")", "(", "plumbing", ".", "Hash", ",", "error", ")", "{", "objects", ",", "err", ":=", "e", ".", "selector", ".", "ObjectsToPack", "(", "hashes", ",", "packWindow", ")", "\n", "if", "err", "!=", "nil", "{", "return", "plumbing", ".", "ZeroHash", ",", "err", "\n", "}", "\n\n", "return", "e", ".", "encode", "(", "objects", ")", "\n", "}" ]
// Encode creates a packfile containing all the objects referenced in // hashes and writes it to the writer in the Encoder. `packWindow` // specifies the size of the sliding window used to compare objects // for delta compression; 0 turns off delta compression entirely.
[ "Encode", "creates", "a", "packfile", "containing", "all", "the", "objects", "referenced", "in", "hashes", "and", "writes", "it", "to", "the", "writer", "in", "the", "Encoder", ".", "packWindow", "specifies", "the", "size", "of", "the", "sliding", "window", "used", "to", "compare", "objects", "for", "delta", "compression", ";", "0", "turns", "off", "delta", "compression", "entirely", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/format/packfile/encoder.go#L48-L58
train
src-d/go-git
plumbing/format/packfile/packfile.go
NewPackfileWithCache
func NewPackfileWithCache( index idxfile.Index, fs billy.Filesystem, file billy.File, cache cache.Object, ) *Packfile { s := NewScanner(file) return &Packfile{ index, fs, file, s, cache, make(map[int64]plumbing.ObjectType), } }
go
func NewPackfileWithCache( index idxfile.Index, fs billy.Filesystem, file billy.File, cache cache.Object, ) *Packfile { s := NewScanner(file) return &Packfile{ index, fs, file, s, cache, make(map[int64]plumbing.ObjectType), } }
[ "func", "NewPackfileWithCache", "(", "index", "idxfile", ".", "Index", ",", "fs", "billy", ".", "Filesystem", ",", "file", "billy", ".", "File", ",", "cache", "cache", ".", "Object", ",", ")", "*", "Packfile", "{", "s", ":=", "NewScanner", "(", "file", ")", "\n", "return", "&", "Packfile", "{", "index", ",", "fs", ",", "file", ",", "s", ",", "cache", ",", "make", "(", "map", "[", "int64", "]", "plumbing", ".", "ObjectType", ")", ",", "}", "\n", "}" ]
// NewPackfileWithCache creates a new Packfile with the given object cache. // If the filesystem is provided, the packfile will return FSObjects, otherwise // it will return MemoryObjects.
[ "NewPackfileWithCache", "creates", "a", "new", "Packfile", "with", "the", "given", "object", "cache", ".", "If", "the", "filesystem", "is", "provided", "the", "packfile", "will", "return", "FSObjects", "otherwise", "it", "will", "return", "MemoryObjects", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/format/packfile/packfile.go#L47-L62
train
src-d/go-git
plumbing/format/packfile/packfile.go
NewPackfile
func NewPackfile(index idxfile.Index, fs billy.Filesystem, file billy.File) *Packfile { return NewPackfileWithCache(index, fs, file, cache.NewObjectLRUDefault()) }
go
func NewPackfile(index idxfile.Index, fs billy.Filesystem, file billy.File) *Packfile { return NewPackfileWithCache(index, fs, file, cache.NewObjectLRUDefault()) }
[ "func", "NewPackfile", "(", "index", "idxfile", ".", "Index", ",", "fs", "billy", ".", "Filesystem", ",", "file", "billy", ".", "File", ")", "*", "Packfile", "{", "return", "NewPackfileWithCache", "(", "index", ",", "fs", ",", "file", ",", "cache", ".", "NewObjectLRUDefault", "(", ")", ")", "\n", "}" ]
// NewPackfile returns a packfile representation for the given packfile file // and packfile idx. // If the filesystem is provided, the packfile will return FSObjects, otherwise // it will return MemoryObjects.
[ "NewPackfile", "returns", "a", "packfile", "representation", "for", "the", "given", "packfile", "file", "and", "packfile", "idx", ".", "If", "the", "filesystem", "is", "provided", "the", "packfile", "will", "return", "FSObjects", "otherwise", "it", "will", "return", "MemoryObjects", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/format/packfile/packfile.go#L68-L70
train
src-d/go-git
plumbing/format/packfile/packfile.go
Get
func (p *Packfile) Get(h plumbing.Hash) (plumbing.EncodedObject, error) { offset, err := p.FindOffset(h) if err != nil { return nil, err } return p.objectAtOffset(offset, h) }
go
func (p *Packfile) Get(h plumbing.Hash) (plumbing.EncodedObject, error) { offset, err := p.FindOffset(h) if err != nil { return nil, err } return p.objectAtOffset(offset, h) }
[ "func", "(", "p", "*", "Packfile", ")", "Get", "(", "h", "plumbing", ".", "Hash", ")", "(", "plumbing", ".", "EncodedObject", ",", "error", ")", "{", "offset", ",", "err", ":=", "p", ".", "FindOffset", "(", "h", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "p", ".", "objectAtOffset", "(", "offset", ",", "h", ")", "\n", "}" ]
// Get retrieves the encoded object in the packfile with the given hash.
[ "Get", "retrieves", "the", "encoded", "object", "in", "the", "packfile", "with", "the", "given", "hash", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/format/packfile/packfile.go#L73-L80
train
src-d/go-git
plumbing/format/packfile/packfile.go
GetByOffset
func (p *Packfile) GetByOffset(o int64) (plumbing.EncodedObject, error) { hash, err := p.FindHash(o) if err != nil { return nil, err } return p.objectAtOffset(o, hash) }
go
func (p *Packfile) GetByOffset(o int64) (plumbing.EncodedObject, error) { hash, err := p.FindHash(o) if err != nil { return nil, err } return p.objectAtOffset(o, hash) }
[ "func", "(", "p", "*", "Packfile", ")", "GetByOffset", "(", "o", "int64", ")", "(", "plumbing", ".", "EncodedObject", ",", "error", ")", "{", "hash", ",", "err", ":=", "p", ".", "FindHash", "(", "o", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "p", ".", "objectAtOffset", "(", "o", ",", "hash", ")", "\n", "}" ]
// GetByOffset retrieves the encoded object from the packfile at the given // offset.
[ "GetByOffset", "retrieves", "the", "encoded", "object", "from", "the", "packfile", "at", "the", "given", "offset", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/format/packfile/packfile.go#L84-L91
train
src-d/go-git
plumbing/format/packfile/packfile.go
GetSizeByOffset
func (p *Packfile) GetSizeByOffset(o int64) (size int64, err error) { if _, err := p.s.SeekFromStart(o); err != nil { if err == io.EOF || isInvalid(err) { return 0, plumbing.ErrObjectNotFound } return 0, err } h, err := p.nextObjectHeader() if err != nil { return 0, err } return p.getObjectSize(h) }
go
func (p *Packfile) GetSizeByOffset(o int64) (size int64, err error) { if _, err := p.s.SeekFromStart(o); err != nil { if err == io.EOF || isInvalid(err) { return 0, plumbing.ErrObjectNotFound } return 0, err } h, err := p.nextObjectHeader() if err != nil { return 0, err } return p.getObjectSize(h) }
[ "func", "(", "p", "*", "Packfile", ")", "GetSizeByOffset", "(", "o", "int64", ")", "(", "size", "int64", ",", "err", "error", ")", "{", "if", "_", ",", "err", ":=", "p", ".", "s", ".", "SeekFromStart", "(", "o", ")", ";", "err", "!=", "nil", "{", "if", "err", "==", "io", ".", "EOF", "||", "isInvalid", "(", "err", ")", "{", "return", "0", ",", "plumbing", ".", "ErrObjectNotFound", "\n", "}", "\n\n", "return", "0", ",", "err", "\n", "}", "\n\n", "h", ",", "err", ":=", "p", ".", "nextObjectHeader", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n", "return", "p", ".", "getObjectSize", "(", "h", ")", "\n", "}" ]
// GetSizeByOffset retrieves the size of the encoded object from the // packfile with the given offset.
[ "GetSizeByOffset", "retrieves", "the", "size", "of", "the", "encoded", "object", "from", "the", "packfile", "with", "the", "given", "offset", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/format/packfile/packfile.go#L95-L109
train
src-d/go-git
plumbing/format/packfile/packfile.go
GetAll
func (p *Packfile) GetAll() (storer.EncodedObjectIter, error) { return p.GetByType(plumbing.AnyObject) }
go
func (p *Packfile) GetAll() (storer.EncodedObjectIter, error) { return p.GetByType(plumbing.AnyObject) }
[ "func", "(", "p", "*", "Packfile", ")", "GetAll", "(", ")", "(", "storer", ".", "EncodedObjectIter", ",", "error", ")", "{", "return", "p", ".", "GetByType", "(", "plumbing", ".", "AnyObject", ")", "\n", "}" ]
// GetAll returns an iterator with all encoded objects in the packfile. // The iterator returned is not thread-safe, it should be used in the same // thread as the Packfile instance.
[ "GetAll", "returns", "an", "iterator", "with", "all", "encoded", "objects", "in", "the", "packfile", ".", "The", "iterator", "returned", "is", "not", "thread", "-", "safe", "it", "should", "be", "used", "in", "the", "same", "thread", "as", "the", "Packfile", "instance", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/format/packfile/packfile.go#L401-L403
train
src-d/go-git
plumbing/format/packfile/packfile.go
GetByType
func (p *Packfile) GetByType(typ plumbing.ObjectType) (storer.EncodedObjectIter, error) { switch typ { case plumbing.AnyObject, plumbing.BlobObject, plumbing.TreeObject, plumbing.CommitObject, plumbing.TagObject: entries, err := p.EntriesByOffset() if err != nil { return nil, err } return &objectIter{ // Easiest way to provide an object decoder is just to pass a Packfile // instance. To not mess with the seeks, it's a new instance with a // different scanner but the same cache and offset to hash map for // reusing as much cache as possible. p: p, iter: entries, typ: typ, }, nil default: return nil, plumbing.ErrInvalidType } }
go
func (p *Packfile) GetByType(typ plumbing.ObjectType) (storer.EncodedObjectIter, error) { switch typ { case plumbing.AnyObject, plumbing.BlobObject, plumbing.TreeObject, plumbing.CommitObject, plumbing.TagObject: entries, err := p.EntriesByOffset() if err != nil { return nil, err } return &objectIter{ // Easiest way to provide an object decoder is just to pass a Packfile // instance. To not mess with the seeks, it's a new instance with a // different scanner but the same cache and offset to hash map for // reusing as much cache as possible. p: p, iter: entries, typ: typ, }, nil default: return nil, plumbing.ErrInvalidType } }
[ "func", "(", "p", "*", "Packfile", ")", "GetByType", "(", "typ", "plumbing", ".", "ObjectType", ")", "(", "storer", ".", "EncodedObjectIter", ",", "error", ")", "{", "switch", "typ", "{", "case", "plumbing", ".", "AnyObject", ",", "plumbing", ".", "BlobObject", ",", "plumbing", ".", "TreeObject", ",", "plumbing", ".", "CommitObject", ",", "plumbing", ".", "TagObject", ":", "entries", ",", "err", ":=", "p", ".", "EntriesByOffset", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "&", "objectIter", "{", "// Easiest way to provide an object decoder is just to pass a Packfile", "// instance. To not mess with the seeks, it's a new instance with a", "// different scanner but the same cache and offset to hash map for", "// reusing as much cache as possible.", "p", ":", "p", ",", "iter", ":", "entries", ",", "typ", ":", "typ", ",", "}", ",", "nil", "\n", "default", ":", "return", "nil", ",", "plumbing", ".", "ErrInvalidType", "\n", "}", "\n", "}" ]
// GetByType returns all the objects of the given type.
[ "GetByType", "returns", "all", "the", "objects", "of", "the", "given", "type", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/format/packfile/packfile.go#L406-L430
train
src-d/go-git
plumbing/format/packfile/packfile.go
ID
func (p *Packfile) ID() (plumbing.Hash, error) { prev, err := p.file.Seek(-20, io.SeekEnd) if err != nil { return plumbing.ZeroHash, err } var hash plumbing.Hash if _, err := io.ReadFull(p.file, hash[:]); err != nil { return plumbing.ZeroHash, err } if _, err := p.file.Seek(prev, io.SeekStart); err != nil { return plumbing.ZeroHash, err } return hash, nil }
go
func (p *Packfile) ID() (plumbing.Hash, error) { prev, err := p.file.Seek(-20, io.SeekEnd) if err != nil { return plumbing.ZeroHash, err } var hash plumbing.Hash if _, err := io.ReadFull(p.file, hash[:]); err != nil { return plumbing.ZeroHash, err } if _, err := p.file.Seek(prev, io.SeekStart); err != nil { return plumbing.ZeroHash, err } return hash, nil }
[ "func", "(", "p", "*", "Packfile", ")", "ID", "(", ")", "(", "plumbing", ".", "Hash", ",", "error", ")", "{", "prev", ",", "err", ":=", "p", ".", "file", ".", "Seek", "(", "-", "20", ",", "io", ".", "SeekEnd", ")", "\n", "if", "err", "!=", "nil", "{", "return", "plumbing", ".", "ZeroHash", ",", "err", "\n", "}", "\n\n", "var", "hash", "plumbing", ".", "Hash", "\n", "if", "_", ",", "err", ":=", "io", ".", "ReadFull", "(", "p", ".", "file", ",", "hash", "[", ":", "]", ")", ";", "err", "!=", "nil", "{", "return", "plumbing", ".", "ZeroHash", ",", "err", "\n", "}", "\n\n", "if", "_", ",", "err", ":=", "p", ".", "file", ".", "Seek", "(", "prev", ",", "io", ".", "SeekStart", ")", ";", "err", "!=", "nil", "{", "return", "plumbing", ".", "ZeroHash", ",", "err", "\n", "}", "\n\n", "return", "hash", ",", "nil", "\n", "}" ]
// ID returns the ID of the packfile, which is the checksum at the end of it.
[ "ID", "returns", "the", "ID", "of", "the", "packfile", "which", "is", "the", "checksum", "at", "the", "end", "of", "it", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/format/packfile/packfile.go#L433-L449
train
src-d/go-git
plumbing/format/packfile/packfile.go
Close
func (p *Packfile) Close() error { closer, ok := p.file.(io.Closer) if !ok { return nil } return closer.Close() }
go
func (p *Packfile) Close() error { closer, ok := p.file.(io.Closer) if !ok { return nil } return closer.Close() }
[ "func", "(", "p", "*", "Packfile", ")", "Close", "(", ")", "error", "{", "closer", ",", "ok", ":=", "p", ".", "file", ".", "(", "io", ".", "Closer", ")", "\n", "if", "!", "ok", "{", "return", "nil", "\n", "}", "\n\n", "return", "closer", ".", "Close", "(", ")", "\n", "}" ]
// Close the packfile and its resources.
[ "Close", "the", "packfile", "and", "its", "resources", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/format/packfile/packfile.go#L457-L464
train
src-d/go-git
plumbing/format/packfile/packfile.go
isInvalid
func isInvalid(err error) bool { pe, ok := err.(*os.PathError) if !ok { return false } errstr := pe.Err.Error() return errstr == errInvalidUnix || errstr == errInvalidWindows }
go
func isInvalid(err error) bool { pe, ok := err.(*os.PathError) if !ok { return false } errstr := pe.Err.Error() return errstr == errInvalidUnix || errstr == errInvalidWindows }
[ "func", "isInvalid", "(", "err", "error", ")", "bool", "{", "pe", ",", "ok", ":=", "err", ".", "(", "*", "os", ".", "PathError", ")", "\n", "if", "!", "ok", "{", "return", "false", "\n", "}", "\n\n", "errstr", ":=", "pe", ".", "Err", ".", "Error", "(", ")", "\n", "return", "errstr", "==", "errInvalidUnix", "||", "errstr", "==", "errInvalidWindows", "\n", "}" ]
// isInvalid checks whether an error is an os.PathError with an os.ErrInvalid // error inside. It also checks for the windows error, which is different from // os.ErrInvalid.
[ "isInvalid", "checks", "whether", "an", "error", "is", "an", "os", ".", "PathError", "with", "an", "os", ".", "ErrInvalid", "error", "inside", ".", "It", "also", "checks", "for", "the", "windows", "error", "which", "is", "different", "from", "os", ".", "ErrInvalid", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/format/packfile/packfile.go#L549-L557
train
src-d/go-git
plumbing/transport/common.go
String
func (u *Endpoint) String() string { var buf bytes.Buffer if u.Protocol != "" { buf.WriteString(u.Protocol) buf.WriteByte(':') } if u.Protocol != "" || u.Host != "" || u.User != "" || u.Password != "" { buf.WriteString("//") if u.User != "" || u.Password != "" { buf.WriteString(url.PathEscape(u.User)) if u.Password != "" { buf.WriteByte(':') buf.WriteString(url.PathEscape(u.Password)) } buf.WriteByte('@') } if u.Host != "" { buf.WriteString(u.Host) if u.Port != 0 { port, ok := defaultPorts[strings.ToLower(u.Protocol)] if !ok || ok && port != u.Port { fmt.Fprintf(&buf, ":%d", u.Port) } } } } if u.Path != "" && u.Path[0] != '/' && u.Host != "" { buf.WriteByte('/') } buf.WriteString(u.Path) return buf.String() }
go
func (u *Endpoint) String() string { var buf bytes.Buffer if u.Protocol != "" { buf.WriteString(u.Protocol) buf.WriteByte(':') } if u.Protocol != "" || u.Host != "" || u.User != "" || u.Password != "" { buf.WriteString("//") if u.User != "" || u.Password != "" { buf.WriteString(url.PathEscape(u.User)) if u.Password != "" { buf.WriteByte(':') buf.WriteString(url.PathEscape(u.Password)) } buf.WriteByte('@') } if u.Host != "" { buf.WriteString(u.Host) if u.Port != 0 { port, ok := defaultPorts[strings.ToLower(u.Protocol)] if !ok || ok && port != u.Port { fmt.Fprintf(&buf, ":%d", u.Port) } } } } if u.Path != "" && u.Path[0] != '/' && u.Host != "" { buf.WriteByte('/') } buf.WriteString(u.Path) return buf.String() }
[ "func", "(", "u", "*", "Endpoint", ")", "String", "(", ")", "string", "{", "var", "buf", "bytes", ".", "Buffer", "\n", "if", "u", ".", "Protocol", "!=", "\"", "\"", "{", "buf", ".", "WriteString", "(", "u", ".", "Protocol", ")", "\n", "buf", ".", "WriteByte", "(", "':'", ")", "\n", "}", "\n\n", "if", "u", ".", "Protocol", "!=", "\"", "\"", "||", "u", ".", "Host", "!=", "\"", "\"", "||", "u", ".", "User", "!=", "\"", "\"", "||", "u", ".", "Password", "!=", "\"", "\"", "{", "buf", ".", "WriteString", "(", "\"", "\"", ")", "\n\n", "if", "u", ".", "User", "!=", "\"", "\"", "||", "u", ".", "Password", "!=", "\"", "\"", "{", "buf", ".", "WriteString", "(", "url", ".", "PathEscape", "(", "u", ".", "User", ")", ")", "\n", "if", "u", ".", "Password", "!=", "\"", "\"", "{", "buf", ".", "WriteByte", "(", "':'", ")", "\n", "buf", ".", "WriteString", "(", "url", ".", "PathEscape", "(", "u", ".", "Password", ")", ")", "\n", "}", "\n\n", "buf", ".", "WriteByte", "(", "'@'", ")", "\n", "}", "\n\n", "if", "u", ".", "Host", "!=", "\"", "\"", "{", "buf", ".", "WriteString", "(", "u", ".", "Host", ")", "\n\n", "if", "u", ".", "Port", "!=", "0", "{", "port", ",", "ok", ":=", "defaultPorts", "[", "strings", ".", "ToLower", "(", "u", ".", "Protocol", ")", "]", "\n", "if", "!", "ok", "||", "ok", "&&", "port", "!=", "u", ".", "Port", "{", "fmt", ".", "Fprintf", "(", "&", "buf", ",", "\"", "\"", ",", "u", ".", "Port", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "}", "\n\n", "if", "u", ".", "Path", "!=", "\"", "\"", "&&", "u", ".", "Path", "[", "0", "]", "!=", "'/'", "&&", "u", ".", "Host", "!=", "\"", "\"", "{", "buf", ".", "WriteByte", "(", "'/'", ")", "\n", "}", "\n\n", "buf", ".", "WriteString", "(", "u", ".", "Path", ")", "\n", "return", "buf", ".", "String", "(", ")", "\n", "}" ]
// String returns a string representation of the Git URL.
[ "String", "returns", "a", "string", "representation", "of", "the", "Git", "URL", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/transport/common.go#L120-L158
train
src-d/go-git
plumbing/transport/common.go
FilterUnsupportedCapabilities
func FilterUnsupportedCapabilities(list *capability.List) { for _, c := range UnsupportedCapabilities { list.Delete(c) } }
go
func FilterUnsupportedCapabilities(list *capability.List) { for _, c := range UnsupportedCapabilities { list.Delete(c) } }
[ "func", "FilterUnsupportedCapabilities", "(", "list", "*", "capability", ".", "List", ")", "{", "for", "_", ",", "c", ":=", "range", "UnsupportedCapabilities", "{", "list", ".", "Delete", "(", "c", ")", "\n", "}", "\n", "}" ]
// FilterUnsupportedCapabilities it filter out all the UnsupportedCapabilities // from a capability.List, the intended usage is on the client implementation // to filter the capabilities from an AdvRefs message.
[ "FilterUnsupportedCapabilities", "it", "filter", "out", "all", "the", "UnsupportedCapabilities", "from", "a", "capability", ".", "List", "the", "intended", "usage", "is", "on", "the", "client", "implementation", "to", "filter", "the", "capabilities", "from", "an", "AdvRefs", "message", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/transport/common.go#L270-L274
train
src-d/go-git
plumbing/format/objfile/writer.go
NewWriter
func NewWriter(w io.Writer) *Writer { return &Writer{ raw: w, zlib: zlib.NewWriter(w), } }
go
func NewWriter(w io.Writer) *Writer { return &Writer{ raw: w, zlib: zlib.NewWriter(w), } }
[ "func", "NewWriter", "(", "w", "io", ".", "Writer", ")", "*", "Writer", "{", "return", "&", "Writer", "{", "raw", ":", "w", ",", "zlib", ":", "zlib", ".", "NewWriter", "(", "w", ")", ",", "}", "\n", "}" ]
// NewWriter returns a new Writer writing to w. // // The returned Writer implements io.WriteCloser. Close should be called when // finished with the Writer. Close will not close the underlying io.Writer.
[ "NewWriter", "returns", "a", "new", "Writer", "writing", "to", "w", ".", "The", "returned", "Writer", "implements", "io", ".", "WriteCloser", ".", "Close", "should", "be", "called", "when", "finished", "with", "the", "Writer", ".", "Close", "will", "not", "close", "the", "underlying", "io", ".", "Writer", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/format/objfile/writer.go#L33-L38
train
src-d/go-git
plumbing/format/objfile/writer.go
WriteHeader
func (w *Writer) WriteHeader(t plumbing.ObjectType, size int64) error { if !t.Valid() { return plumbing.ErrInvalidType } if size < 0 { return ErrNegativeSize } b := t.Bytes() b = append(b, ' ') b = append(b, []byte(strconv.FormatInt(size, 10))...) b = append(b, 0) defer w.prepareForWrite(t, size) _, err := w.zlib.Write(b) return err }
go
func (w *Writer) WriteHeader(t plumbing.ObjectType, size int64) error { if !t.Valid() { return plumbing.ErrInvalidType } if size < 0 { return ErrNegativeSize } b := t.Bytes() b = append(b, ' ') b = append(b, []byte(strconv.FormatInt(size, 10))...) b = append(b, 0) defer w.prepareForWrite(t, size) _, err := w.zlib.Write(b) return err }
[ "func", "(", "w", "*", "Writer", ")", "WriteHeader", "(", "t", "plumbing", ".", "ObjectType", ",", "size", "int64", ")", "error", "{", "if", "!", "t", ".", "Valid", "(", ")", "{", "return", "plumbing", ".", "ErrInvalidType", "\n", "}", "\n", "if", "size", "<", "0", "{", "return", "ErrNegativeSize", "\n", "}", "\n\n", "b", ":=", "t", ".", "Bytes", "(", ")", "\n", "b", "=", "append", "(", "b", ",", "' '", ")", "\n", "b", "=", "append", "(", "b", ",", "[", "]", "byte", "(", "strconv", ".", "FormatInt", "(", "size", ",", "10", ")", ")", "...", ")", "\n", "b", "=", "append", "(", "b", ",", "0", ")", "\n\n", "defer", "w", ".", "prepareForWrite", "(", "t", ",", "size", ")", "\n", "_", ",", "err", ":=", "w", ".", "zlib", ".", "Write", "(", "b", ")", "\n\n", "return", "err", "\n", "}" ]
// WriteHeader writes the type and the size and prepares to accept the object's // contents. If an invalid t is provided, plumbing.ErrInvalidType is returned. If a // negative size is provided, ErrNegativeSize is returned.
[ "WriteHeader", "writes", "the", "type", "and", "the", "size", "and", "prepares", "to", "accept", "the", "object", "s", "contents", ".", "If", "an", "invalid", "t", "is", "provided", "plumbing", ".", "ErrInvalidType", "is", "returned", ".", "If", "a", "negative", "size", "is", "provided", "ErrNegativeSize", "is", "returned", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/format/objfile/writer.go#L43-L60
train
src-d/go-git
plumbing/format/objfile/writer.go
Write
func (w *Writer) Write(p []byte) (n int, err error) { if w.closed { return 0, ErrClosed } overwrite := false if int64(len(p)) > w.pending { p = p[0:w.pending] overwrite = true } n, err = w.multi.Write(p) w.pending -= int64(n) if err == nil && overwrite { err = ErrOverflow return } return }
go
func (w *Writer) Write(p []byte) (n int, err error) { if w.closed { return 0, ErrClosed } overwrite := false if int64(len(p)) > w.pending { p = p[0:w.pending] overwrite = true } n, err = w.multi.Write(p) w.pending -= int64(n) if err == nil && overwrite { err = ErrOverflow return } return }
[ "func", "(", "w", "*", "Writer", ")", "Write", "(", "p", "[", "]", "byte", ")", "(", "n", "int", ",", "err", "error", ")", "{", "if", "w", ".", "closed", "{", "return", "0", ",", "ErrClosed", "\n", "}", "\n\n", "overwrite", ":=", "false", "\n", "if", "int64", "(", "len", "(", "p", ")", ")", ">", "w", ".", "pending", "{", "p", "=", "p", "[", "0", ":", "w", ".", "pending", "]", "\n", "overwrite", "=", "true", "\n", "}", "\n\n", "n", ",", "err", "=", "w", ".", "multi", ".", "Write", "(", "p", ")", "\n", "w", ".", "pending", "-=", "int64", "(", "n", ")", "\n", "if", "err", "==", "nil", "&&", "overwrite", "{", "err", "=", "ErrOverflow", "\n", "return", "\n", "}", "\n\n", "return", "\n", "}" ]
// Write writes the object's contents. Write returns the error ErrOverflow if // more than size bytes are written after WriteHeader.
[ "Write", "writes", "the", "object", "s", "contents", ".", "Write", "returns", "the", "error", "ErrOverflow", "if", "more", "than", "size", "bytes", "are", "written", "after", "WriteHeader", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/format/objfile/writer.go#L71-L90
train
src-d/go-git
plumbing/format/objfile/writer.go
Close
func (w *Writer) Close() error { if err := w.zlib.Close(); err != nil { return err } w.closed = true return nil }
go
func (w *Writer) Close() error { if err := w.zlib.Close(); err != nil { return err } w.closed = true return nil }
[ "func", "(", "w", "*", "Writer", ")", "Close", "(", ")", "error", "{", "if", "err", ":=", "w", ".", "zlib", ".", "Close", "(", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "w", ".", "closed", "=", "true", "\n", "return", "nil", "\n", "}" ]
// Close releases any resources consumed by the Writer. // // Calling Close does not close the wrapped io.Writer originally passed to // NewWriter.
[ "Close", "releases", "any", "resources", "consumed", "by", "the", "Writer", ".", "Calling", "Close", "does", "not", "close", "the", "wrapped", "io", ".", "Writer", "originally", "passed", "to", "NewWriter", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/format/objfile/writer.go#L102-L109
train
src-d/go-git
storage/transactional/config.go
NewConfigStorage
func NewConfigStorage(s, temporal config.ConfigStorer) *ConfigStorage { return &ConfigStorage{ConfigStorer: s, temporal: temporal} }
go
func NewConfigStorage(s, temporal config.ConfigStorer) *ConfigStorage { return &ConfigStorage{ConfigStorer: s, temporal: temporal} }
[ "func", "NewConfigStorage", "(", "s", ",", "temporal", "config", ".", "ConfigStorer", ")", "*", "ConfigStorage", "{", "return", "&", "ConfigStorage", "{", "ConfigStorer", ":", "s", ",", "temporal", ":", "temporal", "}", "\n", "}" ]
// NewConfigStorage returns a new ConfigStorer based on a base storer and a // temporal storer.
[ "NewConfigStorage", "returns", "a", "new", "ConfigStorer", "based", "on", "a", "base", "storer", "and", "a", "temporal", "storer", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/storage/transactional/config.go#L15-L17
train
src-d/go-git
storage/transactional/config.go
SetConfig
func (c *ConfigStorage) SetConfig(cfg *config.Config) error { if err := c.temporal.SetConfig(cfg); err != nil { return err } c.set = true return nil }
go
func (c *ConfigStorage) SetConfig(cfg *config.Config) error { if err := c.temporal.SetConfig(cfg); err != nil { return err } c.set = true return nil }
[ "func", "(", "c", "*", "ConfigStorage", ")", "SetConfig", "(", "cfg", "*", "config", ".", "Config", ")", "error", "{", "if", "err", ":=", "c", ".", "temporal", ".", "SetConfig", "(", "cfg", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "c", ".", "set", "=", "true", "\n", "return", "nil", "\n", "}" ]
// SetConfig honors the storer.ConfigStorer interface.
[ "SetConfig", "honors", "the", "storer", ".", "ConfigStorer", "interface", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/storage/transactional/config.go#L20-L27
train
src-d/go-git
storage/transactional/config.go
Config
func (c *ConfigStorage) Config() (*config.Config, error) { if !c.set { return c.ConfigStorer.Config() } return c.temporal.Config() }
go
func (c *ConfigStorage) Config() (*config.Config, error) { if !c.set { return c.ConfigStorer.Config() } return c.temporal.Config() }
[ "func", "(", "c", "*", "ConfigStorage", ")", "Config", "(", ")", "(", "*", "config", ".", "Config", ",", "error", ")", "{", "if", "!", "c", ".", "set", "{", "return", "c", ".", "ConfigStorer", ".", "Config", "(", ")", "\n", "}", "\n\n", "return", "c", ".", "temporal", ".", "Config", "(", ")", "\n", "}" ]
// Config honors the storer.ConfigStorer interface.
[ "Config", "honors", "the", "storer", ".", "ConfigStorer", "interface", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/storage/transactional/config.go#L30-L36
train
src-d/go-git
storage/transactional/config.go
Commit
func (c *ConfigStorage) Commit() error { if !c.set { return nil } cfg, err := c.temporal.Config() if err != nil { return err } return c.ConfigStorer.SetConfig(cfg) }
go
func (c *ConfigStorage) Commit() error { if !c.set { return nil } cfg, err := c.temporal.Config() if err != nil { return err } return c.ConfigStorer.SetConfig(cfg) }
[ "func", "(", "c", "*", "ConfigStorage", ")", "Commit", "(", ")", "error", "{", "if", "!", "c", ".", "set", "{", "return", "nil", "\n", "}", "\n\n", "cfg", ",", "err", ":=", "c", ".", "temporal", ".", "Config", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "c", ".", "ConfigStorer", ".", "SetConfig", "(", "cfg", ")", "\n", "}" ]
// Commit it copies the config from the temporal storage into the base storage.
[ "Commit", "it", "copies", "the", "config", "from", "the", "temporal", "storage", "into", "the", "base", "storage", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/storage/transactional/config.go#L39-L50
train
src-d/go-git
plumbing/format/packfile/delta_index.go
findMatch
func (idx *deltaIndex) findMatch(src, tgt []byte, tgtOffset int) (srcOffset, l int) { if len(tgt) < tgtOffset+s { return 0, len(tgt) - tgtOffset } if len(src) < blksz { return 0, -1 } if len(tgt) >= tgtOffset+s && len(src) >= blksz { h := hashBlock(tgt, tgtOffset) tIdx := h & idx.mask eIdx := idx.table[tIdx] if eIdx != 0 { srcOffset = idx.entries[eIdx] } else { return } l = matchLength(src, tgt, tgtOffset, srcOffset) } return }
go
func (idx *deltaIndex) findMatch(src, tgt []byte, tgtOffset int) (srcOffset, l int) { if len(tgt) < tgtOffset+s { return 0, len(tgt) - tgtOffset } if len(src) < blksz { return 0, -1 } if len(tgt) >= tgtOffset+s && len(src) >= blksz { h := hashBlock(tgt, tgtOffset) tIdx := h & idx.mask eIdx := idx.table[tIdx] if eIdx != 0 { srcOffset = idx.entries[eIdx] } else { return } l = matchLength(src, tgt, tgtOffset, srcOffset) } return }
[ "func", "(", "idx", "*", "deltaIndex", ")", "findMatch", "(", "src", ",", "tgt", "[", "]", "byte", ",", "tgtOffset", "int", ")", "(", "srcOffset", ",", "l", "int", ")", "{", "if", "len", "(", "tgt", ")", "<", "tgtOffset", "+", "s", "{", "return", "0", ",", "len", "(", "tgt", ")", "-", "tgtOffset", "\n", "}", "\n\n", "if", "len", "(", "src", ")", "<", "blksz", "{", "return", "0", ",", "-", "1", "\n", "}", "\n\n", "if", "len", "(", "tgt", ")", ">=", "tgtOffset", "+", "s", "&&", "len", "(", "src", ")", ">=", "blksz", "{", "h", ":=", "hashBlock", "(", "tgt", ",", "tgtOffset", ")", "\n", "tIdx", ":=", "h", "&", "idx", ".", "mask", "\n", "eIdx", ":=", "idx", ".", "table", "[", "tIdx", "]", "\n", "if", "eIdx", "!=", "0", "{", "srcOffset", "=", "idx", ".", "entries", "[", "eIdx", "]", "\n", "}", "else", "{", "return", "\n", "}", "\n\n", "l", "=", "matchLength", "(", "src", ",", "tgt", ",", "tgtOffset", ",", "srcOffset", ")", "\n", "}", "\n\n", "return", "\n", "}" ]
// findMatch returns the offset of src where the block starting at tgtOffset // is and the length of the match. A length of 0 means there was no match. A // length of -1 means the src length is lower than the blksz and whatever // other positive length is the length of the match in bytes.
[ "findMatch", "returns", "the", "offset", "of", "src", "where", "the", "block", "starting", "at", "tgtOffset", "is", "and", "the", "length", "of", "the", "match", ".", "A", "length", "of", "0", "means", "there", "was", "no", "match", ".", "A", "length", "of", "-", "1", "means", "the", "src", "length", "is", "lower", "than", "the", "blksz", "and", "whatever", "other", "positive", "length", "is", "the", "length", "of", "the", "match", "in", "bytes", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/format/packfile/delta_index.go#L26-L49
train
src-d/go-git
plumbing/object/file.go
NewFile
func NewFile(name string, m filemode.FileMode, b *Blob) *File { return &File{Name: name, Mode: m, Blob: *b} }
go
func NewFile(name string, m filemode.FileMode, b *Blob) *File { return &File{Name: name, Mode: m, Blob: *b} }
[ "func", "NewFile", "(", "name", "string", ",", "m", "filemode", ".", "FileMode", ",", "b", "*", "Blob", ")", "*", "File", "{", "return", "&", "File", "{", "Name", ":", "name", ",", "Mode", ":", "m", ",", "Blob", ":", "*", "b", "}", "\n", "}" ]
// NewFile returns a File based on the given blob object
[ "NewFile", "returns", "a", "File", "based", "on", "the", "given", "blob", "object" ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/object/file.go#L26-L28
train
src-d/go-git
plumbing/object/file.go
Contents
func (f *File) Contents() (content string, err error) { reader, err := f.Reader() if err != nil { return "", err } defer ioutil.CheckClose(reader, &err) buf := new(bytes.Buffer) if _, err := buf.ReadFrom(reader); err != nil { return "", err } return buf.String(), nil }
go
func (f *File) Contents() (content string, err error) { reader, err := f.Reader() if err != nil { return "", err } defer ioutil.CheckClose(reader, &err) buf := new(bytes.Buffer) if _, err := buf.ReadFrom(reader); err != nil { return "", err } return buf.String(), nil }
[ "func", "(", "f", "*", "File", ")", "Contents", "(", ")", "(", "content", "string", ",", "err", "error", ")", "{", "reader", ",", "err", ":=", "f", ".", "Reader", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n", "defer", "ioutil", ".", "CheckClose", "(", "reader", ",", "&", "err", ")", "\n\n", "buf", ":=", "new", "(", "bytes", ".", "Buffer", ")", "\n", "if", "_", ",", "err", ":=", "buf", ".", "ReadFrom", "(", "reader", ")", ";", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n\n", "return", "buf", ".", "String", "(", ")", ",", "nil", "\n", "}" ]
// Contents returns the contents of a file as a string.
[ "Contents", "returns", "the", "contents", "of", "a", "file", "as", "a", "string", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/object/file.go#L31-L44
train
src-d/go-git
plumbing/object/file.go
IsBinary
func (f *File) IsBinary() (bin bool, err error) { reader, err := f.Reader() if err != nil { return false, err } defer ioutil.CheckClose(reader, &err) return binary.IsBinary(reader) }
go
func (f *File) IsBinary() (bin bool, err error) { reader, err := f.Reader() if err != nil { return false, err } defer ioutil.CheckClose(reader, &err) return binary.IsBinary(reader) }
[ "func", "(", "f", "*", "File", ")", "IsBinary", "(", ")", "(", "bin", "bool", ",", "err", "error", ")", "{", "reader", ",", "err", ":=", "f", ".", "Reader", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", ",", "err", "\n", "}", "\n", "defer", "ioutil", ".", "CheckClose", "(", "reader", ",", "&", "err", ")", "\n\n", "return", "binary", ".", "IsBinary", "(", "reader", ")", "\n", "}" ]
// IsBinary returns if the file is binary or not
[ "IsBinary", "returns", "if", "the", "file", "is", "binary", "or", "not" ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/object/file.go#L47-L55
train
src-d/go-git
plumbing/object/file.go
Next
func (iter *FileIter) Next() (*File, error) { for { name, entry, err := iter.w.Next() if err != nil { return nil, err } if entry.Mode == filemode.Dir || entry.Mode == filemode.Submodule { continue } blob, err := GetBlob(iter.s, entry.Hash) if err != nil { return nil, err } return NewFile(name, entry.Mode, blob), nil } }
go
func (iter *FileIter) Next() (*File, error) { for { name, entry, err := iter.w.Next() if err != nil { return nil, err } if entry.Mode == filemode.Dir || entry.Mode == filemode.Submodule { continue } blob, err := GetBlob(iter.s, entry.Hash) if err != nil { return nil, err } return NewFile(name, entry.Mode, blob), nil } }
[ "func", "(", "iter", "*", "FileIter", ")", "Next", "(", ")", "(", "*", "File", ",", "error", ")", "{", "for", "{", "name", ",", "entry", ",", "err", ":=", "iter", ".", "w", ".", "Next", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "if", "entry", ".", "Mode", "==", "filemode", ".", "Dir", "||", "entry", ".", "Mode", "==", "filemode", ".", "Submodule", "{", "continue", "\n", "}", "\n\n", "blob", ",", "err", ":=", "GetBlob", "(", "iter", ".", "s", ",", "entry", ".", "Hash", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "NewFile", "(", "name", ",", "entry", ".", "Mode", ",", "blob", ")", ",", "nil", "\n", "}", "\n", "}" ]
// Next moves the iterator to the next file and returns a pointer to it. If // there are no more files, it returns io.EOF.
[ "Next", "moves", "the", "iterator", "to", "the", "next", "file", "and", "returns", "a", "pointer", "to", "it", ".", "If", "there", "are", "no", "more", "files", "it", "returns", "io", ".", "EOF", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/object/file.go#L89-L107
train
src-d/go-git
plumbing/object/file.go
ForEach
func (iter *FileIter) ForEach(cb func(*File) error) error { defer iter.Close() for { f, err := iter.Next() if err != nil { if err == io.EOF { return nil } return err } if err := cb(f); err != nil { if err == storer.ErrStop { return nil } return err } } }
go
func (iter *FileIter) ForEach(cb func(*File) error) error { defer iter.Close() for { f, err := iter.Next() if err != nil { if err == io.EOF { return nil } return err } if err := cb(f); err != nil { if err == storer.ErrStop { return nil } return err } } }
[ "func", "(", "iter", "*", "FileIter", ")", "ForEach", "(", "cb", "func", "(", "*", "File", ")", "error", ")", "error", "{", "defer", "iter", ".", "Close", "(", ")", "\n\n", "for", "{", "f", ",", "err", ":=", "iter", ".", "Next", "(", ")", "\n", "if", "err", "!=", "nil", "{", "if", "err", "==", "io", ".", "EOF", "{", "return", "nil", "\n", "}", "\n\n", "return", "err", "\n", "}", "\n\n", "if", "err", ":=", "cb", "(", "f", ")", ";", "err", "!=", "nil", "{", "if", "err", "==", "storer", ".", "ErrStop", "{", "return", "nil", "\n", "}", "\n\n", "return", "err", "\n", "}", "\n", "}", "\n", "}" ]
// ForEach call the cb function for each file contained in this iter until // an error happens or the end of the iter is reached. If plumbing.ErrStop is sent // the iteration is stop but no error is returned. The iterator is closed.
[ "ForEach", "call", "the", "cb", "function", "for", "each", "file", "contained", "in", "this", "iter", "until", "an", "error", "happens", "or", "the", "end", "of", "the", "iter", "is", "reached", ".", "If", "plumbing", ".", "ErrStop", "is", "sent", "the", "iteration", "is", "stop", "but", "no", "error", "is", "returned", ".", "The", "iterator", "is", "closed", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/object/file.go#L112-L133
train
src-d/go-git
internal/revision/parser.go
scan
func (p *Parser) scan() (token, string, error) { if p.unreadLastChar { p.unreadLastChar = false return p.currentParsedChar.tok, p.currentParsedChar.lit, nil } tok, lit, err := p.s.scan() p.currentParsedChar.tok, p.currentParsedChar.lit = tok, lit return tok, lit, err }
go
func (p *Parser) scan() (token, string, error) { if p.unreadLastChar { p.unreadLastChar = false return p.currentParsedChar.tok, p.currentParsedChar.lit, nil } tok, lit, err := p.s.scan() p.currentParsedChar.tok, p.currentParsedChar.lit = tok, lit return tok, lit, err }
[ "func", "(", "p", "*", "Parser", ")", "scan", "(", ")", "(", "token", ",", "string", ",", "error", ")", "{", "if", "p", ".", "unreadLastChar", "{", "p", ".", "unreadLastChar", "=", "false", "\n", "return", "p", ".", "currentParsedChar", ".", "tok", ",", "p", ".", "currentParsedChar", ".", "lit", ",", "nil", "\n", "}", "\n\n", "tok", ",", "lit", ",", "err", ":=", "p", ".", "s", ".", "scan", "(", ")", "\n\n", "p", ".", "currentParsedChar", ".", "tok", ",", "p", ".", "currentParsedChar", ".", "lit", "=", "tok", ",", "lit", "\n\n", "return", "tok", ",", "lit", ",", "err", "\n", "}" ]
// scan returns the next token from the underlying scanner // or the last scanned token if an unscan was requested
[ "scan", "returns", "the", "next", "token", "from", "the", "underlying", "scanner", "or", "the", "last", "scanned", "token", "if", "an", "unscan", "was", "requested" ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/internal/revision/parser.go#L121-L132
train
src-d/go-git
internal/revision/parser.go
Parse
func (p *Parser) Parse() ([]Revisioner, error) { var rev Revisioner var revs []Revisioner var tok token var err error for { tok, _, err = p.scan() if err != nil { return nil, err } switch tok { case at: rev, err = p.parseAt() case tilde: rev, err = p.parseTilde() case caret: rev, err = p.parseCaret() case colon: rev, err = p.parseColon() case eof: err = p.validateFullRevision(&revs) if err != nil { return []Revisioner{}, err } return revs, nil default: p.unscan() rev, err = p.parseRef() } if err != nil { return []Revisioner{}, err } revs = append(revs, rev) } }
go
func (p *Parser) Parse() ([]Revisioner, error) { var rev Revisioner var revs []Revisioner var tok token var err error for { tok, _, err = p.scan() if err != nil { return nil, err } switch tok { case at: rev, err = p.parseAt() case tilde: rev, err = p.parseTilde() case caret: rev, err = p.parseCaret() case colon: rev, err = p.parseColon() case eof: err = p.validateFullRevision(&revs) if err != nil { return []Revisioner{}, err } return revs, nil default: p.unscan() rev, err = p.parseRef() } if err != nil { return []Revisioner{}, err } revs = append(revs, rev) } }
[ "func", "(", "p", "*", "Parser", ")", "Parse", "(", ")", "(", "[", "]", "Revisioner", ",", "error", ")", "{", "var", "rev", "Revisioner", "\n", "var", "revs", "[", "]", "Revisioner", "\n", "var", "tok", "token", "\n", "var", "err", "error", "\n\n", "for", "{", "tok", ",", "_", ",", "err", "=", "p", ".", "scan", "(", ")", "\n\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "switch", "tok", "{", "case", "at", ":", "rev", ",", "err", "=", "p", ".", "parseAt", "(", ")", "\n", "case", "tilde", ":", "rev", ",", "err", "=", "p", ".", "parseTilde", "(", ")", "\n", "case", "caret", ":", "rev", ",", "err", "=", "p", ".", "parseCaret", "(", ")", "\n", "case", "colon", ":", "rev", ",", "err", "=", "p", ".", "parseColon", "(", ")", "\n", "case", "eof", ":", "err", "=", "p", ".", "validateFullRevision", "(", "&", "revs", ")", "\n\n", "if", "err", "!=", "nil", "{", "return", "[", "]", "Revisioner", "{", "}", ",", "err", "\n", "}", "\n\n", "return", "revs", ",", "nil", "\n", "default", ":", "p", ".", "unscan", "(", ")", "\n", "rev", ",", "err", "=", "p", ".", "parseRef", "(", ")", "\n", "}", "\n\n", "if", "err", "!=", "nil", "{", "return", "[", "]", "Revisioner", "{", "}", ",", "err", "\n", "}", "\n\n", "revs", "=", "append", "(", "revs", ",", "rev", ")", "\n", "}", "\n", "}" ]
// Parse explode a revision string into revisioner chunks
[ "Parse", "explode", "a", "revision", "string", "into", "revisioner", "chunks" ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/internal/revision/parser.go#L138-L179
train
src-d/go-git
internal/revision/parser.go
validateFullRevision
func (p *Parser) validateFullRevision(chunks *[]Revisioner) error { var hasReference bool for i, chunk := range *chunks { switch chunk.(type) { case Ref: if i == 0 { hasReference = true } else { return &ErrInvalidRevision{`reference must be defined once at the beginning`} } case AtDate: if len(*chunks) == 1 || hasReference && len(*chunks) == 2 { return nil } return &ErrInvalidRevision{`"@" statement is not valid, could be : <refname>@{<ISO-8601 date>}, @{<ISO-8601 date>}`} case AtReflog: if len(*chunks) == 1 || hasReference && len(*chunks) == 2 { return nil } return &ErrInvalidRevision{`"@" statement is not valid, could be : <refname>@{<n>}, @{<n>}`} case AtCheckout: if len(*chunks) == 1 { return nil } return &ErrInvalidRevision{`"@" statement is not valid, could be : @{-<n>}`} case AtUpstream: if len(*chunks) == 1 || hasReference && len(*chunks) == 2 { return nil } return &ErrInvalidRevision{`"@" statement is not valid, could be : <refname>@{upstream}, @{upstream}, <refname>@{u}, @{u}`} case AtPush: if len(*chunks) == 1 || hasReference && len(*chunks) == 2 { return nil } return &ErrInvalidRevision{`"@" statement is not valid, could be : <refname>@{push}, @{push}`} case TildePath, CaretPath, CaretReg: if !hasReference { return &ErrInvalidRevision{`"~" or "^" statement must have a reference defined at the beginning`} } case ColonReg: if len(*chunks) == 1 { return nil } return &ErrInvalidRevision{`":" statement is not valid, could be : :/<regexp>`} case ColonPath: if i == len(*chunks)-1 && hasReference || len(*chunks) == 1 { return nil } return &ErrInvalidRevision{`":" statement is not valid, could be : <revision>:<path>`} case ColonStagePath: if len(*chunks) == 1 { return nil } return &ErrInvalidRevision{`":" statement is not valid, could be : :<n>:<path>`} } } return nil }
go
func (p *Parser) validateFullRevision(chunks *[]Revisioner) error { var hasReference bool for i, chunk := range *chunks { switch chunk.(type) { case Ref: if i == 0 { hasReference = true } else { return &ErrInvalidRevision{`reference must be defined once at the beginning`} } case AtDate: if len(*chunks) == 1 || hasReference && len(*chunks) == 2 { return nil } return &ErrInvalidRevision{`"@" statement is not valid, could be : <refname>@{<ISO-8601 date>}, @{<ISO-8601 date>}`} case AtReflog: if len(*chunks) == 1 || hasReference && len(*chunks) == 2 { return nil } return &ErrInvalidRevision{`"@" statement is not valid, could be : <refname>@{<n>}, @{<n>}`} case AtCheckout: if len(*chunks) == 1 { return nil } return &ErrInvalidRevision{`"@" statement is not valid, could be : @{-<n>}`} case AtUpstream: if len(*chunks) == 1 || hasReference && len(*chunks) == 2 { return nil } return &ErrInvalidRevision{`"@" statement is not valid, could be : <refname>@{upstream}, @{upstream}, <refname>@{u}, @{u}`} case AtPush: if len(*chunks) == 1 || hasReference && len(*chunks) == 2 { return nil } return &ErrInvalidRevision{`"@" statement is not valid, could be : <refname>@{push}, @{push}`} case TildePath, CaretPath, CaretReg: if !hasReference { return &ErrInvalidRevision{`"~" or "^" statement must have a reference defined at the beginning`} } case ColonReg: if len(*chunks) == 1 { return nil } return &ErrInvalidRevision{`":" statement is not valid, could be : :/<regexp>`} case ColonPath: if i == len(*chunks)-1 && hasReference || len(*chunks) == 1 { return nil } return &ErrInvalidRevision{`":" statement is not valid, could be : <revision>:<path>`} case ColonStagePath: if len(*chunks) == 1 { return nil } return &ErrInvalidRevision{`":" statement is not valid, could be : :<n>:<path>`} } } return nil }
[ "func", "(", "p", "*", "Parser", ")", "validateFullRevision", "(", "chunks", "*", "[", "]", "Revisioner", ")", "error", "{", "var", "hasReference", "bool", "\n\n", "for", "i", ",", "chunk", ":=", "range", "*", "chunks", "{", "switch", "chunk", ".", "(", "type", ")", "{", "case", "Ref", ":", "if", "i", "==", "0", "{", "hasReference", "=", "true", "\n", "}", "else", "{", "return", "&", "ErrInvalidRevision", "{", "`reference must be defined once at the beginning`", "}", "\n", "}", "\n", "case", "AtDate", ":", "if", "len", "(", "*", "chunks", ")", "==", "1", "||", "hasReference", "&&", "len", "(", "*", "chunks", ")", "==", "2", "{", "return", "nil", "\n", "}", "\n\n", "return", "&", "ErrInvalidRevision", "{", "`\"@\" statement is not valid, could be : <refname>@{<ISO-8601 date>}, @{<ISO-8601 date>}`", "}", "\n", "case", "AtReflog", ":", "if", "len", "(", "*", "chunks", ")", "==", "1", "||", "hasReference", "&&", "len", "(", "*", "chunks", ")", "==", "2", "{", "return", "nil", "\n", "}", "\n\n", "return", "&", "ErrInvalidRevision", "{", "`\"@\" statement is not valid, could be : <refname>@{<n>}, @{<n>}`", "}", "\n", "case", "AtCheckout", ":", "if", "len", "(", "*", "chunks", ")", "==", "1", "{", "return", "nil", "\n", "}", "\n\n", "return", "&", "ErrInvalidRevision", "{", "`\"@\" statement is not valid, could be : @{-<n>}`", "}", "\n", "case", "AtUpstream", ":", "if", "len", "(", "*", "chunks", ")", "==", "1", "||", "hasReference", "&&", "len", "(", "*", "chunks", ")", "==", "2", "{", "return", "nil", "\n", "}", "\n\n", "return", "&", "ErrInvalidRevision", "{", "`\"@\" statement is not valid, could be : <refname>@{upstream}, @{upstream}, <refname>@{u}, @{u}`", "}", "\n", "case", "AtPush", ":", "if", "len", "(", "*", "chunks", ")", "==", "1", "||", "hasReference", "&&", "len", "(", "*", "chunks", ")", "==", "2", "{", "return", "nil", "\n", "}", "\n\n", "return", "&", "ErrInvalidRevision", "{", "`\"@\" statement is not valid, could be : <refname>@{push}, @{push}`", "}", "\n", "case", "TildePath", ",", "CaretPath", ",", "CaretReg", ":", "if", "!", "hasReference", "{", "return", "&", "ErrInvalidRevision", "{", "`\"~\" or \"^\" statement must have a reference defined at the beginning`", "}", "\n", "}", "\n", "case", "ColonReg", ":", "if", "len", "(", "*", "chunks", ")", "==", "1", "{", "return", "nil", "\n", "}", "\n\n", "return", "&", "ErrInvalidRevision", "{", "`\":\" statement is not valid, could be : :/<regexp>`", "}", "\n", "case", "ColonPath", ":", "if", "i", "==", "len", "(", "*", "chunks", ")", "-", "1", "&&", "hasReference", "||", "len", "(", "*", "chunks", ")", "==", "1", "{", "return", "nil", "\n", "}", "\n\n", "return", "&", "ErrInvalidRevision", "{", "`\":\" statement is not valid, could be : <revision>:<path>`", "}", "\n", "case", "ColonStagePath", ":", "if", "len", "(", "*", "chunks", ")", "==", "1", "{", "return", "nil", "\n", "}", "\n\n", "return", "&", "ErrInvalidRevision", "{", "`\":\" statement is not valid, could be : :<n>:<path>`", "}", "\n", "}", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// validateFullRevision ensures all revisioner chunks make a valid revision
[ "validateFullRevision", "ensures", "all", "revisioner", "chunks", "make", "a", "valid", "revision" ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/internal/revision/parser.go#L182-L249
train
src-d/go-git
internal/revision/parser.go
parseTilde
func (p *Parser) parseTilde() (Revisioner, error) { var tok token var lit string var err error tok, lit, err = p.scan() if err != nil { return nil, err } switch { case tok == number: n, _ := strconv.Atoi(lit) return TildePath{n}, nil default: p.unscan() return TildePath{1}, nil } }
go
func (p *Parser) parseTilde() (Revisioner, error) { var tok token var lit string var err error tok, lit, err = p.scan() if err != nil { return nil, err } switch { case tok == number: n, _ := strconv.Atoi(lit) return TildePath{n}, nil default: p.unscan() return TildePath{1}, nil } }
[ "func", "(", "p", "*", "Parser", ")", "parseTilde", "(", ")", "(", "Revisioner", ",", "error", ")", "{", "var", "tok", "token", "\n", "var", "lit", "string", "\n", "var", "err", "error", "\n\n", "tok", ",", "lit", ",", "err", "=", "p", ".", "scan", "(", ")", "\n\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "switch", "{", "case", "tok", "==", "number", ":", "n", ",", "_", ":=", "strconv", ".", "Atoi", "(", "lit", ")", "\n\n", "return", "TildePath", "{", "n", "}", ",", "nil", "\n", "default", ":", "p", ".", "unscan", "(", ")", "\n", "return", "TildePath", "{", "1", "}", ",", "nil", "\n", "}", "\n", "}" ]
// parseTilde extract ~ statements
[ "parseTilde", "extract", "~", "statements" ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/internal/revision/parser.go#L333-L353
train
src-d/go-git
internal/revision/parser.go
parseCaret
func (p *Parser) parseCaret() (Revisioner, error) { var tok token var lit string var err error tok, lit, err = p.scan() if err != nil { return nil, err } switch { case tok == obrace: r, err := p.parseCaretBraces() if err != nil { return nil, err } return r, nil case tok == number: n, _ := strconv.Atoi(lit) if n > 2 { return nil, &ErrInvalidRevision{fmt.Sprintf(`"%s" found must be 0, 1 or 2 after "^"`, lit)} } return CaretPath{n}, nil default: p.unscan() return CaretPath{1}, nil } }
go
func (p *Parser) parseCaret() (Revisioner, error) { var tok token var lit string var err error tok, lit, err = p.scan() if err != nil { return nil, err } switch { case tok == obrace: r, err := p.parseCaretBraces() if err != nil { return nil, err } return r, nil case tok == number: n, _ := strconv.Atoi(lit) if n > 2 { return nil, &ErrInvalidRevision{fmt.Sprintf(`"%s" found must be 0, 1 or 2 after "^"`, lit)} } return CaretPath{n}, nil default: p.unscan() return CaretPath{1}, nil } }
[ "func", "(", "p", "*", "Parser", ")", "parseCaret", "(", ")", "(", "Revisioner", ",", "error", ")", "{", "var", "tok", "token", "\n", "var", "lit", "string", "\n", "var", "err", "error", "\n\n", "tok", ",", "lit", ",", "err", "=", "p", ".", "scan", "(", ")", "\n\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "switch", "{", "case", "tok", "==", "obrace", ":", "r", ",", "err", ":=", "p", ".", "parseCaretBraces", "(", ")", "\n\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "r", ",", "nil", "\n", "case", "tok", "==", "number", ":", "n", ",", "_", ":=", "strconv", ".", "Atoi", "(", "lit", ")", "\n\n", "if", "n", ">", "2", "{", "return", "nil", ",", "&", "ErrInvalidRevision", "{", "fmt", ".", "Sprintf", "(", "`\"%s\" found must be 0, 1 or 2 after \"^\"`", ",", "lit", ")", "}", "\n", "}", "\n\n", "return", "CaretPath", "{", "n", "}", ",", "nil", "\n", "default", ":", "p", ".", "unscan", "(", ")", "\n", "return", "CaretPath", "{", "1", "}", ",", "nil", "\n", "}", "\n", "}" ]
// parseCaret extract ^ statements
[ "parseCaret", "extract", "^", "statements" ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/internal/revision/parser.go#L356-L388
train
src-d/go-git
internal/revision/parser.go
parseRef
func (p *Parser) parseRef() (Revisioner, error) { var tok, prevTok token var lit, buf string var endOfRef bool var err error for { tok, lit, err = p.scan() if err != nil { return nil, err } switch tok { case eof, at, colon, tilde, caret: endOfRef = true } err := p.checkRefFormat(tok, lit, prevTok, buf, endOfRef) if err != nil { return "", err } if endOfRef { p.unscan() return Ref(buf), nil } buf += lit prevTok = tok } }
go
func (p *Parser) parseRef() (Revisioner, error) { var tok, prevTok token var lit, buf string var endOfRef bool var err error for { tok, lit, err = p.scan() if err != nil { return nil, err } switch tok { case eof, at, colon, tilde, caret: endOfRef = true } err := p.checkRefFormat(tok, lit, prevTok, buf, endOfRef) if err != nil { return "", err } if endOfRef { p.unscan() return Ref(buf), nil } buf += lit prevTok = tok } }
[ "func", "(", "p", "*", "Parser", ")", "parseRef", "(", ")", "(", "Revisioner", ",", "error", ")", "{", "var", "tok", ",", "prevTok", "token", "\n", "var", "lit", ",", "buf", "string", "\n", "var", "endOfRef", "bool", "\n", "var", "err", "error", "\n\n", "for", "{", "tok", ",", "lit", ",", "err", "=", "p", ".", "scan", "(", ")", "\n\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "switch", "tok", "{", "case", "eof", ",", "at", ",", "colon", ",", "tilde", ",", "caret", ":", "endOfRef", "=", "true", "\n", "}", "\n\n", "err", ":=", "p", ".", "checkRefFormat", "(", "tok", ",", "lit", ",", "prevTok", ",", "buf", ",", "endOfRef", ")", "\n\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n\n", "if", "endOfRef", "{", "p", ".", "unscan", "(", ")", "\n", "return", "Ref", "(", "buf", ")", ",", "nil", "\n", "}", "\n\n", "buf", "+=", "lit", "\n", "prevTok", "=", "tok", "\n", "}", "\n", "}" ]
// parseRef extract reference name
[ "parseRef", "extract", "reference", "name" ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/internal/revision/parser.go#L562-L594
train
src-d/go-git
plumbing/format/config/option.go
IsKey
func (o *Option) IsKey(key string) bool { return strings.ToLower(o.Key) == strings.ToLower(key) }
go
func (o *Option) IsKey(key string) bool { return strings.ToLower(o.Key) == strings.ToLower(key) }
[ "func", "(", "o", "*", "Option", ")", "IsKey", "(", "key", "string", ")", "bool", "{", "return", "strings", ".", "ToLower", "(", "o", ".", "Key", ")", "==", "strings", ".", "ToLower", "(", "key", ")", "\n", "}" ]
// IsKey returns true if the given key matches // this option's key in a case-insensitive comparison.
[ "IsKey", "returns", "true", "if", "the", "given", "key", "matches", "this", "option", "s", "key", "in", "a", "case", "-", "insensitive", "comparison", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/format/config/option.go#L21-L23
train
src-d/go-git
plumbing/format/config/option.go
GetAll
func (opts Options) GetAll(key string) []string { result := []string{} for _, o := range opts { if o.IsKey(key) { result = append(result, o.Value) } } return result }
go
func (opts Options) GetAll(key string) []string { result := []string{} for _, o := range opts { if o.IsKey(key) { result = append(result, o.Value) } } return result }
[ "func", "(", "opts", "Options", ")", "GetAll", "(", "key", "string", ")", "[", "]", "string", "{", "result", ":=", "[", "]", "string", "{", "}", "\n", "for", "_", ",", "o", ":=", "range", "opts", "{", "if", "o", ".", "IsKey", "(", "key", ")", "{", "result", "=", "append", "(", "result", ",", "o", ".", "Value", ")", "\n", "}", "\n", "}", "\n", "return", "result", "\n", "}" ]
// GetAll returns all possible values for the same key.
[ "GetAll", "returns", "all", "possible", "values", "for", "the", "same", "key", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/format/config/option.go#L58-L66
train
src-d/go-git
plumbing/protocol/packp/capability/list.go
Decode
func (l *List) Decode(raw []byte) error { // git 1.x receive pack used to send a leading space on its // git-receive-pack capabilities announcement. We just trim space to be // tolerant to space changes in different versions. raw = bytes.TrimSpace(raw) if len(raw) == 0 { return nil } for _, data := range bytes.Split(raw, []byte{' '}) { pair := bytes.SplitN(data, []byte{'='}, 2) c := Capability(pair[0]) if len(pair) == 1 { if err := l.Add(c); err != nil { return err } continue } if err := l.Add(c, string(pair[1])); err != nil { return err } } return nil }
go
func (l *List) Decode(raw []byte) error { // git 1.x receive pack used to send a leading space on its // git-receive-pack capabilities announcement. We just trim space to be // tolerant to space changes in different versions. raw = bytes.TrimSpace(raw) if len(raw) == 0 { return nil } for _, data := range bytes.Split(raw, []byte{' '}) { pair := bytes.SplitN(data, []byte{'='}, 2) c := Capability(pair[0]) if len(pair) == 1 { if err := l.Add(c); err != nil { return err } continue } if err := l.Add(c, string(pair[1])); err != nil { return err } } return nil }
[ "func", "(", "l", "*", "List", ")", "Decode", "(", "raw", "[", "]", "byte", ")", "error", "{", "// git 1.x receive pack used to send a leading space on its", "// git-receive-pack capabilities announcement. We just trim space to be", "// tolerant to space changes in different versions.", "raw", "=", "bytes", ".", "TrimSpace", "(", "raw", ")", "\n\n", "if", "len", "(", "raw", ")", "==", "0", "{", "return", "nil", "\n", "}", "\n\n", "for", "_", ",", "data", ":=", "range", "bytes", ".", "Split", "(", "raw", ",", "[", "]", "byte", "{", "' '", "}", ")", "{", "pair", ":=", "bytes", ".", "SplitN", "(", "data", ",", "[", "]", "byte", "{", "'='", "}", ",", "2", ")", "\n\n", "c", ":=", "Capability", "(", "pair", "[", "0", "]", ")", "\n", "if", "len", "(", "pair", ")", "==", "1", "{", "if", "err", ":=", "l", ".", "Add", "(", "c", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "continue", "\n", "}", "\n\n", "if", "err", ":=", "l", ".", "Add", "(", "c", ",", "string", "(", "pair", "[", "1", "]", ")", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Decode decodes list of capabilities from raw into the list
[ "Decode", "decodes", "list", "of", "capabilities", "from", "raw", "into", "the", "list" ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/protocol/packp/capability/list.go#L48-L76
train
src-d/go-git
plumbing/protocol/packp/capability/list.go
Get
func (l *List) Get(capability Capability) []string { if _, ok := l.m[capability]; !ok { return nil } return l.m[capability].Values }
go
func (l *List) Get(capability Capability) []string { if _, ok := l.m[capability]; !ok { return nil } return l.m[capability].Values }
[ "func", "(", "l", "*", "List", ")", "Get", "(", "capability", "Capability", ")", "[", "]", "string", "{", "if", "_", ",", "ok", ":=", "l", ".", "m", "[", "capability", "]", ";", "!", "ok", "{", "return", "nil", "\n", "}", "\n\n", "return", "l", ".", "m", "[", "capability", "]", ".", "Values", "\n", "}" ]
// Get returns the values for a capability
[ "Get", "returns", "the", "values", "for", "a", "capability" ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/protocol/packp/capability/list.go#L79-L85
train
src-d/go-git
plumbing/protocol/packp/capability/list.go
Set
func (l *List) Set(capability Capability, values ...string) error { if _, ok := l.m[capability]; ok { delete(l.m, capability) } return l.Add(capability, values...) }
go
func (l *List) Set(capability Capability, values ...string) error { if _, ok := l.m[capability]; ok { delete(l.m, capability) } return l.Add(capability, values...) }
[ "func", "(", "l", "*", "List", ")", "Set", "(", "capability", "Capability", ",", "values", "...", "string", ")", "error", "{", "if", "_", ",", "ok", ":=", "l", ".", "m", "[", "capability", "]", ";", "ok", "{", "delete", "(", "l", ".", "m", ",", "capability", ")", "\n", "}", "\n\n", "return", "l", ".", "Add", "(", "capability", ",", "values", "...", ")", "\n", "}" ]
// Set sets a capability removing the previous values
[ "Set", "sets", "a", "capability", "removing", "the", "previous", "values" ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/protocol/packp/capability/list.go#L88-L94
train
src-d/go-git
plumbing/protocol/packp/capability/list.go
Add
func (l *List) Add(c Capability, values ...string) error { if err := l.validate(c, values); err != nil { return err } if !l.Supports(c) { l.m[c] = &entry{Name: c} l.sort = append(l.sort, c.String()) } if len(values) == 0 { return nil } if known[c] && !multipleArgument[c] && len(l.m[c].Values) > 0 { return ErrMultipleArguments } l.m[c].Values = append(l.m[c].Values, values...) return nil }
go
func (l *List) Add(c Capability, values ...string) error { if err := l.validate(c, values); err != nil { return err } if !l.Supports(c) { l.m[c] = &entry{Name: c} l.sort = append(l.sort, c.String()) } if len(values) == 0 { return nil } if known[c] && !multipleArgument[c] && len(l.m[c].Values) > 0 { return ErrMultipleArguments } l.m[c].Values = append(l.m[c].Values, values...) return nil }
[ "func", "(", "l", "*", "List", ")", "Add", "(", "c", "Capability", ",", "values", "...", "string", ")", "error", "{", "if", "err", ":=", "l", ".", "validate", "(", "c", ",", "values", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "if", "!", "l", ".", "Supports", "(", "c", ")", "{", "l", ".", "m", "[", "c", "]", "=", "&", "entry", "{", "Name", ":", "c", "}", "\n", "l", ".", "sort", "=", "append", "(", "l", ".", "sort", ",", "c", ".", "String", "(", ")", ")", "\n", "}", "\n\n", "if", "len", "(", "values", ")", "==", "0", "{", "return", "nil", "\n", "}", "\n\n", "if", "known", "[", "c", "]", "&&", "!", "multipleArgument", "[", "c", "]", "&&", "len", "(", "l", ".", "m", "[", "c", "]", ".", "Values", ")", ">", "0", "{", "return", "ErrMultipleArguments", "\n", "}", "\n\n", "l", ".", "m", "[", "c", "]", ".", "Values", "=", "append", "(", "l", ".", "m", "[", "c", "]", ".", "Values", ",", "values", "...", ")", "\n", "return", "nil", "\n", "}" ]
// Add adds a capability, values are optional
[ "Add", "adds", "a", "capability", "values", "are", "optional" ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/protocol/packp/capability/list.go#L97-L117
train
src-d/go-git
plumbing/protocol/packp/capability/list.go
Supports
func (l *List) Supports(capability Capability) bool { _, ok := l.m[capability] return ok }
go
func (l *List) Supports(capability Capability) bool { _, ok := l.m[capability] return ok }
[ "func", "(", "l", "*", "List", ")", "Supports", "(", "capability", "Capability", ")", "bool", "{", "_", ",", "ok", ":=", "l", ".", "m", "[", "capability", "]", "\n", "return", "ok", "\n", "}" ]
// Supports returns true if capability is present
[ "Supports", "returns", "true", "if", "capability", "is", "present" ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/protocol/packp/capability/list.go#L147-L150
train
src-d/go-git
plumbing/protocol/packp/capability/list.go
Delete
func (l *List) Delete(capability Capability) { if !l.Supports(capability) { return } delete(l.m, capability) for i, c := range l.sort { if c != string(capability) { continue } l.sort = append(l.sort[:i], l.sort[i+1:]...) return } }
go
func (l *List) Delete(capability Capability) { if !l.Supports(capability) { return } delete(l.m, capability) for i, c := range l.sort { if c != string(capability) { continue } l.sort = append(l.sort[:i], l.sort[i+1:]...) return } }
[ "func", "(", "l", "*", "List", ")", "Delete", "(", "capability", "Capability", ")", "{", "if", "!", "l", ".", "Supports", "(", "capability", ")", "{", "return", "\n", "}", "\n\n", "delete", "(", "l", ".", "m", ",", "capability", ")", "\n", "for", "i", ",", "c", ":=", "range", "l", ".", "sort", "{", "if", "c", "!=", "string", "(", "capability", ")", "{", "continue", "\n", "}", "\n\n", "l", ".", "sort", "=", "append", "(", "l", ".", "sort", "[", ":", "i", "]", ",", "l", ".", "sort", "[", "i", "+", "1", ":", "]", "...", ")", "\n", "return", "\n", "}", "\n", "}" ]
// Delete deletes a capability from the List
[ "Delete", "deletes", "a", "capability", "from", "the", "List" ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/protocol/packp/capability/list.go#L153-L167
train
src-d/go-git
plumbing/protocol/packp/capability/list.go
All
func (l *List) All() []Capability { var cs []Capability for _, key := range l.sort { cs = append(cs, Capability(key)) } return cs }
go
func (l *List) All() []Capability { var cs []Capability for _, key := range l.sort { cs = append(cs, Capability(key)) } return cs }
[ "func", "(", "l", "*", "List", ")", "All", "(", ")", "[", "]", "Capability", "{", "var", "cs", "[", "]", "Capability", "\n", "for", "_", ",", "key", ":=", "range", "l", ".", "sort", "{", "cs", "=", "append", "(", "cs", ",", "Capability", "(", "key", ")", ")", "\n", "}", "\n\n", "return", "cs", "\n", "}" ]
// All returns a slice with all defined capabilities.
[ "All", "returns", "a", "slice", "with", "all", "defined", "capabilities", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/protocol/packp/capability/list.go#L170-L177
train
src-d/go-git
plumbing/protocol/packp/capability/list.go
String
func (l *List) String() string { var o []string for _, key := range l.sort { cap := l.m[Capability(key)] if len(cap.Values) == 0 { o = append(o, key) continue } for _, value := range cap.Values { o = append(o, fmt.Sprintf("%s=%s", key, value)) } } return strings.Join(o, " ") }
go
func (l *List) String() string { var o []string for _, key := range l.sort { cap := l.m[Capability(key)] if len(cap.Values) == 0 { o = append(o, key) continue } for _, value := range cap.Values { o = append(o, fmt.Sprintf("%s=%s", key, value)) } } return strings.Join(o, " ") }
[ "func", "(", "l", "*", "List", ")", "String", "(", ")", "string", "{", "var", "o", "[", "]", "string", "\n", "for", "_", ",", "key", ":=", "range", "l", ".", "sort", "{", "cap", ":=", "l", ".", "m", "[", "Capability", "(", "key", ")", "]", "\n", "if", "len", "(", "cap", ".", "Values", ")", "==", "0", "{", "o", "=", "append", "(", "o", ",", "key", ")", "\n", "continue", "\n", "}", "\n\n", "for", "_", ",", "value", ":=", "range", "cap", ".", "Values", "{", "o", "=", "append", "(", "o", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "key", ",", "value", ")", ")", "\n", "}", "\n", "}", "\n\n", "return", "strings", ".", "Join", "(", "o", ",", "\"", "\"", ")", "\n", "}" ]
// String generates the capabilities strings, the capabilities are sorted in // insertion order
[ "String", "generates", "the", "capabilities", "strings", "the", "capabilities", "are", "sorted", "in", "insertion", "order" ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/protocol/packp/capability/list.go#L181-L196
train
src-d/go-git
remote.go
Push
func (r *Remote) Push(o *PushOptions) error { return r.PushContext(context.Background(), o) }
go
func (r *Remote) Push(o *PushOptions) error { return r.PushContext(context.Background(), o) }
[ "func", "(", "r", "*", "Remote", ")", "Push", "(", "o", "*", "PushOptions", ")", "error", "{", "return", "r", ".", "PushContext", "(", "context", ".", "Background", "(", ")", ",", "o", ")", "\n", "}" ]
// Push performs a push to the remote. Returns NoErrAlreadyUpToDate if the // remote was already up-to-date.
[ "Push", "performs", "a", "push", "to", "the", "remote", ".", "Returns", "NoErrAlreadyUpToDate", "if", "the", "remote", "was", "already", "up", "-", "to", "-", "date", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/remote.go#L69-L71
train
src-d/go-git
remote.go
PushContext
func (r *Remote) PushContext(ctx context.Context, o *PushOptions) (err error) { if err := o.Validate(); err != nil { return err } if o.RemoteName != r.c.Name { return fmt.Errorf("remote names don't match: %s != %s", o.RemoteName, r.c.Name) } s, err := newSendPackSession(r.c.URLs[0], o.Auth) if err != nil { return err } defer ioutil.CheckClose(s, &err) ar, err := s.AdvertisedReferences() if err != nil { return err } remoteRefs, err := ar.AllReferences() if err != nil { return err } isDelete := false allDelete := true for _, rs := range o.RefSpecs { if rs.IsDelete() { isDelete = true } else { allDelete = false } if isDelete && !allDelete { break } } if isDelete && !ar.Capabilities.Supports(capability.DeleteRefs) { return ErrDeleteRefNotSupported } localRefs, err := r.references() if err != nil { return err } req, err := r.newReferenceUpdateRequest(o, localRefs, remoteRefs, ar) if err != nil { return err } if len(req.Commands) == 0 { return NoErrAlreadyUpToDate } objects := objectsToPush(req.Commands) haves, err := referencesToHashes(remoteRefs) if err != nil { return err } stop, err := r.s.Shallow() if err != nil { return err } // if we have shallow we should include this as part of the objects that // we are aware. haves = append(haves, stop...) var hashesToPush []plumbing.Hash // Avoid the expensive revlist operation if we're only doing deletes. if !allDelete { if r.c.IsFirstURLLocal() { // If we're are pushing to a local repo, it might be much // faster to use a local storage layer to get the commits // to ignore, when calculating the object revlist. localStorer := filesystem.NewStorage( osfs.New(r.c.URLs[0]), cache.NewObjectLRUDefault()) hashesToPush, err = revlist.ObjectsWithStorageForIgnores( r.s, localStorer, objects, haves) } else { hashesToPush, err = revlist.Objects(r.s, objects, haves) } if err != nil { return err } } rs, err := pushHashes(ctx, s, r.s, req, hashesToPush, r.useRefDeltas(ar)) if err != nil { return err } if err = rs.Error(); err != nil { return err } return r.updateRemoteReferenceStorage(req, rs) }
go
func (r *Remote) PushContext(ctx context.Context, o *PushOptions) (err error) { if err := o.Validate(); err != nil { return err } if o.RemoteName != r.c.Name { return fmt.Errorf("remote names don't match: %s != %s", o.RemoteName, r.c.Name) } s, err := newSendPackSession(r.c.URLs[0], o.Auth) if err != nil { return err } defer ioutil.CheckClose(s, &err) ar, err := s.AdvertisedReferences() if err != nil { return err } remoteRefs, err := ar.AllReferences() if err != nil { return err } isDelete := false allDelete := true for _, rs := range o.RefSpecs { if rs.IsDelete() { isDelete = true } else { allDelete = false } if isDelete && !allDelete { break } } if isDelete && !ar.Capabilities.Supports(capability.DeleteRefs) { return ErrDeleteRefNotSupported } localRefs, err := r.references() if err != nil { return err } req, err := r.newReferenceUpdateRequest(o, localRefs, remoteRefs, ar) if err != nil { return err } if len(req.Commands) == 0 { return NoErrAlreadyUpToDate } objects := objectsToPush(req.Commands) haves, err := referencesToHashes(remoteRefs) if err != nil { return err } stop, err := r.s.Shallow() if err != nil { return err } // if we have shallow we should include this as part of the objects that // we are aware. haves = append(haves, stop...) var hashesToPush []plumbing.Hash // Avoid the expensive revlist operation if we're only doing deletes. if !allDelete { if r.c.IsFirstURLLocal() { // If we're are pushing to a local repo, it might be much // faster to use a local storage layer to get the commits // to ignore, when calculating the object revlist. localStorer := filesystem.NewStorage( osfs.New(r.c.URLs[0]), cache.NewObjectLRUDefault()) hashesToPush, err = revlist.ObjectsWithStorageForIgnores( r.s, localStorer, objects, haves) } else { hashesToPush, err = revlist.Objects(r.s, objects, haves) } if err != nil { return err } } rs, err := pushHashes(ctx, s, r.s, req, hashesToPush, r.useRefDeltas(ar)) if err != nil { return err } if err = rs.Error(); err != nil { return err } return r.updateRemoteReferenceStorage(req, rs) }
[ "func", "(", "r", "*", "Remote", ")", "PushContext", "(", "ctx", "context", ".", "Context", ",", "o", "*", "PushOptions", ")", "(", "err", "error", ")", "{", "if", "err", ":=", "o", ".", "Validate", "(", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "if", "o", ".", "RemoteName", "!=", "r", ".", "c", ".", "Name", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "o", ".", "RemoteName", ",", "r", ".", "c", ".", "Name", ")", "\n", "}", "\n\n", "s", ",", "err", ":=", "newSendPackSession", "(", "r", ".", "c", ".", "URLs", "[", "0", "]", ",", "o", ".", "Auth", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "defer", "ioutil", ".", "CheckClose", "(", "s", ",", "&", "err", ")", "\n\n", "ar", ",", "err", ":=", "s", ".", "AdvertisedReferences", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "remoteRefs", ",", "err", ":=", "ar", ".", "AllReferences", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "isDelete", ":=", "false", "\n", "allDelete", ":=", "true", "\n", "for", "_", ",", "rs", ":=", "range", "o", ".", "RefSpecs", "{", "if", "rs", ".", "IsDelete", "(", ")", "{", "isDelete", "=", "true", "\n", "}", "else", "{", "allDelete", "=", "false", "\n", "}", "\n", "if", "isDelete", "&&", "!", "allDelete", "{", "break", "\n", "}", "\n", "}", "\n\n", "if", "isDelete", "&&", "!", "ar", ".", "Capabilities", ".", "Supports", "(", "capability", ".", "DeleteRefs", ")", "{", "return", "ErrDeleteRefNotSupported", "\n", "}", "\n\n", "localRefs", ",", "err", ":=", "r", ".", "references", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "req", ",", "err", ":=", "r", ".", "newReferenceUpdateRequest", "(", "o", ",", "localRefs", ",", "remoteRefs", ",", "ar", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "if", "len", "(", "req", ".", "Commands", ")", "==", "0", "{", "return", "NoErrAlreadyUpToDate", "\n", "}", "\n\n", "objects", ":=", "objectsToPush", "(", "req", ".", "Commands", ")", "\n\n", "haves", ",", "err", ":=", "referencesToHashes", "(", "remoteRefs", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "stop", ",", "err", ":=", "r", ".", "s", ".", "Shallow", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "// if we have shallow we should include this as part of the objects that", "// we are aware.", "haves", "=", "append", "(", "haves", ",", "stop", "...", ")", "\n\n", "var", "hashesToPush", "[", "]", "plumbing", ".", "Hash", "\n", "// Avoid the expensive revlist operation if we're only doing deletes.", "if", "!", "allDelete", "{", "if", "r", ".", "c", ".", "IsFirstURLLocal", "(", ")", "{", "// If we're are pushing to a local repo, it might be much", "// faster to use a local storage layer to get the commits", "// to ignore, when calculating the object revlist.", "localStorer", ":=", "filesystem", ".", "NewStorage", "(", "osfs", ".", "New", "(", "r", ".", "c", ".", "URLs", "[", "0", "]", ")", ",", "cache", ".", "NewObjectLRUDefault", "(", ")", ")", "\n", "hashesToPush", ",", "err", "=", "revlist", ".", "ObjectsWithStorageForIgnores", "(", "r", ".", "s", ",", "localStorer", ",", "objects", ",", "haves", ")", "\n", "}", "else", "{", "hashesToPush", ",", "err", "=", "revlist", ".", "Objects", "(", "r", ".", "s", ",", "objects", ",", "haves", ")", "\n", "}", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n\n", "rs", ",", "err", ":=", "pushHashes", "(", "ctx", ",", "s", ",", "r", ".", "s", ",", "req", ",", "hashesToPush", ",", "r", ".", "useRefDeltas", "(", "ar", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "if", "err", "=", "rs", ".", "Error", "(", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "r", ".", "updateRemoteReferenceStorage", "(", "req", ",", "rs", ")", "\n", "}" ]
// PushContext performs a push to the remote. Returns NoErrAlreadyUpToDate if // the remote was already up-to-date. // // The provided Context must be non-nil. If the context expires before the // operation is complete, an error is returned. The context only affects to the // transport operations.
[ "PushContext", "performs", "a", "push", "to", "the", "remote", ".", "Returns", "NoErrAlreadyUpToDate", "if", "the", "remote", "was", "already", "up", "-", "to", "-", "date", ".", "The", "provided", "Context", "must", "be", "non", "-", "nil", ".", "If", "the", "context", "expires", "before", "the", "operation", "is", "complete", "an", "error", "is", "returned", ".", "The", "context", "only", "affects", "to", "the", "transport", "operations", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/remote.go#L79-L181
train
src-d/go-git
remote.go
FetchContext
func (r *Remote) FetchContext(ctx context.Context, o *FetchOptions) error { _, err := r.fetch(ctx, o) return err }
go
func (r *Remote) FetchContext(ctx context.Context, o *FetchOptions) error { _, err := r.fetch(ctx, o) return err }
[ "func", "(", "r", "*", "Remote", ")", "FetchContext", "(", "ctx", "context", ".", "Context", ",", "o", "*", "FetchOptions", ")", "error", "{", "_", ",", "err", ":=", "r", ".", "fetch", "(", "ctx", ",", "o", ")", "\n", "return", "err", "\n", "}" ]
// FetchContext fetches references along with the objects necessary to complete // their histories. // // Returns nil if the operation is successful, NoErrAlreadyUpToDate if there are // no changes to be fetched, or an error. // // The provided Context must be non-nil. If the context expires before the // operation is complete, an error is returned. The context only affects to the // transport operations.
[ "FetchContext", "fetches", "references", "along", "with", "the", "objects", "necessary", "to", "complete", "their", "histories", ".", "Returns", "nil", "if", "the", "operation", "is", "successful", "NoErrAlreadyUpToDate", "if", "there", "are", "no", "changes", "to", "be", "fetched", "or", "an", "error", ".", "The", "provided", "Context", "must", "be", "non", "-", "nil", ".", "If", "the", "context", "expires", "before", "the", "operation", "is", "complete", "an", "error", "is", "returned", ".", "The", "context", "only", "affects", "to", "the", "transport", "operations", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/remote.go#L249-L252
train
src-d/go-git
remote.go
getHavesFromRef
func getHavesFromRef( ref *plumbing.Reference, remoteRefs map[plumbing.Hash]bool, s storage.Storer, haves map[plumbing.Hash]bool, ) error { h := ref.Hash() if haves[h] { return nil } // No need to load the commit if we know the remote already // has this hash. if remoteRefs[h] { haves[h] = true return nil } commit, err := object.GetCommit(s, h) if err != nil { // Ignore the error if this isn't a commit. haves[ref.Hash()] = true return nil } // Until go-git supports proper commit negotiation during an // upload pack request, include up to `maxHavesToVisitPerRef` // commits from the history of each ref. walker := object.NewCommitPreorderIter(commit, haves, nil) toVisit := maxHavesToVisitPerRef return walker.ForEach(func(c *object.Commit) error { haves[c.Hash] = true toVisit-- // If toVisit starts out at 0 (indicating there is no // max), then it will be negative here and we won't stop // early. if toVisit == 0 || remoteRefs[c.Hash] { return storer.ErrStop } return nil }) }
go
func getHavesFromRef( ref *plumbing.Reference, remoteRefs map[plumbing.Hash]bool, s storage.Storer, haves map[plumbing.Hash]bool, ) error { h := ref.Hash() if haves[h] { return nil } // No need to load the commit if we know the remote already // has this hash. if remoteRefs[h] { haves[h] = true return nil } commit, err := object.GetCommit(s, h) if err != nil { // Ignore the error if this isn't a commit. haves[ref.Hash()] = true return nil } // Until go-git supports proper commit negotiation during an // upload pack request, include up to `maxHavesToVisitPerRef` // commits from the history of each ref. walker := object.NewCommitPreorderIter(commit, haves, nil) toVisit := maxHavesToVisitPerRef return walker.ForEach(func(c *object.Commit) error { haves[c.Hash] = true toVisit-- // If toVisit starts out at 0 (indicating there is no // max), then it will be negative here and we won't stop // early. if toVisit == 0 || remoteRefs[c.Hash] { return storer.ErrStop } return nil }) }
[ "func", "getHavesFromRef", "(", "ref", "*", "plumbing", ".", "Reference", ",", "remoteRefs", "map", "[", "plumbing", ".", "Hash", "]", "bool", ",", "s", "storage", ".", "Storer", ",", "haves", "map", "[", "plumbing", ".", "Hash", "]", "bool", ",", ")", "error", "{", "h", ":=", "ref", ".", "Hash", "(", ")", "\n", "if", "haves", "[", "h", "]", "{", "return", "nil", "\n", "}", "\n\n", "// No need to load the commit if we know the remote already", "// has this hash.", "if", "remoteRefs", "[", "h", "]", "{", "haves", "[", "h", "]", "=", "true", "\n", "return", "nil", "\n", "}", "\n\n", "commit", ",", "err", ":=", "object", ".", "GetCommit", "(", "s", ",", "h", ")", "\n", "if", "err", "!=", "nil", "{", "// Ignore the error if this isn't a commit.", "haves", "[", "ref", ".", "Hash", "(", ")", "]", "=", "true", "\n", "return", "nil", "\n", "}", "\n\n", "// Until go-git supports proper commit negotiation during an", "// upload pack request, include up to `maxHavesToVisitPerRef`", "// commits from the history of each ref.", "walker", ":=", "object", ".", "NewCommitPreorderIter", "(", "commit", ",", "haves", ",", "nil", ")", "\n", "toVisit", ":=", "maxHavesToVisitPerRef", "\n", "return", "walker", ".", "ForEach", "(", "func", "(", "c", "*", "object", ".", "Commit", ")", "error", "{", "haves", "[", "c", ".", "Hash", "]", "=", "true", "\n", "toVisit", "--", "\n", "// If toVisit starts out at 0 (indicating there is no", "// max), then it will be negative here and we won't stop", "// early.", "if", "toVisit", "==", "0", "||", "remoteRefs", "[", "c", ".", "Hash", "]", "{", "return", "storer", ".", "ErrStop", "\n", "}", "\n", "return", "nil", "\n", "}", ")", "\n", "}" ]
// getHavesFromRef populates the given `haves` map with the given // reference, and up to `maxHavesToVisitPerRef` ancestor commits.
[ "getHavesFromRef", "populates", "the", "given", "haves", "map", "with", "the", "given", "reference", "and", "up", "to", "maxHavesToVisitPerRef", "ancestor", "commits", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/remote.go#L558-L599
train
src-d/go-git
remote.go
List
func (r *Remote) List(o *ListOptions) (rfs []*plumbing.Reference, err error) { s, err := newUploadPackSession(r.c.URLs[0], o.Auth) if err != nil { return nil, err } defer ioutil.CheckClose(s, &err) ar, err := s.AdvertisedReferences() if err != nil { return nil, err } allRefs, err := ar.AllReferences() if err != nil { return nil, err } refs, err := allRefs.IterReferences() if err != nil { return nil, err } var resultRefs []*plumbing.Reference refs.ForEach(func(ref *plumbing.Reference) error { resultRefs = append(resultRefs, ref) return nil }) return resultRefs, nil }
go
func (r *Remote) List(o *ListOptions) (rfs []*plumbing.Reference, err error) { s, err := newUploadPackSession(r.c.URLs[0], o.Auth) if err != nil { return nil, err } defer ioutil.CheckClose(s, &err) ar, err := s.AdvertisedReferences() if err != nil { return nil, err } allRefs, err := ar.AllReferences() if err != nil { return nil, err } refs, err := allRefs.IterReferences() if err != nil { return nil, err } var resultRefs []*plumbing.Reference refs.ForEach(func(ref *plumbing.Reference) error { resultRefs = append(resultRefs, ref) return nil }) return resultRefs, nil }
[ "func", "(", "r", "*", "Remote", ")", "List", "(", "o", "*", "ListOptions", ")", "(", "rfs", "[", "]", "*", "plumbing", ".", "Reference", ",", "err", "error", ")", "{", "s", ",", "err", ":=", "newUploadPackSession", "(", "r", ".", "c", ".", "URLs", "[", "0", "]", ",", "o", ".", "Auth", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "defer", "ioutil", ".", "CheckClose", "(", "s", ",", "&", "err", ")", "\n\n", "ar", ",", "err", ":=", "s", ".", "AdvertisedReferences", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "allRefs", ",", "err", ":=", "ar", ".", "AllReferences", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "refs", ",", "err", ":=", "allRefs", ".", "IterReferences", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "var", "resultRefs", "[", "]", "*", "plumbing", ".", "Reference", "\n", "refs", ".", "ForEach", "(", "func", "(", "ref", "*", "plumbing", ".", "Reference", ")", "error", "{", "resultRefs", "=", "append", "(", "resultRefs", ",", "ref", ")", "\n", "return", "nil", "\n", "}", ")", "\n\n", "return", "resultRefs", ",", "nil", "\n", "}" ]
// List the references on the remote repository.
[ "List", "the", "references", "on", "the", "remote", "repository", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/remote.go#L942-L972
train
src-d/go-git
plumbing/protocol/packp/advrefs_decode.go
Decode
func (a *AdvRefs) Decode(r io.Reader) error { d := newAdvRefsDecoder(r) return d.Decode(a) }
go
func (a *AdvRefs) Decode(r io.Reader) error { d := newAdvRefsDecoder(r) return d.Decode(a) }
[ "func", "(", "a", "*", "AdvRefs", ")", "Decode", "(", "r", "io", ".", "Reader", ")", "error", "{", "d", ":=", "newAdvRefsDecoder", "(", "r", ")", "\n", "return", "d", ".", "Decode", "(", "a", ")", "\n", "}" ]
// Decode reads the next advertised-refs message form its input and // stores it in the AdvRefs.
[ "Decode", "reads", "the", "next", "advertised", "-", "refs", "message", "form", "its", "input", "and", "stores", "it", "in", "the", "AdvRefs", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/protocol/packp/advrefs_decode.go#L16-L19
train
src-d/go-git
plumbing/protocol/packp/advrefs_decode.go
decodePrefix
func decodePrefix(d *advRefsDecoder) decoderStateFn { if ok := d.nextLine(); !ok { return nil } if !isPrefix(d.line) { return decodeFirstHash } tmp := make([]byte, len(d.line)) copy(tmp, d.line) d.data.Prefix = append(d.data.Prefix, tmp) if ok := d.nextLine(); !ok { return nil } if !isFlush(d.line) { return decodeFirstHash } d.data.Prefix = append(d.data.Prefix, pktline.Flush) if ok := d.nextLine(); !ok { return nil } return decodeFirstHash }
go
func decodePrefix(d *advRefsDecoder) decoderStateFn { if ok := d.nextLine(); !ok { return nil } if !isPrefix(d.line) { return decodeFirstHash } tmp := make([]byte, len(d.line)) copy(tmp, d.line) d.data.Prefix = append(d.data.Prefix, tmp) if ok := d.nextLine(); !ok { return nil } if !isFlush(d.line) { return decodeFirstHash } d.data.Prefix = append(d.data.Prefix, pktline.Flush) if ok := d.nextLine(); !ok { return nil } return decodeFirstHash }
[ "func", "decodePrefix", "(", "d", "*", "advRefsDecoder", ")", "decoderStateFn", "{", "if", "ok", ":=", "d", ".", "nextLine", "(", ")", ";", "!", "ok", "{", "return", "nil", "\n", "}", "\n\n", "if", "!", "isPrefix", "(", "d", ".", "line", ")", "{", "return", "decodeFirstHash", "\n", "}", "\n\n", "tmp", ":=", "make", "(", "[", "]", "byte", ",", "len", "(", "d", ".", "line", ")", ")", "\n", "copy", "(", "tmp", ",", "d", ".", "line", ")", "\n", "d", ".", "data", ".", "Prefix", "=", "append", "(", "d", ".", "data", ".", "Prefix", ",", "tmp", ")", "\n", "if", "ok", ":=", "d", ".", "nextLine", "(", ")", ";", "!", "ok", "{", "return", "nil", "\n", "}", "\n\n", "if", "!", "isFlush", "(", "d", ".", "line", ")", "{", "return", "decodeFirstHash", "\n", "}", "\n\n", "d", ".", "data", ".", "Prefix", "=", "append", "(", "d", ".", "data", ".", "Prefix", ",", "pktline", ".", "Flush", ")", "\n", "if", "ok", ":=", "d", ".", "nextLine", "(", ")", ";", "!", "ok", "{", "return", "nil", "\n", "}", "\n\n", "return", "decodeFirstHash", "\n", "}" ]
// The HTTP smart prefix is often followed by a flush-pkt.
[ "The", "HTTP", "smart", "prefix", "is", "often", "followed", "by", "a", "flush", "-", "pkt", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/protocol/packp/advrefs_decode.go#L94-L120
train
src-d/go-git
plumbing/protocol/packp/advrefs_decode.go
decodeFirstHash
func decodeFirstHash(p *advRefsDecoder) decoderStateFn { // If the repository is empty, we receive a flush here (HTTP). if isFlush(p.line) { p.err = ErrEmptyAdvRefs return nil } if len(p.line) < hashSize { p.error("cannot read hash, pkt-line too short") return nil } if _, err := hex.Decode(p.hash[:], p.line[:hashSize]); err != nil { p.error("invalid hash text: %s", err) return nil } p.line = p.line[hashSize:] if p.hash.IsZero() { return decodeSkipNoRefs } return decodeFirstRef }
go
func decodeFirstHash(p *advRefsDecoder) decoderStateFn { // If the repository is empty, we receive a flush here (HTTP). if isFlush(p.line) { p.err = ErrEmptyAdvRefs return nil } if len(p.line) < hashSize { p.error("cannot read hash, pkt-line too short") return nil } if _, err := hex.Decode(p.hash[:], p.line[:hashSize]); err != nil { p.error("invalid hash text: %s", err) return nil } p.line = p.line[hashSize:] if p.hash.IsZero() { return decodeSkipNoRefs } return decodeFirstRef }
[ "func", "decodeFirstHash", "(", "p", "*", "advRefsDecoder", ")", "decoderStateFn", "{", "// If the repository is empty, we receive a flush here (HTTP).", "if", "isFlush", "(", "p", ".", "line", ")", "{", "p", ".", "err", "=", "ErrEmptyAdvRefs", "\n", "return", "nil", "\n", "}", "\n\n", "if", "len", "(", "p", ".", "line", ")", "<", "hashSize", "{", "p", ".", "error", "(", "\"", "\"", ")", "\n", "return", "nil", "\n", "}", "\n\n", "if", "_", ",", "err", ":=", "hex", ".", "Decode", "(", "p", ".", "hash", "[", ":", "]", ",", "p", ".", "line", "[", ":", "hashSize", "]", ")", ";", "err", "!=", "nil", "{", "p", ".", "error", "(", "\"", "\"", ",", "err", ")", "\n", "return", "nil", "\n", "}", "\n\n", "p", ".", "line", "=", "p", ".", "line", "[", "hashSize", ":", "]", "\n\n", "if", "p", ".", "hash", ".", "IsZero", "(", ")", "{", "return", "decodeSkipNoRefs", "\n", "}", "\n\n", "return", "decodeFirstRef", "\n", "}" ]
// If the first hash is zero, then a no-refs is coming. Otherwise, a // list-of-refs is coming, and the hash will be followed by the first // advertised ref.
[ "If", "the", "first", "hash", "is", "zero", "then", "a", "no", "-", "refs", "is", "coming", ".", "Otherwise", "a", "list", "-", "of", "-", "refs", "is", "coming", "and", "the", "hash", "will", "be", "followed", "by", "the", "first", "advertised", "ref", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/protocol/packp/advrefs_decode.go#L129-L153
train
src-d/go-git
plumbing/protocol/packp/advrefs_decode.go
decodeFirstRef
func decodeFirstRef(l *advRefsDecoder) decoderStateFn { if len(l.line) < 3 { l.error("line too short after hash") return nil } if !bytes.HasPrefix(l.line, sp) { l.error("no space after hash") return nil } l.line = l.line[1:] chunks := bytes.SplitN(l.line, null, 2) if len(chunks) < 2 { l.error("NULL not found") return nil } ref := chunks[0] l.line = chunks[1] if bytes.Equal(ref, []byte(head)) { l.data.Head = &l.hash } else { l.data.References[string(ref)] = l.hash } return decodeCaps }
go
func decodeFirstRef(l *advRefsDecoder) decoderStateFn { if len(l.line) < 3 { l.error("line too short after hash") return nil } if !bytes.HasPrefix(l.line, sp) { l.error("no space after hash") return nil } l.line = l.line[1:] chunks := bytes.SplitN(l.line, null, 2) if len(chunks) < 2 { l.error("NULL not found") return nil } ref := chunks[0] l.line = chunks[1] if bytes.Equal(ref, []byte(head)) { l.data.Head = &l.hash } else { l.data.References[string(ref)] = l.hash } return decodeCaps }
[ "func", "decodeFirstRef", "(", "l", "*", "advRefsDecoder", ")", "decoderStateFn", "{", "if", "len", "(", "l", ".", "line", ")", "<", "3", "{", "l", ".", "error", "(", "\"", "\"", ")", "\n", "return", "nil", "\n", "}", "\n\n", "if", "!", "bytes", ".", "HasPrefix", "(", "l", ".", "line", ",", "sp", ")", "{", "l", ".", "error", "(", "\"", "\"", ")", "\n", "return", "nil", "\n", "}", "\n", "l", ".", "line", "=", "l", ".", "line", "[", "1", ":", "]", "\n\n", "chunks", ":=", "bytes", ".", "SplitN", "(", "l", ".", "line", ",", "null", ",", "2", ")", "\n", "if", "len", "(", "chunks", ")", "<", "2", "{", "l", ".", "error", "(", "\"", "\"", ")", "\n", "return", "nil", "\n", "}", "\n", "ref", ":=", "chunks", "[", "0", "]", "\n", "l", ".", "line", "=", "chunks", "[", "1", "]", "\n\n", "if", "bytes", ".", "Equal", "(", "ref", ",", "[", "]", "byte", "(", "head", ")", ")", "{", "l", ".", "data", ".", "Head", "=", "&", "l", ".", "hash", "\n", "}", "else", "{", "l", ".", "data", ".", "References", "[", "string", "(", "ref", ")", "]", "=", "l", ".", "hash", "\n", "}", "\n\n", "return", "decodeCaps", "\n", "}" ]
// decode the refname, expects SP refname NULL
[ "decode", "the", "refname", "expects", "SP", "refname", "NULL" ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/protocol/packp/advrefs_decode.go#L173-L200
train
src-d/go-git
plumbing/protocol/packp/advrefs_decode.go
readRef
func readRef(data []byte) (string, plumbing.Hash, error) { chunks := bytes.Split(data, sp) switch { case len(chunks) == 1: return "", plumbing.ZeroHash, fmt.Errorf("malformed ref data: no space was found") case len(chunks) > 2: return "", plumbing.ZeroHash, fmt.Errorf("malformed ref data: more than one space found") default: return string(chunks[1]), plumbing.NewHash(string(chunks[0])), nil } }
go
func readRef(data []byte) (string, plumbing.Hash, error) { chunks := bytes.Split(data, sp) switch { case len(chunks) == 1: return "", plumbing.ZeroHash, fmt.Errorf("malformed ref data: no space was found") case len(chunks) > 2: return "", plumbing.ZeroHash, fmt.Errorf("malformed ref data: more than one space found") default: return string(chunks[1]), plumbing.NewHash(string(chunks[0])), nil } }
[ "func", "readRef", "(", "data", "[", "]", "byte", ")", "(", "string", ",", "plumbing", ".", "Hash", ",", "error", ")", "{", "chunks", ":=", "bytes", ".", "Split", "(", "data", ",", "sp", ")", "\n", "switch", "{", "case", "len", "(", "chunks", ")", "==", "1", ":", "return", "\"", "\"", ",", "plumbing", ".", "ZeroHash", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "case", "len", "(", "chunks", ")", ">", "2", ":", "return", "\"", "\"", ",", "plumbing", ".", "ZeroHash", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "default", ":", "return", "string", "(", "chunks", "[", "1", "]", ")", ",", "plumbing", ".", "NewHash", "(", "string", "(", "chunks", "[", "0", "]", ")", ")", ",", "nil", "\n", "}", "\n", "}" ]
// Reads a ref-name
[ "Reads", "a", "ref", "-", "name" ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/protocol/packp/advrefs_decode.go#L243-L253
train
src-d/go-git
plumbing/protocol/packp/advrefs_decode.go
decodeShallow
func decodeShallow(p *advRefsDecoder) decoderStateFn { if !bytes.HasPrefix(p.line, shallow) { p.error("malformed shallow prefix, found %q... instead", p.line[:len(shallow)]) return nil } p.line = bytes.TrimPrefix(p.line, shallow) if len(p.line) != hashSize { p.error(fmt.Sprintf( "malformed shallow hash: wrong length, expected 40 bytes, read %d bytes", len(p.line))) return nil } text := p.line[:hashSize] var h plumbing.Hash if _, err := hex.Decode(h[:], text); err != nil { p.error("invalid hash text: %s", err) return nil } p.data.Shallows = append(p.data.Shallows, h) if ok := p.nextLine(); !ok { return nil } if len(p.line) == 0 { return nil // succesfull parse of the advertised-refs message } return decodeShallow }
go
func decodeShallow(p *advRefsDecoder) decoderStateFn { if !bytes.HasPrefix(p.line, shallow) { p.error("malformed shallow prefix, found %q... instead", p.line[:len(shallow)]) return nil } p.line = bytes.TrimPrefix(p.line, shallow) if len(p.line) != hashSize { p.error(fmt.Sprintf( "malformed shallow hash: wrong length, expected 40 bytes, read %d bytes", len(p.line))) return nil } text := p.line[:hashSize] var h plumbing.Hash if _, err := hex.Decode(h[:], text); err != nil { p.error("invalid hash text: %s", err) return nil } p.data.Shallows = append(p.data.Shallows, h) if ok := p.nextLine(); !ok { return nil } if len(p.line) == 0 { return nil // succesfull parse of the advertised-refs message } return decodeShallow }
[ "func", "decodeShallow", "(", "p", "*", "advRefsDecoder", ")", "decoderStateFn", "{", "if", "!", "bytes", ".", "HasPrefix", "(", "p", ".", "line", ",", "shallow", ")", "{", "p", ".", "error", "(", "\"", "\"", ",", "p", ".", "line", "[", ":", "len", "(", "shallow", ")", "]", ")", "\n", "return", "nil", "\n", "}", "\n", "p", ".", "line", "=", "bytes", ".", "TrimPrefix", "(", "p", ".", "line", ",", "shallow", ")", "\n\n", "if", "len", "(", "p", ".", "line", ")", "!=", "hashSize", "{", "p", ".", "error", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "len", "(", "p", ".", "line", ")", ")", ")", "\n", "return", "nil", "\n", "}", "\n\n", "text", ":=", "p", ".", "line", "[", ":", "hashSize", "]", "\n", "var", "h", "plumbing", ".", "Hash", "\n", "if", "_", ",", "err", ":=", "hex", ".", "Decode", "(", "h", "[", ":", "]", ",", "text", ")", ";", "err", "!=", "nil", "{", "p", ".", "error", "(", "\"", "\"", ",", "err", ")", "\n", "return", "nil", "\n", "}", "\n\n", "p", ".", "data", ".", "Shallows", "=", "append", "(", "p", ".", "data", ".", "Shallows", ",", "h", ")", "\n\n", "if", "ok", ":=", "p", ".", "nextLine", "(", ")", ";", "!", "ok", "{", "return", "nil", "\n", "}", "\n\n", "if", "len", "(", "p", ".", "line", ")", "==", "0", "{", "return", "nil", "// succesfull parse of the advertised-refs message", "\n", "}", "\n\n", "return", "decodeShallow", "\n", "}" ]
// Keeps reading shallows until a flush-pkt is found
[ "Keeps", "reading", "shallows", "until", "a", "flush", "-", "pkt", "is", "found" ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/protocol/packp/advrefs_decode.go#L256-L288
train
src-d/go-git
plumbing/format/commitgraph/encoder.go
NewEncoder
func NewEncoder(w io.Writer) *Encoder { h := sha1.New() mw := io.MultiWriter(w, h) return &Encoder{mw, h} }
go
func NewEncoder(w io.Writer) *Encoder { h := sha1.New() mw := io.MultiWriter(w, h) return &Encoder{mw, h} }
[ "func", "NewEncoder", "(", "w", "io", ".", "Writer", ")", "*", "Encoder", "{", "h", ":=", "sha1", ".", "New", "(", ")", "\n", "mw", ":=", "io", ".", "MultiWriter", "(", "w", ",", "h", ")", "\n", "return", "&", "Encoder", "{", "mw", ",", "h", "}", "\n", "}" ]
// NewEncoder returns a new stream encoder that writes to w.
[ "NewEncoder", "returns", "a", "new", "stream", "encoder", "that", "writes", "to", "w", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/format/commitgraph/encoder.go#L19-L23
train
src-d/go-git
storage/transactional/object.go
NewObjectStorage
func NewObjectStorage(base, temporal storer.EncodedObjectStorer) *ObjectStorage { return &ObjectStorage{EncodedObjectStorer: base, temporal: temporal} }
go
func NewObjectStorage(base, temporal storer.EncodedObjectStorer) *ObjectStorage { return &ObjectStorage{EncodedObjectStorer: base, temporal: temporal} }
[ "func", "NewObjectStorage", "(", "base", ",", "temporal", "storer", ".", "EncodedObjectStorer", ")", "*", "ObjectStorage", "{", "return", "&", "ObjectStorage", "{", "EncodedObjectStorer", ":", "base", ",", "temporal", ":", "temporal", "}", "\n", "}" ]
// NewObjectStorage returns a new EncodedObjectStorer based on a base storer and // a temporal storer.
[ "NewObjectStorage", "returns", "a", "new", "EncodedObjectStorer", "based", "on", "a", "base", "storer", "and", "a", "temporal", "storer", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/storage/transactional/object.go#L16-L18
train
src-d/go-git
storage/transactional/object.go
SetEncodedObject
func (o *ObjectStorage) SetEncodedObject(obj plumbing.EncodedObject) (plumbing.Hash, error) { return o.temporal.SetEncodedObject(obj) }
go
func (o *ObjectStorage) SetEncodedObject(obj plumbing.EncodedObject) (plumbing.Hash, error) { return o.temporal.SetEncodedObject(obj) }
[ "func", "(", "o", "*", "ObjectStorage", ")", "SetEncodedObject", "(", "obj", "plumbing", ".", "EncodedObject", ")", "(", "plumbing", ".", "Hash", ",", "error", ")", "{", "return", "o", ".", "temporal", ".", "SetEncodedObject", "(", "obj", ")", "\n", "}" ]
// SetEncodedObject honors the storer.EncodedObjectStorer interface.
[ "SetEncodedObject", "honors", "the", "storer", ".", "EncodedObjectStorer", "interface", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/storage/transactional/object.go#L21-L23
train
src-d/go-git
storage/transactional/object.go
HasEncodedObject
func (o *ObjectStorage) HasEncodedObject(h plumbing.Hash) error { err := o.EncodedObjectStorer.HasEncodedObject(h) if err == plumbing.ErrObjectNotFound { return o.temporal.HasEncodedObject(h) } return err }
go
func (o *ObjectStorage) HasEncodedObject(h plumbing.Hash) error { err := o.EncodedObjectStorer.HasEncodedObject(h) if err == plumbing.ErrObjectNotFound { return o.temporal.HasEncodedObject(h) } return err }
[ "func", "(", "o", "*", "ObjectStorage", ")", "HasEncodedObject", "(", "h", "plumbing", ".", "Hash", ")", "error", "{", "err", ":=", "o", ".", "EncodedObjectStorer", ".", "HasEncodedObject", "(", "h", ")", "\n", "if", "err", "==", "plumbing", ".", "ErrObjectNotFound", "{", "return", "o", ".", "temporal", ".", "HasEncodedObject", "(", "h", ")", "\n", "}", "\n\n", "return", "err", "\n", "}" ]
// HasEncodedObject honors the storer.EncodedObjectStorer interface.
[ "HasEncodedObject", "honors", "the", "storer", ".", "EncodedObjectStorer", "interface", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/storage/transactional/object.go#L26-L33
train
src-d/go-git
storage/transactional/object.go
EncodedObjectSize
func (o *ObjectStorage) EncodedObjectSize(h plumbing.Hash) (int64, error) { sz, err := o.EncodedObjectStorer.EncodedObjectSize(h) if err == plumbing.ErrObjectNotFound { return o.temporal.EncodedObjectSize(h) } return sz, err }
go
func (o *ObjectStorage) EncodedObjectSize(h plumbing.Hash) (int64, error) { sz, err := o.EncodedObjectStorer.EncodedObjectSize(h) if err == plumbing.ErrObjectNotFound { return o.temporal.EncodedObjectSize(h) } return sz, err }
[ "func", "(", "o", "*", "ObjectStorage", ")", "EncodedObjectSize", "(", "h", "plumbing", ".", "Hash", ")", "(", "int64", ",", "error", ")", "{", "sz", ",", "err", ":=", "o", ".", "EncodedObjectStorer", ".", "EncodedObjectSize", "(", "h", ")", "\n", "if", "err", "==", "plumbing", ".", "ErrObjectNotFound", "{", "return", "o", ".", "temporal", ".", "EncodedObjectSize", "(", "h", ")", "\n", "}", "\n\n", "return", "sz", ",", "err", "\n", "}" ]
// EncodedObjectSize honors the storer.EncodedObjectStorer interface.
[ "EncodedObjectSize", "honors", "the", "storer", ".", "EncodedObjectStorer", "interface", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/storage/transactional/object.go#L36-L43
train
src-d/go-git
storage/transactional/object.go
EncodedObject
func (o *ObjectStorage) EncodedObject(t plumbing.ObjectType, h plumbing.Hash) (plumbing.EncodedObject, error) { obj, err := o.EncodedObjectStorer.EncodedObject(t, h) if err == plumbing.ErrObjectNotFound { return o.temporal.EncodedObject(t, h) } return obj, err }
go
func (o *ObjectStorage) EncodedObject(t plumbing.ObjectType, h plumbing.Hash) (plumbing.EncodedObject, error) { obj, err := o.EncodedObjectStorer.EncodedObject(t, h) if err == plumbing.ErrObjectNotFound { return o.temporal.EncodedObject(t, h) } return obj, err }
[ "func", "(", "o", "*", "ObjectStorage", ")", "EncodedObject", "(", "t", "plumbing", ".", "ObjectType", ",", "h", "plumbing", ".", "Hash", ")", "(", "plumbing", ".", "EncodedObject", ",", "error", ")", "{", "obj", ",", "err", ":=", "o", ".", "EncodedObjectStorer", ".", "EncodedObject", "(", "t", ",", "h", ")", "\n", "if", "err", "==", "plumbing", ".", "ErrObjectNotFound", "{", "return", "o", ".", "temporal", ".", "EncodedObject", "(", "t", ",", "h", ")", "\n", "}", "\n\n", "return", "obj", ",", "err", "\n", "}" ]
// EncodedObject honors the storer.EncodedObjectStorer interface.
[ "EncodedObject", "honors", "the", "storer", ".", "EncodedObjectStorer", "interface", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/storage/transactional/object.go#L46-L53
train
src-d/go-git
storage/transactional/object.go
IterEncodedObjects
func (o *ObjectStorage) IterEncodedObjects(t plumbing.ObjectType) (storer.EncodedObjectIter, error) { baseIter, err := o.EncodedObjectStorer.IterEncodedObjects(t) if err != nil { return nil, err } temporalIter, err := o.temporal.IterEncodedObjects(t) if err != nil { return nil, err } return storer.NewMultiEncodedObjectIter([]storer.EncodedObjectIter{ baseIter, temporalIter, }), nil }
go
func (o *ObjectStorage) IterEncodedObjects(t plumbing.ObjectType) (storer.EncodedObjectIter, error) { baseIter, err := o.EncodedObjectStorer.IterEncodedObjects(t) if err != nil { return nil, err } temporalIter, err := o.temporal.IterEncodedObjects(t) if err != nil { return nil, err } return storer.NewMultiEncodedObjectIter([]storer.EncodedObjectIter{ baseIter, temporalIter, }), nil }
[ "func", "(", "o", "*", "ObjectStorage", ")", "IterEncodedObjects", "(", "t", "plumbing", ".", "ObjectType", ")", "(", "storer", ".", "EncodedObjectIter", ",", "error", ")", "{", "baseIter", ",", "err", ":=", "o", ".", "EncodedObjectStorer", ".", "IterEncodedObjects", "(", "t", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "temporalIter", ",", "err", ":=", "o", ".", "temporal", ".", "IterEncodedObjects", "(", "t", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "storer", ".", "NewMultiEncodedObjectIter", "(", "[", "]", "storer", ".", "EncodedObjectIter", "{", "baseIter", ",", "temporalIter", ",", "}", ")", ",", "nil", "\n", "}" ]
// IterEncodedObjects honors the storer.EncodedObjectStorer interface.
[ "IterEncodedObjects", "honors", "the", "storer", ".", "EncodedObjectStorer", "interface", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/storage/transactional/object.go#L56-L71
train
src-d/go-git
storage/transactional/object.go
Commit
func (o *ObjectStorage) Commit() error { iter, err := o.temporal.IterEncodedObjects(plumbing.AnyObject) if err != nil { return err } return iter.ForEach(func(obj plumbing.EncodedObject) error { _, err := o.EncodedObjectStorer.SetEncodedObject(obj) return err }) }
go
func (o *ObjectStorage) Commit() error { iter, err := o.temporal.IterEncodedObjects(plumbing.AnyObject) if err != nil { return err } return iter.ForEach(func(obj plumbing.EncodedObject) error { _, err := o.EncodedObjectStorer.SetEncodedObject(obj) return err }) }
[ "func", "(", "o", "*", "ObjectStorage", ")", "Commit", "(", ")", "error", "{", "iter", ",", "err", ":=", "o", ".", "temporal", ".", "IterEncodedObjects", "(", "plumbing", ".", "AnyObject", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "iter", ".", "ForEach", "(", "func", "(", "obj", "plumbing", ".", "EncodedObject", ")", "error", "{", "_", ",", "err", ":=", "o", ".", "EncodedObjectStorer", ".", "SetEncodedObject", "(", "obj", ")", "\n", "return", "err", "\n", "}", ")", "\n", "}" ]
// Commit it copies the objects of the temporal storage into the base storage.
[ "Commit", "it", "copies", "the", "objects", "of", "the", "temporal", "storage", "into", "the", "base", "storage", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/storage/transactional/object.go#L74-L84
train
src-d/go-git
plumbing/protocol/packp/srvresp.go
Decode
func (r *ServerResponse) Decode(reader *bufio.Reader, isMultiACK bool) error { // TODO: implement support for multi_ack or multi_ack_detailed responses if isMultiACK { return errors.New("multi_ack and multi_ack_detailed are not supported") } s := pktline.NewScanner(reader) for s.Scan() { line := s.Bytes() if err := r.decodeLine(line); err != nil { return err } // we need to detect when the end of a response header and the beginning // of a packfile header happened, some requests to the git daemon // produces a duplicate ACK header even when multi_ack is not supported. stop, err := r.stopReading(reader) if err != nil { return err } if stop { break } } return s.Err() }
go
func (r *ServerResponse) Decode(reader *bufio.Reader, isMultiACK bool) error { // TODO: implement support for multi_ack or multi_ack_detailed responses if isMultiACK { return errors.New("multi_ack and multi_ack_detailed are not supported") } s := pktline.NewScanner(reader) for s.Scan() { line := s.Bytes() if err := r.decodeLine(line); err != nil { return err } // we need to detect when the end of a response header and the beginning // of a packfile header happened, some requests to the git daemon // produces a duplicate ACK header even when multi_ack is not supported. stop, err := r.stopReading(reader) if err != nil { return err } if stop { break } } return s.Err() }
[ "func", "(", "r", "*", "ServerResponse", ")", "Decode", "(", "reader", "*", "bufio", ".", "Reader", ",", "isMultiACK", "bool", ")", "error", "{", "// TODO: implement support for multi_ack or multi_ack_detailed responses", "if", "isMultiACK", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "s", ":=", "pktline", ".", "NewScanner", "(", "reader", ")", "\n\n", "for", "s", ".", "Scan", "(", ")", "{", "line", ":=", "s", ".", "Bytes", "(", ")", "\n\n", "if", "err", ":=", "r", ".", "decodeLine", "(", "line", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "// we need to detect when the end of a response header and the beginning", "// of a packfile header happened, some requests to the git daemon", "// produces a duplicate ACK header even when multi_ack is not supported.", "stop", ",", "err", ":=", "r", ".", "stopReading", "(", "reader", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "if", "stop", "{", "break", "\n", "}", "\n", "}", "\n\n", "return", "s", ".", "Err", "(", ")", "\n", "}" ]
// Decode decodes the response into the struct, isMultiACK should be true, if // the request was done with multi_ack or multi_ack_detailed capabilities.
[ "Decode", "decodes", "the", "response", "into", "the", "struct", "isMultiACK", "should", "be", "true", "if", "the", "request", "was", "done", "with", "multi_ack", "or", "multi_ack_detailed", "capabilities", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/protocol/packp/srvresp.go#L23-L52
train
src-d/go-git
plumbing/protocol/packp/srvresp.go
stopReading
func (r *ServerResponse) stopReading(reader *bufio.Reader) (bool, error) { ahead, err := reader.Peek(7) if err == io.EOF { return true, nil } if err != nil { return false, err } if len(ahead) > 4 && r.isValidCommand(ahead[0:3]) { return false, nil } if len(ahead) == 7 && r.isValidCommand(ahead[4:]) { return false, nil } return true, nil }
go
func (r *ServerResponse) stopReading(reader *bufio.Reader) (bool, error) { ahead, err := reader.Peek(7) if err == io.EOF { return true, nil } if err != nil { return false, err } if len(ahead) > 4 && r.isValidCommand(ahead[0:3]) { return false, nil } if len(ahead) == 7 && r.isValidCommand(ahead[4:]) { return false, nil } return true, nil }
[ "func", "(", "r", "*", "ServerResponse", ")", "stopReading", "(", "reader", "*", "bufio", ".", "Reader", ")", "(", "bool", ",", "error", ")", "{", "ahead", ",", "err", ":=", "reader", ".", "Peek", "(", "7", ")", "\n", "if", "err", "==", "io", ".", "EOF", "{", "return", "true", ",", "nil", "\n", "}", "\n\n", "if", "err", "!=", "nil", "{", "return", "false", ",", "err", "\n", "}", "\n\n", "if", "len", "(", "ahead", ")", ">", "4", "&&", "r", ".", "isValidCommand", "(", "ahead", "[", "0", ":", "3", "]", ")", "{", "return", "false", ",", "nil", "\n", "}", "\n\n", "if", "len", "(", "ahead", ")", "==", "7", "&&", "r", ".", "isValidCommand", "(", "ahead", "[", "4", ":", "]", ")", "{", "return", "false", ",", "nil", "\n", "}", "\n\n", "return", "true", ",", "nil", "\n", "}" ]
// stopReading detects when a valid command such as ACK or NAK is found to be // read in the buffer without moving the read pointer.
[ "stopReading", "detects", "when", "a", "valid", "command", "such", "as", "ACK", "or", "NAK", "is", "found", "to", "be", "read", "in", "the", "buffer", "without", "moving", "the", "read", "pointer", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/protocol/packp/srvresp.go#L56-L75
train
src-d/go-git
plumbing/protocol/packp/srvresp.go
Encode
func (r *ServerResponse) Encode(w io.Writer) error { if len(r.ACKs) > 1 { return errors.New("multi_ack and multi_ack_detailed are not supported") } e := pktline.NewEncoder(w) if len(r.ACKs) == 0 { return e.Encodef("%s\n", nak) } return e.Encodef("%s %s\n", ack, r.ACKs[0].String()) }
go
func (r *ServerResponse) Encode(w io.Writer) error { if len(r.ACKs) > 1 { return errors.New("multi_ack and multi_ack_detailed are not supported") } e := pktline.NewEncoder(w) if len(r.ACKs) == 0 { return e.Encodef("%s\n", nak) } return e.Encodef("%s %s\n", ack, r.ACKs[0].String()) }
[ "func", "(", "r", "*", "ServerResponse", ")", "Encode", "(", "w", "io", ".", "Writer", ")", "error", "{", "if", "len", "(", "r", ".", "ACKs", ")", ">", "1", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "e", ":=", "pktline", ".", "NewEncoder", "(", "w", ")", "\n", "if", "len", "(", "r", ".", "ACKs", ")", "==", "0", "{", "return", "e", ".", "Encodef", "(", "\"", "\\n", "\"", ",", "nak", ")", "\n", "}", "\n\n", "return", "e", ".", "Encodef", "(", "\"", "\\n", "\"", ",", "ack", ",", "r", ".", "ACKs", "[", "0", "]", ".", "String", "(", ")", ")", "\n", "}" ]
// Encode encodes the ServerResponse into a writer.
[ "Encode", "encodes", "the", "ServerResponse", "into", "a", "writer", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/protocol/packp/srvresp.go#L116-L127
train
src-d/go-git
config/refspec.go
Validate
func (s RefSpec) Validate() error { spec := string(s) if strings.Count(spec, refSpecSeparator) != 1 { return ErrRefSpecMalformedSeparator } sep := strings.Index(spec, refSpecSeparator) if sep == len(spec)-1 { return ErrRefSpecMalformedSeparator } ws := strings.Count(spec[0:sep], refSpecWildcard) wd := strings.Count(spec[sep+1:], refSpecWildcard) if ws == wd && ws < 2 && wd < 2 { return nil } return ErrRefSpecMalformedWildcard }
go
func (s RefSpec) Validate() error { spec := string(s) if strings.Count(spec, refSpecSeparator) != 1 { return ErrRefSpecMalformedSeparator } sep := strings.Index(spec, refSpecSeparator) if sep == len(spec)-1 { return ErrRefSpecMalformedSeparator } ws := strings.Count(spec[0:sep], refSpecWildcard) wd := strings.Count(spec[sep+1:], refSpecWildcard) if ws == wd && ws < 2 && wd < 2 { return nil } return ErrRefSpecMalformedWildcard }
[ "func", "(", "s", "RefSpec", ")", "Validate", "(", ")", "error", "{", "spec", ":=", "string", "(", "s", ")", "\n", "if", "strings", ".", "Count", "(", "spec", ",", "refSpecSeparator", ")", "!=", "1", "{", "return", "ErrRefSpecMalformedSeparator", "\n", "}", "\n\n", "sep", ":=", "strings", ".", "Index", "(", "spec", ",", "refSpecSeparator", ")", "\n", "if", "sep", "==", "len", "(", "spec", ")", "-", "1", "{", "return", "ErrRefSpecMalformedSeparator", "\n", "}", "\n\n", "ws", ":=", "strings", ".", "Count", "(", "spec", "[", "0", ":", "sep", "]", ",", "refSpecWildcard", ")", "\n", "wd", ":=", "strings", ".", "Count", "(", "spec", "[", "sep", "+", "1", ":", "]", ",", "refSpecWildcard", ")", "\n", "if", "ws", "==", "wd", "&&", "ws", "<", "2", "&&", "wd", "<", "2", "{", "return", "nil", "\n", "}", "\n\n", "return", "ErrRefSpecMalformedWildcard", "\n", "}" ]
// Validate validates the RefSpec
[ "Validate", "validates", "the", "RefSpec" ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/config/refspec.go#L32-L50
train
src-d/go-git
config/refspec.go
Src
func (s RefSpec) Src() string { spec := string(s) var start int if s.IsForceUpdate() { start = 1 } else { start = 0 } end := strings.Index(spec, refSpecSeparator) return spec[start:end] }
go
func (s RefSpec) Src() string { spec := string(s) var start int if s.IsForceUpdate() { start = 1 } else { start = 0 } end := strings.Index(spec, refSpecSeparator) return spec[start:end] }
[ "func", "(", "s", "RefSpec", ")", "Src", "(", ")", "string", "{", "spec", ":=", "string", "(", "s", ")", "\n\n", "var", "start", "int", "\n", "if", "s", ".", "IsForceUpdate", "(", ")", "{", "start", "=", "1", "\n", "}", "else", "{", "start", "=", "0", "\n", "}", "\n", "end", ":=", "strings", ".", "Index", "(", "spec", ",", "refSpecSeparator", ")", "\n\n", "return", "spec", "[", "start", ":", "end", "]", "\n", "}" ]
// Src return the src side.
[ "Src", "return", "the", "src", "side", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/config/refspec.go#L63-L75
train
src-d/go-git
config/refspec.go
Match
func (s RefSpec) Match(n plumbing.ReferenceName) bool { if !s.IsWildcard() { return s.matchExact(n) } return s.matchGlob(n) }
go
func (s RefSpec) Match(n plumbing.ReferenceName) bool { if !s.IsWildcard() { return s.matchExact(n) } return s.matchGlob(n) }
[ "func", "(", "s", "RefSpec", ")", "Match", "(", "n", "plumbing", ".", "ReferenceName", ")", "bool", "{", "if", "!", "s", ".", "IsWildcard", "(", ")", "{", "return", "s", ".", "matchExact", "(", "n", ")", "\n", "}", "\n\n", "return", "s", ".", "matchGlob", "(", "n", ")", "\n", "}" ]
// Match match the given plumbing.ReferenceName against the source.
[ "Match", "match", "the", "given", "plumbing", ".", "ReferenceName", "against", "the", "source", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/config/refspec.go#L78-L84
train
src-d/go-git
config/refspec.go
Dst
func (s RefSpec) Dst(n plumbing.ReferenceName) plumbing.ReferenceName { spec := string(s) start := strings.Index(spec, refSpecSeparator) + 1 dst := spec[start:] src := s.Src() if !s.IsWildcard() { return plumbing.ReferenceName(dst) } name := n.String() ws := strings.Index(src, refSpecWildcard) wd := strings.Index(dst, refSpecWildcard) match := name[ws : len(name)-(len(src)-(ws+1))] return plumbing.ReferenceName(dst[0:wd] + match + dst[wd+1:]) }
go
func (s RefSpec) Dst(n plumbing.ReferenceName) plumbing.ReferenceName { spec := string(s) start := strings.Index(spec, refSpecSeparator) + 1 dst := spec[start:] src := s.Src() if !s.IsWildcard() { return plumbing.ReferenceName(dst) } name := n.String() ws := strings.Index(src, refSpecWildcard) wd := strings.Index(dst, refSpecWildcard) match := name[ws : len(name)-(len(src)-(ws+1))] return plumbing.ReferenceName(dst[0:wd] + match + dst[wd+1:]) }
[ "func", "(", "s", "RefSpec", ")", "Dst", "(", "n", "plumbing", ".", "ReferenceName", ")", "plumbing", ".", "ReferenceName", "{", "spec", ":=", "string", "(", "s", ")", "\n", "start", ":=", "strings", ".", "Index", "(", "spec", ",", "refSpecSeparator", ")", "+", "1", "\n", "dst", ":=", "spec", "[", "start", ":", "]", "\n", "src", ":=", "s", ".", "Src", "(", ")", "\n\n", "if", "!", "s", ".", "IsWildcard", "(", ")", "{", "return", "plumbing", ".", "ReferenceName", "(", "dst", ")", "\n", "}", "\n\n", "name", ":=", "n", ".", "String", "(", ")", "\n", "ws", ":=", "strings", ".", "Index", "(", "src", ",", "refSpecWildcard", ")", "\n", "wd", ":=", "strings", ".", "Index", "(", "dst", ",", "refSpecWildcard", ")", "\n", "match", ":=", "name", "[", "ws", ":", "len", "(", "name", ")", "-", "(", "len", "(", "src", ")", "-", "(", "ws", "+", "1", ")", ")", "]", "\n\n", "return", "plumbing", ".", "ReferenceName", "(", "dst", "[", "0", ":", "wd", "]", "+", "match", "+", "dst", "[", "wd", "+", "1", ":", "]", ")", "\n", "}" ]
// Dst returns the destination for the given remote reference.
[ "Dst", "returns", "the", "destination", "for", "the", "given", "remote", "reference", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/config/refspec.go#L112-L128
train
src-d/go-git
config/refspec.go
MatchAny
func MatchAny(l []RefSpec, n plumbing.ReferenceName) bool { for _, r := range l { if r.Match(n) { return true } } return false }
go
func MatchAny(l []RefSpec, n plumbing.ReferenceName) bool { for _, r := range l { if r.Match(n) { return true } } return false }
[ "func", "MatchAny", "(", "l", "[", "]", "RefSpec", ",", "n", "plumbing", ".", "ReferenceName", ")", "bool", "{", "for", "_", ",", "r", ":=", "range", "l", "{", "if", "r", ".", "Match", "(", "n", ")", "{", "return", "true", "\n", "}", "\n", "}", "\n\n", "return", "false", "\n", "}" ]
// MatchAny returns true if any of the RefSpec match with the given ReferenceName.
[ "MatchAny", "returns", "true", "if", "any", "of", "the", "RefSpec", "match", "with", "the", "given", "ReferenceName", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/config/refspec.go#L135-L143
train
src-d/go-git
plumbing/transport/client/client.go
InstallProtocol
func InstallProtocol(scheme string, c transport.Transport) { if c == nil { delete(Protocols, scheme) return } Protocols[scheme] = c }
go
func InstallProtocol(scheme string, c transport.Transport) { if c == nil { delete(Protocols, scheme) return } Protocols[scheme] = c }
[ "func", "InstallProtocol", "(", "scheme", "string", ",", "c", "transport", ".", "Transport", ")", "{", "if", "c", "==", "nil", "{", "delete", "(", "Protocols", ",", "scheme", ")", "\n", "return", "\n", "}", "\n\n", "Protocols", "[", "scheme", "]", "=", "c", "\n", "}" ]
// InstallProtocol adds or modifies an existing protocol.
[ "InstallProtocol", "adds", "or", "modifies", "an", "existing", "protocol", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/transport/client/client.go#L25-L32
train
src-d/go-git
plumbing/transport/git/common.go
Start
func (c *command) Start() error { cmd := endpointToCommand(c.command, c.endpoint) e := pktline.NewEncoder(c.conn) return e.Encode([]byte(cmd)) }
go
func (c *command) Start() error { cmd := endpointToCommand(c.command, c.endpoint) e := pktline.NewEncoder(c.conn) return e.Encode([]byte(cmd)) }
[ "func", "(", "c", "*", "command", ")", "Start", "(", ")", "error", "{", "cmd", ":=", "endpointToCommand", "(", "c", ".", "command", ",", "c", ".", "endpoint", ")", "\n\n", "e", ":=", "pktline", ".", "NewEncoder", "(", "c", ".", "conn", ")", "\n", "return", "e", ".", "Encode", "(", "[", "]", "byte", "(", "cmd", ")", ")", "\n", "}" ]
// Start executes the command sending the required message to the TCP connection
[ "Start", "executes", "the", "command", "sending", "the", "required", "message", "to", "the", "TCP", "connection" ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/transport/git/common.go#L43-L48
train
src-d/go-git
plumbing/transport/git/common.go
StdinPipe
func (c *command) StdinPipe() (io.WriteCloser, error) { return ioutil.WriteNopCloser(c.conn), nil }
go
func (c *command) StdinPipe() (io.WriteCloser, error) { return ioutil.WriteNopCloser(c.conn), nil }
[ "func", "(", "c", "*", "command", ")", "StdinPipe", "(", ")", "(", "io", ".", "WriteCloser", ",", "error", ")", "{", "return", "ioutil", ".", "WriteNopCloser", "(", "c", ".", "conn", ")", ",", "nil", "\n", "}" ]
// StdinPipe return the underlying connection as WriteCloser, wrapped to prevent // call to the Close function from the connection, a command execution in git // protocol can't be closed or killed
[ "StdinPipe", "return", "the", "underlying", "connection", "as", "WriteCloser", "wrapped", "to", "prevent", "call", "to", "the", "Close", "function", "from", "the", "connection", "a", "command", "execution", "in", "git", "protocol", "can", "t", "be", "closed", "or", "killed" ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/transport/git/common.go#L83-L85
train
src-d/go-git
plumbing/transport/git/common.go
Close
func (c *command) Close() error { if !c.connected { return nil } c.connected = false return c.conn.Close() }
go
func (c *command) Close() error { if !c.connected { return nil } c.connected = false return c.conn.Close() }
[ "func", "(", "c", "*", "command", ")", "Close", "(", ")", "error", "{", "if", "!", "c", ".", "connected", "{", "return", "nil", "\n", "}", "\n\n", "c", ".", "connected", "=", "false", "\n", "return", "c", ".", "conn", ".", "Close", "(", ")", "\n", "}" ]
// Close closes the TCP connection and connection.
[ "Close", "closes", "the", "TCP", "connection", "and", "connection", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/transport/git/common.go#L102-L109
train
src-d/go-git
utils/merkletrie/internal/frame/frame.go
New
func New(n noder.Noder) (*Frame, error) { children, err := n.Children() if err != nil { return nil, err } sort.Sort(sort.Reverse(byName(children))) return &Frame{ stack: children, }, nil }
go
func New(n noder.Noder) (*Frame, error) { children, err := n.Children() if err != nil { return nil, err } sort.Sort(sort.Reverse(byName(children))) return &Frame{ stack: children, }, nil }
[ "func", "New", "(", "n", "noder", ".", "Noder", ")", "(", "*", "Frame", ",", "error", ")", "{", "children", ",", "err", ":=", "n", ".", "Children", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "sort", ".", "Sort", "(", "sort", ".", "Reverse", "(", "byName", "(", "children", ")", ")", ")", "\n", "return", "&", "Frame", "{", "stack", ":", "children", ",", "}", ",", "nil", "\n", "}" ]
// New returns a frame with the children of the provided node.
[ "New", "returns", "a", "frame", "with", "the", "children", "of", "the", "provided", "node", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/utils/merkletrie/internal/frame/frame.go#L28-L38
train
src-d/go-git
utils/merkletrie/internal/frame/frame.go
First
func (f *Frame) First() (noder.Noder, bool) { if f.Len() == 0 { return nil, false } top := f.Len() - 1 return f.stack[top], true }
go
func (f *Frame) First() (noder.Noder, bool) { if f.Len() == 0 { return nil, false } top := f.Len() - 1 return f.stack[top], true }
[ "func", "(", "f", "*", "Frame", ")", "First", "(", ")", "(", "noder", ".", "Noder", ",", "bool", ")", "{", "if", "f", ".", "Len", "(", ")", "==", "0", "{", "return", "nil", ",", "false", "\n", "}", "\n\n", "top", ":=", "f", ".", "Len", "(", ")", "-", "1", "\n\n", "return", "f", ".", "stack", "[", "top", "]", ",", "true", "\n", "}" ]
// First returns, but dont extract, the noder with the alphabetically // smaller name in the frame and true if the frame was not empy. // Otherwise it returns nil and false.
[ "First", "returns", "but", "dont", "extract", "the", "noder", "with", "the", "alphabetically", "smaller", "name", "in", "the", "frame", "and", "true", "if", "the", "frame", "was", "not", "empy", ".", "Otherwise", "it", "returns", "nil", "and", "false", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/utils/merkletrie/internal/frame/frame.go#L66-L74
train
src-d/go-git
utils/merkletrie/internal/frame/frame.go
Drop
func (f *Frame) Drop() { if f.Len() == 0 { return } top := f.Len() - 1 f.stack[top] = nil f.stack = f.stack[:top] }
go
func (f *Frame) Drop() { if f.Len() == 0 { return } top := f.Len() - 1 f.stack[top] = nil f.stack = f.stack[:top] }
[ "func", "(", "f", "*", "Frame", ")", "Drop", "(", ")", "{", "if", "f", ".", "Len", "(", ")", "==", "0", "{", "return", "\n", "}", "\n\n", "top", ":=", "f", ".", "Len", "(", ")", "-", "1", "\n", "f", ".", "stack", "[", "top", "]", "=", "nil", "\n", "f", ".", "stack", "=", "f", ".", "stack", "[", ":", "top", "]", "\n", "}" ]
// Drop extracts the noder with the alphabetically smaller name in the // frame or does nothing if the frame was empty.
[ "Drop", "extracts", "the", "noder", "with", "the", "alphabetically", "smaller", "name", "in", "the", "frame", "or", "does", "nothing", "if", "the", "frame", "was", "empty", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/utils/merkletrie/internal/frame/frame.go#L78-L86
train
src-d/go-git
plumbing/format/index/decoder.go
Decode
func (d *Decoder) Decode(idx *Index) error { var err error idx.Version, err = validateHeader(d.r) if err != nil { return err } entryCount, err := binary.ReadUint32(d.r) if err != nil { return err } if err := d.readEntries(idx, int(entryCount)); err != nil { return err } return d.readExtensions(idx) }
go
func (d *Decoder) Decode(idx *Index) error { var err error idx.Version, err = validateHeader(d.r) if err != nil { return err } entryCount, err := binary.ReadUint32(d.r) if err != nil { return err } if err := d.readEntries(idx, int(entryCount)); err != nil { return err } return d.readExtensions(idx) }
[ "func", "(", "d", "*", "Decoder", ")", "Decode", "(", "idx", "*", "Index", ")", "error", "{", "var", "err", "error", "\n", "idx", ".", "Version", ",", "err", "=", "validateHeader", "(", "d", ".", "r", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "entryCount", ",", "err", ":=", "binary", ".", "ReadUint32", "(", "d", ".", "r", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "if", "err", ":=", "d", ".", "readEntries", "(", "idx", ",", "int", "(", "entryCount", ")", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "d", ".", "readExtensions", "(", "idx", ")", "\n", "}" ]
// Decode reads the whole index object from its input and stores it in the // value pointed to by idx.
[ "Decode", "reads", "the", "whole", "index", "object", "from", "its", "input", "and", "stores", "it", "in", "the", "value", "pointed", "to", "by", "idx", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/format/index/decoder.go#L62-L79
train
src-d/go-git
plumbing/format/index/decoder.go
padEntry
func (d *Decoder) padEntry(idx *Index, e *Entry, read int) error { if idx.Version == 4 { return nil } entrySize := read + len(e.Name) padLen := 8 - entrySize%8 _, err := io.CopyN(ioutil.Discard, d.r, int64(padLen)) return err }
go
func (d *Decoder) padEntry(idx *Index, e *Entry, read int) error { if idx.Version == 4 { return nil } entrySize := read + len(e.Name) padLen := 8 - entrySize%8 _, err := io.CopyN(ioutil.Discard, d.r, int64(padLen)) return err }
[ "func", "(", "d", "*", "Decoder", ")", "padEntry", "(", "idx", "*", "Index", ",", "e", "*", "Entry", ",", "read", "int", ")", "error", "{", "if", "idx", ".", "Version", "==", "4", "{", "return", "nil", "\n", "}", "\n\n", "entrySize", ":=", "read", "+", "len", "(", "e", ".", "Name", ")", "\n", "padLen", ":=", "8", "-", "entrySize", "%", "8", "\n", "_", ",", "err", ":=", "io", ".", "CopyN", "(", "ioutil", ".", "Discard", ",", "d", ".", "r", ",", "int64", "(", "padLen", ")", ")", "\n", "return", "err", "\n", "}" ]
// Index entries are padded out to the next 8 byte alignment // for historical reasons related to how C Git read the files.
[ "Index", "entries", "are", "padded", "out", "to", "the", "next", "8", "byte", "alignment", "for", "historical", "reasons", "related", "to", "how", "C", "Git", "read", "the", "files", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/format/index/decoder.go#L198-L207
train
src-d/go-git
plumbing/object/commit_walker.go
NewCommitPostorderIter
func NewCommitPostorderIter(c *Commit, ignore []plumbing.Hash) CommitIter { seen := make(map[plumbing.Hash]bool) for _, h := range ignore { seen[h] = true } return &commitPostIterator{ stack: []*Commit{c}, seen: seen, } }
go
func NewCommitPostorderIter(c *Commit, ignore []plumbing.Hash) CommitIter { seen := make(map[plumbing.Hash]bool) for _, h := range ignore { seen[h] = true } return &commitPostIterator{ stack: []*Commit{c}, seen: seen, } }
[ "func", "NewCommitPostorderIter", "(", "c", "*", "Commit", ",", "ignore", "[", "]", "plumbing", ".", "Hash", ")", "CommitIter", "{", "seen", ":=", "make", "(", "map", "[", "plumbing", ".", "Hash", "]", "bool", ")", "\n", "for", "_", ",", "h", ":=", "range", "ignore", "{", "seen", "[", "h", "]", "=", "true", "\n", "}", "\n\n", "return", "&", "commitPostIterator", "{", "stack", ":", "[", "]", "*", "Commit", "{", "c", "}", ",", "seen", ":", "seen", ",", "}", "\n", "}" ]
// NewCommitPostorderIter returns a CommitIter that walks the commit // history like WalkCommitHistory but in post-order. This means that after // walking a merge commit, the merged commit will be walked before the base // it was merged on. This can be useful if you wish to see the history in // chronological order. Ignore allows to skip some commits from being iterated.
[ "NewCommitPostorderIter", "returns", "a", "CommitIter", "that", "walks", "the", "commit", "history", "like", "WalkCommitHistory", "but", "in", "post", "-", "order", ".", "This", "means", "that", "after", "walking", "a", "merge", "commit", "the", "merged", "commit", "will", "be", "walked", "before", "the", "base", "it", "was", "merged", "on", ".", "This", "can", "be", "useful", "if", "you", "wish", "to", "see", "the", "history", "in", "chronological", "order", ".", "Ignore", "allows", "to", "skip", "some", "commits", "from", "being", "iterated", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/object/commit_walker.go#L129-L139
train
src-d/go-git
plumbing/format/gitattributes/pattern.go
ParsePattern
func ParsePattern(p string, domain []string) Pattern { return &pattern{ domain: domain, pattern: strings.Split(p, patternDirSep), } }
go
func ParsePattern(p string, domain []string) Pattern { return &pattern{ domain: domain, pattern: strings.Split(p, patternDirSep), } }
[ "func", "ParsePattern", "(", "p", "string", ",", "domain", "[", "]", "string", ")", "Pattern", "{", "return", "&", "pattern", "{", "domain", ":", "domain", ",", "pattern", ":", "strings", ".", "Split", "(", "p", ",", "patternDirSep", ")", ",", "}", "\n", "}" ]
// ParsePattern parses a gitattributes pattern string into the Pattern // structure.
[ "ParsePattern", "parses", "a", "gitattributes", "pattern", "string", "into", "the", "Pattern", "structure", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/format/gitattributes/pattern.go#L26-L31
train
src-d/go-git
plumbing/transport/file/server.go
ServeUploadPack
func ServeUploadPack(path string) error { ep, err := transport.NewEndpoint(path) if err != nil { return err } // TODO: define and implement a server-side AuthMethod s, err := server.DefaultServer.NewUploadPackSession(ep, nil) if err != nil { return fmt.Errorf("error creating session: %s", err) } return common.ServeUploadPack(srvCmd, s) }
go
func ServeUploadPack(path string) error { ep, err := transport.NewEndpoint(path) if err != nil { return err } // TODO: define and implement a server-side AuthMethod s, err := server.DefaultServer.NewUploadPackSession(ep, nil) if err != nil { return fmt.Errorf("error creating session: %s", err) } return common.ServeUploadPack(srvCmd, s) }
[ "func", "ServeUploadPack", "(", "path", "string", ")", "error", "{", "ep", ",", "err", ":=", "transport", ".", "NewEndpoint", "(", "path", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "// TODO: define and implement a server-side AuthMethod", "s", ",", "err", ":=", "server", ".", "DefaultServer", ".", "NewUploadPackSession", "(", "ep", ",", "nil", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "return", "common", ".", "ServeUploadPack", "(", "srvCmd", ",", "s", ")", "\n", "}" ]
// ServeUploadPack serves a git-upload-pack request using standard output, input // and error. This is meant to be used when implementing a git-upload-pack // command.
[ "ServeUploadPack", "serves", "a", "git", "-", "upload", "-", "pack", "request", "using", "standard", "output", "input", "and", "error", ".", "This", "is", "meant", "to", "be", "used", "when", "implementing", "a", "git", "-", "upload", "-", "pack", "command", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/transport/file/server.go#L16-L29
train
src-d/go-git
plumbing/transport/file/server.go
ServeReceivePack
func ServeReceivePack(path string) error { ep, err := transport.NewEndpoint(path) if err != nil { return err } // TODO: define and implement a server-side AuthMethod s, err := server.DefaultServer.NewReceivePackSession(ep, nil) if err != nil { return fmt.Errorf("error creating session: %s", err) } return common.ServeReceivePack(srvCmd, s) }
go
func ServeReceivePack(path string) error { ep, err := transport.NewEndpoint(path) if err != nil { return err } // TODO: define and implement a server-side AuthMethod s, err := server.DefaultServer.NewReceivePackSession(ep, nil) if err != nil { return fmt.Errorf("error creating session: %s", err) } return common.ServeReceivePack(srvCmd, s) }
[ "func", "ServeReceivePack", "(", "path", "string", ")", "error", "{", "ep", ",", "err", ":=", "transport", ".", "NewEndpoint", "(", "path", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "// TODO: define and implement a server-side AuthMethod", "s", ",", "err", ":=", "server", ".", "DefaultServer", ".", "NewReceivePackSession", "(", "ep", ",", "nil", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "return", "common", ".", "ServeReceivePack", "(", "srvCmd", ",", "s", ")", "\n", "}" ]
// ServeReceivePack serves a git-receive-pack request using standard output, // input and error. This is meant to be used when implementing a // git-receive-pack command.
[ "ServeReceivePack", "serves", "a", "git", "-", "receive", "-", "pack", "request", "using", "standard", "output", "input", "and", "error", ".", "This", "is", "meant", "to", "be", "used", "when", "implementing", "a", "git", "-", "receive", "-", "pack", "command", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/transport/file/server.go#L34-L47
train
src-d/go-git
storage/transactional/reference.go
NewReferenceStorage
func NewReferenceStorage(base, temporal storer.ReferenceStorer) *ReferenceStorage { return &ReferenceStorage{ ReferenceStorer: base, temporal: temporal, deleted: make(map[plumbing.ReferenceName]struct{}, 0), } }
go
func NewReferenceStorage(base, temporal storer.ReferenceStorer) *ReferenceStorage { return &ReferenceStorage{ ReferenceStorer: base, temporal: temporal, deleted: make(map[plumbing.ReferenceName]struct{}, 0), } }
[ "func", "NewReferenceStorage", "(", "base", ",", "temporal", "storer", ".", "ReferenceStorer", ")", "*", "ReferenceStorage", "{", "return", "&", "ReferenceStorage", "{", "ReferenceStorer", ":", "base", ",", "temporal", ":", "temporal", ",", "deleted", ":", "make", "(", "map", "[", "plumbing", ".", "ReferenceName", "]", "struct", "{", "}", ",", "0", ")", ",", "}", "\n", "}" ]
// NewReferenceStorage returns a new ReferenceStorer based on a base storer and // a temporal storer.
[ "NewReferenceStorage", "returns", "a", "new", "ReferenceStorer", "based", "on", "a", "base", "storer", "and", "a", "temporal", "storer", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/storage/transactional/reference.go#L25-L32
train
src-d/go-git
storage/transactional/reference.go
Reference
func (r ReferenceStorage) Reference(n plumbing.ReferenceName) (*plumbing.Reference, error) { if _, deleted := r.deleted[n]; deleted { return nil, plumbing.ErrReferenceNotFound } ref, err := r.temporal.Reference(n) if err == plumbing.ErrReferenceNotFound { return r.ReferenceStorer.Reference(n) } return ref, err }
go
func (r ReferenceStorage) Reference(n plumbing.ReferenceName) (*plumbing.Reference, error) { if _, deleted := r.deleted[n]; deleted { return nil, plumbing.ErrReferenceNotFound } ref, err := r.temporal.Reference(n) if err == plumbing.ErrReferenceNotFound { return r.ReferenceStorer.Reference(n) } return ref, err }
[ "func", "(", "r", "ReferenceStorage", ")", "Reference", "(", "n", "plumbing", ".", "ReferenceName", ")", "(", "*", "plumbing", ".", "Reference", ",", "error", ")", "{", "if", "_", ",", "deleted", ":=", "r", ".", "deleted", "[", "n", "]", ";", "deleted", "{", "return", "nil", ",", "plumbing", ".", "ErrReferenceNotFound", "\n", "}", "\n\n", "ref", ",", "err", ":=", "r", ".", "temporal", ".", "Reference", "(", "n", ")", "\n", "if", "err", "==", "plumbing", ".", "ErrReferenceNotFound", "{", "return", "r", ".", "ReferenceStorer", ".", "Reference", "(", "n", ")", "\n", "}", "\n\n", "return", "ref", ",", "err", "\n", "}" ]
// Reference honors the storer.ReferenceStorer interface.
[ "Reference", "honors", "the", "storer", ".", "ReferenceStorer", "interface", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/storage/transactional/reference.go#L63-L74
train
src-d/go-git
storage/transactional/reference.go
IterReferences
func (r ReferenceStorage) IterReferences() (storer.ReferenceIter, error) { baseIter, err := r.ReferenceStorer.IterReferences() if err != nil { return nil, err } temporalIter, err := r.temporal.IterReferences() if err != nil { return nil, err } return storer.NewMultiReferenceIter([]storer.ReferenceIter{ baseIter, temporalIter, }), nil }
go
func (r ReferenceStorage) IterReferences() (storer.ReferenceIter, error) { baseIter, err := r.ReferenceStorer.IterReferences() if err != nil { return nil, err } temporalIter, err := r.temporal.IterReferences() if err != nil { return nil, err } return storer.NewMultiReferenceIter([]storer.ReferenceIter{ baseIter, temporalIter, }), nil }
[ "func", "(", "r", "ReferenceStorage", ")", "IterReferences", "(", ")", "(", "storer", ".", "ReferenceIter", ",", "error", ")", "{", "baseIter", ",", "err", ":=", "r", ".", "ReferenceStorer", ".", "IterReferences", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "temporalIter", ",", "err", ":=", "r", ".", "temporal", ".", "IterReferences", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "storer", ".", "NewMultiReferenceIter", "(", "[", "]", "storer", ".", "ReferenceIter", "{", "baseIter", ",", "temporalIter", ",", "}", ")", ",", "nil", "\n", "}" ]
// IterReferences honors the storer.ReferenceStorer interface.
[ "IterReferences", "honors", "the", "storer", ".", "ReferenceStorer", "interface", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/storage/transactional/reference.go#L77-L92
train
src-d/go-git
storage/transactional/reference.go
CountLooseRefs
func (r ReferenceStorage) CountLooseRefs() (int, error) { tc, err := r.temporal.CountLooseRefs() if err != nil { return -1, err } bc, err := r.ReferenceStorer.CountLooseRefs() if err != nil { return -1, err } return tc + bc, nil }
go
func (r ReferenceStorage) CountLooseRefs() (int, error) { tc, err := r.temporal.CountLooseRefs() if err != nil { return -1, err } bc, err := r.ReferenceStorer.CountLooseRefs() if err != nil { return -1, err } return tc + bc, nil }
[ "func", "(", "r", "ReferenceStorage", ")", "CountLooseRefs", "(", ")", "(", "int", ",", "error", ")", "{", "tc", ",", "err", ":=", "r", ".", "temporal", ".", "CountLooseRefs", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "-", "1", ",", "err", "\n", "}", "\n\n", "bc", ",", "err", ":=", "r", ".", "ReferenceStorer", ".", "CountLooseRefs", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "-", "1", ",", "err", "\n", "}", "\n\n", "return", "tc", "+", "bc", ",", "nil", "\n", "}" ]
// CountLooseRefs honors the storer.ReferenceStorer interface.
[ "CountLooseRefs", "honors", "the", "storer", ".", "ReferenceStorer", "interface", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/storage/transactional/reference.go#L95-L107
train
src-d/go-git
storage/transactional/reference.go
RemoveReference
func (r ReferenceStorage) RemoveReference(n plumbing.ReferenceName) error { r.deleted[n] = struct{}{} return r.temporal.RemoveReference(n) }
go
func (r ReferenceStorage) RemoveReference(n plumbing.ReferenceName) error { r.deleted[n] = struct{}{} return r.temporal.RemoveReference(n) }
[ "func", "(", "r", "ReferenceStorage", ")", "RemoveReference", "(", "n", "plumbing", ".", "ReferenceName", ")", "error", "{", "r", ".", "deleted", "[", "n", "]", "=", "struct", "{", "}", "{", "}", "\n", "return", "r", ".", "temporal", ".", "RemoveReference", "(", "n", ")", "\n", "}" ]
// RemoveReference honors the storer.ReferenceStorer interface.
[ "RemoveReference", "honors", "the", "storer", ".", "ReferenceStorer", "interface", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/storage/transactional/reference.go#L116-L119
train
src-d/go-git
storage/transactional/reference.go
Commit
func (r ReferenceStorage) Commit() error { for name := range r.deleted { if err := r.ReferenceStorer.RemoveReference(name); err != nil { return err } } iter, err := r.temporal.IterReferences() if err != nil { return err } return iter.ForEach(func(ref *plumbing.Reference) error { return r.ReferenceStorer.SetReference(ref) }) }
go
func (r ReferenceStorage) Commit() error { for name := range r.deleted { if err := r.ReferenceStorer.RemoveReference(name); err != nil { return err } } iter, err := r.temporal.IterReferences() if err != nil { return err } return iter.ForEach(func(ref *plumbing.Reference) error { return r.ReferenceStorer.SetReference(ref) }) }
[ "func", "(", "r", "ReferenceStorage", ")", "Commit", "(", ")", "error", "{", "for", "name", ":=", "range", "r", ".", "deleted", "{", "if", "err", ":=", "r", ".", "ReferenceStorer", ".", "RemoveReference", "(", "name", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n\n", "iter", ",", "err", ":=", "r", ".", "temporal", ".", "IterReferences", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "iter", ".", "ForEach", "(", "func", "(", "ref", "*", "plumbing", ".", "Reference", ")", "error", "{", "return", "r", ".", "ReferenceStorer", ".", "SetReference", "(", "ref", ")", "\n", "}", ")", "\n", "}" ]
// Commit it copies the reference information of the temporal storage into the // base storage.
[ "Commit", "it", "copies", "the", "reference", "information", "of", "the", "temporal", "storage", "into", "the", "base", "storage", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/storage/transactional/reference.go#L123-L138
train
src-d/go-git
plumbing/memory.go
Hash
func (o *MemoryObject) Hash() Hash { if o.h == ZeroHash && int64(len(o.cont)) == o.sz { o.h = ComputeHash(o.t, o.cont) } return o.h }
go
func (o *MemoryObject) Hash() Hash { if o.h == ZeroHash && int64(len(o.cont)) == o.sz { o.h = ComputeHash(o.t, o.cont) } return o.h }
[ "func", "(", "o", "*", "MemoryObject", ")", "Hash", "(", ")", "Hash", "{", "if", "o", ".", "h", "==", "ZeroHash", "&&", "int64", "(", "len", "(", "o", ".", "cont", ")", ")", "==", "o", ".", "sz", "{", "o", ".", "h", "=", "ComputeHash", "(", "o", ".", "t", ",", "o", ".", "cont", ")", "\n", "}", "\n\n", "return", "o", ".", "h", "\n", "}" ]
// Hash returns the object Hash, the hash is calculated on-the-fly the first // time it's called, in all subsequent calls the same Hash is returned even // if the type or the content have changed. The Hash is only generated if the // size of the content is exactly the object size.
[ "Hash", "returns", "the", "object", "Hash", "the", "hash", "is", "calculated", "on", "-", "the", "-", "fly", "the", "first", "time", "it", "s", "called", "in", "all", "subsequent", "calls", "the", "same", "Hash", "is", "returned", "even", "if", "the", "type", "or", "the", "content", "have", "changed", ".", "The", "Hash", "is", "only", "generated", "if", "the", "size", "of", "the", "content", "is", "exactly", "the", "object", "size", "." ]
e17ee112ca6cc7db0a732c0676b61511e84ec899
https://github.com/src-d/go-git/blob/e17ee112ca6cc7db0a732c0676b61511e84ec899/plumbing/memory.go#L21-L27
train