-
Notifications
You must be signed in to change notification settings - Fork 0
/
commits.go
57 lines (45 loc) · 1.05 KB
/
commits.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package main
import (
"io"
"github.com/go-git/go-git/v5/plumbing/object"
)
func CommitsWalk(commits object.CommitIter, fn func(prev, next *object.Commit, patch *object.Patch, i int) error, max int) (int, error) {
var commitsProcessed int
var prevCommit *object.Commit
for {
if commitsProcessed == max {
break
}
commit, err := commits.Next()
if err == io.EOF {
patch, err := prevCommit.Patch(nil)
if err != nil {
return commitsProcessed, err
}
err = fn(prevCommit, commit, patch, commitsProcessed)
if err != nil {
return commitsProcessed, err
}
commitsProcessed = commitsProcessed + 1
break
}
if err != nil {
return commitsProcessed, err
}
if prevCommit == nil {
prevCommit = commit
continue
}
patch, err := commit.Patch(prevCommit)
if err != nil {
return commitsProcessed, err
}
err = fn(prevCommit, commit, patch, commitsProcessed)
if err != nil {
return commitsProcessed, err
}
commitsProcessed = commitsProcessed + 1
prevCommit = commit
}
return commitsProcessed, nil
}