mirror of
https://github.com/sourcegraph/sourcegraph.git
synced 2026-02-06 19:21:50 +00:00
Gitserver: move subrepo permissions client to the gitserver client struct (#57429)
Most of our gitserver client methods require a subrepo permissions checker, but we require the caller to pass one in every time. This adds the checker to the gitserver client struct so that it can be used for all methods. Since it's one more thing that needs to be overridden for some tests, I added some more general helpers around constructing a test client as well. Some history: the authz.DefaultSubrepoPermsClient was written as an global variable that was overridden during the enterprise init step. However, we no longer have an enterprise init step, so this does not need to be a global, mutable variable. This takes the first step towards making that not the case by removing many of the sites that reference the global authz.DefaultSubrepoPermsClient, consolidating all those references to the NewClient() method, which eventually should be made to require a subrepo perms client as a dependency rather than relying on the global.
This commit is contained in:
parent
6895d49f35
commit
ef1573f51d
@ -93,7 +93,6 @@ go_test(
|
||||
"//cmd/frontend/envvar",
|
||||
"//internal/actor",
|
||||
"//internal/api",
|
||||
"//internal/authz",
|
||||
"//internal/conf",
|
||||
"//internal/database",
|
||||
"//internal/database/dbmocks",
|
||||
|
||||
@ -11,7 +11,6 @@ import (
|
||||
"github.com/sourcegraph/log"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/internal/api"
|
||||
"github.com/sourcegraph/sourcegraph/internal/authz"
|
||||
"github.com/sourcegraph/sourcegraph/internal/env"
|
||||
"github.com/sourcegraph/sourcegraph/internal/gitserver"
|
||||
"github.com/sourcegraph/sourcegraph/internal/gitserver/gitdomain"
|
||||
@ -47,10 +46,10 @@ func InventoryContext(logger log.Logger, repo api.RepoName, gsClient gitserver.C
|
||||
ReadTree: func(ctx context.Context, path string) ([]fs.FileInfo, error) {
|
||||
// TODO: As a perf optimization, we could read multiple levels of the Git tree at once
|
||||
// to avoid sequential tree traversal calls.
|
||||
return gsClient.ReadDir(ctx, authz.DefaultSubRepoPermsChecker, repo, commitID, path, false)
|
||||
return gsClient.ReadDir(ctx, repo, commitID, path, false)
|
||||
},
|
||||
NewFileReader: func(ctx context.Context, path string) (io.ReadCloser, error) {
|
||||
return gsClient.NewFileReader(ctx, authz.DefaultSubRepoPermsChecker, repo, commitID, path)
|
||||
return gsClient.NewFileReader(ctx, repo, commitID, path)
|
||||
},
|
||||
CacheGet: func(e fs.FileInfo) (inventory.Inventory, bool) {
|
||||
cacheKey := cacheKey(e)
|
||||
|
||||
@ -13,7 +13,6 @@ import (
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/cmd/frontend/envvar"
|
||||
"github.com/sourcegraph/sourcegraph/internal/api"
|
||||
"github.com/sourcegraph/sourcegraph/internal/authz"
|
||||
"github.com/sourcegraph/sourcegraph/internal/database"
|
||||
"github.com/sourcegraph/sourcegraph/internal/database/dbcache"
|
||||
"github.com/sourcegraph/sourcegraph/internal/errcode"
|
||||
@ -270,7 +269,7 @@ func (s *repos) GetInventory(ctx context.Context, repo *types.Repo, commitID api
|
||||
return nil, err
|
||||
}
|
||||
|
||||
root, err := s.gitserverClient.Stat(ctx, authz.DefaultSubRepoPermsChecker, repo.Name, commitID, "")
|
||||
root, err := s.gitserverClient.Stat(ctx, repo.Name, commitID, "")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -352,7 +351,7 @@ func (s *repos) GetCommit(ctx context.Context, repo *types.Repo, commitID api.Co
|
||||
return nil, errors.Errorf("non-absolute CommitID for Repos.GetCommit: %v", commitID)
|
||||
}
|
||||
|
||||
return s.gitserverClient.GetCommit(ctx, authz.DefaultSubRepoPermsChecker, repo.Name, commitID, gitserver.ResolveRevisionOptions{})
|
||||
return s.gitserverClient.GetCommit(ctx, repo.Name, commitID, gitserver.ResolveRevisionOptions{})
|
||||
}
|
||||
|
||||
// ErrRepoSeeOther indicates that the repo does not exist on this server but might exist on an external Sourcegraph
|
||||
|
||||
@ -20,7 +20,6 @@ import (
|
||||
"github.com/sourcegraph/log/logtest"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/internal/api"
|
||||
"github.com/sourcegraph/sourcegraph/internal/authz"
|
||||
"github.com/sourcegraph/sourcegraph/internal/database"
|
||||
"github.com/sourcegraph/sourcegraph/internal/database/dbmocks"
|
||||
"github.com/sourcegraph/sourcegraph/internal/errcode"
|
||||
@ -168,13 +167,13 @@ func TestReposGetInventory(t *testing.T) {
|
||||
return &protocol.RepoLookupResult{Repo: &protocol.RepoInfo{Name: wantRepo}}, nil
|
||||
}
|
||||
defer func() { repoupdater.MockRepoLookup = nil }()
|
||||
gitserverClient.StatFunc.SetDefaultHook(func(_ context.Context, _ authz.SubRepoPermissionChecker, _ api.RepoName, commit api.CommitID, path string) (fs.FileInfo, error) {
|
||||
gitserverClient.StatFunc.SetDefaultHook(func(_ context.Context, _ api.RepoName, commit api.CommitID, path string) (fs.FileInfo, error) {
|
||||
if commit != wantCommitID {
|
||||
t.Errorf("got commit %q, want %q", commit, wantCommitID)
|
||||
}
|
||||
return &fileutil.FileInfo{Name_: path, Mode_: os.ModeDir, Sys_: gitObjectInfo(wantRootOID)}, nil
|
||||
})
|
||||
gitserverClient.ReadDirFunc.SetDefaultHook(func(_ context.Context, _ authz.SubRepoPermissionChecker, _ api.RepoName, commit api.CommitID, name string, _ bool) ([]fs.FileInfo, error) {
|
||||
gitserverClient.ReadDirFunc.SetDefaultHook(func(_ context.Context, _ api.RepoName, commit api.CommitID, name string, _ bool) ([]fs.FileInfo, error) {
|
||||
if commit != wantCommitID {
|
||||
t.Errorf("got commit %q, want %q", commit, wantCommitID)
|
||||
}
|
||||
@ -190,7 +189,7 @@ func TestReposGetInventory(t *testing.T) {
|
||||
panic("unhandled mock ReadDir " + name)
|
||||
}
|
||||
})
|
||||
gitserverClient.NewFileReaderFunc.SetDefaultHook(func(_ context.Context, _ authz.SubRepoPermissionChecker, _ api.RepoName, commit api.CommitID, name string) (io.ReadCloser, error) {
|
||||
gitserverClient.NewFileReaderFunc.SetDefaultHook(func(_ context.Context, _ api.RepoName, commit api.CommitID, name string) (io.ReadCloser, error) {
|
||||
if commit != wantCommitID {
|
||||
t.Errorf("got commit %q, want %q", commit, wantCommitID)
|
||||
}
|
||||
|
||||
@ -8,7 +8,6 @@ import (
|
||||
"github.com/sourcegraph/log/logtest"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/internal/api"
|
||||
"github.com/sourcegraph/sourcegraph/internal/authz"
|
||||
"github.com/sourcegraph/sourcegraph/internal/database/dbmocks"
|
||||
"github.com/sourcegraph/sourcegraph/internal/gitserver"
|
||||
"github.com/sourcegraph/sourcegraph/internal/gitserver/gitdomain"
|
||||
@ -195,7 +194,7 @@ func TestRepos_GetCommit_repoupdaterError(t *testing.T) {
|
||||
var calledVCSRepoGetCommit bool
|
||||
|
||||
gsClient := gitserver.NewMockClient()
|
||||
gsClient.GetCommitFunc.SetDefaultHook(func(context.Context, authz.SubRepoPermissionChecker, api.RepoName, api.CommitID, gitserver.ResolveRevisionOptions) (*gitdomain.Commit, error) {
|
||||
gsClient.GetCommitFunc.SetDefaultHook(func(context.Context, api.RepoName, api.CommitID, gitserver.ResolveRevisionOptions) (*gitdomain.Commit, error) {
|
||||
calledVCSRepoGetCommit = true
|
||||
return &gitdomain.Commit{ID: want}, nil
|
||||
})
|
||||
|
||||
@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/internal/api"
|
||||
"github.com/sourcegraph/sourcegraph/internal/authz"
|
||||
"github.com/sourcegraph/sourcegraph/internal/gitserver"
|
||||
)
|
||||
|
||||
@ -13,7 +12,7 @@ func (r *GitTreeEntryResolver) Blame(ctx context.Context,
|
||||
StartLine int32
|
||||
EndLine int32
|
||||
}) ([]*hunkResolver, error) {
|
||||
hunks, err := r.gitserverClient.BlameFile(ctx, authz.DefaultSubRepoPermsChecker, r.commit.repoResolver.RepoName(), r.Path(), &gitserver.BlameOptions{
|
||||
hunks, err := r.gitserverClient.BlameFile(ctx, r.commit.repoResolver.RepoName(), r.Path(), &gitserver.BlameOptions{
|
||||
NewestCommit: api.CommitID(r.commit.OID()),
|
||||
StartLine: int(args.StartLine),
|
||||
EndLine: int(args.EndLine),
|
||||
|
||||
@ -17,7 +17,6 @@ import (
|
||||
"github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/externallink"
|
||||
"github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil"
|
||||
"github.com/sourcegraph/sourcegraph/internal/api"
|
||||
"github.com/sourcegraph/sourcegraph/internal/authz"
|
||||
"github.com/sourcegraph/sourcegraph/internal/database"
|
||||
"github.com/sourcegraph/sourcegraph/internal/gitserver"
|
||||
"github.com/sourcegraph/sourcegraph/internal/gitserver/gitdomain"
|
||||
@ -92,7 +91,7 @@ func (r *GitCommitResolver) resolveCommit(ctx context.Context) (*gitdomain.Commi
|
||||
}
|
||||
|
||||
opts := gitserver.ResolveRevisionOptions{}
|
||||
r.commit, r.commitErr = r.gitserverClient.GetCommit(ctx, authz.DefaultSubRepoPermsChecker, r.gitRepo, api.CommitID(r.oid), opts)
|
||||
r.commit, r.commitErr = r.gitserverClient.GetCommit(ctx, r.gitRepo, api.CommitID(r.oid), opts)
|
||||
})
|
||||
return r.commit, r.commitErr
|
||||
}
|
||||
@ -282,7 +281,7 @@ func (r *GitCommitResolver) path(ctx context.Context, path string, validate func
|
||||
tr, ctx := trace.New(ctx, "GitCommitResolver.path", attribute.String("path", path))
|
||||
defer tr.EndWithErr(&err)
|
||||
|
||||
stat, err := r.gitserverClient.Stat(ctx, authz.DefaultSubRepoPermsChecker, r.gitRepo, api.CommitID(r.oid), path)
|
||||
stat, err := r.gitserverClient.Stat(ctx, r.gitRepo, api.CommitID(r.oid), path)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return nil, nil
|
||||
@ -300,7 +299,7 @@ func (r *GitCommitResolver) path(ctx context.Context, path string, validate func
|
||||
}
|
||||
|
||||
func (r *GitCommitResolver) FileNames(ctx context.Context) ([]string, error) {
|
||||
return r.gitserverClient.LsFiles(ctx, authz.DefaultSubRepoPermsChecker, r.gitRepo, api.CommitID(r.oid))
|
||||
return r.gitserverClient.LsFiles(ctx, r.gitRepo, api.CommitID(r.oid))
|
||||
}
|
||||
|
||||
func (r *GitCommitResolver) Languages(ctx context.Context) ([]string, error) {
|
||||
|
||||
@ -16,7 +16,6 @@ import (
|
||||
"github.com/sourcegraph/sourcegraph/cmd/frontend/backend"
|
||||
"github.com/sourcegraph/sourcegraph/internal/actor"
|
||||
"github.com/sourcegraph/sourcegraph/internal/api"
|
||||
"github.com/sourcegraph/sourcegraph/internal/authz"
|
||||
"github.com/sourcegraph/sourcegraph/internal/database/dbmocks"
|
||||
"github.com/sourcegraph/sourcegraph/internal/extsvc"
|
||||
"github.com/sourcegraph/sourcegraph/internal/gitserver"
|
||||
@ -82,7 +81,7 @@ func TestGitCommitResolver(t *testing.T) {
|
||||
db.ReposFunc.SetDefaultReturn(repos)
|
||||
|
||||
client := gitserver.NewMockClient()
|
||||
client.GetCommitFunc.SetDefaultHook(func(context.Context, authz.SubRepoPermissionChecker, api.RepoName, api.CommitID, gitserver.ResolveRevisionOptions) (*gitdomain.Commit, error) {
|
||||
client.GetCommitFunc.SetDefaultHook(func(context.Context, api.RepoName, api.CommitID, gitserver.ResolveRevisionOptions) (*gitdomain.Commit, error) {
|
||||
return commit, nil
|
||||
})
|
||||
|
||||
@ -364,7 +363,6 @@ func TestGitCommitAncestors(t *testing.T) {
|
||||
|
||||
client.CommitsFunc.SetDefaultHook(func(
|
||||
ctx context.Context,
|
||||
authz authz.SubRepoPermissionChecker,
|
||||
repo api.RepoName,
|
||||
opt gitserver.CommitsOptions) ([]*gitdomain.Commit, error) {
|
||||
|
||||
|
||||
@ -6,7 +6,6 @@ import (
|
||||
"sync"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil"
|
||||
"github.com/sourcegraph/sourcegraph/internal/authz"
|
||||
"github.com/sourcegraph/sourcegraph/internal/database"
|
||||
"github.com/sourcegraph/sourcegraph/internal/gitserver"
|
||||
"github.com/sourcegraph/sourcegraph/internal/gitserver/gitdomain"
|
||||
@ -77,7 +76,7 @@ func (r *gitCommitConnectionResolver) compute(ctx context.Context) ([]*gitdomain
|
||||
return []*gitdomain.Commit{}, errors.Wrap(err, "failed to parse afterCursor")
|
||||
}
|
||||
|
||||
return r.gitserverClient.Commits(ctx, authz.DefaultSubRepoPermsChecker, r.repo.RepoName(), gitserver.CommitsOptions{
|
||||
return r.gitserverClient.Commits(ctx, r.repo.RepoName(), gitserver.CommitsOptions{
|
||||
Range: r.revisionRange,
|
||||
N: uint(n),
|
||||
MessageQuery: toValue(r.query).(string),
|
||||
|
||||
@ -9,7 +9,6 @@ import (
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil"
|
||||
"github.com/sourcegraph/sourcegraph/internal/api"
|
||||
"github.com/sourcegraph/sourcegraph/internal/authz"
|
||||
"github.com/sourcegraph/sourcegraph/internal/trace"
|
||||
)
|
||||
|
||||
@ -45,7 +44,7 @@ func (r *GitTreeEntryResolver) entries(ctx context.Context, args *gitTreeEntryCo
|
||||
tr, ctx := trace.New(ctx, "GitTreeEntryResolver.entries")
|
||||
defer tr.EndWithErr(&err)
|
||||
|
||||
entries, err := r.gitserverClient.ReadDir(ctx, authz.DefaultSubRepoPermsChecker, r.commit.repoResolver.RepoName(), api.CommitID(r.commit.OID()), r.Path(), r.isRecursive || args.Recursive)
|
||||
entries, err := r.gitserverClient.ReadDir(ctx, r.commit.repoResolver.RepoName(), api.CommitID(r.commit.OID()), r.Path(), r.isRecursive || args.Recursive)
|
||||
if err != nil {
|
||||
if strings.Contains(err.Error(), "file does not exist") { // TODO proper error value
|
||||
// empty tree is not an error
|
||||
|
||||
@ -17,7 +17,6 @@ import (
|
||||
"github.com/sourcegraph/sourcegraph/cmd/frontend/globals"
|
||||
"github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/externallink"
|
||||
"github.com/sourcegraph/sourcegraph/internal/api"
|
||||
"github.com/sourcegraph/sourcegraph/internal/authz"
|
||||
"github.com/sourcegraph/sourcegraph/internal/binary"
|
||||
"github.com/sourcegraph/sourcegraph/internal/cloneurls"
|
||||
resolverstubs "github.com/sourcegraph/sourcegraph/internal/codeintel/resolvers"
|
||||
@ -108,7 +107,6 @@ func (r *GitTreeEntryResolver) Content(ctx context.Context, args *GitTreeContent
|
||||
r.contentOnce.Do(func() {
|
||||
r.fullContentBytes, r.contentErr = r.gitserverClient.ReadFile(
|
||||
ctx,
|
||||
authz.DefaultSubRepoPermsChecker,
|
||||
r.commit.repoResolver.RepoName(),
|
||||
api.CommitID(r.commit.OID()),
|
||||
r.Path(),
|
||||
@ -318,7 +316,7 @@ func (r *GitTreeEntryResolver) IsSingleChild(ctx context.Context, args *gitTreeE
|
||||
if r.isSingleChild != nil {
|
||||
return *r.isSingleChild, nil
|
||||
}
|
||||
entries, err := r.gitserverClient.ReadDir(ctx, authz.DefaultSubRepoPermsChecker, r.commit.repoResolver.RepoName(), api.CommitID(r.commit.OID()), path.Dir(r.Path()), false)
|
||||
entries, err := r.gitserverClient.ReadDir(ctx, r.commit.repoResolver.RepoName(), api.CommitID(r.commit.OID()), path.Dir(r.Path()), false)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
@ -6,7 +6,6 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/sourcegraph/sourcegraph/internal/authz"
|
||||
"github.com/sourcegraph/sourcegraph/internal/database/dbmocks"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/internal/api"
|
||||
@ -37,7 +36,7 @@ func TestGitTreeEntry_Content(t *testing.T) {
|
||||
db := dbmocks.NewMockDB()
|
||||
gitserverClient := gitserver.NewMockClient()
|
||||
|
||||
gitserverClient.ReadFileFunc.SetDefaultHook(func(_ context.Context, _ authz.SubRepoPermissionChecker, _ api.RepoName, _ api.CommitID, name string) ([]byte, error) {
|
||||
gitserverClient.ReadFileFunc.SetDefaultHook(func(_ context.Context, _ api.RepoName, _ api.CommitID, name string) ([]byte, error) {
|
||||
if name != wantPath {
|
||||
t.Fatalf("wrong name in ReadFile call. want=%q, have=%q", wantPath, name)
|
||||
}
|
||||
@ -82,7 +81,7 @@ func TestGitTreeEntry_ContentPagination(t *testing.T) {
|
||||
db := dbmocks.NewMockDB()
|
||||
gitserverClient := gitserver.NewMockClient()
|
||||
|
||||
gitserverClient.ReadFileFunc.SetDefaultHook(func(_ context.Context, _ authz.SubRepoPermissionChecker, _ api.RepoName, _ api.CommitID, name string) ([]byte, error) {
|
||||
gitserverClient.ReadFileFunc.SetDefaultHook(func(_ context.Context, _ api.RepoName, _ api.CommitID, name string) ([]byte, error) {
|
||||
if name != wantPath {
|
||||
t.Fatalf("wrong name in ReadFile call. want=%q, have=%q", wantPath, name)
|
||||
}
|
||||
|
||||
@ -10,7 +10,6 @@ import (
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/cmd/frontend/backend"
|
||||
"github.com/sourcegraph/sourcegraph/internal/api"
|
||||
"github.com/sourcegraph/sourcegraph/internal/authz"
|
||||
"github.com/sourcegraph/sourcegraph/internal/database/dbmocks"
|
||||
"github.com/sourcegraph/sourcegraph/internal/fileutil"
|
||||
"github.com/sourcegraph/sourcegraph/internal/gitserver"
|
||||
@ -86,7 +85,7 @@ func TestGitTree(t *testing.T) {
|
||||
func setupGitserverClient(t *testing.T) gitserver.Client {
|
||||
t.Helper()
|
||||
gsClient := gitserver.NewMockClient()
|
||||
gsClient.ReadDirFunc.SetDefaultHook(func(_ context.Context, _ authz.SubRepoPermissionChecker, _ api.RepoName, commit api.CommitID, name string, recurse bool) ([]fs.FileInfo, error) {
|
||||
gsClient.ReadDirFunc.SetDefaultHook(func(_ context.Context, _ api.RepoName, commit api.CommitID, name string, recurse bool) ([]fs.FileInfo, error) {
|
||||
assert.Equal(t, api.CommitID(exampleCommitSHA1), commit)
|
||||
assert.Equal(t, "foo bar", name)
|
||||
assert.False(t, recurse)
|
||||
@ -97,7 +96,7 @@ func setupGitserverClient(t *testing.T) gitserver.Client {
|
||||
&fileutil.FileInfo{Name_: name + "/% token.4288249258.sql", Mode_: 0},
|
||||
}, nil
|
||||
})
|
||||
gsClient.StatFunc.SetDefaultHook(func(_ context.Context, _ authz.SubRepoPermissionChecker, _ api.RepoName, commit api.CommitID, path string) (fs.FileInfo, error) {
|
||||
gsClient.StatFunc.SetDefaultHook(func(_ context.Context, _ api.RepoName, commit api.CommitID, path string) (fs.FileInfo, error) {
|
||||
assert.Equal(t, api.CommitID(exampleCommitSHA1), commit)
|
||||
assert.Equal(t, "foo bar", path)
|
||||
return &fileutil.FileInfo{Name_: path, Mode_: os.ModeDir}, nil
|
||||
|
||||
@ -9,7 +9,6 @@ import (
|
||||
godiff "github.com/sourcegraph/go-diff/diff"
|
||||
"github.com/sourcegraph/log/logtest"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/internal/authz"
|
||||
"github.com/sourcegraph/sourcegraph/internal/gitserver/gitdomain"
|
||||
"github.com/sourcegraph/sourcegraph/lib/errors"
|
||||
|
||||
@ -240,7 +239,7 @@ index 9bd8209..d2acfa9 100644
|
||||
}
|
||||
fileDiff := fileDiffs[0]
|
||||
|
||||
gitserverClient.ReadFileFunc.SetDefaultHook(func(_ context.Context, _ authz.SubRepoPermissionChecker, _ api.RepoName, _ api.CommitID, name string) ([]byte, error) {
|
||||
gitserverClient.ReadFileFunc.SetDefaultHook(func(_ context.Context, _ api.RepoName, _ api.CommitID, name string) ([]byte, error) {
|
||||
if name != "INSTALL.md" {
|
||||
t.Fatalf("ReadFile received call for wrong file: %s", name)
|
||||
}
|
||||
|
||||
@ -18,7 +18,6 @@ import (
|
||||
"github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil"
|
||||
"github.com/sourcegraph/sourcegraph/internal/api"
|
||||
"github.com/sourcegraph/sourcegraph/internal/auth"
|
||||
"github.com/sourcegraph/sourcegraph/internal/authz"
|
||||
resolverstubs "github.com/sourcegraph/sourcegraph/internal/codeintel/resolvers"
|
||||
"github.com/sourcegraph/sourcegraph/internal/conf"
|
||||
"github.com/sourcegraph/sourcegraph/internal/database"
|
||||
@ -322,7 +321,7 @@ func (r *RepositoryResolver) FirstEverCommit(ctx context.Context) (_ *GitCommitR
|
||||
return nil, err
|
||||
}
|
||||
|
||||
commit, err := r.gitserverClient.FirstEverCommit(ctx, authz.DefaultSubRepoPermsChecker, repo.Name)
|
||||
commit, err := r.gitserverClient.FirstEverCommit(ctx, repo.Name)
|
||||
if err != nil {
|
||||
if errors.HasType(err, &gitdomain.RevisionNotFoundError{}) {
|
||||
return nil, nil
|
||||
|
||||
@ -16,7 +16,6 @@ import (
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil"
|
||||
"github.com/sourcegraph/sourcegraph/internal/api"
|
||||
"github.com/sourcegraph/sourcegraph/internal/authz"
|
||||
"github.com/sourcegraph/sourcegraph/internal/database"
|
||||
"github.com/sourcegraph/sourcegraph/internal/gitserver"
|
||||
"github.com/sourcegraph/sourcegraph/internal/gosyntect"
|
||||
@ -247,7 +246,7 @@ func computeRepositoryComparisonDiff(cmp *RepositoryComparisonResolver) ComputeD
|
||||
}
|
||||
|
||||
var iter *gitserver.DiffFileIterator
|
||||
iter, err = cmp.gitserverClient.Diff(ctx, authz.DefaultSubRepoPermsChecker, gitserver.DiffOptions{
|
||||
iter, err = cmp.gitserverClient.Diff(ctx, gitserver.DiffOptions{
|
||||
Repo: cmp.repo.RepoName(),
|
||||
Base: base,
|
||||
Head: string(cmp.head.OID()),
|
||||
|
||||
@ -17,7 +17,6 @@ import (
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/externallink"
|
||||
"github.com/sourcegraph/sourcegraph/internal/api"
|
||||
"github.com/sourcegraph/sourcegraph/internal/authz"
|
||||
"github.com/sourcegraph/sourcegraph/internal/database"
|
||||
"github.com/sourcegraph/sourcegraph/internal/gitserver"
|
||||
"github.com/sourcegraph/sourcegraph/internal/gitserver/gitdomain"
|
||||
@ -75,7 +74,7 @@ func TestRepositoryComparison(t *testing.T) {
|
||||
CreatedAt: time.Now(),
|
||||
}
|
||||
|
||||
gsClient := gitserver.NewMockClientWithExecReader(func(_ context.Context, _ api.RepoName, args []string) (io.ReadCloser, error) {
|
||||
gsClient := gitserver.NewMockClientWithExecReader(nil, func(_ context.Context, _ api.RepoName, args []string) (io.ReadCloser, error) {
|
||||
if len(args) < 1 && args[0] != "diff" {
|
||||
t.Fatalf("gitserver.ExecReader received wrong args: %v", args)
|
||||
}
|
||||
@ -135,7 +134,7 @@ func TestRepositoryComparison(t *testing.T) {
|
||||
}
|
||||
|
||||
mockGSClient := gitserver.NewMockClient()
|
||||
mockGSClient.CommitsFunc.SetDefaultHook(func(_ context.Context, _ authz.SubRepoPermissionChecker, _ api.RepoName, opts gitserver.CommitsOptions) ([]*gitdomain.Commit, error) {
|
||||
mockGSClient.CommitsFunc.SetDefaultHook(func(_ context.Context, _ api.RepoName, opts gitserver.CommitsOptions) ([]*gitdomain.Commit, error) {
|
||||
wantRange := fmt.Sprintf("%s..%s", wantBaseRevision, wantHeadRevision)
|
||||
|
||||
if have, want := opts.Range, wantRange; have != want {
|
||||
@ -185,7 +184,7 @@ func TestRepositoryComparison(t *testing.T) {
|
||||
}
|
||||
|
||||
mockGSClient := gitserver.NewMockClient()
|
||||
mockGSClient.CommitsFunc.SetDefaultHook(func(_ context.Context, _ authz.SubRepoPermissionChecker, _ api.RepoName, opts gitserver.CommitsOptions) ([]*gitdomain.Commit, error) {
|
||||
mockGSClient.CommitsFunc.SetDefaultHook(func(_ context.Context, _ api.RepoName, opts gitserver.CommitsOptions) ([]*gitdomain.Commit, error) {
|
||||
if opts.Path == "" {
|
||||
t.Fatalf("expected a path as part of commits args")
|
||||
}
|
||||
|
||||
@ -8,7 +8,6 @@ import (
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil"
|
||||
"github.com/sourcegraph/sourcegraph/internal/api"
|
||||
"github.com/sourcegraph/sourcegraph/internal/authz"
|
||||
"github.com/sourcegraph/sourcegraph/internal/gitserver"
|
||||
"github.com/sourcegraph/sourcegraph/internal/gitserver/gitdomain"
|
||||
)
|
||||
@ -158,7 +157,7 @@ func hydrateBranchCommits(ctx context.Context, gitserverClient gitserver.Client,
|
||||
}
|
||||
|
||||
for _, branch := range branches {
|
||||
branch.Commit, err = gitserverClient.GetCommit(ctx, authz.DefaultSubRepoPermsChecker, repo, branch.Head, gitserver.ResolveRevisionOptions{})
|
||||
branch.Commit, err = gitserverClient.GetCommit(ctx, repo, branch.Head, gitserver.ResolveRevisionOptions{})
|
||||
if err != nil {
|
||||
if parentCtx.Err() == nil && ctx.Err() != nil {
|
||||
// reached interactive timeout
|
||||
|
||||
@ -19,7 +19,6 @@ import (
|
||||
|
||||
searchlogs "github.com/sourcegraph/sourcegraph/cmd/frontend/internal/search/logs"
|
||||
"github.com/sourcegraph/sourcegraph/internal/api"
|
||||
"github.com/sourcegraph/sourcegraph/internal/authz"
|
||||
"github.com/sourcegraph/sourcegraph/internal/database"
|
||||
"github.com/sourcegraph/sourcegraph/internal/gitserver"
|
||||
"github.com/sourcegraph/sourcegraph/internal/honey"
|
||||
@ -244,7 +243,7 @@ func (sr *SearchResultsResolver) blameFileMatch(ctx context.Context, fm *result.
|
||||
return time.Time{}, nil
|
||||
}
|
||||
hm := fm.ChunkMatches[0]
|
||||
hunks, err := gitserver.NewClient().BlameFile(ctx, authz.DefaultSubRepoPermsChecker, fm.Repo.Name, fm.Path, &gitserver.BlameOptions{
|
||||
hunks, err := gitserver.NewClient().BlameFile(ctx, fm.Repo.Name, fm.Path, &gitserver.BlameOptions{
|
||||
NewestCommit: fm.CommitID,
|
||||
StartLine: hm.Ranges[0].Start.Line,
|
||||
EndLine: hm.Ranges[0].Start.Line,
|
||||
|
||||
@ -13,7 +13,6 @@ import (
|
||||
"github.com/sourcegraph/log/logtest"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/internal/api"
|
||||
"github.com/sourcegraph/sourcegraph/internal/authz"
|
||||
"github.com/sourcegraph/sourcegraph/internal/database/dbmocks"
|
||||
"github.com/sourcegraph/sourcegraph/internal/fileutil"
|
||||
"github.com/sourcegraph/sourcegraph/internal/gitserver"
|
||||
@ -29,7 +28,7 @@ func TestSearchResultsStatsLanguages(t *testing.T) {
|
||||
rcache.SetupForTest(t)
|
||||
|
||||
gsClient := gitserver.NewMockClient()
|
||||
gsClient.NewFileReaderFunc.SetDefaultHook(func(_ context.Context, _ authz.SubRepoPermissionChecker, _ api.RepoName, commit api.CommitID, name string) (io.ReadCloser, error) {
|
||||
gsClient.NewFileReaderFunc.SetDefaultHook(func(_ context.Context, _ api.RepoName, commit api.CommitID, name string) (io.ReadCloser, error) {
|
||||
if commit != wantCommitID {
|
||||
t.Errorf("got commit %q, want %q", commit, wantCommitID)
|
||||
}
|
||||
@ -56,7 +55,7 @@ func TestSearchResultsStatsLanguages(t *testing.T) {
|
||||
return wantCommitID, nil
|
||||
})
|
||||
|
||||
gsClient.StatFunc.SetDefaultHook(func(_ context.Context, _ authz.SubRepoPermissionChecker, _ api.RepoName, _ api.CommitID, path string) (fs.FileInfo, error) {
|
||||
gsClient.StatFunc.SetDefaultHook(func(_ context.Context, _ api.RepoName, _ api.CommitID, path string) (fs.FileInfo, error) {
|
||||
return &fileutil.FileInfo{Name_: path, Mode_: os.ModeDir}, nil
|
||||
})
|
||||
|
||||
@ -110,7 +109,7 @@ func TestSearchResultsStatsLanguages(t *testing.T) {
|
||||
}
|
||||
for name, test := range tests {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
gsClient.ReadDirFunc.SetDefaultHook(func(context.Context, authz.SubRepoPermissionChecker, api.RepoName, api.CommitID, string, bool) ([]fs.FileInfo, error) {
|
||||
gsClient.ReadDirFunc.SetDefaultHook(func(context.Context, api.RepoName, api.CommitID, string, bool) ([]fs.FileInfo, error) {
|
||||
return test.getFiles, nil
|
||||
})
|
||||
|
||||
|
||||
@ -89,7 +89,6 @@ go_test(
|
||||
"//cmd/frontend/globals",
|
||||
"//cmd/frontend/internal/app/ui/router",
|
||||
"//internal/api",
|
||||
"//internal/authz",
|
||||
"//internal/conf",
|
||||
"//internal/database",
|
||||
"//internal/database/dbmocks",
|
||||
|
||||
@ -424,7 +424,7 @@ func redirectTreeOrBlob(routeName, path string, common *Common, w http.ResponseW
|
||||
}
|
||||
return false, nil
|
||||
}
|
||||
stat, err := client.Stat(r.Context(), authz.DefaultSubRepoPermsChecker, common.Repo.Name, common.CommitID, path)
|
||||
stat, err := client.Stat(r.Context(), common.Repo.Name, common.CommitID, path)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
serveError(w, r, db, err, http.StatusNotFound)
|
||||
|
||||
@ -20,7 +20,6 @@ import (
|
||||
"github.com/prometheus/client_golang/prometheus/promauto"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/cmd/frontend/globals"
|
||||
"github.com/sourcegraph/sourcegraph/internal/authz"
|
||||
"github.com/sourcegraph/sourcegraph/internal/database"
|
||||
"github.com/sourcegraph/sourcegraph/internal/errcode"
|
||||
"github.com/sourcegraph/sourcegraph/internal/gitserver"
|
||||
@ -185,7 +184,7 @@ func serveRaw(db database.DB, gitserverClient gitserver.Client) handlerFunc {
|
||||
// caching locally is not useful. Additionally we transfer the output over the
|
||||
// internet, so we use default compression levels on zips (instead of no
|
||||
// compression).
|
||||
f, err := gitserverClient.ArchiveReader(r.Context(), authz.DefaultSubRepoPermsChecker, common.Repo.Name,
|
||||
f, err := gitserverClient.ArchiveReader(r.Context(), common.Repo.Name,
|
||||
gitserver.ArchiveOptions{Format: format, Treeish: string(common.CommitID), Pathspecs: []gitdomain.Pathspec{gitdomain.PathspecLiteral(relativePath)}})
|
||||
if err != nil {
|
||||
return err
|
||||
@ -237,7 +236,7 @@ func serveRaw(db database.DB, gitserverClient gitserver.Client) handlerFunc {
|
||||
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
|
||||
w.Header().Set("X-Content-Type-Options", "nosniff")
|
||||
|
||||
fi, err := gitserverClient.Stat(r.Context(), authz.DefaultSubRepoPermsChecker, common.Repo.Name, common.CommitID, requestedPath)
|
||||
fi, err := gitserverClient.Stat(r.Context(), common.Repo.Name, common.CommitID, requestedPath)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
requestType = "404"
|
||||
@ -249,7 +248,7 @@ func serveRaw(db database.DB, gitserverClient gitserver.Client) handlerFunc {
|
||||
|
||||
if fi.IsDir() {
|
||||
requestType = "dir"
|
||||
infos, err := gitserverClient.ReadDir(r.Context(), authz.DefaultSubRepoPermsChecker, common.Repo.Name, common.CommitID, requestedPath, false)
|
||||
infos, err := gitserverClient.ReadDir(r.Context(), common.Repo.Name, common.CommitID, requestedPath, false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -272,7 +271,7 @@ func serveRaw(db database.DB, gitserverClient gitserver.Client) handlerFunc {
|
||||
// File
|
||||
requestType = "file"
|
||||
size = fi.Size()
|
||||
f, err := gitserverClient.NewFileReader(r.Context(), authz.DefaultSubRepoPermsChecker, common.Repo.Name, common.CommitID, requestedPath)
|
||||
f, err := gitserverClient.NewFileReader(r.Context(), common.Repo.Name, common.CommitID, requestedPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -16,7 +16,6 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/internal/api"
|
||||
"github.com/sourcegraph/sourcegraph/internal/authz"
|
||||
"github.com/sourcegraph/sourcegraph/internal/database"
|
||||
"github.com/sourcegraph/sourcegraph/internal/database/dbmocks"
|
||||
"github.com/sourcegraph/sourcegraph/internal/fileutil"
|
||||
@ -283,7 +282,7 @@ func Test_serveRawWithContentTypePlain(t *testing.T) {
|
||||
|
||||
gsClient := gitserver.NewMockClient()
|
||||
gsClient.StatFunc.SetDefaultReturn(&fileutil.FileInfo{Mode_: os.ModeDir}, nil)
|
||||
gsClient.ReadDirFunc.SetDefaultHook(func(context.Context, authz.SubRepoPermissionChecker, api.RepoName, api.CommitID, string, bool) ([]fs.FileInfo, error) {
|
||||
gsClient.ReadDirFunc.SetDefaultHook(func(context.Context, api.RepoName, api.CommitID, string, bool) ([]fs.FileInfo, error) {
|
||||
return []fs.FileInfo{
|
||||
&fileutil.FileInfo{Name_: "test/a", Mode_: os.ModeDir},
|
||||
&fileutil.FileInfo{Name_: "test/b", Mode_: os.ModeDir},
|
||||
@ -321,7 +320,7 @@ c.go`
|
||||
|
||||
gitserverClient := gitserver.NewMockClient()
|
||||
gitserverClient.StatFunc.SetDefaultReturn(&fileutil.FileInfo{Mode_: 0}, nil)
|
||||
gitserverClient.NewFileReaderFunc.SetDefaultHook(func(context.Context, authz.SubRepoPermissionChecker, api.RepoName, api.CommitID, string) (io.ReadCloser, error) {
|
||||
gitserverClient.NewFileReaderFunc.SetDefaultHook(func(context.Context, api.RepoName, api.CommitID, string) (io.ReadCloser, error) {
|
||||
return io.NopCloser(strings.NewReader("this is a test file")), nil
|
||||
})
|
||||
|
||||
@ -354,7 +353,7 @@ c.go`
|
||||
|
||||
gitserverClient := gitserver.NewMockClient()
|
||||
gitserverClient.StatFunc.SetDefaultReturn(&fileutil.FileInfo{Mode_: 0}, nil)
|
||||
gitserverClient.NewFileReaderFunc.SetDefaultHook(func(context.Context, authz.SubRepoPermissionChecker, api.RepoName, api.CommitID, string) (io.ReadCloser, error) {
|
||||
gitserverClient.NewFileReaderFunc.SetDefaultHook(func(context.Context, api.RepoName, api.CommitID, string) (io.ReadCloser, error) {
|
||||
return io.NopCloser(strings.NewReader("this is a test file")), nil
|
||||
})
|
||||
|
||||
|
||||
@ -189,7 +189,7 @@ func mockRepoComparison(t *testing.T, gitserverClient *gitserver.MockClient, bas
|
||||
t.Helper()
|
||||
|
||||
spec := fmt.Sprintf("%s...%s", baseRev, headRev)
|
||||
gitserverClientWithExecReader := gitserver.NewMockClientWithExecReader(func(_ context.Context, _ api.RepoName, args []string) (io.ReadCloser, error) {
|
||||
gitserverClientWithExecReader := gitserver.NewMockClientWithExecReader(nil, func(_ context.Context, _ api.RepoName, args []string) (io.ReadCloser, error) {
|
||||
if len(args) < 1 && args[0] != "diff" {
|
||||
t.Fatalf("gitserver.ExecReader received wrong args: %v", args)
|
||||
}
|
||||
|
||||
@ -8,7 +8,6 @@ go_library(
|
||||
visibility = ["//cmd/frontend:__subpackages__"],
|
||||
deps = [
|
||||
"//cmd/frontend/graphqlbackend",
|
||||
"//internal/authz",
|
||||
"//internal/codycontext:context",
|
||||
"//internal/database",
|
||||
"//internal/gitserver",
|
||||
@ -31,7 +30,6 @@ go_test(
|
||||
"//cmd/frontend/graphqlbackend",
|
||||
"//internal/actor",
|
||||
"//internal/api",
|
||||
"//internal/authz",
|
||||
"//internal/codycontext:context",
|
||||
"//internal/conf",
|
||||
"//internal/database",
|
||||
|
||||
@ -6,7 +6,6 @@ import (
|
||||
"github.com/sourcegraph/conc/iter"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend"
|
||||
"github.com/sourcegraph/sourcegraph/internal/authz"
|
||||
codycontext "github.com/sourcegraph/sourcegraph/internal/codycontext"
|
||||
"github.com/sourcegraph/sourcegraph/internal/database"
|
||||
"github.com/sourcegraph/sourcegraph/internal/gitserver"
|
||||
@ -76,7 +75,7 @@ func (r *Resolver) fileChunkToResolver(ctx context.Context, chunk *codycontext.F
|
||||
})
|
||||
|
||||
commitResolver := graphqlbackend.NewGitCommitResolver(r.db, r.gitserverClient, repoResolver, chunk.CommitID, nil)
|
||||
stat, err := r.gitserverClient.Stat(ctx, authz.DefaultSubRepoPermsChecker, chunk.RepoName, chunk.CommitID, chunk.Path)
|
||||
stat, err := r.gitserverClient.Stat(ctx, chunk.RepoName, chunk.CommitID, chunk.Path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@ -13,7 +13,6 @@ import (
|
||||
"github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend"
|
||||
"github.com/sourcegraph/sourcegraph/internal/actor"
|
||||
"github.com/sourcegraph/sourcegraph/internal/api"
|
||||
"github.com/sourcegraph/sourcegraph/internal/authz"
|
||||
codycontext "github.com/sourcegraph/sourcegraph/internal/codycontext"
|
||||
"github.com/sourcegraph/sourcegraph/internal/conf"
|
||||
"github.com/sourcegraph/sourcegraph/internal/database"
|
||||
@ -56,10 +55,10 @@ func TestContextResolver(t *testing.T) {
|
||||
}
|
||||
|
||||
mockGitserver := gitserver.NewMockClient()
|
||||
mockGitserver.StatFunc.SetDefaultHook(func(_ context.Context, _ authz.SubRepoPermissionChecker, repo api.RepoName, _ api.CommitID, fileName string) (fs.FileInfo, error) {
|
||||
mockGitserver.StatFunc.SetDefaultHook(func(_ context.Context, repo api.RepoName, _ api.CommitID, fileName string) (fs.FileInfo, error) {
|
||||
return fakeFileInfo{path: fileName}, nil
|
||||
})
|
||||
mockGitserver.ReadFileFunc.SetDefaultHook(func(_ context.Context, _ authz.SubRepoPermissionChecker, repo api.RepoName, _ api.CommitID, fileName string) ([]byte, error) {
|
||||
mockGitserver.ReadFileFunc.SetDefaultHook(func(_ context.Context, repo api.RepoName, _ api.CommitID, fileName string) ([]byte, error) {
|
||||
if content, ok := files[repo][fileName]; ok {
|
||||
return content, nil
|
||||
}
|
||||
|
||||
@ -15,7 +15,6 @@ go_library(
|
||||
"//cmd/frontend/graphqlbackend/graphqlutil",
|
||||
"//internal/api",
|
||||
"//internal/auth",
|
||||
"//internal/authz",
|
||||
"//internal/cody",
|
||||
"//internal/conf",
|
||||
"//internal/database",
|
||||
@ -40,7 +39,6 @@ go_test(
|
||||
"//cmd/frontend/graphqlbackend",
|
||||
"//internal/actor",
|
||||
"//internal/api",
|
||||
"//internal/authz",
|
||||
"//internal/conf",
|
||||
"//internal/database/dbmocks",
|
||||
"//internal/embeddings",
|
||||
|
||||
@ -16,7 +16,6 @@ import (
|
||||
"github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil"
|
||||
"github.com/sourcegraph/sourcegraph/internal/api"
|
||||
"github.com/sourcegraph/sourcegraph/internal/auth"
|
||||
"github.com/sourcegraph/sourcegraph/internal/authz"
|
||||
"github.com/sourcegraph/sourcegraph/internal/cody"
|
||||
"github.com/sourcegraph/sourcegraph/internal/conf"
|
||||
"github.com/sourcegraph/sourcegraph/internal/database"
|
||||
@ -220,7 +219,7 @@ func embeddingsSearchResultsToResolvers(
|
||||
for i, result := range results {
|
||||
i, result := i, result
|
||||
p.Go(func() {
|
||||
content, err := gs.ReadFile(ctx, authz.DefaultSubRepoPermsChecker, result.RepoName, result.Revision, result.FileName)
|
||||
content, err := gs.ReadFile(ctx, result.RepoName, result.Revision, result.FileName)
|
||||
allContents[i] = content
|
||||
allErrors[i] = err
|
||||
})
|
||||
|
||||
@ -12,7 +12,6 @@ import (
|
||||
"github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend"
|
||||
"github.com/sourcegraph/sourcegraph/internal/actor"
|
||||
"github.com/sourcegraph/sourcegraph/internal/api"
|
||||
"github.com/sourcegraph/sourcegraph/internal/authz"
|
||||
"github.com/sourcegraph/sourcegraph/internal/conf"
|
||||
"github.com/sourcegraph/sourcegraph/internal/database/dbmocks"
|
||||
"github.com/sourcegraph/sourcegraph/internal/embeddings"
|
||||
@ -42,7 +41,7 @@ func TestEmbeddingSearchResolver(t *testing.T) {
|
||||
mockDB.ReposFunc.SetDefaultReturn(mockRepos)
|
||||
|
||||
mockGitserver := gitserver.NewMockClient()
|
||||
mockGitserver.ReadFileFunc.SetDefaultHook(func(_ context.Context, _ authz.SubRepoPermissionChecker, _ api.RepoName, _ api.CommitID, fileName string) ([]byte, error) {
|
||||
mockGitserver.ReadFileFunc.SetDefaultHook(func(_ context.Context, _ api.RepoName, _ api.CommitID, fileName string) ([]byte, error) {
|
||||
if fileName == "testfile" {
|
||||
return []byte("test\nfirst\nfour\nlines\nplus\nsome\nmore"), nil
|
||||
}
|
||||
|
||||
@ -14,7 +14,6 @@ import (
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/cmd/frontend/internal/handlerutil"
|
||||
"github.com/sourcegraph/sourcegraph/internal/api"
|
||||
"github.com/sourcegraph/sourcegraph/internal/authz"
|
||||
"github.com/sourcegraph/sourcegraph/internal/database"
|
||||
"github.com/sourcegraph/sourcegraph/internal/errcode"
|
||||
"github.com/sourcegraph/sourcegraph/internal/featureflag"
|
||||
@ -83,7 +82,7 @@ func handleStreamBlame(logger log.Logger, db database.DB, gitserverClient gitser
|
||||
|
||||
requestedPath = strings.TrimPrefix(requestedPath, "/")
|
||||
|
||||
hunkReader, err := gitserverClient.StreamBlameFile(r.Context(), authz.DefaultSubRepoPermsChecker, repo.Name, requestedPath, &gitserver.BlameOptions{
|
||||
hunkReader, err := gitserverClient.StreamBlameFile(r.Context(), repo.Name, requestedPath, &gitserver.BlameOptions{
|
||||
NewestCommit: commitID,
|
||||
})
|
||||
if err != nil {
|
||||
@ -110,7 +109,7 @@ func handleStreamBlame(logger log.Logger, db database.DB, gitserverClient gitser
|
||||
if p, ok := parentsCache[h.CommitID]; ok {
|
||||
parents = p
|
||||
} else {
|
||||
c, err := gitserverClient.GetCommit(ctx, authz.DefaultSubRepoPermsChecker, repo.Name, h.CommitID, gitserver.ResolveRevisionOptions{})
|
||||
c, err := gitserverClient.GetCommit(ctx, repo.Name, h.CommitID, gitserver.ResolveRevisionOptions{})
|
||||
if err != nil {
|
||||
tr.SetError(err)
|
||||
http.Error(w, html.EscapeString(err.Error()), http.StatusInternalServerError)
|
||||
|
||||
@ -11,7 +11,6 @@ import (
|
||||
"github.com/sourcegraph/log/logtest"
|
||||
"github.com/sourcegraph/sourcegraph/cmd/frontend/backend"
|
||||
"github.com/sourcegraph/sourcegraph/internal/api"
|
||||
"github.com/sourcegraph/sourcegraph/internal/authz"
|
||||
"github.com/sourcegraph/sourcegraph/internal/database"
|
||||
"github.com/sourcegraph/sourcegraph/internal/database/dbmocks"
|
||||
"github.com/sourcegraph/sourcegraph/internal/errcode"
|
||||
@ -29,7 +28,6 @@ func setupMockGSClient(t *testing.T, wantRev api.CommitID, returnErr error, hunk
|
||||
gsClient := gitserver.NewMockClient()
|
||||
gsClient.GetCommitFunc.SetDefaultHook(
|
||||
func(_ context.Context,
|
||||
checker authz.SubRepoPermissionChecker,
|
||||
repoName api.RepoName,
|
||||
commit api.CommitID,
|
||||
opts gitserver.ResolveRevisionOptions,
|
||||
@ -41,7 +39,6 @@ func setupMockGSClient(t *testing.T, wantRev api.CommitID, returnErr error, hunk
|
||||
gsClient.StreamBlameFileFunc.SetDefaultHook(
|
||||
func(
|
||||
ctx context.Context,
|
||||
checker authz.SubRepoPermissionChecker,
|
||||
repo api.RepoName,
|
||||
path string,
|
||||
opts *gitserver.BlameOptions,
|
||||
|
||||
@ -60,7 +60,6 @@ go_test(
|
||||
"//internal/actor",
|
||||
"//internal/api",
|
||||
"//internal/auth",
|
||||
"//internal/authz",
|
||||
"//internal/database",
|
||||
"//internal/database/dbmocks",
|
||||
"//internal/database/dbtest",
|
||||
|
||||
@ -23,7 +23,6 @@ import (
|
||||
"github.com/sourcegraph/sourcegraph/cmd/frontend/internal/own/resolvers"
|
||||
"github.com/sourcegraph/sourcegraph/internal/actor"
|
||||
"github.com/sourcegraph/sourcegraph/internal/api"
|
||||
"github.com/sourcegraph/sourcegraph/internal/authz"
|
||||
"github.com/sourcegraph/sourcegraph/internal/database"
|
||||
"github.com/sourcegraph/sourcegraph/internal/database/dbmocks"
|
||||
"github.com/sourcegraph/sourcegraph/internal/database/dbtest"
|
||||
@ -110,7 +109,7 @@ func fakeOwnDb() *dbmocks.MockDB {
|
||||
|
||||
type repoFiles map[repoPath]string
|
||||
|
||||
func (g fakeGitserver) ReadFile(_ context.Context, _ authz.SubRepoPermissionChecker, repoName api.RepoName, commitID api.CommitID, file string) ([]byte, error) {
|
||||
func (g fakeGitserver) ReadFile(_ context.Context, repoName api.RepoName, commitID api.CommitID, file string) ([]byte, error) {
|
||||
if g.files == nil {
|
||||
return nil, os.ErrNotExist
|
||||
}
|
||||
@ -125,7 +124,7 @@ func (g fakeGitserver) ReadFile(_ context.Context, _ authz.SubRepoPermissionChec
|
||||
// indicating a regular file for every path it is given,
|
||||
// except the ones that are actual ancestor paths of some file
|
||||
// in fakeGitServer.files.
|
||||
func (g fakeGitserver) Stat(_ context.Context, _ authz.SubRepoPermissionChecker, repoName api.RepoName, commitID api.CommitID, path string) (fs.FileInfo, error) {
|
||||
func (g fakeGitserver) Stat(_ context.Context, repoName api.RepoName, commitID api.CommitID, path string) (fs.FileInfo, error) {
|
||||
isDir := false
|
||||
p := repoPath{
|
||||
Repo: repoName,
|
||||
|
||||
@ -7,7 +7,6 @@ import (
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"net/url"
|
||||
"os"
|
||||
@ -133,7 +132,7 @@ func TestClient_ArchiveReader(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
rc, err := cli.ArchiveReader(ctx, nil, name, gitserver.ArchiveOptions{Treeish: test.revision, Format: gitserver.ArchiveFormatZip})
|
||||
rc, err := cli.ArchiveReader(ctx, name, gitserver.ArchiveOptions{Treeish: test.revision, Format: gitserver.ArchiveFormatZip})
|
||||
if have, want := fmt.Sprint(err), fmt.Sprint(test.clientErr); have != want {
|
||||
t.Errorf("archive: have err %v, want %v", have, want)
|
||||
}
|
||||
@ -223,7 +222,7 @@ func TestClient_ArchiveReader(t *testing.T) {
|
||||
}
|
||||
})
|
||||
|
||||
return gitserver.NewTestClient(&http.Client{}, source)
|
||||
return gitserver.NewTestClient(t).WithClientSource(source)
|
||||
}
|
||||
|
||||
runArchiveReaderTestfunc(t, mkClient, repoName, test)
|
||||
@ -266,7 +265,7 @@ func TestClient_ArchiveReader(t *testing.T) {
|
||||
}
|
||||
})
|
||||
|
||||
return gitserver.NewTestClient(&http.Client{}, source)
|
||||
return gitserver.NewTestClient(t).WithClientSource(source)
|
||||
}
|
||||
|
||||
runArchiveReaderTestfunc(t, mkClient, repoName, test)
|
||||
|
||||
@ -3,7 +3,6 @@ package inttests
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@ -80,7 +79,7 @@ func TestGetCommits(t *testing.T) {
|
||||
}
|
||||
|
||||
source := gitserver.NewTestClientSource(t, GitserverAddresses)
|
||||
commits, err := gitserver.NewTestClient(http.DefaultClient, source).GetCommits(ctx, nil, repoCommits, true)
|
||||
commits, err := gitserver.NewTestClient(t).WithClientSource(source).GetCommits(ctx, repoCommits, true)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error calling getCommits: %s", err)
|
||||
}
|
||||
@ -119,7 +118,10 @@ func TestGetCommits(t *testing.T) {
|
||||
}
|
||||
source := gitserver.NewTestClientSource(t, GitserverAddresses)
|
||||
|
||||
commits, err := gitserver.NewTestClient(http.DefaultClient, source).GetCommits(ctx, getTestSubRepoPermsChecker("file1", "file3"), repoCommits, true)
|
||||
client := gitserver.NewTestClient(t).
|
||||
WithClientSource(source).
|
||||
WithChecker(getTestSubRepoPermsChecker("file1", "file3"))
|
||||
commits, err := client.GetCommits(ctx, repoCommits, true)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error calling getCommits: %s", err)
|
||||
}
|
||||
@ -151,7 +153,7 @@ func mustParseDate(s string, t *testing.T) *time.Time {
|
||||
|
||||
func TestHead(t *testing.T) {
|
||||
source := gitserver.NewTestClientSource(t, GitserverAddresses)
|
||||
client := gitserver.NewTestClient(http.DefaultClient, source)
|
||||
client := gitserver.NewTestClient(t).WithClientSource(source)
|
||||
t.Run("basic", func(t *testing.T) {
|
||||
gitCommands := []string{
|
||||
"GIT_COMMITTER_NAME=a GIT_COMMITTER_EMAIL=a@a.com GIT_COMMITTER_DATE=2006-01-02T15:04:05Z git commit --allow-empty -m foo --author='a <a@a.com>' --date 2006-01-02T15:04:05Z",
|
||||
@ -159,7 +161,7 @@ func TestHead(t *testing.T) {
|
||||
repo := MakeGitRepository(t, gitCommands...)
|
||||
ctx := context.Background()
|
||||
|
||||
head, exists, err := client.Head(ctx, nil, repo)
|
||||
head, exists, err := client.Head(ctx, repo)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -183,8 +185,9 @@ func TestHead(t *testing.T) {
|
||||
UID: 1,
|
||||
})
|
||||
checker := getTestSubRepoPermsChecker("file")
|
||||
client = client.WithChecker(checker)
|
||||
// call Head() when user doesn't have access to view the commit
|
||||
_, exists, err := client.Head(ctx, checker, repo)
|
||||
_, exists, err := client.Head(ctx, repo)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -192,8 +195,9 @@ func TestHead(t *testing.T) {
|
||||
t.Fatalf("exists should be false since the user doesn't have access to view the commit")
|
||||
}
|
||||
readAllChecker := getTestSubRepoPermsChecker()
|
||||
client = client.WithChecker(readAllChecker)
|
||||
// call Head() when user has access to view the commit; should return expected commit
|
||||
head, exists, err := client.Head(ctx, readAllChecker, repo)
|
||||
head, exists, err := client.Head(ctx, repo)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@ -2,7 +2,6 @@ package inttests
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/internal/api"
|
||||
@ -62,7 +61,7 @@ func TestGetObject(t *testing.T) {
|
||||
})
|
||||
for label, test := range tests {
|
||||
source := gitserver.NewTestClientSource(t, GitserverAddresses)
|
||||
cli := gitserver.NewTestClient(http.DefaultClient, source)
|
||||
cli := gitserver.NewTestClient(t).WithClientSource(source)
|
||||
runTest(t, label, test, cli)
|
||||
}
|
||||
})
|
||||
@ -77,7 +76,7 @@ func TestGetObject(t *testing.T) {
|
||||
})
|
||||
for label, test := range tests {
|
||||
source := gitserver.NewTestClientSource(t, GitserverAddresses)
|
||||
cli := gitserver.NewTestClient(http.DefaultClient, source)
|
||||
cli := gitserver.NewTestClient(t).WithClientSource(source)
|
||||
runTest(t, label, test, cli)
|
||||
}
|
||||
})
|
||||
|
||||
@ -3,7 +3,6 @@ package inttests
|
||||
import (
|
||||
"container/list"
|
||||
"context"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"net/url"
|
||||
"path/filepath"
|
||||
@ -99,7 +98,7 @@ func TestClient_ResolveRevisions(t *testing.T) {
|
||||
addrs := []string{u.Host}
|
||||
source := gitserver.NewTestClientSource(t, addrs)
|
||||
|
||||
cli := gitserver.NewTestClient(&http.Client{}, source)
|
||||
cli := gitserver.NewTestClient(t).WithClientSource(source)
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run("", func(t *testing.T) {
|
||||
|
||||
@ -105,7 +105,7 @@ func InitGitserver() {
|
||||
|
||||
serverAddress := l.Addr().String()
|
||||
source := gitserver.NewTestClientSource(&t, []string{serverAddress})
|
||||
testGitserverClient = gitserver.NewTestClient(httpcli.InternalDoer, source)
|
||||
testGitserverClient = gitserver.NewTestClient(&t).WithDoer(httpcli.InternalDoer).WithClientSource(source)
|
||||
GitserverAddresses = []string{serverAddress}
|
||||
}
|
||||
|
||||
|
||||
@ -4,7 +4,6 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"io/fs"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
@ -63,16 +62,16 @@ func TestRepository_FileSystem(t *testing.T) {
|
||||
}
|
||||
|
||||
source := gitserver.NewTestClientSource(t, GitserverAddresses)
|
||||
client := gitserver.NewTestClient(http.DefaultClient, source)
|
||||
client := gitserver.NewTestClient(t).WithClientSource(source)
|
||||
for label, test := range tests {
|
||||
// notafile should not exist.
|
||||
if _, err := client.Stat(ctx, authz.DefaultSubRepoPermsChecker, test.repo, test.first, "notafile"); !os.IsNotExist(err) {
|
||||
if _, err := client.Stat(ctx, test.repo, test.first, "notafile"); !os.IsNotExist(err) {
|
||||
t.Errorf("%s: fs1.Stat(notafile): got err %v, want os.IsNotExist", label, err)
|
||||
continue
|
||||
}
|
||||
|
||||
// dir1 should exist and be a dir.
|
||||
dir1Info, err := client.Stat(ctx, authz.DefaultSubRepoPermsChecker, test.repo, test.first, "dir1")
|
||||
dir1Info, err := client.Stat(ctx, test.repo, test.first, "dir1")
|
||||
if err != nil {
|
||||
t.Errorf("%s: fs1.Stat(dir1): %s", label, err)
|
||||
continue
|
||||
@ -90,10 +89,10 @@ func TestRepository_FileSystem(t *testing.T) {
|
||||
t.Errorf("%s: got dir1 OID %q, want %q", label, got, want)
|
||||
}
|
||||
source := gitserver.NewTestClientSource(t, GitserverAddresses)
|
||||
client := gitserver.NewTestClient(http.DefaultClient, source)
|
||||
client := gitserver.NewTestClient(t).WithClientSource(source)
|
||||
|
||||
// dir1 should contain one entry: file1.
|
||||
dir1Entries, err := client.ReadDir(ctx, authz.DefaultSubRepoPermsChecker, test.repo, test.first, "dir1", false)
|
||||
dir1Entries, err := client.ReadDir(ctx, test.repo, test.first, "dir1", false)
|
||||
if err != nil {
|
||||
t.Errorf("%s: fs1.ReadDir(dir1): %s", label, err)
|
||||
continue
|
||||
@ -114,14 +113,14 @@ func TestRepository_FileSystem(t *testing.T) {
|
||||
}
|
||||
|
||||
// dir2 should not exist
|
||||
_, err = client.ReadDir(ctx, authz.DefaultSubRepoPermsChecker, test.repo, test.first, "dir2", false)
|
||||
_, err = client.ReadDir(ctx, test.repo, test.first, "dir2", false)
|
||||
if !os.IsNotExist(err) {
|
||||
t.Errorf("%s: fs1.ReadDir(dir2): should not exist: %s", label, err)
|
||||
continue
|
||||
}
|
||||
|
||||
// dir1/file1 should exist, contain "infile1", have the right mtime, and be a file.
|
||||
file1Data, err := client.ReadFile(ctx, nil, test.repo, test.first, "dir1/file1")
|
||||
file1Data, err := client.ReadFile(ctx, test.repo, test.first, "dir1/file1")
|
||||
if err != nil {
|
||||
t.Errorf("%s: fs1.ReadFile(dir1/file1): %s", label, err)
|
||||
continue
|
||||
@ -129,7 +128,7 @@ func TestRepository_FileSystem(t *testing.T) {
|
||||
if !bytes.Equal(file1Data, []byte("infile1")) {
|
||||
t.Errorf("%s: got file1Data == %q, want %q", label, string(file1Data), "infile1")
|
||||
}
|
||||
file1Info, err = client.Stat(ctx, authz.DefaultSubRepoPermsChecker, test.repo, test.first, "dir1/file1")
|
||||
file1Info, err = client.Stat(ctx, test.repo, test.first, "dir1/file1")
|
||||
if err != nil {
|
||||
t.Errorf("%s: fs1.Stat(dir1/file1): %s", label, err)
|
||||
continue
|
||||
@ -145,30 +144,30 @@ func TestRepository_FileSystem(t *testing.T) {
|
||||
}
|
||||
|
||||
// file 2 shouldn't exist in the 1st commit.
|
||||
_, err = client.ReadFile(ctx, nil, test.repo, test.first, "file 2")
|
||||
_, err = client.ReadFile(ctx, test.repo, test.first, "file 2")
|
||||
if !os.IsNotExist(err) {
|
||||
t.Errorf("%s: fs1.Open(file 2): got err %v, want os.IsNotExist (file 2 should not exist in this commit)", label, err)
|
||||
}
|
||||
|
||||
// file 2 should exist in the 2nd commit.
|
||||
_, err = client.ReadFile(ctx, nil, test.repo, test.second, "file 2")
|
||||
_, err = client.ReadFile(ctx, test.repo, test.second, "file 2")
|
||||
if err != nil {
|
||||
t.Errorf("%s: fs2.Open(file 2): %s", label, err)
|
||||
continue
|
||||
}
|
||||
|
||||
// file1 should also exist in the 2nd commit.
|
||||
if _, err := client.Stat(ctx, authz.DefaultSubRepoPermsChecker, test.repo, test.second, "dir1/file1"); err != nil {
|
||||
if _, err := client.Stat(ctx, test.repo, test.second, "dir1/file1"); err != nil {
|
||||
t.Errorf("%s: fs2.Stat(dir1/file1): %s", label, err)
|
||||
continue
|
||||
}
|
||||
if _, err := client.ReadFile(ctx, nil, test.repo, test.second, "dir1/file1"); err != nil {
|
||||
if _, err := client.ReadFile(ctx, test.repo, test.second, "dir1/file1"); err != nil {
|
||||
t.Errorf("%s: fs2.Open(dir1/file1): %s", label, err)
|
||||
continue
|
||||
}
|
||||
|
||||
// root should exist (via Stat).
|
||||
root, err := client.Stat(ctx, authz.DefaultSubRepoPermsChecker, test.repo, test.second, ".")
|
||||
root, err := client.Stat(ctx, test.repo, test.second, ".")
|
||||
if err != nil {
|
||||
t.Errorf("%s: fs2.Stat(.): %s", label, err)
|
||||
continue
|
||||
@ -178,7 +177,7 @@ func TestRepository_FileSystem(t *testing.T) {
|
||||
}
|
||||
|
||||
// root should have 2 entries: dir1 and file 2.
|
||||
rootEntries, err := client.ReadDir(ctx, authz.DefaultSubRepoPermsChecker, test.repo, test.second, ".", false)
|
||||
rootEntries, err := client.ReadDir(ctx, test.repo, test.second, ".", false)
|
||||
if err != nil {
|
||||
t.Errorf("%s: fs2.ReadDir(.): %s", label, err)
|
||||
continue
|
||||
@ -195,7 +194,7 @@ func TestRepository_FileSystem(t *testing.T) {
|
||||
}
|
||||
|
||||
// dir1 should still only contain one entry: file1.
|
||||
dir1Entries, err = client.ReadDir(ctx, authz.DefaultSubRepoPermsChecker, test.repo, test.second, "dir1", false)
|
||||
dir1Entries, err = client.ReadDir(ctx, test.repo, test.second, "dir1", false)
|
||||
if err != nil {
|
||||
t.Errorf("%s: fs1.ReadDir(dir1): %s", label, err)
|
||||
continue
|
||||
@ -209,7 +208,7 @@ func TestRepository_FileSystem(t *testing.T) {
|
||||
}
|
||||
|
||||
// rootEntries should be empty for third commit
|
||||
rootEntries, err = client.ReadDir(ctx, authz.DefaultSubRepoPermsChecker, test.repo, test.third, ".", false)
|
||||
rootEntries, err = client.ReadDir(ctx, test.repo, test.third, ".", false)
|
||||
if err != nil {
|
||||
t.Errorf("%s: fs3.ReadDir(.): %s", label, err)
|
||||
continue
|
||||
@ -257,14 +256,14 @@ func TestRepository_FileSystem_quoteChars(t *testing.T) {
|
||||
}
|
||||
|
||||
source := gitserver.NewTestClientSource(t, GitserverAddresses)
|
||||
client := gitserver.NewTestClient(http.DefaultClient, source)
|
||||
client := gitserver.NewTestClient(t).WithClientSource(source)
|
||||
for label, test := range tests {
|
||||
commitID, err := client.ResolveRevision(ctx, test.repo, "master", gitserver.ResolveRevisionOptions{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
entries, err := client.ReadDir(ctx, authz.DefaultSubRepoPermsChecker, test.repo, commitID, ".", false)
|
||||
entries, err := client.ReadDir(ctx, test.repo, commitID, ".", false)
|
||||
if err != nil {
|
||||
t.Errorf("%s: fs.ReadDir(.): %s", label, err)
|
||||
continue
|
||||
@ -281,7 +280,7 @@ func TestRepository_FileSystem_quoteChars(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, name := range wantNames {
|
||||
stat, err := client.Stat(ctx, authz.DefaultSubRepoPermsChecker, test.repo, commitID, name)
|
||||
stat, err := client.Stat(ctx, test.repo, commitID, name)
|
||||
if err != nil {
|
||||
t.Errorf("%s: Stat(%q): %s", label, name, err)
|
||||
continue
|
||||
@ -318,7 +317,7 @@ func TestRepository_FileSystem_gitSubmodules(t *testing.T) {
|
||||
}
|
||||
|
||||
source := gitserver.NewTestClientSource(t, GitserverAddresses)
|
||||
client := gitserver.NewTestClient(http.DefaultClient, source)
|
||||
client := gitserver.NewTestClient(t).WithClientSource(source)
|
||||
for label, test := range tests {
|
||||
commitID, err := client.ResolveRevision(ctx, test.repo, "master", gitserver.ResolveRevisionOptions{})
|
||||
if err != nil {
|
||||
@ -354,13 +353,13 @@ func TestRepository_FileSystem_gitSubmodules(t *testing.T) {
|
||||
|
||||
// Check the submodule fs.FileInfo both when it's returned by
|
||||
// Stat and when it's returned in a list by ReadDir.
|
||||
submod, err := client.Stat(ctx, authz.DefaultSubRepoPermsChecker, test.repo, commitID, "submod")
|
||||
submod, err := client.Stat(ctx, test.repo, commitID, "submod")
|
||||
if err != nil {
|
||||
t.Errorf("%s: fs.Stat(submod): %s", label, err)
|
||||
continue
|
||||
}
|
||||
checkSubmoduleFileInfo(label+" (Stat)", submod)
|
||||
entries, err := client.ReadDir(ctx, authz.DefaultSubRepoPermsChecker, test.repo, commitID, ".", false)
|
||||
entries, err := client.ReadDir(ctx, test.repo, commitID, ".", false)
|
||||
if err != nil {
|
||||
t.Errorf("%s: fs.ReadDir(.): %s", label, err)
|
||||
continue
|
||||
@ -368,7 +367,7 @@ func TestRepository_FileSystem_gitSubmodules(t *testing.T) {
|
||||
// .gitmodules file is entries[0]
|
||||
checkSubmoduleFileInfo(label+" (ReadDir)", entries[1])
|
||||
|
||||
_, err = client.ReadFile(ctx, nil, test.repo, commitID, "submod")
|
||||
_, err = client.ReadFile(ctx, test.repo, commitID, "submod")
|
||||
if err != nil {
|
||||
t.Errorf("%s: fs.Open(submod): %s", label, err)
|
||||
continue
|
||||
@ -416,8 +415,8 @@ func TestReadDir_SubRepoFiltering(t *testing.T) {
|
||||
}
|
||||
|
||||
source := gitserver.NewTestClientSource(t, GitserverAddresses)
|
||||
client := gitserver.NewTestClient(http.DefaultClient, source)
|
||||
files, err := client.ReadDir(ctx, checker, repo, commitID, "", false)
|
||||
client := gitserver.NewTestClient(t).WithClientSource(source).WithChecker(checker)
|
||||
files, err := client.ReadDir(ctx, repo, commitID, "", false)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %s", err)
|
||||
}
|
||||
|
||||
@ -19,7 +19,7 @@ import (
|
||||
// NewFilter calls gitserver to retrieve the ignore-file. If the file doesn't
|
||||
// exist we return an empty ignore.Matcher.
|
||||
func NewFilter(ctx context.Context, client gitserver.Client, repo api.RepoName, commit api.CommitID) (FilterFunc, error) {
|
||||
ignoreFile, err := client.ReadFile(ctx, nil, repo, commit, ignore.IgnoreFile)
|
||||
ignoreFile, err := client.ReadFile(ctx, repo, commit, ignore.IgnoreFile)
|
||||
if err != nil {
|
||||
// We do not ignore anything if the ignore file does not exist.
|
||||
if strings.Contains(err.Error(), "file does not exist") {
|
||||
|
||||
@ -135,7 +135,7 @@ func Start(ctx context.Context, observationCtx *observation.Context, ready servi
|
||||
// We pass in a nil sub-repo permissions checker and an internal actor here since
|
||||
// searcher needs access to all data in the archive.
|
||||
ctx = actor.WithInternalActor(ctx)
|
||||
return git.ArchiveReader(ctx, nil, repo, gitserver.ArchiveOptions{
|
||||
return git.ArchiveReader(ctx, repo, gitserver.ArchiveOptions{
|
||||
Treeish: string(commit),
|
||||
Format: gitserver.ArchiveFormatTar,
|
||||
})
|
||||
@ -148,7 +148,7 @@ func Start(ctx context.Context, observationCtx *observation.Context, ready servi
|
||||
// We pass in a nil sub-repo permissions checker and an internal actor here since
|
||||
// searcher needs access to all data in the archive.
|
||||
ctx = actor.WithInternalActor(ctx)
|
||||
return git.ArchiveReader(ctx, nil, repo, gitserver.ArchiveOptions{
|
||||
return git.ArchiveReader(ctx, repo, gitserver.ArchiveOptions{
|
||||
Treeish: string(commit),
|
||||
Format: gitserver.ArchiveFormatTar,
|
||||
Pathspecs: pathspecs,
|
||||
|
||||
@ -75,7 +75,7 @@ func (c *gitserverClient) FetchTar(ctx context.Context, repo api.RepoName, commi
|
||||
}
|
||||
|
||||
// Note: the sub-repo perms checker is nil here because we do the sub-repo filtering at a higher level
|
||||
return c.innerClient.ArchiveReader(ctx, nil, repo, opts)
|
||||
return c.innerClient.ArchiveReader(ctx, repo, opts)
|
||||
}
|
||||
|
||||
func (c *gitserverClient) GitDiff(ctx context.Context, repo api.RepoName, commitA, commitB api.CommitID) (_ Changes, err error) {
|
||||
@ -97,7 +97,7 @@ func (c *gitserverClient) GitDiff(ctx context.Context, repo api.RepoName, commit
|
||||
}
|
||||
|
||||
func (c *gitserverClient) ReadFile(ctx context.Context, repoCommitPath types.RepoCommitPath) ([]byte, error) {
|
||||
data, err := c.innerClient.ReadFile(ctx, nil, api.RepoName(repoCommitPath.Repo), api.CommitID(repoCommitPath.Commit), repoCommitPath.Path)
|
||||
data, err := c.innerClient.ReadFile(ctx, api.RepoName(repoCommitPath.Repo), api.CommitID(repoCommitPath.Commit), repoCommitPath.Path)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to get file contents")
|
||||
}
|
||||
|
||||
@ -51,7 +51,6 @@ go_test(
|
||||
embed = [":repo"],
|
||||
deps = [
|
||||
"//internal/api",
|
||||
"//internal/authz",
|
||||
"//internal/conf/conftypes",
|
||||
"//internal/embeddings/embed",
|
||||
"//internal/gitserver",
|
||||
|
||||
@ -237,11 +237,11 @@ type revisionFetcher struct {
|
||||
}
|
||||
|
||||
func (r *revisionFetcher) Read(ctx context.Context, fileName string) ([]byte, error) {
|
||||
return r.gitserver.ReadFile(ctx, nil, r.repo, r.revision, fileName)
|
||||
return r.gitserver.ReadFile(ctx, r.repo, r.revision, fileName)
|
||||
}
|
||||
|
||||
func (r *revisionFetcher) List(ctx context.Context) ([]embed.FileEntry, error) {
|
||||
fileInfos, err := r.gitserver.ReadDir(ctx, nil, r.repo, r.revision, "", true)
|
||||
fileInfos, err := r.gitserver.ReadDir(ctx, r.repo, r.revision, "", true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@ -12,7 +12,6 @@ import (
|
||||
"github.com/google/go-cmp/cmp"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/internal/api"
|
||||
"github.com/sourcegraph/sourcegraph/internal/authz"
|
||||
"github.com/sourcegraph/sourcegraph/internal/conf/conftypes"
|
||||
"github.com/sourcegraph/sourcegraph/internal/embeddings/embed"
|
||||
"github.com/sourcegraph/sourcegraph/internal/gitserver"
|
||||
@ -33,7 +32,7 @@ func TestDiff(t *testing.T) {
|
||||
})
|
||||
|
||||
readDirFunc := &gitserver.ClientReadDirFunc{}
|
||||
readDirFunc.SetDefaultHook(func(context.Context, authz.SubRepoPermissionChecker, api.RepoName, api.CommitID, string, bool) ([]fs.FileInfo, error) {
|
||||
readDirFunc.SetDefaultHook(func(context.Context, api.RepoName, api.CommitID, string, bool) ([]fs.FileInfo, error) {
|
||||
return []fs.FileInfo{
|
||||
FakeFileInfo{
|
||||
name: "modifiedFile",
|
||||
|
||||
@ -17,7 +17,6 @@ go_library(
|
||||
"//internal/api",
|
||||
"//internal/api/internalapi",
|
||||
"//internal/auth",
|
||||
"//internal/authz",
|
||||
"//internal/batches/global",
|
||||
"//internal/batches/graphql",
|
||||
"//internal/batches/rewirer",
|
||||
@ -73,7 +72,6 @@ go_test(
|
||||
"//internal/actor",
|
||||
"//internal/api",
|
||||
"//internal/auth",
|
||||
"//internal/authz",
|
||||
"//internal/batches/reconciler",
|
||||
"//internal/batches/sources/testing",
|
||||
"//internal/batches/store",
|
||||
|
||||
@ -18,7 +18,6 @@ import (
|
||||
"github.com/sourcegraph/sourcegraph/internal/actor"
|
||||
"github.com/sourcegraph/sourcegraph/internal/api"
|
||||
"github.com/sourcegraph/sourcegraph/internal/api/internalapi"
|
||||
"github.com/sourcegraph/sourcegraph/internal/authz"
|
||||
"github.com/sourcegraph/sourcegraph/internal/batches/store"
|
||||
btypes "github.com/sourcegraph/sourcegraph/internal/batches/types"
|
||||
"github.com/sourcegraph/sourcegraph/internal/database"
|
||||
@ -450,7 +449,7 @@ func hasBatchIgnoreFile(ctx context.Context, gitserverClient gitserver.Client, r
|
||||
tr, ctx := trace.New(ctx, "hasBatchIgnoreFile", attribute.Int("repoID", int(r.Repo.ID)))
|
||||
defer tr.EndWithErr(&err)
|
||||
|
||||
stat, err := gitserverClient.Stat(ctx, authz.DefaultSubRepoPermsChecker, r.Repo.Name, r.Commit, batchIgnoreFilePath)
|
||||
stat, err := gitserverClient.Stat(ctx, r.Repo.Name, r.Commit, batchIgnoreFilePath)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return false, nil
|
||||
|
||||
@ -18,7 +18,6 @@ import (
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/internal/actor"
|
||||
"github.com/sourcegraph/sourcegraph/internal/api"
|
||||
"github.com/sourcegraph/sourcegraph/internal/authz"
|
||||
"github.com/sourcegraph/sourcegraph/internal/batches/store"
|
||||
bt "github.com/sourcegraph/sourcegraph/internal/batches/testing"
|
||||
"github.com/sourcegraph/sourcegraph/internal/database"
|
||||
@ -120,7 +119,7 @@ func TestService_ResolveWorkspacesForBatchSpec(t *testing.T) {
|
||||
return "", "", &gitdomain.RepoNotExistError{Repo: repo}
|
||||
})
|
||||
|
||||
gitserverClient.StatFunc.SetDefaultHook(func(ctx context.Context, _ authz.SubRepoPermissionChecker, repo api.RepoName, commit api.CommitID, s string) (fs.FileInfo, error) {
|
||||
gitserverClient.StatFunc.SetDefaultHook(func(ctx context.Context, repo api.RepoName, commit api.CommitID, s string) (fs.FileInfo, error) {
|
||||
hasBatchIgnore, ok := commitMap[commit]
|
||||
if !ok {
|
||||
return nil, errors.Newf("unknown commit: %s", commit)
|
||||
|
||||
@ -78,7 +78,6 @@ go_test(
|
||||
],
|
||||
deps = [
|
||||
"//internal/api",
|
||||
"//internal/authz",
|
||||
"//internal/batches/sources/azuredevops",
|
||||
"//internal/batches/sources/bitbucketcloud",
|
||||
"//internal/batches/sources/gerrit",
|
||||
|
||||
784
internal/batches/sources/mocks_test.go
generated
784
internal/batches/sources/mocks_test.go
generated
File diff suppressed because it is too large
Load Diff
@ -14,7 +14,6 @@ go_library(
|
||||
deps = [
|
||||
"//internal/actor",
|
||||
"//internal/api",
|
||||
"//internal/authz",
|
||||
"//internal/batches/sources/azuredevops",
|
||||
"//internal/batches/sources/bitbucketcloud",
|
||||
"//internal/batches/sources/gerrit",
|
||||
|
||||
@ -21,7 +21,6 @@ import (
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/internal/actor"
|
||||
"github.com/sourcegraph/sourcegraph/internal/api"
|
||||
"github.com/sourcegraph/sourcegraph/internal/authz"
|
||||
bbcs "github.com/sourcegraph/sourcegraph/internal/batches/sources/bitbucketcloud"
|
||||
btypes "github.com/sourcegraph/sourcegraph/internal/batches/types"
|
||||
"github.com/sourcegraph/sourcegraph/internal/database"
|
||||
@ -794,7 +793,7 @@ func computeDiffStat(ctx context.Context, client gitserver.Client, c *btypes.Cha
|
||||
if c.SyncState.BaseRefOid == c.SyncState.HeadRefOid {
|
||||
return c.DiffStat(), nil
|
||||
}
|
||||
iter, err := client.Diff(ctx, authz.DefaultSubRepoPermsChecker, gitserver.DiffOptions{
|
||||
iter, err := client.Diff(ctx, gitserver.DiffOptions{
|
||||
Repo: repo,
|
||||
Base: c.SyncState.BaseRefOid,
|
||||
Head: c.SyncState.HeadRefOid,
|
||||
|
||||
@ -10,7 +10,6 @@ import (
|
||||
"github.com/sourcegraph/go-diff/diff"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/internal/api"
|
||||
"github.com/sourcegraph/sourcegraph/internal/authz"
|
||||
"github.com/sourcegraph/sourcegraph/internal/gitserver"
|
||||
"github.com/sourcegraph/sourcegraph/internal/repoupdater"
|
||||
"github.com/sourcegraph/sourcegraph/internal/repoupdater/protocol"
|
||||
@ -45,7 +44,7 @@ func MockChangesetSyncState(repo *protocol.RepoInfo) *MockedChangesetSyncState {
|
||||
}
|
||||
|
||||
gitserverClient := gitserver.NewMockClient()
|
||||
gitserverClient.DiffFunc.SetDefaultHook(func(_ context.Context, _ authz.SubRepoPermissionChecker, opts gitserver.DiffOptions) (*gitserver.DiffFileIterator, error) {
|
||||
gitserverClient.DiffFunc.SetDefaultHook(func(_ context.Context, opts gitserver.DiffOptions) (*gitserver.DiffFileIterator, error) {
|
||||
// This provides a diff that will resolve to 1 added line, 1 changed
|
||||
// line, and 3 deleted lines.
|
||||
const testGitHubDiff = `
|
||||
|
||||
@ -13,7 +13,6 @@ go_library(
|
||||
visibility = ["//:__subpackages__"],
|
||||
deps = [
|
||||
"//internal/api",
|
||||
"//internal/authz",
|
||||
"//internal/codeintel/autoindexing/internal/background",
|
||||
"//internal/codeintel/autoindexing/internal/background/dependencies",
|
||||
"//internal/codeintel/autoindexing/internal/background/scheduler",
|
||||
|
||||
@ -37,10 +37,10 @@ func NewDefaultGitService(checker authz.SubRepoPermissionChecker) GitService {
|
||||
}
|
||||
|
||||
func (s *gitService) LsFiles(ctx context.Context, repo api.RepoName, commit string, pathspecs ...gitdomain.Pathspec) ([]string, error) {
|
||||
return s.client.LsFiles(ctx, s.checker, repo, api.CommitID(commit), pathspecs...)
|
||||
return s.client.LsFiles(ctx, repo, api.CommitID(commit), pathspecs...)
|
||||
}
|
||||
|
||||
func (s *gitService) Archive(ctx context.Context, repo api.RepoName, opts gitserver.ArchiveOptions) (io.ReadCloser, error) {
|
||||
// Note: the sub-repo perms checker is nil here because all paths were already checked via a previous call to s.ListFiles
|
||||
return s.client.ArchiveReader(ctx, nil, repo, opts)
|
||||
return s.client.ArchiveReader(ctx, repo, opts)
|
||||
}
|
||||
|
||||
@ -10,7 +10,6 @@ go_library(
|
||||
visibility = ["//:__subpackages__"],
|
||||
deps = [
|
||||
"//internal/api",
|
||||
"//internal/authz",
|
||||
"//internal/codeintel/autoindexing/internal/store",
|
||||
"//internal/codeintel/autoindexing/shared",
|
||||
"//internal/codeintel/uploads/shared",
|
||||
|
||||
@ -7,7 +7,6 @@ import (
|
||||
"github.com/sourcegraph/log"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/internal/api"
|
||||
"github.com/sourcegraph/sourcegraph/internal/authz"
|
||||
"github.com/sourcegraph/sourcegraph/internal/codeintel/autoindexing/internal/store"
|
||||
"github.com/sourcegraph/sourcegraph/internal/codeintel/autoindexing/shared"
|
||||
uploadsshared "github.com/sourcegraph/sourcegraph/internal/codeintel/uploads/shared"
|
||||
@ -175,7 +174,7 @@ func (s *JobSelector) getIndexRecordsFromConfigurationInRepository(ctx context.C
|
||||
return nil, false, err
|
||||
}
|
||||
|
||||
content, err := s.gitserverClient.ReadFile(ctx, authz.DefaultSubRepoPermsChecker, repo.Name, api.CommitID(commit), "sourcegraph.yaml")
|
||||
content, err := s.gitserverClient.ReadFile(ctx, repo.Name, api.CommitID(commit), "sourcegraph.yaml")
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return nil, false, nil
|
||||
|
||||
@ -8,7 +8,6 @@ import (
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/internal/api"
|
||||
"github.com/sourcegraph/sourcegraph/internal/authz"
|
||||
"github.com/sourcegraph/sourcegraph/internal/codeintel/autoindexing/internal/enqueuer"
|
||||
"github.com/sourcegraph/sourcegraph/internal/codeintel/autoindexing/internal/inference"
|
||||
"github.com/sourcegraph/sourcegraph/internal/codeintel/autoindexing/internal/jobselector"
|
||||
@ -92,12 +91,12 @@ func (s *Service) InferIndexConfiguration(ctx context.Context, repositoryID int,
|
||||
|
||||
if commit == "" {
|
||||
var ok bool
|
||||
commit, ok, err = s.gitserverClient.Head(ctx, authz.DefaultSubRepoPermsChecker, repo.Name)
|
||||
commit, ok, err = s.gitserverClient.Head(ctx, repo.Name)
|
||||
if err != nil || !ok {
|
||||
return nil, errors.Wrapf(err, "gitserver.Head: error resolving HEAD for %d", repositoryID)
|
||||
}
|
||||
} else {
|
||||
exists, err := s.gitserverClient.CommitExists(ctx, authz.DefaultSubRepoPermsChecker, repo.Name, api.CommitID(commit))
|
||||
exists, err := s.gitserverClient.CommitExists(ctx, repo.Name, api.CommitID(commit))
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "gitserver.CommitExists: error checking %s for %d", commit, repositoryID)
|
||||
}
|
||||
|
||||
@ -7,7 +7,6 @@ import (
|
||||
"sync"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/internal/api"
|
||||
"github.com/sourcegraph/sourcegraph/internal/authz"
|
||||
"github.com/sourcegraph/sourcegraph/internal/database"
|
||||
"github.com/sourcegraph/sourcegraph/internal/gitserver"
|
||||
"github.com/sourcegraph/sourcegraph/lib/errors"
|
||||
@ -146,7 +145,7 @@ func (c *commitCache) commitsExist(ctx context.Context, commits []RepositoryComm
|
||||
}
|
||||
}
|
||||
|
||||
exists, err := c.gitserverClient.CommitsExist(ctx, authz.DefaultSubRepoPermsChecker, repoCommits)
|
||||
exists, err := c.gitserverClient.CommitsExist(ctx, repoCommits)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@ -8,7 +8,6 @@ import (
|
||||
"github.com/dgraph-io/ristretto"
|
||||
"github.com/sourcegraph/go-diff/diff"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/internal/authz"
|
||||
"github.com/sourcegraph/sourcegraph/internal/codeintel/codenav/shared"
|
||||
"github.com/sourcegraph/sourcegraph/internal/gitserver"
|
||||
sgtypes "github.com/sourcegraph/sourcegraph/internal/types"
|
||||
@ -156,7 +155,7 @@ func (g *gitTreeTranslator) readCachedHunks(ctx context.Context, repo *sgtypes.R
|
||||
// readHunks returns a position-ordered slice of changes (additions or deletions) of
|
||||
// the given path between the given source and target commits.
|
||||
func (g *gitTreeTranslator) readHunks(ctx context.Context, repo *sgtypes.Repo, sourceCommit, targetCommit, path string) ([]*diff.Hunk, error) {
|
||||
return g.client.DiffPath(ctx, authz.DefaultSubRepoPermsChecker, repo.Name, sourceCommit, targetCommit, path)
|
||||
return g.client.DiffPath(ctx, repo.Name, sourceCommit, targetCommit, path)
|
||||
}
|
||||
|
||||
// findHunk returns the last thunk that does not begin after the given line.
|
||||
|
||||
@ -40,7 +40,7 @@ func TestGetTargetCommitPathFromSourcePath(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetTargetCommitPositionFromSourcePosition(t *testing.T) {
|
||||
client := gitserver.NewMockClientWithExecReader(func(_ context.Context, _ api.RepoName, args []string) (reader io.ReadCloser, err error) {
|
||||
client := gitserver.NewMockClientWithExecReader(nil, func(_ context.Context, _ api.RepoName, args []string) (reader io.ReadCloser, err error) {
|
||||
expectedArgs := []string{"diff", "deadbeef1", "deadbeef2", "--", "/foo/bar.go"}
|
||||
if diff := cmp.Diff(expectedArgs, args); diff != "" {
|
||||
t.Errorf("unexpected exec reader args (-want +got):\n%s", diff)
|
||||
@ -76,7 +76,7 @@ func TestGetTargetCommitPositionFromSourcePosition(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetTargetCommitPositionFromSourcePositionEmptyDiff(t *testing.T) {
|
||||
client := gitserver.NewMockClientWithExecReader(func(_ context.Context, _ api.RepoName, args []string) (reader io.ReadCloser, err error) {
|
||||
client := gitserver.NewMockClientWithExecReader(nil, func(_ context.Context, _ api.RepoName, args []string) (reader io.ReadCloser, err error) {
|
||||
return io.NopCloser(bytes.NewReader(nil)), nil
|
||||
})
|
||||
|
||||
@ -105,7 +105,7 @@ func TestGetTargetCommitPositionFromSourcePositionEmptyDiff(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetTargetCommitPositionFromSourcePositionReverse(t *testing.T) {
|
||||
client := gitserver.NewMockClientWithExecReader(func(_ context.Context, _ api.RepoName, args []string) (reader io.ReadCloser, err error) {
|
||||
client := gitserver.NewMockClientWithExecReader(nil, func(_ context.Context, _ api.RepoName, args []string) (reader io.ReadCloser, err error) {
|
||||
expectedArgs := []string{"diff", "deadbeef2", "deadbeef1", "--", "/foo/bar.go"}
|
||||
if diff := cmp.Diff(expectedArgs, args); diff != "" {
|
||||
t.Errorf("unexpected exec reader args (-want +got):\n%s", diff)
|
||||
@ -141,7 +141,7 @@ func TestGetTargetCommitPositionFromSourcePositionReverse(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetTargetCommitRangeFromSourceRange(t *testing.T) {
|
||||
client := gitserver.NewMockClientWithExecReader(func(_ context.Context, _ api.RepoName, args []string) (reader io.ReadCloser, err error) {
|
||||
client := gitserver.NewMockClientWithExecReader(nil, func(_ context.Context, _ api.RepoName, args []string) (reader io.ReadCloser, err error) {
|
||||
expectedArgs := []string{"diff", "deadbeef1", "deadbeef2", "--", "/foo/bar.go"}
|
||||
if diff := cmp.Diff(expectedArgs, args); diff != "" {
|
||||
t.Errorf("unexpected exec reader args (-want +got):\n%s", diff)
|
||||
@ -183,7 +183,7 @@ func TestGetTargetCommitRangeFromSourceRange(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetTargetCommitRangeFromSourceRangeEmptyDiff(t *testing.T) {
|
||||
client := gitserver.NewMockClientWithExecReader(func(_ context.Context, _ api.RepoName, args []string) (reader io.ReadCloser, err error) {
|
||||
client := gitserver.NewMockClientWithExecReader(nil, func(_ context.Context, _ api.RepoName, args []string) (reader io.ReadCloser, err error) {
|
||||
return io.NopCloser(bytes.NewReader([]byte(nil))), nil
|
||||
})
|
||||
|
||||
@ -215,7 +215,7 @@ func TestGetTargetCommitRangeFromSourceRangeEmptyDiff(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetTargetCommitRangeFromSourceRangeReverse(t *testing.T) {
|
||||
client := gitserver.NewMockClientWithExecReader(func(_ context.Context, _ api.RepoName, args []string) (reader io.ReadCloser, err error) {
|
||||
client := gitserver.NewMockClientWithExecReader(nil, func(_ context.Context, _ api.RepoName, args []string) (reader io.ReadCloser, err error) {
|
||||
expectedArgs := []string{"diff", "deadbeef2", "deadbeef1", "--", "/foo/bar.go"}
|
||||
if diff := cmp.Diff(expectedArgs, args); diff != "" {
|
||||
t.Errorf("unexpected exec reader args (-want +got):\n%s", diff)
|
||||
|
||||
@ -983,7 +983,7 @@ func (s *Service) SnapshotForDocument(ctx context.Context, repositoryID int, com
|
||||
return nil, err
|
||||
}
|
||||
|
||||
file, err := s.gitserver.ReadFile(ctx, authz.DefaultSubRepoPermsChecker, api.RepoName(dump.RepositoryName), api.CommitID(dump.Commit), path)
|
||||
file, err := s.gitserver.ReadFile(ctx, api.RepoName(dump.RepositoryName), api.CommitID(dump.Commit), path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@ -7,7 +7,6 @@ import (
|
||||
"github.com/google/go-cmp/cmp"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/internal/api"
|
||||
"github.com/sourcegraph/sourcegraph/internal/authz"
|
||||
"github.com/sourcegraph/sourcegraph/internal/codeintel/codenav/shared"
|
||||
uploadsshared "github.com/sourcegraph/sourcegraph/internal/codeintel/uploads/shared"
|
||||
"github.com/sourcegraph/sourcegraph/internal/gitserver"
|
||||
@ -138,7 +137,7 @@ func TestHoverRemote(t *testing.T) {
|
||||
mockLsifStore.GetBulkMonikerLocationsFunc.PushReturn(locations, 0, nil)
|
||||
mockLsifStore.GetBulkMonikerLocationsFunc.PushReturn(locations, len(locations), nil)
|
||||
|
||||
mockGitserverClient.CommitsExistFunc.SetDefaultHook(func(ctx context.Context, _ authz.SubRepoPermissionChecker, rcs []api.RepoCommit) (exists []bool, _ error) {
|
||||
mockGitserverClient.CommitsExistFunc.SetDefaultHook(func(ctx context.Context, rcs []api.RepoCommit) (exists []bool, _ error) {
|
||||
for range rcs {
|
||||
exists = append(exists, true)
|
||||
}
|
||||
|
||||
@ -7,7 +7,6 @@ import (
|
||||
"github.com/google/go-cmp/cmp"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/internal/api"
|
||||
"github.com/sourcegraph/sourcegraph/internal/authz"
|
||||
"github.com/sourcegraph/sourcegraph/internal/codeintel/codenav/shared"
|
||||
uploadsshared "github.com/sourcegraph/sourcegraph/internal/codeintel/uploads/shared"
|
||||
"github.com/sourcegraph/sourcegraph/internal/gitserver"
|
||||
@ -113,7 +112,7 @@ func TestGetDefinitions(t *testing.T) {
|
||||
mockUploadSvc.GetDumpsWithDefinitionsForMonikersFunc.PushReturn(dumps, nil)
|
||||
|
||||
// upload #150's commit no longer exists; all others do
|
||||
mockGitserverClient.CommitsExistFunc.SetDefaultHook(func(ctx context.Context, _ authz.SubRepoPermissionChecker, rcs []api.RepoCommit) (exists []bool, _ error) {
|
||||
mockGitserverClient.CommitsExistFunc.SetDefaultHook(func(ctx context.Context, rcs []api.RepoCommit) (exists []bool, _ error) {
|
||||
for _, rc := range rcs {
|
||||
exists = append(exists, rc.CommitID != "deadbeef1")
|
||||
}
|
||||
@ -312,7 +311,7 @@ func TestGetReferences(t *testing.T) {
|
||||
mockUploadSvc.GetUploadIDsWithReferencesFunc.PushReturn([]int{252, 253}, 0, 2, nil)
|
||||
|
||||
// upload #150/#250's commits no longer exists; all others do
|
||||
mockGitserverClient.CommitsExistFunc.SetDefaultHook(func(ctx context.Context, _ authz.SubRepoPermissionChecker, rcs []api.RepoCommit) (exists []bool, _ error) {
|
||||
mockGitserverClient.CommitsExistFunc.SetDefaultHook(func(ctx context.Context, rcs []api.RepoCommit) (exists []bool, _ error) {
|
||||
for _, rc := range rcs {
|
||||
exists = append(exists, rc.CommitID != "deadbeef1")
|
||||
}
|
||||
|
||||
@ -9,7 +9,6 @@ import (
|
||||
godiff "github.com/sourcegraph/go-diff/diff"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/internal/api"
|
||||
"github.com/sourcegraph/sourcegraph/internal/authz"
|
||||
"github.com/sourcegraph/sourcegraph/internal/codeintel/codenav/shared"
|
||||
uploadsshared "github.com/sourcegraph/sourcegraph/internal/codeintel/uploads/shared"
|
||||
"github.com/sourcegraph/sourcegraph/internal/gitserver"
|
||||
@ -39,7 +38,7 @@ func TestRanges(t *testing.T) {
|
||||
mockLsifStore := NewMockLsifStore()
|
||||
mockUploadSvc := NewMockUploadService()
|
||||
mockGitserverClient := gitserver.NewMockClient()
|
||||
mockGitserverClient.DiffPathFunc.SetDefaultHook(func(ctx context.Context, _ authz.SubRepoPermissionChecker, repo api.RepoName, sourceCommit, targetCommit, path string) ([]*godiff.Hunk, error) {
|
||||
mockGitserverClient.DiffPathFunc.SetDefaultHook(func(ctx context.Context, repo api.RepoName, sourceCommit, targetCommit, path string) ([]*godiff.Hunk, error) {
|
||||
if path == "sub3/changed.go" {
|
||||
fileDiff, err := godiff.ParseFileDiff([]byte(rangesDiff))
|
||||
if err != nil {
|
||||
|
||||
@ -51,7 +51,6 @@ go_test(
|
||||
],
|
||||
deps = [
|
||||
"//internal/api",
|
||||
"//internal/authz",
|
||||
"//internal/codeintel/dependencies/internal/store",
|
||||
"//internal/codeintel/dependencies/shared",
|
||||
"//internal/conf/reposource",
|
||||
|
||||
@ -119,7 +119,7 @@ func (j *crateSyncerJob) handleCrateSyncer(ctx context.Context, interval time.Du
|
||||
return errors.Newf("failed to update repo %s, error %s", repoName, update.Error)
|
||||
}
|
||||
|
||||
allFilesStr, err := j.gitClient.LsFiles(ctx, nil, repoName, "HEAD")
|
||||
allFilesStr, err := j.gitClient.LsFiles(ctx, repoName, "HEAD")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -244,7 +244,6 @@ func (j *crateSyncerJob) handleCrateSyncer(ctx context.Context, interval time.Du
|
||||
func (j *crateSyncerJob) readIndexArchiveBatch(ctx context.Context, repoName api.RepoName, batch []gitdomain.Pathspec) (io.Reader, error) {
|
||||
reader, err := j.gitClient.ArchiveReader(
|
||||
ctx,
|
||||
nil,
|
||||
repoName,
|
||||
gitserver.ArchiveOptions{
|
||||
Treeish: "HEAD",
|
||||
|
||||
@ -16,7 +16,6 @@ import (
|
||||
"golang.org/x/exp/slices"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/internal/api"
|
||||
"github.com/sourcegraph/sourcegraph/internal/authz"
|
||||
"github.com/sourcegraph/sourcegraph/internal/codeintel/dependencies/shared"
|
||||
"github.com/sourcegraph/sourcegraph/internal/conf/reposource"
|
||||
"github.com/sourcegraph/sourcegraph/internal/encryption"
|
||||
@ -63,7 +62,7 @@ func TestCrateSyncer(t *testing.T) {
|
||||
|
||||
gitclient := gitserver.NewMockClient()
|
||||
gitclient.LsFilesFunc.SetDefaultReturn([]string{"petgraph", "percent"}, nil)
|
||||
gitclient.ArchiveReaderFunc.SetDefaultHook(func(ctx context.Context, sub authz.SubRepoPermissionChecker, name api.RepoName, opts gitserver.ArchiveOptions) (io.ReadCloser, error) {
|
||||
gitclient.ArchiveReaderFunc.SetDefaultHook(func(ctx context.Context, name api.RepoName, opts gitserver.ArchiveOptions) (io.ReadCloser, error) {
|
||||
var archive io.ReadCloser
|
||||
switch opts.Pathspecs[0] {
|
||||
case "petgraph":
|
||||
@ -120,7 +119,7 @@ func TestCrateSyncer(t *testing.T) {
|
||||
extsvcStore.GetByIDFunc.history = extsvcStore.GetByIDFunc.history[:0]
|
||||
autoindexSvc.QueueIndexesForPackageFunc.history = autoindexSvc.QueueIndexesForPackageFunc.history[:0]
|
||||
|
||||
gitclient.ArchiveReaderFunc.SetDefaultHook(func(ctx context.Context, sub authz.SubRepoPermissionChecker, name api.RepoName, opts gitserver.ArchiveOptions) (io.ReadCloser, error) {
|
||||
gitclient.ArchiveReaderFunc.SetDefaultHook(func(ctx context.Context, name api.RepoName, opts gitserver.ArchiveOptions) (io.ReadCloser, error) {
|
||||
if slices.Contains(opts.Pathspecs, "petgraph") {
|
||||
return createArchive(t, fileInfo{"petgraph", []byte(petgraphJSON)}), nil
|
||||
}
|
||||
@ -152,7 +151,7 @@ func TestCrateSyncer(t *testing.T) {
|
||||
extsvcStore.GetByIDFunc.history = extsvcStore.GetByIDFunc.history[:0]
|
||||
autoindexSvc.QueueIndexesForPackageFunc.history = autoindexSvc.QueueIndexesForPackageFunc.history[:0]
|
||||
|
||||
gitclient.ArchiveReaderFunc.SetDefaultHook(func(ctx context.Context, sub authz.SubRepoPermissionChecker, name api.RepoName, opts gitserver.ArchiveOptions) (io.ReadCloser, error) {
|
||||
gitclient.ArchiveReaderFunc.SetDefaultHook(func(ctx context.Context, name api.RepoName, opts gitserver.ArchiveOptions) (io.ReadCloser, error) {
|
||||
if slices.Contains(opts.Pathspecs, "petgraph") {
|
||||
return createArchive(t, fileInfo{"petgraph", []byte(petgraphJSON[:len(petgraphJSON)-5])}), nil
|
||||
}
|
||||
|
||||
@ -15,7 +15,6 @@ go_library(
|
||||
visibility = ["//:__subpackages__"],
|
||||
deps = [
|
||||
"//internal/api",
|
||||
"//internal/authz",
|
||||
"//internal/codeintel/policies/internal/background",
|
||||
"//internal/codeintel/policies/internal/background/repository_matcher",
|
||||
"//internal/codeintel/policies/internal/store",
|
||||
@ -48,7 +47,6 @@ go_test(
|
||||
embed = [":policies"],
|
||||
deps = [
|
||||
"//internal/api",
|
||||
"//internal/authz",
|
||||
"//internal/codeintel/policies/internal/store",
|
||||
"//internal/codeintel/policies/shared",
|
||||
"//internal/codeintel/uploads/shared",
|
||||
|
||||
@ -8,7 +8,6 @@ import (
|
||||
"github.com/gobwas/glob"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/internal/api"
|
||||
"github.com/sourcegraph/sourcegraph/internal/authz"
|
||||
"github.com/sourcegraph/sourcegraph/internal/codeintel/policies/shared"
|
||||
"github.com/sourcegraph/sourcegraph/internal/gitserver"
|
||||
"github.com/sourcegraph/sourcegraph/internal/gitserver/gitdomain"
|
||||
@ -79,7 +78,7 @@ func (m *Matcher) CommitsDescribedByPolicy(ctx context.Context, repositoryID int
|
||||
branchRequests: map[string]branchRequestMeta{},
|
||||
}
|
||||
|
||||
refDescriptions, err := m.gitserverClient.RefDescriptions(ctx, authz.DefaultSubRepoPermsChecker, repoName, filterCommits...)
|
||||
refDescriptions, err := m.gitserverClient.RefDescriptions(ctx, repoName, filterCommits...)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "gitserver.RefDescriptions")
|
||||
}
|
||||
@ -214,7 +213,6 @@ func (m *Matcher) matchCommitsOnBranch(ctx context.Context, context matcherConte
|
||||
|
||||
commitDates, err := m.gitserverClient.CommitsUniqueToBranch(
|
||||
ctx,
|
||||
authz.DefaultSubRepoPermsChecker,
|
||||
context.repo,
|
||||
branchRequestMeta.commitID,
|
||||
branchRequestMeta.isDefaultBranch,
|
||||
@ -261,7 +259,7 @@ func (m *Matcher) matchCommitsOnBranch(ctx context.Context, context matcherConte
|
||||
func (m *Matcher) matchCommitPolicies(ctx context.Context, context matcherContext, now time.Time) error {
|
||||
for _, policy := range context.policies {
|
||||
if policy.Type == shared.GitObjectTypeCommit {
|
||||
commit, commitDate, revisionExists, err := m.gitserverClient.CommitDate(ctx, authz.DefaultSubRepoPermsChecker, context.repo, api.CommitID(policy.Pattern))
|
||||
commit, commitDate, revisionExists, err := m.gitserverClient.CommitDate(ctx, context.repo, api.CommitID(policy.Pattern))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -6,7 +6,6 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/internal/api"
|
||||
"github.com/sourcegraph/sourcegraph/internal/authz"
|
||||
"github.com/sourcegraph/sourcegraph/internal/gitserver"
|
||||
"github.com/sourcegraph/sourcegraph/internal/gitserver/gitdomain"
|
||||
)
|
||||
@ -59,12 +58,12 @@ func testUploadExpirerMockGitserverClient(defaultBranchName string, now time.Tim
|
||||
"deadbeef09": testCommitDateFor("deadbeef09", now),
|
||||
}
|
||||
|
||||
commitDate := func(ctx context.Context, _ authz.SubRepoPermissionChecker, repo api.RepoName, commitID api.CommitID) (string, time.Time, bool, error) {
|
||||
commitDate := func(ctx context.Context, repo api.RepoName, commitID api.CommitID) (string, time.Time, bool, error) {
|
||||
commitDate, ok := createdAt[string(commitID)]
|
||||
return string(commitID), commitDate, ok, nil
|
||||
}
|
||||
|
||||
refDescriptions := func(ctx context.Context, _ authz.SubRepoPermissionChecker, repo api.RepoName, _ ...string) (map[string][]gitdomain.RefDescription, error) {
|
||||
refDescriptions := func(ctx context.Context, repo api.RepoName, _ ...string) (map[string][]gitdomain.RefDescription, error) {
|
||||
refDescriptions := map[string][]gitdomain.RefDescription{}
|
||||
for branch, commit := range branchHeads {
|
||||
branchHeadCreateDate := createdAt[commit]
|
||||
@ -88,7 +87,7 @@ func testUploadExpirerMockGitserverClient(defaultBranchName string, now time.Tim
|
||||
return refDescriptions, nil
|
||||
}
|
||||
|
||||
commitsUniqueToBranch := func(ctx context.Context, _ authz.SubRepoPermissionChecker, repo api.RepoName, branchName string, isDefaultBranch bool, maxAge *time.Time) (map[string]time.Time, error) {
|
||||
commitsUniqueToBranch := func(ctx context.Context, repo api.RepoName, branchName string, isDefaultBranch bool, maxAge *time.Time) (map[string]time.Time, error) {
|
||||
branches := map[string]time.Time{}
|
||||
for _, commit := range branchMembers[branchName] {
|
||||
if maxAge == nil || !createdAt[commit].Before(*maxAge) {
|
||||
|
||||
@ -32,7 +32,7 @@ func TestCommitsDescribedByPolicyForRetention(t *testing.T) {
|
||||
}
|
||||
|
||||
for i, call := range gitserverClient.CommitsUniqueToBranchFunc.History() {
|
||||
if call.Arg5 != nil {
|
||||
if call.Arg4 != nil {
|
||||
t.Errorf("unexpected restriction of git results by date: call #%d", i)
|
||||
}
|
||||
}
|
||||
|
||||
@ -15,7 +15,6 @@ go_library(
|
||||
visibility = ["//:__subpackages__"],
|
||||
deps = [
|
||||
"//internal/api",
|
||||
"//internal/authz",
|
||||
"//internal/codeintel/resolvers",
|
||||
"//internal/codeintel/shared/resolvers/dataloader",
|
||||
"//internal/database",
|
||||
|
||||
@ -8,7 +8,6 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/internal/api"
|
||||
"github.com/sourcegraph/sourcegraph/internal/authz"
|
||||
"github.com/sourcegraph/sourcegraph/internal/codeintel/resolvers"
|
||||
"github.com/sourcegraph/sourcegraph/internal/gitserver"
|
||||
)
|
||||
@ -57,7 +56,6 @@ func (r *treeEntryResolver) Content(ctx context.Context, args *resolvers.GitTree
|
||||
|
||||
content, err := r.gitserverClient.ReadFile(
|
||||
ctx,
|
||||
authz.DefaultSubRepoPermsChecker,
|
||||
api.RepoName(r.commit.Repository().Name()), // repository name
|
||||
api.CommitID(r.commit.OID()), // commit oid
|
||||
r.path, // path
|
||||
|
||||
@ -12,7 +12,6 @@ go_library(
|
||||
deps = [
|
||||
"//internal/actor",
|
||||
"//internal/api",
|
||||
"//internal/authz",
|
||||
"//internal/codeintel/uploads/internal/store",
|
||||
"//internal/env",
|
||||
"//internal/gitserver",
|
||||
@ -30,7 +29,6 @@ go_test(
|
||||
embed = [":backfiller"],
|
||||
deps = [
|
||||
"//internal/api",
|
||||
"//internal/authz",
|
||||
"//internal/codeintel/uploads/internal/store",
|
||||
"//internal/codeintel/uploads/shared",
|
||||
"//internal/database/basestore",
|
||||
|
||||
@ -6,7 +6,6 @@ import (
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/internal/actor"
|
||||
"github.com/sourcegraph/sourcegraph/internal/api"
|
||||
"github.com/sourcegraph/sourcegraph/internal/authz"
|
||||
"github.com/sourcegraph/sourcegraph/internal/codeintel/uploads/internal/store"
|
||||
"github.com/sourcegraph/sourcegraph/internal/gitserver"
|
||||
"github.com/sourcegraph/sourcegraph/internal/goroutine"
|
||||
@ -71,7 +70,7 @@ func (s *backfiller) BackfillCommittedAtBatch(ctx context.Context, batchSize int
|
||||
|
||||
func (s *backfiller) getCommitDate(ctx context.Context, repositoryName, commit string) (string, error) {
|
||||
repo := api.RepoName(repositoryName)
|
||||
_, commitDate, revisionExists, err := s.gitserverClient.CommitDate(ctx, authz.DefaultSubRepoPermsChecker, repo, api.CommitID(commit))
|
||||
_, commitDate, revisionExists, err := s.gitserverClient.CommitDate(ctx, repo, api.CommitID(commit))
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "gitserver.CommitDate")
|
||||
}
|
||||
|
||||
@ -9,7 +9,6 @@ import (
|
||||
"github.com/google/go-cmp/cmp"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/internal/api"
|
||||
"github.com/sourcegraph/sourcegraph/internal/authz"
|
||||
shared "github.com/sourcegraph/sourcegraph/internal/codeintel/uploads/internal/store"
|
||||
"github.com/sourcegraph/sourcegraph/internal/gitserver"
|
||||
)
|
||||
@ -33,7 +32,7 @@ func TestBackfillCommittedAtBatch(t *testing.T) {
|
||||
expectedCommitDates[fmt.Sprintf("%040d", i)] = t0.Add(time.Second * time.Duration(i))
|
||||
}
|
||||
|
||||
gitserverClient.CommitDateFunc.SetDefaultHook(func(ctx context.Context, _ authz.SubRepoPermissionChecker, repo api.RepoName, commit api.CommitID) (string, time.Time, bool, error) {
|
||||
gitserverClient.CommitDateFunc.SetDefaultHook(func(ctx context.Context, repo api.RepoName, commit api.CommitID) (string, time.Time, bool, error) {
|
||||
date, ok := expectedCommitDates[string(commit)]
|
||||
return string(commit), date, ok, nil
|
||||
})
|
||||
@ -112,7 +111,7 @@ func TestBackfillCommittedAtBatchUnknownCommits(t *testing.T) {
|
||||
expectedCommitDates[fmt.Sprintf("%040d", i)] = t0.Add(time.Second * time.Duration(i))
|
||||
}
|
||||
|
||||
gitserverClient.CommitDateFunc.SetDefaultHook(func(ctx context.Context, _ authz.SubRepoPermissionChecker, repo api.RepoName, commit api.CommitID) (string, time.Time, bool, error) {
|
||||
gitserverClient.CommitDateFunc.SetDefaultHook(func(ctx context.Context, repo api.RepoName, commit api.CommitID) (string, time.Time, bool, error) {
|
||||
date, ok := expectedCommitDates[string(commit)]
|
||||
return string(commit), date, ok, nil
|
||||
})
|
||||
|
||||
@ -12,7 +12,6 @@ go_library(
|
||||
deps = [
|
||||
"//internal/actor",
|
||||
"//internal/api",
|
||||
"//internal/authz",
|
||||
"//internal/codeintel/uploads/internal/store",
|
||||
"//internal/database/locker",
|
||||
"//internal/env",
|
||||
|
||||
@ -6,7 +6,6 @@ import (
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/internal/actor"
|
||||
"github.com/sourcegraph/sourcegraph/internal/api"
|
||||
"github.com/sourcegraph/sourcegraph/internal/authz"
|
||||
"github.com/sourcegraph/sourcegraph/internal/codeintel/uploads/internal/store"
|
||||
"github.com/sourcegraph/sourcegraph/internal/database/locker"
|
||||
"github.com/sourcegraph/sourcegraph/internal/gitserver"
|
||||
@ -102,7 +101,7 @@ func (s *commitGraphUpdater) lockAndUpdateUploadsVisibleToCommits(ctx context.Co
|
||||
return err
|
||||
}
|
||||
|
||||
refDescriptions, err := s.gitserverClient.RefDescriptions(ctx, authz.DefaultSubRepoPermsChecker, repo)
|
||||
refDescriptions, err := s.gitserverClient.RefDescriptions(ctx, repo)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "gitserver.RefDescriptions")
|
||||
}
|
||||
|
||||
@ -17,7 +17,6 @@ go_library(
|
||||
deps = [
|
||||
"//internal/actor",
|
||||
"//internal/api",
|
||||
"//internal/authz",
|
||||
"//internal/codeintel/uploads/internal/lsifstore",
|
||||
"//internal/codeintel/uploads/internal/store",
|
||||
"//internal/codeintel/uploads/shared",
|
||||
|
||||
@ -18,7 +18,6 @@ import (
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/internal/actor"
|
||||
"github.com/sourcegraph/sourcegraph/internal/api"
|
||||
"github.com/sourcegraph/sourcegraph/internal/authz"
|
||||
"github.com/sourcegraph/sourcegraph/internal/codeintel/uploads/internal/lsifstore"
|
||||
"github.com/sourcegraph/sourcegraph/internal/codeintel/uploads/internal/store"
|
||||
uploadsshared "github.com/sourcegraph/sourcegraph/internal/codeintel/uploads/shared"
|
||||
@ -187,7 +186,7 @@ func createLogFields(upload uploadsshared.Upload) []attribute.KeyValue {
|
||||
// defaultBranchContains tells if the default branch contains the given commit ID.
|
||||
func (c *handler) defaultBranchContains(ctx context.Context, repo api.RepoName, commit string) (bool, error) {
|
||||
// Determine default branch name.
|
||||
descriptions, err := c.gitserverClient.RefDescriptions(ctx, authz.DefaultSubRepoPermsChecker, repo)
|
||||
descriptions, err := c.gitserverClient.RefDescriptions(ctx, repo)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
@ -202,7 +201,7 @@ func (c *handler) defaultBranchContains(ctx context.Context, repo api.RepoName,
|
||||
}
|
||||
|
||||
// Determine if branch contains commit.
|
||||
branches, err := c.gitserverClient.BranchesContaining(ctx, authz.DefaultSubRepoPermsChecker, repo, api.CommitID(commit))
|
||||
branches, err := c.gitserverClient.BranchesContaining(ctx, repo, api.CommitID(commit))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
@ -235,7 +234,7 @@ func (h *handler) HandleRawUpload(ctx context.Context, logger log.Logger, upload
|
||||
trace.AddEvent("TODO Domain Owner", attribute.Bool("defaultBranch", isDefaultBranch))
|
||||
|
||||
getChildren := func(ctx context.Context, dirnames []string) (map[string][]string, error) {
|
||||
directoryChildren, err := h.gitserverClient.ListDirectoryChildren(ctx, authz.DefaultSubRepoPermsChecker, repo.Name, api.CommitID(upload.Commit), dirnames)
|
||||
directoryChildren, err := h.gitserverClient.ListDirectoryChildren(ctx, repo.Name, api.CommitID(upload.Commit), dirnames)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "gitserverClient.DirectoryChildren")
|
||||
}
|
||||
@ -257,7 +256,7 @@ func (h *handler) HandleRawUpload(ctx context.Context, logger log.Logger, upload
|
||||
// database (if not already present). We need to have the commit data of every processed upload
|
||||
// for a repository when calculating the commit graph (triggered at the end of this handler).
|
||||
|
||||
_, commitDate, revisionExists, err := h.gitserverClient.CommitDate(ctx, authz.DefaultSubRepoPermsChecker, repo.Name, api.CommitID(upload.Commit))
|
||||
_, commitDate, revisionExists, err := h.gitserverClient.CommitDate(ctx, repo.Name, api.CommitID(upload.Commit))
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "gitserverClient.CommitDate")
|
||||
}
|
||||
|
||||
@ -17,7 +17,6 @@ go_library(
|
||||
importpath = "github.com/sourcegraph/sourcegraph/internal/compute",
|
||||
visibility = ["//:__subpackages__"],
|
||||
deps = [
|
||||
"//internal/authz",
|
||||
"//internal/comby",
|
||||
"//internal/gitserver",
|
||||
"//internal/lazyregexp",
|
||||
|
||||
@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/internal/authz"
|
||||
"github.com/sourcegraph/sourcegraph/internal/comby"
|
||||
"github.com/sourcegraph/sourcegraph/internal/gitserver"
|
||||
"github.com/sourcegraph/sourcegraph/internal/search/result"
|
||||
@ -52,7 +51,7 @@ func replace(ctx context.Context, content []byte, matchPattern MatchPattern, rep
|
||||
func (c *Replace) Run(ctx context.Context, gitserverClient gitserver.Client, r result.Match) (Result, error) {
|
||||
switch m := r.(type) {
|
||||
case *result.FileMatch:
|
||||
content, err := gitserverClient.ReadFile(ctx, authz.DefaultSubRepoPermsChecker, m.Repo.Name, m.CommitID, m.Path)
|
||||
content, err := gitserverClient.ReadFile(ctx, m.Repo.Name, m.CommitID, m.Path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@ -54,7 +54,7 @@ type TestClientSourceOptions struct {
|
||||
Logger log.Logger
|
||||
}
|
||||
|
||||
func NewTestClientSource(t *testing.T, addrs []string, options ...func(o *TestClientSourceOptions)) ClientSource {
|
||||
func NewTestClientSource(t testing.TB, addrs []string, options ...func(o *TestClientSourceOptions)) ClientSource {
|
||||
logger := logtest.Scoped(t)
|
||||
opts := TestClientSourceOptions{
|
||||
ClientFunc: func(conn *grpc.ClientConn) proto.GitserverServiceClient {
|
||||
|
||||
@ -13,6 +13,7 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
@ -27,6 +28,7 @@ import (
|
||||
"github.com/sourcegraph/conc/pool"
|
||||
"github.com/sourcegraph/go-diff/diff"
|
||||
sglog "github.com/sourcegraph/log"
|
||||
"github.com/sourcegraph/log/logtest"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/internal/actor"
|
||||
"github.com/sourcegraph/sourcegraph/internal/api"
|
||||
@ -95,36 +97,59 @@ func NewClient() Client {
|
||||
// Use the binary name for userAgent. This should effectively identify
|
||||
// which service is making the request (excluding requests proxied via the
|
||||
// frontend internal API)
|
||||
userAgent: filepath.Base(os.Args[0]),
|
||||
operations: getOperations(),
|
||||
clientSource: conns,
|
||||
userAgent: filepath.Base(os.Args[0]),
|
||||
operations: getOperations(),
|
||||
clientSource: conns,
|
||||
subRepoPermsChecker: authz.DefaultSubRepoPermsChecker,
|
||||
}
|
||||
}
|
||||
|
||||
// NewTestClient returns a test client that will use the given list of
|
||||
// addresses provided by the clientSource.
|
||||
func NewTestClient(cli httpcli.Doer, clientSource ClientSource) Client {
|
||||
logger := sglog.Scoped("NewTestClient", "Test New client")
|
||||
// NewTestClient returns a test client that will us
|
||||
func NewTestClient(t testing.TB) TestClient {
|
||||
logger := logtest.Scoped(t)
|
||||
|
||||
return &clientImplementor{
|
||||
logger: logger,
|
||||
httpClient: cli,
|
||||
httpClient: http.DefaultClient,
|
||||
HTTPLimiter: limiter.New(500),
|
||||
// Use the binary name for userAgent. This should effectively identify
|
||||
// which service is making the request (excluding requests proxied via the
|
||||
// frontend internal API)
|
||||
userAgent: filepath.Base(os.Args[0]),
|
||||
operations: newOperations(observation.ContextWithLogger(logger, &observation.TestContext)),
|
||||
clientSource: clientSource,
|
||||
userAgent: filepath.Base(os.Args[0]),
|
||||
operations: newOperations(observation.ContextWithLogger(logger, &observation.TestContext)),
|
||||
clientSource: NewTestClientSource(t, nil),
|
||||
subRepoPermsChecker: authz.DefaultSubRepoPermsChecker,
|
||||
}
|
||||
}
|
||||
|
||||
type TestClient interface {
|
||||
Client
|
||||
WithChecker(authz.SubRepoPermissionChecker) TestClient
|
||||
WithDoer(httpcli.Doer) TestClient
|
||||
WithClientSource(ClientSource) TestClient
|
||||
}
|
||||
|
||||
func (c *clientImplementor) WithChecker(checker authz.SubRepoPermissionChecker) TestClient {
|
||||
c.subRepoPermsChecker = checker
|
||||
return c
|
||||
}
|
||||
|
||||
func (c *clientImplementor) WithDoer(doer httpcli.Doer) TestClient {
|
||||
c.httpClient = doer
|
||||
return c
|
||||
}
|
||||
|
||||
func (c *clientImplementor) WithClientSource(cs ClientSource) TestClient {
|
||||
c.clientSource = cs
|
||||
return c
|
||||
}
|
||||
|
||||
// NewMockClientWithExecReader return new MockClient with provided mocked
|
||||
// behaviour of ExecReader function.
|
||||
func NewMockClientWithExecReader(execReader func(context.Context, api.RepoName, []string) (io.ReadCloser, error)) *MockClient {
|
||||
func NewMockClientWithExecReader(checker authz.SubRepoPermissionChecker, execReader func(context.Context, api.RepoName, []string) (io.ReadCloser, error)) *MockClient {
|
||||
client := NewMockClient()
|
||||
// NOTE: This hook is the same as DiffFunc, but with `execReader` used above
|
||||
client.DiffFunc.SetDefaultHook(func(ctx context.Context, checker authz.SubRepoPermissionChecker, opts DiffOptions) (*DiffFileIterator, error) {
|
||||
client.DiffFunc.SetDefaultHook(func(ctx context.Context, opts DiffOptions) (*DiffFileIterator, error) {
|
||||
if opts.Base == DevNullSHA {
|
||||
opts.RangeType = ".."
|
||||
} else if opts.RangeType != ".." {
|
||||
@ -158,7 +183,7 @@ func NewMockClientWithExecReader(execReader func(context.Context, api.RepoName,
|
||||
})
|
||||
|
||||
// NOTE: This hook is the same as DiffPath, but with `execReader` used above
|
||||
client.DiffPathFunc.SetDefaultHook(func(ctx context.Context, checker authz.SubRepoPermissionChecker, repo api.RepoName, sourceCommit, targetCommit, path string) ([]*diff.Hunk, error) {
|
||||
client.DiffPathFunc.SetDefaultHook(func(ctx context.Context, repo api.RepoName, sourceCommit, targetCommit, path string) ([]*diff.Hunk, error) {
|
||||
a := actor.FromContext(ctx)
|
||||
if hasAccess, err := authz.FilterActorPath(ctx, checker, a, repo, path); err != nil {
|
||||
return nil, err
|
||||
@ -210,6 +235,10 @@ type clientImplementor struct {
|
||||
|
||||
// clientSource is used to get the corresponding gprc client or address for a given repository
|
||||
clientSource ClientSource
|
||||
|
||||
// subRepoPermsChecker is sub-repository permissions checker. This will
|
||||
// usually be authz.DefaultSubRepoPermsChecker, at least until that global is removed.
|
||||
subRepoPermsChecker authz.SubRepoPermissionChecker
|
||||
}
|
||||
|
||||
type RawBatchLogResult struct {
|
||||
@ -236,7 +265,7 @@ type Client interface {
|
||||
AddrForRepo(ctx context.Context, repoName api.RepoName) string
|
||||
|
||||
// ArchiveReader streams back the file contents of an archived git repo.
|
||||
ArchiveReader(ctx context.Context, checker authz.SubRepoPermissionChecker, repo api.RepoName, options ArchiveOptions) (io.ReadCloser, error)
|
||||
ArchiveReader(ctx context.Context, repo api.RepoName, options ArchiveOptions) (io.ReadCloser, error)
|
||||
|
||||
// BatchLog invokes the given callback with the `git log` output for a batch of repository
|
||||
// and commit pairs. If the invoked callback returns a non-nil error, the operation will begin
|
||||
@ -244,9 +273,9 @@ type Client interface {
|
||||
BatchLog(ctx context.Context, opts BatchLogOptions, callback BatchLogCallback) error
|
||||
|
||||
// BlameFile returns Git blame information about a file.
|
||||
BlameFile(ctx context.Context, checker authz.SubRepoPermissionChecker, repo api.RepoName, path string, opt *BlameOptions) ([]*Hunk, error)
|
||||
BlameFile(ctx context.Context, repo api.RepoName, path string, opt *BlameOptions) ([]*Hunk, error)
|
||||
|
||||
StreamBlameFile(ctx context.Context, checker authz.SubRepoPermissionChecker, repo api.RepoName, path string, opt *BlameOptions) (HunkReader, error)
|
||||
StreamBlameFile(ctx context.Context, repo api.RepoName, path string, opt *BlameOptions) (HunkReader, error)
|
||||
|
||||
// CreateCommitFromPatch will attempt to create a commit from a patch
|
||||
// If possible, the error returned will be of type protocol.CreateCommitFromPatchError
|
||||
@ -265,7 +294,7 @@ type Client interface {
|
||||
|
||||
// HasCommitAfter indicates the staleness of a repository. It returns a boolean indicating if a repository
|
||||
// contains a commit past a specified date.
|
||||
HasCommitAfter(ctx context.Context, checker authz.SubRepoPermissionChecker, repo api.RepoName, date string, revspec string) (bool, error)
|
||||
HasCommitAfter(ctx context.Context, repo api.RepoName, date string, revspec string) (bool, error)
|
||||
|
||||
// IsRepoCloneable returns nil if the repository is cloneable.
|
||||
IsRepoCloneable(context.Context, api.RepoName) error
|
||||
@ -315,27 +344,27 @@ type Client interface {
|
||||
Search(_ context.Context, _ *protocol.SearchRequest, onMatches func([]protocol.CommitMatch)) (limitHit bool, _ error)
|
||||
|
||||
// Stat returns a FileInfo describing the named file at commit.
|
||||
Stat(ctx context.Context, checker authz.SubRepoPermissionChecker, repo api.RepoName, commit api.CommitID, path string) (fs.FileInfo, error)
|
||||
Stat(ctx context.Context, repo api.RepoName, commit api.CommitID, path string) (fs.FileInfo, error)
|
||||
|
||||
// DiffPath returns a position-ordered slice of changes (additions or deletions)
|
||||
// of the given path between the given source and target commits.
|
||||
DiffPath(ctx context.Context, checker authz.SubRepoPermissionChecker, repo api.RepoName, sourceCommit, targetCommit, path string) ([]*diff.Hunk, error)
|
||||
DiffPath(ctx context.Context, repo api.RepoName, sourceCommit, targetCommit, path string) ([]*diff.Hunk, error)
|
||||
|
||||
// ReadDir reads the contents of the named directory at commit.
|
||||
ReadDir(ctx context.Context, checker authz.SubRepoPermissionChecker, repo api.RepoName, commit api.CommitID, path string, recurse bool) ([]fs.FileInfo, error)
|
||||
ReadDir(ctx context.Context, repo api.RepoName, commit api.CommitID, path string, recurse bool) ([]fs.FileInfo, error)
|
||||
|
||||
// NewFileReader returns an io.ReadCloser reading from the named file at commit.
|
||||
// The caller should always close the reader after use.
|
||||
NewFileReader(ctx context.Context, checker authz.SubRepoPermissionChecker, repo api.RepoName, commit api.CommitID, name string) (io.ReadCloser, error)
|
||||
NewFileReader(ctx context.Context, repo api.RepoName, commit api.CommitID, name string) (io.ReadCloser, 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, checker authz.SubRepoPermissionChecker, repo api.RepoName, opt CommitsOptions) ([]*gitdomain.Commit, error)
|
||||
Commits(ctx context.Context, repo api.RepoName, opt CommitsOptions) ([]*gitdomain.Commit, error)
|
||||
|
||||
// FirstEverCommit returns the first commit ever made to the repository.
|
||||
FirstEverCommit(ctx context.Context, checker authz.SubRepoPermissionChecker, repo api.RepoName) (*gitdomain.Commit, error)
|
||||
FirstEverCommit(ctx context.Context, repo api.RepoName) (*gitdomain.Commit, error)
|
||||
|
||||
// ListTags returns a list of all tags in the repository. If commitObjs is non-empty, only all tags pointing at those commits are returned.
|
||||
ListTags(ctx context.Context, repo api.RepoName, commitObjs ...string) ([]*gitdomain.Tag, error)
|
||||
@ -343,43 +372,43 @@ type Client interface {
|
||||
// ListDirectoryChildren fetches the list of children under the given directory
|
||||
// names. The result is a map keyed by the directory names with the list of files
|
||||
// under each.
|
||||
ListDirectoryChildren(ctx context.Context, checker authz.SubRepoPermissionChecker, repo api.RepoName, commit api.CommitID, dirnames []string) (map[string][]string, error)
|
||||
ListDirectoryChildren(ctx context.Context, repo api.RepoName, commit api.CommitID, dirnames []string) (map[string][]string, error)
|
||||
|
||||
// Diff returns an iterator that can be used to access the diff between two
|
||||
// commits on a per-file basis. The iterator must be closed with Close when no
|
||||
// longer required.
|
||||
Diff(ctx context.Context, checker authz.SubRepoPermissionChecker, opts DiffOptions) (*DiffFileIterator, error)
|
||||
Diff(ctx context.Context, opts DiffOptions) (*DiffFileIterator, error)
|
||||
|
||||
// ReadFile returns the first maxBytes of the named file at commit. If maxBytes <= 0, the entire
|
||||
// file is read. (If you just need to check a file's existence, use Stat, not ReadFile.)
|
||||
ReadFile(ctx context.Context, checker authz.SubRepoPermissionChecker, repo api.RepoName, commit api.CommitID, name string) ([]byte, error)
|
||||
ReadFile(ctx context.Context, repo api.RepoName, commit api.CommitID, name string) ([]byte, error)
|
||||
|
||||
// BranchesContaining returns a map from branch names to branch tip hashes for
|
||||
// each branch containing the given commit.
|
||||
BranchesContaining(ctx context.Context, checker authz.SubRepoPermissionChecker, repo api.RepoName, commit api.CommitID) ([]string, error)
|
||||
BranchesContaining(ctx context.Context, repo api.RepoName, commit api.CommitID) ([]string, error)
|
||||
|
||||
// RefDescriptions returns a map from commits to descriptions of the tip of each
|
||||
// branch and tag of the given repository.
|
||||
RefDescriptions(ctx context.Context, checker authz.SubRepoPermissionChecker, repo api.RepoName, gitObjs ...string) (map[string][]gitdomain.RefDescription, error)
|
||||
RefDescriptions(ctx context.Context, repo api.RepoName, gitObjs ...string) (map[string][]gitdomain.RefDescription, error)
|
||||
|
||||
// CommitExists determines if the given commit exists in the given repository.
|
||||
CommitExists(ctx context.Context, checker authz.SubRepoPermissionChecker, repo api.RepoName, id api.CommitID) (bool, error)
|
||||
CommitExists(ctx context.Context, repo api.RepoName, id api.CommitID) (bool, error)
|
||||
|
||||
// CommitsExist determines if the given commits exists in the given repositories. This function returns
|
||||
// a slice of the same size as the input slice, true indicating that the commit at the symmetric index
|
||||
// exists.
|
||||
CommitsExist(ctx context.Context, checker authz.SubRepoPermissionChecker, repoCommits []api.RepoCommit) ([]bool, error)
|
||||
CommitsExist(ctx context.Context, repoCommits []api.RepoCommit) ([]bool, error)
|
||||
|
||||
// Head determines the tip commit of the default branch for the given repository.
|
||||
// If no HEAD revision exists for the given repository (which occurs with empty
|
||||
// repositories), a false-valued flag is returned along with a nil error and
|
||||
// empty revision.
|
||||
Head(ctx context.Context, checker authz.SubRepoPermissionChecker, repo api.RepoName) (string, bool, error)
|
||||
Head(ctx context.Context, repo api.RepoName) (string, bool, error)
|
||||
|
||||
// CommitDate returns the time that the given commit was committed. If the given
|
||||
// revision does not exist, a false-valued flag is returned along with a nil
|
||||
// error and zero-valued time.
|
||||
CommitDate(ctx context.Context, checker authz.SubRepoPermissionChecker, repo api.RepoName, commit api.CommitID) (string, time.Time, bool, error)
|
||||
CommitDate(ctx context.Context, repo api.RepoName, commit api.CommitID) (string, time.Time, bool, error)
|
||||
|
||||
// CommitGraph returns the commit graph for the given repository as a mapping
|
||||
// from a commit to its parents. If a commit is supplied, the returned graph will
|
||||
@ -395,10 +424,10 @@ type Client interface {
|
||||
// commits on {branchName} not also on the tip of the default branch. If the
|
||||
// supplied branch name is the default branch, then this method instead returns
|
||||
// all commits reachable from HEAD.
|
||||
CommitsUniqueToBranch(ctx context.Context, checker authz.SubRepoPermissionChecker, repo api.RepoName, branchName string, isDefaultBranch bool, maxAge *time.Time) (map[string]time.Time, error)
|
||||
CommitsUniqueToBranch(ctx context.Context, repo api.RepoName, branchName string, isDefaultBranch bool, maxAge *time.Time) (map[string]time.Time, error)
|
||||
|
||||
// LsFiles returns the output of `git ls-files`
|
||||
LsFiles(ctx context.Context, checker authz.SubRepoPermissionChecker, repo api.RepoName, commit api.CommitID, pathspecs ...gitdomain.Pathspec) ([]string, error)
|
||||
LsFiles(ctx context.Context, repo api.RepoName, commit api.CommitID, pathspecs ...gitdomain.Pathspec) ([]string, error)
|
||||
|
||||
// GetCommits returns a git commit object describing each of the given repository and commit pairs. This
|
||||
// function returns a slice of the same size as the input slice. Values in the output slice may be nil if
|
||||
@ -406,7 +435,7 @@ type Client interface {
|
||||
//
|
||||
// If ignoreErrors is true, then errors arising from any single failed git log operation will cause the
|
||||
// resulting commit to be nil, but not fail the entire operation.
|
||||
GetCommits(ctx context.Context, checker authz.SubRepoPermissionChecker, repoCommits []api.RepoCommit, ignoreErrors bool) ([]*gitdomain.Commit, error)
|
||||
GetCommits(ctx context.Context, repoCommits []api.RepoCommit, ignoreErrors bool) ([]*gitdomain.Commit, error)
|
||||
|
||||
// GetCommit returns the commit with the given commit ID, or ErrCommitNotFound if no such commit
|
||||
// exists.
|
||||
@ -414,7 +443,7 @@ type Client interface {
|
||||
// The remoteURLFunc is called to get the Git remote URL if it's not set in repo and if it is
|
||||
// needed. The Git remote URL is only required if the gitserver doesn't already contain a clone of
|
||||
// the repository or if the commit must be fetched from the remote.
|
||||
GetCommit(ctx context.Context, checker authz.SubRepoPermissionChecker, repo api.RepoName, id api.CommitID, opt ResolveRevisionOptions) (*gitdomain.Commit, error)
|
||||
GetCommit(ctx context.Context, repo api.RepoName, id api.CommitID, opt ResolveRevisionOptions) (*gitdomain.Commit, error)
|
||||
|
||||
// GetBehindAhead returns the behind/ahead commit counts information for right vs. left (both Git
|
||||
// revspecs).
|
||||
|
||||
@ -309,8 +309,8 @@ func TestClient_Remove(t *testing.T) {
|
||||
return cli
|
||||
}
|
||||
})
|
||||
cli := gitserver.NewTestClient(
|
||||
httpcli.DoerFunc(func(r *http.Request) (*http.Response, error) {
|
||||
cli := gitserver.NewTestClient(t).
|
||||
WithDoer(httpcli.DoerFunc(func(r *http.Request) (*http.Response, error) {
|
||||
switch r.URL.String() {
|
||||
// Ensure that the request was received by the "expected" gitserver instance - where
|
||||
// expected is the gitserver instance according to the Rendezvous hashing scheme.
|
||||
@ -323,10 +323,8 @@ func TestClient_Remove(t *testing.T) {
|
||||
default:
|
||||
return nil, errors.Newf("unexpected URL: %q", r.URL.String())
|
||||
}
|
||||
}),
|
||||
|
||||
source,
|
||||
)
|
||||
})).
|
||||
WithClientSource(source)
|
||||
|
||||
err := cli.Remove(context.Background(), repo)
|
||||
if err != nil {
|
||||
@ -416,7 +414,7 @@ func TestClient_BatchLogGRPC(t *testing.T) {
|
||||
}
|
||||
})
|
||||
|
||||
cli := gitserver.NewTestClient(&http.Client{}, source)
|
||||
cli := gitserver.NewTestClient(t).WithClientSource(source)
|
||||
|
||||
opts := gitserver.BatchLogOptions{
|
||||
RepoCommits: []api.RepoCommit{
|
||||
@ -499,8 +497,8 @@ func TestClient_BatchLog(t *testing.T) {
|
||||
}
|
||||
})
|
||||
|
||||
cli := gitserver.NewTestClient(
|
||||
httpcli.DoerFunc(func(r *http.Request) (*http.Response, error) {
|
||||
cli := gitserver.NewTestClient(t).
|
||||
WithDoer(httpcli.DoerFunc(func(r *http.Request) (*http.Response, error) {
|
||||
var req protocol.BatchLogRequest
|
||||
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
||||
return nil, err
|
||||
@ -518,9 +516,8 @@ func TestClient_BatchLog(t *testing.T) {
|
||||
encoded, _ := json.Marshal(protocol.BatchLogResponse{Results: results})
|
||||
body := io.NopCloser(strings.NewReader(strings.TrimSpace(string(encoded))))
|
||||
return &http.Response{StatusCode: 200, Body: body}, nil
|
||||
}),
|
||||
source,
|
||||
)
|
||||
})).
|
||||
WithClientSource(source)
|
||||
|
||||
opts := gitserver.BatchLogOptions{
|
||||
RepoCommits: []api.RepoCommit{
|
||||
@ -699,7 +696,7 @@ func TestClient_IsRepoCloneableGRPC(t *testing.T) {
|
||||
}
|
||||
})
|
||||
|
||||
client := gitserver.NewTestClient(http.DefaultClient, source)
|
||||
client := gitserver.NewTestClient(t).WithClientSource(source)
|
||||
|
||||
runTests(t, client, tc)
|
||||
if !called {
|
||||
@ -738,8 +735,8 @@ func TestClient_IsRepoCloneableGRPC(t *testing.T) {
|
||||
}
|
||||
})
|
||||
|
||||
client := gitserver.NewTestClient(
|
||||
httpcli.DoerFunc(func(r *http.Request) (*http.Response, error) {
|
||||
client := gitserver.NewTestClient(t).
|
||||
WithDoer(httpcli.DoerFunc(func(r *http.Request) (*http.Response, error) {
|
||||
switch r.URL.String() {
|
||||
case expected + "/is-repo-cloneable":
|
||||
encoded, _ := json.Marshal(tc.mockResponse)
|
||||
@ -751,9 +748,8 @@ func TestClient_IsRepoCloneableGRPC(t *testing.T) {
|
||||
default:
|
||||
return nil, errors.Newf("unexpected URL: %q", r.URL.String())
|
||||
}
|
||||
}),
|
||||
source,
|
||||
)
|
||||
})).
|
||||
WithClientSource(source)
|
||||
|
||||
runTests(t, client, tc)
|
||||
if called {
|
||||
@ -842,7 +838,7 @@ func TestClient_SystemsInfo(t *testing.T) {
|
||||
}
|
||||
})
|
||||
|
||||
client := gitserver.NewTestClient(http.DefaultClient, source)
|
||||
client := gitserver.NewTestClient(t).WithClientSource(source)
|
||||
|
||||
runTest(t, client)
|
||||
if !called {
|
||||
@ -875,8 +871,8 @@ func TestClient_SystemsInfo(t *testing.T) {
|
||||
}
|
||||
})
|
||||
|
||||
client := gitserver.NewTestClient(
|
||||
httpcli.DoerFunc(func(r *http.Request) (*http.Response, error) {
|
||||
client := gitserver.NewTestClient(t).
|
||||
WithDoer(httpcli.DoerFunc(func(r *http.Request) (*http.Response, error) {
|
||||
responseByAddress := make(map[string]*proto.DiskInfoResponse, len(expectedResponses))
|
||||
for _, response := range expectedResponses {
|
||||
responseByAddress[fmt.Sprintf("http://%s/disk-info", response.Address)] = &proto.DiskInfoResponse{
|
||||
@ -898,9 +894,8 @@ func TestClient_SystemsInfo(t *testing.T) {
|
||||
StatusCode: 200,
|
||||
Body: body,
|
||||
}, nil
|
||||
}),
|
||||
source,
|
||||
)
|
||||
})).
|
||||
WithClientSource(source)
|
||||
|
||||
runTest(t, client)
|
||||
if called {
|
||||
@ -950,7 +945,7 @@ func TestClient_SystemInfo(t *testing.T) {
|
||||
}
|
||||
})
|
||||
|
||||
client := gitserver.NewTestClient(http.DefaultClient, source)
|
||||
client := gitserver.NewTestClient(t).WithClientSource(source)
|
||||
|
||||
runTest(t, client, gitserverAddr)
|
||||
if !called {
|
||||
@ -984,8 +979,8 @@ func TestClient_SystemInfo(t *testing.T) {
|
||||
}
|
||||
})
|
||||
|
||||
client := gitserver.NewTestClient(
|
||||
httpcli.DoerFunc(func(r *http.Request) (*http.Response, error) {
|
||||
client := gitserver.NewTestClient(t).
|
||||
WithDoer(httpcli.DoerFunc(func(r *http.Request) (*http.Response, error) {
|
||||
switch r.URL.String() {
|
||||
case expected + "/disk-info":
|
||||
encoded, _ := json.Marshal(mockResponse)
|
||||
@ -997,9 +992,8 @@ func TestClient_SystemInfo(t *testing.T) {
|
||||
default:
|
||||
return nil, errors.Newf("unexpected URL: %q", r.URL.String())
|
||||
}
|
||||
}),
|
||||
source,
|
||||
)
|
||||
})).
|
||||
WithClientSource(source)
|
||||
|
||||
runTest(t, client, gitserverAddr)
|
||||
if called {
|
||||
|
||||
@ -60,7 +60,7 @@ type DiffOptions struct {
|
||||
// Diff returns an iterator that can be used to access the diff between two
|
||||
// commits on a per-file basis. The iterator must be closed with Close when no
|
||||
// longer required.
|
||||
func (c *clientImplementor) Diff(ctx context.Context, checker authz.SubRepoPermissionChecker, opts DiffOptions) (*DiffFileIterator, error) {
|
||||
func (c *clientImplementor) Diff(ctx context.Context, opts DiffOptions) (*DiffFileIterator, error) {
|
||||
// Rare case: the base is the empty tree, in which case we must use ..
|
||||
// instead of ... as the latter only works for commits.
|
||||
if opts.Base == DevNullSHA {
|
||||
@ -97,7 +97,7 @@ func (c *clientImplementor) Diff(ctx context.Context, checker authz.SubRepoPermi
|
||||
return &DiffFileIterator{
|
||||
rdr: rdr,
|
||||
mfdr: diff.NewMultiFileDiffReader(rdr),
|
||||
fileFilterFunc: getFilterFunc(ctx, checker, opts.Repo),
|
||||
fileFilterFunc: getFilterFunc(ctx, c.subRepoPermsChecker, opts.Repo),
|
||||
}, nil
|
||||
}
|
||||
|
||||
@ -363,9 +363,9 @@ func parseTimestamp(timestamp string) (time.Time, error) {
|
||||
// the root commit.
|
||||
const DevNullSHA = "4b825dc642cb6eb9a060e54bf8d69288fbee4904"
|
||||
|
||||
func (c *clientImplementor) DiffPath(ctx context.Context, checker authz.SubRepoPermissionChecker, repo api.RepoName, sourceCommit, targetCommit, path string) ([]*diff.Hunk, error) {
|
||||
func (c *clientImplementor) DiffPath(ctx context.Context, repo api.RepoName, sourceCommit, targetCommit, path string) ([]*diff.Hunk, error) {
|
||||
a := actor.FromContext(ctx)
|
||||
if hasAccess, err := authz.FilterActorPath(ctx, checker, a, repo, path); err != nil {
|
||||
if hasAccess, err := authz.FilterActorPath(ctx, c.subRepoPermsChecker, a, repo, path); err != nil {
|
||||
return nil, err
|
||||
} else if !hasAccess {
|
||||
return nil, os.ErrNotExist
|
||||
@ -399,7 +399,7 @@ func (c *clientImplementor) DiffSymbols(ctx context.Context, repo api.RepoName,
|
||||
}
|
||||
|
||||
// ReadDir reads the contents of the named directory at commit.
|
||||
func (c *clientImplementor) ReadDir(ctx context.Context, checker authz.SubRepoPermissionChecker, repo api.RepoName, commit api.CommitID, path string, recurse bool) (_ []fs.FileInfo, err error) {
|
||||
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{Attrs: []attribute.KeyValue{
|
||||
repo.Attr(),
|
||||
commit.Attr(),
|
||||
@ -419,12 +419,12 @@ func (c *clientImplementor) ReadDir(ctx context.Context, checker authz.SubRepoPe
|
||||
}
|
||||
files, err := c.lsTree(ctx, repo, commit, path, recurse)
|
||||
|
||||
if err != nil || !authz.SubRepoEnabled(checker) {
|
||||
if err != nil || !authz.SubRepoEnabled(c.subRepoPermsChecker) {
|
||||
return files, err
|
||||
}
|
||||
|
||||
a := actor.FromContext(ctx)
|
||||
filtered, filteringErr := authz.FilterActorFileInfos(ctx, checker, a, repo, files)
|
||||
filtered, filteringErr := authz.FilterActorFileInfos(ctx, c.subRepoPermsChecker, a, repo, files)
|
||||
if filteringErr != nil {
|
||||
return nil, errors.Wrap(err, "filtering paths")
|
||||
} else {
|
||||
@ -490,7 +490,7 @@ func (oid objectInfo) OID() gitdomain.OID { return gitdomain.OID(oid) }
|
||||
// lStat returns a FileInfo describing the named file at commit. If the file is a
|
||||
// symbolic link, the returned FileInfo describes the symbolic link. lStat makes
|
||||
// no attempt to follow the link.
|
||||
func (c *clientImplementor) lStat(ctx context.Context, checker authz.SubRepoPermissionChecker, repo api.RepoName, commit api.CommitID, path string) (_ fs.FileInfo, err error) {
|
||||
func (c *clientImplementor) lStat(ctx context.Context, repo api.RepoName, commit api.CommitID, path string) (_ fs.FileInfo, err error) {
|
||||
ctx, _, endObservation := c.operations.lstat.With(ctx, &err, observation.Args{Attrs: []attribute.KeyValue{
|
||||
commit.Attr(),
|
||||
attribute.String("path", path),
|
||||
@ -520,12 +520,12 @@ func (c *clientImplementor) lStat(ctx context.Context, checker authz.SubRepoPerm
|
||||
return nil, &os.PathError{Op: "ls-tree", Path: path, Err: os.ErrNotExist}
|
||||
}
|
||||
|
||||
if !authz.SubRepoEnabled(checker) {
|
||||
if !authz.SubRepoEnabled(c.subRepoPermsChecker) {
|
||||
return fis[0], nil
|
||||
}
|
||||
// Applying sub-repo permissions
|
||||
a := actor.FromContext(ctx)
|
||||
include, filteringErr := authz.FilterActorFileInfo(ctx, checker, a, repo, fis[0])
|
||||
include, filteringErr := authz.FilterActorFileInfo(ctx, c.subRepoPermsChecker, a, repo, fis[0])
|
||||
if include && filteringErr == nil {
|
||||
return fis[0], nil
|
||||
} else {
|
||||
@ -749,7 +749,7 @@ type Hunk struct {
|
||||
}
|
||||
|
||||
// StreamBlameFile returns Git blame information about a file.
|
||||
func (c *clientImplementor) StreamBlameFile(ctx context.Context, checker authz.SubRepoPermissionChecker, repo api.RepoName, path string, opt *BlameOptions) (_ HunkReader, err error) {
|
||||
func (c *clientImplementor) StreamBlameFile(ctx context.Context, repo api.RepoName, path string, opt *BlameOptions) (_ HunkReader, err error) {
|
||||
ctx, _, endObservation := c.operations.streamBlameFile.With(ctx, &err, observation.Args{
|
||||
Attrs: append([]attribute.KeyValue{
|
||||
repo.Attr(),
|
||||
@ -758,7 +758,7 @@ func (c *clientImplementor) StreamBlameFile(ctx context.Context, checker authz.S
|
||||
})
|
||||
defer endObservation(1, observation.Args{})
|
||||
|
||||
return streamBlameFileCmd(ctx, checker, repo, path, opt, c.gitserverGitCommandFunc(repo))
|
||||
return streamBlameFileCmd(ctx, c.subRepoPermsChecker, repo, path, opt, c.gitserverGitCommandFunc(repo))
|
||||
}
|
||||
|
||||
type errUnauthorizedStreamBlame struct {
|
||||
@ -804,7 +804,7 @@ func streamBlameFileCmd(ctx context.Context, checker authz.SubRepoPermissionChec
|
||||
}
|
||||
|
||||
// BlameFile returns Git blame information about a file.
|
||||
func (c *clientImplementor) BlameFile(ctx context.Context, checker authz.SubRepoPermissionChecker, repo api.RepoName, path string, opt *BlameOptions) (_ []*Hunk, err error) {
|
||||
func (c *clientImplementor) BlameFile(ctx context.Context, repo api.RepoName, path string, opt *BlameOptions) (_ []*Hunk, err error) {
|
||||
ctx, _, endObservation := c.operations.blameFile.With(ctx, &err, observation.Args{
|
||||
Attrs: append([]attribute.KeyValue{
|
||||
repo.Attr(),
|
||||
@ -813,7 +813,7 @@ func (c *clientImplementor) BlameFile(ctx context.Context, checker authz.SubRepo
|
||||
})
|
||||
defer endObservation(1, observation.Args{})
|
||||
|
||||
return blameFileCmd(ctx, checker, c.gitserverGitCommandFunc(repo), path, opt, repo)
|
||||
return blameFileCmd(ctx, c.subRepoPermsChecker, c.gitserverGitCommandFunc(repo), path, opt, repo)
|
||||
}
|
||||
|
||||
func blameFileCmd(ctx context.Context, checker authz.SubRepoPermissionChecker, command gitCommandFunc, path string, opt *BlameOptions, repo api.RepoName) ([]*Hunk, error) {
|
||||
@ -1043,7 +1043,7 @@ func runRevParse(ctx context.Context, cmd GitCommand, spec string) (api.CommitID
|
||||
}
|
||||
|
||||
// LsFiles returns the output of `git ls-files`.
|
||||
func (c *clientImplementor) LsFiles(ctx context.Context, checker authz.SubRepoPermissionChecker, repo api.RepoName, commit api.CommitID, pathspecs ...gitdomain.Pathspec) ([]string, error) {
|
||||
func (c *clientImplementor) LsFiles(ctx context.Context, repo api.RepoName, commit api.CommitID, pathspecs ...gitdomain.Pathspec) ([]string, error) {
|
||||
args := []string{
|
||||
"ls-files",
|
||||
"-z",
|
||||
@ -1069,7 +1069,7 @@ func (c *clientImplementor) LsFiles(ctx context.Context, checker authz.SubRepoPe
|
||||
if len(files) > 0 && files[len(files)-1] == "" {
|
||||
files = files[:len(files)-1]
|
||||
}
|
||||
return filterPaths(ctx, checker, repo, files)
|
||||
return filterPaths(ctx, c.subRepoPermsChecker, repo, files)
|
||||
}
|
||||
|
||||
// 🚨 SECURITY: All git methods that deal with file or path access need to have
|
||||
@ -1091,7 +1091,6 @@ func filterPaths(ctx context.Context, checker authz.SubRepoPermissionChecker, re
|
||||
// under each.
|
||||
func (c *clientImplementor) ListDirectoryChildren(
|
||||
ctx context.Context,
|
||||
checker authz.SubRepoPermissionChecker,
|
||||
repo api.RepoName,
|
||||
commit api.CommitID,
|
||||
dirnames []string,
|
||||
@ -1106,8 +1105,8 @@ func (c *clientImplementor) ListDirectoryChildren(
|
||||
}
|
||||
|
||||
paths := strings.Split(string(out), "\n")
|
||||
if authz.SubRepoEnabled(checker) {
|
||||
paths, err = authz.FilterActorPaths(ctx, checker, actor.FromContext(ctx), repo, paths)
|
||||
if authz.SubRepoEnabled(c.subRepoPermsChecker) {
|
||||
paths, err = authz.FilterActorPaths(ctx, c.subRepoPermsChecker, actor.FromContext(ctx), repo, paths)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -1341,7 +1340,7 @@ func (c *clientImplementor) GetBehindAhead(ctx context.Context, repo api.RepoNam
|
||||
|
||||
// ReadFile returns the first maxBytes of the named file at commit. If maxBytes <= 0, the entire
|
||||
// file is read. (If you just need to check a file's existence, use Stat, not ReadFile.)
|
||||
func (c *clientImplementor) ReadFile(ctx context.Context, checker authz.SubRepoPermissionChecker, repo api.RepoName, commit api.CommitID, name string) (_ []byte, err error) {
|
||||
func (c *clientImplementor) ReadFile(ctx context.Context, repo api.RepoName, commit api.CommitID, name string) (_ []byte, err error) {
|
||||
ctx, _, endObservation := c.operations.readFile.With(ctx, &err, observation.Args{Attrs: []attribute.KeyValue{
|
||||
repo.Attr(),
|
||||
commit.Attr(),
|
||||
@ -1349,7 +1348,7 @@ func (c *clientImplementor) ReadFile(ctx context.Context, checker authz.SubRepoP
|
||||
}})
|
||||
defer endObservation(1, observation.Args{})
|
||||
|
||||
br, err := c.NewFileReader(ctx, checker, repo, commit, name)
|
||||
br, err := c.NewFileReader(ctx, repo, commit, name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -1365,7 +1364,7 @@ func (c *clientImplementor) ReadFile(ctx context.Context, checker authz.SubRepoP
|
||||
|
||||
// NewFileReader returns an io.ReadCloser reading from the named file at commit.
|
||||
// The caller should always close the reader after use
|
||||
func (c *clientImplementor) NewFileReader(ctx context.Context, checker authz.SubRepoPermissionChecker, repo api.RepoName, commit api.CommitID, name string) (_ io.ReadCloser, err error) {
|
||||
func (c *clientImplementor) NewFileReader(ctx context.Context, repo api.RepoName, commit api.CommitID, name string) (_ io.ReadCloser, err error) {
|
||||
// TODO: this does not capture the lifetime of the request since we return a reader
|
||||
ctx, _, endObservation := c.operations.newFileReader.With(ctx, &err, observation.Args{Attrs: []attribute.KeyValue{
|
||||
repo.Attr(),
|
||||
@ -1375,7 +1374,7 @@ func (c *clientImplementor) NewFileReader(ctx context.Context, checker authz.Sub
|
||||
defer endObservation(1, observation.Args{})
|
||||
|
||||
a := actor.FromContext(ctx)
|
||||
if hasAccess, err := authz.FilterActorPath(ctx, checker, a, repo, name); err != nil {
|
||||
if hasAccess, err := authz.FilterActorPath(ctx, c.subRepoPermsChecker, a, repo, name); err != nil {
|
||||
return nil, err
|
||||
} else if !hasAccess {
|
||||
return nil, os.ErrNotExist
|
||||
@ -1491,7 +1490,7 @@ func (br *blobReader) convertError(err error) error {
|
||||
}
|
||||
if strings.Contains(err.Error(), "fatal: bad object ") {
|
||||
// Could be a git submodule.
|
||||
fi, err := br.c.Stat(br.ctx, authz.DefaultSubRepoPermsChecker, br.repo, br.commit, br.name)
|
||||
fi, err := br.c.Stat(br.ctx, br.repo, br.commit, br.name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -1504,7 +1503,7 @@ func (br *blobReader) convertError(err error) error {
|
||||
}
|
||||
|
||||
// Stat returns a FileInfo describing the named file at commit.
|
||||
func (c *clientImplementor) Stat(ctx context.Context, checker authz.SubRepoPermissionChecker, repo api.RepoName, commit api.CommitID, path string) (_ fs.FileInfo, err error) {
|
||||
func (c *clientImplementor) Stat(ctx context.Context, repo api.RepoName, commit api.CommitID, path string) (_ fs.FileInfo, err error) {
|
||||
ctx, _, endObservation := c.operations.stat.With(ctx, &err, observation.Args{Attrs: []attribute.KeyValue{
|
||||
commit.Attr(),
|
||||
attribute.String("path", path),
|
||||
@ -1517,7 +1516,7 @@ func (c *clientImplementor) Stat(ctx context.Context, checker authz.SubRepoPermi
|
||||
|
||||
path = rel(path)
|
||||
|
||||
fi, err := c.lStat(ctx, checker, repo, commit, path)
|
||||
fi, err := c.lStat(ctx, repo, commit, path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -1555,7 +1554,7 @@ type CommitsOptions struct {
|
||||
var recordGetCommitQueries = os.Getenv("RECORD_GET_COMMIT_QUERIES") == "1"
|
||||
|
||||
// getCommit returns the commit with the given id.
|
||||
func (c *clientImplementor) getCommit(ctx context.Context, checker authz.SubRepoPermissionChecker, repo api.RepoName, id api.CommitID, opt ResolveRevisionOptions) (_ *gitdomain.Commit, err error) {
|
||||
func (c *clientImplementor) getCommit(ctx context.Context, repo api.RepoName, id api.CommitID, opt ResolveRevisionOptions) (_ *gitdomain.Commit, err error) {
|
||||
if honey.Enabled() && recordGetCommitQueries {
|
||||
defer func() {
|
||||
ev := honey.NewEvent("getCommit")
|
||||
@ -1585,9 +1584,9 @@ func (c *clientImplementor) getCommit(ctx context.Context, checker authz.SubRepo
|
||||
N: 1,
|
||||
NoEnsureRevision: opt.NoEnsureRevision,
|
||||
}
|
||||
commitOptions = addNameOnly(commitOptions, checker)
|
||||
commitOptions = addNameOnly(commitOptions, c.subRepoPermsChecker)
|
||||
|
||||
commits, err := c.commitLog(ctx, repo, commitOptions, checker)
|
||||
commits, err := c.commitLog(ctx, repo, commitOptions)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -1608,7 +1607,7 @@ func (c *clientImplementor) getCommit(ctx context.Context, checker authz.SubRepo
|
||||
// The remoteURLFunc is called to get the Git remote URL if it's not set in repo and if it is
|
||||
// needed. The Git remote URL is only required if the gitserver doesn't already contain a clone of
|
||||
// the repository or if the commit must be fetched from the remote.
|
||||
func (c *clientImplementor) GetCommit(ctx context.Context, checker authz.SubRepoPermissionChecker, repo api.RepoName, id api.CommitID, opt ResolveRevisionOptions) (_ *gitdomain.Commit, err error) {
|
||||
func (c *clientImplementor) GetCommit(ctx context.Context, repo api.RepoName, id api.CommitID, opt ResolveRevisionOptions) (_ *gitdomain.Commit, err error) {
|
||||
ctx, _, endObservation := c.operations.getCommit.With(ctx, &err, observation.Args{Attrs: []attribute.KeyValue{
|
||||
repo.Attr(),
|
||||
id.Attr(),
|
||||
@ -1616,12 +1615,12 @@ func (c *clientImplementor) GetCommit(ctx context.Context, checker authz.SubRepo
|
||||
}})
|
||||
defer endObservation(1, observation.Args{})
|
||||
|
||||
return c.getCommit(ctx, checker, repo, id, opt)
|
||||
return c.getCommit(ctx, repo, id, opt)
|
||||
}
|
||||
|
||||
// Commits returns all commits matching the options.
|
||||
func (c *clientImplementor) Commits(ctx context.Context, checker authz.SubRepoPermissionChecker, repo api.RepoName, opt CommitsOptions) (_ []*gitdomain.Commit, err error) {
|
||||
opt = addNameOnly(opt, checker)
|
||||
func (c *clientImplementor) Commits(ctx context.Context, repo api.RepoName, opt CommitsOptions) (_ []*gitdomain.Commit, err error) {
|
||||
opt = addNameOnly(opt, c.subRepoPermsChecker)
|
||||
ctx, _, endObservation := c.operations.commits.With(ctx, &err, observation.Args{Attrs: []attribute.KeyValue{
|
||||
repo.Attr(),
|
||||
attribute.String("opts", fmt.Sprintf("%#v", opt)),
|
||||
@ -1631,7 +1630,7 @@ func (c *clientImplementor) Commits(ctx context.Context, checker authz.SubRepoPe
|
||||
if err := checkSpecArgSafety(opt.Range); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return c.commitLog(ctx, repo, opt, checker)
|
||||
return c.commitLog(ctx, repo, opt)
|
||||
}
|
||||
|
||||
func filterCommits(ctx context.Context, checker authz.SubRepoPermissionChecker, commits []*wrappedCommit, repoName api.RepoName) ([]*gitdomain.Commit, error) {
|
||||
@ -1679,7 +1678,7 @@ func hasAccessToCommit(ctx context.Context, commit *wrappedCommit, repoName api.
|
||||
// commits on {branchName} not also on the tip of the default branch. If the
|
||||
// supplied branch name is the default branch, then this method instead returns
|
||||
// all commits reachable from HEAD.
|
||||
func (c *clientImplementor) CommitsUniqueToBranch(ctx context.Context, checker authz.SubRepoPermissionChecker, repo api.RepoName, branchName string, isDefaultBranch bool, maxAge *time.Time) (_ map[string]time.Time, err error) {
|
||||
func (c *clientImplementor) CommitsUniqueToBranch(ctx context.Context, repo api.RepoName, branchName string, isDefaultBranch bool, maxAge *time.Time) (_ map[string]time.Time, err error) {
|
||||
args := []string{"log", "--pretty=format:%H:%cI"}
|
||||
if maxAge != nil {
|
||||
args = append(args, fmt.Sprintf("--after=%s", *maxAge))
|
||||
@ -1697,16 +1696,16 @@ func (c *clientImplementor) CommitsUniqueToBranch(ctx context.Context, checker a
|
||||
}
|
||||
|
||||
commits, err := parseCommitsUniqueToBranch(strings.Split(string(out), "\n"))
|
||||
if authz.SubRepoEnabled(checker) && err == nil {
|
||||
return c.filterCommitsUniqueToBranch(ctx, repo, commits, checker), nil
|
||||
if authz.SubRepoEnabled(c.subRepoPermsChecker) && err == nil {
|
||||
return c.filterCommitsUniqueToBranch(ctx, repo, commits), nil
|
||||
}
|
||||
return commits, err
|
||||
}
|
||||
|
||||
func (c *clientImplementor) filterCommitsUniqueToBranch(ctx context.Context, repo api.RepoName, commitsMap map[string]time.Time, checker authz.SubRepoPermissionChecker) map[string]time.Time {
|
||||
func (c *clientImplementor) filterCommitsUniqueToBranch(ctx context.Context, repo api.RepoName, commitsMap map[string]time.Time) map[string]time.Time {
|
||||
filtered := make(map[string]time.Time, len(commitsMap))
|
||||
for commitID, timeStamp := range commitsMap {
|
||||
if _, err := c.GetCommit(ctx, checker, repo, api.CommitID(commitID), ResolveRevisionOptions{}); !errors.HasType(err, &gitdomain.RevisionNotFoundError{}) {
|
||||
if _, err := c.GetCommit(ctx, repo, api.CommitID(commitID), ResolveRevisionOptions{}); !errors.HasType(err, &gitdomain.RevisionNotFoundError{}) {
|
||||
filtered[commitID] = timeStamp
|
||||
}
|
||||
}
|
||||
@ -1739,7 +1738,7 @@ func parseCommitsUniqueToBranch(lines []string) (_ map[string]time.Time, err err
|
||||
|
||||
// HasCommitAfter indicates the staleness of a repository. It returns a boolean indicating if a repository
|
||||
// contains a commit past a specified date.
|
||||
func (c *clientImplementor) HasCommitAfter(ctx context.Context, checker authz.SubRepoPermissionChecker, repo api.RepoName, date string, revspec string) (_ bool, err error) {
|
||||
func (c *clientImplementor) HasCommitAfter(ctx context.Context, repo api.RepoName, date string, revspec string) (_ bool, err error) {
|
||||
ctx, _, endObservation := c.operations.hasCommitAfter.With(ctx, &err, observation.Args{Attrs: []attribute.KeyValue{
|
||||
repo.Attr(),
|
||||
attribute.String("date", date),
|
||||
@ -1747,8 +1746,8 @@ func (c *clientImplementor) HasCommitAfter(ctx context.Context, checker authz.Su
|
||||
}})
|
||||
defer endObservation(1, observation.Args{})
|
||||
|
||||
if authz.SubRepoEnabled(checker) {
|
||||
return c.hasCommitAfterWithFiltering(ctx, repo, date, revspec, checker)
|
||||
if authz.SubRepoEnabled(c.subRepoPermsChecker) {
|
||||
return c.hasCommitAfterWithFiltering(ctx, repo, date, revspec)
|
||||
}
|
||||
|
||||
if revspec == "" {
|
||||
@ -1780,8 +1779,8 @@ func (c *clientImplementor) HasCommitAfter(ctx context.Context, checker authz.Su
|
||||
return n > 0, err
|
||||
}
|
||||
|
||||
func (c *clientImplementor) hasCommitAfterWithFiltering(ctx context.Context, repo api.RepoName, date, revspec string, checker authz.SubRepoPermissionChecker) (bool, error) {
|
||||
if commits, err := c.Commits(ctx, checker, repo, CommitsOptions{After: date, Range: revspec}); err != nil {
|
||||
func (c *clientImplementor) hasCommitAfterWithFiltering(ctx context.Context, repo api.RepoName, date, revspec string) (bool, error) {
|
||||
if commits, err := c.Commits(ctx, repo, CommitsOptions{After: date, Range: revspec}); err != nil {
|
||||
return false, err
|
||||
} else if len(commits) > 0 {
|
||||
return true, nil
|
||||
@ -1796,19 +1795,19 @@ func isBadObjectErr(output, obj string) bool {
|
||||
// commitLog returns a list of commits.
|
||||
//
|
||||
// The caller is responsible for doing checkSpecArgSafety on opt.Head and opt.Base.
|
||||
func (c *clientImplementor) commitLog(ctx context.Context, repo api.RepoName, opt CommitsOptions, checker authz.SubRepoPermissionChecker) ([]*gitdomain.Commit, error) {
|
||||
func (c *clientImplementor) commitLog(ctx context.Context, repo api.RepoName, opt CommitsOptions) ([]*gitdomain.Commit, error) {
|
||||
wrappedCommits, err := c.getWrappedCommits(ctx, repo, opt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
filtered, err := filterCommits(ctx, checker, wrappedCommits, repo)
|
||||
filtered, err := filterCommits(ctx, c.subRepoPermsChecker, wrappedCommits, repo)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "filtering commits")
|
||||
}
|
||||
|
||||
if needMoreCommits(filtered, wrappedCommits, opt, checker) {
|
||||
return c.getMoreCommits(ctx, repo, opt, checker, filtered)
|
||||
if needMoreCommits(filtered, wrappedCommits, opt, c.subRepoPermsChecker) {
|
||||
return c.getMoreCommits(ctx, repo, opt, filtered)
|
||||
}
|
||||
return filtered, err
|
||||
}
|
||||
@ -1851,7 +1850,7 @@ func isRequestForSingleCommit(opt CommitsOptions) bool {
|
||||
// filtering, fewer than that requested number was left. This function requests the next N commits (where N was the number
|
||||
// originally requested), filters the commits, and determines if this is at least N commits total after filtering. If not,
|
||||
// the loop continues until N total filtered commits are collected _or_ there are no commits left to request.
|
||||
func (c *clientImplementor) getMoreCommits(ctx context.Context, repo api.RepoName, opt CommitsOptions, checker authz.SubRepoPermissionChecker, baselineCommits []*gitdomain.Commit) ([]*gitdomain.Commit, error) {
|
||||
func (c *clientImplementor) getMoreCommits(ctx context.Context, repo api.RepoName, opt CommitsOptions, baselineCommits []*gitdomain.Commit) ([]*gitdomain.Commit, error) {
|
||||
// We want to place an upper bound on the number of times we loop here so that we
|
||||
// don't hit pathological conditions where a lot of filtering has been applied.
|
||||
const maxIterations = 5
|
||||
@ -1867,7 +1866,7 @@ func (c *clientImplementor) getMoreCommits(ctx context.Context, repo api.RepoNam
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
filtered, err := filterCommits(ctx, checker, wrappedCommits, repo)
|
||||
filtered, err := filterCommits(ctx, c.subRepoPermsChecker, wrappedCommits, repo)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -1982,7 +1981,7 @@ func commitLogArgs(initialArgs []string, opt CommitsOptions) (args []string, err
|
||||
}
|
||||
|
||||
// FirstEverCommit returns the first commit ever made to the repository.
|
||||
func (c *clientImplementor) FirstEverCommit(ctx context.Context, checker authz.SubRepoPermissionChecker, repo api.RepoName) (_ *gitdomain.Commit, err error) {
|
||||
func (c *clientImplementor) FirstEverCommit(ctx context.Context, repo api.RepoName) (_ *gitdomain.Commit, err error) {
|
||||
ctx, _, endObservation := c.operations.firstEverCommit.With(ctx, &err, observation.Args{Attrs: []attribute.KeyValue{
|
||||
repo.Attr(),
|
||||
}})
|
||||
@ -2001,12 +2000,12 @@ func (c *clientImplementor) FirstEverCommit(ctx context.Context, checker authz.S
|
||||
}
|
||||
first := tokens[0]
|
||||
id := api.CommitID(bytes.TrimSpace(first))
|
||||
return c.GetCommit(ctx, checker, repo, id, ResolveRevisionOptions{NoEnsureRevision: true})
|
||||
return c.GetCommit(ctx, repo, id, ResolveRevisionOptions{NoEnsureRevision: true})
|
||||
}
|
||||
|
||||
// CommitExists determines if the given commit exists in the given repository.
|
||||
func (c *clientImplementor) CommitExists(ctx context.Context, checker authz.SubRepoPermissionChecker, repo api.RepoName, id api.CommitID) (bool, error) {
|
||||
commit, err := c.getCommit(ctx, checker, repo, id, ResolveRevisionOptions{NoEnsureRevision: true})
|
||||
func (c *clientImplementor) CommitExists(ctx context.Context, repo api.RepoName, id api.CommitID) (bool, error) {
|
||||
commit, err := c.getCommit(ctx, repo, id, ResolveRevisionOptions{NoEnsureRevision: true})
|
||||
if errors.HasType(err, &gitdomain.RevisionNotFoundError{}) {
|
||||
return false, nil
|
||||
}
|
||||
@ -2019,8 +2018,8 @@ func (c *clientImplementor) CommitExists(ctx context.Context, checker authz.SubR
|
||||
// CommitsExist determines if the given commits exists in the given repositories. This function returns
|
||||
// a slice of the same size as the input slice, true indicating that the commit at the symmetric index
|
||||
// exists.
|
||||
func (c *clientImplementor) CommitsExist(ctx context.Context, checker authz.SubRepoPermissionChecker, repoCommits []api.RepoCommit) ([]bool, error) {
|
||||
commits, err := c.GetCommits(ctx, checker, repoCommits, true)
|
||||
func (c *clientImplementor) CommitsExist(ctx context.Context, repoCommits []api.RepoCommit) ([]bool, error) {
|
||||
commits, err := c.GetCommits(ctx, repoCommits, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -2039,7 +2038,7 @@ func (c *clientImplementor) CommitsExist(ctx context.Context, checker authz.SubR
|
||||
//
|
||||
// If ignoreErrors is true, then errors arising from any single failed git log operation will cause the
|
||||
// resulting commit to be nil, but not fail the entire operation.
|
||||
func (c *clientImplementor) GetCommits(ctx context.Context, checker authz.SubRepoPermissionChecker, repoCommits []api.RepoCommit, ignoreErrors bool) (_ []*gitdomain.Commit, err error) {
|
||||
func (c *clientImplementor) GetCommits(ctx context.Context, repoCommits []api.RepoCommit, ignoreErrors bool) (_ []*gitdomain.Commit, err error) {
|
||||
ctx, _, endObservation := c.operations.getCommits.With(ctx, &err, observation.Args{Attrs: []attribute.KeyValue{
|
||||
attribute.Int("numRepoCommits", len(repoCommits)),
|
||||
attribute.Bool("ignoreErrors", ignoreErrors),
|
||||
@ -2095,7 +2094,7 @@ func (c *clientImplementor) GetCommits(ctx context.Context, checker authz.SubRep
|
||||
}
|
||||
|
||||
// Enforce sub-repository permissions
|
||||
filteredCommits, err := filterCommits(ctx, checker, wrappedCommits, repoCommit.Repo)
|
||||
filteredCommits, err := filterCommits(ctx, c.subRepoPermsChecker, wrappedCommits, repoCommit.Repo)
|
||||
if err != nil {
|
||||
// Note that we don't check ignoreErrors on this condition. When we
|
||||
// ignore errors it's to hide an issue with a single git log request on a
|
||||
@ -2133,7 +2132,7 @@ func (c *clientImplementor) GetCommits(ctx context.Context, checker authz.SubRep
|
||||
// If no HEAD revision exists for the given repository (which occurs with empty
|
||||
// repositories), a false-valued flag is returned along with a nil error and
|
||||
// empty revision.
|
||||
func (c *clientImplementor) Head(ctx context.Context, checker authz.SubRepoPermissionChecker, repo api.RepoName) (_ string, revisionExists bool, err error) {
|
||||
func (c *clientImplementor) Head(ctx context.Context, repo api.RepoName) (_ string, revisionExists bool, err error) {
|
||||
cmd := c.gitCommand(repo, "rev-parse", "HEAD")
|
||||
|
||||
out, err := cmd.Output(ctx)
|
||||
@ -2141,8 +2140,8 @@ func (c *clientImplementor) Head(ctx context.Context, checker authz.SubRepoPermi
|
||||
return checkError(err)
|
||||
}
|
||||
commitID := string(out)
|
||||
if authz.SubRepoEnabled(checker) {
|
||||
if _, err := c.GetCommit(ctx, checker, repo, api.CommitID(commitID), ResolveRevisionOptions{}); err != nil {
|
||||
if authz.SubRepoEnabled(c.subRepoPermsChecker) {
|
||||
if _, err := c.GetCommit(ctx, repo, api.CommitID(commitID), ResolveRevisionOptions{}); err != nil {
|
||||
return checkError(err)
|
||||
}
|
||||
}
|
||||
@ -2244,10 +2243,10 @@ func parseCommitFileNames(partsPerCommit int, parts [][]byte) ([]string, []byte)
|
||||
|
||||
// BranchesContaining returns a map from branch names to branch tip hashes for
|
||||
// each branch containing the given commit.
|
||||
func (c *clientImplementor) BranchesContaining(ctx context.Context, checker authz.SubRepoPermissionChecker, repo api.RepoName, commit api.CommitID) ([]string, error) {
|
||||
if authz.SubRepoEnabled(checker) {
|
||||
func (c *clientImplementor) BranchesContaining(ctx context.Context, repo api.RepoName, commit api.CommitID) ([]string, error) {
|
||||
if authz.SubRepoEnabled(c.subRepoPermsChecker) {
|
||||
// GetCommit to validate that the user has permissions to access it.
|
||||
if _, err := c.GetCommit(ctx, checker, repo, commit, ResolveRevisionOptions{}); err != nil {
|
||||
if _, err := c.GetCommit(ctx, repo, commit, ResolveRevisionOptions{}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
@ -2280,7 +2279,7 @@ func parseBranchesContaining(lines []string) []string {
|
||||
|
||||
// RefDescriptions returns a map from commits to descriptions of the tip of each
|
||||
// branch and tag of the given repository.
|
||||
func (c *clientImplementor) RefDescriptions(ctx context.Context, checker authz.SubRepoPermissionChecker, repo api.RepoName, gitObjs ...string) (map[string][]gitdomain.RefDescription, error) {
|
||||
func (c *clientImplementor) RefDescriptions(ctx context.Context, repo api.RepoName, gitObjs ...string) (map[string][]gitdomain.RefDescription, error) {
|
||||
f := func(refPrefix string) (map[string][]gitdomain.RefDescription, error) {
|
||||
format := strings.Join([]string{
|
||||
derefField("objectname"),
|
||||
@ -2317,8 +2316,8 @@ func (c *clientImplementor) RefDescriptions(ctx context.Context, checker authz.S
|
||||
}
|
||||
}
|
||||
|
||||
if authz.SubRepoEnabled(checker) {
|
||||
return c.filterRefDescriptions(ctx, repo, aggregate, checker), nil
|
||||
if authz.SubRepoEnabled(c.subRepoPermsChecker) {
|
||||
return c.filterRefDescriptions(ctx, repo, aggregate), nil
|
||||
}
|
||||
return aggregate, nil
|
||||
}
|
||||
@ -2330,11 +2329,10 @@ func derefField(field string) string {
|
||||
func (c *clientImplementor) filterRefDescriptions(ctx context.Context,
|
||||
repo api.RepoName,
|
||||
refDescriptions map[string][]gitdomain.RefDescription,
|
||||
checker authz.SubRepoPermissionChecker,
|
||||
) map[string][]gitdomain.RefDescription {
|
||||
filtered := make(map[string][]gitdomain.RefDescription, len(refDescriptions))
|
||||
for commitID, descriptions := range refDescriptions {
|
||||
if _, err := c.GetCommit(ctx, checker, repo, api.CommitID(commitID), ResolveRevisionOptions{}); !errors.HasType(err, &gitdomain.RevisionNotFoundError{}) {
|
||||
if _, err := c.GetCommit(ctx, repo, api.CommitID(commitID), ResolveRevisionOptions{}); !errors.HasType(err, &gitdomain.RevisionNotFoundError{}) {
|
||||
filtered[commitID] = descriptions
|
||||
}
|
||||
}
|
||||
@ -2422,10 +2420,10 @@ lineLoop:
|
||||
// CommitDate returns the time that the given commit was committed. If the given
|
||||
// revision does not exist, a false-valued flag is returned along with a nil
|
||||
// error and zero-valued time.
|
||||
func (c *clientImplementor) CommitDate(ctx context.Context, checker authz.SubRepoPermissionChecker, repo api.RepoName, commit api.CommitID) (_ string, _ time.Time, revisionExists bool, err error) {
|
||||
if authz.SubRepoEnabled(checker) {
|
||||
func (c *clientImplementor) CommitDate(ctx context.Context, repo api.RepoName, commit api.CommitID) (_ string, _ time.Time, revisionExists bool, err error) {
|
||||
if authz.SubRepoEnabled(c.subRepoPermsChecker) {
|
||||
// GetCommit to validate that the user has permissions to access it.
|
||||
if _, err := c.GetCommit(ctx, checker, repo, commit, ResolveRevisionOptions{}); err != nil {
|
||||
if _, err := c.GetCommit(ctx, repo, commit, ResolveRevisionOptions{}); err != nil {
|
||||
return "", time.Time{}, false, nil
|
||||
}
|
||||
}
|
||||
@ -2472,7 +2470,6 @@ const (
|
||||
// ArchiveReader streams back the file contents of an archived git repo.
|
||||
func (c *clientImplementor) ArchiveReader(
|
||||
ctx context.Context,
|
||||
checker authz.SubRepoPermissionChecker,
|
||||
repo api.RepoName,
|
||||
options ArchiveOptions,
|
||||
) (_ io.ReadCloser, err error) {
|
||||
@ -2485,8 +2482,8 @@ func (c *clientImplementor) ArchiveReader(
|
||||
})
|
||||
defer endObservation(1, observation.Args{})
|
||||
|
||||
if authz.SubRepoEnabled(checker) {
|
||||
if enabled, err := authz.SubRepoEnabledForRepo(ctx, checker, repo); err != nil {
|
||||
if authz.SubRepoEnabled(c.subRepoPermsChecker) {
|
||||
if enabled, err := authz.SubRepoEnabledForRepo(ctx, c.subRepoPermsChecker, repo); err != nil {
|
||||
return nil, errors.Wrap(err, "sub-repo permissions check:")
|
||||
} else if enabled {
|
||||
return nil, errors.New("archiveReader invoked for a repo with sub-repo permissions")
|
||||
@ -2724,7 +2721,7 @@ func (c *clientImplementor) ListBranches(ctx context.Context, repo api.RepoName,
|
||||
|
||||
branch := &gitdomain.Branch{Name: name, Head: ref.CommitID}
|
||||
if opt.IncludeCommit {
|
||||
branch.Commit, err = c.GetCommit(ctx, authz.DefaultSubRepoPermsChecker, repo, ref.CommitID, ResolveRevisionOptions{})
|
||||
branch.Commit, err = c.GetCommit(ctx, repo, ref.CommitID, ResolveRevisionOptions{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@ -149,8 +149,8 @@ func TestDiffWithSubRepoFiltering(t *testing.T) {
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.label, func(t *testing.T) {
|
||||
repo := MakeGitRepository(t, append(cmds, tc.extraGitCommands...)...)
|
||||
c := NewClient()
|
||||
commits, err := c.Commits(ctx, nil, repo, CommitsOptions{})
|
||||
c := NewTestClient(t)
|
||||
commits, err := c.Commits(ctx, repo, CommitsOptions{})
|
||||
if err != nil {
|
||||
t.Fatalf("err fetching commits: %s", err)
|
||||
}
|
||||
@ -160,7 +160,8 @@ func TestDiffWithSubRepoFiltering(t *testing.T) {
|
||||
baseCommit = commits[len(commits)-1]
|
||||
}
|
||||
|
||||
iter, err := c.Diff(ctx, checker, DiffOptions{Base: string(baseCommit.ID), Head: string(headCommit.ID), Repo: repo})
|
||||
c = c.WithChecker(checker)
|
||||
iter, err := c.Diff(ctx, DiffOptions{Base: string(baseCommit.ID), Head: string(headCommit.ID), Repo: repo})
|
||||
if err != nil {
|
||||
t.Fatalf("error fetching diff: %s", err)
|
||||
}
|
||||
@ -203,7 +204,7 @@ func TestDiff(t *testing.T) {
|
||||
".foo",
|
||||
} {
|
||||
t.Run("invalid base: "+input, func(t *testing.T) {
|
||||
i, err := NewClient().Diff(ctx, nil, DiffOptions{Base: input})
|
||||
i, err := NewClient().Diff(ctx, DiffOptions{Base: input})
|
||||
if i != nil {
|
||||
t.Errorf("unexpected non-nil iterator: %+v", i)
|
||||
}
|
||||
@ -222,23 +223,23 @@ func TestDiff(t *testing.T) {
|
||||
{opts: DiffOptions{Base: "foo", Head: "bar"}, want: "foo...bar"},
|
||||
} {
|
||||
t.Run("rangeSpec: "+tc.want, func(t *testing.T) {
|
||||
c := NewMockClientWithExecReader(func(_ context.Context, _ api.RepoName, args []string) (io.ReadCloser, error) {
|
||||
c := NewMockClientWithExecReader(nil, func(_ context.Context, _ api.RepoName, args []string) (io.ReadCloser, error) {
|
||||
// The range spec is the sixth argument.
|
||||
if args[5] != tc.want {
|
||||
t.Errorf("unexpected rangeSpec: have: %s; want: %s", args[5], tc.want)
|
||||
}
|
||||
return nil, nil
|
||||
})
|
||||
_, _ = c.Diff(ctx, nil, tc.opts)
|
||||
_, _ = c.Diff(ctx, tc.opts)
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("ExecReader error", func(t *testing.T) {
|
||||
c := NewMockClientWithExecReader(func(_ context.Context, _ api.RepoName, args []string) (io.ReadCloser, error) {
|
||||
c := NewMockClientWithExecReader(nil, func(_ context.Context, _ api.RepoName, args []string) (io.ReadCloser, error) {
|
||||
return nil, errors.New("ExecReader error")
|
||||
})
|
||||
i, err := c.Diff(ctx, nil, DiffOptions{Base: "foo", Head: "bar"})
|
||||
i, err := c.Diff(ctx, DiffOptions{Base: "foo", Head: "bar"})
|
||||
if i != nil {
|
||||
t.Errorf("unexpected non-nil iterator: %+v", i)
|
||||
}
|
||||
@ -313,11 +314,11 @@ index 9bd8209..d2acfa9 100644
|
||||
"README.md",
|
||||
}
|
||||
|
||||
c := NewMockClientWithExecReader(func(_ context.Context, _ api.RepoName, args []string) (io.ReadCloser, error) {
|
||||
c := NewMockClientWithExecReader(nil, func(_ context.Context, _ api.RepoName, args []string) (io.ReadCloser, error) {
|
||||
return io.NopCloser(strings.NewReader(testDiff)), nil
|
||||
})
|
||||
|
||||
i, err := c.Diff(ctx, nil, DiffOptions{Base: "foo", Head: "bar"})
|
||||
i, err := c.Diff(ctx, DiffOptions{Base: "foo", Head: "bar"})
|
||||
if i == nil {
|
||||
t.Error("unexpected nil iterator")
|
||||
}
|
||||
@ -357,14 +358,14 @@ index 51a59ef1c..493090958 100644
|
||||
+this is my file contnent
|
||||
`
|
||||
t.Run("basic", func(t *testing.T) {
|
||||
c := NewMockClientWithExecReader(func(_ context.Context, _ api.RepoName, args []string) (io.ReadCloser, error) {
|
||||
checker := authz.NewMockSubRepoPermissionChecker()
|
||||
c := NewMockClientWithExecReader(checker, func(_ context.Context, _ api.RepoName, args []string) (io.ReadCloser, error) {
|
||||
return io.NopCloser(strings.NewReader(testDiff)), nil
|
||||
})
|
||||
checker := authz.NewMockSubRepoPermissionChecker()
|
||||
ctx := actor.WithActor(context.Background(), &actor.Actor{
|
||||
UID: 1,
|
||||
})
|
||||
hunks, err := c.DiffPath(ctx, checker, "", "sourceCommit", "", "file")
|
||||
hunks, err := c.DiffPath(ctx, "", "sourceCommit", "", "file")
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %s", err)
|
||||
}
|
||||
@ -373,9 +374,6 @@ index 51a59ef1c..493090958 100644
|
||||
}
|
||||
})
|
||||
t.Run("with sub-repo permissions enabled", func(t *testing.T) {
|
||||
c := NewMockClientWithExecReader(func(_ context.Context, _ api.RepoName, args []string) (io.ReadCloser, error) {
|
||||
return io.NopCloser(strings.NewReader(testDiff)), nil
|
||||
})
|
||||
checker := authz.NewMockSubRepoPermissionChecker()
|
||||
ctx := actor.WithActor(context.Background(), &actor.Actor{
|
||||
UID: 1,
|
||||
@ -392,7 +390,10 @@ index 51a59ef1c..493090958 100644
|
||||
return authz.Read, nil
|
||||
})
|
||||
usePermissionsForFilePermissionsFunc(checker)
|
||||
hunks, err := c.DiffPath(ctx, checker, "", "sourceCommit", "", fileName)
|
||||
c := NewMockClientWithExecReader(checker, func(_ context.Context, _ api.RepoName, args []string) (io.ReadCloser, error) {
|
||||
return io.NopCloser(strings.NewReader(testDiff)), nil
|
||||
})
|
||||
hunks, err := c.DiffPath(ctx, "", "sourceCommit", "", fileName)
|
||||
if !os.IsNotExist(err) {
|
||||
t.Errorf("unexpected error: %s", err)
|
||||
}
|
||||
@ -496,7 +497,8 @@ func runBlameFileTest(ctx context.Context, t *testing.T, repo api.RepoName, path
|
||||
checker authz.SubRepoPermissionChecker, label string, wantHunks []*Hunk,
|
||||
) {
|
||||
t.Helper()
|
||||
hunks, err := NewClient().BlameFile(ctx, checker, repo, path, opt)
|
||||
client := NewTestClient(t).WithChecker(checker)
|
||||
hunks, err := client.BlameFile(ctx, repo, path, opt)
|
||||
if err != nil {
|
||||
t.Errorf("%s: BlameFile(%s, %+v): %s", label, path, opt, err)
|
||||
return
|
||||
@ -638,9 +640,9 @@ func TestRepository_ResolveTag_error(t *testing.T) {
|
||||
func TestLsFiles(t *testing.T) {
|
||||
ClientMocks.LocalGitserver = true
|
||||
defer ResetClientMocks()
|
||||
client := NewClient()
|
||||
runFileListingTest(t, func(ctx context.Context, checker authz.SubRepoPermissionChecker, repo api.RepoName, commit string) ([]string, error) {
|
||||
return client.LsFiles(ctx, checker, repo, api.CommitID(commit))
|
||||
client := NewTestClient(t).WithChecker(checker)
|
||||
return client.LsFiles(ctx, repo, api.CommitID(commit))
|
||||
})
|
||||
}
|
||||
|
||||
@ -781,7 +783,6 @@ func TestCleanDirectoriesForLsTree(t *testing.T) {
|
||||
func TestListDirectoryChildren(t *testing.T) {
|
||||
ClientMocks.LocalGitserver = true
|
||||
defer ResetClientMocks()
|
||||
client := NewClient()
|
||||
gitCommands := []string{
|
||||
"mkdir -p dir{1..3}/sub{1..3}",
|
||||
"touch dir1/sub1/file",
|
||||
@ -803,9 +804,10 @@ func TestListDirectoryChildren(t *testing.T) {
|
||||
checker.EnabledFunc.SetDefaultHook(func() bool {
|
||||
return false
|
||||
})
|
||||
client1 := NewTestClient(t).WithChecker(checker)
|
||||
|
||||
dirnames := []string{"dir1/", "dir2/", "dir3/"}
|
||||
children, err := client.ListDirectoryChildren(ctx, checker, repo, "HEAD", dirnames)
|
||||
children, err := client1.ListDirectoryChildren(ctx, repo, "HEAD", dirnames)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -829,10 +831,11 @@ func TestListDirectoryChildren(t *testing.T) {
|
||||
return authz.None, nil
|
||||
})
|
||||
usePermissionsForFilePermissionsFunc(checker)
|
||||
client2 := NewTestClient(t).WithChecker(checker)
|
||||
ctx = actor.WithActor(ctx, &actor.Actor{
|
||||
UID: 1,
|
||||
})
|
||||
children, err = client.ListDirectoryChildren(ctx, checker, repo, "HEAD", dirnames)
|
||||
children, err = client2.ListDirectoryChildren(ctx, repo, "HEAD", dirnames)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -1023,7 +1026,7 @@ func TestRepository_FileSystem_Symlinks(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
// file1 should be a file.
|
||||
file1Info, err := client.Stat(ctx, authz.DefaultSubRepoPermsChecker, repo, commitID, "file1")
|
||||
file1Info, err := client.Stat(ctx, repo, commitID, "file1")
|
||||
if err != nil {
|
||||
t.Fatalf("fs.Stat(file1): %s", err)
|
||||
}
|
||||
@ -1043,7 +1046,7 @@ func TestRepository_FileSystem_Symlinks(t *testing.T) {
|
||||
|
||||
// Check symlinks are links
|
||||
for symlink := range symlinks {
|
||||
fi, err := client.Stat(ctx, authz.DefaultSubRepoPermsChecker, repo, commitID, symlink)
|
||||
fi, err := client.Stat(ctx, repo, commitID, symlink)
|
||||
if err != nil {
|
||||
t.Fatalf("fs.Stat(%s): %s", symlink, err)
|
||||
}
|
||||
@ -1055,7 +1058,7 @@ func TestRepository_FileSystem_Symlinks(t *testing.T) {
|
||||
|
||||
// Also check the FileInfo returned by ReadDir to ensure it's
|
||||
// consistent with the FileInfo returned by lStat.
|
||||
entries, err := client.ReadDir(ctx, authz.DefaultSubRepoPermsChecker, repo, commitID, ".", false)
|
||||
entries, err := client.ReadDir(ctx, repo, commitID, ".", false)
|
||||
if err != nil {
|
||||
t.Fatalf("fs.ReadDir(.): %s", err)
|
||||
}
|
||||
@ -1073,7 +1076,7 @@ func TestRepository_FileSystem_Symlinks(t *testing.T) {
|
||||
}
|
||||
|
||||
for symlink, size := range symlinks {
|
||||
fi, err := client.Stat(ctx, authz.DefaultSubRepoPermsChecker, repo, commitID, symlink)
|
||||
fi, err := client.Stat(ctx, repo, commitID, symlink)
|
||||
if err != nil {
|
||||
t.Fatalf("fs.Stat(%s): %s", symlink, err)
|
||||
}
|
||||
@ -1102,19 +1105,18 @@ func TestStat(t *testing.T) {
|
||||
|
||||
dir := InitGitRepository(t, gitCommands...)
|
||||
repo := api.RepoName(filepath.Base(dir))
|
||||
client := NewClient()
|
||||
|
||||
commitID := api.CommitID(ComputeCommitHash(dir, true))
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
checker := authz.NewMockSubRepoPermissionChecker()
|
||||
// Start disabled
|
||||
checker.EnabledFunc.SetDefaultHook(func() bool {
|
||||
return false
|
||||
})
|
||||
client := NewTestClient(t).WithChecker(checker)
|
||||
|
||||
fileInfo, err := client.Stat(ctx, checker, repo, commitID, "dir1/file1")
|
||||
commitID := api.CommitID(ComputeCommitHash(dir, true))
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
fileInfo, err := client.Stat(ctx, repo, commitID, "dir1/file1")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -1123,6 +1125,10 @@ func TestStat(t *testing.T) {
|
||||
t.Fatal(diff)
|
||||
}
|
||||
|
||||
ctx = actor.WithActor(ctx, &actor.Actor{
|
||||
UID: 1,
|
||||
})
|
||||
|
||||
// With filtering
|
||||
checker.EnabledFunc.SetDefaultHook(func() bool {
|
||||
return true
|
||||
@ -1134,11 +1140,7 @@ func TestStat(t *testing.T) {
|
||||
return authz.None, nil
|
||||
})
|
||||
usePermissionsForFilePermissionsFunc(checker)
|
||||
ctx = actor.WithActor(ctx, &actor.Actor{
|
||||
UID: 1,
|
||||
})
|
||||
|
||||
_, err = client.Stat(ctx, checker, repo, commitID, "dir1/file1")
|
||||
_, err = client.Stat(ctx, repo, commitID, "dir1/file1")
|
||||
if err == nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -1182,10 +1184,11 @@ func TestRepository_GetCommit(t *testing.T) {
|
||||
revisionNotFoundError bool
|
||||
}
|
||||
|
||||
client := NewClient()
|
||||
runGetCommitTests := func(checker authz.SubRepoPermissionChecker, tests map[string]testCase) {
|
||||
for label, test := range tests {
|
||||
t.Run(label, func(t *testing.T) {
|
||||
client := NewTestClient(t).WithChecker(checker)
|
||||
|
||||
testRepo := MakeGitRepository(t, test.gitCmds...)
|
||||
var noEnsureRevision bool
|
||||
t.Cleanup(func() {
|
||||
@ -1200,7 +1203,7 @@ func TestRepository_GetCommit(t *testing.T) {
|
||||
resolveRevisionOptions := ResolveRevisionOptions{
|
||||
NoEnsureRevision: test.noEnsureRevision,
|
||||
}
|
||||
commit, err := client.GetCommit(ctx, checker, testRepo, test.id, resolveRevisionOptions)
|
||||
commit, err := client.GetCommit(ctx, testRepo, test.id, resolveRevisionOptions)
|
||||
if err != nil {
|
||||
if test.revisionNotFoundError {
|
||||
if !errors.HasType(err, &gitdomain.RevisionNotFoundError{}) {
|
||||
@ -1217,7 +1220,7 @@ func TestRepository_GetCommit(t *testing.T) {
|
||||
}
|
||||
|
||||
// Test that trying to get a nonexistent commit returns RevisionNotFoundError.
|
||||
if _, err := client.GetCommit(ctx, checker, testRepo, NonExistentCommitID, resolveRevisionOptions); !errors.HasType(err, &gitdomain.RevisionNotFoundError{}) {
|
||||
if _, err := client.GetCommit(ctx, testRepo, NonExistentCommitID, resolveRevisionOptions); !errors.HasType(err, &gitdomain.RevisionNotFoundError{}) {
|
||||
t.Errorf("%s: for nonexistent commit: got err %v, want RevisionNotFoundError", label, err)
|
||||
}
|
||||
|
||||
@ -1351,8 +1354,8 @@ func TestRepository_HasCommitAfter(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
client := NewClient()
|
||||
t.Run("basic", func(t *testing.T) {
|
||||
client := NewClient()
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.label, func(t *testing.T) {
|
||||
gitCommands := make([]string, len(tc.commitDates))
|
||||
@ -1360,7 +1363,7 @@ func TestRepository_HasCommitAfter(t *testing.T) {
|
||||
gitCommands[i] = fmt.Sprintf("GIT_COMMITTER_NAME=a GIT_COMMITTER_EMAIL=a@a.com GIT_COMMITTER_DATE=%s git commit --allow-empty -m foo --author='a <a@a.com>'", date)
|
||||
}
|
||||
repo := MakeGitRepository(t, gitCommands...)
|
||||
got, err := client.HasCommitAfter(ctx, nil, repo, tc.after, tc.revspec)
|
||||
got, err := client.HasCommitAfter(ctx, repo, tc.after, tc.revspec)
|
||||
if err != nil || got != tc.want {
|
||||
t.Errorf("got %t hascommitafter, want %t", got, tc.want)
|
||||
}
|
||||
@ -1379,8 +1382,9 @@ func TestRepository_HasCommitAfter(t *testing.T) {
|
||||
}
|
||||
// Case where user can't view commit 2, but can view commits 0 and 1. In each test case the result should match the case where no sub-repo perms enabled
|
||||
checker := getTestSubRepoPermsChecker("file2")
|
||||
client := NewTestClient(t).WithChecker(checker)
|
||||
repo := MakeGitRepository(t, gitCommands...)
|
||||
got, err := client.HasCommitAfter(ctx, checker, repo, tc.after, tc.revspec)
|
||||
got, err := client.HasCommitAfter(ctx, repo, tc.after, tc.revspec)
|
||||
if err != nil {
|
||||
t.Errorf("got error: %s", err)
|
||||
}
|
||||
@ -1390,7 +1394,8 @@ func TestRepository_HasCommitAfter(t *testing.T) {
|
||||
|
||||
// Case where user can't view commit 1 or commit 2, which will mean in some cases since HasCommitAfter will be false due to those commits not being visible.
|
||||
checker = getTestSubRepoPermsChecker("file1", "file2")
|
||||
got, err = client.HasCommitAfter(ctx, checker, repo, tc.after, tc.revspec)
|
||||
client = NewTestClient(t).WithChecker(checker)
|
||||
got, err = client.HasCommitAfter(ctx, repo, tc.after, tc.revspec)
|
||||
if err != nil {
|
||||
t.Errorf("got error: %s", err)
|
||||
}
|
||||
@ -1439,7 +1444,7 @@ func TestRepository_FirstEverCommit(t *testing.T) {
|
||||
}
|
||||
|
||||
repo := MakeGitRepository(t, gitCommands...)
|
||||
gotCommit, err := client.FirstEverCommit(ctx, nil, repo)
|
||||
gotCommit, err := client.FirstEverCommit(ctx, repo)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -1453,7 +1458,7 @@ func TestRepository_FirstEverCommit(t *testing.T) {
|
||||
// Added for awareness if this error message changes. Insights skip over empty repos and check against error message
|
||||
t.Run("empty repo", func(t *testing.T) {
|
||||
repo := MakeGitRepository(t)
|
||||
_, err := client.FirstEverCommit(ctx, nil, repo)
|
||||
_, err := client.FirstEverCommit(ctx, repo)
|
||||
wantErr := `git command [rev-list --reverse --date-order --max-parents=0 HEAD] failed (output: ""): exit status 128`
|
||||
if err.Error() != wantErr {
|
||||
t.Errorf("expected :%s, got :%s", wantErr, err)
|
||||
@ -1461,8 +1466,8 @@ func TestRepository_FirstEverCommit(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("with sub-repo permissions", func(t *testing.T) {
|
||||
checkerWithoutAccessFirstCommit := getTestSubRepoPermsChecker("file0")
|
||||
checkerWithAccessFirstCommit := getTestSubRepoPermsChecker("file1")
|
||||
clientWithoutAccessFirstCommit := NewTestClient(t).WithChecker(getTestSubRepoPermsChecker("file0"))
|
||||
clientWithAccessFirstCommit := NewTestClient(t).WithChecker(getTestSubRepoPermsChecker("file1"))
|
||||
for _, tc := range testCases {
|
||||
gitCommands := make([]string, 0, len(tc.commitDates))
|
||||
for i, date := range tc.commitDates {
|
||||
@ -1473,13 +1478,14 @@ func TestRepository_FirstEverCommit(t *testing.T) {
|
||||
}
|
||||
|
||||
repo := MakeGitRepository(t, gitCommands...)
|
||||
|
||||
// Try to get first commit when user doesn't have permission to view
|
||||
_, err := client.FirstEverCommit(ctx, checkerWithoutAccessFirstCommit, repo)
|
||||
_, err := clientWithoutAccessFirstCommit.FirstEverCommit(ctx, repo)
|
||||
if !errors.HasType(err, &gitdomain.RevisionNotFoundError{}) {
|
||||
t.Errorf("expected a RevisionNotFoundError since the user does not have access to view this commit, got :%s", err)
|
||||
}
|
||||
// Try to get first commit when user does have permission to view, should succeed
|
||||
gotCommit, err := client.FirstEverCommit(ctx, checkerWithAccessFirstCommit, repo)
|
||||
gotCommit, err := clientWithAccessFirstCommit.FirstEverCommit(ctx, repo)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -1492,7 +1498,7 @@ func TestRepository_FirstEverCommit(t *testing.T) {
|
||||
UID: 1,
|
||||
Internal: true,
|
||||
})
|
||||
gotCommit, err = client.FirstEverCommit(newCtx, checkerWithoutAccessFirstCommit, repo)
|
||||
gotCommit, err = clientWithoutAccessFirstCommit.FirstEverCommit(newCtx, repo)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -1510,12 +1516,12 @@ func TestCommitExists(t *testing.T) {
|
||||
ctx := actor.WithActor(context.Background(), &actor.Actor{
|
||||
UID: 1,
|
||||
})
|
||||
client := NewClient()
|
||||
testCommitExists := func(label string, gitCommands []string, commitID, nonExistentCommitID api.CommitID, checker authz.SubRepoPermissionChecker) {
|
||||
t.Run(label, func(t *testing.T) {
|
||||
client := NewTestClient(t).WithChecker(checker)
|
||||
repo := MakeGitRepository(t, gitCommands...)
|
||||
|
||||
exists, err := client.CommitExists(ctx, checker, repo, commitID)
|
||||
exists, err := client.CommitExists(ctx, repo, commitID)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -1523,7 +1529,7 @@ func TestCommitExists(t *testing.T) {
|
||||
t.Fatal("Should exist")
|
||||
}
|
||||
|
||||
exists, err = client.CommitExists(ctx, checker, repo, nonExistentCommitID)
|
||||
exists, err = client.CommitExists(ctx, repo, nonExistentCommitID)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -1594,7 +1600,7 @@ func TestRepository_Commits(t *testing.T) {
|
||||
testCommits(ctx, label, test.repo, CommitsOptions{Range: string(test.id)}, checker, test.wantCommits, t)
|
||||
|
||||
// Test that trying to get a nonexistent commit returns RevisionNotFoundError.
|
||||
if _, err := client.Commits(ctx, nil, test.repo, CommitsOptions{Range: string(NonExistentCommitID)}); !errors.HasType(err, &gitdomain.RevisionNotFoundError{}) {
|
||||
if _, err := client.Commits(ctx, test.repo, CommitsOptions{Range: string(NonExistentCommitID)}); !errors.HasType(err, &gitdomain.RevisionNotFoundError{}) {
|
||||
t.Errorf("%s: for nonexistent commit: got err %v, want RevisionNotFoundError", label, err)
|
||||
}
|
||||
})
|
||||
@ -1679,7 +1685,8 @@ func TestCommits_SubRepoPerms(t *testing.T) {
|
||||
for label, test := range tests {
|
||||
t.Run(label, func(t *testing.T) {
|
||||
checker := getTestSubRepoPermsChecker(test.noAccessPaths...)
|
||||
commits, err := NewClient().Commits(ctx, checker, repo, test.opt)
|
||||
client := NewTestClient(t).WithChecker(checker)
|
||||
commits, err := client.Commits(ctx, repo, test.opt)
|
||||
if err != nil {
|
||||
t.Errorf("%s: Commits(): %s", label, err)
|
||||
return
|
||||
@ -1771,11 +1778,11 @@ func TestCommits_SubRepoPerms_ReturnNCommits(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
client := NewClient()
|
||||
for label, test := range tests {
|
||||
t.Run(label, func(t *testing.T) {
|
||||
checker := getTestSubRepoPermsChecker(test.noAccessPaths...)
|
||||
commits, err := client.Commits(ctx, checker, test.repo, test.opt)
|
||||
client := NewTestClient(t).WithChecker(checker)
|
||||
commits, err := client.Commits(ctx, test.repo, test.opt)
|
||||
if err != nil {
|
||||
t.Errorf("%s: Commits(): %s", label, err)
|
||||
return
|
||||
@ -1868,7 +1875,8 @@ func TestRepository_Commits_options(t *testing.T) {
|
||||
repo := MakeGitRepository(t)
|
||||
before := ""
|
||||
after := time.Date(2022, 11, 11, 12, 10, 0, 4, time.UTC).Format(time.RFC3339)
|
||||
_, err := NewClient().Commits(ctx, checker, repo, CommitsOptions{N: 0, DateOrder: true, NoEnsureRevision: true, After: after, Before: before})
|
||||
client := NewTestClient(t).WithChecker(checker)
|
||||
_, err := client.Commits(ctx, repo, CommitsOptions{N: 0, DateOrder: true, NoEnsureRevision: true, After: after, Before: before})
|
||||
if err == nil {
|
||||
t.Error("expected error, got nil")
|
||||
}
|
||||
@ -2170,8 +2178,8 @@ func TestFilterRefDescriptions(t *testing.T) { // KEEP
|
||||
}
|
||||
|
||||
checker := getTestSubRepoPermsChecker("file3")
|
||||
client := NewClient().(*clientImplementor)
|
||||
filtered := client.filterRefDescriptions(ctx, repo, refDescriptions, checker)
|
||||
client := NewTestClient(t).WithChecker(checker).(*clientImplementor)
|
||||
filtered := client.filterRefDescriptions(ctx, repo, refDescriptions)
|
||||
expectedRefDescriptions := map[string][]gitdomain.RefDescription{
|
||||
"d38233a79e037d2ab8170b0d0bc0aa438473e6da": {},
|
||||
"2ba4dd2b9a27ec125fea7d72e12b9824ead18631": {},
|
||||
@ -2200,7 +2208,7 @@ func TestRefDescriptions(t *testing.T) { // KEEP
|
||||
}
|
||||
|
||||
t.Run("basic", func(t *testing.T) {
|
||||
refDescriptions, err := client.RefDescriptions(ctx, nil, repo)
|
||||
refDescriptions, err := client.RefDescriptions(ctx, repo)
|
||||
if err != nil {
|
||||
t.Errorf("err calling RefDescriptions: %s", err)
|
||||
}
|
||||
@ -2216,7 +2224,8 @@ func TestRefDescriptions(t *testing.T) { // KEEP
|
||||
|
||||
t.Run("with sub-repo enabled", func(t *testing.T) {
|
||||
checker := getTestSubRepoPermsChecker("file-with-no-access")
|
||||
refDescriptions, err := client.RefDescriptions(ctx, checker, repo)
|
||||
client2 := NewTestClient(t).WithChecker(checker)
|
||||
refDescriptions, err := client2.RefDescriptions(ctx, repo)
|
||||
if err != nil {
|
||||
t.Errorf("err calling RefDescriptions: %s", err)
|
||||
}
|
||||
@ -2236,13 +2245,13 @@ func TestCommitsUniqueToBranch(t *testing.T) {
|
||||
ctx := actor.WithActor(context.Background(), &actor.Actor{
|
||||
UID: 1,
|
||||
})
|
||||
client := NewClient()
|
||||
gitCommands := append([]string{"git checkout -b my-branch"}, getGitCommandsWithFiles("file1", "file2")...)
|
||||
gitCommands = append(gitCommands, getGitCommandsWithFiles("file3", "file-with-no-access")...)
|
||||
repo := MakeGitRepository(t, gitCommands...)
|
||||
|
||||
t.Run("basic", func(t *testing.T) {
|
||||
commits, err := client.CommitsUniqueToBranch(ctx, nil, repo, "my-branch", true, &time.Time{})
|
||||
client := NewClient()
|
||||
commits, err := client.CommitsUniqueToBranch(ctx, repo, "my-branch", true, &time.Time{})
|
||||
if err != nil {
|
||||
t.Errorf("err calling RefDescriptions: %s", err)
|
||||
}
|
||||
@ -2259,7 +2268,8 @@ func TestCommitsUniqueToBranch(t *testing.T) {
|
||||
|
||||
t.Run("with sub-repo enabled", func(t *testing.T) {
|
||||
checker := getTestSubRepoPermsChecker("file-with-no-access")
|
||||
commits, err := client.CommitsUniqueToBranch(ctx, checker, repo, "my-branch", true, &time.Time{})
|
||||
client := NewTestClient(t).WithChecker(checker)
|
||||
commits, err := client.CommitsUniqueToBranch(ctx, repo, "my-branch", true, &time.Time{})
|
||||
if err != nil {
|
||||
t.Errorf("err calling RefDescriptions: %s", err)
|
||||
}
|
||||
@ -2280,12 +2290,12 @@ func TestCommitDate(t *testing.T) {
|
||||
ctx := actor.WithActor(context.Background(), &actor.Actor{
|
||||
UID: 1,
|
||||
})
|
||||
client := NewClient()
|
||||
gitCommands := getGitCommandsWithFiles("file1", "file2")
|
||||
repo := MakeGitRepository(t, gitCommands...)
|
||||
|
||||
t.Run("basic", func(t *testing.T) {
|
||||
_, date, commitExists, err := client.CommitDate(ctx, nil, repo, "d38233a79e037d2ab8170b0d0bc0aa438473e6da")
|
||||
client := NewClient()
|
||||
_, date, commitExists, err := client.CommitDate(ctx, repo, "d38233a79e037d2ab8170b0d0bc0aa438473e6da")
|
||||
if err != nil {
|
||||
t.Errorf("error fetching CommitDate: %s", err)
|
||||
}
|
||||
@ -2299,7 +2309,8 @@ func TestCommitDate(t *testing.T) {
|
||||
|
||||
t.Run("with sub-repo permissions enabled", func(t *testing.T) {
|
||||
checker := getTestSubRepoPermsChecker("file1")
|
||||
_, date, commitExists, err := client.CommitDate(ctx, checker, repo, "d38233a79e037d2ab8170b0d0bc0aa438473e6da")
|
||||
client := NewTestClient(t).WithChecker(checker)
|
||||
_, date, commitExists, err := client.CommitDate(ctx, repo, "d38233a79e037d2ab8170b0d0bc0aa438473e6da")
|
||||
if err != nil {
|
||||
t.Errorf("error fetching CommitDate: %s", err)
|
||||
}
|
||||
@ -2314,8 +2325,8 @@ func TestCommitDate(t *testing.T) {
|
||||
|
||||
func testCommits(ctx context.Context, label string, repo api.RepoName, opt CommitsOptions, checker authz.SubRepoPermissionChecker, wantCommits []*gitdomain.Commit, t *testing.T) {
|
||||
t.Helper()
|
||||
client := NewClient().(*clientImplementor)
|
||||
commits, err := client.Commits(ctx, checker, repo, opt)
|
||||
client := NewTestClient(t).WithChecker(checker)
|
||||
commits, err := client.Commits(ctx, repo, opt)
|
||||
if err != nil {
|
||||
t.Errorf("%s: Commits(): %s", label, err)
|
||||
return
|
||||
@ -2448,8 +2459,8 @@ func TestArchiveReaderForRepoWithSubRepoPermissions(t *testing.T) {
|
||||
Treeish: commitID,
|
||||
Pathspecs: []gitdomain.Pathspec{"."},
|
||||
}
|
||||
client := NewClient()
|
||||
if _, err := client.ArchiveReader(context.Background(), checker, repo.Name, opts); err == nil {
|
||||
client := NewTestClient(t).WithChecker(checker)
|
||||
if _, err := client.ArchiveReader(context.Background(), repo.Name, opts); err == nil {
|
||||
t.Error("Error should not be null because ArchiveReader is invoked for a repo with sub-repo permissions")
|
||||
}
|
||||
}
|
||||
@ -2484,7 +2495,7 @@ func TestArchiveReaderForRepoWithoutSubRepoPermissions(t *testing.T) {
|
||||
Pathspecs: []gitdomain.Pathspec{"."},
|
||||
}
|
||||
client := NewClient()
|
||||
readCloser, err := client.ArchiveReader(context.Background(), checker, repo.Name, opts)
|
||||
readCloser, err := client.ArchiveReader(context.Background(), repo.Name, opts)
|
||||
if err != nil {
|
||||
t.Error("Error should not be thrown because ArchiveReader is invoked for a repo without sub-repo permissions")
|
||||
}
|
||||
@ -2556,7 +2567,6 @@ func TestRead(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
client := NewClient()
|
||||
ClientMocks.LocalGitserver = true
|
||||
t.Cleanup(func() {
|
||||
ResetClientMocks()
|
||||
@ -2587,7 +2597,8 @@ func TestRead(t *testing.T) {
|
||||
}
|
||||
|
||||
t.Run(name+"-ReadFile", func(t *testing.T) {
|
||||
data, err := client.ReadFile(ctx, nil, repo, commitID, test.file)
|
||||
client := NewTestClient(t).WithChecker(checker)
|
||||
data, err := client.ReadFile(ctx, repo, commitID, test.file)
|
||||
checkFn(t, err, data)
|
||||
})
|
||||
t.Run(name+"-ReadFile-with-sub-repo-permissions-no-op", func(t *testing.T) {
|
||||
@ -2600,7 +2611,8 @@ func TestRead(t *testing.T) {
|
||||
}
|
||||
return authz.None, nil
|
||||
})
|
||||
data, err := client.ReadFile(ctx, checker, repo, commitID, test.file)
|
||||
client := NewTestClient(t).WithChecker(checker)
|
||||
data, err := client.ReadFile(ctx, repo, commitID, test.file)
|
||||
checkFn(t, err, data)
|
||||
})
|
||||
t.Run(name+"-ReadFile-with-sub-repo-permissions-filters-file", func(t *testing.T) {
|
||||
@ -2610,7 +2622,8 @@ func TestRead(t *testing.T) {
|
||||
checker.PermissionsFunc.SetDefaultHook(func(ctx context.Context, i int32, content authz.RepoContent) (authz.Perms, error) {
|
||||
return authz.None, nil
|
||||
})
|
||||
data, err := client.ReadFile(ctx, checker, repo, commitID, test.file)
|
||||
client := NewTestClient(t).WithChecker(checker)
|
||||
data, err := client.ReadFile(ctx, repo, commitID, test.file)
|
||||
if err != os.ErrNotExist {
|
||||
t.Errorf("unexpected error reading file: %s", err)
|
||||
}
|
||||
@ -2640,7 +2653,8 @@ func TestRead(t *testing.T) {
|
||||
checker.PermissionsFunc.SetDefaultHook(func(ctx context.Context, i int32, content authz.RepoContent) (authz.Perms, error) {
|
||||
return authz.None, nil
|
||||
})
|
||||
rc, err := client.NewFileReader(ctx, checker, repo, commitID, test.file)
|
||||
client := NewTestClient(t).WithChecker(checker)
|
||||
rc, err := client.NewFileReader(ctx, repo, commitID, test.file)
|
||||
if err != os.ErrNotExist {
|
||||
t.Fatalf("unexpected error: %s", err)
|
||||
}
|
||||
@ -2654,7 +2668,7 @@ func TestRead(t *testing.T) {
|
||||
func runNewFileReaderTest(ctx context.Context, t *testing.T, repo api.RepoName, commitID api.CommitID, file string,
|
||||
checker authz.SubRepoPermissionChecker, checkFn func(*testing.T, error, []byte)) {
|
||||
t.Helper()
|
||||
rc, err := NewClient().NewFileReader(ctx, checker, repo, commitID, file)
|
||||
rc, err := NewClient().NewFileReader(ctx, repo, commitID, file)
|
||||
if err != nil {
|
||||
checkFn(t, err, nil)
|
||||
return
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -11,7 +11,6 @@ go_library(
|
||||
visibility = ["//:__subpackages__"],
|
||||
deps = [
|
||||
"//internal/api",
|
||||
"//internal/authz",
|
||||
"//internal/gitserver",
|
||||
"//internal/gitserver/gitdomain",
|
||||
"//lib/errors",
|
||||
|
||||
@ -5,7 +5,6 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/internal/api"
|
||||
"github.com/sourcegraph/sourcegraph/internal/authz"
|
||||
"github.com/sourcegraph/sourcegraph/internal/gitserver"
|
||||
"github.com/sourcegraph/sourcegraph/internal/gitserver/gitdomain"
|
||||
)
|
||||
@ -30,7 +29,7 @@ func (g *GitCommitClient) RecentCommits(ctx context.Context, repoName api.RepoNa
|
||||
if len(revision) > 0 {
|
||||
options.Range = revision
|
||||
}
|
||||
return g.gitserverClient.Commits(ctx, authz.DefaultSubRepoPermsChecker, repoName, options)
|
||||
return g.gitserverClient.Commits(ctx, repoName, options)
|
||||
}
|
||||
|
||||
func (g *GitCommitClient) GitserverClient() gitserver.Client {
|
||||
|
||||
@ -6,7 +6,6 @@ import (
|
||||
"sync"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/internal/api"
|
||||
"github.com/sourcegraph/sourcegraph/internal/authz"
|
||||
"github.com/sourcegraph/sourcegraph/internal/gitserver"
|
||||
"github.com/sourcegraph/sourcegraph/internal/gitserver/gitdomain"
|
||||
"github.com/sourcegraph/sourcegraph/lib/errors"
|
||||
@ -30,7 +29,7 @@ func isFirstCommitEmptyRepoError(err error) bool {
|
||||
}
|
||||
|
||||
func GitFirstEverCommit(ctx context.Context, gitserverClient gitserver.Client, repoName api.RepoName) (*gitdomain.Commit, error) {
|
||||
commit, err := gitserverClient.FirstEverCommit(ctx, authz.DefaultSubRepoPermsChecker, repoName)
|
||||
commit, err := gitserverClient.FirstEverCommit(ctx, repoName)
|
||||
if err != nil && isFirstCommitEmptyRepoError(err) {
|
||||
return nil, errors.Wrap(EmptyRepoErr, err.Error())
|
||||
}
|
||||
|
||||
@ -12,7 +12,6 @@ go_library(
|
||||
deps = [
|
||||
"//internal/api",
|
||||
"//internal/auth/providers",
|
||||
"//internal/authz",
|
||||
"//internal/collections",
|
||||
"//internal/database",
|
||||
"//internal/errcode",
|
||||
@ -40,7 +39,6 @@ go_test(
|
||||
deps = [
|
||||
"//internal/api",
|
||||
"//internal/auth/providers",
|
||||
"//internal/authz",
|
||||
"//internal/database",
|
||||
"//internal/database/dbmocks",
|
||||
"//internal/database/dbtest",
|
||||
|
||||
@ -64,7 +64,7 @@ func (r *analyticsIndexer) indexRepo(ctx context.Context, repoId api.RepoID, che
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "repoStore.Get")
|
||||
}
|
||||
files, err := r.client.LsFiles(ctx, nil, repo.Name, "HEAD")
|
||||
files, err := r.client.LsFiles(ctx, repo.Name, "HEAD")
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "ls-files")
|
||||
}
|
||||
|
||||
@ -26,7 +26,7 @@ type fakeGitServer struct {
|
||||
fileContents map[string]string
|
||||
}
|
||||
|
||||
func (f fakeGitServer) LsFiles(ctx context.Context, checker authz.SubRepoPermissionChecker, repo api.RepoName, commit api.CommitID, pathspecs ...gitdomain.Pathspec) ([]string, error) {
|
||||
func (f fakeGitServer) LsFiles(ctx context.Context, repo api.RepoName, commit api.CommitID, pathspecs ...gitdomain.Pathspec) ([]string, error) {
|
||||
return f.files, nil
|
||||
}
|
||||
|
||||
@ -34,7 +34,7 @@ func (f fakeGitServer) ResolveRevision(ctx context.Context, repo api.RepoName, s
|
||||
return api.CommitID(""), nil
|
||||
}
|
||||
|
||||
func (f fakeGitServer) ReadFile(ctx context.Context, checker authz.SubRepoPermissionChecker, repo api.RepoName, commit api.CommitID, name string) ([]byte, error) {
|
||||
func (f fakeGitServer) ReadFile(ctx context.Context, repo api.RepoName, commit api.CommitID, name string) ([]byte, error) {
|
||||
if f.fileContents == nil {
|
||||
return nil, os.ErrNotExist
|
||||
}
|
||||
|
||||
@ -37,7 +37,6 @@ go_test(
|
||||
embed = [":search"],
|
||||
deps = [
|
||||
"//internal/api",
|
||||
"//internal/authz",
|
||||
"//internal/database",
|
||||
"//internal/database/dbmocks",
|
||||
"//internal/gitserver",
|
||||
|
||||
@ -8,7 +8,6 @@ import (
|
||||
|
||||
"github.com/hexops/autogold/v2"
|
||||
"github.com/sourcegraph/sourcegraph/internal/api"
|
||||
"github.com/sourcegraph/sourcegraph/internal/authz"
|
||||
"github.com/sourcegraph/sourcegraph/internal/database"
|
||||
"github.com/sourcegraph/sourcegraph/internal/database/dbmocks"
|
||||
"github.com/sourcegraph/sourcegraph/internal/gitserver"
|
||||
@ -538,7 +537,7 @@ func TestApplyCodeOwnershipFiltering(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
gitserverClient := gitserver.NewMockClient()
|
||||
gitserverClient.ReadFileFunc.SetDefaultHook(func(_ context.Context, _ authz.SubRepoPermissionChecker, _ api.RepoName, _ api.CommitID, file string) ([]byte, error) {
|
||||
gitserverClient.ReadFileFunc.SetDefaultHook(func(_ context.Context, _ api.RepoName, _ api.CommitID, file string) ([]byte, error) {
|
||||
content, ok := tt.args.repoContent[file]
|
||||
if !ok {
|
||||
return nil, fs.ErrNotExist
|
||||
|
||||
@ -9,7 +9,6 @@ import (
|
||||
|
||||
"github.com/hexops/autogold/v2"
|
||||
"github.com/sourcegraph/sourcegraph/internal/api"
|
||||
"github.com/sourcegraph/sourcegraph/internal/authz"
|
||||
"github.com/sourcegraph/sourcegraph/internal/database"
|
||||
"github.com/sourcegraph/sourcegraph/internal/database/dbmocks"
|
||||
"github.com/sourcegraph/sourcegraph/internal/gitserver"
|
||||
@ -40,7 +39,7 @@ func TestGetCodeOwnersFromMatches(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
gitserverClient := gitserver.NewMockClient()
|
||||
gitserverClient.ReadFileFunc.SetDefaultHook(func(_ context.Context, _ authz.SubRepoPermissionChecker, _ api.RepoName, _ api.CommitID, file string) ([]byte, error) {
|
||||
gitserverClient.ReadFileFunc.SetDefaultHook(func(_ context.Context, _ api.RepoName, _ api.CommitID, file string) ([]byte, error) {
|
||||
return nil, fs.ErrNotExist
|
||||
})
|
||||
|
||||
@ -64,7 +63,7 @@ func TestGetCodeOwnersFromMatches(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
gitserverClient := gitserver.NewMockClient()
|
||||
gitserverClient.ReadFileFunc.SetDefaultHook(func(_ context.Context, _ authz.SubRepoPermissionChecker, _ api.RepoName, _ api.CommitID, file string) ([]byte, error) {
|
||||
gitserverClient.ReadFileFunc.SetDefaultHook(func(_ context.Context, _ api.RepoName, _ api.CommitID, file string) ([]byte, error) {
|
||||
// return a codeowner path for no which doesn't match the path of the match below.
|
||||
return []byte("NO.md @test\n"), nil
|
||||
})
|
||||
@ -88,7 +87,7 @@ func TestGetCodeOwnersFromMatches(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
gitserverClient := gitserver.NewMockClient()
|
||||
gitserverClient.ReadFileFunc.SetDefaultHook(func(_ context.Context, _ authz.SubRepoPermissionChecker, _ api.RepoName, _ api.CommitID, file string) ([]byte, error) {
|
||||
gitserverClient.ReadFileFunc.SetDefaultHook(func(_ context.Context, _ api.RepoName, _ api.CommitID, file string) ([]byte, error) {
|
||||
// README is owned by a user and a team.
|
||||
// code.go is owner by another user and an unknown entity.
|
||||
return []byte("README.md @testUserHandle @testTeamHandle\ncode.go user@email.com @unknown"), nil
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user