tangled
alpha
login
or
join now
back
round
2
view raw
knotserver: fix commit counting for branch creation
#447
merged
opened by
oppi.li
5 months ago
targeting
master
from
push-ytkuzknmmrmn
rev-list was over-counting
Signed-off-by: oppiliappan
me@oppi.li
options
unified
split
Changed files
+24
-14
knotserver
git
post_receive.go
internal.go
+19
-12
knotserver/git/post_receive.go
···
3
3
import (
4
4
"bufio"
5
5
"context"
6
6
+
"errors"
6
7
"fmt"
7
8
"io"
8
9
"strings"
···
57
58
ByEmail map[string]int
58
59
}
59
60
60
60
-
func (g *GitRepo) RefUpdateMeta(line PostReceiveLine) RefUpdateMeta {
61
61
+
func (g *GitRepo) RefUpdateMeta(line PostReceiveLine) (RefUpdateMeta, error) {
62
62
+
var errs error
63
63
+
61
64
commitCount, err := g.newCommitCount(line)
62
62
-
if err != nil {
63
63
-
// TODO: log this
64
64
-
}
65
65
+
errors.Join(errs, err)
65
66
66
67
isDefaultRef, err := g.isDefaultBranch(line)
67
67
-
if err != nil {
68
68
-
// TODO: log this
69
69
-
}
68
68
+
errors.Join(errs, err)
70
69
71
70
ctx, cancel := context.WithTimeout(context.Background(), time.Second*2)
72
71
defer cancel()
73
72
breakdown, err := g.AnalyzeLanguages(ctx)
74
74
-
if err != nil {
75
75
-
// TODO: log this
76
76
-
}
73
73
+
errors.Join(errs, err)
77
74
78
75
return RefUpdateMeta{
79
76
CommitCount: commitCount,
80
77
IsDefaultRef: isDefaultRef,
81
78
LangBreakdown: breakdown,
82
82
-
}
79
79
+
}, errs
83
80
}
84
81
85
82
func (g *GitRepo) newCommitCount(line PostReceiveLine) (CommitCount, error) {
···
95
92
args := []string{fmt.Sprintf("--max-count=%d", 100)}
96
93
97
94
if line.OldSha.IsZero() {
98
98
-
// just git rev-list <newsha>
95
95
+
// git rev-list <newsha> ^other-branches --not ^this-branch
99
96
args = append(args, line.NewSha.String())
97
97
+
98
98
+
branches, _ := g.Branches()
99
99
+
for _, b := range branches {
100
100
+
if !strings.Contains(line.Ref, b.Name) {
101
101
+
args = append(args, fmt.Sprintf("^%s", b.Name))
102
102
+
}
103
103
+
}
104
104
+
105
105
+
args = append(args, "--not")
106
106
+
args = append(args, fmt.Sprintf("^%s", line.Ref))
100
107
} else {
101
108
// git rev-list <oldsha>..<newsha>
102
109
args = append(args, fmt.Sprintf("%s..%s", line.OldSha.String(), line.NewSha.String()))
+5
-2
knotserver/internal.go
···
3
3
import (
4
4
"context"
5
5
"encoding/json"
6
6
+
"errors"
6
7
"fmt"
7
8
"log/slog"
8
9
"net/http"
···
145
146
return fmt.Errorf("failed to open git repo at ref %s: %w", line.Ref, err)
146
147
}
147
148
148
148
-
meta := gr.RefUpdateMeta(line)
149
149
+
var errs error
150
150
+
meta, err := gr.RefUpdateMeta(line)
151
151
+
errors.Join(errs, err)
149
152
150
153
metaRecord := meta.AsRecord()
151
154
···
169
172
EventJson: string(eventJson),
170
173
}
171
174
172
172
-
return h.db.InsertEvent(event, h.n)
175
175
+
return errors.Join(errs, h.db.InsertEvent(event, h.n))
173
176
}
174
177
175
178
func (h *InternalHandle) triggerPipeline(clientMsgs *[]string, line git.PostReceiveLine, gitUserDid, repoDid, repoName string, pushOptions PushOptions) error {