Monorepo for Tangled tangled.org

knotserver: git: improve formatSiglePatch to use builtin flag

there exists a git flag to generate patches for a single commit: -1. use
this instead of calculating the parent when preparing format-patches.

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

oppi.li 07a99af5 4cb4af22

verified
Changed files
+4 -10
knotserver
git
+4 -10
knotserver/git/diff.go
··· 134 134 135 135 // FormatPatch generates a git-format-patch output between two commits, 136 136 // and returns the raw format-patch series, a parsed FormatPatch and an error. 137 - func (g *GitRepo) formatSinglePatch(base, commit2 plumbing.Hash, extraArgs ...string) (string, *types.FormatPatch, error) { 137 + func (g *GitRepo) formatSinglePatch(commit plumbing.Hash, extraArgs ...string) (string, *types.FormatPatch, error) { 138 138 var stdout bytes.Buffer 139 139 140 140 args := []string{ 141 141 "-C", 142 142 g.path, 143 143 "format-patch", 144 - fmt.Sprintf("%s..%s", base.String(), commit2.String()), 144 + "-1", 145 + commit.String(), 145 146 "--stdout", 146 147 } 147 148 args = append(args, extraArgs...) ··· 227 228 changeId = string(val) 228 229 } 229 230 230 - var parentHash plumbing.Hash 231 - if len(commit.ParentHashes) > 0 { 232 - parentHash = commit.ParentHashes[0] 233 - } else { 234 - parentHash = plumbing.NewHash("4b825dc642cb6eb9a060e54bf8d69288fbee4904") // git empty tree hash 235 - } 236 - 237 231 var additionalArgs []string 238 232 if changeId != "" { 239 233 additionalArgs = append(additionalArgs, "--add-header", fmt.Sprintf("Change-Id: %s", changeId)) 240 234 } 241 235 242 - stdout, patch, err := g.formatSinglePatch(parentHash, commit.Hash, additionalArgs...) 236 + stdout, patch, err := g.formatSinglePatch(commit.Hash, additionalArgs...) 243 237 if err != nil { 244 238 return "", nil, fmt.Errorf("failed to format patch for commit %s: %w", commit.Hash.String(), err) 245 239 }