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 list | docstring stringlengths 6 2.61k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 85 252 | partition stringclasses 1 value |
|---|---|---|---|---|---|---|---|---|---|---|---|
paulmach/orb | encoding/mvt/clip.go | Clip | func (ls Layers) Clip(box orb.Bound) {
for _, l := range ls {
l.Clip(box)
}
} | go | func (ls Layers) Clip(box orb.Bound) {
for _, l := range ls {
l.Clip(box)
}
} | [
"func",
"(",
"ls",
"Layers",
")",
"Clip",
"(",
"box",
"orb",
".",
"Bound",
")",
"{",
"for",
"_",
",",
"l",
":=",
"range",
"ls",
"{",
"l",
".",
"Clip",
"(",
"box",
")",
"\n",
"}",
"\n",
"}"
] | // Clip will clip all geometries in all layers to the given bounds. | [
"Clip",
"will",
"clip",
"all",
"geometries",
"in",
"all",
"layers",
"to",
"the",
"given",
"bounds",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/encoding/mvt/clip.go#L18-L22 | train |
paulmach/orb | encoding/mvt/clip.go | Clip | func (l *Layer) Clip(box orb.Bound) {
for _, f := range l.Features {
g := clip.Geometry(box, f.Geometry)
f.Geometry = g
}
} | go | func (l *Layer) Clip(box orb.Bound) {
for _, f := range l.Features {
g := clip.Geometry(box, f.Geometry)
f.Geometry = g
}
} | [
"func",
"(",
"l",
"*",
"Layer",
")",
"Clip",
"(",
"box",
"orb",
".",
"Bound",
")",
"{",
"for",
"_",
",",
"f",
":=",
"range",
"l",
".",
"Features",
"{",
"g",
":=",
"clip",
".",
"Geometry",
"(",
"box",
",",
"f",
".",
"Geometry",
")",
"\n",
"f",... | // Clip will clip all geometries in this layer to the given bounds. | [
"Clip",
"will",
"clip",
"all",
"geometries",
"in",
"this",
"layer",
"to",
"the",
"given",
"bounds",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/encoding/mvt/clip.go#L25-L30 | train |
paulmach/orb | clip/smartclip/around_bound.go | aroundBound | func aroundBound(
box orb.Bound,
in orb.Ring,
o orb.Orientation,
) orb.Ring {
if o != orb.CCW && o != orb.CW {
panic("invalid orientation")
}
if len(in) == 0 {
return nil
}
next := nexts[o]
f := in[0]
l := in[len(in)-1]
target := bitCodeOpen(box, f)
current := bitCodeOpen(box, l)
if target == 0 || current == 0 {
panic("endpoints must be outside bound")
}
if current == target {
// endpoints long an edge. Need to figure out what order they're in
// to figure out if we just need to connect them or go all the way around.
points := []*endpoint{
{
Point: f,
Start: true,
Side: pointSide(box, f),
Index: 0,
},
{
Point: l,
Start: false,
Side: pointSide(box, l),
Index: 0,
},
}
se := &sortableEndpoints{
mls: []orb.LineString{orb.LineString(in)},
eps: points,
}
if o == orb.CCW {
sort.Sort(se)
} else {
sort.Sort(sort.Reverse(se))
}
if !points[0].Start {
if f != in[len(in)-1] {
in = append(in, f)
}
return in
}
}
// move to next and go until we're all the way around.
current = next[current]
for target != current {
in = append(in, pointFor(box, current))
current = next[current]
}
// add first point to the end to make it a ring
in = append(in, f)
return in
} | go | func aroundBound(
box orb.Bound,
in orb.Ring,
o orb.Orientation,
) orb.Ring {
if o != orb.CCW && o != orb.CW {
panic("invalid orientation")
}
if len(in) == 0 {
return nil
}
next := nexts[o]
f := in[0]
l := in[len(in)-1]
target := bitCodeOpen(box, f)
current := bitCodeOpen(box, l)
if target == 0 || current == 0 {
panic("endpoints must be outside bound")
}
if current == target {
// endpoints long an edge. Need to figure out what order they're in
// to figure out if we just need to connect them or go all the way around.
points := []*endpoint{
{
Point: f,
Start: true,
Side: pointSide(box, f),
Index: 0,
},
{
Point: l,
Start: false,
Side: pointSide(box, l),
Index: 0,
},
}
se := &sortableEndpoints{
mls: []orb.LineString{orb.LineString(in)},
eps: points,
}
if o == orb.CCW {
sort.Sort(se)
} else {
sort.Sort(sort.Reverse(se))
}
if !points[0].Start {
if f != in[len(in)-1] {
in = append(in, f)
}
return in
}
}
// move to next and go until we're all the way around.
current = next[current]
for target != current {
in = append(in, pointFor(box, current))
current = next[current]
}
// add first point to the end to make it a ring
in = append(in, f)
return in
} | [
"func",
"aroundBound",
"(",
"box",
"orb",
".",
"Bound",
",",
"in",
"orb",
".",
"Ring",
",",
"o",
"orb",
".",
"Orientation",
",",
")",
"orb",
".",
"Ring",
"{",
"if",
"o",
"!=",
"orb",
".",
"CCW",
"&&",
"o",
"!=",
"orb",
".",
"CW",
"{",
"panic",
... | // aroundBound will connect the endpoints of the linestring provided
// by wrapping the line around the bounds in the direction provided.
// Will append to the input. | [
"aroundBound",
"will",
"connect",
"the",
"endpoints",
"of",
"the",
"linestring",
"provided",
"by",
"wrapping",
"the",
"line",
"around",
"the",
"bounds",
"in",
"the",
"direction",
"provided",
".",
"Will",
"append",
"to",
"the",
"input",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/clip/smartclip/around_bound.go#L12-L84 | train |
paulmach/orb | clip/smartclip/around_bound.go | pointFor | func pointFor(b orb.Bound, code int) orb.Point {
switch code {
case 1:
return orb.Point{b.Min[0], (b.Max[1] + b.Min[1]) / 2}
case 2:
return orb.Point{b.Max[0], (b.Max[1] + b.Min[1]) / 2}
case 4:
return orb.Point{(b.Max[0] + b.Min[0]) / 2, b.Min[1]}
case 5:
return orb.Point{b.Min[0], b.Min[1]}
case 6:
return orb.Point{b.Max[0], b.Min[1]}
case 8:
return orb.Point{(b.Max[0] + b.Min[0]) / 2, b.Max[1]}
case 9:
return orb.Point{b.Min[0], b.Max[1]}
case 10:
return orb.Point{b.Max[0], b.Max[1]}
}
panic("invalid code")
} | go | func pointFor(b orb.Bound, code int) orb.Point {
switch code {
case 1:
return orb.Point{b.Min[0], (b.Max[1] + b.Min[1]) / 2}
case 2:
return orb.Point{b.Max[0], (b.Max[1] + b.Min[1]) / 2}
case 4:
return orb.Point{(b.Max[0] + b.Min[0]) / 2, b.Min[1]}
case 5:
return orb.Point{b.Min[0], b.Min[1]}
case 6:
return orb.Point{b.Max[0], b.Min[1]}
case 8:
return orb.Point{(b.Max[0] + b.Min[0]) / 2, b.Max[1]}
case 9:
return orb.Point{b.Min[0], b.Max[1]}
case 10:
return orb.Point{b.Max[0], b.Max[1]}
}
panic("invalid code")
} | [
"func",
"pointFor",
"(",
"b",
"orb",
".",
"Bound",
",",
"code",
"int",
")",
"orb",
".",
"Point",
"{",
"switch",
"code",
"{",
"case",
"1",
":",
"return",
"orb",
".",
"Point",
"{",
"b",
".",
"Min",
"[",
"0",
"]",
",",
"(",
"b",
".",
"Max",
"[",... | // pointFor returns a representative point for the side of the given bitCode. | [
"pointFor",
"returns",
"a",
"representative",
"point",
"for",
"the",
"side",
"of",
"the",
"given",
"bitCode",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/clip/smartclip/around_bound.go#L110-L131 | train |
paulmach/orb | line_string.go | Reverse | func (ls LineString) Reverse() {
l := len(ls) - 1
for i := 0; i <= l/2; i++ {
ls[i], ls[l-i] = ls[l-i], ls[i]
}
} | go | func (ls LineString) Reverse() {
l := len(ls) - 1
for i := 0; i <= l/2; i++ {
ls[i], ls[l-i] = ls[l-i], ls[i]
}
} | [
"func",
"(",
"ls",
"LineString",
")",
"Reverse",
"(",
")",
"{",
"l",
":=",
"len",
"(",
"ls",
")",
"-",
"1",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<=",
"l",
"/",
"2",
";",
"i",
"++",
"{",
"ls",
"[",
"i",
"]",
",",
"ls",
"[",
"l",
"-",
... | // Reverse will reverse the line string.
// This is done inplace, ie. it modifies the original data. | [
"Reverse",
"will",
"reverse",
"the",
"line",
"string",
".",
"This",
"is",
"done",
"inplace",
"ie",
".",
"it",
"modifies",
"the",
"original",
"data",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/line_string.go#L18-L23 | train |
paulmach/orb | line_string.go | Equal | func (ls LineString) Equal(lineString LineString) bool {
return MultiPoint(ls).Equal(MultiPoint(lineString))
} | go | func (ls LineString) Equal(lineString LineString) bool {
return MultiPoint(ls).Equal(MultiPoint(lineString))
} | [
"func",
"(",
"ls",
"LineString",
")",
"Equal",
"(",
"lineString",
"LineString",
")",
"bool",
"{",
"return",
"MultiPoint",
"(",
"ls",
")",
".",
"Equal",
"(",
"MultiPoint",
"(",
"lineString",
")",
")",
"\n",
"}"
] | // Equal compares two line strings. Returns true if lengths are the same
// and all points are Equal. | [
"Equal",
"compares",
"two",
"line",
"strings",
".",
"Returns",
"true",
"if",
"lengths",
"are",
"the",
"same",
"and",
"all",
"points",
"are",
"Equal",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/line_string.go#L32-L34 | train |
paulmach/orb | line_string.go | Clone | func (ls LineString) Clone() LineString {
ps := MultiPoint(ls)
return LineString(ps.Clone())
} | go | func (ls LineString) Clone() LineString {
ps := MultiPoint(ls)
return LineString(ps.Clone())
} | [
"func",
"(",
"ls",
"LineString",
")",
"Clone",
"(",
")",
"LineString",
"{",
"ps",
":=",
"MultiPoint",
"(",
"ls",
")",
"\n",
"return",
"LineString",
"(",
"ps",
".",
"Clone",
"(",
")",
")",
"\n",
"}"
] | // Clone returns a new copy of the line string. | [
"Clone",
"returns",
"a",
"new",
"copy",
"of",
"the",
"line",
"string",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/line_string.go#L37-L40 | train |
paulmach/orb | geo/distance.go | Distance | func Distance(p1, p2 orb.Point) float64 {
dLat := deg2rad(p1[1] - p2[1])
dLon := deg2rad(p1[0] - p2[0])
dLon = math.Abs(dLon)
if dLon > math.Pi {
dLon = 2*math.Pi - dLon
}
// fast way using pythagorean theorem on an equirectangular projection
x := dLon * math.Cos(deg2rad((p1[1]+p2[1])/2.0))
return math.Sqrt(dLat*dLat+x*x) * orb.EarthRadius
} | go | func Distance(p1, p2 orb.Point) float64 {
dLat := deg2rad(p1[1] - p2[1])
dLon := deg2rad(p1[0] - p2[0])
dLon = math.Abs(dLon)
if dLon > math.Pi {
dLon = 2*math.Pi - dLon
}
// fast way using pythagorean theorem on an equirectangular projection
x := dLon * math.Cos(deg2rad((p1[1]+p2[1])/2.0))
return math.Sqrt(dLat*dLat+x*x) * orb.EarthRadius
} | [
"func",
"Distance",
"(",
"p1",
",",
"p2",
"orb",
".",
"Point",
")",
"float64",
"{",
"dLat",
":=",
"deg2rad",
"(",
"p1",
"[",
"1",
"]",
"-",
"p2",
"[",
"1",
"]",
")",
"\n",
"dLon",
":=",
"deg2rad",
"(",
"p1",
"[",
"0",
"]",
"-",
"p2",
"[",
"... | // Distance returns the distance between two points on the earth. | [
"Distance",
"returns",
"the",
"distance",
"between",
"two",
"points",
"on",
"the",
"earth",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/geo/distance.go#L10-L22 | train |
paulmach/orb | geo/distance.go | DistanceHaversine | func DistanceHaversine(p1, p2 orb.Point) float64 {
dLat := deg2rad(p1[1] - p2[1])
dLon := deg2rad(p1[0] - p2[0])
dLat2Sin := math.Sin(dLat / 2)
dLon2Sin := math.Sin(dLon / 2)
a := dLat2Sin*dLat2Sin + math.Cos(deg2rad(p2[1]))*math.Cos(deg2rad(p1[1]))*dLon2Sin*dLon2Sin
return 2.0 * orb.EarthRadius * math.Atan2(math.Sqrt(a), math.Sqrt(1-a))
} | go | func DistanceHaversine(p1, p2 orb.Point) float64 {
dLat := deg2rad(p1[1] - p2[1])
dLon := deg2rad(p1[0] - p2[0])
dLat2Sin := math.Sin(dLat / 2)
dLon2Sin := math.Sin(dLon / 2)
a := dLat2Sin*dLat2Sin + math.Cos(deg2rad(p2[1]))*math.Cos(deg2rad(p1[1]))*dLon2Sin*dLon2Sin
return 2.0 * orb.EarthRadius * math.Atan2(math.Sqrt(a), math.Sqrt(1-a))
} | [
"func",
"DistanceHaversine",
"(",
"p1",
",",
"p2",
"orb",
".",
"Point",
")",
"float64",
"{",
"dLat",
":=",
"deg2rad",
"(",
"p1",
"[",
"1",
"]",
"-",
"p2",
"[",
"1",
"]",
")",
"\n",
"dLon",
":=",
"deg2rad",
"(",
"p1",
"[",
"0",
"]",
"-",
"p2",
... | // DistanceHaversine computes the distance on the earth using the
// more accurate haversine formula. | [
"DistanceHaversine",
"computes",
"the",
"distance",
"on",
"the",
"earth",
"using",
"the",
"more",
"accurate",
"haversine",
"formula",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/geo/distance.go#L26-L35 | train |
paulmach/orb | geo/distance.go | Bearing | func Bearing(from, to orb.Point) float64 {
dLon := deg2rad(to[0] - from[0])
fromLatRad := deg2rad(from[1])
toLatRad := deg2rad(to[1])
y := math.Sin(dLon) * math.Cos(toLatRad)
x := math.Cos(fromLatRad)*math.Sin(toLatRad) - math.Sin(fromLatRad)*math.Cos(toLatRad)*math.Cos(dLon)
return rad2deg(math.Atan2(y, x))
} | go | func Bearing(from, to orb.Point) float64 {
dLon := deg2rad(to[0] - from[0])
fromLatRad := deg2rad(from[1])
toLatRad := deg2rad(to[1])
y := math.Sin(dLon) * math.Cos(toLatRad)
x := math.Cos(fromLatRad)*math.Sin(toLatRad) - math.Sin(fromLatRad)*math.Cos(toLatRad)*math.Cos(dLon)
return rad2deg(math.Atan2(y, x))
} | [
"func",
"Bearing",
"(",
"from",
",",
"to",
"orb",
".",
"Point",
")",
"float64",
"{",
"dLon",
":=",
"deg2rad",
"(",
"to",
"[",
"0",
"]",
"-",
"from",
"[",
"0",
"]",
")",
"\n\n",
"fromLatRad",
":=",
"deg2rad",
"(",
"from",
"[",
"1",
"]",
")",
"\n... | // Bearing computes the direction one must start traveling on earth
// to be heading from, to the given points. | [
"Bearing",
"computes",
"the",
"direction",
"one",
"must",
"start",
"traveling",
"on",
"earth",
"to",
"be",
"heading",
"from",
"to",
"the",
"given",
"points",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/geo/distance.go#L39-L49 | train |
paulmach/orb | geo/distance.go | Midpoint | func Midpoint(p, p2 orb.Point) orb.Point {
dLon := deg2rad(p2[0] - p[0])
aLatRad := deg2rad(p[1])
bLatRad := deg2rad(p2[1])
x := math.Cos(bLatRad) * math.Cos(dLon)
y := math.Cos(bLatRad) * math.Sin(dLon)
r := orb.Point{
deg2rad(p[0]) + math.Atan2(y, math.Cos(aLatRad)+x),
math.Atan2(math.Sin(aLatRad)+math.Sin(bLatRad), math.Sqrt((math.Cos(aLatRad)+x)*(math.Cos(aLatRad)+x)+y*y)),
}
// convert back to degrees
r[0] = rad2deg(r[0])
r[1] = rad2deg(r[1])
return r
} | go | func Midpoint(p, p2 orb.Point) orb.Point {
dLon := deg2rad(p2[0] - p[0])
aLatRad := deg2rad(p[1])
bLatRad := deg2rad(p2[1])
x := math.Cos(bLatRad) * math.Cos(dLon)
y := math.Cos(bLatRad) * math.Sin(dLon)
r := orb.Point{
deg2rad(p[0]) + math.Atan2(y, math.Cos(aLatRad)+x),
math.Atan2(math.Sin(aLatRad)+math.Sin(bLatRad), math.Sqrt((math.Cos(aLatRad)+x)*(math.Cos(aLatRad)+x)+y*y)),
}
// convert back to degrees
r[0] = rad2deg(r[0])
r[1] = rad2deg(r[1])
return r
} | [
"func",
"Midpoint",
"(",
"p",
",",
"p2",
"orb",
".",
"Point",
")",
"orb",
".",
"Point",
"{",
"dLon",
":=",
"deg2rad",
"(",
"p2",
"[",
"0",
"]",
"-",
"p",
"[",
"0",
"]",
")",
"\n\n",
"aLatRad",
":=",
"deg2rad",
"(",
"p",
"[",
"1",
"]",
")",
... | // Midpoint returns the half-way point along a great circle path between the two points. | [
"Midpoint",
"returns",
"the",
"half",
"-",
"way",
"point",
"along",
"a",
"great",
"circle",
"path",
"between",
"the",
"two",
"points",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/geo/distance.go#L52-L71 | train |
paulmach/orb | maptile/set.go | ToFeatureCollection | func (s Set) ToFeatureCollection() *geojson.FeatureCollection {
fc := geojson.NewFeatureCollection()
fc.Features = make([]*geojson.Feature, 0, len(s))
for t := range s {
fc.Append(geojson.NewFeature(t.Bound().ToPolygon()))
}
return fc
} | go | func (s Set) ToFeatureCollection() *geojson.FeatureCollection {
fc := geojson.NewFeatureCollection()
fc.Features = make([]*geojson.Feature, 0, len(s))
for t := range s {
fc.Append(geojson.NewFeature(t.Bound().ToPolygon()))
}
return fc
} | [
"func",
"(",
"s",
"Set",
")",
"ToFeatureCollection",
"(",
")",
"*",
"geojson",
".",
"FeatureCollection",
"{",
"fc",
":=",
"geojson",
".",
"NewFeatureCollection",
"(",
")",
"\n",
"fc",
".",
"Features",
"=",
"make",
"(",
"[",
"]",
"*",
"geojson",
".",
"F... | // ToFeatureCollection converts a set of tiles into a feature collection.
// This method is mostly useful for debugging output. | [
"ToFeatureCollection",
"converts",
"a",
"set",
"of",
"tiles",
"into",
"a",
"feature",
"collection",
".",
"This",
"method",
"is",
"mostly",
"useful",
"for",
"debugging",
"output",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/maptile/set.go#L12-L20 | train |
paulmach/orb | maptile/set.go | Merge | func (s Set) Merge(set Set) {
for t, v := range set {
if v {
s[t] = true
}
}
} | go | func (s Set) Merge(set Set) {
for t, v := range set {
if v {
s[t] = true
}
}
} | [
"func",
"(",
"s",
"Set",
")",
"Merge",
"(",
"set",
"Set",
")",
"{",
"for",
"t",
",",
"v",
":=",
"range",
"set",
"{",
"if",
"v",
"{",
"s",
"[",
"t",
"]",
"=",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // Merge will merge the given set into the existing set. | [
"Merge",
"will",
"merge",
"the",
"given",
"set",
"into",
"the",
"existing",
"set",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/maptile/set.go#L23-L29 | train |
paulmach/orb | maptile/tilecover/line_string.go | LineString | func LineString(ls orb.LineString, z maptile.Zoom) maptile.Set {
set := make(maptile.Set)
line(set, ls, z, nil)
return set
} | go | func LineString(ls orb.LineString, z maptile.Zoom) maptile.Set {
set := make(maptile.Set)
line(set, ls, z, nil)
return set
} | [
"func",
"LineString",
"(",
"ls",
"orb",
".",
"LineString",
",",
"z",
"maptile",
".",
"Zoom",
")",
"maptile",
".",
"Set",
"{",
"set",
":=",
"make",
"(",
"maptile",
".",
"Set",
")",
"\n",
"line",
"(",
"set",
",",
"ls",
",",
"z",
",",
"nil",
")",
... | // LineString creates a tile cover for the line string. | [
"LineString",
"creates",
"a",
"tile",
"cover",
"for",
"the",
"line",
"string",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/maptile/tilecover/line_string.go#L11-L16 | train |
paulmach/orb | maptile/tilecover/line_string.go | MultiLineString | func MultiLineString(mls orb.MultiLineString, z maptile.Zoom) maptile.Set {
set := make(maptile.Set)
for _, ls := range mls {
line(set, ls, z, nil)
}
return set
} | go | func MultiLineString(mls orb.MultiLineString, z maptile.Zoom) maptile.Set {
set := make(maptile.Set)
for _, ls := range mls {
line(set, ls, z, nil)
}
return set
} | [
"func",
"MultiLineString",
"(",
"mls",
"orb",
".",
"MultiLineString",
",",
"z",
"maptile",
".",
"Zoom",
")",
"maptile",
".",
"Set",
"{",
"set",
":=",
"make",
"(",
"maptile",
".",
"Set",
")",
"\n",
"for",
"_",
",",
"ls",
":=",
"range",
"mls",
"{",
"... | // MultiLineString creates a tile cover for the line strings. | [
"MultiLineString",
"creates",
"a",
"tile",
"cover",
"for",
"the",
"line",
"strings",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/maptile/tilecover/line_string.go#L19-L26 | train |
paulmach/orb | maptile/tile.go | ToFeatureCollection | func (ts Tiles) ToFeatureCollection() *geojson.FeatureCollection {
fc := geojson.NewFeatureCollection()
fc.Features = make([]*geojson.Feature, 0, len(ts))
for _, t := range ts {
fc.Append(geojson.NewFeature(t.Bound().ToPolygon()))
}
return fc
} | go | func (ts Tiles) ToFeatureCollection() *geojson.FeatureCollection {
fc := geojson.NewFeatureCollection()
fc.Features = make([]*geojson.Feature, 0, len(ts))
for _, t := range ts {
fc.Append(geojson.NewFeature(t.Bound().ToPolygon()))
}
return fc
} | [
"func",
"(",
"ts",
"Tiles",
")",
"ToFeatureCollection",
"(",
")",
"*",
"geojson",
".",
"FeatureCollection",
"{",
"fc",
":=",
"geojson",
".",
"NewFeatureCollection",
"(",
")",
"\n",
"fc",
".",
"Features",
"=",
"make",
"(",
"[",
"]",
"*",
"geojson",
".",
... | // ToFeatureCollection converts the tiles into a feature collection.
// This method is mostly useful for debugging output. | [
"ToFeatureCollection",
"converts",
"the",
"tiles",
"into",
"a",
"feature",
"collection",
".",
"This",
"method",
"is",
"mostly",
"useful",
"for",
"debugging",
"output",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/maptile/tile.go#L19-L27 | train |
paulmach/orb | maptile/tile.go | New | func New(x, y uint32, z Zoom) Tile {
return Tile{x, y, z}
} | go | func New(x, y uint32, z Zoom) Tile {
return Tile{x, y, z}
} | [
"func",
"New",
"(",
"x",
",",
"y",
"uint32",
",",
"z",
"Zoom",
")",
"Tile",
"{",
"return",
"Tile",
"{",
"x",
",",
"y",
",",
"z",
"}",
"\n",
"}"
] | // New creates a new tile with the given coordinates. | [
"New",
"creates",
"a",
"new",
"tile",
"with",
"the",
"given",
"coordinates",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/maptile/tile.go#L39-L41 | train |
paulmach/orb | maptile/tile.go | FromQuadkey | func FromQuadkey(k uint64, z Zoom) Tile {
t := Tile{Z: z}
for i := Zoom(0); i < z; i++ {
t.X |= uint32((k & (1 << (2 * i))) >> i)
t.Y |= uint32((k & (1 << (2*i + 1))) >> (i + 1))
}
return t
} | go | func FromQuadkey(k uint64, z Zoom) Tile {
t := Tile{Z: z}
for i := Zoom(0); i < z; i++ {
t.X |= uint32((k & (1 << (2 * i))) >> i)
t.Y |= uint32((k & (1 << (2*i + 1))) >> (i + 1))
}
return t
} | [
"func",
"FromQuadkey",
"(",
"k",
"uint64",
",",
"z",
"Zoom",
")",
"Tile",
"{",
"t",
":=",
"Tile",
"{",
"Z",
":",
"z",
"}",
"\n\n",
"for",
"i",
":=",
"Zoom",
"(",
"0",
")",
";",
"i",
"<",
"z",
";",
"i",
"++",
"{",
"t",
".",
"X",
"|=",
"uin... | // FromQuadkey creates the tile from the quadkey. | [
"FromQuadkey",
"creates",
"the",
"tile",
"from",
"the",
"quadkey",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/maptile/tile.go#L59-L68 | train |
paulmach/orb | maptile/tile.go | Parent | func (t Tile) Parent() Tile {
if t.Z == 0 {
return t
}
return Tile{
X: t.X >> 1,
Y: t.Y >> 1,
Z: t.Z - 1,
}
} | go | func (t Tile) Parent() Tile {
if t.Z == 0 {
return t
}
return Tile{
X: t.X >> 1,
Y: t.Y >> 1,
Z: t.Z - 1,
}
} | [
"func",
"(",
"t",
"Tile",
")",
"Parent",
"(",
")",
"Tile",
"{",
"if",
"t",
".",
"Z",
"==",
"0",
"{",
"return",
"t",
"\n",
"}",
"\n\n",
"return",
"Tile",
"{",
"X",
":",
"t",
".",
"X",
">>",
"1",
",",
"Y",
":",
"t",
".",
"Y",
">>",
"1",
"... | // Parent returns the parent of the tile. | [
"Parent",
"returns",
"the",
"parent",
"of",
"the",
"tile",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/maptile/tile.go#L129-L139 | train |
paulmach/orb | maptile/tile.go | Fraction | func Fraction(ll orb.Point, z Zoom) orb.Point {
var p orb.Point
factor := uint32(1 << z)
maxtiles := float64(factor)
lng := ll[0]/360.0 + 0.5
p[0] = lng * maxtiles
// bound it because we have a top of the world problem
if ll[1] < -85.0511 {
p[1] = maxtiles - 1
} else if ll[1] > 85.0511 {
p[1] = 0
} else {
siny := math.Sin(ll[1] * math.Pi / 180.0)
lat := 0.5 + 0.5*math.Log((1.0+siny)/(1.0-siny))/(-2*math.Pi)
p[1] = lat * maxtiles
}
return p
} | go | func Fraction(ll orb.Point, z Zoom) orb.Point {
var p orb.Point
factor := uint32(1 << z)
maxtiles := float64(factor)
lng := ll[0]/360.0 + 0.5
p[0] = lng * maxtiles
// bound it because we have a top of the world problem
if ll[1] < -85.0511 {
p[1] = maxtiles - 1
} else if ll[1] > 85.0511 {
p[1] = 0
} else {
siny := math.Sin(ll[1] * math.Pi / 180.0)
lat := 0.5 + 0.5*math.Log((1.0+siny)/(1.0-siny))/(-2*math.Pi)
p[1] = lat * maxtiles
}
return p
} | [
"func",
"Fraction",
"(",
"ll",
"orb",
".",
"Point",
",",
"z",
"Zoom",
")",
"orb",
".",
"Point",
"{",
"var",
"p",
"orb",
".",
"Point",
"\n\n",
"factor",
":=",
"uint32",
"(",
"1",
"<<",
"z",
")",
"\n",
"maxtiles",
":=",
"float64",
"(",
"factor",
")... | // Fraction returns the precise tile fraction at the given zoom.
// Will return 2^zoom-1 if the point is below 85.0511 S. | [
"Fraction",
"returns",
"the",
"precise",
"tile",
"fraction",
"at",
"the",
"given",
"zoom",
".",
"Will",
"return",
"2^zoom",
"-",
"1",
"if",
"the",
"point",
"is",
"below",
"85",
".",
"0511",
"S",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/maptile/tile.go#L143-L164 | train |
paulmach/orb | maptile/tile.go | SharedParent | func (t Tile) SharedParent(tile Tile) Tile {
// bring both tiles to the lowest zoom.
if t.Z != tile.Z {
if t.Z < tile.Z {
tile = tile.toZoom(t.Z)
} else {
t = t.toZoom(tile.Z)
}
}
if t == tile {
return t
}
// go version < 1.9
// bit package usage was about 10% faster
//
// TODO: use build flags to support older versions of go.
//
// move from most significant to least until there isn't a match.
// for i := t.Z - 1; i >= 0; i-- {
// if t.X&(1<<i) != tile.X&(1<<i) ||
// t.Y&(1<<i) != tile.Y&(1<<i) {
// return Tile{
// t.X >> (i + 1),
// t.Y >> (i + 1),
// t.Z - (i + 1),
// }
// }
// }
//
// if we reach here the tiles are the same, which was checked above.
// panic("unreachable")
// bits different for x and y
xc := uint32(32 - bits.LeadingZeros32(t.X^tile.X))
yc := uint32(32 - bits.LeadingZeros32(t.Y^tile.Y))
// max of xc, yc
maxc := xc
if yc > maxc {
maxc = yc
}
return Tile{
X: t.X >> maxc,
Y: t.Y >> maxc,
Z: t.Z - Zoom(maxc),
}
} | go | func (t Tile) SharedParent(tile Tile) Tile {
// bring both tiles to the lowest zoom.
if t.Z != tile.Z {
if t.Z < tile.Z {
tile = tile.toZoom(t.Z)
} else {
t = t.toZoom(tile.Z)
}
}
if t == tile {
return t
}
// go version < 1.9
// bit package usage was about 10% faster
//
// TODO: use build flags to support older versions of go.
//
// move from most significant to least until there isn't a match.
// for i := t.Z - 1; i >= 0; i-- {
// if t.X&(1<<i) != tile.X&(1<<i) ||
// t.Y&(1<<i) != tile.Y&(1<<i) {
// return Tile{
// t.X >> (i + 1),
// t.Y >> (i + 1),
// t.Z - (i + 1),
// }
// }
// }
//
// if we reach here the tiles are the same, which was checked above.
// panic("unreachable")
// bits different for x and y
xc := uint32(32 - bits.LeadingZeros32(t.X^tile.X))
yc := uint32(32 - bits.LeadingZeros32(t.Y^tile.Y))
// max of xc, yc
maxc := xc
if yc > maxc {
maxc = yc
}
return Tile{
X: t.X >> maxc,
Y: t.Y >> maxc,
Z: t.Z - Zoom(maxc),
}
} | [
"func",
"(",
"t",
"Tile",
")",
"SharedParent",
"(",
"tile",
"Tile",
")",
"Tile",
"{",
"// bring both tiles to the lowest zoom.",
"if",
"t",
".",
"Z",
"!=",
"tile",
".",
"Z",
"{",
"if",
"t",
".",
"Z",
"<",
"tile",
".",
"Z",
"{",
"tile",
"=",
"tile",
... | // SharedParent returns the tile that contains both the tiles. | [
"SharedParent",
"returns",
"the",
"tile",
"that",
"contains",
"both",
"the",
"tiles",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/maptile/tile.go#L167-L217 | train |
paulmach/orb | maptile/tile.go | Children | func (t Tile) Children() Tiles {
return Tiles{
Tile{t.X << 1, t.Y << 1, t.Z + 1},
Tile{(t.X << 1) + 1, t.Y << 1, t.Z + 1},
Tile{(t.X << 1) + 1, (t.Y << 1) + 1, t.Z + 1},
Tile{t.X << 1, (t.Y << 1) + 1, t.Z + 1},
}
} | go | func (t Tile) Children() Tiles {
return Tiles{
Tile{t.X << 1, t.Y << 1, t.Z + 1},
Tile{(t.X << 1) + 1, t.Y << 1, t.Z + 1},
Tile{(t.X << 1) + 1, (t.Y << 1) + 1, t.Z + 1},
Tile{t.X << 1, (t.Y << 1) + 1, t.Z + 1},
}
} | [
"func",
"(",
"t",
"Tile",
")",
"Children",
"(",
")",
"Tiles",
"{",
"return",
"Tiles",
"{",
"Tile",
"{",
"t",
".",
"X",
"<<",
"1",
",",
"t",
".",
"Y",
"<<",
"1",
",",
"t",
".",
"Z",
"+",
"1",
"}",
",",
"Tile",
"{",
"(",
"t",
".",
"X",
"<... | // Children returns the 4 children of the tile. | [
"Children",
"returns",
"the",
"4",
"children",
"of",
"the",
"tile",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/maptile/tile.go#L220-L227 | train |
paulmach/orb | maptile/tile.go | Quadkey | func (t Tile) Quadkey() uint64 {
var i, result uint64
for i = 0; i < uint64(t.Z); i++ {
result |= (uint64(t.X) & (1 << i)) << i
result |= (uint64(t.Y) & (1 << i)) << (i + 1)
}
return result
} | go | func (t Tile) Quadkey() uint64 {
var i, result uint64
for i = 0; i < uint64(t.Z); i++ {
result |= (uint64(t.X) & (1 << i)) << i
result |= (uint64(t.Y) & (1 << i)) << (i + 1)
}
return result
} | [
"func",
"(",
"t",
"Tile",
")",
"Quadkey",
"(",
")",
"uint64",
"{",
"var",
"i",
",",
"result",
"uint64",
"\n",
"for",
"i",
"=",
"0",
";",
"i",
"<",
"uint64",
"(",
"t",
".",
"Z",
")",
";",
"i",
"++",
"{",
"result",
"|=",
"(",
"uint64",
"(",
"... | // Quadkey returns the quad key for the tile. | [
"Quadkey",
"returns",
"the",
"quad",
"key",
"for",
"the",
"tile",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/maptile/tile.go#L235-L243 | train |
paulmach/orb | maptile/tile.go | Range | func (t Tile) Range(z Zoom) (min, max Tile) {
if z < t.Z {
t = t.toZoom(z)
return t, t
}
offset := z - t.Z
return Tile{
X: t.X << offset,
Y: t.Y << offset,
Z: z,
}, Tile{
X: ((t.X + 1) << offset) - 1,
Y: ((t.Y + 1) << offset) - 1,
Z: z,
}
} | go | func (t Tile) Range(z Zoom) (min, max Tile) {
if z < t.Z {
t = t.toZoom(z)
return t, t
}
offset := z - t.Z
return Tile{
X: t.X << offset,
Y: t.Y << offset,
Z: z,
}, Tile{
X: ((t.X + 1) << offset) - 1,
Y: ((t.Y + 1) << offset) - 1,
Z: z,
}
} | [
"func",
"(",
"t",
"Tile",
")",
"Range",
"(",
"z",
"Zoom",
")",
"(",
"min",
",",
"max",
"Tile",
")",
"{",
"if",
"z",
"<",
"t",
".",
"Z",
"{",
"t",
"=",
"t",
".",
"toZoom",
"(",
"z",
")",
"\n",
"return",
"t",
",",
"t",
"\n",
"}",
"\n\n",
... | // Range returns the min and max tile "range" to cover the tile
// at the given zoom. | [
"Range",
"returns",
"the",
"min",
"and",
"max",
"tile",
"range",
"to",
"cover",
"the",
"tile",
"at",
"the",
"given",
"zoom",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/maptile/tile.go#L247-L263 | train |
paulmach/orb | geo/area.go | Area | func Area(g orb.Geometry) float64 {
if g == nil {
return 0
}
switch g := g.(type) {
case orb.Point, orb.MultiPoint, orb.LineString, orb.MultiLineString:
return 0
case orb.Ring:
return math.Abs(ringArea(g))
case orb.Polygon:
return polygonArea(g)
case orb.MultiPolygon:
return multiPolygonArea(g)
case orb.Collection:
return collectionArea(g)
case orb.Bound:
return Area(g.ToRing())
}
panic(fmt.Sprintf("geometry type not supported: %T", g))
} | go | func Area(g orb.Geometry) float64 {
if g == nil {
return 0
}
switch g := g.(type) {
case orb.Point, orb.MultiPoint, orb.LineString, orb.MultiLineString:
return 0
case orb.Ring:
return math.Abs(ringArea(g))
case orb.Polygon:
return polygonArea(g)
case orb.MultiPolygon:
return multiPolygonArea(g)
case orb.Collection:
return collectionArea(g)
case orb.Bound:
return Area(g.ToRing())
}
panic(fmt.Sprintf("geometry type not supported: %T", g))
} | [
"func",
"Area",
"(",
"g",
"orb",
".",
"Geometry",
")",
"float64",
"{",
"if",
"g",
"==",
"nil",
"{",
"return",
"0",
"\n",
"}",
"\n\n",
"switch",
"g",
":=",
"g",
".",
"(",
"type",
")",
"{",
"case",
"orb",
".",
"Point",
",",
"orb",
".",
"MultiPoin... | // Area returns the area of the geometry on the earth. | [
"Area",
"returns",
"the",
"area",
"of",
"the",
"geometry",
"on",
"the",
"earth",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/geo/area.go#L12-L33 | train |
paulmach/orb | geojson/feature.go | UnmarshalJSON | func (f *Feature) UnmarshalJSON(data []byte) error {
jf := &jsonFeature{}
err := json.Unmarshal(data, &jf)
if err != nil {
return err
}
if jf.Type != "Feature" {
return fmt.Errorf("geojson: not a feature: type=%s", jf.Type)
}
*f = Feature{
ID: jf.ID,
Type: jf.Type,
Properties: jf.Properties,
BBox: jf.BBox,
Geometry: jf.Geometry.Coordinates,
}
return nil
} | go | func (f *Feature) UnmarshalJSON(data []byte) error {
jf := &jsonFeature{}
err := json.Unmarshal(data, &jf)
if err != nil {
return err
}
if jf.Type != "Feature" {
return fmt.Errorf("geojson: not a feature: type=%s", jf.Type)
}
*f = Feature{
ID: jf.ID,
Type: jf.Type,
Properties: jf.Properties,
BBox: jf.BBox,
Geometry: jf.Geometry.Coordinates,
}
return nil
} | [
"func",
"(",
"f",
"*",
"Feature",
")",
"UnmarshalJSON",
"(",
"data",
"[",
"]",
"byte",
")",
"error",
"{",
"jf",
":=",
"&",
"jsonFeature",
"{",
"}",
"\n",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"data",
",",
"&",
"jf",
")",
"\n",
"if",
"err",
... | // UnmarshalJSON handles the correct unmarshalling of the data
// into the orb.Geometry types. | [
"UnmarshalJSON",
"handles",
"the",
"correct",
"unmarshalling",
"of",
"the",
"data",
"into",
"the",
"orb",
".",
"Geometry",
"types",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/geojson/feature.go#L70-L90 | train |
paulmach/orb | maptile/tilecover/helpers.go | Geometry | func Geometry(g orb.Geometry, z maptile.Zoom) maptile.Set {
if g == nil {
return nil
}
switch g := g.(type) {
case orb.Point:
return Point(g, z)
case orb.MultiPoint:
return MultiPoint(g, z)
case orb.LineString:
return LineString(g, z)
case orb.MultiLineString:
return MultiLineString(g, z)
case orb.Ring:
return Ring(g, z)
case orb.Polygon:
return Polygon(g, z)
case orb.MultiPolygon:
return MultiPolygon(g, z)
case orb.Collection:
return Collection(g, z)
case orb.Bound:
return Bound(g, z)
}
panic(fmt.Sprintf("geometry type not supported: %T", g))
} | go | func Geometry(g orb.Geometry, z maptile.Zoom) maptile.Set {
if g == nil {
return nil
}
switch g := g.(type) {
case orb.Point:
return Point(g, z)
case orb.MultiPoint:
return MultiPoint(g, z)
case orb.LineString:
return LineString(g, z)
case orb.MultiLineString:
return MultiLineString(g, z)
case orb.Ring:
return Ring(g, z)
case orb.Polygon:
return Polygon(g, z)
case orb.MultiPolygon:
return MultiPolygon(g, z)
case orb.Collection:
return Collection(g, z)
case orb.Bound:
return Bound(g, z)
}
panic(fmt.Sprintf("geometry type not supported: %T", g))
} | [
"func",
"Geometry",
"(",
"g",
"orb",
".",
"Geometry",
",",
"z",
"maptile",
".",
"Zoom",
")",
"maptile",
".",
"Set",
"{",
"if",
"g",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"switch",
"g",
":=",
"g",
".",
"(",
"type",
")",
"{",
"cas... | // Geometry returns the covering set of tiles for the given geometry. | [
"Geometry",
"returns",
"the",
"covering",
"set",
"of",
"tiles",
"for",
"the",
"given",
"geometry",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/maptile/tilecover/helpers.go#L12-L39 | train |
paulmach/orb | maptile/tilecover/helpers.go | Point | func Point(ll orb.Point, z maptile.Zoom) maptile.Set {
return maptile.Set{
maptile.At(ll, z): true,
}
} | go | func Point(ll orb.Point, z maptile.Zoom) maptile.Set {
return maptile.Set{
maptile.At(ll, z): true,
}
} | [
"func",
"Point",
"(",
"ll",
"orb",
".",
"Point",
",",
"z",
"maptile",
".",
"Zoom",
")",
"maptile",
".",
"Set",
"{",
"return",
"maptile",
".",
"Set",
"{",
"maptile",
".",
"At",
"(",
"ll",
",",
"z",
")",
":",
"true",
",",
"}",
"\n",
"}"
] | // Point creates a tile cover for the point, i.e. just the tile
// containing the point. | [
"Point",
"creates",
"a",
"tile",
"cover",
"for",
"the",
"point",
"i",
".",
"e",
".",
"just",
"the",
"tile",
"containing",
"the",
"point",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/maptile/tilecover/helpers.go#L43-L47 | train |
paulmach/orb | maptile/tilecover/helpers.go | MultiPoint | func MultiPoint(mp orb.MultiPoint, z maptile.Zoom) maptile.Set {
set := make(maptile.Set)
for _, p := range mp {
set[maptile.At(p, z)] = true
}
return set
} | go | func MultiPoint(mp orb.MultiPoint, z maptile.Zoom) maptile.Set {
set := make(maptile.Set)
for _, p := range mp {
set[maptile.At(p, z)] = true
}
return set
} | [
"func",
"MultiPoint",
"(",
"mp",
"orb",
".",
"MultiPoint",
",",
"z",
"maptile",
".",
"Zoom",
")",
"maptile",
".",
"Set",
"{",
"set",
":=",
"make",
"(",
"maptile",
".",
"Set",
")",
"\n",
"for",
"_",
",",
"p",
":=",
"range",
"mp",
"{",
"set",
"[",
... | // MultiPoint creates a tile cover for the set of points, | [
"MultiPoint",
"creates",
"a",
"tile",
"cover",
"for",
"the",
"set",
"of",
"points"
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/maptile/tilecover/helpers.go#L50-L57 | train |
paulmach/orb | maptile/tilecover/helpers.go | Bound | func Bound(b orb.Bound, z maptile.Zoom) maptile.Set {
lo := maptile.At(b.Min, z)
hi := maptile.At(b.Max, z)
result := make(maptile.Set, (hi.X-lo.X+1)*(lo.Y-hi.Y+1))
for x := lo.X; x <= hi.X; x++ {
for y := hi.Y; y <= lo.Y; y++ {
result[maptile.Tile{X: x, Y: y, Z: z}] = true
}
}
return result
} | go | func Bound(b orb.Bound, z maptile.Zoom) maptile.Set {
lo := maptile.At(b.Min, z)
hi := maptile.At(b.Max, z)
result := make(maptile.Set, (hi.X-lo.X+1)*(lo.Y-hi.Y+1))
for x := lo.X; x <= hi.X; x++ {
for y := hi.Y; y <= lo.Y; y++ {
result[maptile.Tile{X: x, Y: y, Z: z}] = true
}
}
return result
} | [
"func",
"Bound",
"(",
"b",
"orb",
".",
"Bound",
",",
"z",
"maptile",
".",
"Zoom",
")",
"maptile",
".",
"Set",
"{",
"lo",
":=",
"maptile",
".",
"At",
"(",
"b",
".",
"Min",
",",
"z",
")",
"\n",
"hi",
":=",
"maptile",
".",
"At",
"(",
"b",
".",
... | // Bound creates a tile cover for the bound. i.e. all the tiles
// that intersect the bound. | [
"Bound",
"creates",
"a",
"tile",
"cover",
"for",
"the",
"bound",
".",
"i",
".",
"e",
".",
"all",
"the",
"tiles",
"that",
"intersect",
"the",
"bound",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/maptile/tilecover/helpers.go#L61-L74 | train |
paulmach/orb | maptile/tilecover/helpers.go | Collection | func Collection(c orb.Collection, z maptile.Zoom) maptile.Set {
set := make(maptile.Set)
for _, g := range c {
set.Merge(Geometry(g, z))
}
return set
} | go | func Collection(c orb.Collection, z maptile.Zoom) maptile.Set {
set := make(maptile.Set)
for _, g := range c {
set.Merge(Geometry(g, z))
}
return set
} | [
"func",
"Collection",
"(",
"c",
"orb",
".",
"Collection",
",",
"z",
"maptile",
".",
"Zoom",
")",
"maptile",
".",
"Set",
"{",
"set",
":=",
"make",
"(",
"maptile",
".",
"Set",
")",
"\n",
"for",
"_",
",",
"g",
":=",
"range",
"c",
"{",
"set",
".",
... | // Collection returns the covering set of tiles for the
// geoemtry collection. | [
"Collection",
"returns",
"the",
"covering",
"set",
"of",
"tiles",
"for",
"the",
"geoemtry",
"collection",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/maptile/tilecover/helpers.go#L78-L85 | train |
paulmach/orb | polygon.go | Equal | func (p Polygon) Equal(polygon Polygon) bool {
if len(p) != len(polygon) {
return false
}
for i := range p {
if !p[i].Equal(polygon[i]) {
return false
}
}
return true
} | go | func (p Polygon) Equal(polygon Polygon) bool {
if len(p) != len(polygon) {
return false
}
for i := range p {
if !p[i].Equal(polygon[i]) {
return false
}
}
return true
} | [
"func",
"(",
"p",
"Polygon",
")",
"Equal",
"(",
"polygon",
"Polygon",
")",
"bool",
"{",
"if",
"len",
"(",
"p",
")",
"!=",
"len",
"(",
"polygon",
")",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"for",
"i",
":=",
"range",
"p",
"{",
"if",
"!",
"p"... | // Equal compares two polygons. Returns true if lengths are the same
// and all points are Equal. | [
"Equal",
"compares",
"two",
"polygons",
".",
"Returns",
"true",
"if",
"lengths",
"are",
"the",
"same",
"and",
"all",
"points",
"are",
"Equal",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/polygon.go#L28-L40 | train |
paulmach/orb | polygon.go | Clone | func (p Polygon) Clone() Polygon {
if p == nil {
return p
}
np := make(Polygon, 0, len(p))
for _, r := range p {
np = append(np, r.Clone())
}
return np
} | go | func (p Polygon) Clone() Polygon {
if p == nil {
return p
}
np := make(Polygon, 0, len(p))
for _, r := range p {
np = append(np, r.Clone())
}
return np
} | [
"func",
"(",
"p",
"Polygon",
")",
"Clone",
"(",
")",
"Polygon",
"{",
"if",
"p",
"==",
"nil",
"{",
"return",
"p",
"\n",
"}",
"\n\n",
"np",
":=",
"make",
"(",
"Polygon",
",",
"0",
",",
"len",
"(",
"p",
")",
")",
"\n",
"for",
"_",
",",
"r",
":... | // Clone returns a new deep copy of the polygon.
// All of the rings are also cloned. | [
"Clone",
"returns",
"a",
"new",
"deep",
"copy",
"of",
"the",
"polygon",
".",
"All",
"of",
"the",
"rings",
"are",
"also",
"cloned",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/polygon.go#L44-L55 | train |
paulmach/orb | multi_polygon.go | Bound | func (mp MultiPolygon) Bound() Bound {
if len(mp) == 0 {
return emptyBound
}
bound := mp[0].Bound()
for i := 1; i < len(mp); i++ {
bound = bound.Union(mp[i].Bound())
}
return bound
} | go | func (mp MultiPolygon) Bound() Bound {
if len(mp) == 0 {
return emptyBound
}
bound := mp[0].Bound()
for i := 1; i < len(mp); i++ {
bound = bound.Union(mp[i].Bound())
}
return bound
} | [
"func",
"(",
"mp",
"MultiPolygon",
")",
"Bound",
"(",
")",
"Bound",
"{",
"if",
"len",
"(",
"mp",
")",
"==",
"0",
"{",
"return",
"emptyBound",
"\n",
"}",
"\n",
"bound",
":=",
"mp",
"[",
"0",
"]",
".",
"Bound",
"(",
")",
"\n",
"for",
"i",
":=",
... | // Bound returns a bound around the multi-polygon. | [
"Bound",
"returns",
"a",
"bound",
"around",
"the",
"multi",
"-",
"polygon",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/multi_polygon.go#L17-L27 | train |
paulmach/orb | multi_polygon.go | Equal | func (mp MultiPolygon) Equal(multiPolygon MultiPolygon) bool {
if len(mp) != len(multiPolygon) {
return false
}
for i, p := range mp {
if !p.Equal(multiPolygon[i]) {
return false
}
}
return true
} | go | func (mp MultiPolygon) Equal(multiPolygon MultiPolygon) bool {
if len(mp) != len(multiPolygon) {
return false
}
for i, p := range mp {
if !p.Equal(multiPolygon[i]) {
return false
}
}
return true
} | [
"func",
"(",
"mp",
"MultiPolygon",
")",
"Equal",
"(",
"multiPolygon",
"MultiPolygon",
")",
"bool",
"{",
"if",
"len",
"(",
"mp",
")",
"!=",
"len",
"(",
"multiPolygon",
")",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"for",
"i",
",",
"p",
":=",
"range"... | // Equal compares two multi-polygons. | [
"Equal",
"compares",
"two",
"multi",
"-",
"polygons",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/multi_polygon.go#L30-L42 | train |
paulmach/orb | multi_polygon.go | Clone | func (mp MultiPolygon) Clone() MultiPolygon {
if mp == nil {
return nil
}
nmp := make(MultiPolygon, 0, len(mp))
for _, p := range mp {
nmp = append(nmp, p.Clone())
}
return nmp
} | go | func (mp MultiPolygon) Clone() MultiPolygon {
if mp == nil {
return nil
}
nmp := make(MultiPolygon, 0, len(mp))
for _, p := range mp {
nmp = append(nmp, p.Clone())
}
return nmp
} | [
"func",
"(",
"mp",
"MultiPolygon",
")",
"Clone",
"(",
")",
"MultiPolygon",
"{",
"if",
"mp",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"nmp",
":=",
"make",
"(",
"MultiPolygon",
",",
"0",
",",
"len",
"(",
"mp",
")",
")",
"\n",
"for",
"_... | // Clone returns a new deep copy of the multi-polygon. | [
"Clone",
"returns",
"a",
"new",
"deep",
"copy",
"of",
"the",
"multi",
"-",
"polygon",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/multi_polygon.go#L45-L56 | train |
paulmach/orb | internal/length/length.go | Length | func Length(g orb.Geometry, df orb.DistanceFunc) float64 {
if g == nil {
return 0
}
switch g := g.(type) {
case orb.Point:
return 0
case orb.MultiPoint:
return 0
case orb.LineString:
return lineStringLength(g, df)
case orb.MultiLineString:
sum := 0.0
for _, ls := range g {
sum += lineStringLength(ls, df)
}
return sum
case orb.Ring:
return lineStringLength(orb.LineString(g), df)
case orb.Polygon:
return polygonLength(g, df)
case orb.MultiPolygon:
sum := 0.0
for _, p := range g {
sum += polygonLength(p, df)
}
return sum
case orb.Collection:
sum := 0.0
for _, c := range g {
sum += Length(c, df)
}
return sum
case orb.Bound:
return Length(g.ToRing(), df)
}
panic(fmt.Sprintf("geometry type not supported: %T", g))
} | go | func Length(g orb.Geometry, df orb.DistanceFunc) float64 {
if g == nil {
return 0
}
switch g := g.(type) {
case orb.Point:
return 0
case orb.MultiPoint:
return 0
case orb.LineString:
return lineStringLength(g, df)
case orb.MultiLineString:
sum := 0.0
for _, ls := range g {
sum += lineStringLength(ls, df)
}
return sum
case orb.Ring:
return lineStringLength(orb.LineString(g), df)
case orb.Polygon:
return polygonLength(g, df)
case orb.MultiPolygon:
sum := 0.0
for _, p := range g {
sum += polygonLength(p, df)
}
return sum
case orb.Collection:
sum := 0.0
for _, c := range g {
sum += Length(c, df)
}
return sum
case orb.Bound:
return Length(g.ToRing(), df)
}
panic(fmt.Sprintf("geometry type not supported: %T", g))
} | [
"func",
"Length",
"(",
"g",
"orb",
".",
"Geometry",
",",
"df",
"orb",
".",
"DistanceFunc",
")",
"float64",
"{",
"if",
"g",
"==",
"nil",
"{",
"return",
"0",
"\n",
"}",
"\n\n",
"switch",
"g",
":=",
"g",
".",
"(",
"type",
")",
"{",
"case",
"orb",
... | // Length returns the length of the boundary of the geometry
// using 2d euclidean geometry. | [
"Length",
"returns",
"the",
"length",
"of",
"the",
"boundary",
"of",
"the",
"geometry",
"using",
"2d",
"euclidean",
"geometry",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/internal/length/length.go#L11-L53 | train |
paulmach/orb | encoding/mvt/layer.go | NewLayer | func NewLayer(name string, fc *geojson.FeatureCollection) *Layer {
return &Layer{
Name: name,
Version: 1,
Extent: DefaultExtent,
Features: fc.Features,
}
} | go | func NewLayer(name string, fc *geojson.FeatureCollection) *Layer {
return &Layer{
Name: name,
Version: 1,
Extent: DefaultExtent,
Features: fc.Features,
}
} | [
"func",
"NewLayer",
"(",
"name",
"string",
",",
"fc",
"*",
"geojson",
".",
"FeatureCollection",
")",
"*",
"Layer",
"{",
"return",
"&",
"Layer",
"{",
"Name",
":",
"name",
",",
"Version",
":",
"1",
",",
"Extent",
":",
"DefaultExtent",
",",
"Features",
":... | // NewLayer is a helper to create a Layer from a feature collection
// and a name, it sets the default extent and version to 1. | [
"NewLayer",
"is",
"a",
"helper",
"to",
"create",
"a",
"Layer",
"from",
"a",
"feature",
"collection",
"and",
"a",
"name",
"it",
"sets",
"the",
"default",
"extent",
"and",
"version",
"to",
"1",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/encoding/mvt/layer.go#L24-L31 | train |
paulmach/orb | encoding/mvt/layer.go | ProjectToTile | func (l *Layer) ProjectToTile(tile maptile.Tile) {
p := newProjection(tile, l.Extent)
for _, f := range l.Features {
f.Geometry = project.Geometry(f.Geometry, p.ToTile)
}
} | go | func (l *Layer) ProjectToTile(tile maptile.Tile) {
p := newProjection(tile, l.Extent)
for _, f := range l.Features {
f.Geometry = project.Geometry(f.Geometry, p.ToTile)
}
} | [
"func",
"(",
"l",
"*",
"Layer",
")",
"ProjectToTile",
"(",
"tile",
"maptile",
".",
"Tile",
")",
"{",
"p",
":=",
"newProjection",
"(",
"tile",
",",
"l",
".",
"Extent",
")",
"\n",
"for",
"_",
",",
"f",
":=",
"range",
"l",
".",
"Features",
"{",
"f",... | // ProjectToTile will project all the geometries in the layer
// to tile coordinates based on the extent and the mercator projection. | [
"ProjectToTile",
"will",
"project",
"all",
"the",
"geometries",
"in",
"the",
"layer",
"to",
"tile",
"coordinates",
"based",
"on",
"the",
"extent",
"and",
"the",
"mercator",
"projection",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/encoding/mvt/layer.go#L35-L40 | train |
paulmach/orb | encoding/mvt/layer.go | ProjectToWGS84 | func (l *Layer) ProjectToWGS84(tile maptile.Tile) {
p := newProjection(tile, l.Extent)
for _, f := range l.Features {
f.Geometry = project.Geometry(f.Geometry, p.ToWGS84)
}
} | go | func (l *Layer) ProjectToWGS84(tile maptile.Tile) {
p := newProjection(tile, l.Extent)
for _, f := range l.Features {
f.Geometry = project.Geometry(f.Geometry, p.ToWGS84)
}
} | [
"func",
"(",
"l",
"*",
"Layer",
")",
"ProjectToWGS84",
"(",
"tile",
"maptile",
".",
"Tile",
")",
"{",
"p",
":=",
"newProjection",
"(",
"tile",
",",
"l",
".",
"Extent",
")",
"\n",
"for",
"_",
",",
"f",
":=",
"range",
"l",
".",
"Features",
"{",
"f"... | // ProjectToWGS84 will project all the geometries backed to WGS84 from
// the extent and mercator projection. | [
"ProjectToWGS84",
"will",
"project",
"all",
"the",
"geometries",
"backed",
"to",
"WGS84",
"from",
"the",
"extent",
"and",
"mercator",
"projection",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/encoding/mvt/layer.go#L44-L49 | train |
paulmach/orb | encoding/mvt/layer.go | NewLayers | func NewLayers(layers map[string]*geojson.FeatureCollection) Layers {
result := make(Layers, 0, len(layers))
for name, fc := range layers {
result = append(result, NewLayer(name, fc))
}
return result
} | go | func NewLayers(layers map[string]*geojson.FeatureCollection) Layers {
result := make(Layers, 0, len(layers))
for name, fc := range layers {
result = append(result, NewLayer(name, fc))
}
return result
} | [
"func",
"NewLayers",
"(",
"layers",
"map",
"[",
"string",
"]",
"*",
"geojson",
".",
"FeatureCollection",
")",
"Layers",
"{",
"result",
":=",
"make",
"(",
"Layers",
",",
"0",
",",
"len",
"(",
"layers",
")",
")",
"\n",
"for",
"name",
",",
"fc",
":=",
... | // NewLayers creates a set of layers given a set of feature collections. | [
"NewLayers",
"creates",
"a",
"set",
"of",
"layers",
"given",
"a",
"set",
"of",
"feature",
"collections",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/encoding/mvt/layer.go#L55-L62 | train |
paulmach/orb | encoding/mvt/layer.go | ToFeatureCollections | func (ls Layers) ToFeatureCollections() map[string]*geojson.FeatureCollection {
result := make(map[string]*geojson.FeatureCollection, len(ls))
for _, l := range ls {
result[l.Name] = &geojson.FeatureCollection{
Features: l.Features,
}
}
return result
} | go | func (ls Layers) ToFeatureCollections() map[string]*geojson.FeatureCollection {
result := make(map[string]*geojson.FeatureCollection, len(ls))
for _, l := range ls {
result[l.Name] = &geojson.FeatureCollection{
Features: l.Features,
}
}
return result
} | [
"func",
"(",
"ls",
"Layers",
")",
"ToFeatureCollections",
"(",
")",
"map",
"[",
"string",
"]",
"*",
"geojson",
".",
"FeatureCollection",
"{",
"result",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"geojson",
".",
"FeatureCollection",
",",
"len",
"(... | // ToFeatureCollections converts the layers to sets of geojson
// feature collections. | [
"ToFeatureCollections",
"converts",
"the",
"layers",
"to",
"sets",
"of",
"geojson",
"feature",
"collections",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/encoding/mvt/layer.go#L66-L75 | train |
paulmach/orb | encoding/mvt/layer.go | ProjectToTile | func (ls Layers) ProjectToTile(tile maptile.Tile) {
for _, l := range ls {
l.ProjectToTile(tile)
}
} | go | func (ls Layers) ProjectToTile(tile maptile.Tile) {
for _, l := range ls {
l.ProjectToTile(tile)
}
} | [
"func",
"(",
"ls",
"Layers",
")",
"ProjectToTile",
"(",
"tile",
"maptile",
".",
"Tile",
")",
"{",
"for",
"_",
",",
"l",
":=",
"range",
"ls",
"{",
"l",
".",
"ProjectToTile",
"(",
"tile",
")",
"\n",
"}",
"\n",
"}"
] | // ProjectToTile will project all the geometries in all layers
// to tile coordinates based on the extent and the mercator projection. | [
"ProjectToTile",
"will",
"project",
"all",
"the",
"geometries",
"in",
"all",
"layers",
"to",
"tile",
"coordinates",
"based",
"on",
"the",
"extent",
"and",
"the",
"mercator",
"projection",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/encoding/mvt/layer.go#L79-L83 | train |
paulmach/orb | encoding/mvt/layer.go | ProjectToWGS84 | func (ls Layers) ProjectToWGS84(tile maptile.Tile) {
for _, l := range ls {
l.ProjectToWGS84(tile)
}
} | go | func (ls Layers) ProjectToWGS84(tile maptile.Tile) {
for _, l := range ls {
l.ProjectToWGS84(tile)
}
} | [
"func",
"(",
"ls",
"Layers",
")",
"ProjectToWGS84",
"(",
"tile",
"maptile",
".",
"Tile",
")",
"{",
"for",
"_",
",",
"l",
":=",
"range",
"ls",
"{",
"l",
".",
"ProjectToWGS84",
"(",
"tile",
")",
"\n",
"}",
"\n",
"}"
] | // ProjectToWGS84 will project all the geometries in all the layers backed
// to WGS84 from the extent and mercator projection. | [
"ProjectToWGS84",
"will",
"project",
"all",
"the",
"geometries",
"in",
"all",
"the",
"layers",
"backed",
"to",
"WGS84",
"from",
"the",
"extent",
"and",
"mercator",
"projection",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/encoding/mvt/layer.go#L87-L91 | train |
libgit2/git2go | config.go | NewConfig | func NewConfig() (*Config, error) {
config := new(Config)
runtime.LockOSThread()
defer runtime.UnlockOSThread()
if ret := C.git_config_new(&config.ptr); ret < 0 {
return nil, MakeGitError(ret)
}
return config, nil
} | go | func NewConfig() (*Config, error) {
config := new(Config)
runtime.LockOSThread()
defer runtime.UnlockOSThread()
if ret := C.git_config_new(&config.ptr); ret < 0 {
return nil, MakeGitError(ret)
}
return config, nil
} | [
"func",
"NewConfig",
"(",
")",
"(",
"*",
"Config",
",",
"error",
")",
"{",
"config",
":=",
"new",
"(",
"Config",
")",
"\n\n",
"runtime",
".",
"LockOSThread",
"(",
")",
"\n",
"defer",
"runtime",
".",
"UnlockOSThread",
"(",
")",
"\n\n",
"if",
"ret",
":... | // NewConfig creates a new empty configuration object | [
"NewConfig",
"creates",
"a",
"new",
"empty",
"configuration",
"object"
] | bf1e8a4338822ad2539a3876f58b15b590eb9e1f | https://github.com/libgit2/git2go/blob/bf1e8a4338822ad2539a3876f58b15b590eb9e1f/config.go#L59-L70 | train |
libgit2/git2go | config.go | AddFile | func (c *Config) AddFile(path string, level ConfigLevel, force bool) error {
cpath := C.CString(path)
defer C.free(unsafe.Pointer(cpath))
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ret := C.git_config_add_file_ondisk(c.ptr, cpath, C.git_config_level_t(level), nil, cbool(force))
runtime.KeepAlive(c)
if ret < 0 {
return MakeGitError(ret)
}
return nil
} | go | func (c *Config) AddFile(path string, level ConfigLevel, force bool) error {
cpath := C.CString(path)
defer C.free(unsafe.Pointer(cpath))
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ret := C.git_config_add_file_ondisk(c.ptr, cpath, C.git_config_level_t(level), nil, cbool(force))
runtime.KeepAlive(c)
if ret < 0 {
return MakeGitError(ret)
}
return nil
} | [
"func",
"(",
"c",
"*",
"Config",
")",
"AddFile",
"(",
"path",
"string",
",",
"level",
"ConfigLevel",
",",
"force",
"bool",
")",
"error",
"{",
"cpath",
":=",
"C",
".",
"CString",
"(",
"path",
")",
"\n",
"defer",
"C",
".",
"free",
"(",
"unsafe",
".",... | // AddFile adds a file-backed backend to the config object at the specified level. | [
"AddFile",
"adds",
"a",
"file",
"-",
"backed",
"backend",
"to",
"the",
"config",
"object",
"at",
"the",
"specified",
"level",
"."
] | bf1e8a4338822ad2539a3876f58b15b590eb9e1f | https://github.com/libgit2/git2go/blob/bf1e8a4338822ad2539a3876f58b15b590eb9e1f/config.go#L73-L87 | train |
libgit2/git2go | config.go | NewIterator | func (c *Config) NewIterator() (*ConfigIterator, error) {
iter := &ConfigIterator{cfg: c}
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ret := C.git_config_iterator_new(&iter.ptr, c.ptr)
if ret < 0 {
return nil, MakeGitError(ret)
}
return iter, nil
} | go | func (c *Config) NewIterator() (*ConfigIterator, error) {
iter := &ConfigIterator{cfg: c}
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ret := C.git_config_iterator_new(&iter.ptr, c.ptr)
if ret < 0 {
return nil, MakeGitError(ret)
}
return iter, nil
} | [
"func",
"(",
"c",
"*",
"Config",
")",
"NewIterator",
"(",
")",
"(",
"*",
"ConfigIterator",
",",
"error",
")",
"{",
"iter",
":=",
"&",
"ConfigIterator",
"{",
"cfg",
":",
"c",
"}",
"\n\n",
"runtime",
".",
"LockOSThread",
"(",
")",
"\n",
"defer",
"runti... | // NewIterator creates an iterator over each entry in the
// configuration | [
"NewIterator",
"creates",
"an",
"iterator",
"over",
"each",
"entry",
"in",
"the",
"configuration"
] | bf1e8a4338822ad2539a3876f58b15b590eb9e1f | https://github.com/libgit2/git2go/blob/bf1e8a4338822ad2539a3876f58b15b590eb9e1f/config.go#L187-L199 | train |
libgit2/git2go | config.go | NewIteratorGlob | func (c *Config) NewIteratorGlob(regexp string) (*ConfigIterator, error) {
iter := &ConfigIterator{cfg: c}
cregexp := C.CString(regexp)
defer C.free(unsafe.Pointer(cregexp))
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ret := C.git_config_iterator_glob_new(&iter.ptr, c.ptr, cregexp)
if ret < 0 {
return nil, MakeGitError(ret)
}
return iter, nil
} | go | func (c *Config) NewIteratorGlob(regexp string) (*ConfigIterator, error) {
iter := &ConfigIterator{cfg: c}
cregexp := C.CString(regexp)
defer C.free(unsafe.Pointer(cregexp))
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ret := C.git_config_iterator_glob_new(&iter.ptr, c.ptr, cregexp)
if ret < 0 {
return nil, MakeGitError(ret)
}
return iter, nil
} | [
"func",
"(",
"c",
"*",
"Config",
")",
"NewIteratorGlob",
"(",
"regexp",
"string",
")",
"(",
"*",
"ConfigIterator",
",",
"error",
")",
"{",
"iter",
":=",
"&",
"ConfigIterator",
"{",
"cfg",
":",
"c",
"}",
"\n",
"cregexp",
":=",
"C",
".",
"CString",
"("... | // NewIteratorGlob creates an iterator over each entry in the
// configuration whose name matches the given regular expression | [
"NewIteratorGlob",
"creates",
"an",
"iterator",
"over",
"each",
"entry",
"in",
"the",
"configuration",
"whose",
"name",
"matches",
"the",
"given",
"regular",
"expression"
] | bf1e8a4338822ad2539a3876f58b15b590eb9e1f | https://github.com/libgit2/git2go/blob/bf1e8a4338822ad2539a3876f58b15b590eb9e1f/config.go#L203-L217 | train |
libgit2/git2go | config.go | OpenLevel | func (c *Config) OpenLevel(parent *Config, level ConfigLevel) (*Config, error) {
config := new(Config)
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ret := C.git_config_open_level(&config.ptr, parent.ptr, C.git_config_level_t(level))
runtime.KeepAlive(c)
runtime.KeepAlive(parent)
if ret < 0 {
return nil, MakeGitError(ret)
}
return config, nil
} | go | func (c *Config) OpenLevel(parent *Config, level ConfigLevel) (*Config, error) {
config := new(Config)
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ret := C.git_config_open_level(&config.ptr, parent.ptr, C.git_config_level_t(level))
runtime.KeepAlive(c)
runtime.KeepAlive(parent)
if ret < 0 {
return nil, MakeGitError(ret)
}
return config, nil
} | [
"func",
"(",
"c",
"*",
"Config",
")",
"OpenLevel",
"(",
"parent",
"*",
"Config",
",",
"level",
"ConfigLevel",
")",
"(",
"*",
"Config",
",",
"error",
")",
"{",
"config",
":=",
"new",
"(",
"Config",
")",
"\n\n",
"runtime",
".",
"LockOSThread",
"(",
")"... | // OpenLevel creates a single-level focused config object from a multi-level one | [
"OpenLevel",
"creates",
"a",
"single",
"-",
"level",
"focused",
"config",
"object",
"from",
"a",
"multi",
"-",
"level",
"one"
] | bf1e8a4338822ad2539a3876f58b15b590eb9e1f | https://github.com/libgit2/git2go/blob/bf1e8a4338822ad2539a3876f58b15b590eb9e1f/config.go#L330-L344 | train |
libgit2/git2go | config.go | OpenOndisk | func OpenOndisk(path string) (*Config, error) {
cpath := C.CString(path)
defer C.free(unsafe.Pointer(cpath))
config := new(Config)
runtime.LockOSThread()
defer runtime.UnlockOSThread()
if ret := C.git_config_open_ondisk(&config.ptr, cpath); ret < 0 {
return nil, MakeGitError(ret)
}
return config, nil
} | go | func OpenOndisk(path string) (*Config, error) {
cpath := C.CString(path)
defer C.free(unsafe.Pointer(cpath))
config := new(Config)
runtime.LockOSThread()
defer runtime.UnlockOSThread()
if ret := C.git_config_open_ondisk(&config.ptr, cpath); ret < 0 {
return nil, MakeGitError(ret)
}
return config, nil
} | [
"func",
"OpenOndisk",
"(",
"path",
"string",
")",
"(",
"*",
"Config",
",",
"error",
")",
"{",
"cpath",
":=",
"C",
".",
"CString",
"(",
"path",
")",
"\n",
"defer",
"C",
".",
"free",
"(",
"unsafe",
".",
"Pointer",
"(",
"cpath",
")",
")",
"\n\n",
"c... | // OpenOndisk creates a new config instance containing a single on-disk file | [
"OpenOndisk",
"creates",
"a",
"new",
"config",
"instance",
"containing",
"a",
"single",
"on",
"-",
"disk",
"file"
] | bf1e8a4338822ad2539a3876f58b15b590eb9e1f | https://github.com/libgit2/git2go/blob/bf1e8a4338822ad2539a3876f58b15b590eb9e1f/config.go#L347-L361 | train |
libgit2/git2go | config.go | Next | func (iter *ConfigIterator) Next() (*ConfigEntry, error) {
var centry *C.git_config_entry
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ret := C.git_config_next(¢ry, iter.ptr)
if ret < 0 {
return nil, MakeGitError(ret)
}
entry := newConfigEntryFromC(centry)
runtime.KeepAlive(iter)
return entry, nil
} | go | func (iter *ConfigIterator) Next() (*ConfigEntry, error) {
var centry *C.git_config_entry
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ret := C.git_config_next(¢ry, iter.ptr)
if ret < 0 {
return nil, MakeGitError(ret)
}
entry := newConfigEntryFromC(centry)
runtime.KeepAlive(iter)
return entry, nil
} | [
"func",
"(",
"iter",
"*",
"ConfigIterator",
")",
"Next",
"(",
")",
"(",
"*",
"ConfigEntry",
",",
"error",
")",
"{",
"var",
"centry",
"*",
"C",
".",
"git_config_entry",
"\n\n",
"runtime",
".",
"LockOSThread",
"(",
")",
"\n",
"defer",
"runtime",
".",
"Un... | // Next returns the next entry for this iterator | [
"Next",
"returns",
"the",
"next",
"entry",
"for",
"this",
"iterator"
] | bf1e8a4338822ad2539a3876f58b15b590eb9e1f | https://github.com/libgit2/git2go/blob/bf1e8a4338822ad2539a3876f58b15b590eb9e1f/config.go#L369-L384 | train |
libgit2/git2go | config.go | ConfigFindProgramdata | func ConfigFindProgramdata() (string, error) {
var buf C.git_buf
defer C.git_buf_dispose(&buf)
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ret := C.git_config_find_programdata(&buf)
if ret < 0 {
return "", MakeGitError(ret)
}
return C.GoString(buf.ptr), nil
} | go | func ConfigFindProgramdata() (string, error) {
var buf C.git_buf
defer C.git_buf_dispose(&buf)
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ret := C.git_config_find_programdata(&buf)
if ret < 0 {
return "", MakeGitError(ret)
}
return C.GoString(buf.ptr), nil
} | [
"func",
"ConfigFindProgramdata",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"var",
"buf",
"C",
".",
"git_buf",
"\n",
"defer",
"C",
".",
"git_buf_dispose",
"(",
"&",
"buf",
")",
"\n\n",
"runtime",
".",
"LockOSThread",
"(",
")",
"\n",
"defer",
"run... | // ConfigFindProgramdata locate the path to the configuration file in ProgramData.
//
// Look for the file in %PROGRAMDATA%\Git\config used by portable git. | [
"ConfigFindProgramdata",
"locate",
"the",
"path",
"to",
"the",
"configuration",
"file",
"in",
"ProgramData",
".",
"Look",
"for",
"the",
"file",
"in",
"%PROGRAMDATA%",
"\\",
"Git",
"\\",
"config",
"used",
"by",
"portable",
"git",
"."
] | bf1e8a4338822ad2539a3876f58b15b590eb9e1f | https://github.com/libgit2/git2go/blob/bf1e8a4338822ad2539a3876f58b15b590eb9e1f/config.go#L439-L452 | train |
libgit2/git2go | merge.go | MergeAnalysis | func (r *Repository) MergeAnalysis(theirHeads []*AnnotatedCommit) (MergeAnalysis, MergePreference, error) {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
gmerge_head_array := make([]*C.git_annotated_commit, len(theirHeads))
for i := 0; i < len(theirHeads); i++ {
gmerge_head_array[i] = theirHeads[i].ptr
}
ptr := unsafe.Pointer(&gmerge_head_array[0])
var analysis C.git_merge_analysis_t
var preference C.git_merge_preference_t
err := C.git_merge_analysis(&analysis, &preference, r.ptr, (**C.git_annotated_commit)(ptr), C.size_t(len(theirHeads)))
runtime.KeepAlive(theirHeads)
if err < 0 {
return MergeAnalysisNone, MergePreferenceNone, MakeGitError(err)
}
return MergeAnalysis(analysis), MergePreference(preference), nil
} | go | func (r *Repository) MergeAnalysis(theirHeads []*AnnotatedCommit) (MergeAnalysis, MergePreference, error) {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
gmerge_head_array := make([]*C.git_annotated_commit, len(theirHeads))
for i := 0; i < len(theirHeads); i++ {
gmerge_head_array[i] = theirHeads[i].ptr
}
ptr := unsafe.Pointer(&gmerge_head_array[0])
var analysis C.git_merge_analysis_t
var preference C.git_merge_preference_t
err := C.git_merge_analysis(&analysis, &preference, r.ptr, (**C.git_annotated_commit)(ptr), C.size_t(len(theirHeads)))
runtime.KeepAlive(theirHeads)
if err < 0 {
return MergeAnalysisNone, MergePreferenceNone, MakeGitError(err)
}
return MergeAnalysis(analysis), MergePreference(preference), nil
} | [
"func",
"(",
"r",
"*",
"Repository",
")",
"MergeAnalysis",
"(",
"theirHeads",
"[",
"]",
"*",
"AnnotatedCommit",
")",
"(",
"MergeAnalysis",
",",
"MergePreference",
",",
"error",
")",
"{",
"runtime",
".",
"LockOSThread",
"(",
")",
"\n",
"defer",
"runtime",
"... | // MergeAnalysis returns the possible actions which could be taken by
// a 'git-merge' command. There may be multiple answers, so the first
// return value is a bitmask of MergeAnalysis values. | [
"MergeAnalysis",
"returns",
"the",
"possible",
"actions",
"which",
"could",
"be",
"taken",
"by",
"a",
"git",
"-",
"merge",
"command",
".",
"There",
"may",
"be",
"multiple",
"answers",
"so",
"the",
"first",
"return",
"value",
"is",
"a",
"bitmask",
"of",
"Me... | bf1e8a4338822ad2539a3876f58b15b590eb9e1f | https://github.com/libgit2/git2go/blob/bf1e8a4338822ad2539a3876f58b15b590eb9e1f/merge.go#L193-L211 | train |
libgit2/git2go | merge.go | MergeBases | func (r *Repository) MergeBases(one, two *Oid) ([]*Oid, error) {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
var coids C.git_oidarray
ret := C.git_merge_bases(&coids, r.ptr, one.toC(), two.toC())
runtime.KeepAlive(one)
runtime.KeepAlive(two)
if ret < 0 {
return make([]*Oid, 0), MakeGitError(ret)
}
oids := make([]*Oid, coids.count)
hdr := reflect.SliceHeader{
Data: uintptr(unsafe.Pointer(coids.ids)),
Len: int(coids.count),
Cap: int(coids.count),
}
goSlice := *(*[]C.git_oid)(unsafe.Pointer(&hdr))
for i, cid := range goSlice {
oids[i] = newOidFromC(&cid)
}
return oids, nil
} | go | func (r *Repository) MergeBases(one, two *Oid) ([]*Oid, error) {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
var coids C.git_oidarray
ret := C.git_merge_bases(&coids, r.ptr, one.toC(), two.toC())
runtime.KeepAlive(one)
runtime.KeepAlive(two)
if ret < 0 {
return make([]*Oid, 0), MakeGitError(ret)
}
oids := make([]*Oid, coids.count)
hdr := reflect.SliceHeader{
Data: uintptr(unsafe.Pointer(coids.ids)),
Len: int(coids.count),
Cap: int(coids.count),
}
goSlice := *(*[]C.git_oid)(unsafe.Pointer(&hdr))
for i, cid := range goSlice {
oids[i] = newOidFromC(&cid)
}
return oids, nil
} | [
"func",
"(",
"r",
"*",
"Repository",
")",
"MergeBases",
"(",
"one",
",",
"two",
"*",
"Oid",
")",
"(",
"[",
"]",
"*",
"Oid",
",",
"error",
")",
"{",
"runtime",
".",
"LockOSThread",
"(",
")",
"\n",
"defer",
"runtime",
".",
"UnlockOSThread",
"(",
")",... | // MergeBases retrieves the list of merge bases between two commits.
//
// If none are found, an empty slice is returned and the error is set
// approprately | [
"MergeBases",
"retrieves",
"the",
"list",
"of",
"merge",
"bases",
"between",
"two",
"commits",
".",
"If",
"none",
"are",
"found",
"an",
"empty",
"slice",
"is",
"returned",
"and",
"the",
"error",
"is",
"set",
"approprately"
] | bf1e8a4338822ad2539a3876f58b15b590eb9e1f | https://github.com/libgit2/git2go/blob/bf1e8a4338822ad2539a3876f58b15b590eb9e1f/merge.go#L271-L297 | train |
libgit2/git2go | note.go | Create | func (c *NoteCollection) Create(
ref string, author, committer *Signature, id *Oid,
note string, force bool) (*Oid, error) {
oid := new(Oid)
var cref *C.char
if ref == "" {
cref = nil
} else {
cref = C.CString(ref)
defer C.free(unsafe.Pointer(cref))
}
authorSig, err := author.toC()
if err != nil {
return nil, err
}
defer C.git_signature_free(authorSig)
committerSig, err := committer.toC()
if err != nil {
return nil, err
}
defer C.git_signature_free(committerSig)
cnote := C.CString(note)
defer C.free(unsafe.Pointer(cnote))
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ret := C.git_note_create(
oid.toC(), c.repo.ptr, cref, authorSig,
committerSig, id.toC(), cnote, cbool(force))
runtime.KeepAlive(c)
runtime.KeepAlive(id)
if ret < 0 {
return nil, MakeGitError(ret)
}
return oid, nil
} | go | func (c *NoteCollection) Create(
ref string, author, committer *Signature, id *Oid,
note string, force bool) (*Oid, error) {
oid := new(Oid)
var cref *C.char
if ref == "" {
cref = nil
} else {
cref = C.CString(ref)
defer C.free(unsafe.Pointer(cref))
}
authorSig, err := author.toC()
if err != nil {
return nil, err
}
defer C.git_signature_free(authorSig)
committerSig, err := committer.toC()
if err != nil {
return nil, err
}
defer C.git_signature_free(committerSig)
cnote := C.CString(note)
defer C.free(unsafe.Pointer(cnote))
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ret := C.git_note_create(
oid.toC(), c.repo.ptr, cref, authorSig,
committerSig, id.toC(), cnote, cbool(force))
runtime.KeepAlive(c)
runtime.KeepAlive(id)
if ret < 0 {
return nil, MakeGitError(ret)
}
return oid, nil
} | [
"func",
"(",
"c",
"*",
"NoteCollection",
")",
"Create",
"(",
"ref",
"string",
",",
"author",
",",
"committer",
"*",
"Signature",
",",
"id",
"*",
"Oid",
",",
"note",
"string",
",",
"force",
"bool",
")",
"(",
"*",
"Oid",
",",
"error",
")",
"{",
"oid"... | // Create adds a note for an object | [
"Create",
"adds",
"a",
"note",
"for",
"an",
"object"
] | bf1e8a4338822ad2539a3876f58b15b590eb9e1f | https://github.com/libgit2/git2go/blob/bf1e8a4338822ad2539a3876f58b15b590eb9e1f/note.go#L20-L61 | train |
libgit2/git2go | note.go | Read | func (c *NoteCollection) Read(ref string, id *Oid) (*Note, error) {
var cref *C.char
if ref == "" {
cref = nil
} else {
cref = C.CString(ref)
defer C.free(unsafe.Pointer(cref))
}
runtime.LockOSThread()
defer runtime.UnlockOSThread()
var ptr *C.git_note
ret := C.git_note_read(&ptr, c.repo.ptr, cref, id.toC())
runtime.KeepAlive(c)
runtime.KeepAlive(id)
if ret < 0 {
return nil, MakeGitError(ret)
}
return newNoteFromC(ptr, c.repo), nil
} | go | func (c *NoteCollection) Read(ref string, id *Oid) (*Note, error) {
var cref *C.char
if ref == "" {
cref = nil
} else {
cref = C.CString(ref)
defer C.free(unsafe.Pointer(cref))
}
runtime.LockOSThread()
defer runtime.UnlockOSThread()
var ptr *C.git_note
ret := C.git_note_read(&ptr, c.repo.ptr, cref, id.toC())
runtime.KeepAlive(c)
runtime.KeepAlive(id)
if ret < 0 {
return nil, MakeGitError(ret)
}
return newNoteFromC(ptr, c.repo), nil
} | [
"func",
"(",
"c",
"*",
"NoteCollection",
")",
"Read",
"(",
"ref",
"string",
",",
"id",
"*",
"Oid",
")",
"(",
"*",
"Note",
",",
"error",
")",
"{",
"var",
"cref",
"*",
"C",
".",
"char",
"\n",
"if",
"ref",
"==",
"\"",
"\"",
"{",
"cref",
"=",
"ni... | // Read reads the note for an object | [
"Read",
"reads",
"the",
"note",
"for",
"an",
"object"
] | bf1e8a4338822ad2539a3876f58b15b590eb9e1f | https://github.com/libgit2/git2go/blob/bf1e8a4338822ad2539a3876f58b15b590eb9e1f/note.go#L64-L85 | train |
libgit2/git2go | note.go | Remove | func (c *NoteCollection) Remove(ref string, author, committer *Signature, id *Oid) error {
var cref *C.char
if ref == "" {
cref = nil
} else {
cref = C.CString(ref)
defer C.free(unsafe.Pointer(cref))
}
authorSig, err := author.toC()
if err != nil {
return err
}
defer C.git_signature_free(authorSig)
committerSig, err := committer.toC()
if err != nil {
return err
}
defer C.git_signature_free(committerSig)
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ret := C.git_note_remove(c.repo.ptr, cref, authorSig, committerSig, id.toC())
runtime.KeepAlive(c)
runtime.KeepAlive(id)
if ret < 0 {
return MakeGitError(ret)
}
return nil
} | go | func (c *NoteCollection) Remove(ref string, author, committer *Signature, id *Oid) error {
var cref *C.char
if ref == "" {
cref = nil
} else {
cref = C.CString(ref)
defer C.free(unsafe.Pointer(cref))
}
authorSig, err := author.toC()
if err != nil {
return err
}
defer C.git_signature_free(authorSig)
committerSig, err := committer.toC()
if err != nil {
return err
}
defer C.git_signature_free(committerSig)
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ret := C.git_note_remove(c.repo.ptr, cref, authorSig, committerSig, id.toC())
runtime.KeepAlive(c)
runtime.KeepAlive(id)
if ret < 0 {
return MakeGitError(ret)
}
return nil
} | [
"func",
"(",
"c",
"*",
"NoteCollection",
")",
"Remove",
"(",
"ref",
"string",
",",
"author",
",",
"committer",
"*",
"Signature",
",",
"id",
"*",
"Oid",
")",
"error",
"{",
"var",
"cref",
"*",
"C",
".",
"char",
"\n",
"if",
"ref",
"==",
"\"",
"\"",
... | // Remove removes the note for an object | [
"Remove",
"removes",
"the",
"note",
"for",
"an",
"object"
] | bf1e8a4338822ad2539a3876f58b15b590eb9e1f | https://github.com/libgit2/git2go/blob/bf1e8a4338822ad2539a3876f58b15b590eb9e1f/note.go#L88-L119 | train |
libgit2/git2go | note.go | DefaultRef | func (c *NoteCollection) DefaultRef() (string, error) {
buf := C.git_buf{}
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ecode := C.git_note_default_ref(&buf, c.repo.ptr)
runtime.KeepAlive(c)
if ecode < 0 {
return "", MakeGitError(ecode)
}
ret := C.GoString(buf.ptr)
C.git_buf_dispose(&buf)
return ret, nil
} | go | func (c *NoteCollection) DefaultRef() (string, error) {
buf := C.git_buf{}
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ecode := C.git_note_default_ref(&buf, c.repo.ptr)
runtime.KeepAlive(c)
if ecode < 0 {
return "", MakeGitError(ecode)
}
ret := C.GoString(buf.ptr)
C.git_buf_dispose(&buf)
return ret, nil
} | [
"func",
"(",
"c",
"*",
"NoteCollection",
")",
"DefaultRef",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"buf",
":=",
"C",
".",
"git_buf",
"{",
"}",
"\n\n",
"runtime",
".",
"LockOSThread",
"(",
")",
"\n",
"defer",
"runtime",
".",
"UnlockOSThread",
... | // DefaultRef returns the default notes reference for a repository | [
"DefaultRef",
"returns",
"the",
"default",
"notes",
"reference",
"for",
"a",
"repository"
] | bf1e8a4338822ad2539a3876f58b15b590eb9e1f | https://github.com/libgit2/git2go/blob/bf1e8a4338822ad2539a3876f58b15b590eb9e1f/note.go#L122-L138 | train |
libgit2/git2go | note.go | Free | func (n *Note) Free() error {
if n.ptr == nil {
return ErrInvalid
}
runtime.SetFinalizer(n, nil)
C.git_note_free(n.ptr)
n.ptr = nil
return nil
} | go | func (n *Note) Free() error {
if n.ptr == nil {
return ErrInvalid
}
runtime.SetFinalizer(n, nil)
C.git_note_free(n.ptr)
n.ptr = nil
return nil
} | [
"func",
"(",
"n",
"*",
"Note",
")",
"Free",
"(",
")",
"error",
"{",
"if",
"n",
".",
"ptr",
"==",
"nil",
"{",
"return",
"ErrInvalid",
"\n",
"}",
"\n",
"runtime",
".",
"SetFinalizer",
"(",
"n",
",",
"nil",
")",
"\n",
"C",
".",
"git_note_free",
"(",... | // Free frees a git_note object | [
"Free",
"frees",
"a",
"git_note",
"object"
] | bf1e8a4338822ad2539a3876f58b15b590eb9e1f | https://github.com/libgit2/git2go/blob/bf1e8a4338822ad2539a3876f58b15b590eb9e1f/note.go#L153-L161 | train |
libgit2/git2go | note.go | Author | func (n *Note) Author() *Signature {
ptr := C.git_note_author(n.ptr)
return newSignatureFromC(ptr)
} | go | func (n *Note) Author() *Signature {
ptr := C.git_note_author(n.ptr)
return newSignatureFromC(ptr)
} | [
"func",
"(",
"n",
"*",
"Note",
")",
"Author",
"(",
")",
"*",
"Signature",
"{",
"ptr",
":=",
"C",
".",
"git_note_author",
"(",
"n",
".",
"ptr",
")",
"\n",
"return",
"newSignatureFromC",
"(",
"ptr",
")",
"\n",
"}"
] | // Author returns the signature of the note author | [
"Author",
"returns",
"the",
"signature",
"of",
"the",
"note",
"author"
] | bf1e8a4338822ad2539a3876f58b15b590eb9e1f | https://github.com/libgit2/git2go/blob/bf1e8a4338822ad2539a3876f58b15b590eb9e1f/note.go#L164-L167 | train |
libgit2/git2go | note.go | Id | func (n *Note) Id() *Oid {
ptr := C.git_note_id(n.ptr)
runtime.KeepAlive(n)
return newOidFromC(ptr)
} | go | func (n *Note) Id() *Oid {
ptr := C.git_note_id(n.ptr)
runtime.KeepAlive(n)
return newOidFromC(ptr)
} | [
"func",
"(",
"n",
"*",
"Note",
")",
"Id",
"(",
")",
"*",
"Oid",
"{",
"ptr",
":=",
"C",
".",
"git_note_id",
"(",
"n",
".",
"ptr",
")",
"\n",
"runtime",
".",
"KeepAlive",
"(",
"n",
")",
"\n",
"return",
"newOidFromC",
"(",
"ptr",
")",
"\n",
"}"
] | // Id returns the note object's id | [
"Id",
"returns",
"the",
"note",
"object",
"s",
"id"
] | bf1e8a4338822ad2539a3876f58b15b590eb9e1f | https://github.com/libgit2/git2go/blob/bf1e8a4338822ad2539a3876f58b15b590eb9e1f/note.go#L170-L174 | train |
libgit2/git2go | note.go | Committer | func (n *Note) Committer() *Signature {
ptr := C.git_note_committer(n.ptr)
runtime.KeepAlive(n)
return newSignatureFromC(ptr)
} | go | func (n *Note) Committer() *Signature {
ptr := C.git_note_committer(n.ptr)
runtime.KeepAlive(n)
return newSignatureFromC(ptr)
} | [
"func",
"(",
"n",
"*",
"Note",
")",
"Committer",
"(",
")",
"*",
"Signature",
"{",
"ptr",
":=",
"C",
".",
"git_note_committer",
"(",
"n",
".",
"ptr",
")",
"\n",
"runtime",
".",
"KeepAlive",
"(",
"n",
")",
"\n",
"return",
"newSignatureFromC",
"(",
"ptr... | // Committer returns the signature of the note committer | [
"Committer",
"returns",
"the",
"signature",
"of",
"the",
"note",
"committer"
] | bf1e8a4338822ad2539a3876f58b15b590eb9e1f | https://github.com/libgit2/git2go/blob/bf1e8a4338822ad2539a3876f58b15b590eb9e1f/note.go#L177-L181 | train |
libgit2/git2go | note.go | Message | func (n *Note) Message() string {
ret := C.GoString(C.git_note_message(n.ptr))
runtime.KeepAlive(n)
return ret
} | go | func (n *Note) Message() string {
ret := C.GoString(C.git_note_message(n.ptr))
runtime.KeepAlive(n)
return ret
} | [
"func",
"(",
"n",
"*",
"Note",
")",
"Message",
"(",
")",
"string",
"{",
"ret",
":=",
"C",
".",
"GoString",
"(",
"C",
".",
"git_note_message",
"(",
"n",
".",
"ptr",
")",
")",
"\n",
"runtime",
".",
"KeepAlive",
"(",
"n",
")",
"\n",
"return",
"ret",... | // Message returns the note message | [
"Message",
"returns",
"the",
"note",
"message"
] | bf1e8a4338822ad2539a3876f58b15b590eb9e1f | https://github.com/libgit2/git2go/blob/bf1e8a4338822ad2539a3876f58b15b590eb9e1f/note.go#L184-L188 | train |
libgit2/git2go | note.go | NewNoteIterator | func (repo *Repository) NewNoteIterator(ref string) (*NoteIterator, error) {
var cref *C.char
if ref == "" {
cref = nil
} else {
cref = C.CString(ref)
defer C.free(unsafe.Pointer(cref))
}
var ptr *C.git_note_iterator
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ret := C.git_note_iterator_new(&ptr, repo.ptr, cref)
runtime.KeepAlive(repo)
if ret < 0 {
return nil, MakeGitError(ret)
}
iter := &NoteIterator{ptr: ptr, r: repo}
runtime.SetFinalizer(iter, (*NoteIterator).Free)
return iter, nil
} | go | func (repo *Repository) NewNoteIterator(ref string) (*NoteIterator, error) {
var cref *C.char
if ref == "" {
cref = nil
} else {
cref = C.CString(ref)
defer C.free(unsafe.Pointer(cref))
}
var ptr *C.git_note_iterator
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ret := C.git_note_iterator_new(&ptr, repo.ptr, cref)
runtime.KeepAlive(repo)
if ret < 0 {
return nil, MakeGitError(ret)
}
iter := &NoteIterator{ptr: ptr, r: repo}
runtime.SetFinalizer(iter, (*NoteIterator).Free)
return iter, nil
} | [
"func",
"(",
"repo",
"*",
"Repository",
")",
"NewNoteIterator",
"(",
"ref",
"string",
")",
"(",
"*",
"NoteIterator",
",",
"error",
")",
"{",
"var",
"cref",
"*",
"C",
".",
"char",
"\n",
"if",
"ref",
"==",
"\"",
"\"",
"{",
"cref",
"=",
"nil",
"\n",
... | // NewNoteIterator creates a new iterator for notes | [
"NewNoteIterator",
"creates",
"a",
"new",
"iterator",
"for",
"notes"
] | bf1e8a4338822ad2539a3876f58b15b590eb9e1f | https://github.com/libgit2/git2go/blob/bf1e8a4338822ad2539a3876f58b15b590eb9e1f/note.go#L197-L220 | train |
libgit2/git2go | note.go | Free | func (v *NoteIterator) Free() {
runtime.SetFinalizer(v, nil)
C.git_note_iterator_free(v.ptr)
} | go | func (v *NoteIterator) Free() {
runtime.SetFinalizer(v, nil)
C.git_note_iterator_free(v.ptr)
} | [
"func",
"(",
"v",
"*",
"NoteIterator",
")",
"Free",
"(",
")",
"{",
"runtime",
".",
"SetFinalizer",
"(",
"v",
",",
"nil",
")",
"\n",
"C",
".",
"git_note_iterator_free",
"(",
"v",
".",
"ptr",
")",
"\n",
"}"
] | // Free frees the note interator | [
"Free",
"frees",
"the",
"note",
"interator"
] | bf1e8a4338822ad2539a3876f58b15b590eb9e1f | https://github.com/libgit2/git2go/blob/bf1e8a4338822ad2539a3876f58b15b590eb9e1f/note.go#L223-L226 | train |
libgit2/git2go | blob.go | Write | func (stream *BlobWriteStream) Write(p []byte) (int, error) {
header := (*reflect.SliceHeader)(unsafe.Pointer(&p))
ptr := (*C.char)(unsafe.Pointer(header.Data))
size := C.size_t(header.Len)
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ecode := C._go_git_writestream_write(stream.ptr, ptr, size)
runtime.KeepAlive(stream)
if ecode < 0 {
return 0, MakeGitError(ecode)
}
return len(p), nil
} | go | func (stream *BlobWriteStream) Write(p []byte) (int, error) {
header := (*reflect.SliceHeader)(unsafe.Pointer(&p))
ptr := (*C.char)(unsafe.Pointer(header.Data))
size := C.size_t(header.Len)
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ecode := C._go_git_writestream_write(stream.ptr, ptr, size)
runtime.KeepAlive(stream)
if ecode < 0 {
return 0, MakeGitError(ecode)
}
return len(p), nil
} | [
"func",
"(",
"stream",
"*",
"BlobWriteStream",
")",
"Write",
"(",
"p",
"[",
"]",
"byte",
")",
"(",
"int",
",",
"error",
")",
"{",
"header",
":=",
"(",
"*",
"reflect",
".",
"SliceHeader",
")",
"(",
"unsafe",
".",
"Pointer",
"(",
"&",
"p",
")",
")"... | // Implement io.Writer | [
"Implement",
"io",
".",
"Writer"
] | bf1e8a4338822ad2539a3876f58b15b590eb9e1f | https://github.com/libgit2/git2go/blob/bf1e8a4338822ad2539a3876f58b15b590eb9e1f/blob.go#L135-L150 | train |
libgit2/git2go | diff.go | DiffBlobs | func DiffBlobs(oldBlob *Blob, oldAsPath string, newBlob *Blob, newAsPath string, opts *DiffOptions, fileCallback DiffForEachFileCallback, detail DiffDetail) error {
data := &diffForEachData{
FileCallback: fileCallback,
}
intHunks := C.int(0)
if detail >= DiffDetailHunks {
intHunks = C.int(1)
}
intLines := C.int(0)
if detail >= DiffDetailLines {
intLines = C.int(1)
}
handle := pointerHandles.Track(data)
defer pointerHandles.Untrack(handle)
var oldBlobPtr, newBlobPtr *C.git_blob
if oldBlob != nil {
oldBlobPtr = oldBlob.cast_ptr
}
if newBlob != nil {
newBlobPtr = newBlob.cast_ptr
}
oldBlobPath := C.CString(oldAsPath)
defer C.free(unsafe.Pointer(oldBlobPath))
newBlobPath := C.CString(newAsPath)
defer C.free(unsafe.Pointer(newBlobPath))
copts, _ := diffOptionsToC(opts)
defer freeDiffOptions(copts)
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ecode := C._go_git_diff_blobs(oldBlobPtr, oldBlobPath, newBlobPtr, newBlobPath, copts, 1, intHunks, intLines, handle)
runtime.KeepAlive(oldBlob)
runtime.KeepAlive(newBlob)
if ecode < 0 {
return MakeGitError(ecode)
}
return nil
} | go | func DiffBlobs(oldBlob *Blob, oldAsPath string, newBlob *Blob, newAsPath string, opts *DiffOptions, fileCallback DiffForEachFileCallback, detail DiffDetail) error {
data := &diffForEachData{
FileCallback: fileCallback,
}
intHunks := C.int(0)
if detail >= DiffDetailHunks {
intHunks = C.int(1)
}
intLines := C.int(0)
if detail >= DiffDetailLines {
intLines = C.int(1)
}
handle := pointerHandles.Track(data)
defer pointerHandles.Untrack(handle)
var oldBlobPtr, newBlobPtr *C.git_blob
if oldBlob != nil {
oldBlobPtr = oldBlob.cast_ptr
}
if newBlob != nil {
newBlobPtr = newBlob.cast_ptr
}
oldBlobPath := C.CString(oldAsPath)
defer C.free(unsafe.Pointer(oldBlobPath))
newBlobPath := C.CString(newAsPath)
defer C.free(unsafe.Pointer(newBlobPath))
copts, _ := diffOptionsToC(opts)
defer freeDiffOptions(copts)
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ecode := C._go_git_diff_blobs(oldBlobPtr, oldBlobPath, newBlobPtr, newBlobPath, copts, 1, intHunks, intLines, handle)
runtime.KeepAlive(oldBlob)
runtime.KeepAlive(newBlob)
if ecode < 0 {
return MakeGitError(ecode)
}
return nil
} | [
"func",
"DiffBlobs",
"(",
"oldBlob",
"*",
"Blob",
",",
"oldAsPath",
"string",
",",
"newBlob",
"*",
"Blob",
",",
"newAsPath",
"string",
",",
"opts",
"*",
"DiffOptions",
",",
"fileCallback",
"DiffForEachFileCallback",
",",
"detail",
"DiffDetail",
")",
"error",
"... | // DiffBlobs performs a diff between two arbitrary blobs. You can pass
// whatever file names you'd like for them to appear as in the diff. | [
"DiffBlobs",
"performs",
"a",
"diff",
"between",
"two",
"arbitrary",
"blobs",
".",
"You",
"can",
"pass",
"whatever",
"file",
"names",
"you",
"d",
"like",
"for",
"them",
"to",
"appear",
"as",
"in",
"the",
"diff",
"."
] | bf1e8a4338822ad2539a3876f58b15b590eb9e1f | https://github.com/libgit2/git2go/blob/bf1e8a4338822ad2539a3876f58b15b590eb9e1f/diff.go#L765-L810 | train |
libgit2/git2go | rebase.go | DefaultRebaseOptions | func DefaultRebaseOptions() (RebaseOptions, error) {
opts := C.git_rebase_options{}
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ecode := C.git_rebase_init_options(&opts, C.GIT_REBASE_OPTIONS_VERSION)
if ecode < 0 {
return RebaseOptions{}, MakeGitError(ecode)
}
return rebaseOptionsFromC(&opts), nil
} | go | func DefaultRebaseOptions() (RebaseOptions, error) {
opts := C.git_rebase_options{}
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ecode := C.git_rebase_init_options(&opts, C.GIT_REBASE_OPTIONS_VERSION)
if ecode < 0 {
return RebaseOptions{}, MakeGitError(ecode)
}
return rebaseOptionsFromC(&opts), nil
} | [
"func",
"DefaultRebaseOptions",
"(",
")",
"(",
"RebaseOptions",
",",
"error",
")",
"{",
"opts",
":=",
"C",
".",
"git_rebase_options",
"{",
"}",
"\n\n",
"runtime",
".",
"LockOSThread",
"(",
")",
"\n",
"defer",
"runtime",
".",
"UnlockOSThread",
"(",
")",
"\n... | // DefaultRebaseOptions returns a RebaseOptions with default values. | [
"DefaultRebaseOptions",
"returns",
"a",
"RebaseOptions",
"with",
"default",
"values",
"."
] | bf1e8a4338822ad2539a3876f58b15b590eb9e1f | https://github.com/libgit2/git2go/blob/bf1e8a4338822ad2539a3876f58b15b590eb9e1f/rebase.go#L83-L94 | train |
libgit2/git2go | rebase.go | InitRebase | func (r *Repository) InitRebase(branch *AnnotatedCommit, upstream *AnnotatedCommit, onto *AnnotatedCommit, opts *RebaseOptions) (*Rebase, error) {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
if branch == nil {
branch = &AnnotatedCommit{ptr: nil}
}
if upstream == nil {
upstream = &AnnotatedCommit{ptr: nil}
}
if onto == nil {
onto = &AnnotatedCommit{ptr: nil}
}
var ptr *C.git_rebase
err := C.git_rebase_init(&ptr, r.ptr, branch.ptr, upstream.ptr, onto.ptr, opts.toC())
runtime.KeepAlive(branch)
runtime.KeepAlive(upstream)
runtime.KeepAlive(onto)
if err < 0 {
return nil, MakeGitError(err)
}
return newRebaseFromC(ptr), nil
} | go | func (r *Repository) InitRebase(branch *AnnotatedCommit, upstream *AnnotatedCommit, onto *AnnotatedCommit, opts *RebaseOptions) (*Rebase, error) {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
if branch == nil {
branch = &AnnotatedCommit{ptr: nil}
}
if upstream == nil {
upstream = &AnnotatedCommit{ptr: nil}
}
if onto == nil {
onto = &AnnotatedCommit{ptr: nil}
}
var ptr *C.git_rebase
err := C.git_rebase_init(&ptr, r.ptr, branch.ptr, upstream.ptr, onto.ptr, opts.toC())
runtime.KeepAlive(branch)
runtime.KeepAlive(upstream)
runtime.KeepAlive(onto)
if err < 0 {
return nil, MakeGitError(err)
}
return newRebaseFromC(ptr), nil
} | [
"func",
"(",
"r",
"*",
"Repository",
")",
"InitRebase",
"(",
"branch",
"*",
"AnnotatedCommit",
",",
"upstream",
"*",
"AnnotatedCommit",
",",
"onto",
"*",
"AnnotatedCommit",
",",
"opts",
"*",
"RebaseOptions",
")",
"(",
"*",
"Rebase",
",",
"error",
")",
"{",... | // InitRebase initializes a rebase operation to rebase the changes in branch relative to upstream onto another branch. | [
"InitRebase",
"initializes",
"a",
"rebase",
"operation",
"to",
"rebase",
"the",
"changes",
"in",
"branch",
"relative",
"to",
"upstream",
"onto",
"another",
"branch",
"."
] | bf1e8a4338822ad2539a3876f58b15b590eb9e1f | https://github.com/libgit2/git2go/blob/bf1e8a4338822ad2539a3876f58b15b590eb9e1f/rebase.go#L135-L161 | train |
libgit2/git2go | rebase.go | OpenRebase | func (r *Repository) OpenRebase(opts *RebaseOptions) (*Rebase, error) {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
var ptr *C.git_rebase
err := C.git_rebase_open(&ptr, r.ptr, opts.toC())
runtime.KeepAlive(r)
if err < 0 {
return nil, MakeGitError(err)
}
return newRebaseFromC(ptr), nil
} | go | func (r *Repository) OpenRebase(opts *RebaseOptions) (*Rebase, error) {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
var ptr *C.git_rebase
err := C.git_rebase_open(&ptr, r.ptr, opts.toC())
runtime.KeepAlive(r)
if err < 0 {
return nil, MakeGitError(err)
}
return newRebaseFromC(ptr), nil
} | [
"func",
"(",
"r",
"*",
"Repository",
")",
"OpenRebase",
"(",
"opts",
"*",
"RebaseOptions",
")",
"(",
"*",
"Rebase",
",",
"error",
")",
"{",
"runtime",
".",
"LockOSThread",
"(",
")",
"\n",
"defer",
"runtime",
".",
"UnlockOSThread",
"(",
")",
"\n\n",
"va... | // OpenRebase opens an existing rebase that was previously started by either an invocation of InitRebase or by another client. | [
"OpenRebase",
"opens",
"an",
"existing",
"rebase",
"that",
"was",
"previously",
"started",
"by",
"either",
"an",
"invocation",
"of",
"InitRebase",
"or",
"by",
"another",
"client",
"."
] | bf1e8a4338822ad2539a3876f58b15b590eb9e1f | https://github.com/libgit2/git2go/blob/bf1e8a4338822ad2539a3876f58b15b590eb9e1f/rebase.go#L164-L176 | train |
libgit2/git2go | rebase.go | OperationAt | func (rebase *Rebase) OperationAt(index uint) *RebaseOperation {
operation := C.git_rebase_operation_byindex(rebase.ptr, C.size_t(index))
return newRebaseOperationFromC(operation)
} | go | func (rebase *Rebase) OperationAt(index uint) *RebaseOperation {
operation := C.git_rebase_operation_byindex(rebase.ptr, C.size_t(index))
return newRebaseOperationFromC(operation)
} | [
"func",
"(",
"rebase",
"*",
"Rebase",
")",
"OperationAt",
"(",
"index",
"uint",
")",
"*",
"RebaseOperation",
"{",
"operation",
":=",
"C",
".",
"git_rebase_operation_byindex",
"(",
"rebase",
".",
"ptr",
",",
"C",
".",
"size_t",
"(",
"index",
")",
")",
"\n... | // OperationAt gets the rebase operation specified by the given index. | [
"OperationAt",
"gets",
"the",
"rebase",
"operation",
"specified",
"by",
"the",
"given",
"index",
"."
] | bf1e8a4338822ad2539a3876f58b15b590eb9e1f | https://github.com/libgit2/git2go/blob/bf1e8a4338822ad2539a3876f58b15b590eb9e1f/rebase.go#L179-L183 | train |
libgit2/git2go | rebase.go | CurrentOperationIndex | func (rebase *Rebase) CurrentOperationIndex() (uint, error) {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
var err error
operationIndex := uint(C.git_rebase_operation_current(rebase.ptr))
runtime.KeepAlive(rebase)
if operationIndex == RebaseNoOperation {
err = ErrRebaseNoOperation
}
return uint(operationIndex), err
} | go | func (rebase *Rebase) CurrentOperationIndex() (uint, error) {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
var err error
operationIndex := uint(C.git_rebase_operation_current(rebase.ptr))
runtime.KeepAlive(rebase)
if operationIndex == RebaseNoOperation {
err = ErrRebaseNoOperation
}
return uint(operationIndex), err
} | [
"func",
"(",
"rebase",
"*",
"Rebase",
")",
"CurrentOperationIndex",
"(",
")",
"(",
"uint",
",",
"error",
")",
"{",
"runtime",
".",
"LockOSThread",
"(",
")",
"\n",
"defer",
"runtime",
".",
"UnlockOSThread",
"(",
")",
"\n\n",
"var",
"err",
"error",
"\n",
... | // CurrentOperationIndex gets the index of the rebase operation that is
// currently being applied. There is also an error returned for API
// compatibility. | [
"CurrentOperationIndex",
"gets",
"the",
"index",
"of",
"the",
"rebase",
"operation",
"that",
"is",
"currently",
"being",
"applied",
".",
"There",
"is",
"also",
"an",
"error",
"returned",
"for",
"API",
"compatibility",
"."
] | bf1e8a4338822ad2539a3876f58b15b590eb9e1f | https://github.com/libgit2/git2go/blob/bf1e8a4338822ad2539a3876f58b15b590eb9e1f/rebase.go#L188-L200 | train |
libgit2/git2go | rebase.go | OperationCount | func (rebase *Rebase) OperationCount() uint {
ret := uint(C.git_rebase_operation_entrycount(rebase.ptr))
runtime.KeepAlive(rebase)
return ret
} | go | func (rebase *Rebase) OperationCount() uint {
ret := uint(C.git_rebase_operation_entrycount(rebase.ptr))
runtime.KeepAlive(rebase)
return ret
} | [
"func",
"(",
"rebase",
"*",
"Rebase",
")",
"OperationCount",
"(",
")",
"uint",
"{",
"ret",
":=",
"uint",
"(",
"C",
".",
"git_rebase_operation_entrycount",
"(",
"rebase",
".",
"ptr",
")",
")",
"\n",
"runtime",
".",
"KeepAlive",
"(",
"rebase",
")",
"\n",
... | // OperationCount gets the count of rebase operations that are to be applied. | [
"OperationCount",
"gets",
"the",
"count",
"of",
"rebase",
"operations",
"that",
"are",
"to",
"be",
"applied",
"."
] | bf1e8a4338822ad2539a3876f58b15b590eb9e1f | https://github.com/libgit2/git2go/blob/bf1e8a4338822ad2539a3876f58b15b590eb9e1f/rebase.go#L203-L207 | train |
libgit2/git2go | rebase.go | Finish | func (rebase *Rebase) Finish() error {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
err := C.git_rebase_finish(rebase.ptr, nil)
runtime.KeepAlive(rebase)
if err < 0 {
return MakeGitError(err)
}
return nil
} | go | func (rebase *Rebase) Finish() error {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
err := C.git_rebase_finish(rebase.ptr, nil)
runtime.KeepAlive(rebase)
if err < 0 {
return MakeGitError(err)
}
return nil
} | [
"func",
"(",
"rebase",
"*",
"Rebase",
")",
"Finish",
"(",
")",
"error",
"{",
"runtime",
".",
"LockOSThread",
"(",
")",
"\n",
"defer",
"runtime",
".",
"UnlockOSThread",
"(",
")",
"\n\n",
"err",
":=",
"C",
".",
"git_rebase_finish",
"(",
"rebase",
".",
"p... | // Finish finishes a rebase that is currently in progress once all patches have been applied. | [
"Finish",
"finishes",
"a",
"rebase",
"that",
"is",
"currently",
"in",
"progress",
"once",
"all",
"patches",
"have",
"been",
"applied",
"."
] | bf1e8a4338822ad2539a3876f58b15b590eb9e1f | https://github.com/libgit2/git2go/blob/bf1e8a4338822ad2539a3876f58b15b590eb9e1f/rebase.go#L259-L270 | train |
libgit2/git2go | rebase.go | Abort | func (rebase *Rebase) Abort() error {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
err := C.git_rebase_abort(rebase.ptr)
runtime.KeepAlive(rebase)
if err < 0 {
return MakeGitError(err)
}
return nil
} | go | func (rebase *Rebase) Abort() error {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
err := C.git_rebase_abort(rebase.ptr)
runtime.KeepAlive(rebase)
if err < 0 {
return MakeGitError(err)
}
return nil
} | [
"func",
"(",
"rebase",
"*",
"Rebase",
")",
"Abort",
"(",
")",
"error",
"{",
"runtime",
".",
"LockOSThread",
"(",
")",
"\n",
"defer",
"runtime",
".",
"UnlockOSThread",
"(",
")",
"\n\n",
"err",
":=",
"C",
".",
"git_rebase_abort",
"(",
"rebase",
".",
"ptr... | // Abort aborts a rebase that is currently in progress, resetting the repository and working directory to their state before rebase began. | [
"Abort",
"aborts",
"a",
"rebase",
"that",
"is",
"currently",
"in",
"progress",
"resetting",
"the",
"repository",
"and",
"working",
"directory",
"to",
"their",
"state",
"before",
"rebase",
"began",
"."
] | bf1e8a4338822ad2539a3876f58b15b590eb9e1f | https://github.com/libgit2/git2go/blob/bf1e8a4338822ad2539a3876f58b15b590eb9e1f/rebase.go#L273-L283 | train |
libgit2/git2go | rebase.go | Free | func (rebase *Rebase) Free() {
runtime.SetFinalizer(rebase, nil)
C.git_rebase_free(rebase.ptr)
} | go | func (rebase *Rebase) Free() {
runtime.SetFinalizer(rebase, nil)
C.git_rebase_free(rebase.ptr)
} | [
"func",
"(",
"rebase",
"*",
"Rebase",
")",
"Free",
"(",
")",
"{",
"runtime",
".",
"SetFinalizer",
"(",
"rebase",
",",
"nil",
")",
"\n",
"C",
".",
"git_rebase_free",
"(",
"rebase",
".",
"ptr",
")",
"\n",
"}"
] | // Free frees the Rebase object. | [
"Free",
"frees",
"the",
"Rebase",
"object",
"."
] | bf1e8a4338822ad2539a3876f58b15b590eb9e1f | https://github.com/libgit2/git2go/blob/bf1e8a4338822ad2539a3876f58b15b590eb9e1f/rebase.go#L286-L289 | train |
libgit2/git2go | mempack.go | NewMempack | func NewMempack(odb *Odb) (mempack *Mempack, err error) {
mempack = new(Mempack)
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ret := C.git_mempack_new(&mempack.ptr)
if ret < 0 {
return nil, MakeGitError(ret)
}
ret = C.git_odb_add_backend(odb.ptr, mempack.ptr, C.int(999))
runtime.KeepAlive(odb)
if ret < 0 {
// Since git_odb_add_alternate() takes ownership of the ODB backend, the
// only case in which we free the mempack's memory is if it fails to be
// added to the ODB.
C._go_git_odb_backend_free(mempack.ptr)
return nil, MakeGitError(ret)
}
return mempack, nil
} | go | func NewMempack(odb *Odb) (mempack *Mempack, err error) {
mempack = new(Mempack)
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ret := C.git_mempack_new(&mempack.ptr)
if ret < 0 {
return nil, MakeGitError(ret)
}
ret = C.git_odb_add_backend(odb.ptr, mempack.ptr, C.int(999))
runtime.KeepAlive(odb)
if ret < 0 {
// Since git_odb_add_alternate() takes ownership of the ODB backend, the
// only case in which we free the mempack's memory is if it fails to be
// added to the ODB.
C._go_git_odb_backend_free(mempack.ptr)
return nil, MakeGitError(ret)
}
return mempack, nil
} | [
"func",
"NewMempack",
"(",
"odb",
"*",
"Odb",
")",
"(",
"mempack",
"*",
"Mempack",
",",
"err",
"error",
")",
"{",
"mempack",
"=",
"new",
"(",
"Mempack",
")",
"\n\n",
"runtime",
".",
"LockOSThread",
"(",
")",
"\n",
"defer",
"runtime",
".",
"UnlockOSThre... | // NewMempack creates a new mempack instance and registers it to the ODB. | [
"NewMempack",
"creates",
"a",
"new",
"mempack",
"instance",
"and",
"registers",
"it",
"to",
"the",
"ODB",
"."
] | bf1e8a4338822ad2539a3876f58b15b590eb9e1f | https://github.com/libgit2/git2go/blob/bf1e8a4338822ad2539a3876f58b15b590eb9e1f/mempack.go#L25-L47 | train |
libgit2/git2go | remote.go | Fetch | func (o *Remote) Fetch(refspecs []string, opts *FetchOptions, msg string) error {
var cmsg *C.char = nil
if msg != "" {
cmsg = C.CString(msg)
defer C.free(unsafe.Pointer(cmsg))
}
crefspecs := C.git_strarray{}
crefspecs.count = C.size_t(len(refspecs))
crefspecs.strings = makeCStringsFromStrings(refspecs)
defer freeStrarray(&crefspecs)
coptions := (*C.git_fetch_options)(C.calloc(1, C.size_t(unsafe.Sizeof(C.git_fetch_options{}))))
defer C.free(unsafe.Pointer(coptions))
populateFetchOptions(coptions, opts)
defer untrackCalbacksPayload(&coptions.callbacks)
defer freeStrarray(&coptions.custom_headers)
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ret := C.git_remote_fetch(o.ptr, &crefspecs, coptions, cmsg)
runtime.KeepAlive(o)
if ret < 0 {
return MakeGitError(ret)
}
return nil
} | go | func (o *Remote) Fetch(refspecs []string, opts *FetchOptions, msg string) error {
var cmsg *C.char = nil
if msg != "" {
cmsg = C.CString(msg)
defer C.free(unsafe.Pointer(cmsg))
}
crefspecs := C.git_strarray{}
crefspecs.count = C.size_t(len(refspecs))
crefspecs.strings = makeCStringsFromStrings(refspecs)
defer freeStrarray(&crefspecs)
coptions := (*C.git_fetch_options)(C.calloc(1, C.size_t(unsafe.Sizeof(C.git_fetch_options{}))))
defer C.free(unsafe.Pointer(coptions))
populateFetchOptions(coptions, opts)
defer untrackCalbacksPayload(&coptions.callbacks)
defer freeStrarray(&coptions.custom_headers)
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ret := C.git_remote_fetch(o.ptr, &crefspecs, coptions, cmsg)
runtime.KeepAlive(o)
if ret < 0 {
return MakeGitError(ret)
}
return nil
} | [
"func",
"(",
"o",
"*",
"Remote",
")",
"Fetch",
"(",
"refspecs",
"[",
"]",
"string",
",",
"opts",
"*",
"FetchOptions",
",",
"msg",
"string",
")",
"error",
"{",
"var",
"cmsg",
"*",
"C",
".",
"char",
"=",
"nil",
"\n",
"if",
"msg",
"!=",
"\"",
"\"",
... | // Fetch performs a fetch operation. refspecs specifies which refspecs
// to use for this fetch, use an empty list to use the refspecs from
// the configuration; msg specifies what to use for the reflog
// entries. Leave "" to use defaults. | [
"Fetch",
"performs",
"a",
"fetch",
"operation",
".",
"refspecs",
"specifies",
"which",
"refspecs",
"to",
"use",
"for",
"this",
"fetch",
"use",
"an",
"empty",
"list",
"to",
"use",
"the",
"refspecs",
"from",
"the",
"configuration",
";",
"msg",
"specifies",
"wh... | bf1e8a4338822ad2539a3876f58b15b590eb9e1f | https://github.com/libgit2/git2go/blob/bf1e8a4338822ad2539a3876f58b15b590eb9e1f/remote.go#L706-L734 | train |
libgit2/git2go | signature.go | Offset | func (v *Signature) Offset() int {
_, offset := v.When.Zone()
return offset / 60
} | go | func (v *Signature) Offset() int {
_, offset := v.When.Zone()
return offset / 60
} | [
"func",
"(",
"v",
"*",
"Signature",
")",
"Offset",
"(",
")",
"int",
"{",
"_",
",",
"offset",
":=",
"v",
".",
"When",
".",
"Zone",
"(",
")",
"\n",
"return",
"offset",
"/",
"60",
"\n",
"}"
] | // Offset returns the time zone offset of v.When in minutes, which is what git wants. | [
"Offset",
"returns",
"the",
"time",
"zone",
"offset",
"of",
"v",
".",
"When",
"in",
"minutes",
"which",
"is",
"what",
"git",
"wants",
"."
] | bf1e8a4338822ad2539a3876f58b15b590eb9e1f | https://github.com/libgit2/git2go/blob/bf1e8a4338822ad2539a3876f58b15b590eb9e1f/signature.go#L30-L33 | train |
libgit2/git2go | stash.go | Save | func (c *StashCollection) Save(
stasher *Signature, message string, flags StashFlag) (*Oid, error) {
oid := new(Oid)
stasherC, err := stasher.toC()
if err != nil {
return nil, err
}
defer C.git_signature_free(stasherC)
messageC := C.CString(message)
defer C.free(unsafe.Pointer(messageC))
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ret := C.git_stash_save(
oid.toC(), c.repo.ptr,
stasherC, messageC, C.uint32_t(flags))
runtime.KeepAlive(c)
if ret < 0 {
return nil, MakeGitError(ret)
}
return oid, nil
} | go | func (c *StashCollection) Save(
stasher *Signature, message string, flags StashFlag) (*Oid, error) {
oid := new(Oid)
stasherC, err := stasher.toC()
if err != nil {
return nil, err
}
defer C.git_signature_free(stasherC)
messageC := C.CString(message)
defer C.free(unsafe.Pointer(messageC))
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ret := C.git_stash_save(
oid.toC(), c.repo.ptr,
stasherC, messageC, C.uint32_t(flags))
runtime.KeepAlive(c)
if ret < 0 {
return nil, MakeGitError(ret)
}
return oid, nil
} | [
"func",
"(",
"c",
"*",
"StashCollection",
")",
"Save",
"(",
"stasher",
"*",
"Signature",
",",
"message",
"string",
",",
"flags",
"StashFlag",
")",
"(",
"*",
"Oid",
",",
"error",
")",
"{",
"oid",
":=",
"new",
"(",
"Oid",
")",
"\n\n",
"stasherC",
",",
... | // Save saves the local modifications to a new stash.
//
// Stasher is the identity of the person performing the stashing.
// Message is the optional description along with the stashed state.
// Flags control the stashing process and are given as bitwise OR. | [
"Save",
"saves",
"the",
"local",
"modifications",
"to",
"a",
"new",
"stash",
".",
"Stasher",
"is",
"the",
"identity",
"of",
"the",
"person",
"performing",
"the",
"stashing",
".",
"Message",
"is",
"the",
"optional",
"description",
"along",
"with",
"the",
"sta... | bf1e8a4338822ad2539a3876f58b15b590eb9e1f | https://github.com/libgit2/git2go/blob/bf1e8a4338822ad2539a3876f58b15b590eb9e1f/stash.go#L46-L71 | train |
libgit2/git2go | stash.go | DefaultStashApplyOptions | func DefaultStashApplyOptions() (StashApplyOptions, error) {
optsC := C.git_stash_apply_options{}
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ecode := C.git_stash_apply_init_options(&optsC, C.GIT_STASH_APPLY_OPTIONS_VERSION)
if ecode < 0 {
return StashApplyOptions{}, MakeGitError(ecode)
}
return StashApplyOptions{
Flags: StashApplyFlag(optsC.flags),
CheckoutOptions: checkoutOptionsFromC(&optsC.checkout_options),
}, nil
} | go | func DefaultStashApplyOptions() (StashApplyOptions, error) {
optsC := C.git_stash_apply_options{}
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ecode := C.git_stash_apply_init_options(&optsC, C.GIT_STASH_APPLY_OPTIONS_VERSION)
if ecode < 0 {
return StashApplyOptions{}, MakeGitError(ecode)
}
return StashApplyOptions{
Flags: StashApplyFlag(optsC.flags),
CheckoutOptions: checkoutOptionsFromC(&optsC.checkout_options),
}, nil
} | [
"func",
"DefaultStashApplyOptions",
"(",
")",
"(",
"StashApplyOptions",
",",
"error",
")",
"{",
"optsC",
":=",
"C",
".",
"git_stash_apply_options",
"{",
"}",
"\n\n",
"runtime",
".",
"LockOSThread",
"(",
")",
"\n",
"defer",
"runtime",
".",
"UnlockOSThread",
"("... | // DefaultStashApplyOptions initializes the structure with default values. | [
"DefaultStashApplyOptions",
"initializes",
"the",
"structure",
"with",
"default",
"values",
"."
] | bf1e8a4338822ad2539a3876f58b15b590eb9e1f | https://github.com/libgit2/git2go/blob/bf1e8a4338822ad2539a3876f58b15b590eb9e1f/stash.go#L148-L162 | train |
libgit2/git2go | stash.go | Foreach | func (c *StashCollection) Foreach(callback StashCallback) error {
data := stashCallbackData{
Callback: callback,
}
handle := pointerHandles.Track(&data)
defer pointerHandles.Untrack(handle)
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ret := C._go_git_stash_foreach(c.repo.ptr, handle)
runtime.KeepAlive(c)
if ret == C.GIT_EUSER {
return data.Error
}
if ret < 0 {
return MakeGitError(ret)
}
return nil
} | go | func (c *StashCollection) Foreach(callback StashCallback) error {
data := stashCallbackData{
Callback: callback,
}
handle := pointerHandles.Track(&data)
defer pointerHandles.Untrack(handle)
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ret := C._go_git_stash_foreach(c.repo.ptr, handle)
runtime.KeepAlive(c)
if ret == C.GIT_EUSER {
return data.Error
}
if ret < 0 {
return MakeGitError(ret)
}
return nil
} | [
"func",
"(",
"c",
"*",
"StashCollection",
")",
"Foreach",
"(",
"callback",
"StashCallback",
")",
"error",
"{",
"data",
":=",
"stashCallbackData",
"{",
"Callback",
":",
"callback",
",",
"}",
"\n\n",
"handle",
":=",
"pointerHandles",
".",
"Track",
"(",
"&",
... | // Foreach loops over all the stashed states and calls the callback
// for each one.
//
// If callback returns an error, this will stop looping. | [
"Foreach",
"loops",
"over",
"all",
"the",
"stashed",
"states",
"and",
"calls",
"the",
"callback",
"for",
"each",
"one",
".",
"If",
"callback",
"returns",
"an",
"error",
"this",
"will",
"stop",
"looping",
"."
] | bf1e8a4338822ad2539a3876f58b15b590eb9e1f | https://github.com/libgit2/git2go/blob/bf1e8a4338822ad2539a3876f58b15b590eb9e1f/stash.go#L274-L294 | train |
libgit2/git2go | stash.go | Drop | func (c *StashCollection) Drop(index int) error {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ret := C.git_stash_drop(c.repo.ptr, C.size_t(index))
runtime.KeepAlive(c)
if ret < 0 {
return MakeGitError(ret)
}
return nil
} | go | func (c *StashCollection) Drop(index int) error {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ret := C.git_stash_drop(c.repo.ptr, C.size_t(index))
runtime.KeepAlive(c)
if ret < 0 {
return MakeGitError(ret)
}
return nil
} | [
"func",
"(",
"c",
"*",
"StashCollection",
")",
"Drop",
"(",
"index",
"int",
")",
"error",
"{",
"runtime",
".",
"LockOSThread",
"(",
")",
"\n",
"defer",
"runtime",
".",
"UnlockOSThread",
"(",
")",
"\n\n",
"ret",
":=",
"C",
".",
"git_stash_drop",
"(",
"c... | // Drop removes a single stashed state from the stash list.
//
// 'index' is the position within the stash list. 0 points
// to the most recent stashed state.
//
// Returns error code ErrNotFound if there's no stashed
// state for the given index. | [
"Drop",
"removes",
"a",
"single",
"stashed",
"state",
"from",
"the",
"stash",
"list",
".",
"index",
"is",
"the",
"position",
"within",
"the",
"stash",
"list",
".",
"0",
"points",
"to",
"the",
"most",
"recent",
"stashed",
"state",
".",
"Returns",
"error",
... | bf1e8a4338822ad2539a3876f58b15b590eb9e1f | https://github.com/libgit2/git2go/blob/bf1e8a4338822ad2539a3876f58b15b590eb9e1f/stash.go#L303-L313 | train |
libgit2/git2go | handles.go | Track | func (v *HandleList) Track(pointer interface{}) unsafe.Pointer {
handle := C.malloc(1)
v.Lock()
v.handles[handle] = pointer
v.Unlock()
return handle
} | go | func (v *HandleList) Track(pointer interface{}) unsafe.Pointer {
handle := C.malloc(1)
v.Lock()
v.handles[handle] = pointer
v.Unlock()
return handle
} | [
"func",
"(",
"v",
"*",
"HandleList",
")",
"Track",
"(",
"pointer",
"interface",
"{",
"}",
")",
"unsafe",
".",
"Pointer",
"{",
"handle",
":=",
"C",
".",
"malloc",
"(",
"1",
")",
"\n\n",
"v",
".",
"Lock",
"(",
")",
"\n",
"v",
".",
"handles",
"[",
... | // Track adds the given pointer to the list of pointers to track and
// returns a pointer value which can be passed to C as an opaque
// pointer. | [
"Track",
"adds",
"the",
"given",
"pointer",
"to",
"the",
"list",
"of",
"pointers",
"to",
"track",
"and",
"returns",
"a",
"pointer",
"value",
"which",
"can",
"be",
"passed",
"to",
"C",
"as",
"an",
"opaque",
"pointer",
"."
] | bf1e8a4338822ad2539a3876f58b15b590eb9e1f | https://github.com/libgit2/git2go/blob/bf1e8a4338822ad2539a3876f58b15b590eb9e1f/handles.go#L28-L36 | train |
libgit2/git2go | handles.go | Untrack | func (v *HandleList) Untrack(handle unsafe.Pointer) {
v.Lock()
delete(v.handles, handle)
C.free(handle)
v.Unlock()
} | go | func (v *HandleList) Untrack(handle unsafe.Pointer) {
v.Lock()
delete(v.handles, handle)
C.free(handle)
v.Unlock()
} | [
"func",
"(",
"v",
"*",
"HandleList",
")",
"Untrack",
"(",
"handle",
"unsafe",
".",
"Pointer",
")",
"{",
"v",
".",
"Lock",
"(",
")",
"\n",
"delete",
"(",
"v",
".",
"handles",
",",
"handle",
")",
"\n",
"C",
".",
"free",
"(",
"handle",
")",
"\n",
... | // Untrack stops tracking the pointer given by the handle | [
"Untrack",
"stops",
"tracking",
"the",
"pointer",
"given",
"by",
"the",
"handle"
] | bf1e8a4338822ad2539a3876f58b15b590eb9e1f | https://github.com/libgit2/git2go/blob/bf1e8a4338822ad2539a3876f58b15b590eb9e1f/handles.go#L39-L44 | train |
libgit2/git2go | handles.go | Get | func (v *HandleList) Get(handle unsafe.Pointer) interface{} {
v.RLock()
defer v.RUnlock()
ptr, ok := v.handles[handle]
if !ok {
panic(fmt.Sprintf("invalid pointer handle: %p", handle))
}
return ptr
} | go | func (v *HandleList) Get(handle unsafe.Pointer) interface{} {
v.RLock()
defer v.RUnlock()
ptr, ok := v.handles[handle]
if !ok {
panic(fmt.Sprintf("invalid pointer handle: %p", handle))
}
return ptr
} | [
"func",
"(",
"v",
"*",
"HandleList",
")",
"Get",
"(",
"handle",
"unsafe",
".",
"Pointer",
")",
"interface",
"{",
"}",
"{",
"v",
".",
"RLock",
"(",
")",
"\n",
"defer",
"v",
".",
"RUnlock",
"(",
")",
"\n\n",
"ptr",
",",
"ok",
":=",
"v",
".",
"han... | // Get retrieves the pointer from the given handle | [
"Get",
"retrieves",
"the",
"pointer",
"from",
"the",
"given",
"handle"
] | bf1e8a4338822ad2539a3876f58b15b590eb9e1f | https://github.com/libgit2/git2go/blob/bf1e8a4338822ad2539a3876f58b15b590eb9e1f/handles.go#L47-L57 | train |
libgit2/git2go | index.go | NewIndex | func NewIndex() (*Index, error) {
var ptr *C.git_index
runtime.LockOSThread()
defer runtime.UnlockOSThread()
if err := C.git_index_new(&ptr); err < 0 {
return nil, MakeGitError(err)
}
return newIndexFromC(ptr, nil), nil
} | go | func NewIndex() (*Index, error) {
var ptr *C.git_index
runtime.LockOSThread()
defer runtime.UnlockOSThread()
if err := C.git_index_new(&ptr); err < 0 {
return nil, MakeGitError(err)
}
return newIndexFromC(ptr, nil), nil
} | [
"func",
"NewIndex",
"(",
")",
"(",
"*",
"Index",
",",
"error",
")",
"{",
"var",
"ptr",
"*",
"C",
".",
"git_index",
"\n\n",
"runtime",
".",
"LockOSThread",
"(",
")",
"\n",
"defer",
"runtime",
".",
"UnlockOSThread",
"(",
")",
"\n\n",
"if",
"err",
":=",... | // NewIndex allocates a new index. It won't be associated with any
// file on the filesystem or repository | [
"NewIndex",
"allocates",
"a",
"new",
"index",
".",
"It",
"won",
"t",
"be",
"associated",
"with",
"any",
"file",
"on",
"the",
"filesystem",
"or",
"repository"
] | bf1e8a4338822ad2539a3876f58b15b590eb9e1f | https://github.com/libgit2/git2go/blob/bf1e8a4338822ad2539a3876f58b15b590eb9e1f/index.go#L109-L120 | train |
libgit2/git2go | index.go | Path | func (v *Index) Path() string {
ret := C.GoString(C.git_index_path(v.ptr))
runtime.KeepAlive(v)
return ret
} | go | func (v *Index) Path() string {
ret := C.GoString(C.git_index_path(v.ptr))
runtime.KeepAlive(v)
return ret
} | [
"func",
"(",
"v",
"*",
"Index",
")",
"Path",
"(",
")",
"string",
"{",
"ret",
":=",
"C",
".",
"GoString",
"(",
"C",
".",
"git_index_path",
"(",
"v",
".",
"ptr",
")",
")",
"\n",
"runtime",
".",
"KeepAlive",
"(",
"v",
")",
"\n",
"return",
"ret",
"... | // Path returns the index' path on disk or an empty string if it
// exists only in memory. | [
"Path",
"returns",
"the",
"index",
"path",
"on",
"disk",
"or",
"an",
"empty",
"string",
"if",
"it",
"exists",
"only",
"in",
"memory",
"."
] | bf1e8a4338822ad2539a3876f58b15b590eb9e1f | https://github.com/libgit2/git2go/blob/bf1e8a4338822ad2539a3876f58b15b590eb9e1f/index.go#L142-L146 | train |
libgit2/git2go | index.go | Clear | func (v *Index) Clear() error {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
err := C.git_index_clear(v.ptr)
runtime.KeepAlive(v)
if err < 0 {
return MakeGitError(err)
}
return nil
} | go | func (v *Index) Clear() error {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
err := C.git_index_clear(v.ptr)
runtime.KeepAlive(v)
if err < 0 {
return MakeGitError(err)
}
return nil
} | [
"func",
"(",
"v",
"*",
"Index",
")",
"Clear",
"(",
")",
"error",
"{",
"runtime",
".",
"LockOSThread",
"(",
")",
"\n",
"defer",
"runtime",
".",
"UnlockOSThread",
"(",
")",
"\n\n",
"err",
":=",
"C",
".",
"git_index_clear",
"(",
"v",
".",
"ptr",
")",
... | // Clear clears the index object in memory; changes must be explicitly
// written to disk for them to take effect persistently | [
"Clear",
"clears",
"the",
"index",
"object",
"in",
"memory",
";",
"changes",
"must",
"be",
"explicitly",
"written",
"to",
"disk",
"for",
"them",
"to",
"take",
"effect",
"persistently"
] | bf1e8a4338822ad2539a3876f58b15b590eb9e1f | https://github.com/libgit2/git2go/blob/bf1e8a4338822ad2539a3876f58b15b590eb9e1f/index.go#L150-L160 | train |
libgit2/git2go | index.go | Add | func (v *Index) Add(entry *IndexEntry) error {
var centry C.git_index_entry
populateCIndexEntry(entry, ¢ry)
defer freeCIndexEntry(¢ry)
runtime.LockOSThread()
defer runtime.UnlockOSThread()
err := C.git_index_add(v.ptr, ¢ry)
runtime.KeepAlive(v)
if err < 0 {
return MakeGitError(err)
}
return nil
} | go | func (v *Index) Add(entry *IndexEntry) error {
var centry C.git_index_entry
populateCIndexEntry(entry, ¢ry)
defer freeCIndexEntry(¢ry)
runtime.LockOSThread()
defer runtime.UnlockOSThread()
err := C.git_index_add(v.ptr, ¢ry)
runtime.KeepAlive(v)
if err < 0 {
return MakeGitError(err)
}
return nil
} | [
"func",
"(",
"v",
"*",
"Index",
")",
"Add",
"(",
"entry",
"*",
"IndexEntry",
")",
"error",
"{",
"var",
"centry",
"C",
".",
"git_index_entry",
"\n\n",
"populateCIndexEntry",
"(",
"entry",
",",
"&",
"centry",
")",
"\n",
"defer",
"freeCIndexEntry",
"(",
"&"... | // Add adds or replaces the given entry to the index, making a copy of
// the data | [
"Add",
"adds",
"or",
"replaces",
"the",
"given",
"entry",
"to",
"the",
"index",
"making",
"a",
"copy",
"of",
"the",
"data"
] | bf1e8a4338822ad2539a3876f58b15b590eb9e1f | https://github.com/libgit2/git2go/blob/bf1e8a4338822ad2539a3876f58b15b590eb9e1f/index.go#L164-L180 | train |
libgit2/git2go | index.go | RemoveDirectory | func (v *Index) RemoveDirectory(dir string, stage int) error {
cstr := C.CString(dir)
defer C.free(unsafe.Pointer(cstr))
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ret := C.git_index_remove_directory(v.ptr, cstr, C.int(stage))
runtime.KeepAlive(v)
if ret < 0 {
return MakeGitError(ret)
}
return nil
} | go | func (v *Index) RemoveDirectory(dir string, stage int) error {
cstr := C.CString(dir)
defer C.free(unsafe.Pointer(cstr))
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ret := C.git_index_remove_directory(v.ptr, cstr, C.int(stage))
runtime.KeepAlive(v)
if ret < 0 {
return MakeGitError(ret)
}
return nil
} | [
"func",
"(",
"v",
"*",
"Index",
")",
"RemoveDirectory",
"(",
"dir",
"string",
",",
"stage",
"int",
")",
"error",
"{",
"cstr",
":=",
"C",
".",
"CString",
"(",
"dir",
")",
"\n",
"defer",
"C",
".",
"free",
"(",
"unsafe",
".",
"Pointer",
"(",
"cstr",
... | // RemoveDirectory removes all entries from the index under a given directory. | [
"RemoveDirectory",
"removes",
"all",
"entries",
"from",
"the",
"index",
"under",
"a",
"given",
"directory",
"."
] | bf1e8a4338822ad2539a3876f58b15b590eb9e1f | https://github.com/libgit2/git2go/blob/bf1e8a4338822ad2539a3876f58b15b590eb9e1f/index.go#L306-L320 | train |
libgit2/git2go | index.go | ReadTree | func (v *Index) ReadTree(tree *Tree) error {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ret := C.git_index_read_tree(v.ptr, tree.cast_ptr)
runtime.KeepAlive(v)
runtime.KeepAlive(tree)
if ret < 0 {
return MakeGitError(ret)
}
return nil
} | go | func (v *Index) ReadTree(tree *Tree) error {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ret := C.git_index_read_tree(v.ptr, tree.cast_ptr)
runtime.KeepAlive(v)
runtime.KeepAlive(tree)
if ret < 0 {
return MakeGitError(ret)
}
return nil
} | [
"func",
"(",
"v",
"*",
"Index",
")",
"ReadTree",
"(",
"tree",
"*",
"Tree",
")",
"error",
"{",
"runtime",
".",
"LockOSThread",
"(",
")",
"\n",
"defer",
"runtime",
".",
"UnlockOSThread",
"(",
")",
"\n\n",
"ret",
":=",
"C",
".",
"git_index_read_tree",
"("... | // ReadTree replaces the contents of the index with those of the given
// tree | [
"ReadTree",
"replaces",
"the",
"contents",
"of",
"the",
"index",
"with",
"those",
"of",
"the",
"given",
"tree"
] | bf1e8a4338822ad2539a3876f58b15b590eb9e1f | https://github.com/libgit2/git2go/blob/bf1e8a4338822ad2539a3876f58b15b590eb9e1f/index.go#L340-L352 | train |
libgit2/git2go | describe.go | DefaultDescribeOptions | func DefaultDescribeOptions() (DescribeOptions, error) {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
opts := C.git_describe_options{}
ecode := C.git_describe_init_options(&opts, C.GIT_DESCRIBE_OPTIONS_VERSION)
if ecode < 0 {
return DescribeOptions{}, MakeGitError(ecode)
}
return DescribeOptions{
MaxCandidatesTags: uint(opts.max_candidates_tags),
Strategy: DescribeOptionsStrategy(opts.describe_strategy),
}, nil
} | go | func DefaultDescribeOptions() (DescribeOptions, error) {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
opts := C.git_describe_options{}
ecode := C.git_describe_init_options(&opts, C.GIT_DESCRIBE_OPTIONS_VERSION)
if ecode < 0 {
return DescribeOptions{}, MakeGitError(ecode)
}
return DescribeOptions{
MaxCandidatesTags: uint(opts.max_candidates_tags),
Strategy: DescribeOptionsStrategy(opts.describe_strategy),
}, nil
} | [
"func",
"DefaultDescribeOptions",
"(",
")",
"(",
"DescribeOptions",
",",
"error",
")",
"{",
"runtime",
".",
"LockOSThread",
"(",
")",
"\n",
"defer",
"runtime",
".",
"UnlockOSThread",
"(",
")",
"\n\n",
"opts",
":=",
"C",
".",
"git_describe_options",
"{",
"}",... | // DefaultDescribeOptions returns default options for the describe operation. | [
"DefaultDescribeOptions",
"returns",
"default",
"options",
"for",
"the",
"describe",
"operation",
"."
] | bf1e8a4338822ad2539a3876f58b15b590eb9e1f | https://github.com/libgit2/git2go/blob/bf1e8a4338822ad2539a3876f58b15b590eb9e1f/describe.go#L41-L55 | train |
libgit2/git2go | describe.go | DefaultDescribeFormatOptions | func DefaultDescribeFormatOptions() (DescribeFormatOptions, error) {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
opts := C.git_describe_format_options{}
ecode := C.git_describe_init_format_options(&opts, C.GIT_DESCRIBE_FORMAT_OPTIONS_VERSION)
if ecode < 0 {
return DescribeFormatOptions{}, MakeGitError(ecode)
}
return DescribeFormatOptions{
AbbreviatedSize: uint(opts.abbreviated_size),
AlwaysUseLongFormat: opts.always_use_long_format == 1,
}, nil
} | go | func DefaultDescribeFormatOptions() (DescribeFormatOptions, error) {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
opts := C.git_describe_format_options{}
ecode := C.git_describe_init_format_options(&opts, C.GIT_DESCRIBE_FORMAT_OPTIONS_VERSION)
if ecode < 0 {
return DescribeFormatOptions{}, MakeGitError(ecode)
}
return DescribeFormatOptions{
AbbreviatedSize: uint(opts.abbreviated_size),
AlwaysUseLongFormat: opts.always_use_long_format == 1,
}, nil
} | [
"func",
"DefaultDescribeFormatOptions",
"(",
")",
"(",
"DescribeFormatOptions",
",",
"error",
")",
"{",
"runtime",
".",
"LockOSThread",
"(",
")",
"\n",
"defer",
"runtime",
".",
"UnlockOSThread",
"(",
")",
"\n\n",
"opts",
":=",
"C",
".",
"git_describe_format_opti... | // DefaultDescribeFormatOptions returns default options for formatting
// the output. | [
"DefaultDescribeFormatOptions",
"returns",
"default",
"options",
"for",
"formatting",
"the",
"output",
"."
] | bf1e8a4338822ad2539a3876f58b15b590eb9e1f | https://github.com/libgit2/git2go/blob/bf1e8a4338822ad2539a3876f58b15b590eb9e1f/describe.go#L75-L89 | train |
libgit2/git2go | describe.go | Format | func (result *DescribeResult) Format(opts *DescribeFormatOptions) (string, error) {
resultBuf := C.git_buf{}
var cFormatOpts *C.git_describe_format_options
if opts != nil {
cDirtySuffix := C.CString(opts.DirtySuffix)
defer C.free(unsafe.Pointer(cDirtySuffix))
cFormatOpts = &C.git_describe_format_options{
version: C.GIT_DESCRIBE_FORMAT_OPTIONS_VERSION,
abbreviated_size: C.uint(opts.AbbreviatedSize),
always_use_long_format: cbool(opts.AlwaysUseLongFormat),
dirty_suffix: cDirtySuffix,
}
}
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ecode := C.git_describe_format(&resultBuf, result.ptr, cFormatOpts)
runtime.KeepAlive(result)
if ecode < 0 {
return "", MakeGitError(ecode)
}
defer C.git_buf_dispose(&resultBuf)
return C.GoString(resultBuf.ptr), nil
} | go | func (result *DescribeResult) Format(opts *DescribeFormatOptions) (string, error) {
resultBuf := C.git_buf{}
var cFormatOpts *C.git_describe_format_options
if opts != nil {
cDirtySuffix := C.CString(opts.DirtySuffix)
defer C.free(unsafe.Pointer(cDirtySuffix))
cFormatOpts = &C.git_describe_format_options{
version: C.GIT_DESCRIBE_FORMAT_OPTIONS_VERSION,
abbreviated_size: C.uint(opts.AbbreviatedSize),
always_use_long_format: cbool(opts.AlwaysUseLongFormat),
dirty_suffix: cDirtySuffix,
}
}
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ecode := C.git_describe_format(&resultBuf, result.ptr, cFormatOpts)
runtime.KeepAlive(result)
if ecode < 0 {
return "", MakeGitError(ecode)
}
defer C.git_buf_dispose(&resultBuf)
return C.GoString(resultBuf.ptr), nil
} | [
"func",
"(",
"result",
"*",
"DescribeResult",
")",
"Format",
"(",
"opts",
"*",
"DescribeFormatOptions",
")",
"(",
"string",
",",
"error",
")",
"{",
"resultBuf",
":=",
"C",
".",
"git_buf",
"{",
"}",
"\n\n",
"var",
"cFormatOpts",
"*",
"C",
".",
"git_descri... | // Format prints the DescribeResult as a string. | [
"Format",
"prints",
"the",
"DescribeResult",
"as",
"a",
"string",
"."
] | bf1e8a4338822ad2539a3876f58b15b590eb9e1f | https://github.com/libgit2/git2go/blob/bf1e8a4338822ad2539a3876f58b15b590eb9e1f/describe.go#L191-L218 | train |
libgit2/git2go | describe.go | Free | func (result *DescribeResult) Free() {
runtime.SetFinalizer(result, nil)
C.git_describe_result_free(result.ptr)
result.ptr = nil
} | go | func (result *DescribeResult) Free() {
runtime.SetFinalizer(result, nil)
C.git_describe_result_free(result.ptr)
result.ptr = nil
} | [
"func",
"(",
"result",
"*",
"DescribeResult",
")",
"Free",
"(",
")",
"{",
"runtime",
".",
"SetFinalizer",
"(",
"result",
",",
"nil",
")",
"\n",
"C",
".",
"git_describe_result_free",
"(",
"result",
".",
"ptr",
")",
"\n",
"result",
".",
"ptr",
"=",
"nil"... | // Free cleans up the C reference. | [
"Free",
"cleans",
"up",
"the",
"C",
"reference",
"."
] | bf1e8a4338822ad2539a3876f58b15b590eb9e1f | https://github.com/libgit2/git2go/blob/bf1e8a4338822ad2539a3876f58b15b590eb9e1f/describe.go#L221-L225 | train |
libgit2/git2go | tag.go | Foreach | func (c *TagsCollection) Foreach(callback TagForeachCallback) error {
data := tagForeachData{
callback: callback,
err: nil,
}
handle := pointerHandles.Track(&data)
defer pointerHandles.Untrack(handle)
runtime.LockOSThread()
defer runtime.UnlockOSThread()
err := C._go_git_tag_foreach(c.repo.ptr, handle)
runtime.KeepAlive(c)
if err == C.GIT_EUSER {
return data.err
}
if err < 0 {
return MakeGitError(err)
}
return nil
} | go | func (c *TagsCollection) Foreach(callback TagForeachCallback) error {
data := tagForeachData{
callback: callback,
err: nil,
}
handle := pointerHandles.Track(&data)
defer pointerHandles.Untrack(handle)
runtime.LockOSThread()
defer runtime.UnlockOSThread()
err := C._go_git_tag_foreach(c.repo.ptr, handle)
runtime.KeepAlive(c)
if err == C.GIT_EUSER {
return data.err
}
if err < 0 {
return MakeGitError(err)
}
return nil
} | [
"func",
"(",
"c",
"*",
"TagsCollection",
")",
"Foreach",
"(",
"callback",
"TagForeachCallback",
")",
"error",
"{",
"data",
":=",
"tagForeachData",
"{",
"callback",
":",
"callback",
",",
"err",
":",
"nil",
",",
"}",
"\n\n",
"handle",
":=",
"pointerHandles",
... | // Foreach calls the callback for each tag in the repository. | [
"Foreach",
"calls",
"the",
"callback",
"for",
"each",
"tag",
"in",
"the",
"repository",
"."
] | bf1e8a4338822ad2539a3876f58b15b590eb9e1f | https://github.com/libgit2/git2go/blob/bf1e8a4338822ad2539a3876f58b15b590eb9e1f/tag.go#L223-L245 | train |
libgit2/git2go | reference.go | EnsureLog | func (c *ReferenceCollection) EnsureLog(name string) error {
cname := C.CString(name)
defer C.free(unsafe.Pointer(cname))
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ret := C.git_reference_ensure_log(c.repo.ptr, cname)
runtime.KeepAlive(c)
if ret < 0 {
return MakeGitError(ret)
}
return nil
} | go | func (c *ReferenceCollection) EnsureLog(name string) error {
cname := C.CString(name)
defer C.free(unsafe.Pointer(cname))
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ret := C.git_reference_ensure_log(c.repo.ptr, cname)
runtime.KeepAlive(c)
if ret < 0 {
return MakeGitError(ret)
}
return nil
} | [
"func",
"(",
"c",
"*",
"ReferenceCollection",
")",
"EnsureLog",
"(",
"name",
"string",
")",
"error",
"{",
"cname",
":=",
"C",
".",
"CString",
"(",
"name",
")",
"\n",
"defer",
"C",
".",
"free",
"(",
"unsafe",
".",
"Pointer",
"(",
"cname",
")",
")",
... | // EnsureLog ensures that there is a reflog for the given reference
// name and creates an empty one if necessary. | [
"EnsureLog",
"ensures",
"that",
"there",
"is",
"a",
"reflog",
"for",
"the",
"given",
"reference",
"name",
"and",
"creates",
"an",
"empty",
"one",
"if",
"necessary",
"."
] | bf1e8a4338822ad2539a3876f58b15b590eb9e1f | https://github.com/libgit2/git2go/blob/bf1e8a4338822ad2539a3876f58b15b590eb9e1f/reference.go#L103-L117 | train |
libgit2/git2go | reference.go | HasLog | func (c *ReferenceCollection) HasLog(name string) (bool, error) {
cname := C.CString(name)
defer C.free(unsafe.Pointer(cname))
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ret := C.git_reference_has_log(c.repo.ptr, cname)
runtime.KeepAlive(c)
if ret < 0 {
return false, MakeGitError(ret)
}
return ret == 1, nil
} | go | func (c *ReferenceCollection) HasLog(name string) (bool, error) {
cname := C.CString(name)
defer C.free(unsafe.Pointer(cname))
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ret := C.git_reference_has_log(c.repo.ptr, cname)
runtime.KeepAlive(c)
if ret < 0 {
return false, MakeGitError(ret)
}
return ret == 1, nil
} | [
"func",
"(",
"c",
"*",
"ReferenceCollection",
")",
"HasLog",
"(",
"name",
"string",
")",
"(",
"bool",
",",
"error",
")",
"{",
"cname",
":=",
"C",
".",
"CString",
"(",
"name",
")",
"\n",
"defer",
"C",
".",
"free",
"(",
"unsafe",
".",
"Pointer",
"(",... | // HasLog returns whether there is a reflog for the given reference
// name | [
"HasLog",
"returns",
"whether",
"there",
"is",
"a",
"reflog",
"for",
"the",
"given",
"reference",
"name"
] | bf1e8a4338822ad2539a3876f58b15b590eb9e1f | https://github.com/libgit2/git2go/blob/bf1e8a4338822ad2539a3876f58b15b590eb9e1f/reference.go#L121-L135 | train |
libgit2/git2go | reference.go | Dwim | func (c *ReferenceCollection) Dwim(name string) (*Reference, error) {
cname := C.CString(name)
defer C.free(unsafe.Pointer(cname))
runtime.LockOSThread()
defer runtime.UnlockOSThread()
var ptr *C.git_reference
ret := C.git_reference_dwim(&ptr, c.repo.ptr, cname)
runtime.KeepAlive(c)
if ret < 0 {
return nil, MakeGitError(ret)
}
return newReferenceFromC(ptr, c.repo), nil
} | go | func (c *ReferenceCollection) Dwim(name string) (*Reference, error) {
cname := C.CString(name)
defer C.free(unsafe.Pointer(cname))
runtime.LockOSThread()
defer runtime.UnlockOSThread()
var ptr *C.git_reference
ret := C.git_reference_dwim(&ptr, c.repo.ptr, cname)
runtime.KeepAlive(c)
if ret < 0 {
return nil, MakeGitError(ret)
}
return newReferenceFromC(ptr, c.repo), nil
} | [
"func",
"(",
"c",
"*",
"ReferenceCollection",
")",
"Dwim",
"(",
"name",
"string",
")",
"(",
"*",
"Reference",
",",
"error",
")",
"{",
"cname",
":=",
"C",
".",
"CString",
"(",
"name",
")",
"\n",
"defer",
"C",
".",
"free",
"(",
"unsafe",
".",
"Pointe... | // Dwim looks up a reference by DWIMing its short name | [
"Dwim",
"looks",
"up",
"a",
"reference",
"by",
"DWIMing",
"its",
"short",
"name"
] | bf1e8a4338822ad2539a3876f58b15b590eb9e1f | https://github.com/libgit2/git2go/blob/bf1e8a4338822ad2539a3876f58b15b590eb9e1f/reference.go#L138-L153 | train |
Subsets and Splits
SQL Console for semeru/code-text-go
Retrieves a limited set of code samples with their languages, with a specific case adjustment for 'Go' language.