()
| 57 | } |
| 58 | |
| 59 | func (c *commitPathIter) getNextFileCommit() (*Commit, error) { |
| 60 | var parentTree, currentTree *Tree |
| 61 | |
| 62 | for { |
| 63 | // Parent-commit can be nil if the current-commit is the initial commit |
| 64 | parentCommit, parentCommitErr := c.sourceIter.Next() |
| 65 | if parentCommitErr != nil { |
| 66 | // If the parent-commit is beyond the initial commit, keep it nil |
| 67 | if parentCommitErr != io.EOF { |
| 68 | return nil, parentCommitErr |
| 69 | } |
| 70 | parentCommit = nil |
| 71 | } |
| 72 | |
| 73 | if parentTree == nil { |
| 74 | var currTreeErr error |
| 75 | currentTree, currTreeErr = c.currentCommit.Tree() |
| 76 | if currTreeErr != nil { |
| 77 | return nil, currTreeErr |
| 78 | } |
| 79 | } else { |
| 80 | currentTree = parentTree |
| 81 | parentTree = nil |
| 82 | } |
| 83 | |
| 84 | if parentCommit != nil { |
| 85 | var parentTreeErr error |
| 86 | parentTree, parentTreeErr = parentCommit.Tree() |
| 87 | if parentTreeErr != nil { |
| 88 | return nil, parentTreeErr |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | // Find diff between current and parent trees |
| 93 | changes, diffErr := DiffTree(currentTree, parentTree) |
| 94 | if diffErr != nil { |
| 95 | return nil, diffErr |
| 96 | } |
| 97 | |
| 98 | found := c.hasFileChange(changes, parentCommit) |
| 99 | |
| 100 | // Storing the current-commit in-case a change is found, and |
| 101 | // Updating the current-commit for the next-iteration |
| 102 | prevCommit := c.currentCommit |
| 103 | c.currentCommit = parentCommit |
| 104 | |
| 105 | if found { |
| 106 | return prevCommit, nil |
| 107 | } |
| 108 | |
| 109 | // If not matches found and if parent-commit is beyond the initial commit, then return with EOF |
| 110 | if parentCommit == nil { |
| 111 | return nil, io.EOF |
| 112 | } |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | func (c *commitPathIter) hasFileChange(changes Changes, parent *Commit) bool { |
no test coverage detected