MCPcopy
hub / github.com/go-git/go-git / getLastCommitForPaths

Function getLastCommitForPaths

_examples/ls/main.go:157–272  ·  view source on GitHub ↗
(c commitgraph.CommitNode, treePath string, paths []string)

Source from the content-addressed store, hash-verified

155}
156
157func getLastCommitForPaths(c commitgraph.CommitNode, treePath string, paths []string) (map[string]*object.Commit, error) {
158 // We do a tree traversal with nodes sorted by commit time
159 heap := binaryheap.NewWith(func(a, b interface{}) int {
160 if a.(*commitAndPaths).commit.CommitTime().Before(b.(*commitAndPaths).commit.CommitTime()) {
161 return 1
162 }
163 return -1
164 })
165
166 resultNodes := make(map[string]commitgraph.CommitNode)
167 initialHashes, err := getFileHashes(c, treePath, paths)
168 if err != nil {
169 return nil, err
170 }
171
172 // Start search from the root commit and with full set of paths
173 heap.Push(&commitAndPaths{c, paths, initialHashes})
174
175 for {
176 cIn, ok := heap.Pop()
177 if !ok {
178 break
179 }
180 current := cIn.(*commitAndPaths)
181
182 // Load the parent commits for the one we are currently examining
183 numParents := current.commit.NumParents()
184 var parents []commitgraph.CommitNode
185 for i := 0; i < numParents; i++ {
186 parent, err := current.commit.ParentNode(i)
187 if err != nil {
188 break
189 }
190 parents = append(parents, parent)
191 }
192
193 // Examine the current commit and set of interesting paths
194 pathUnchanged := make([]bool, len(current.paths))
195 parentHashes := make([]map[string]plumbing.Hash, len(parents))
196 for j, parent := range parents {
197 parentHashes[j], err = getFileHashes(parent, treePath, current.paths)
198 if err != nil {
199 break
200 }
201
202 for i, path := range current.paths {
203 if parentHashes[j][path] == current.hashes[path] {
204 pathUnchanged[i] = true
205 }
206 }
207 }
208
209 var remainingPaths []string
210 for i, path := range current.paths {
211 // The results could already contain some newer change for the same path,
212 // so don't override that and bail out on the file early.
213 if resultNodes[path] == nil {
214 if pathUnchanged[i] {

Callers 1

mainFunction · 0.85

Calls 7

getFileHashesFunction · 0.85
CommitTimeMethod · 0.65
PushMethod · 0.65
PopMethod · 0.65
NumParentsMethod · 0.65
ParentNodeMethod · 0.65
CommitMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…