Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Kim <dkim@gitlab.com>2023-10-18 11:22:40 +0300
committerDavid Kim <dkim@gitlab.com>2023-10-31 14:44:36 +0300
commitce1e201240ff2d4a692681cb995df1a8303b43eb (patch)
tree5391f7f69c2effce1588f6271955c4fa2776104a
parente501d39f116a9e1b9a54baef2a27afd3e2942e25 (diff)
Check CollapseGenerated flag first
-rw-r--r--internal/gitaly/service/diff/commit_diff.go23
-rw-r--r--internal/gitaly/service/diff/commit_diff_test.go14
2 files changed, 25 insertions, 12 deletions
diff --git a/internal/gitaly/service/diff/commit_diff.go b/internal/gitaly/service/diff/commit_diff.go
index d5b42c19b..439c8d70a 100644
--- a/internal/gitaly/service/diff/commit_diff.go
+++ b/internal/gitaly/service/diff/commit_diff.go
@@ -99,26 +99,29 @@ func (s *server) CommitDiff(in *gitalypb.CommitDiffRequest, stream gitalypb.Diff
TooLarge: diff.TooLarge,
}
- generated, err := linguist.IsGenerated(ctx, repo, git.Revision(leftSha), string(diff.ToPath), []byte(""))
- if err != nil {
- return structerr.NewAborted("send: %w", err)
- }
+ patch := diff.Patch
+
+ if in.CollapseGenerated {
+ linguistGenerated, err := linguist.IsGenerated(ctx, repo, git.Revision(leftSha), string(diff.FromPath), []byte(""))
+ if err != nil {
+ return structerr.NewAborted("send: %w", err)
+ }
- if len(diff.Patch) <= s.MsgSizeThreshold {
- if generated {
+ if linguistGenerated {
response.Generated = true
response.Collapsed = true
- } else {
- response.RawPatchData = diff.Patch
+ patch = nil
}
+ }
+
+ if len(patch) <= s.MsgSizeThreshold {
+ response.RawPatchData = patch
response.EndOfPatch = true
if err := stream.Send(response); err != nil {
return structerr.NewAborted("send: %w", err)
}
} else {
- patch := diff.Patch
-
for len(patch) > 0 {
if len(patch) > s.MsgSizeThreshold {
response.RawPatchData = patch[:s.MsgSizeThreshold]
diff --git a/internal/gitaly/service/diff/commit_diff_test.go b/internal/gitaly/service/diff/commit_diff_test.go
index 79de1751a..dbf3ff7a2 100644
--- a/internal/gitaly/service/diff/commit_diff_test.go
+++ b/internal/gitaly/service/diff/commit_diff_test.go
@@ -1093,7 +1093,7 @@ func TestCommitDiff_collapseGenerated(t *testing.T) {
}{
{
desc: "forced by linguist-generated",
- request: &gitalypb.CommitDiffRequest{},
+ request: &gitalypb.CommitDiffRequest{CollapseGenerated: true},
expectedResult: []diffAttributes{
{path: ".gitattributes", collapsed: false},
{path: "Gopkg.lock", collapsed: true},
@@ -1101,6 +1101,16 @@ func TestCommitDiff_collapseGenerated(t *testing.T) {
{path: "abc.txt", collapsed: true},
},
},
+ {
+ desc: "without CollapseGenerated",
+ request: &gitalypb.CommitDiffRequest{},
+ expectedResult: []diffAttributes{
+ {path: ".gitattributes", collapsed: false},
+ {path: "Gopkg.lock", collapsed: false},
+ {path: "abc.nib", collapsed: false},
+ {path: "abc.txt", collapsed: false},
+ },
+ },
} {
tc := tc
t.Run(tc.desc, func(t *testing.T) {
@@ -1124,7 +1134,7 @@ func TestCommitDiff_collapseGenerated(t *testing.T) {
require.Equal(t, expectedDiff.collapsed, diff.Collapsed, "%s collapsed", diff.FromPath)
if expectedDiff.collapsed {
- require.Empty(t, diff.Patch, "patch")
+ require.Empty(t, diff.Patch, "%s patch", diff.FromPath)
}
}
})