forked from tangled.org/core
Monorepo for Tangled

knotserver: git: remove MergeBase calculation

the rev-list approach to building format-patch internally performs
merge-base calculations.

Signed-off-by: oppiliappan <me@oppi.li>

authored by oppi.li and committed by Tangled ef1a54aa 1e4fe088

Changed files
+3 -34
knotserver
types
+1 -24
knotserver/git/diff.go
··· 166 return stdout.String(), &formatPatch[0], nil 167 } 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 func (g *GitRepo) ResolveRevision(revStr string) (*object.Commit, error) { 192 rev, err := g.r.ResolveRevision(plumbing.Revision(revStr)) 193 if err != nil { ··· 224 if err != nil { 225 continue 226 } 227 - 228 commits = append(commits, obj) 229 } 230 ··· 232 } 233 234 func (g *GitRepo) FormatPatch(base, commit2 *object.Commit) (string, []types.FormatPatch, error) { 235 - // get list of commits between commir2 and base 236 commits, err := g.commitsBetween(commit2, base) 237 if err != nil { 238 return "", nil, fmt.Errorf("failed to get commits: %w", err)
··· 166 return stdout.String(), &formatPatch[0], nil 167 } 168 169 func (g *GitRepo) ResolveRevision(revStr string) (*object.Commit, error) { 170 rev, err := g.r.ResolveRevision(plumbing.Revision(revStr)) 171 if err != nil { ··· 202 if err != nil { 203 continue 204 } 205 commits = append(commits, obj) 206 } 207 ··· 209 } 210 211 func (g *GitRepo) FormatPatch(base, commit2 *object.Commit) (string, []types.FormatPatch, error) { 212 + // get list of commits between commit2 and base 213 commits, err := g.commitsBetween(commit2, base) 214 if err != nil { 215 return "", nil, fmt.Errorf("failed to get commits: %w", err)
+1 -9
knotserver/routes.go
··· 1109 return 1110 } 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) 1120 if err != nil { 1121 l.Error("error comparing revisions", "msg", err.Error()) 1122 writeError(w, "error comparing revisions", http.StatusBadRequest) ··· 1127 Rev1: commit1.Hash.String(), 1128 Rev2: commit2.Hash.String(), 1129 FormatPatch: formatPatch, 1130 - MergeBase: mergeBase.Hash.String(), 1131 Patch: rawPatch, 1132 }) 1133 return
··· 1109 return 1110 } 1111 1112 + rawPatch, formatPatch, err := gr.FormatPatch(commit1, commit2) 1113 if err != nil { 1114 l.Error("error comparing revisions", "msg", err.Error()) 1115 writeError(w, "error comparing revisions", http.StatusBadRequest) ··· 1120 Rev1: commit1.Hash.String(), 1121 Rev2: commit2.Hash.String(), 1122 FormatPatch: formatPatch, 1123 Patch: rawPatch, 1124 }) 1125 return
+1 -1
types/repo.go
··· 36 Rev1 string `json:"rev1,omitempty"` 37 Rev2 string `json:"rev2,omitempty"` 38 FormatPatch []FormatPatch `json:"format_patch,omitempty"` 39 - MergeBase string `json:"merge_base,omitempty"` 40 Patch string `json:"patch,omitempty"` 41 } 42
··· 36 Rev1 string `json:"rev1,omitempty"` 37 Rev2 string `json:"rev2,omitempty"` 38 FormatPatch []FormatPatch `json:"format_patch,omitempty"` 39 + MergeBase string `json:"merge_base,omitempty"` // deprecated 40 Patch string `json:"patch,omitempty"` 41 } 42