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-24 13:59:32 +0300
committerDavid Kim <dkim@gitlab.com>2023-10-31 14:44:36 +0300
commitb313620dc67c333ed93a3a3d40eb7800e8b52ae8 (patch)
tree6b512a9ebeb493e3eb088ea22ec86c4efcef3034
parent5c97ae0d9c11b90e5680fd903a43f3a40db4d1b7 (diff)
Add Generated to Diff and add missing comments
-rw-r--r--internal/gitaly/diff/diff.go1
-rw-r--r--internal/gitaly/linguist/linguist.go2
-rw-r--r--internal/gitaly/service/diff/commit_diff_test.go41
3 files changed, 25 insertions, 19 deletions
diff --git a/internal/gitaly/diff/diff.go b/internal/gitaly/diff/diff.go
index 66075e5ed..a9c9490b2 100644
--- a/internal/gitaly/diff/diff.go
+++ b/internal/gitaly/diff/diff.go
@@ -18,6 +18,7 @@ type Diff struct {
Binary bool
OverflowMarker bool
Collapsed bool
+ Generated bool
TooLarge bool
CollectAllPaths bool
Status byte
diff --git a/internal/gitaly/linguist/linguist.go b/internal/gitaly/linguist/linguist.go
index 095818778..94183ae42 100644
--- a/internal/gitaly/linguist/linguist.go
+++ b/internal/gitaly/linguist/linguist.go
@@ -38,6 +38,7 @@ func New(logger log.Logger, catfileCache catfile.Cache, repo *localrepo.Repo) *I
}
}
+// NewWithGitAttributes creates a new instance with CheckAttrCmd
func NewWithGitAttributes(logger log.Logger, catfileCache catfile.Cache, repo *localrepo.Repo, ctx context.Context, revision git.Revision) (*Instance, func(), error) {
attrs := []string{linguistGenerated}
@@ -65,6 +66,7 @@ func Color(language string) string {
return fmt.Sprintf("#%x", colorSha[0:3])
}
+// IsGenerated returns true if the given file is considered to be generated
func (inst *Instance) IsGenerated(filename string, oid string) (bool, error) {
fileInstance, err := newFileInstance(filename, inst.checkAttrCmd)
if err != nil {
diff --git a/internal/gitaly/service/diff/commit_diff_test.go b/internal/gitaly/service/diff/commit_diff_test.go
index 5ab7a2eea..2b8b534ba 100644
--- a/internal/gitaly/service/diff/commit_diff_test.go
+++ b/internal/gitaly/service/diff/commit_diff_test.go
@@ -1060,6 +1060,7 @@ func TestCommitDiff_limits(t *testing.T) {
})
}
}
+
func TestCommitDiff_collapseGenerated(t *testing.T) {
t.Parallel()
@@ -1094,39 +1095,39 @@ func TestCommitDiff_collapseGenerated(t *testing.T) {
expectedResult []diffAttributes
}{
{
- desc: "forced by linguist-generated",
+ desc: "with both Collapse Generated and CollapseDiffs",
request: &gitalypb.CommitDiffRequest{CollapseGenerated: true, CollapseDiffs: true, SafeMaxLines: 9000, SafeMaxFiles: 9000, SafeMaxBytes: 9000},
expectedResult: []diffAttributes{
- {path: ".gitattributes", collapsed: false},
- {path: "Gopkg.lock", collapsed: true},
- {path: "abc.go", collapsed: true},
- {path: "abc.nib", collapsed: true},
- {path: "abc.txt", collapsed: true},
- {path: "package-lock.json", collapsed: false},
+ {path: ".gitattributes", collapsed: false, generated: false},
+ {path: "Gopkg.lock", collapsed: true, generated: true},
+ {path: "abc.go", collapsed: true, generated: true},
+ {path: "abc.nib", collapsed: true, generated: true},
+ {path: "abc.txt", collapsed: true, generated: true},
+ {path: "package-lock.json", collapsed: false, generated: false},
},
},
{
desc: "without CollapseDiffs options",
request: &gitalypb.CommitDiffRequest{CollapseGenerated: true},
expectedResult: []diffAttributes{
- {path: ".gitattributes", collapsed: false},
- {path: "Gopkg.lock", collapsed: false},
- {path: "abc.go", collapsed: false},
- {path: "abc.nib", collapsed: false},
- {path: "abc.txt", collapsed: false},
- {path: "package-lock.json", collapsed: false},
+ {path: ".gitattributes", collapsed: false, generated: false},
+ {path: "Gopkg.lock", collapsed: false, generated: false},
+ {path: "abc.go", collapsed: false, generated: false},
+ {path: "abc.nib", collapsed: false, generated: false},
+ {path: "abc.txt", collapsed: false, generated: false},
+ {path: "package-lock.json", collapsed: false, generated: false},
},
},
{
desc: "without CollapseGenerated option",
request: &gitalypb.CommitDiffRequest{CollapseDiffs: true, SafeMaxLines: 9000, SafeMaxFiles: 9000, SafeMaxBytes: 9000},
expectedResult: []diffAttributes{
- {path: ".gitattributes", collapsed: false},
- {path: "Gopkg.lock", collapsed: false},
- {path: "abc.go", collapsed: false},
- {path: "abc.nib", collapsed: false},
- {path: "abc.txt", collapsed: false},
- {path: "package-lock.json", collapsed: false},
+ {path: ".gitattributes", collapsed: false, generated: false},
+ {path: "Gopkg.lock", collapsed: false, generated: false},
+ {path: "abc.go", collapsed: false, generated: false},
+ {path: "abc.nib", collapsed: false, generated: false},
+ {path: "abc.txt", collapsed: false, generated: false},
+ {path: "package-lock.json", collapsed: false, generated: false},
},
},
} {
@@ -1150,6 +1151,7 @@ func TestCommitDiff_collapseGenerated(t *testing.T) {
require.Equal(t, expectedDiff.path, string(diff.FromPath), "%s path", diff.FromPath)
require.Equal(t, expectedDiff.collapsed, diff.Collapsed, "%s collapsed", diff.FromPath)
+ require.Equal(t, expectedDiff.generated, diff.Generated, "%s generated", diff.FromPath)
if expectedDiff.collapsed {
require.Empty(t, diff.Patch, "%s patch", diff.FromPath)
@@ -1259,6 +1261,7 @@ func getDiffsFromCommitDiffClient(t *testing.T, client gitalypb.DiffService_Comm
ToPath: fetchedDiff.ToPath,
Binary: fetchedDiff.Binary,
Collapsed: fetchedDiff.Collapsed,
+ Generated: fetchedDiff.Generated,
OverflowMarker: fetchedDiff.OverflowMarker,
Patch: fetchedDiff.RawPatchData,
TooLarge: fetchedDiff.TooLarge,