Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gitserver: grpc: port DiffSymbols from client as new GitBackend.ChangedFiles() func #62252

Conversation

ggilmore
Copy link
Contributor

@ggilmore ggilmore commented Apr 29, 2024

Part of #61691

This PR adds a new method, ChangedFiles to the git cli backend that lists the files that between the base and head commits, along with their added/modified/deleted status. Unlike the current workflow that involves multiple callsites with their own implementations for parsing the raw gitserver exec output, all the parsing now happens server-side and is well tested.

This functionality should be able to subsume the other diff-tree / diff use-cases in:

Test plan

Added new unit tests:

  • some that test the E2E output of the git diff-tree command
  • adapted tests from
    func TestParseGitDiffOutput(t *testing.T) {
    testCases := []struct {
    output []byte
    expectedChanges Changes
    shouldError bool
    }{
    {
    output: combineBytes(
    []byte("A"), NUL, []byte("added1.json"), NUL,
    []byte("M"), NUL, []byte("modified1.json"), NUL,
    []byte("D"), NUL, []byte("deleted1.json"), NUL,
    []byte("A"), NUL, []byte("added2.json"), NUL,
    []byte("M"), NUL, []byte("modified2.json"), NUL,
    []byte("D"), NUL, []byte("deleted2.json"), NUL,
    []byte("A"), NUL, []byte("added3.json"), NUL,
    []byte("M"), NUL, []byte("modified3.json"), NUL,
    []byte("D"), NUL, []byte("deleted3.json"), NUL,
    ),
    expectedChanges: Changes{
    Added: []string{"added1.json", "added2.json", "added3.json"},
    Modified: []string{"modified1.json", "modified2.json", "modified3.json"},
    Deleted: []string{"deleted1.json", "deleted2.json", "deleted3.json"},
    },
    },
    {
    output: combineBytes(
    []byte("A"), NUL, []byte("added1.json"), NUL,
    []byte("M"), NUL, []byte("modified1.json"), NUL,
    []byte("D"), NUL,
    ),
    shouldError: true,
    },
    {
    output: []byte{},
    },
    }
    for _, testCase := range testCases {
    changes, err := parseGitDiffOutput(testCase.output)
    if err != nil {
    if !testCase.shouldError {
    t.Fatalf("unexpected error parsing git diff output: %s", err)
    }
    } else if testCase.shouldError {
    t.Fatalf("expected error, got none")
    }
    if diff := cmp.Diff(testCase.expectedChanges, changes); diff != "" {
    t.Errorf("unexpected changes (-want +got):\n%s", diff)
    }
    }
    }

Copy link
Contributor Author

ggilmore commented Apr 29, 2024

This stack of pull requests is managed by Graphite. Learn more about stacking.

Join @ggilmore and the rest of your teammates on Graphite Graphite

@github-actions github-actions bot added team/product-platform team/source Tickets under the purview of Source - the one Source to graph it all labels Apr 29, 2024
@ggilmore ggilmore force-pushed the 04-26-gitserver_grpc_swap_client_implementation_of_getaheadbehind_from_exec_to_bespoke_grpc_endpoint branch from d02b395 to 39e5cfb Compare April 30, 2024 05:16
@ggilmore ggilmore force-pushed the 04-29-gitserver_grpc_port_diffsymbols_from_client_as_new_gitbackend.changedfiles_func branch from cc96f91 to 75dd653 Compare April 30, 2024 05:16
@ggilmore ggilmore force-pushed the 04-26-gitserver_grpc_swap_client_implementation_of_getaheadbehind_from_exec_to_bespoke_grpc_endpoint branch from 39e5cfb to 3e6f221 Compare April 30, 2024 05:20
@ggilmore ggilmore force-pushed the 04-29-gitserver_grpc_port_diffsymbols_from_client_as_new_gitbackend.changedfiles_func branch from 75dd653 to 18d4bba Compare April 30, 2024 05:20
@ggilmore ggilmore force-pushed the 04-26-gitserver_grpc_swap_client_implementation_of_getaheadbehind_from_exec_to_bespoke_grpc_endpoint branch from 3e6f221 to ca768ec Compare April 30, 2024 17:03
@ggilmore ggilmore force-pushed the 04-29-gitserver_grpc_port_diffsymbols_from_client_as_new_gitbackend.changedfiles_func branch from 18d4bba to 7a9e364 Compare April 30, 2024 17:03
@ggilmore ggilmore force-pushed the 04-26-gitserver_grpc_swap_client_implementation_of_getaheadbehind_from_exec_to_bespoke_grpc_endpoint branch from ca768ec to dd16782 Compare April 30, 2024 17:14
@ggilmore ggilmore force-pushed the 04-29-gitserver_grpc_port_diffsymbols_from_client_as_new_gitbackend.changedfiles_func branch from 7a9e364 to 319d6a9 Compare April 30, 2024 17:15
@ggilmore ggilmore force-pushed the 04-26-gitserver_grpc_swap_client_implementation_of_getaheadbehind_from_exec_to_bespoke_grpc_endpoint branch from dd16782 to 6d618e6 Compare April 30, 2024 18:06
@ggilmore ggilmore force-pushed the 04-29-gitserver_grpc_port_diffsymbols_from_client_as_new_gitbackend.changedfiles_func branch from 319d6a9 to d8cb7fe Compare April 30, 2024 18:06
@ggilmore ggilmore force-pushed the 04-26-gitserver_grpc_swap_client_implementation_of_getaheadbehind_from_exec_to_bespoke_grpc_endpoint branch from 6d618e6 to a450397 Compare April 30, 2024 19:21
@ggilmore ggilmore force-pushed the 04-29-gitserver_grpc_port_diffsymbols_from_client_as_new_gitbackend.changedfiles_func branch from d8cb7fe to 59cae3e Compare April 30, 2024 19:21
@ggilmore ggilmore force-pushed the 04-26-gitserver_grpc_swap_client_implementation_of_getaheadbehind_from_exec_to_bespoke_grpc_endpoint branch from a450397 to 48fb88c Compare April 30, 2024 19:22
@ggilmore ggilmore force-pushed the 04-29-gitserver_grpc_port_diffsymbols_from_client_as_new_gitbackend.changedfiles_func branch from 59cae3e to 43d8723 Compare April 30, 2024 19:22
@ggilmore ggilmore force-pushed the 04-26-gitserver_grpc_swap_client_implementation_of_getaheadbehind_from_exec_to_bespoke_grpc_endpoint branch from 48fb88c to 1a44563 Compare April 30, 2024 19:37
@ggilmore ggilmore force-pushed the 04-29-gitserver_grpc_port_diffsymbols_from_client_as_new_gitbackend.changedfiles_func branch from 43d8723 to 9e1c79e Compare April 30, 2024 19:37
@ggilmore ggilmore force-pushed the 04-26-gitserver_grpc_swap_client_implementation_of_getaheadbehind_from_exec_to_bespoke_grpc_endpoint branch from 1a44563 to 8ad5a04 Compare April 30, 2024 20:07
@ggilmore ggilmore force-pushed the 04-29-gitserver_grpc_port_diffsymbols_from_client_as_new_gitbackend.changedfiles_func branch from f800d7e to 4a1d819 Compare May 2, 2024 18:04
@ggilmore ggilmore force-pushed the 04-26-gitserver_grpc_swap_client_implementation_of_getaheadbehind_from_exec_to_bespoke_grpc_endpoint branch from 1762bcd to 9c1c0ad Compare May 2, 2024 18:18
@ggilmore ggilmore force-pushed the 04-29-gitserver_grpc_port_diffsymbols_from_client_as_new_gitbackend.changedfiles_func branch from 4a1d819 to 6dcb97e Compare May 2, 2024 18:18
@ggilmore ggilmore force-pushed the 04-26-gitserver_grpc_swap_client_implementation_of_getaheadbehind_from_exec_to_bespoke_grpc_endpoint branch from 9c1c0ad to ea74865 Compare May 2, 2024 18:24
@ggilmore ggilmore force-pushed the 04-29-gitserver_grpc_port_diffsymbols_from_client_as_new_gitbackend.changedfiles_func branch from 6dcb97e to 4dc9626 Compare May 2, 2024 18:24
@ggilmore ggilmore force-pushed the 04-26-gitserver_grpc_swap_client_implementation_of_getaheadbehind_from_exec_to_bespoke_grpc_endpoint branch from ea74865 to 226ef53 Compare May 2, 2024 18:26
@ggilmore ggilmore force-pushed the 04-29-gitserver_grpc_port_diffsymbols_from_client_as_new_gitbackend.changedfiles_func branch 3 times, most recently from 2b94c9e to 95ae787 Compare May 2, 2024 18:53
@ggilmore ggilmore force-pushed the 04-26-gitserver_grpc_swap_client_implementation_of_getaheadbehind_from_exec_to_bespoke_grpc_endpoint branch from 226ef53 to 9a67eff Compare May 3, 2024 16:48
@ggilmore ggilmore force-pushed the 04-29-gitserver_grpc_port_diffsymbols_from_client_as_new_gitbackend.changedfiles_func branch from 95ae787 to 8a62f4f Compare May 3, 2024 16:48
@ggilmore ggilmore force-pushed the 04-26-gitserver_grpc_swap_client_implementation_of_getaheadbehind_from_exec_to_bespoke_grpc_endpoint branch from 9a67eff to 3c952f2 Compare May 3, 2024 17:18
Base automatically changed from 04-26-gitserver_grpc_swap_client_implementation_of_getaheadbehind_from_exec_to_bespoke_grpc_endpoint to main May 3, 2024 17:27
@ggilmore ggilmore force-pushed the 04-29-gitserver_grpc_port_diffsymbols_from_client_as_new_gitbackend.changedfiles_func branch from 8a62f4f to 04ebcb0 Compare May 3, 2024 22:03
@ggilmore ggilmore requested review from eseliger and pjlast May 6, 2024 19:16
Copy link
Contributor Author

ggilmore commented May 6, 2024

@sourcegraph/source Could you please re-review this (and the upstream PRs)? I refactored the approach to use the iterator pattern.

@ggilmore ggilmore force-pushed the 04-29-gitserver_grpc_port_diffsymbols_from_client_as_new_gitbackend.changedfiles_func branch from 04ebcb0 to 09a543b Compare May 6, 2024 19:37
Copy link
Member

@eseliger eseliger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, left a question about using an iterator here as well

Comment on lines 110 to 116
switch status[0] {
case 'A':
changes = append(changes, gitdomain.PathStatus{Path: string(path), Status: gitdomain.AddedAMD})
case 'M':
changes = append(changes, gitdomain.PathStatus{Path: string(path), Status: gitdomain.ModifiedAMD})
case 'D':
changes = append(changes, gitdomain.PathStatus{Path: string(path), Status: gitdomain.DeletedAMD})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic in LogReverseEach that we had here: https://github.com/sourcegraph/sourcegraph/pull/62260/files#diff-e7b89c0e3e24a2fda065a7cfa5f06f7b7def4d36189d88e495e5b40f5ca9795fL112-L194 also does some more checks on submodule status and stuff. Not sure if needed here, but might be cool for consolidation. We can do that separately though

cmd/gitserver/internal/git/gitcli/diff.go Outdated Show resolved Hide resolved
cmd/gitserver/internal/git/gitcli/diff.go Outdated Show resolved Hide resolved
@ggilmore ggilmore force-pushed the 04-29-gitserver_grpc_port_diffsymbols_from_client_as_new_gitbackend.changedfiles_func branch 3 times, most recently from 469da92 to 6f8daa5 Compare May 7, 2024 03:47
@ggilmore ggilmore force-pushed the 04-29-gitserver_grpc_port_diffsymbols_from_client_as_new_gitbackend.changedfiles_func branch from 6f8daa5 to 1326bb8 Compare May 7, 2024 16:17
@ggilmore ggilmore merged commit b4c835b into main May 7, 2024
16 of 17 checks passed
@ggilmore ggilmore deleted the 04-29-gitserver_grpc_port_diffsymbols_from_client_as_new_gitbackend.changedfiles_func branch May 7, 2024 17:32
Copy link
Contributor Author

ggilmore commented May 7, 2024

Merge activity

ggilmore added a commit that referenced this pull request May 7, 2024
…ver (#62262)

Part of #60654


This PR implements a new gitserver gRPC method, ChangedFiles that lists the files that changed between two commits alonside their added/modified/deleted status. This PR builds on the functionality exposed in #62252. 

## Test plan

Unit tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla-signed team/product-platform team/source Tickets under the purview of Source - the one Source to graph it all
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants