(c commitgraph.CommitNode, treePath string, paths []string)
| 155 | } |
| 156 | |
| 157 | func 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] { |
no test coverage detected
searching dependent graphs…