From b9cb4c580fa5aa2c23261a10b340264034e82370 Mon Sep 17 00:00:00 2001 From: Geoffrey Gilmore Date: Tue, 7 May 2024 11:50:00 -0700 Subject: [PATCH] gitserver: grpc: remove now unused DiffSymbols func (#62360) --- CHANGELOG.md | 1 + internal/batches/sources/mocks_test.go | 130 ------------------------- internal/gitserver/client.go | 3 - internal/gitserver/commands.go | 20 ---- internal/gitserver/mocks_temp.go | 129 ------------------------ 5 files changed, 1 insertion(+), 282 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 13536d98ddc..ef19099eb41 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,7 @@ All notable changes to Sourcegraph are documented in this file. - Code insights drilldown behavior has been changed from a diff search to a point-in-time search with the new `rev:at.time()`. [#61953](https://github.com/sourcegraph/sourcegraph/pull/61953) - The `FirstEverCommit` gitserver client method has been changed to use a new bespoke gRPC endpoint instead of the legacy `exec` endpoint. [#62173](https://github.com/sourcegraph/sourcegraph/pull/62173) - The `GetBehindAhead` gitserver client method has been changed to use a new bespoke gRPC endpoint instead of the legacy `exec` endpoint. [#62217](https://github.com/sourcegraph/sourcegraph/pull/62217) +- All uses of the `DiffSymbols` gitserver client method have been replaced with the new `ChangedFiles` method. As such, the `DiffSymbos` method has been removed [#62355](https://github.com/sourcegraph/sourcegraph/pull/62355) ### Fixed diff --git a/internal/batches/sources/mocks_test.go b/internal/batches/sources/mocks_test.go index f354ffc7195..6a698f84e44 100644 --- a/internal/batches/sources/mocks_test.go +++ b/internal/batches/sources/mocks_test.go @@ -11013,9 +11013,6 @@ type MockGitserverClient struct { // DiffFunc is an instance of a mock function object controlling the // behavior of the method Diff. DiffFunc *GitserverClientDiffFunc - // DiffSymbolsFunc is an instance of a mock function object controlling - // the behavior of the method DiffSymbols. - DiffSymbolsFunc *GitserverClientDiffSymbolsFunc // FirstEverCommitFunc is an instance of a mock function object // controlling the behavior of the method FirstEverCommit. FirstEverCommitFunc *GitserverClientFirstEverCommitFunc @@ -11167,11 +11164,6 @@ func NewMockGitserverClient() *MockGitserverClient { return }, }, - DiffSymbolsFunc: &GitserverClientDiffSymbolsFunc{ - defaultHook: func(context.Context, api.RepoName, api.CommitID, api.CommitID) (r0 []byte, r1 error) { - return - }, - }, FirstEverCommitFunc: &GitserverClientFirstEverCommitFunc{ defaultHook: func(context.Context, api.RepoName) (r0 *gitdomain.Commit, r1 error) { return @@ -11384,11 +11376,6 @@ func NewStrictMockGitserverClient() *MockGitserverClient { panic("unexpected invocation of MockGitserverClient.Diff") }, }, - DiffSymbolsFunc: &GitserverClientDiffSymbolsFunc{ - defaultHook: func(context.Context, api.RepoName, api.CommitID, api.CommitID) ([]byte, error) { - panic("unexpected invocation of MockGitserverClient.DiffSymbols") - }, - }, FirstEverCommitFunc: &GitserverClientFirstEverCommitFunc{ defaultHook: func(context.Context, api.RepoName) (*gitdomain.Commit, error) { panic("unexpected invocation of MockGitserverClient.FirstEverCommit") @@ -11580,9 +11567,6 @@ func NewMockGitserverClientFrom(i gitserver.Client) *MockGitserverClient { DiffFunc: &GitserverClientDiffFunc{ defaultHook: i.Diff, }, - DiffSymbolsFunc: &GitserverClientDiffSymbolsFunc{ - defaultHook: i.DiffSymbols, - }, FirstEverCommitFunc: &GitserverClientFirstEverCommitFunc{ defaultHook: i.FirstEverCommit, }, @@ -12911,120 +12895,6 @@ func (c GitserverClientDiffFuncCall) Results() []interface{} { return []interface{}{c.Result0, c.Result1} } -// GitserverClientDiffSymbolsFunc describes the behavior when the -// DiffSymbols method of the parent MockGitserverClient instance is invoked. -type GitserverClientDiffSymbolsFunc struct { - defaultHook func(context.Context, api.RepoName, api.CommitID, api.CommitID) ([]byte, error) - hooks []func(context.Context, api.RepoName, api.CommitID, api.CommitID) ([]byte, error) - history []GitserverClientDiffSymbolsFuncCall - mutex sync.Mutex -} - -// DiffSymbols delegates to the next hook function in the queue and stores -// the parameter and result values of this invocation. -func (m *MockGitserverClient) DiffSymbols(v0 context.Context, v1 api.RepoName, v2 api.CommitID, v3 api.CommitID) ([]byte, error) { - r0, r1 := m.DiffSymbolsFunc.nextHook()(v0, v1, v2, v3) - m.DiffSymbolsFunc.appendCall(GitserverClientDiffSymbolsFuncCall{v0, v1, v2, v3, r0, r1}) - return r0, r1 -} - -// SetDefaultHook sets function that is called when the DiffSymbols method -// of the parent MockGitserverClient instance is invoked and the hook queue -// is empty. -func (f *GitserverClientDiffSymbolsFunc) SetDefaultHook(hook func(context.Context, api.RepoName, api.CommitID, api.CommitID) ([]byte, error)) { - f.defaultHook = hook -} - -// PushHook adds a function to the end of hook queue. Each invocation of the -// DiffSymbols method of the parent MockGitserverClient instance invokes the -// hook at the front of the queue and discards it. After the queue is empty, -// the default hook function is invoked for any future action. -func (f *GitserverClientDiffSymbolsFunc) PushHook(hook func(context.Context, api.RepoName, api.CommitID, api.CommitID) ([]byte, error)) { - f.mutex.Lock() - f.hooks = append(f.hooks, hook) - f.mutex.Unlock() -} - -// SetDefaultReturn calls SetDefaultHook with a function that returns the -// given values. -func (f *GitserverClientDiffSymbolsFunc) SetDefaultReturn(r0 []byte, r1 error) { - f.SetDefaultHook(func(context.Context, api.RepoName, api.CommitID, api.CommitID) ([]byte, error) { - return r0, r1 - }) -} - -// PushReturn calls PushHook with a function that returns the given values. -func (f *GitserverClientDiffSymbolsFunc) PushReturn(r0 []byte, r1 error) { - f.PushHook(func(context.Context, api.RepoName, api.CommitID, api.CommitID) ([]byte, error) { - return r0, r1 - }) -} - -func (f *GitserverClientDiffSymbolsFunc) nextHook() func(context.Context, api.RepoName, api.CommitID, api.CommitID) ([]byte, error) { - f.mutex.Lock() - defer f.mutex.Unlock() - - if len(f.hooks) == 0 { - return f.defaultHook - } - - hook := f.hooks[0] - f.hooks = f.hooks[1:] - return hook -} - -func (f *GitserverClientDiffSymbolsFunc) appendCall(r0 GitserverClientDiffSymbolsFuncCall) { - f.mutex.Lock() - f.history = append(f.history, r0) - f.mutex.Unlock() -} - -// History returns a sequence of GitserverClientDiffSymbolsFuncCall objects -// describing the invocations of this function. -func (f *GitserverClientDiffSymbolsFunc) History() []GitserverClientDiffSymbolsFuncCall { - f.mutex.Lock() - history := make([]GitserverClientDiffSymbolsFuncCall, len(f.history)) - copy(history, f.history) - f.mutex.Unlock() - - return history -} - -// GitserverClientDiffSymbolsFuncCall is an object that describes an -// invocation of method DiffSymbols on an instance of MockGitserverClient. -type GitserverClientDiffSymbolsFuncCall struct { - // Arg0 is the value of the 1st argument passed to this method - // invocation. - Arg0 context.Context - // Arg1 is the value of the 2nd argument passed to this method - // invocation. - Arg1 api.RepoName - // Arg2 is the value of the 3rd argument passed to this method - // invocation. - Arg2 api.CommitID - // Arg3 is the value of the 4th argument passed to this method - // invocation. - Arg3 api.CommitID - // Result0 is the value of the 1st result returned from this method - // invocation. - Result0 []byte - // Result1 is the value of the 2nd result returned from this method - // invocation. - Result1 error -} - -// Args returns an interface slice containing the arguments of this -// invocation. -func (c GitserverClientDiffSymbolsFuncCall) Args() []interface{} { - return []interface{}{c.Arg0, c.Arg1, c.Arg2, c.Arg3} -} - -// Results returns an interface slice containing the results of this -// invocation. -func (c GitserverClientDiffSymbolsFuncCall) Results() []interface{} { - return []interface{}{c.Result0, c.Result1} -} - // GitserverClientFirstEverCommitFunc describes the behavior when the // FirstEverCommit method of the parent MockGitserverClient instance is // invoked. diff --git a/internal/gitserver/client.go b/internal/gitserver/client.go index 4976f0eca24..2a7430f5b01 100644 --- a/internal/gitserver/client.go +++ b/internal/gitserver/client.go @@ -448,9 +448,6 @@ type Client interface { // If either the base or head id does not exist, a gitdomain.RevisionNotFoundError is returned. ChangedFiles(ctx context.Context, repo api.RepoName, base, head string) (ChangedFilesIterator, error) - // DiffSymbols performs a diff command which is expected to be parsed by our symbols package - DiffSymbols(ctx context.Context, repo api.RepoName, commitA, commitB api.CommitID) ([]byte, error) - // Commits returns all commits matching the options. Commits(ctx context.Context, repo api.RepoName, opt CommitsOptions) ([]*gitdomain.Commit, error) diff --git a/internal/gitserver/commands.go b/internal/gitserver/commands.go index 20191889b2a..0546d9b067b 100644 --- a/internal/gitserver/commands.go +++ b/internal/gitserver/commands.go @@ -418,26 +418,6 @@ func (i *changedFilesIterator) Close() { }) } -// DiffSymbols performs a diff command which is expected to be parsed by our symbols package -func (c *clientImplementor) DiffSymbols(ctx context.Context, repo api.RepoName, commitA, commitB api.CommitID) (_ []byte, err error) { - ctx, _, endObservation := c.operations.diffSymbols.With(ctx, &err, observation.Args{ - MetricLabelValues: []string{c.scope}, - Attrs: []attribute.KeyValue{ - repo.Attr(), - attribute.String("commitA", string(commitA)), - attribute.String("commitB", string(commitB)), - }, - }) - defer endObservation(1, observation.Args{}) - - command := c.gitCommand(repo, "diff", "-z", "--name-status", "--no-renames", string(commitA), string(commitB)) - out, err := command.Output(ctx) - if err != nil { - return nil, errors.Wrapf(err, "failed to run git diff on %s between %s and %s", repo, commitA, commitB) - } - return out, nil -} - // ReadDir reads the contents of the named directory at commit. func (c *clientImplementor) ReadDir(ctx context.Context, repo api.RepoName, commit api.CommitID, path string, recurse bool) (_ []fs.FileInfo, err error) { ctx, _, endObservation := c.operations.readDir.With(ctx, &err, observation.Args{ diff --git a/internal/gitserver/mocks_temp.go b/internal/gitserver/mocks_temp.go index a0c7e74844a..4e20778d317 100644 --- a/internal/gitserver/mocks_temp.go +++ b/internal/gitserver/mocks_temp.go @@ -57,9 +57,6 @@ type MockClient struct { // DiffFunc is an instance of a mock function object controlling the // behavior of the method Diff. DiffFunc *ClientDiffFunc - // DiffSymbolsFunc is an instance of a mock function object controlling - // the behavior of the method DiffSymbols. - DiffSymbolsFunc *ClientDiffSymbolsFunc // FirstEverCommitFunc is an instance of a mock function object // controlling the behavior of the method FirstEverCommit. FirstEverCommitFunc *ClientFirstEverCommitFunc @@ -211,11 +208,6 @@ func NewMockClient() *MockClient { return }, }, - DiffSymbolsFunc: &ClientDiffSymbolsFunc{ - defaultHook: func(context.Context, api.RepoName, api.CommitID, api.CommitID) (r0 []byte, r1 error) { - return - }, - }, FirstEverCommitFunc: &ClientFirstEverCommitFunc{ defaultHook: func(context.Context, api.RepoName) (r0 *gitdomain.Commit, r1 error) { return @@ -428,11 +420,6 @@ func NewStrictMockClient() *MockClient { panic("unexpected invocation of MockClient.Diff") }, }, - DiffSymbolsFunc: &ClientDiffSymbolsFunc{ - defaultHook: func(context.Context, api.RepoName, api.CommitID, api.CommitID) ([]byte, error) { - panic("unexpected invocation of MockClient.DiffSymbols") - }, - }, FirstEverCommitFunc: &ClientFirstEverCommitFunc{ defaultHook: func(context.Context, api.RepoName) (*gitdomain.Commit, error) { panic("unexpected invocation of MockClient.FirstEverCommit") @@ -623,9 +610,6 @@ func NewMockClientFrom(i Client) *MockClient { DiffFunc: &ClientDiffFunc{ defaultHook: i.Diff, }, - DiffSymbolsFunc: &ClientDiffSymbolsFunc{ - defaultHook: i.DiffSymbols, - }, FirstEverCommitFunc: &ClientFirstEverCommitFunc{ defaultHook: i.FirstEverCommit, }, @@ -1934,119 +1918,6 @@ func (c ClientDiffFuncCall) Results() []interface{} { return []interface{}{c.Result0, c.Result1} } -// ClientDiffSymbolsFunc describes the behavior when the DiffSymbols method -// of the parent MockClient instance is invoked. -type ClientDiffSymbolsFunc struct { - defaultHook func(context.Context, api.RepoName, api.CommitID, api.CommitID) ([]byte, error) - hooks []func(context.Context, api.RepoName, api.CommitID, api.CommitID) ([]byte, error) - history []ClientDiffSymbolsFuncCall - mutex sync.Mutex -} - -// DiffSymbols delegates to the next hook function in the queue and stores -// the parameter and result values of this invocation. -func (m *MockClient) DiffSymbols(v0 context.Context, v1 api.RepoName, v2 api.CommitID, v3 api.CommitID) ([]byte, error) { - r0, r1 := m.DiffSymbolsFunc.nextHook()(v0, v1, v2, v3) - m.DiffSymbolsFunc.appendCall(ClientDiffSymbolsFuncCall{v0, v1, v2, v3, r0, r1}) - return r0, r1 -} - -// SetDefaultHook sets function that is called when the DiffSymbols method -// of the parent MockClient instance is invoked and the hook queue is empty. -func (f *ClientDiffSymbolsFunc) SetDefaultHook(hook func(context.Context, api.RepoName, api.CommitID, api.CommitID) ([]byte, error)) { - f.defaultHook = hook -} - -// PushHook adds a function to the end of hook queue. Each invocation of the -// DiffSymbols method of the parent MockClient instance invokes the hook at -// the front of the queue and discards it. After the queue is empty, the -// default hook function is invoked for any future action. -func (f *ClientDiffSymbolsFunc) PushHook(hook func(context.Context, api.RepoName, api.CommitID, api.CommitID) ([]byte, error)) { - f.mutex.Lock() - f.hooks = append(f.hooks, hook) - f.mutex.Unlock() -} - -// SetDefaultReturn calls SetDefaultHook with a function that returns the -// given values. -func (f *ClientDiffSymbolsFunc) SetDefaultReturn(r0 []byte, r1 error) { - f.SetDefaultHook(func(context.Context, api.RepoName, api.CommitID, api.CommitID) ([]byte, error) { - return r0, r1 - }) -} - -// PushReturn calls PushHook with a function that returns the given values. -func (f *ClientDiffSymbolsFunc) PushReturn(r0 []byte, r1 error) { - f.PushHook(func(context.Context, api.RepoName, api.CommitID, api.CommitID) ([]byte, error) { - return r0, r1 - }) -} - -func (f *ClientDiffSymbolsFunc) nextHook() func(context.Context, api.RepoName, api.CommitID, api.CommitID) ([]byte, error) { - f.mutex.Lock() - defer f.mutex.Unlock() - - if len(f.hooks) == 0 { - return f.defaultHook - } - - hook := f.hooks[0] - f.hooks = f.hooks[1:] - return hook -} - -func (f *ClientDiffSymbolsFunc) appendCall(r0 ClientDiffSymbolsFuncCall) { - f.mutex.Lock() - f.history = append(f.history, r0) - f.mutex.Unlock() -} - -// History returns a sequence of ClientDiffSymbolsFuncCall objects -// describing the invocations of this function. -func (f *ClientDiffSymbolsFunc) History() []ClientDiffSymbolsFuncCall { - f.mutex.Lock() - history := make([]ClientDiffSymbolsFuncCall, len(f.history)) - copy(history, f.history) - f.mutex.Unlock() - - return history -} - -// ClientDiffSymbolsFuncCall is an object that describes an invocation of -// method DiffSymbols on an instance of MockClient. -type ClientDiffSymbolsFuncCall struct { - // Arg0 is the value of the 1st argument passed to this method - // invocation. - Arg0 context.Context - // Arg1 is the value of the 2nd argument passed to this method - // invocation. - Arg1 api.RepoName - // Arg2 is the value of the 3rd argument passed to this method - // invocation. - Arg2 api.CommitID - // Arg3 is the value of the 4th argument passed to this method - // invocation. - Arg3 api.CommitID - // Result0 is the value of the 1st result returned from this method - // invocation. - Result0 []byte - // Result1 is the value of the 2nd result returned from this method - // invocation. - Result1 error -} - -// Args returns an interface slice containing the arguments of this -// invocation. -func (c ClientDiffSymbolsFuncCall) Args() []interface{} { - return []interface{}{c.Arg0, c.Arg1, c.Arg2, c.Arg3} -} - -// Results returns an interface slice containing the results of this -// invocation. -func (c ClientDiffSymbolsFuncCall) Results() []interface{} { - return []interface{}{c.Result0, c.Result1} -} - // ClientFirstEverCommitFunc describes the behavior when the FirstEverCommit // method of the parent MockClient instance is invoked. type ClientFirstEverCommitFunc struct {