-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathdump.go
94 lines (79 loc) · 1.45 KB
/
dump.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
package main
import (
"bufio"
"context"
"fmt"
"os"
"strings"
"time"
"github.com/sinclairtarget/git-who/internal/git"
)
// Just prints out the output of git log as seen by git who.
func dump(
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 \"dump\": %w", err)
}
}()
logger().Debug(
"called revs()",
"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,
}
var subprocess *git.Subprocess
if short {
subprocess, err = git.RunLog(ctx, revs, paths, filters, false)
} else {
subprocess, err = git.RunLog(ctx, revs, paths, filters, true)
}
if err != nil {
return err
}
w := bufio.NewWriter(os.Stdout)
lines := subprocess.StdoutLogLines()
for line, err := range lines {
if err != nil {
w.Flush()
return err
}
lineWithNulls := strings.ReplaceAll(line, "\x00", "^@")
fmt.Fprintln(w, lineWithNulls)
}
w.Flush()
err = subprocess.Wait()
if err != nil {
return err
}
elapsed := time.Now().Sub(start)
logger().Debug("finished dump", "duration_ms", elapsed.Milliseconds())
return nil
}