Monorepo for Tangled tangled.org
854
fork

Configure Feed

Select the types of activity you want to include in your feed.

knotserver,types: remove unused fields from repo.compare response #299

open opened by boltless.me targeting master from sl/suwkskkoykun
Labels

None yet.

assignee

None yet.

Participants 1
AT URI
at://did:plc:xasnlahkri4ewmbuzly2rlc5/sh.tangled.repo.pull/3mku2jgtqtu22
+7 -18
Diff #1
+5 -8
knotserver/git/diff.go
··· 200 200 return commits, nil 201 201 } 202 202 203 - func (g *GitRepo) FormatPatch(base, commit2 *object.Commit) (string, []types.FormatPatch, error) { 203 + func (g *GitRepo) FormatPatch(base, commit2 *object.Commit) (string, int, error) { 204 204 // get list of commits between commit2 and base 205 205 commits, err := g.commitsBetween(commit2, base) 206 206 if err != nil { 207 - return "", nil, fmt.Errorf("failed to get commits: %w", err) 207 + return "", 0, fmt.Errorf("failed to get commits: %w", err) 208 208 } 209 209 210 210 // reverse the list so we start from the oldest one and go up to the most recent one 211 211 slices.Reverse(commits) 212 212 213 213 var allPatchesContent strings.Builder 214 - var allPatches []types.FormatPatch 215 214 216 215 for _, commit := range commits { 217 216 changeId := "" ··· 224 223 additionalArgs = append(additionalArgs, "--add-header", fmt.Sprintf("Change-Id: %s", changeId)) 225 224 } 226 225 227 - stdout, patch, err := g.formatSinglePatch(commit.Hash, additionalArgs...) 226 + stdout, _, err := g.formatSinglePatch(commit.Hash, additionalArgs...) 228 227 if err != nil { 229 - return "", nil, fmt.Errorf("failed to format patch for commit %s: %w", commit.Hash.String(), err) 228 + return "", 0, fmt.Errorf("failed to format patch for commit %s: %w", commit.Hash.String(), err) 230 229 } 231 230 232 231 allPatchesContent.WriteString(stdout) 233 232 allPatchesContent.WriteString("\n") 234 - 235 - allPatches = append(allPatches, *patch) 236 233 } 237 234 238 - return allPatchesContent.String(), allPatches, nil 235 + return allPatchesContent.String(), len(commits), nil 239 236 }
+2 -7
knotserver/xrpc/repo_compare.go
··· 4 4 "fmt" 5 5 "net/http" 6 6 7 - "github.com/bluekeyes/go-gitdiff/gitdiff" 8 7 "tangled.org/core/knotserver/git" 9 8 "tangled.org/core/types" 10 9 xrpcerr "tangled.org/core/xrpc/errors" ··· 62 61 return 63 62 } 64 63 65 - rawPatch, formatPatch, err := gr.FormatPatch(commit1, commit2) 64 + rawPatch, patchCount, err := gr.FormatPatch(commit1, commit2) 66 65 if err != nil { 67 66 x.Logger.Error("error comparing revisions", "msg", err.Error()) 68 67 writeError(w, xrpcerr.NewXrpcError( ··· 72 71 return 73 72 } 74 73 75 - var combinedPatch []*gitdiff.File 76 74 var combinedPatchRaw string 77 75 // we need the combined patch 78 - if len(formatPatch) >= 2 { 76 + if patchCount > 1 { 79 77 mergeBaseCommit, err := gr.MergeBase(commit1, commit2) 80 78 if err != nil { 81 79 x.Logger.Error("error comparing revisions", "msg", err.Error()) ··· 84 82 if err != nil { 85 83 x.Logger.Error("error comparing revisions", "msg", err.Error()) 86 84 } else { 87 - combinedPatch = diffTree.Diff 88 85 combinedPatchRaw = diffTree.Patch 89 86 } 90 87 } ··· 93 90 response := types.RepoFormatPatchResponse{ 94 91 Rev1: commit1.Hash.String(), 95 92 Rev2: commit2.Hash.String(), 96 - FormatPatch: formatPatch, 97 93 FormatPatchRaw: rawPatch, 98 - CombinedPatch: combinedPatch, 99 94 CombinedPatchRaw: combinedPatchRaw, 100 95 } 101 96
-3
types/repo.go
··· 1 1 package types 2 2 3 3 import ( 4 - "github.com/bluekeyes/go-gitdiff/gitdiff" 5 4 "github.com/go-git/go-git/v5/plumbing/object" 6 5 ) 7 6 ··· 36 35 type RepoFormatPatchResponse struct { 37 36 Rev1 string `json:"rev1,omitempty"` 38 37 Rev2 string `json:"rev2,omitempty"` 39 - FormatPatch []FormatPatch `json:"format_patch,omitempty"` 40 38 FormatPatchRaw string `json:"patch,omitempty"` 41 - CombinedPatch []*gitdiff.File `json:"combined_patch,omitempty"` 42 39 CombinedPatchRaw string `json:"combined_patch_raw,omitempty"` 43 40 } 44 41

History

2 rounds 0 comments
sign up or login to add to the discussion
1 commit
expand
knotserver,types: remove unused fields from repo.compare response
no conflicts, ready to merge
expand 0 comments
1 commit
expand
knotserver,types: remove unused fields from repo.compare response
expand 0 comments