+1
-24
knotserver/git/diff.go
+1
-24
knotserver/git/diff.go
···
166
166
return stdout.String(), &formatPatch[0], nil
167
167
}
168
168
169
-
func (g *GitRepo) MergeBase(commit1, commit2 *object.Commit) (*object.Commit, error) {
170
-
isAncestor, err := commit1.IsAncestor(commit2)
171
-
if err != nil {
172
-
return nil, err
173
-
}
174
-
175
-
if isAncestor {
176
-
return commit1, nil
177
-
}
178
-
179
-
mergeBase, err := commit1.MergeBase(commit2)
180
-
if err != nil {
181
-
return nil, err
182
-
}
183
-
184
-
if len(mergeBase) == 0 {
185
-
return nil, fmt.Errorf("failed to find a merge-base")
186
-
}
187
-
188
-
return mergeBase[0], nil
189
-
}
190
-
191
169
func (g *GitRepo) ResolveRevision(revStr string) (*object.Commit, error) {
192
170
rev, err := g.r.ResolveRevision(plumbing.Revision(revStr))
193
171
if err != nil {
···
224
202
if err != nil {
225
203
continue
226
204
}
227
-
228
205
commits = append(commits, obj)
229
206
}
230
207
···
232
209
}
233
210
234
211
func (g *GitRepo) FormatPatch(base, commit2 *object.Commit) (string, []types.FormatPatch, error) {
235
-
// get list of commits between commir2 and base
212
+
// get list of commits between commit2 and base
236
213
commits, err := g.commitsBetween(commit2, base)
237
214
if err != nil {
238
215
return "", nil, fmt.Errorf("failed to get commits: %w", err)
+1
-9
knotserver/routes.go
+1
-9
knotserver/routes.go
···
1109
1109
return
1110
1110
}
1111
1111
1112
-
mergeBase, err := gr.MergeBase(commit1, commit2)
1113
-
if err != nil {
1114
-
l.Error("failed to find merge-base", "msg", err.Error())
1115
-
writeError(w, "failed to calculate diff", http.StatusBadRequest)
1116
-
return
1117
-
}
1118
-
1119
-
rawPatch, formatPatch, err := gr.FormatPatch(mergeBase, commit2)
1112
+
rawPatch, formatPatch, err := gr.FormatPatch(commit1, commit2)
1120
1113
if err != nil {
1121
1114
l.Error("error comparing revisions", "msg", err.Error())
1122
1115
writeError(w, "error comparing revisions", http.StatusBadRequest)
···
1127
1120
Rev1: commit1.Hash.String(),
1128
1121
Rev2: commit2.Hash.String(),
1129
1122
FormatPatch: formatPatch,
1130
-
MergeBase: mergeBase.Hash.String(),
1131
1123
Patch: rawPatch,
1132
1124
})
1133
1125
return
+1
-1
types/repo.go
+1
-1
types/repo.go
···
36
36
Rev1 string `json:"rev1,omitempty"`
37
37
Rev2 string `json:"rev2,omitempty"`
38
38
FormatPatch []FormatPatch `json:"format_patch,omitempty"`
39
-
MergeBase string `json:"merge_base,omitempty"`
39
+
MergeBase string `json:"merge_base,omitempty"` // deprecated
40
40
Patch string `json:"patch,omitempty"`
41
41
}
42
42