MCPcopy Index your code
hub / github.com/go-git/go-git / OpenChainFile

Function OpenChainFile

plumbing/format/commitgraph/v2/chain.go:18–40  ·  view source on GitHub ↗

OpenChainFile reads a commit chain file and returns a slice of the hashes within it Commit-Graph chains are described at https://git-scm.com/docs/commit-graph and are new line separated list of graph file hashes, oldest to newest. This function simply reads the file and returns the hashes as a sli

(r io.Reader)

Source from the content-addressed store, hash-verified

16//
17// This function simply reads the file and returns the hashes as a slice.
18func OpenChainFile(r io.Reader) ([]string, error) {
19 if r == nil {
20 return nil, io.ErrUnexpectedEOF
21 }
22 bufRd := bufio.NewReader(r)
23 chain := make([]string, 0, 8)
24 for {
25 line, err := bufRd.ReadSlice('\n')
26 if err != nil {
27 if err == io.EOF {
28 break
29 }
30 return nil, err
31 }
32
33 hashStr := string(line[:len(line)-1])
34 if !plumbing.IsHash(hashStr) {
35 return nil, ErrMalformedCommitGraphFile
36 }
37 chain = append(chain, hashStr)
38 }
39 return chain, nil
40}
41
42// OpenChainOrFileIndex expects a billy.Filesystem representing a .git directory.
43// It will first attempt to read a commit-graph index file, before trying to read a

Callers 1

OpenChainIndexFunction · 0.85

Calls 1

IsHashFunction · 0.92

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…