MCPcopy Create free account
hub / github.com/go-git/go-git / incBytes

Function incBytes

storage/filesystem/dotgit/dotgit.go:1244–1255  ·  view source on GitHub ↗

incBytes increments a byte slice, which involves incrementing the right-most byte, and following carry leftward. It makes a copy so that the provided slice's underlying array is not modified. If the overall operation overflows (e.g. incBytes(0xff, 0xff)), the second return parameter indicates that.

(in []byte)

Source from the content-addressed store, hash-verified

1242// It makes a copy so that the provided slice's underlying array is not modified.
1243// If the overall operation overflows (e.g. incBytes(0xff, 0xff)), the second return parameter indicates that.
1244func incBytes(in []byte) (out []byte, overflow bool) {
1245 out = make([]byte, len(in))
1246 copy(out, in)
1247 for i := len(out) - 1; i >= 0; i-- {
1248 out[i]++
1249 if out[i] != 0 {
1250 return // Didn't overflow.
1251 }
1252 }
1253 overflow = true
1254 return
1255}

Callers 2

ObjectsWithPrefixMethod · 0.85
TestIncBytesMethod · 0.85

Calls

no outgoing calls

Tested by 1

TestIncBytesMethod · 0.68