+27
-18
knotserver/git/post_receive.go
+27
-18
knotserver/git/post_receive.go
···
77
77
ByEmail: byEmail,
78
78
}
79
79
80
-
if !line.NewSha.IsZero() {
81
-
output, err := g.revList(
82
-
fmt.Sprintf("--max-count=%d", 100),
83
-
fmt.Sprintf("%s..%s", line.OldSha.String(), line.NewSha.String()),
84
-
)
85
-
if err != nil {
86
-
return commitCount, fmt.Errorf("failed to run rev-list: %w", err)
87
-
}
80
+
if line.NewSha.IsZero() {
81
+
return commitCount, nil
82
+
}
83
+
84
+
args := []string{fmt.Sprintf("--max-count=%d", 100)}
85
+
86
+
if line.OldSha.IsZero() {
87
+
// just git rev-list <newsha>
88
+
args = append(args, line.NewSha.String())
89
+
} else {
90
+
// git rev-list <oldsha>..<newsha>
91
+
args = append(args, fmt.Sprintf("%s..%s", line.OldSha.String(), line.NewSha.String()))
92
+
}
93
+
94
+
output, err := g.revList(args...)
95
+
if err != nil {
96
+
return commitCount, fmt.Errorf("failed to run rev-list: %w", err)
97
+
}
88
98
89
-
lines := strings.Split(strings.TrimSpace(string(output)), "\n")
90
-
if len(lines) == 1 && lines[0] == "" {
91
-
return commitCount, nil
92
-
}
99
+
lines := strings.Split(strings.TrimSpace(string(output)), "\n")
100
+
if len(lines) == 1 && lines[0] == "" {
101
+
return commitCount, nil
102
+
}
93
103
94
-
for _, item := range lines {
95
-
obj, err := g.r.CommitObject(plumbing.NewHash(item))
96
-
if err != nil {
97
-
continue
98
-
}
99
-
commitCount.ByEmail[obj.Author.Email] += 1
104
+
for _, item := range lines {
105
+
obj, err := g.r.CommitObject(plumbing.NewHash(item))
106
+
if err != nil {
107
+
continue
100
108
}
109
+
commitCount.ByEmail[obj.Author.Email] += 1
101
110
}
102
111
103
112
return commitCount, nil