-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathparse.go
103 lines (85 loc) · 1.52 KB
/
parse.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package main
import (
"bufio"
"context"
"fmt"
"os"
"time"
"github.com/sinclairtarget/git-who/internal/git"
)
// Just prints out a simple representation of the commits parsed from `git log`
// for debugging.
func parse(
revs []string,
paths []string,
short bool,
since string,
until string,
authors []string,
nauthors []string,
) (err error) {
defer func() {
if err != nil {
err = fmt.Errorf("error running \"parse\": %w", err)
}
}()
logger().Debug(
"called parse()",
"revs",
revs,
"paths",
paths,
"short",
short,
"since",
since,
"until",
until,
"authors",
authors,
"nauthors",
nauthors,
)
start := time.Now()
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
filters := git.LogFilters{
Since: since,
Until: until,
Authors: authors,
Nauthors: nauthors,
}
commits, closer, err := git.CommitsWithOpts(
ctx,
revs,
paths,
filters,
!short,
)
if err != nil {
return err
}
w := bufio.NewWriter(os.Stdout)
numCommits := 0
for commit, err := range commits {
if err != nil {
w.Flush()
return fmt.Errorf("Error iterating commits: %w", err)
}
fmt.Fprintf(w, "%s\n", commit)
for _, diff := range commit.FileDiffs {
fmt.Fprintf(w, " %s\n", diff)
}
fmt.Fprintln(w)
numCommits += 1
}
w.Flush()
fmt.Printf("Parsed %d commits.\n", numCommits)
err = closer()
if err != nil {
return err
}
elapsed := time.Now().Sub(start)
logger().Debug("finished parse", "duration_ms", elapsed.Milliseconds())
return nil
}