OpenChainIndex expects a billy.Filesystem representing a .git directory. It will read a commit-graph chain file and return a coalesced index. If the chain file or a graph in that chain is not present, an error is returned. See: https://git-scm.com/docs/commit-graph
(fs billy.Filesystem)
| 67 | // |
| 68 | // See: https://git-scm.com/docs/commit-graph |
| 69 | func OpenChainIndex(fs billy.Filesystem) (Index, error) { |
| 70 | chainFile, err := fs.Open(path.Join("objects", "info", "commit-graphs", "commit-graph-chain")) |
| 71 | if err != nil { |
| 72 | return nil, err |
| 73 | } |
| 74 | |
| 75 | chain, err := OpenChainFile(chainFile) |
| 76 | _ = chainFile.Close() |
| 77 | if err != nil { |
| 78 | return nil, err |
| 79 | } |
| 80 | |
| 81 | var index Index |
| 82 | for _, hash := range chain { |
| 83 | |
| 84 | file, err := fs.Open(path.Join("objects", "info", "commit-graphs", "graph-"+hash+".graph")) |
| 85 | if err != nil { |
| 86 | // Ignore all other file closing errors and return the error from opening the last file in the graph |
| 87 | _ = index.Close() |
| 88 | return nil, err |
| 89 | } |
| 90 | |
| 91 | index, err = OpenFileIndexWithParent(file, index) |
| 92 | if err != nil { |
| 93 | // Ignore file closing errors and return the error from OpenFileIndex instead |
| 94 | _ = index.Close() |
| 95 | return nil, err |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | return index, nil |
| 100 | } |
no test coverage detected
searching dependent graphs…