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)
| 16 | // |
| 17 | // This function simply reads the file and returns the hashes as a slice. |
| 18 | func 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 |
no test coverage detected
searching dependent graphs…