Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Commit 74f4831

Browse files
chore: Replace gitserver.Client -> minimalGitserver in codenav (#64416)
In codenav, we use very few APIs from gitserver, so let's use a more narrow interface (which we can potentially fake in the future) instead of depending on gitserver.Client directly.
1 parent 6a28eb8 commit 74f4831

File tree

5 files changed

+42
-17
lines changed

5 files changed

+42
-17
lines changed

internal/codeintel/codenav/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ go_library(
1414
"observability.go",
1515
"request_state.go",
1616
"service.go",
17+
"service_deps.go",
1718
"service_new.go",
1819
"syntactic.go",
1920
"types.go",

internal/codeintel/codenav/commit_cache.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88

99
"github.com/sourcegraph/sourcegraph/internal/api"
1010
"github.com/sourcegraph/sourcegraph/internal/collections"
11-
"github.com/sourcegraph/sourcegraph/internal/gitserver"
1211
"github.com/sourcegraph/sourcegraph/internal/gitserver/gitdomain"
1312
"github.com/sourcegraph/sourcegraph/lib/errors"
1413
)
@@ -25,12 +24,12 @@ type RepositoryCommit struct {
2524

2625
type commitCache struct {
2726
repoStore minimalRepoStore
28-
gitserverClient gitserver.Client
27+
gitserverClient minimalGitserver
2928
mutex sync.RWMutex
3029
cache map[api.RepoID]map[api.CommitID]bool
3130
}
3231

33-
func NewCommitCache(repoStore minimalRepoStore, client gitserver.Client) CommitCache {
32+
func NewCommitCache(repoStore minimalRepoStore, client minimalGitserver) CommitCache {
3433
return &commitCache{
3534
repoStore: repoStore,
3635
gitserverClient: client,

internal/codeintel/codenav/gittree_translator.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ type GitTreeTranslator interface {
3737
Prefetch(ctx context.Context, from api.CommitID, to api.CommitID, paths []core.RepoRelPath)
3838
}
3939

40-
func NewGitTreeTranslator(client gitserver.Client, repo sgtypes.Repo) GitTreeTranslator {
40+
func NewGitTreeTranslator(client minimalGitserver, repo sgtypes.Repo) GitTreeTranslator {
4141
return &newTranslator{
4242
client: client,
4343
repo: repo,
@@ -52,7 +52,7 @@ type hunkCacheKey struct {
5252
}
5353

5454
type newTranslator struct {
55-
client gitserver.Client
55+
client minimalGitserver
5656
repo sgtypes.Repo
5757
cacheLock sync.RWMutex
5858
hunkCache map[hunkCacheKey]func() ([]compactHunk, error)

internal/codeintel/codenav/service.go

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"github.com/sourcegraph/sourcegraph/internal/codeintel/codenav/shared"
2222
"github.com/sourcegraph/sourcegraph/internal/codeintel/core"
2323
uploadsshared "github.com/sourcegraph/sourcegraph/internal/codeintel/uploads/shared"
24-
"github.com/sourcegraph/sourcegraph/internal/gitserver"
2524
"github.com/sourcegraph/sourcegraph/internal/observation"
2625
searcher "github.com/sourcegraph/sourcegraph/internal/search/client"
2726
"github.com/sourcegraph/sourcegraph/internal/types"
@@ -33,28 +32,19 @@ import (
3332
type Service struct {
3433
repoStore minimalRepoStore
3534
lsifstore lsifstore.LsifStore
36-
gitserver gitserver.Client
35+
gitserver minimalGitserver
3736
uploadSvc UploadService
3837
searchClient searcher.SearchClient
3938
operations *operations
4039
logger log.Logger
4140
}
4241

43-
// minimalRepoStore covers the subset of database.RepoStore APIs that we need
44-
// for code navigation.
45-
//
46-
// Prefer calling GetReposSetByIDs instead of calling Get in a loop.
47-
type minimalRepoStore interface {
48-
Get(context.Context, api.RepoID) (*types.Repo, error)
49-
GetReposSetByIDs(context.Context, ...api.RepoID) (map[api.RepoID]*types.Repo, error)
50-
}
51-
5242
func newService(
5343
observationCtx *observation.Context,
5444
repoStore minimalRepoStore,
5545
lsifstore lsifstore.LsifStore,
5646
uploadSvc UploadService,
57-
gitserver gitserver.Client,
47+
gitserver minimalGitserver,
5848
searchClient searcher.SearchClient,
5949
logger log.Logger,
6050
) *Service {
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package codenav
2+
3+
import (
4+
"context"
5+
"io"
6+
"io/fs"
7+
8+
"github.com/sourcegraph/sourcegraph/internal/api"
9+
"github.com/sourcegraph/sourcegraph/internal/database"
10+
"github.com/sourcegraph/sourcegraph/internal/gitserver"
11+
"github.com/sourcegraph/sourcegraph/internal/gitserver/gitdomain"
12+
"github.com/sourcegraph/sourcegraph/internal/types"
13+
)
14+
15+
// minimalRepoStore covers the subset of database.RepoStore APIs that we need
16+
// for code navigation.
17+
//
18+
// Prefer calling GetReposSetByIDs instead of calling Get in a loop.
19+
type minimalRepoStore interface {
20+
Get(context.Context, api.RepoID) (*types.Repo, error)
21+
GetReposSetByIDs(context.Context, ...api.RepoID) (map[api.RepoID]*types.Repo, error)
22+
}
23+
24+
var _ minimalRepoStore = (database.RepoStore)(nil)
25+
26+
// minimalGitserver covers the subset of gitserver.Client APIs that we
27+
// need for code navigation
28+
type minimalGitserver interface {
29+
Diff(ctx context.Context, repo api.RepoName, opts gitserver.DiffOptions) (*gitserver.DiffFileIterator, error)
30+
GetCommit(ctx context.Context, repo api.RepoName, id api.CommitID) (*gitdomain.Commit, error)
31+
NewFileReader(ctx context.Context, repo api.RepoName, commit api.CommitID, name string) (io.ReadCloser, error)
32+
Stat(ctx context.Context, repo api.RepoName, commit api.CommitID, path string) (fs.FileInfo, error)
33+
}
34+
35+
var _ minimalGitserver = (gitserver.Client)(nil)

0 commit comments

Comments
 (0)