From 6de010e285904ad7b03edd2a8638e007b9b3a054 Mon Sep 17 00:00:00 2001 From: Vasilii Iakliushin Date: Sun, 31 Jan 2021 21:20:13 +0100 Subject: [PATCH 1/6] Add support for word-diff mode Contributes to https://gitlab.com/gitlab-org/gitlab/-/issues/324805 * Extend `CommitDiffRequest` with `wordDiff` field * Add testdata for word-diff outputs --- .../unreleased/16950_add_word_diff_mode.yml | 5 + internal/gitaly/diff/diff.go | 6 +- internal/gitaly/diff/diff_test.go | 67 +++++- internal/gitaly/service/diff/commit.go | 13 +- internal/gitaly/service/diff/commit_test.go | 183 ++++++++++++++++ .../word-diff/deleted-file-chunks.txt | 3 + .../file-with-multiple-chunks-chunks.txt | 199 ++++++++++++++++++ .../word-diff/file-with-pluses-chunks.txt | 11 + .../word-diff/mode-file-with-mods-chunks.txt | 10 + .../word-diff/named-file-with-mods-chunks.txt | 3 + .../no-newline-at-the-end-chunks.txt | 3 + .../testdata/word-diff/readme-md-chunks.txt | 9 + .../renamed-file-with-mods-chunks.txt | 3 + .../word-diff/tab-newline-file-chunks.txt | 3 + .../word-diff/z-short-diff-chunks.txt | 7 + proto/diff.proto | 2 +- proto/go/gitalypb/diff.pb.go | 137 ++++++------ ruby/proto/gitaly/diff_pb.rb | 1 + 18 files changed, 586 insertions(+), 79 deletions(-) create mode 100644 changelogs/unreleased/16950_add_word_diff_mode.yml create mode 100644 internal/gitaly/service/diff/testdata/word-diff/deleted-file-chunks.txt create mode 100644 internal/gitaly/service/diff/testdata/word-diff/file-with-multiple-chunks-chunks.txt create mode 100644 internal/gitaly/service/diff/testdata/word-diff/file-with-pluses-chunks.txt create mode 100644 internal/gitaly/service/diff/testdata/word-diff/mode-file-with-mods-chunks.txt create mode 100644 internal/gitaly/service/diff/testdata/word-diff/named-file-with-mods-chunks.txt create mode 100644 internal/gitaly/service/diff/testdata/word-diff/no-newline-at-the-end-chunks.txt create mode 100644 internal/gitaly/service/diff/testdata/word-diff/readme-md-chunks.txt create mode 100644 internal/gitaly/service/diff/testdata/word-diff/renamed-file-with-mods-chunks.txt create mode 100644 internal/gitaly/service/diff/testdata/word-diff/tab-newline-file-chunks.txt create mode 100644 internal/gitaly/service/diff/testdata/word-diff/z-short-diff-chunks.txt diff --git a/changelogs/unreleased/16950_add_word_diff_mode.yml b/changelogs/unreleased/16950_add_word_diff_mode.yml new file mode 100644 index 0000000000..2373ca1e40 --- /dev/null +++ b/changelogs/unreleased/16950_add_word_diff_mode.yml @@ -0,0 +1,5 @@ +--- +title: Add support for word-diff mode +merge_request: 3086 +author: +type: added diff --git a/internal/gitaly/diff/diff.go b/internal/gitaly/diff/diff.go index c9def42283..348cbe2b35 100644 --- a/internal/gitaly/diff/diff.go +++ b/internal/gitaly/diff/diff.go @@ -41,6 +41,7 @@ type Parser struct { linesProcessed int bytesProcessed int finished bool + wordDiff bool err error } @@ -91,7 +92,7 @@ var ( ) // NewDiffParser returns a new Parser -func NewDiffParser(src io.Reader, limits Limits) *Parser { +func NewDiffParser(src io.Reader, limits Limits, wordDiff bool) *Parser { limits.enforceUpperBound() parser := &Parser{} @@ -100,6 +101,7 @@ func NewDiffParser(src io.Reader, limits Limits) *Parser { parser.cacheRawLines(reader) parser.patchReader = reader parser.limits = limits + parser.wordDiff = wordDiff return parser } @@ -156,7 +158,7 @@ func (parser *Parser) Parse() bool { parser.consumeChunkLine(false) } else if helper.ByteSliceHasAnyPrefix(line, "---", "+++") && !parser.isParsingChunkLines() { parser.consumeLine(false) - } else if helper.ByteSliceHasAnyPrefix(line, "-", "+", " ", "\\", "Binary") { + } else if helper.ByteSliceHasAnyPrefix(line, "~", "-", "+", " ", "\\", "Binary") { parser.consumeChunkLine(true) } else { parser.consumeLine(false) diff --git a/internal/gitaly/diff/diff_test.go b/internal/gitaly/diff/diff_test.go index 17f24bfc5e..c788803778 100644 --- a/internal/gitaly/diff/diff_test.go +++ b/internal/gitaly/diff/diff_test.go @@ -40,7 +40,8 @@ index 0000000000000000000000000000000000000000..3be11c69355948412925fa5e073d76d5 MaxPatchBytes: 100000, CollapseDiffs: true, } - diffs := getDiffs(rawDiff, limits) + wordDiff := false + diffs := getDiffs(rawDiff, limits, wordDiff) expectedDiffs := []*Diff{ &Diff{ @@ -71,6 +72,53 @@ index 0000000000000000000000000000000000000000..3be11c69355948412925fa5e073d76d5 require.Equal(t, expectedDiffs, diffs) } +func TestDiffParserWithWordDiff(t *testing.T) { + rawDiff := `:000000 100644 0000000000000000000000000000000000000000 4cc7061661b8f52891bc1b39feb4d856b21a1067 A big.txt + +diff --git a/big.txt b/big.txt +new file mode 100644 +index 000000000..3a62d28e3 +--- /dev/null ++++ b/big.txt +@@ -1 +1 @@ + Hello +-world ++GitLab +~ +` + + limits := Limits{ + EnforceLimits: true, + SafeMaxFiles: 3, + SafeMaxBytes: 200, + SafeMaxLines: 200, + MaxFiles: 5, + MaxBytes: 10000000, + MaxLines: 10000000, + MaxPatchBytes: 100000, + CollapseDiffs: false, + } + wordDiff := true + diffs := getDiffs(rawDiff, limits, wordDiff) + + expectedDiffs := []*Diff{ + &Diff{ + OldMode: 0, + NewMode: 0100644, + FromID: "0000000000000000000000000000000000000000", + ToID: "4cc7061661b8f52891bc1b39feb4d856b21a1067", + FromPath: []byte("big.txt"), + ToPath: []byte("big.txt"), + Status: 'A', + Collapsed: false, + Patch: []byte("@@ -1 +1 @@\n Hello\n-world\n+GitLab\n~\n"), + lineCount: 4, + }, + } + + require.Equal(t, expectedDiffs, diffs) +} + func TestDiffParserWithLargeDiffWithFalseCollapseDiffsFlag(t *testing.T) { bigPatch := strings.Repeat("+Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.\n", 100000) rawDiff := fmt.Sprintf(`:000000 100644 0000000000000000000000000000000000000000 4cc7061661b8f52891bc1b39feb4d856b21a1067 A big.txt @@ -102,7 +150,8 @@ index 0000000000000000000000000000000000000000..3be11c69355948412925fa5e073d76d5 MaxPatchBytes: 100000, CollapseDiffs: false, } - diffParser := NewDiffParser(strings.NewReader(rawDiff), limits) + wordDiff := false + diffParser := NewDiffParser(strings.NewReader(rawDiff), limits, wordDiff) diffs := []*Diff{} for diffParser.Parse() { @@ -169,7 +218,8 @@ index 0000000000000000000000000000000000000000..3be11c69355948412925fa5e073d76d5 MaxPatchBytes: 125000, // bumping from default 100KB to 125kb (first patch has 124.6KB) CollapseDiffs: false, } - diffParser := NewDiffParser(strings.NewReader(rawDiff), limits) + wordDiff := false + diffParser := NewDiffParser(strings.NewReader(rawDiff), limits, wordDiff) diffs := []*Diff{} for diffParser.Parse() { @@ -237,7 +287,8 @@ index 0000000000000000000000000000000000000000..b6507e5b5ce18077e3ec8aaa2291404e MaxPatchBytes: 100000, CollapseDiffs: true, } - diffs := getDiffs(rawDiff, limits) + wordDiff := false + diffs := getDiffs(rawDiff, limits, wordDiff) expectedDiffs := []*Diff{ &Diff{ @@ -291,8 +342,8 @@ func TestDiffLimitsBeingEnforcedByUpperBound(t *testing.T) { MaxLines: 0, MaxPatchBytes: 0, } - - diffParser := NewDiffParser(strings.NewReader(""), limits) + wordDiff := false + diffParser := NewDiffParser(strings.NewReader(""), limits, wordDiff) require.Equal(t, diffParser.limits.SafeMaxBytes, safeMaxBytesUpperBound) require.Equal(t, diffParser.limits.SafeMaxFiles, safeMaxFilesUpperBound) @@ -303,8 +354,8 @@ func TestDiffLimitsBeingEnforcedByUpperBound(t *testing.T) { require.Equal(t, diffParser.limits.MaxPatchBytes, 0) } -func getDiffs(rawDiff string, limits Limits) []*Diff { - diffParser := NewDiffParser(strings.NewReader(rawDiff), limits) +func getDiffs(rawDiff string, limits Limits, wordDiff bool) []*Diff { + diffParser := NewDiffParser(strings.NewReader(rawDiff), limits, wordDiff) diffs := []*Diff{} for diffParser.Parse() { diff --git a/internal/gitaly/service/diff/commit.go b/internal/gitaly/service/diff/commit.go index 8824f6c040..053baf7fdd 100644 --- a/internal/gitaly/service/diff/commit.go +++ b/internal/gitaly/service/diff/commit.go @@ -33,6 +33,7 @@ func (s *server) CommitDiff(in *gitalypb.CommitDiffRequest, stream gitalypb.Diff leftSha := in.LeftCommitId rightSha := in.RightCommitId ignoreWhitespaceChange := in.GetIgnoreWhitespaceChange() + wordDiff := in.GetWordDiff() paths := in.GetPaths() cmd := git.SubCmd{ @@ -50,6 +51,9 @@ func (s *server) CommitDiff(in *gitalypb.CommitDiffRequest, stream gitalypb.Diff if ignoreWhitespaceChange { cmd.Flags = append(cmd.Flags, git.Flag{Name: "--ignore-space-change"}) } + if wordDiff { + cmd.Flags = append(cmd.Flags, git.Flag{Name: "--word-diff=porcelain"}) + } if len(paths) > 0 { for _, path := range paths { cmd.PostSepArgs = append(cmd.PostSepArgs, string(path)) @@ -69,7 +73,7 @@ func (s *server) CommitDiff(in *gitalypb.CommitDiffRequest, stream gitalypb.Diff limits.SafeMaxLines = int(in.SafeMaxLines) limits.SafeMaxBytes = int(in.SafeMaxBytes) - return s.eachDiff(stream.Context(), "CommitDiff", in.Repository, cmd, limits, func(diff *diff.Diff) error { + return s.eachDiff(stream.Context(), "CommitDiff", in.Repository, cmd, limits, wordDiff, func(diff *diff.Diff) error { response := &gitalypb.CommitDiffResponse{ FromPath: diff.FromPath, ToPath: diff.ToPath, @@ -129,6 +133,7 @@ func (s *server) CommitDelta(in *gitalypb.CommitDeltaRequest, stream gitalypb.Di leftSha := in.LeftCommitId rightSha := in.RightCommitId + wordDiff := false paths := in.GetPaths() cmd := git.SubCmd{ @@ -162,7 +167,7 @@ func (s *server) CommitDelta(in *gitalypb.CommitDeltaRequest, stream gitalypb.Di return nil } - err := s.eachDiff(stream.Context(), "CommitDelta", in.Repository, cmd, diff.Limits{}, func(diff *diff.Diff) error { + err := s.eachDiff(stream.Context(), "CommitDelta", in.Repository, cmd, diff.Limits{}, wordDiff, func(diff *diff.Diff) error { delta := &gitalypb.CommitDelta{ FromPath: diff.FromPath, ToPath: diff.ToPath, @@ -205,7 +210,7 @@ func validateRequest(in requestWithLeftRightCommitIds) error { return nil } -func (s *server) eachDiff(ctx context.Context, rpc string, repo *gitalypb.Repository, subCmd git.Cmd, limits diff.Limits, callback func(*diff.Diff) error) error { +func (s *server) eachDiff(ctx context.Context, rpc string, repo *gitalypb.Repository, subCmd git.Cmd, limits diff.Limits, wordDiff bool, callback func(*diff.Diff) error) error { diffConfig := git.ConfigPair{Key: "diff.noprefix", Value: "false"} cmd, err := s.gitCmdFactory.New(ctx, repo, subCmd, git.WithConfig(diffConfig)) @@ -216,7 +221,7 @@ func (s *server) eachDiff(ctx context.Context, rpc string, repo *gitalypb.Reposi return status.Errorf(codes.Internal, "%s: cmd: %v", rpc, err) } - diffParser := diff.NewDiffParser(cmd, limits) + diffParser := diff.NewDiffParser(cmd, limits, wordDiff) for diffParser.Parse() { if err := callback(diffParser.Diff()); err != nil { diff --git a/internal/gitaly/service/diff/commit_test.go b/internal/gitaly/service/diff/commit_test.go index 502814029d..45e2a85bbf 100644 --- a/internal/gitaly/service/diff/commit_test.go +++ b/internal/gitaly/service/diff/commit_test.go @@ -397,6 +397,189 @@ func TestSuccessfulCommitDiffRequestWithIgnoreWhitespaceChange(t *testing.T) { } } +func TestSuccessfulCommitDiffRequestWithWordDiff(t *testing.T) { + server, serverSocketPath := runDiffServer(t) + defer server.Stop() + + client, conn := newDiffClient(t, serverSocketPath) + defer conn.Close() + + testRepo, testRepoPath, cleanupFn := gittest.CloneRepo(t) + defer cleanupFn() + + rightCommit := "ab2c9622c02288a2bbaaf35d96088cfdff31d9d9" + leftCommit := "8a0f2ee90d940bfb0ba1e14e8214b0649056e4ab" + expectedDiffs := []diff.Diff{ + { + FromID: "faaf198af3a36dbf41961466703cc1d47c61d051", + ToID: "877cee6ab11f9094e1bcdb7f1fd9c0001b572185", + OldMode: 0100644, + NewMode: 0100644, + FromPath: []byte("README.md"), + ToPath: []byte("README.md"), + Binary: false, + Patch: testhelper.MustReadFile(t, "testdata/word-diff/readme-md-chunks.txt"), + }, + { + FromID: "bdea48ee65c869eb0b86b1283069d76cce0a7254", + ToID: "0000000000000000000000000000000000000000", + OldMode: 0100644, + NewMode: 0, + FromPath: []byte("gitaly/deleted-file"), + ToPath: []byte("gitaly/deleted-file"), + Binary: false, + Patch: testhelper.MustReadFile(t, "testdata/word-diff/deleted-file-chunks.txt"), + }, + { + FromID: "aa408b4556e594f7974390ad6b86210617fbda6e", + ToID: "1c69c4d2a65ad05c24ac3b6780b5748b97ffd3aa", + OldMode: 0100644, + NewMode: 0100644, + FromPath: []byte("gitaly/file-with-multiple-chunks"), + ToPath: []byte("gitaly/file-with-multiple-chunks"), + Binary: false, + Patch: testhelper.MustReadFile(t, "testdata/word-diff/file-with-multiple-chunks-chunks.txt"), + }, + { + FromID: "0000000000000000000000000000000000000000", + ToID: "389c7a36a6e133268b0d36b00e7ffc0f3a5b6651", + OldMode: 0, + NewMode: 0100644, + FromPath: []byte("gitaly/file-with-pluses.txt"), + ToPath: []byte("gitaly/file-with-pluses.txt"), + Binary: false, + Patch: testhelper.MustReadFile(t, "testdata/word-diff/file-with-pluses-chunks.txt"), + }, + { + FromID: "0000000000000000000000000000000000000000", + ToID: "bc2ef601a538d69ef99d5bdafa605e63f902e8e4", + OldMode: 0, + NewMode: 0100644, + FromPath: []byte("gitaly/logo-white.png"), + ToPath: []byte("gitaly/logo-white.png"), + Binary: true, + Patch: []byte("Binary files /dev/null and b/gitaly/logo-white.png differ\n"), + }, + { + FromID: "ead5a0eee1391308803cfebd8a2a8530495645eb", + ToID: "ead5a0eee1391308803cfebd8a2a8530495645eb", + OldMode: 0100644, + NewMode: 0100755, + FromPath: []byte("gitaly/mode-file"), + ToPath: []byte("gitaly/mode-file"), + Binary: false, + }, + { + FromID: "357406f3075a57708d0163752905cc1576fceacc", + ToID: "8e5177d718c561d36efde08bad36b43687ee6bf0", + OldMode: 0100644, + NewMode: 0100755, + FromPath: []byte("gitaly/mode-file-with-mods"), + ToPath: []byte("gitaly/mode-file-with-mods"), + Binary: false, + Patch: testhelper.MustReadFile(t, "testdata/word-diff/mode-file-with-mods-chunks.txt"), + }, + { + FromID: "43d24af4e22580f36b1ca52647c1aff75a766a33", + ToID: "0000000000000000000000000000000000000000", + OldMode: 0100644, + NewMode: 0, + FromPath: []byte("gitaly/named-file-with-mods"), + ToPath: []byte("gitaly/named-file-with-mods"), + Binary: false, + Patch: testhelper.MustReadFile(t, "testdata/word-diff/named-file-with-mods-chunks.txt"), + }, + { + FromID: "0000000000000000000000000000000000000000", + ToID: "b464dff7a75ccc92fbd920fd9ae66a84b9d2bf94", + OldMode: 0, + NewMode: 0100644, + FromPath: []byte("gitaly/no-newline-at-the-end"), + ToPath: []byte("gitaly/no-newline-at-the-end"), + Binary: false, + Patch: testhelper.MustReadFile(t, "testdata/word-diff/no-newline-at-the-end-chunks.txt"), + }, + { + FromID: "4e76e90b3c7e52390de9311a23c0a77575aed8a8", + ToID: "4e76e90b3c7e52390de9311a23c0a77575aed8a8", + OldMode: 0100644, + NewMode: 0100644, + FromPath: []byte("gitaly/named-file"), + ToPath: []byte("gitaly/renamed-file"), + Binary: false, + }, + { + FromID: "0000000000000000000000000000000000000000", + ToID: "3856c00e9450a51a62096327167fc43d3be62eef", + OldMode: 0, + NewMode: 0100644, + FromPath: []byte("gitaly/renamed-file-with-mods"), + ToPath: []byte("gitaly/renamed-file-with-mods"), + Binary: false, + Patch: testhelper.MustReadFile(t, "testdata/word-diff/renamed-file-with-mods-chunks.txt"), + }, + { + FromID: "0000000000000000000000000000000000000000", + ToID: "a135e3e0d4af177a902ca57dcc4c7fc6f30858b1", + OldMode: 0, + NewMode: 0100644, + FromPath: []byte("gitaly/tab\tnewline\n file"), + ToPath: []byte("gitaly/tab\tnewline\n file"), + Binary: false, + Patch: testhelper.MustReadFile(t, "testdata/word-diff/tab-newline-file-chunks.txt"), + }, + { + FromID: "0000000000000000000000000000000000000000", + ToID: "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391", + OldMode: 0, + NewMode: 0100755, + FromPath: []byte("gitaly/テスト.txt"), + ToPath: []byte("gitaly/テスト.txt"), + Binary: false, + }, + { + FromID: "0000000000000000000000000000000000000000", + ToID: "b1e67221afe8461efd244b487afca22d46b95eb8", + OldMode: 0, + NewMode: 0100644, + FromPath: []byte("z-short-diff"), + ToPath: []byte("z-short-diff"), + Binary: false, + Patch: testhelper.MustReadFile(t, "testdata/word-diff/z-short-diff-chunks.txt"), + }, + } + + testCases := []struct { + noPrefixConfig string + desc string + }{ + {noPrefixConfig: "false", desc: "Git config diff.noprefix set to false"}, + {noPrefixConfig: "true", desc: "Git config diff.noprefix set to true"}, + } + + for _, testCase := range testCases { + t.Run(testCase.desc, func(t *testing.T) { + testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "config", "diff.noprefix", testCase.noPrefixConfig) + rpcRequest := &gitalypb.CommitDiffRequest{ + Repository: testRepo, + RightCommitId: rightCommit, + LeftCommitId: leftCommit, + IgnoreWhitespaceChange: false, + WordDiff: true, + } + + ctx, cancel := testhelper.Context() + defer cancel() + c, err := client.CommitDiff(ctx, rpcRequest) + if err != nil { + t.Fatal(err) + } + + assertExactReceivedDiffs(t, c, expectedDiffs) + }) + } +} + func TestSuccessfulCommitDiffRequestWithLimits(t *testing.T) { _, repo, _, client := setupDiffService(t) diff --git a/internal/gitaly/service/diff/testdata/word-diff/deleted-file-chunks.txt b/internal/gitaly/service/diff/testdata/word-diff/deleted-file-chunks.txt new file mode 100644 index 0000000000..af60c4c8d2 --- /dev/null +++ b/internal/gitaly/service/diff/testdata/word-diff/deleted-file-chunks.txt @@ -0,0 +1,3 @@ +@@ -1 +0,0 @@ +-This file will be deleted +~ diff --git a/internal/gitaly/service/diff/testdata/word-diff/file-with-multiple-chunks-chunks.txt b/internal/gitaly/service/diff/testdata/word-diff/file-with-multiple-chunks-chunks.txt new file mode 100644 index 0000000000..e035460b11 --- /dev/null +++ b/internal/gitaly/service/diff/testdata/word-diff/file-with-multiple-chunks-chunks.txt @@ -0,0 +1,199 @@ +@@ -13,9 +13,10 @@ class Project < ActiveRecord::Base + include CaseSensitivity +~ + include TokenAuthenticatable +~ + include ValidAttribute +~ + include +-ProjectFeaturesCompatibility ++InvalidAttribute +~ + include +-SelectForProjectAuthorization ++ProjectFeaturesIncompatibility +~ + include +-Routable ++SelectForProjectUnauthorization +~ ++ include Unroutable +~ + +~ + extend Gitlab::ConfigHelper +~ + +~ +@@ -115,9 +116,11 @@ class Project < ActiveRecord::Base + has_one :external_wiki_service, dependent: :destroy +~ + has_one :kubernetes_service, dependent: :destroy, inverse_of: :project +~ + +~ + ++has_one :developer +~ + has_one :forked_project_link, dependent: :destroy, foreign_key: "forked_to_project_id" +~ + has_one :forked_from_project, through: :forked_project_link +~ + +~ + ++has_many :bug_reporters +~ + has_many :forked_project_links, foreign_key: "forked_from_project_id" +~ + has_many :forks, through: :forked_project_links, source: :forked_to_project +~ + +~ +@@ -215,7 +218,7 @@ class Project < ActiveRecord::Base + default_scope { where(pending_delete: false) } +~ + +~ + scope :sorted_by_activity, -> { reorder(last_activity_at: :desc) } +~ + scope :sorted_by_stars, -> { reorder('projects.star_count +-DESC') ++ASC') + } ++# :troll: +~ + +~ + scope :in_namespace, ->(namespace_ids) { where(namespace_id: namespace_ids) } +~ + scope :personal, ->(user) { where(namespace_id: user.namespace_id) } +~ +@@ -304,6 +307,8 @@ class Project < ActiveRecord::Base + # +~ + # query - The search query as a String. +~ + def search(query) +~ + ++return [] +~ +~ + ptable = arel_table +~ + ntable = Namespace.arel_table +~ + pattern = "%#{query}%" +~ +@@ -402,24 +407,6 @@ class Project < ActiveRecord::Base + path_with_namespace.downcase +~ + end +~ + +~ +- def container_registry_repository +~ +- return unless Gitlab.config.registry.enabled +~ +~ +- @container_registry_repository ||= begin +~ +- token = Auth::ContainerRegistryAuthenticationService.full_access_token(container_registry_path_with_namespace) +~ +- url = Gitlab.config.registry.api_url +~ +- host_port = Gitlab.config.registry.host_port +~ +- registry = ContainerRegistry::Registry.new(url, token: token, path: host_port) +~ +- registry.repository(container_registry_path_with_namespace) +~ +- end +~ +- end +~ +~ +- def container_registry_repository_url +~ +- if Gitlab.config.registry.enabled +~ +- "#{Gitlab.config.registry.host_port}/#{container_registry_path_with_namespace}" +~ +- end +~ +- end +~ +~ + def has_container_registry_tags? +~ + return unless container_registry_repository +~ + +~ +@@ -489,6 +476,24 @@ class Project < ActiveRecord::Base + end +~ + end +~ + +~ + ++def container_registry_repository +~ ++ return unless Gitlab.config.registry.enabled +~ +~ ++ @container_registry_repository ||= begin +~ ++ token = Auth::ContainerRegistryAuthenticationService.full_access_token(container_registry_path_with_namespace) +~ ++ url = Gitlab.config.registry.api_url +~ ++ host_port = Gitlab.config.registry.host_port +~ ++ registry = ContainerRegistry::Registry.new(url, token: token, path: host_port) +~ ++ registry.repository(container_registry_path_with_namespace) +~ ++ end +~ ++ end +~ +~ ++ def container_registry_repository_url +~ ++ if Gitlab.config.registry.enabled +~ ++ "#{Gitlab.config.registry.host_port}/#{container_registry_path_with_namespace}" +~ ++ end +~ ++ end +~ +~ + def valid_import_url? +~ + valid? || errors.messages[:import_url].nil? +~ + end +~ +@@ -1325,7 +1330,7 @@ class Project < ActiveRecord::Base + alias_method :human_name, :full_name +~ + alias_method :path_with_namespace, :full_path +~ + +~ + ++# + private ++# Transparency and openness are the key +~ + +~ + def cross_namespace_reference?(from) +~ + case from +~ diff --git a/internal/gitaly/service/diff/testdata/word-diff/file-with-pluses-chunks.txt b/internal/gitaly/service/diff/testdata/word-diff/file-with-pluses-chunks.txt new file mode 100644 index 0000000000..bb96bb19e2 --- /dev/null +++ b/internal/gitaly/service/diff/testdata/word-diff/file-with-pluses-chunks.txt @@ -0,0 +1,11 @@ +@@ -0,0 +1,5 @@ +++ +~ ++++ +~ +++++ +~ ++++++ +~ +++++++ +~ diff --git a/internal/gitaly/service/diff/testdata/word-diff/mode-file-with-mods-chunks.txt b/internal/gitaly/service/diff/testdata/word-diff/mode-file-with-mods-chunks.txt new file mode 100644 index 0000000000..da8abed34a --- /dev/null +++ b/internal/gitaly/service/diff/testdata/word-diff/mode-file-with-mods-chunks.txt @@ -0,0 +1,10 @@ +@@ -1 +1,2 @@ ++Here are the modifications: +~ + This file +-will have ++had + its mode changed, with some +-modifications ++modifications. +~ diff --git a/internal/gitaly/service/diff/testdata/word-diff/named-file-with-mods-chunks.txt b/internal/gitaly/service/diff/testdata/word-diff/named-file-with-mods-chunks.txt new file mode 100644 index 0000000000..fc9a5d4f02 --- /dev/null +++ b/internal/gitaly/service/diff/testdata/word-diff/named-file-with-mods-chunks.txt @@ -0,0 +1,3 @@ +@@ -1 +0,0 @@ +-This file will [sic] renamed with modificationns, hencee the typos +~ diff --git a/internal/gitaly/service/diff/testdata/word-diff/no-newline-at-the-end-chunks.txt b/internal/gitaly/service/diff/testdata/word-diff/no-newline-at-the-end-chunks.txt new file mode 100644 index 0000000000..b9dcffc63d --- /dev/null +++ b/internal/gitaly/service/diff/testdata/word-diff/no-newline-at-the-end-chunks.txt @@ -0,0 +1,3 @@ +@@ -0,0 +1 @@ ++No newline at end of file. +~ diff --git a/internal/gitaly/service/diff/testdata/word-diff/readme-md-chunks.txt b/internal/gitaly/service/diff/testdata/word-diff/readme-md-chunks.txt new file mode 100644 index 0000000000..171bb04737 --- /dev/null +++ b/internal/gitaly/service/diff/testdata/word-diff/readme-md-chunks.txt @@ -0,0 +1,9 @@ +@@ -1,4 +1,4 @@ + testme +~ + ====== +~ + +~ + Sample repo for testing gitlab features +~ diff --git a/internal/gitaly/service/diff/testdata/word-diff/renamed-file-with-mods-chunks.txt b/internal/gitaly/service/diff/testdata/word-diff/renamed-file-with-mods-chunks.txt new file mode 100644 index 0000000000..0b8fa26467 --- /dev/null +++ b/internal/gitaly/service/diff/testdata/word-diff/renamed-file-with-mods-chunks.txt @@ -0,0 +1,3 @@ +@@ -0,0 +1 @@ ++This file will be renamed with modifications, hence no typos. +~ diff --git a/internal/gitaly/service/diff/testdata/word-diff/tab-newline-file-chunks.txt b/internal/gitaly/service/diff/testdata/word-diff/tab-newline-file-chunks.txt new file mode 100644 index 0000000000..d2e7b4c1ba --- /dev/null +++ b/internal/gitaly/service/diff/testdata/word-diff/tab-newline-file-chunks.txt @@ -0,0 +1,3 @@ +@@ -0,0 +1 @@ ++A file with a tab (\t) and a new line (\n) in its name. +~ diff --git a/internal/gitaly/service/diff/testdata/word-diff/z-short-diff-chunks.txt b/internal/gitaly/service/diff/testdata/word-diff/z-short-diff-chunks.txt new file mode 100644 index 0000000000..9f5e1d8232 --- /dev/null +++ b/internal/gitaly/service/diff/testdata/word-diff/z-short-diff-chunks.txt @@ -0,0 +1,7 @@ +@@ -0,0 +1,3 @@ ++A +~ ++B +~ ++C +~ diff --git a/proto/diff.proto b/proto/diff.proto index b7199fb236..b6cb8adebd 100644 --- a/proto/diff.proto +++ b/proto/diff.proto @@ -51,6 +51,7 @@ message CommitDiffRequest { repeated bytes paths = 5; bool collapse_diffs = 6; bool enforce_limits = 7; + bool word_diff = 15; // These limits are only enforced when enforce_limits == true. int32 max_files = 8; @@ -176,4 +177,3 @@ message ChangedPaths { bytes path = 1; Status status = 2; } - diff --git a/proto/go/gitalypb/diff.pb.go b/proto/go/gitalypb/diff.pb.go index 0b0d0f294f..a7f04a0dfc 100644 --- a/proto/go/gitalypb/diff.pb.go +++ b/proto/go/gitalypb/diff.pb.go @@ -66,6 +66,7 @@ type CommitDiffRequest struct { Paths [][]byte `protobuf:"bytes,5,rep,name=paths,proto3" json:"paths,omitempty"` CollapseDiffs bool `protobuf:"varint,6,opt,name=collapse_diffs,json=collapseDiffs,proto3" json:"collapse_diffs,omitempty"` EnforceLimits bool `protobuf:"varint,7,opt,name=enforce_limits,json=enforceLimits,proto3" json:"enforce_limits,omitempty"` + WordDiff bool `protobuf:"varint,15,opt,name=word_diff,json=wordDiff,proto3" json:"word_diff,omitempty"` // These limits are only enforced when enforce_limits == true. MaxFiles int32 `protobuf:"varint,8,opt,name=max_files,json=maxFiles,proto3" json:"max_files,omitempty"` MaxLines int32 `protobuf:"varint,9,opt,name=max_lines,json=maxLines,proto3" json:"max_lines,omitempty"` @@ -157,6 +158,13 @@ func (m *CommitDiffRequest) GetEnforceLimits() bool { return false } +func (m *CommitDiffRequest) GetWordDiff() bool { + if m != nil { + return m.WordDiff + } + return false +} + func (m *CommitDiffRequest) GetMaxFiles() int32 { if m != nil { return m.MaxFiles @@ -1028,72 +1036,73 @@ func init() { func init() { proto.RegisterFile("diff.proto", fileDescriptor_686521effc814b25) } var fileDescriptor_686521effc814b25 = []byte{ - // 1040 bytes of a gzipped FileDescriptorProto + // 1053 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xcc, 0x56, 0xcd, 0x6e, 0xdb, 0x46, 0x10, 0x2e, 0x25, 0x8a, 0xa2, 0x46, 0xb4, 0xac, 0xac, 0x03, 0x9b, 0x96, 0x0b, 0x54, 0x20, 0xf2, - 0x23, 0xf4, 0x47, 0x0e, 0x9c, 0x4b, 0x0e, 0xbd, 0xc4, 0xa6, 0x9c, 0x2a, 0xb5, 0x6a, 0x81, 0x09, - 0x50, 0xb4, 0x17, 0x62, 0x25, 0x2e, 0x25, 0xa2, 0x24, 0x57, 0x25, 0x37, 0x96, 0xfd, 0x24, 0x4d, - 0x7b, 0x2e, 0x50, 0xa0, 0xc7, 0x3e, 0x44, 0x1f, 0xa6, 0x4f, 0x50, 0xf4, 0x54, 0xec, 0x2e, 0x49, - 0x51, 0x96, 0xd2, 0x53, 0x0f, 0xba, 0x71, 0xbe, 0xef, 0xf3, 0xec, 0xec, 0xb7, 0x33, 0x23, 0x03, - 0x78, 0x81, 0xef, 0xf7, 0x17, 0x09, 0x65, 0x14, 0x69, 0xb3, 0x80, 0xe1, 0xf0, 0xae, 0x03, 0x61, - 0x10, 0x33, 0x89, 0x75, 0x8c, 0x74, 0x8e, 0x13, 0xe2, 0xc9, 0xc8, 0xfa, 0x5d, 0x85, 0x07, 0x17, - 0x34, 0x8a, 0x02, 0x66, 0x07, 0xbe, 0xef, 0x90, 0x1f, 0xdf, 0x91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xb5, 0x93, 0xb2, 0x19, 0x4b, 0x32, 0x2a, 0x6e, 0x13, 0xa4, 0x2c, 0x16, + 0x15, 0x4f, 0x65, 0x27, 0x59, 0x9e, 0x29, 0x80, 0x6b, 0xcc, 0xa7, 0x68, 0x0f, 0x9a, 0x9c, 0x29, + 0xaa, 0x26, 0x29, 0x83, 0xb3, 0x82, 0x90, 0x7f, 0x55, 0x36, 0x86, 0x21, 0xc2, 0x73, 0x82, 0x76, + 0xa0, 0xc1, 0x99, 0x80, 0x75, 0x09, 0xeb, 0x9c, 0x9d, 0x13, 0xb4, 0x0f, 0x26, 0x8b, 0x88, 0x1f, + 0x33, 0x42, 0xed, 0x86, 0x2c, 0xad, 0xc9, 0x22, 0x72, 0xc9, 0x08, 0x15, 0x54, 0x42, 0xe7, 0x8a, + 0x32, 0x14, 0x95, 0xd0, 0xb9, 0xa4, 0x76, 0xc1, 0x18, 0x85, 0x09, 0x4e, 0xef, 0xf2, 0xd7, 0xcd, + 0x23, 0x71, 0xdd, 0x14, 0xcf, 0x73, 0x8b, 0x09, 0xe6, 0x58, 0xbe, 0x90, 0xe5, 0x59, 0x29, 0x9e, + 0x4b, 0x87, 0x5d, 0xcc, 0x31, 0xea, 0x83, 0x45, 0x13, 0xe2, 0xb3, 0x40, 0x09, 0xe5, 0x43, 0x99, + 0x1e, 0xd0, 0x84, 0x5c, 0x05, 0x52, 0x85, 0x9e, 0xc2, 0x36, 0xbb, 0xa1, 0x69, 0x10, 0xb1, 0xb9, + 0x1f, 0xe3, 0xf4, 0x07, 0x9a, 0xca, 0x37, 0x30, 0xbd, 0x4e, 0x01, 0x5f, 0x4a, 0x14, 0x7d, 0x0c, + 0xad, 0xa2, 0xff, 0x88, 0x7c, 0x00, 0xd3, 0x5b, 0x00, 0xc2, 0x40, 0xce, 0x98, 0x1f, 0xe1, 0x74, + 0x42, 0xa5, 0xf1, 0xa6, 0x67, 0x72, 0xc6, 0x2e, 0x44, 0xfc, 0x5a, 0x37, 0xcd, 0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d, 0xd7, 0xdb, 0x5b, 0xc1, 0x57, 0xb2, 0xbc, + 0x02, 0xb3, 0x98, 0x67, 0x54, 0x95, 0x57, 0x97, 0x4f, 0xcf, 0x5e, 0x25, 0x56, 0x12, 0xbd, 0xae, + 0xce, 0x94, 0xbd, 0xda, 0xc4, 0x79, 0xaa, 0xfd, 0x35, 0xcc, 0x4a, 0x2e, 0x1f, 0xba, 0xf7, 0x5b, + 0x0f, 0x7d, 0x52, 0xfc, 0xe1, 0x07, 0x66, 0xa0, 0xd7, 0xff, 0xb0, 0xe0, 0xfe, 0x01, 0x27, 0xcf, + 0xbe, 0x17, 0xe2, 0x08, 0x8f, 0x0e, 0xc7, 0x2c, 0x3e, 0x52, 0x9f, 0x5f, 0xb0, 0x74, 0x72, 0xa4, + 0x52, 0x1c, 0xc9, 0xff, 0xd8, 0x8f, 0x26, 0x2c, 0x8f, 0x67, 0xa3, 0x91, 0x21, 0xa1, 0xe7, 0xff, + 0x06, 0x00, 0x00, 0xff, 0xff, 0xd3, 0x62, 0xbf, 0xf7, 0xf4, 0x0b, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. diff --git a/ruby/proto/gitaly/diff_pb.rb b/ruby/proto/gitaly/diff_pb.rb index 8baa2817fe..3cea25d4c6 100644 --- a/ruby/proto/gitaly/diff_pb.rb +++ b/ruby/proto/gitaly/diff_pb.rb @@ -15,6 +15,7 @@ Google::Protobuf::DescriptorPool.generated_pool.build do repeated :paths, :bytes, 5 optional :collapse_diffs, :bool, 6 optional :enforce_limits, :bool, 7 + optional :word_diff, :bool, 15 optional :max_files, :int32, 8 optional :max_lines, :int32, 9 optional :max_bytes, :int32, 10 -- GitLab From f478273983a49972a530b86d1778c48dc1c0cc5d Mon Sep 17 00:00:00 2001 From: Vasilii Iakliushin Date: Thu, 18 Mar 2021 11:33:26 +0100 Subject: [PATCH 2/6] Replace wordDiff with diffMode --- internal/gitaly/diff/diff.go | 4 +- internal/gitaly/diff/diff_test.go | 22 +-- internal/gitaly/service/diff/commit.go | 13 +- internal/gitaly/service/diff/commit_test.go | 2 +- proto/diff.proto | 8 +- proto/go/gitalypb/diff.pb.go | 189 +++++++++++--------- ruby/proto/gitaly/diff_pb.rb | 7 +- 7 files changed, 138 insertions(+), 107 deletions(-) diff --git a/internal/gitaly/diff/diff.go b/internal/gitaly/diff/diff.go index 348cbe2b35..6b3d336f23 100644 --- a/internal/gitaly/diff/diff.go +++ b/internal/gitaly/diff/diff.go @@ -41,7 +41,6 @@ type Parser struct { linesProcessed int bytesProcessed int finished bool - wordDiff bool err error } @@ -92,7 +91,7 @@ var ( ) // NewDiffParser returns a new Parser -func NewDiffParser(src io.Reader, limits Limits, wordDiff bool) *Parser { +func NewDiffParser(src io.Reader, limits Limits) *Parser { limits.enforceUpperBound() parser := &Parser{} @@ -101,7 +100,6 @@ func NewDiffParser(src io.Reader, limits Limits, wordDiff bool) *Parser { parser.cacheRawLines(reader) parser.patchReader = reader parser.limits = limits - parser.wordDiff = wordDiff return parser } diff --git a/internal/gitaly/diff/diff_test.go b/internal/gitaly/diff/diff_test.go index c788803778..4ce171284e 100644 --- a/internal/gitaly/diff/diff_test.go +++ b/internal/gitaly/diff/diff_test.go @@ -40,8 +40,7 @@ index 0000000000000000000000000000000000000000..3be11c69355948412925fa5e073d76d5 MaxPatchBytes: 100000, CollapseDiffs: true, } - wordDiff := false - diffs := getDiffs(rawDiff, limits, wordDiff) + diffs := getDiffs(rawDiff, limits) expectedDiffs := []*Diff{ &Diff{ @@ -98,8 +97,7 @@ index 000000000..3a62d28e3 MaxPatchBytes: 100000, CollapseDiffs: false, } - wordDiff := true - diffs := getDiffs(rawDiff, limits, wordDiff) + diffs := getDiffs(rawDiff, limits) expectedDiffs := []*Diff{ &Diff{ @@ -150,8 +148,7 @@ index 0000000000000000000000000000000000000000..3be11c69355948412925fa5e073d76d5 MaxPatchBytes: 100000, CollapseDiffs: false, } - wordDiff := false - diffParser := NewDiffParser(strings.NewReader(rawDiff), limits, wordDiff) + diffParser := NewDiffParser(strings.NewReader(rawDiff), limits) diffs := []*Diff{} for diffParser.Parse() { @@ -218,8 +215,7 @@ index 0000000000000000000000000000000000000000..3be11c69355948412925fa5e073d76d5 MaxPatchBytes: 125000, // bumping from default 100KB to 125kb (first patch has 124.6KB) CollapseDiffs: false, } - wordDiff := false - diffParser := NewDiffParser(strings.NewReader(rawDiff), limits, wordDiff) + diffParser := NewDiffParser(strings.NewReader(rawDiff), limits) diffs := []*Diff{} for diffParser.Parse() { @@ -287,8 +283,7 @@ index 0000000000000000000000000000000000000000..b6507e5b5ce18077e3ec8aaa2291404e MaxPatchBytes: 100000, CollapseDiffs: true, } - wordDiff := false - diffs := getDiffs(rawDiff, limits, wordDiff) + diffs := getDiffs(rawDiff, limits) expectedDiffs := []*Diff{ &Diff{ @@ -342,8 +337,7 @@ func TestDiffLimitsBeingEnforcedByUpperBound(t *testing.T) { MaxLines: 0, MaxPatchBytes: 0, } - wordDiff := false - diffParser := NewDiffParser(strings.NewReader(""), limits, wordDiff) + diffParser := NewDiffParser(strings.NewReader(""), limits) require.Equal(t, diffParser.limits.SafeMaxBytes, safeMaxBytesUpperBound) require.Equal(t, diffParser.limits.SafeMaxFiles, safeMaxFilesUpperBound) @@ -354,8 +348,8 @@ func TestDiffLimitsBeingEnforcedByUpperBound(t *testing.T) { require.Equal(t, diffParser.limits.MaxPatchBytes, 0) } -func getDiffs(rawDiff string, limits Limits, wordDiff bool) []*Diff { - diffParser := NewDiffParser(strings.NewReader(rawDiff), limits, wordDiff) +func getDiffs(rawDiff string, limits Limits) []*Diff { + diffParser := NewDiffParser(strings.NewReader(rawDiff), limits) diffs := []*Diff{} for diffParser.Parse() { diff --git a/internal/gitaly/service/diff/commit.go b/internal/gitaly/service/diff/commit.go index 053baf7fdd..e7d2cc0a26 100644 --- a/internal/gitaly/service/diff/commit.go +++ b/internal/gitaly/service/diff/commit.go @@ -33,7 +33,7 @@ func (s *server) CommitDiff(in *gitalypb.CommitDiffRequest, stream gitalypb.Diff leftSha := in.LeftCommitId rightSha := in.RightCommitId ignoreWhitespaceChange := in.GetIgnoreWhitespaceChange() - wordDiff := in.GetWordDiff() + diffMode := in.GetDiffMode() paths := in.GetPaths() cmd := git.SubCmd{ @@ -51,7 +51,7 @@ func (s *server) CommitDiff(in *gitalypb.CommitDiffRequest, stream gitalypb.Diff if ignoreWhitespaceChange { cmd.Flags = append(cmd.Flags, git.Flag{Name: "--ignore-space-change"}) } - if wordDiff { + if diffMode == gitalypb.CommitDiffRequest_WORDDIFF { cmd.Flags = append(cmd.Flags, git.Flag{Name: "--word-diff=porcelain"}) } if len(paths) > 0 { @@ -73,7 +73,7 @@ func (s *server) CommitDiff(in *gitalypb.CommitDiffRequest, stream gitalypb.Diff limits.SafeMaxLines = int(in.SafeMaxLines) limits.SafeMaxBytes = int(in.SafeMaxBytes) - return s.eachDiff(stream.Context(), "CommitDiff", in.Repository, cmd, limits, wordDiff, func(diff *diff.Diff) error { + return s.eachDiff(stream.Context(), "CommitDiff", in.Repository, cmd, limits, func(diff *diff.Diff) error { response := &gitalypb.CommitDiffResponse{ FromPath: diff.FromPath, ToPath: diff.ToPath, @@ -133,7 +133,6 @@ func (s *server) CommitDelta(in *gitalypb.CommitDeltaRequest, stream gitalypb.Di leftSha := in.LeftCommitId rightSha := in.RightCommitId - wordDiff := false paths := in.GetPaths() cmd := git.SubCmd{ @@ -167,7 +166,7 @@ func (s *server) CommitDelta(in *gitalypb.CommitDeltaRequest, stream gitalypb.Di return nil } - err := s.eachDiff(stream.Context(), "CommitDelta", in.Repository, cmd, diff.Limits{}, wordDiff, func(diff *diff.Diff) error { + err := s.eachDiff(stream.Context(), "CommitDelta", in.Repository, cmd, diff.Limits{}, func(diff *diff.Diff) error { delta := &gitalypb.CommitDelta{ FromPath: diff.FromPath, ToPath: diff.ToPath, @@ -210,7 +209,7 @@ func validateRequest(in requestWithLeftRightCommitIds) error { return nil } -func (s *server) eachDiff(ctx context.Context, rpc string, repo *gitalypb.Repository, subCmd git.Cmd, limits diff.Limits, wordDiff bool, callback func(*diff.Diff) error) error { +func (s *server) eachDiff(ctx context.Context, rpc string, repo *gitalypb.Repository, subCmd git.Cmd, limits diff.Limits, callback func(*diff.Diff) error) error { diffConfig := git.ConfigPair{Key: "diff.noprefix", Value: "false"} cmd, err := s.gitCmdFactory.New(ctx, repo, subCmd, git.WithConfig(diffConfig)) @@ -221,7 +220,7 @@ func (s *server) eachDiff(ctx context.Context, rpc string, repo *gitalypb.Reposi return status.Errorf(codes.Internal, "%s: cmd: %v", rpc, err) } - diffParser := diff.NewDiffParser(cmd, limits, wordDiff) + diffParser := diff.NewDiffParser(cmd, limits) for diffParser.Parse() { if err := callback(diffParser.Diff()); err != nil { diff --git a/internal/gitaly/service/diff/commit_test.go b/internal/gitaly/service/diff/commit_test.go index 45e2a85bbf..8c59dd6d9c 100644 --- a/internal/gitaly/service/diff/commit_test.go +++ b/internal/gitaly/service/diff/commit_test.go @@ -565,7 +565,7 @@ func TestSuccessfulCommitDiffRequestWithWordDiff(t *testing.T) { RightCommitId: rightCommit, LeftCommitId: leftCommit, IgnoreWhitespaceChange: false, - WordDiff: true, + DiffMode: gitalypb.CommitDiffRequest_WORDDIFF, } ctx, cancel := testhelper.Context() diff --git a/proto/diff.proto b/proto/diff.proto index b6cb8adebd..50bddf62ab 100644 --- a/proto/diff.proto +++ b/proto/diff.proto @@ -44,6 +44,11 @@ service DiffService { } message CommitDiffRequest { + enum DiffMode { + DEFAULT = 0; + WORDDIFF = 1; + } + Repository repository = 1 [(target_repository)=true]; string left_commit_id = 2; string right_commit_id = 3; @@ -51,7 +56,6 @@ message CommitDiffRequest { repeated bytes paths = 5; bool collapse_diffs = 6; bool enforce_limits = 7; - bool word_diff = 15; // These limits are only enforced when enforce_limits == true. int32 max_files = 8; @@ -66,6 +70,8 @@ message CommitDiffRequest { int32 safe_max_files = 11; int32 safe_max_lines = 12; int32 safe_max_bytes = 13; + + DiffMode diff_mode = 15; } // A CommitDiffResponse corresponds to a single changed file in a commit. diff --git a/proto/go/gitalypb/diff.pb.go b/proto/go/gitalypb/diff.pb.go index a7f04a0dfc..1079a8b19c 100644 --- a/proto/go/gitalypb/diff.pb.go +++ b/proto/go/gitalypb/diff.pb.go @@ -24,6 +24,31 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package +type CommitDiffRequest_DiffMode int32 + +const ( + CommitDiffRequest_DEFAULT CommitDiffRequest_DiffMode = 0 + CommitDiffRequest_WORDDIFF CommitDiffRequest_DiffMode = 1 +) + +var CommitDiffRequest_DiffMode_name = map[int32]string{ + 0: "DEFAULT", + 1: "WORDDIFF", +} + +var CommitDiffRequest_DiffMode_value = map[string]int32{ + "DEFAULT": 0, + "WORDDIFF": 1, +} + +func (x CommitDiffRequest_DiffMode) String() string { + return proto.EnumName(CommitDiffRequest_DiffMode_name, int32(x)) +} + +func (CommitDiffRequest_DiffMode) EnumDescriptor() ([]byte, []int) { + return fileDescriptor_686521effc814b25, []int{0, 0} +} + type ChangedPaths_Status int32 const ( @@ -66,7 +91,6 @@ type CommitDiffRequest struct { Paths [][]byte `protobuf:"bytes,5,rep,name=paths,proto3" json:"paths,omitempty"` CollapseDiffs bool `protobuf:"varint,6,opt,name=collapse_diffs,json=collapseDiffs,proto3" json:"collapse_diffs,omitempty"` EnforceLimits bool `protobuf:"varint,7,opt,name=enforce_limits,json=enforceLimits,proto3" json:"enforce_limits,omitempty"` - WordDiff bool `protobuf:"varint,15,opt,name=word_diff,json=wordDiff,proto3" json:"word_diff,omitempty"` // These limits are only enforced when enforce_limits == true. MaxFiles int32 `protobuf:"varint,8,opt,name=max_files,json=maxFiles,proto3" json:"max_files,omitempty"` MaxLines int32 `protobuf:"varint,9,opt,name=max_lines,json=maxLines,proto3" json:"max_lines,omitempty"` @@ -76,12 +100,13 @@ type CommitDiffRequest struct { // If this is 0 you will get back empty patches. MaxPatchBytes int32 `protobuf:"varint,14,opt,name=max_patch_bytes,json=maxPatchBytes,proto3" json:"max_patch_bytes,omitempty"` // These limits are only enforced if collapse_diffs == true. - SafeMaxFiles int32 `protobuf:"varint,11,opt,name=safe_max_files,json=safeMaxFiles,proto3" json:"safe_max_files,omitempty"` - SafeMaxLines int32 `protobuf:"varint,12,opt,name=safe_max_lines,json=safeMaxLines,proto3" json:"safe_max_lines,omitempty"` - SafeMaxBytes int32 `protobuf:"varint,13,opt,name=safe_max_bytes,json=safeMaxBytes,proto3" json:"safe_max_bytes,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + SafeMaxFiles int32 `protobuf:"varint,11,opt,name=safe_max_files,json=safeMaxFiles,proto3" json:"safe_max_files,omitempty"` + SafeMaxLines int32 `protobuf:"varint,12,opt,name=safe_max_lines,json=safeMaxLines,proto3" json:"safe_max_lines,omitempty"` + SafeMaxBytes int32 `protobuf:"varint,13,opt,name=safe_max_bytes,json=safeMaxBytes,proto3" json:"safe_max_bytes,omitempty"` + DiffMode CommitDiffRequest_DiffMode `protobuf:"varint,15,opt,name=diff_mode,json=diffMode,proto3,enum=gitaly.CommitDiffRequest_DiffMode" json:"diff_mode,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` } func (m *CommitDiffRequest) Reset() { *m = CommitDiffRequest{} } @@ -158,13 +183,6 @@ func (m *CommitDiffRequest) GetEnforceLimits() bool { return false } -func (m *CommitDiffRequest) GetWordDiff() bool { - if m != nil { - return m.WordDiff - } - return false -} - func (m *CommitDiffRequest) GetMaxFiles() int32 { if m != nil { return m.MaxFiles @@ -214,6 +232,13 @@ func (m *CommitDiffRequest) GetSafeMaxBytes() int32 { return 0 } +func (m *CommitDiffRequest) GetDiffMode() CommitDiffRequest_DiffMode { + if m != nil { + return m.DiffMode + } + return CommitDiffRequest_DEFAULT +} + // A CommitDiffResponse corresponds to a single changed file in a commit. type CommitDiffResponse struct { FromPath []byte `protobuf:"bytes,1,opt,name=from_path,json=fromPath,proto3" json:"from_path,omitempty"` @@ -1015,6 +1040,7 @@ func (m *ChangedPaths) GetStatus() ChangedPaths_Status { } func init() { + proto.RegisterEnum("gitaly.CommitDiffRequest_DiffMode", CommitDiffRequest_DiffMode_name, CommitDiffRequest_DiffMode_value) proto.RegisterEnum("gitaly.ChangedPaths_Status", ChangedPaths_Status_name, ChangedPaths_Status_value) proto.RegisterType((*CommitDiffRequest)(nil), "gitaly.CommitDiffRequest") proto.RegisterType((*CommitDiffResponse)(nil), "gitaly.CommitDiffResponse") @@ -1036,73 +1062,76 @@ func init() { func init() { proto.RegisterFile("diff.proto", fileDescriptor_686521effc814b25) } var fileDescriptor_686521effc814b25 = []byte{ - // 1053 bytes of a gzipped FileDescriptorProto + // 1091 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xcc, 0x56, 0xcd, 0x6e, 0xdb, 0x46, - 0x10, 0x2e, 0x25, 0x8a, 0xa2, 0x46, 0xb4, 0xac, 0xac, 0x03, 0x9b, 0x96, 0x0b, 0x54, 0x20, 0xf2, - 0x23, 0xf4, 0xc7, 0x0e, 0x9c, 0x4b, 0x0e, 0xbd, 0xc4, 0xa6, 0x9c, 0x3a, 0xb5, 0x6b, 0x83, 0x09, - 0x50, 0xb4, 0x17, 0x62, 0xa5, 0x5d, 0x4a, 0x44, 0x49, 0xae, 0x4a, 0x6e, 0x2c, 0xfb, 0x49, 0x9a, - 0xf6, 0x5c, 0xa0, 0xf7, 0x3e, 0x44, 0xfb, 0x2e, 0x7d, 0x82, 0xa2, 0xa7, 0x62, 0x77, 0x49, 0x8a, - 0xb2, 0x94, 0x9e, 0x7a, 0xd0, 0x8d, 0xf3, 0x7d, 0x9f, 0x67, 0x67, 0xbf, 0x9d, 0x19, 0x19, 0x80, - 0x84, 0x41, 0x70, 0x38, 0x4b, 0x19, 0x67, 0x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x21, 0xcf, 0xec, - 0xa6, 0x92, 0xe5, 0xe8, 0x85, 0x04, 0xd1, 0x01, 0xb4, 0xe6, 0x2c, 0x25, 0x32, 0x93, 0xbd, 0x2d, - 0x15, 0xa6, 0x00, 0x44, 0x12, 0x41, 0xc6, 0xf8, 0xd6, 0x0f, 0xc2, 0x88, 0x66, 0xb6, 0xd9, 0xd7, - 0x06, 0x0d, 0xcf, 0x8c, 0xf1, 0xed, 0x99, 0x88, 0x0b, 0x32, 0x0a, 0x13, 0x9a, 0xd9, 0xad, 0x92, - 0xbc, 0x10, 0x71, 0x41, 0x8e, 0xee, 0x38, 0xcd, 0x6c, 0x28, 0xc9, 0x13, 0x11, 0x0b, 0xe7, 0x04, - 0x39, 0xc3, 0x7c, 0x3c, 0xcd, 0x25, 0x1d, 0x29, 0xd9, 0x8a, 0xf1, 0xed, 0xb5, 0x40, 0x95, 0xee, - 0x11, 0x74, 0x32, 0x1c, 0x50, 0x7f, 0x51, 0x43, 0x5b, 0xca, 0x2c, 0x81, 0x5e, 0x16, 0x75, 0x54, - 0x55, 0xaa, 0x18, 0x6b, 0x49, 0xa5, 0x0a, 0xaa, 0xaa, 0xd4, 0x91, 0x5b, 0x4b, 0x2a, 0x79, 0xa2, - 0xf3, 0x77, 0x0d, 0x50, 0xb5, 0x93, 0xb2, 0x19, 0x4b, 0x32, 0x2a, 0x6e, 0x13, 0xa4, 0x2c, 0x16, - 0x15, 0x4f, 0x65, 0x27, 0x59, 0x9e, 0x29, 0x80, 0x6b, 0xcc, 0xa7, 0x68, 0x0f, 0x9a, 0x9c, 0x29, - 0xaa, 0x26, 0x29, 0x83, 0xb3, 0x82, 0x90, 0x7f, 0x55, 0x36, 0x86, 0x21, 0xc2, 0x73, 0x82, 0x76, - 0xa0, 0xc1, 0x99, 0x80, 0x75, 0x09, 0xeb, 0x9c, 0x9d, 0x13, 0xb4, 0x0f, 0x26, 0x8b, 0x88, 0x1f, - 0x33, 0x42, 0xed, 0x86, 0x2c, 0xad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c3, 0x76, 0x59, 0x59, - 0x7e, 0x35, 0x04, 0xba, 0x6c, 0x7c, 0xf5, 0x0c, 0xf2, 0xdb, 0xf9, 0x59, 0x93, 0x3a, 0xd9, 0xdb, - 0x9b, 0x76, 0x85, 0x27, 0xd0, 0x5d, 0x94, 0xf6, 0x1f, 0x77, 0xf8, 0x45, 0x83, 0xae, 0xb8, 0xe8, - 0x1b, 0x8e, 0x79, 0xb6, 0x69, 0x97, 0xb8, 0x81, 0x56, 0x59, 0x9b, 0xa8, 0xbe, 0x32, 0x08, 0xf2, - 0x5b, 0xec, 0x09, 0x4c, 0x48, 0xc8, 0x43, 0x96, 0x64, 0xf2, 0xa4, 0x86, 0xb7, 0x00, 0x04, 0x4b, - 0x68, 0x44, 0x15, 0x5b, 0x57, 0x6c, 0x09, 0x14, 0x9d, 0x2f, 0x73, 0xea, 0x32, 0xa7, 0xe8, 0x7c, - 0x31, 0x42, 0xce, 0x97, 0xf0, 0xa0, 0xe2, 0x49, 0xee, 0xde, 0x53, 0x68, 0x64, 0x02, 0xc8, 0x7b, - 0xfb, 0x41, 0xe1, 0xc7, 0x42, 0xa9, 0x78, 0x27, 0x86, 0xbd, 0xb3, 0x30, 0x21, 0xea, 0x67, 0x57, - 0x26, 0xfc, 0x1f, 0x8c, 0xb5, 0xa1, 0xa9, 0xcc, 0x12, 0xf7, 0xac, 0x0f, 0x5a, 0x5e, 0x11, 0x3a, - 0x67, 0x60, 0xaf, 0x1e, 0x97, 0xd7, 0xfc, 0x69, 0xb1, 0x67, 0x54, 0xcd, 0x0f, 0xcb, 0x79, 0xac, - 0x8a, 0xf3, 0xed, 0xf3, 0xab, 0x06, 0x56, 0x15, 0x5f, 0x6b, 0xf8, 0x73, 0x30, 0xc4, 0x25, 0xdf, - 0x29, 0xb7, 0x3b, 0xc7, 0x07, 0xeb, 0x32, 0x1e, 0xbe, 0x91, 0x12, 0x2f, 0x97, 0x3a, 0x5f, 0x83, - 0xa1, 0x10, 0xd4, 0x82, 0x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x3e, 0x52, 0x9f, 0x5f, 0xb0, 0x74, 0x72, 0xa4, - 0x52, 0x1c, 0xc9, 0xff, 0xd8, 0x8f, 0x26, 0x2c, 0x8f, 0x67, 0xa3, 0x91, 0x21, 0xa1, 0xe7, 0xff, - 0x06, 0x00, 0x00, 0xff, 0xff, 0xd3, 0x62, 0xbf, 0xf7, 0xf4, 0x0b, 0x00, 0x00, + 0x17, 0xfd, 0xa8, 0x1f, 0x8a, 0xba, 0xa2, 0x65, 0x79, 0x1c, 0xd8, 0xb4, 0xfc, 0x01, 0x15, 0x88, + 0x38, 0x11, 0xfa, 0x23, 0x07, 0xce, 0x26, 0x8b, 0x02, 0x85, 0x6d, 0x4a, 0xa9, 0x52, 0xbb, 0x36, + 0x18, 0x17, 0x41, 0xbb, 0x21, 0x46, 0xe2, 0x50, 0x22, 0x4a, 0x72, 0x54, 0x72, 0x62, 0xd9, 0xaf, + 0xd1, 0x4d, 0xd3, 0xae, 0x0b, 0x74, 0xdf, 0x87, 0xe8, 0xc3, 0xf4, 0x09, 0x8a, 0xae, 0x8a, 0x99, + 0x21, 0x29, 0xca, 0x92, 0xbb, 0xea, 0x42, 0x3b, 0xde, 0x73, 0x8e, 0xee, 0xdc, 0x39, 0x73, 0xe7, + 0x8e, 0x00, 0x5c, 0xdf, 0xf3, 0x7a, 0xb3, 0x98, 0x32, 0x8a, 0xd4, 0x89, 0xcf, 0x70, 0x70, 0xdf, + 0x86, 0xc0, 0x8f, 0x98, 0xc4, 0xda, 0x7a, 0x32, 0xc5, 0x31, 0x71, 0x65, 0x64, 0xfe, 0x58, 0x85, + 0x9d, 0x73, 0x1a, 0x86, 0x3e, 0xb3, 0x7c, 0xcf, 0xb3, 0xc9, 0x0f, 0xef, 0x49, 0xc2, 0xd0, 0x2b, + 0x80, 0x98, 0xcc, 0x68, 0xe2, 0x33, 0x1a, 0xdf, 0x1b, 0x4a, 0x47, 0xe9, 0x36, 0x4e, 0x50, 0x4f, + 0x26, 0xeb, 0xd9, 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 0x9e, 0xd0, 0x34, 0x9e, + 0x8d, 0x46, 0xaa, 0x80, 0x5e, 0xfe, 0x13, 0x00, 0x00, 0xff, 0xff, 0x44, 0xf3, 0x8d, 0x8e, 0x3f, + 0x0c, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. diff --git a/ruby/proto/gitaly/diff_pb.rb b/ruby/proto/gitaly/diff_pb.rb index 3cea25d4c6..877589823a 100644 --- a/ruby/proto/gitaly/diff_pb.rb +++ b/ruby/proto/gitaly/diff_pb.rb @@ -15,7 +15,6 @@ Google::Protobuf::DescriptorPool.generated_pool.build do repeated :paths, :bytes, 5 optional :collapse_diffs, :bool, 6 optional :enforce_limits, :bool, 7 - optional :word_diff, :bool, 15 optional :max_files, :int32, 8 optional :max_lines, :int32, 9 optional :max_bytes, :int32, 10 @@ -23,6 +22,11 @@ Google::Protobuf::DescriptorPool.generated_pool.build do optional :safe_max_files, :int32, 11 optional :safe_max_lines, :int32, 12 optional :safe_max_bytes, :int32, 13 + optional :diff_mode, :enum, 15, "gitaly.CommitDiffRequest.DiffMode" + end + add_enum "gitaly.CommitDiffRequest.DiffMode" do + value :DEFAULT, 0 + value :WORDDIFF, 1 end add_message "gitaly.CommitDiffResponse" do optional :from_path, :bytes, 1 @@ -108,6 +112,7 @@ end module Gitaly CommitDiffRequest = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("gitaly.CommitDiffRequest").msgclass + CommitDiffRequest::DiffMode = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("gitaly.CommitDiffRequest.DiffMode").enummodule CommitDiffResponse = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("gitaly.CommitDiffResponse").msgclass CommitDeltaRequest = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("gitaly.CommitDeltaRequest").msgclass CommitDelta = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("gitaly.CommitDelta").msgclass -- GitLab From 45c2d4352edd6b91a0a76453ac58add9d5d00f8b Mon Sep 17 00:00:00 2001 From: Vasilii Iakliushin Date: Thu, 18 Mar 2021 14:27:35 +0100 Subject: [PATCH 3/6] Apply code-review suggestions --- internal/gitaly/diff/diff.go | 4 +++- internal/gitaly/diff/diff_test.go | 12 +++++++----- internal/gitaly/service/diff/commit.go | 3 +-- proto/diff.proto | 1 + proto/go/gitalypb/diff.pb.go | 7 ++++--- 5 files changed, 16 insertions(+), 11 deletions(-) diff --git a/internal/gitaly/diff/diff.go b/internal/gitaly/diff/diff.go index 6b3d336f23..65f179f0ed 100644 --- a/internal/gitaly/diff/diff.go +++ b/internal/gitaly/diff/diff.go @@ -156,7 +156,9 @@ func (parser *Parser) Parse() bool { parser.consumeChunkLine(false) } else if helper.ByteSliceHasAnyPrefix(line, "---", "+++") && !parser.isParsingChunkLines() { parser.consumeLine(false) - } else if helper.ByteSliceHasAnyPrefix(line, "~", "-", "+", " ", "\\", "Binary") { + } else if bytes.HasPrefix(line, []byte("~\n")) { + parser.consumeChunkLine(true) + } else if helper.ByteSliceHasAnyPrefix(line, "-", "+", " ", "\\", "Binary") { parser.consumeChunkLine(true) } else { parser.consumeLine(false) diff --git a/internal/gitaly/diff/diff_test.go b/internal/gitaly/diff/diff_test.go index 4ce171284e..4cc919d5c6 100644 --- a/internal/gitaly/diff/diff_test.go +++ b/internal/gitaly/diff/diff_test.go @@ -79,10 +79,12 @@ new file mode 100644 index 000000000..3a62d28e3 --- /dev/null +++ b/big.txt -@@ -1 +1 @@ - Hello --world -+GitLab +@@ -0,0 +1,3 @@ ++A +~ ++B +~ignoreme ++C ~ ` @@ -109,7 +111,7 @@ index 000000000..3a62d28e3 ToPath: []byte("big.txt"), Status: 'A', Collapsed: false, - Patch: []byte("@@ -1 +1 @@\n Hello\n-world\n+GitLab\n~\n"), + Patch: []byte("@@ -0,0 +1,3 @@\n+A\n~\n+B\n+C\n~\n"), lineCount: 4, }, } diff --git a/internal/gitaly/service/diff/commit.go b/internal/gitaly/service/diff/commit.go index e7d2cc0a26..7f940ef901 100644 --- a/internal/gitaly/service/diff/commit.go +++ b/internal/gitaly/service/diff/commit.go @@ -33,7 +33,6 @@ func (s *server) CommitDiff(in *gitalypb.CommitDiffRequest, stream gitalypb.Diff leftSha := in.LeftCommitId rightSha := in.RightCommitId ignoreWhitespaceChange := in.GetIgnoreWhitespaceChange() - diffMode := in.GetDiffMode() paths := in.GetPaths() cmd := git.SubCmd{ @@ -51,7 +50,7 @@ func (s *server) CommitDiff(in *gitalypb.CommitDiffRequest, stream gitalypb.Diff if ignoreWhitespaceChange { cmd.Flags = append(cmd.Flags, git.Flag{Name: "--ignore-space-change"}) } - if diffMode == gitalypb.CommitDiffRequest_WORDDIFF { + if in.GetDiffMode() == gitalypb.CommitDiffRequest_WORDDIFF { cmd.Flags = append(cmd.Flags, git.Flag{Name: "--word-diff=porcelain"}) } if len(paths) > 0 { diff --git a/proto/diff.proto b/proto/diff.proto index 50bddf62ab..03d3220e66 100644 --- a/proto/diff.proto +++ b/proto/diff.proto @@ -71,6 +71,7 @@ message CommitDiffRequest { int32 safe_max_lines = 12; int32 safe_max_bytes = 13; + // Stores requested diff mode (default or word-diff) DiffMode diff_mode = 15; } diff --git a/proto/go/gitalypb/diff.pb.go b/proto/go/gitalypb/diff.pb.go index 1079a8b19c..93b095dfca 100644 --- a/proto/go/gitalypb/diff.pb.go +++ b/proto/go/gitalypb/diff.pb.go @@ -100,9 +100,10 @@ type CommitDiffRequest struct { // If this is 0 you will get back empty patches. MaxPatchBytes int32 `protobuf:"varint,14,opt,name=max_patch_bytes,json=maxPatchBytes,proto3" json:"max_patch_bytes,omitempty"` // These limits are only enforced if collapse_diffs == true. - SafeMaxFiles int32 `protobuf:"varint,11,opt,name=safe_max_files,json=safeMaxFiles,proto3" json:"safe_max_files,omitempty"` - SafeMaxLines int32 `protobuf:"varint,12,opt,name=safe_max_lines,json=safeMaxLines,proto3" json:"safe_max_lines,omitempty"` - SafeMaxBytes int32 `protobuf:"varint,13,opt,name=safe_max_bytes,json=safeMaxBytes,proto3" json:"safe_max_bytes,omitempty"` + SafeMaxFiles int32 `protobuf:"varint,11,opt,name=safe_max_files,json=safeMaxFiles,proto3" json:"safe_max_files,omitempty"` + SafeMaxLines int32 `protobuf:"varint,12,opt,name=safe_max_lines,json=safeMaxLines,proto3" json:"safe_max_lines,omitempty"` + SafeMaxBytes int32 `protobuf:"varint,13,opt,name=safe_max_bytes,json=safeMaxBytes,proto3" json:"safe_max_bytes,omitempty"` + // Stores requested diff mode (default or word-diff) DiffMode CommitDiffRequest_DiffMode `protobuf:"varint,15,opt,name=diff_mode,json=diffMode,proto3,enum=gitaly.CommitDiffRequest_DiffMode" json:"diff_mode,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` -- GitLab From cb9c4f2e1e3555e0d8fc6f4bbf12c21a639519e0 Mon Sep 17 00:00:00 2001 From: Vasilii Iakliushin Date: Tue, 23 Mar 2021 13:17:30 +0100 Subject: [PATCH 4/6] Apply suggestion to diff mode descriptions --- proto/diff.proto | 4 +++- proto/go/gitalypb/diff.pb.go | 6 ++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/proto/diff.proto b/proto/diff.proto index 03d3220e66..e3c22b5280 100644 --- a/proto/diff.proto +++ b/proto/diff.proto @@ -45,7 +45,9 @@ service DiffService { message CommitDiffRequest { enum DiffMode { + // DEFAULT is the standard diff mode and results in a linewise diff for textfiles. DEFAULT = 0; + // WORDDIFF is a word diff and computes the diff for whitespace separated words instead of for whole lines. WORDDIFF = 1; } @@ -71,7 +73,7 @@ message CommitDiffRequest { int32 safe_max_lines = 12; int32 safe_max_bytes = 13; - // Stores requested diff mode (default or word-diff) + // DiffMode is the mode used for generating the diff. Please refer to the enum declaration for supported modes. DiffMode diff_mode = 15; } diff --git a/proto/go/gitalypb/diff.pb.go b/proto/go/gitalypb/diff.pb.go index 93b095dfca..75f92a31a7 100644 --- a/proto/go/gitalypb/diff.pb.go +++ b/proto/go/gitalypb/diff.pb.go @@ -27,7 +27,9 @@ const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package type CommitDiffRequest_DiffMode int32 const ( - CommitDiffRequest_DEFAULT CommitDiffRequest_DiffMode = 0 + // DEFAULT is the standard diff mode and results in a linewise diff for textfiles. + CommitDiffRequest_DEFAULT CommitDiffRequest_DiffMode = 0 + // WORDDIFF is a word diff and computes the diff for whitespace separated words instead of for whole lines. CommitDiffRequest_WORDDIFF CommitDiffRequest_DiffMode = 1 ) @@ -103,7 +105,7 @@ type CommitDiffRequest struct { SafeMaxFiles int32 `protobuf:"varint,11,opt,name=safe_max_files,json=safeMaxFiles,proto3" json:"safe_max_files,omitempty"` SafeMaxLines int32 `protobuf:"varint,12,opt,name=safe_max_lines,json=safeMaxLines,proto3" json:"safe_max_lines,omitempty"` SafeMaxBytes int32 `protobuf:"varint,13,opt,name=safe_max_bytes,json=safeMaxBytes,proto3" json:"safe_max_bytes,omitempty"` - // Stores requested diff mode (default or word-diff) + // DiffMode is the mode used for generating the diff. Please refer to the enum declaration for supported modes. DiffMode CommitDiffRequest_DiffMode `protobuf:"varint,15,opt,name=diff_mode,json=diffMode,proto3,enum=gitaly.CommitDiffRequest_DiffMode" json:"diff_mode,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` -- GitLab From 5c89dd6aa41a5813f378a998dc2cd7765c0d0811 Mon Sep 17 00:00:00 2001 From: Vasilii Iakliushin Date: Mon, 29 Mar 2021 13:44:10 +0200 Subject: [PATCH 5/6] Remove testdata and make a custom git diff call instead --- internal/gitaly/service/diff/commit_test.go | 31 ++- .../word-diff/deleted-file-chunks.txt | 3 - .../file-with-multiple-chunks-chunks.txt | 199 ------------------ .../word-diff/file-with-pluses-chunks.txt | 11 - .../word-diff/mode-file-with-mods-chunks.txt | 10 - .../word-diff/named-file-with-mods-chunks.txt | 3 - .../no-newline-at-the-end-chunks.txt | 3 - .../testdata/word-diff/readme-md-chunks.txt | 9 - .../renamed-file-with-mods-chunks.txt | 3 - .../word-diff/tab-newline-file-chunks.txt | 3 - .../word-diff/z-short-diff-chunks.txt | 7 - 11 files changed, 21 insertions(+), 261 deletions(-) delete mode 100644 internal/gitaly/service/diff/testdata/word-diff/deleted-file-chunks.txt delete mode 100644 internal/gitaly/service/diff/testdata/word-diff/file-with-multiple-chunks-chunks.txt delete mode 100644 internal/gitaly/service/diff/testdata/word-diff/file-with-pluses-chunks.txt delete mode 100644 internal/gitaly/service/diff/testdata/word-diff/mode-file-with-mods-chunks.txt delete mode 100644 internal/gitaly/service/diff/testdata/word-diff/named-file-with-mods-chunks.txt delete mode 100644 internal/gitaly/service/diff/testdata/word-diff/no-newline-at-the-end-chunks.txt delete mode 100644 internal/gitaly/service/diff/testdata/word-diff/readme-md-chunks.txt delete mode 100644 internal/gitaly/service/diff/testdata/word-diff/renamed-file-with-mods-chunks.txt delete mode 100644 internal/gitaly/service/diff/testdata/word-diff/tab-newline-file-chunks.txt delete mode 100644 internal/gitaly/service/diff/testdata/word-diff/z-short-diff-chunks.txt diff --git a/internal/gitaly/service/diff/commit_test.go b/internal/gitaly/service/diff/commit_test.go index 8c59dd6d9c..2f87ebd121 100644 --- a/internal/gitaly/service/diff/commit_test.go +++ b/internal/gitaly/service/diff/commit_test.go @@ -409,6 +409,17 @@ func TestSuccessfulCommitDiffRequestWithWordDiff(t *testing.T) { rightCommit := "ab2c9622c02288a2bbaaf35d96088cfdff31d9d9" leftCommit := "8a0f2ee90d940bfb0ba1e14e8214b0649056e4ab" + + var diffPatches [][]byte + output := testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "diff", "--word-diff=porcelain", leftCommit, rightCommit) + diffPerFile := bytes.Split(output, []byte("diff --git")) + + for _, s := range diffPerFile { + if idx := bytes.Index(s, []byte("@@")); idx != -1 { + diffPatches = append(diffPatches, s[idx:]) + } + } + expectedDiffs := []diff.Diff{ { FromID: "faaf198af3a36dbf41961466703cc1d47c61d051", @@ -418,7 +429,7 @@ func TestSuccessfulCommitDiffRequestWithWordDiff(t *testing.T) { FromPath: []byte("README.md"), ToPath: []byte("README.md"), Binary: false, - Patch: testhelper.MustReadFile(t, "testdata/word-diff/readme-md-chunks.txt"), + Patch: diffPatches[0], }, { FromID: "bdea48ee65c869eb0b86b1283069d76cce0a7254", @@ -428,7 +439,7 @@ func TestSuccessfulCommitDiffRequestWithWordDiff(t *testing.T) { FromPath: []byte("gitaly/deleted-file"), ToPath: []byte("gitaly/deleted-file"), Binary: false, - Patch: testhelper.MustReadFile(t, "testdata/word-diff/deleted-file-chunks.txt"), + Patch: diffPatches[1], }, { FromID: "aa408b4556e594f7974390ad6b86210617fbda6e", @@ -438,7 +449,7 @@ func TestSuccessfulCommitDiffRequestWithWordDiff(t *testing.T) { FromPath: []byte("gitaly/file-with-multiple-chunks"), ToPath: []byte("gitaly/file-with-multiple-chunks"), Binary: false, - Patch: testhelper.MustReadFile(t, "testdata/word-diff/file-with-multiple-chunks-chunks.txt"), + Patch: diffPatches[2], }, { FromID: "0000000000000000000000000000000000000000", @@ -448,7 +459,7 @@ func TestSuccessfulCommitDiffRequestWithWordDiff(t *testing.T) { FromPath: []byte("gitaly/file-with-pluses.txt"), ToPath: []byte("gitaly/file-with-pluses.txt"), Binary: false, - Patch: testhelper.MustReadFile(t, "testdata/word-diff/file-with-pluses-chunks.txt"), + Patch: diffPatches[3], }, { FromID: "0000000000000000000000000000000000000000", @@ -477,7 +488,7 @@ func TestSuccessfulCommitDiffRequestWithWordDiff(t *testing.T) { FromPath: []byte("gitaly/mode-file-with-mods"), ToPath: []byte("gitaly/mode-file-with-mods"), Binary: false, - Patch: testhelper.MustReadFile(t, "testdata/word-diff/mode-file-with-mods-chunks.txt"), + Patch: diffPatches[4], }, { FromID: "43d24af4e22580f36b1ca52647c1aff75a766a33", @@ -487,7 +498,7 @@ func TestSuccessfulCommitDiffRequestWithWordDiff(t *testing.T) { FromPath: []byte("gitaly/named-file-with-mods"), ToPath: []byte("gitaly/named-file-with-mods"), Binary: false, - Patch: testhelper.MustReadFile(t, "testdata/word-diff/named-file-with-mods-chunks.txt"), + Patch: diffPatches[5], }, { FromID: "0000000000000000000000000000000000000000", @@ -497,7 +508,7 @@ func TestSuccessfulCommitDiffRequestWithWordDiff(t *testing.T) { FromPath: []byte("gitaly/no-newline-at-the-end"), ToPath: []byte("gitaly/no-newline-at-the-end"), Binary: false, - Patch: testhelper.MustReadFile(t, "testdata/word-diff/no-newline-at-the-end-chunks.txt"), + Patch: diffPatches[6], }, { FromID: "4e76e90b3c7e52390de9311a23c0a77575aed8a8", @@ -516,7 +527,7 @@ func TestSuccessfulCommitDiffRequestWithWordDiff(t *testing.T) { FromPath: []byte("gitaly/renamed-file-with-mods"), ToPath: []byte("gitaly/renamed-file-with-mods"), Binary: false, - Patch: testhelper.MustReadFile(t, "testdata/word-diff/renamed-file-with-mods-chunks.txt"), + Patch: diffPatches[7], }, { FromID: "0000000000000000000000000000000000000000", @@ -526,7 +537,7 @@ func TestSuccessfulCommitDiffRequestWithWordDiff(t *testing.T) { FromPath: []byte("gitaly/tab\tnewline\n file"), ToPath: []byte("gitaly/tab\tnewline\n file"), Binary: false, - Patch: testhelper.MustReadFile(t, "testdata/word-diff/tab-newline-file-chunks.txt"), + Patch: diffPatches[8], }, { FromID: "0000000000000000000000000000000000000000", @@ -545,7 +556,7 @@ func TestSuccessfulCommitDiffRequestWithWordDiff(t *testing.T) { FromPath: []byte("z-short-diff"), ToPath: []byte("z-short-diff"), Binary: false, - Patch: testhelper.MustReadFile(t, "testdata/word-diff/z-short-diff-chunks.txt"), + Patch: diffPatches[9], }, } diff --git a/internal/gitaly/service/diff/testdata/word-diff/deleted-file-chunks.txt b/internal/gitaly/service/diff/testdata/word-diff/deleted-file-chunks.txt deleted file mode 100644 index af60c4c8d2..0000000000 --- a/internal/gitaly/service/diff/testdata/word-diff/deleted-file-chunks.txt +++ /dev/null @@ -1,3 +0,0 @@ -@@ -1 +0,0 @@ --This file will be deleted -~ diff --git a/internal/gitaly/service/diff/testdata/word-diff/file-with-multiple-chunks-chunks.txt b/internal/gitaly/service/diff/testdata/word-diff/file-with-multiple-chunks-chunks.txt deleted file mode 100644 index e035460b11..0000000000 --- a/internal/gitaly/service/diff/testdata/word-diff/file-with-multiple-chunks-chunks.txt +++ /dev/null @@ -1,199 +0,0 @@ -@@ -13,9 +13,10 @@ class Project < ActiveRecord::Base - include CaseSensitivity -~ - include TokenAuthenticatable -~ - include ValidAttribute -~ - include --ProjectFeaturesCompatibility -+InvalidAttribute -~ - include --SelectForProjectAuthorization -+ProjectFeaturesIncompatibility -~ - include --Routable -+SelectForProjectUnauthorization -~ -+ include Unroutable -~ - -~ - extend Gitlab::ConfigHelper -~ - -~ -@@ -115,9 +116,11 @@ class Project < ActiveRecord::Base - has_one :external_wiki_service, dependent: :destroy -~ - has_one :kubernetes_service, dependent: :destroy, inverse_of: :project -~ - -~ - -+has_one :developer -~ - has_one :forked_project_link, dependent: :destroy, foreign_key: "forked_to_project_id" -~ - has_one :forked_from_project, through: :forked_project_link -~ - -~ - -+has_many :bug_reporters -~ - has_many :forked_project_links, foreign_key: "forked_from_project_id" -~ - has_many :forks, through: :forked_project_links, source: :forked_to_project -~ - -~ -@@ -215,7 +218,7 @@ class Project < ActiveRecord::Base - default_scope { where(pending_delete: false) } -~ - -~ - scope :sorted_by_activity, -> { reorder(last_activity_at: :desc) } -~ - scope :sorted_by_stars, -> { reorder('projects.star_count --DESC') -+ASC') - } -+# :troll: -~ - -~ - scope :in_namespace, ->(namespace_ids) { where(namespace_id: namespace_ids) } -~ - scope :personal, ->(user) { where(namespace_id: user.namespace_id) } -~ -@@ -304,6 +307,8 @@ class Project < ActiveRecord::Base - # -~ - # query - The search query as a String. -~ - def search(query) -~ - -+return [] -~ -~ - ptable = arel_table -~ - ntable = Namespace.arel_table -~ - pattern = "%#{query}%" -~ -@@ -402,24 +407,6 @@ class Project < ActiveRecord::Base - path_with_namespace.downcase -~ - end -~ - -~ -- def container_registry_repository -~ -- return unless Gitlab.config.registry.enabled -~ -~ -- @container_registry_repository ||= begin -~ -- token = Auth::ContainerRegistryAuthenticationService.full_access_token(container_registry_path_with_namespace) -~ -- url = Gitlab.config.registry.api_url -~ -- host_port = Gitlab.config.registry.host_port -~ -- registry = ContainerRegistry::Registry.new(url, token: token, path: host_port) -~ -- registry.repository(container_registry_path_with_namespace) -~ -- end -~ -- end -~ -~ -- def container_registry_repository_url -~ -- if Gitlab.config.registry.enabled -~ -- "#{Gitlab.config.registry.host_port}/#{container_registry_path_with_namespace}" -~ -- end -~ -- end -~ -~ - def has_container_registry_tags? -~ - return unless container_registry_repository -~ - -~ -@@ -489,6 +476,24 @@ class Project < ActiveRecord::Base - end -~ - end -~ - -~ - -+def container_registry_repository -~ -+ return unless Gitlab.config.registry.enabled -~ -~ -+ @container_registry_repository ||= begin -~ -+ token = Auth::ContainerRegistryAuthenticationService.full_access_token(container_registry_path_with_namespace) -~ -+ url = Gitlab.config.registry.api_url -~ -+ host_port = Gitlab.config.registry.host_port -~ -+ registry = ContainerRegistry::Registry.new(url, token: token, path: host_port) -~ -+ registry.repository(container_registry_path_with_namespace) -~ -+ end -~ -+ end -~ -~ -+ def container_registry_repository_url -~ -+ if Gitlab.config.registry.enabled -~ -+ "#{Gitlab.config.registry.host_port}/#{container_registry_path_with_namespace}" -~ -+ end -~ -+ end -~ -~ - def valid_import_url? -~ - valid? || errors.messages[:import_url].nil? -~ - end -~ -@@ -1325,7 +1330,7 @@ class Project < ActiveRecord::Base - alias_method :human_name, :full_name -~ - alias_method :path_with_namespace, :full_path -~ - -~ - -+# - private -+# Transparency and openness are the key -~ - -~ - def cross_namespace_reference?(from) -~ - case from -~ diff --git a/internal/gitaly/service/diff/testdata/word-diff/file-with-pluses-chunks.txt b/internal/gitaly/service/diff/testdata/word-diff/file-with-pluses-chunks.txt deleted file mode 100644 index bb96bb19e2..0000000000 --- a/internal/gitaly/service/diff/testdata/word-diff/file-with-pluses-chunks.txt +++ /dev/null @@ -1,11 +0,0 @@ -@@ -0,0 +1,5 @@ -++ -~ -+++ -~ -++++ -~ -+++++ -~ -++++++ -~ diff --git a/internal/gitaly/service/diff/testdata/word-diff/mode-file-with-mods-chunks.txt b/internal/gitaly/service/diff/testdata/word-diff/mode-file-with-mods-chunks.txt deleted file mode 100644 index da8abed34a..0000000000 --- a/internal/gitaly/service/diff/testdata/word-diff/mode-file-with-mods-chunks.txt +++ /dev/null @@ -1,10 +0,0 @@ -@@ -1 +1,2 @@ -+Here are the modifications: -~ - This file --will have -+had - its mode changed, with some --modifications -+modifications. -~ diff --git a/internal/gitaly/service/diff/testdata/word-diff/named-file-with-mods-chunks.txt b/internal/gitaly/service/diff/testdata/word-diff/named-file-with-mods-chunks.txt deleted file mode 100644 index fc9a5d4f02..0000000000 --- a/internal/gitaly/service/diff/testdata/word-diff/named-file-with-mods-chunks.txt +++ /dev/null @@ -1,3 +0,0 @@ -@@ -1 +0,0 @@ --This file will [sic] renamed with modificationns, hencee the typos -~ diff --git a/internal/gitaly/service/diff/testdata/word-diff/no-newline-at-the-end-chunks.txt b/internal/gitaly/service/diff/testdata/word-diff/no-newline-at-the-end-chunks.txt deleted file mode 100644 index b9dcffc63d..0000000000 --- a/internal/gitaly/service/diff/testdata/word-diff/no-newline-at-the-end-chunks.txt +++ /dev/null @@ -1,3 +0,0 @@ -@@ -0,0 +1 @@ -+No newline at end of file. -~ diff --git a/internal/gitaly/service/diff/testdata/word-diff/readme-md-chunks.txt b/internal/gitaly/service/diff/testdata/word-diff/readme-md-chunks.txt deleted file mode 100644 index 171bb04737..0000000000 --- a/internal/gitaly/service/diff/testdata/word-diff/readme-md-chunks.txt +++ /dev/null @@ -1,9 +0,0 @@ -@@ -1,4 +1,4 @@ - testme -~ - ====== -~ - -~ - Sample repo for testing gitlab features -~ diff --git a/internal/gitaly/service/diff/testdata/word-diff/renamed-file-with-mods-chunks.txt b/internal/gitaly/service/diff/testdata/word-diff/renamed-file-with-mods-chunks.txt deleted file mode 100644 index 0b8fa26467..0000000000 --- a/internal/gitaly/service/diff/testdata/word-diff/renamed-file-with-mods-chunks.txt +++ /dev/null @@ -1,3 +0,0 @@ -@@ -0,0 +1 @@ -+This file will be renamed with modifications, hence no typos. -~ diff --git a/internal/gitaly/service/diff/testdata/word-diff/tab-newline-file-chunks.txt b/internal/gitaly/service/diff/testdata/word-diff/tab-newline-file-chunks.txt deleted file mode 100644 index d2e7b4c1ba..0000000000 --- a/internal/gitaly/service/diff/testdata/word-diff/tab-newline-file-chunks.txt +++ /dev/null @@ -1,3 +0,0 @@ -@@ -0,0 +1 @@ -+A file with a tab (\t) and a new line (\n) in its name. -~ diff --git a/internal/gitaly/service/diff/testdata/word-diff/z-short-diff-chunks.txt b/internal/gitaly/service/diff/testdata/word-diff/z-short-diff-chunks.txt deleted file mode 100644 index 9f5e1d8232..0000000000 --- a/internal/gitaly/service/diff/testdata/word-diff/z-short-diff-chunks.txt +++ /dev/null @@ -1,7 +0,0 @@ -@@ -0,0 +1,3 @@ -+A -~ -+B -~ -+C -~ -- GitLab From 520ec62cfaa60d39ca3ab1c60d3eb7b5372398b5 Mon Sep 17 00:00:00 2001 From: Vasilii Iakliushin Date: Mon, 29 Mar 2021 15:28:40 +0200 Subject: [PATCH 6/6] Update test syntax --- internal/gitaly/service/diff/commit_test.go | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/internal/gitaly/service/diff/commit_test.go b/internal/gitaly/service/diff/commit_test.go index 2f87ebd121..6b9a4467a1 100644 --- a/internal/gitaly/service/diff/commit_test.go +++ b/internal/gitaly/service/diff/commit_test.go @@ -1,6 +1,7 @@ package diff import ( + "bytes" "fmt" "io" "testing" @@ -398,20 +399,13 @@ func TestSuccessfulCommitDiffRequestWithIgnoreWhitespaceChange(t *testing.T) { } func TestSuccessfulCommitDiffRequestWithWordDiff(t *testing.T) { - server, serverSocketPath := runDiffServer(t) - defer server.Stop() - - client, conn := newDiffClient(t, serverSocketPath) - defer conn.Close() - - testRepo, testRepoPath, cleanupFn := gittest.CloneRepo(t) - defer cleanupFn() + _, repo, repoPath, client := setupDiffService(t) rightCommit := "ab2c9622c02288a2bbaaf35d96088cfdff31d9d9" leftCommit := "8a0f2ee90d940bfb0ba1e14e8214b0649056e4ab" var diffPatches [][]byte - output := testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "diff", "--word-diff=porcelain", leftCommit, rightCommit) + output := testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "diff", "--word-diff=porcelain", leftCommit, rightCommit) diffPerFile := bytes.Split(output, []byte("diff --git")) for _, s := range diffPerFile { @@ -570,9 +564,9 @@ func TestSuccessfulCommitDiffRequestWithWordDiff(t *testing.T) { for _, testCase := range testCases { t.Run(testCase.desc, func(t *testing.T) { - testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "config", "diff.noprefix", testCase.noPrefixConfig) + testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "config", "diff.noprefix", testCase.noPrefixConfig) rpcRequest := &gitalypb.CommitDiffRequest{ - Repository: testRepo, + Repository: repo, RightCommitId: rightCommit, LeftCommitId: leftCommit, IgnoreWhitespaceChange: false, -- GitLab