mirror of
https://github.com/sourcegraph/sourcegraph.git
synced 2026-02-06 20:51:43 +00:00
gitserver: Cleanups (#38082)
A few small cleanups which are easier now that everything is in the gitserver package: - Move Rel function into gitserver package as it is only used there - Make LStat private - Consistently move checker parameters as second parameter after context - Remove unused db param from client.ReadDir
This commit is contained in:
parent
2402a1c11f
commit
38bade2aa2
@ -45,7 +45,7 @@ func InventoryContext(repo api.RepoName, db database.DB, commitID api.CommitID,
|
||||
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 gitserver.NewClient(db).ReadDir(ctx, db, authz.DefaultSubRepoPermsChecker, repo, commitID, path, false)
|
||||
return gitserver.NewClient(db).ReadDir(ctx, authz.DefaultSubRepoPermsChecker, repo, commitID, path, false)
|
||||
},
|
||||
NewFileReader: func(ctx context.Context, path string) (io.ReadCloser, error) {
|
||||
return gitserver.NewClient(db).NewFileReader(ctx, repo, commitID, path, authz.DefaultSubRepoPermsChecker)
|
||||
|
||||
@ -13,11 +13,11 @@ func (r *GitTreeEntryResolver) Blame(ctx context.Context,
|
||||
StartLine int32
|
||||
EndLine int32
|
||||
}) ([]*hunkResolver, error) {
|
||||
hunks, err := gitserver.NewClient(r.db).BlameFile(ctx, r.commit.repoResolver.RepoName(), r.Path(), &gitserver.BlameOptions{
|
||||
hunks, err := gitserver.NewClient(r.db).BlameFile(ctx, authz.DefaultSubRepoPermsChecker, r.commit.repoResolver.RepoName(), r.Path(), &gitserver.BlameOptions{
|
||||
NewestCommit: api.CommitID(r.commit.OID()),
|
||||
StartLine: int(args.StartLine),
|
||||
EndLine: int(args.EndLine),
|
||||
}, authz.DefaultSubRepoPermsChecker)
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@ -43,15 +43,7 @@ func (r *GitTreeEntryResolver) entries(ctx context.Context, args *gitTreeEntryCo
|
||||
span, ctx := ot.StartSpanFromContext(ctx, "tree.entries")
|
||||
defer span.Finish()
|
||||
|
||||
entries, err := gitserver.NewClient(r.db).ReadDir(
|
||||
ctx,
|
||||
r.db,
|
||||
authz.DefaultSubRepoPermsChecker,
|
||||
r.commit.repoResolver.RepoName(),
|
||||
api.CommitID(r.commit.OID()),
|
||||
r.Path(),
|
||||
r.isRecursive || args.Recursive,
|
||||
)
|
||||
entries, err := gitserver.NewClient(r.db).ReadDir(ctx, authz.DefaultSubRepoPermsChecker, 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
|
||||
|
||||
@ -226,15 +226,7 @@ func (r *GitTreeEntryResolver) IsSingleChild(ctx context.Context, args *gitTreeE
|
||||
if r.isSingleChild != nil {
|
||||
return *r.isSingleChild, nil
|
||||
}
|
||||
entries, err := gitserver.NewClient(r.db).ReadDir(
|
||||
ctx,
|
||||
r.db,
|
||||
authz.DefaultSubRepoPermsChecker,
|
||||
r.commit.repoResolver.RepoName(),
|
||||
api.CommitID(r.commit.OID()),
|
||||
path.Dir(r.Path()),
|
||||
false,
|
||||
)
|
||||
entries, err := gitserver.NewClient(r.db).ReadDir(ctx, authz.DefaultSubRepoPermsChecker, r.commit.repoResolver.RepoName(), api.CommitID(r.commit.OID()), path.Dir(r.Path()), false)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
@ -255,11 +255,11 @@ func (sr *SearchResultsResolver) blameFileMatch(ctx context.Context, fm *result.
|
||||
return time.Time{}, nil
|
||||
}
|
||||
hm := fm.ChunkMatches[0]
|
||||
hunks, err := gitserver.NewClient(sr.db).BlameFile(ctx, fm.Repo.Name, fm.Path, &gitserver.BlameOptions{
|
||||
hunks, err := gitserver.NewClient(sr.db).BlameFile(ctx, authz.DefaultSubRepoPermsChecker, fm.Repo.Name, fm.Path, &gitserver.BlameOptions{
|
||||
NewestCommit: fm.CommitID,
|
||||
StartLine: hm.Ranges[0].Start.Line,
|
||||
EndLine: hm.Ranges[0].Start.Line,
|
||||
}, authz.DefaultSubRepoPermsChecker)
|
||||
})
|
||||
if err != nil {
|
||||
return time.Time{}, err
|
||||
}
|
||||
|
||||
@ -246,7 +246,7 @@ func serveRaw(db database.DB) handlerFunc {
|
||||
|
||||
if fi.IsDir() {
|
||||
requestType = "dir"
|
||||
infos, err := client.ReadDir(r.Context(), db, authz.DefaultSubRepoPermsChecker, common.Repo.Name, common.CommitID, requestedPath, false)
|
||||
infos, err := client.ReadDir(r.Context(), authz.DefaultSubRepoPermsChecker, common.Repo.Name, common.CommitID, requestedPath, false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -124,7 +124,7 @@ func (p *positionAdjuster) readHunksCached(ctx context.Context, repo *types.Repo
|
||||
// readHunks returns a position-ordered slice of changes (additions or deletions) of
|
||||
// the given path between the given source and target commits.
|
||||
func (p *positionAdjuster) readHunks(ctx context.Context, repo *types.Repo, sourceCommit, targetCommit, path string) ([]*diff.Hunk, error) {
|
||||
return p.client.DiffPath(ctx, repo.Name, sourceCommit, targetCommit, path, authz.DefaultSubRepoPermsChecker)
|
||||
return p.client.DiffPath(ctx, authz.DefaultSubRepoPermsChecker, repo.Name, sourceCommit, targetCommit, path)
|
||||
}
|
||||
|
||||
// adjustPosition translates the given position by adjusting the line number based on the
|
||||
|
||||
@ -182,7 +182,7 @@ type Client interface {
|
||||
BatchLog(ctx context.Context, opts BatchLogOptions, callback BatchLogCallback) error
|
||||
|
||||
// BlameFile returns Git blame information about a file.
|
||||
BlameFile(ctx context.Context, repo api.RepoName, path string, opt *BlameOptions, checker authz.SubRepoPermissionChecker) ([]*Hunk, error)
|
||||
BlameFile(ctx context.Context, checker authz.SubRepoPermissionChecker, repo api.RepoName, path string, opt *BlameOptions) ([]*Hunk, error)
|
||||
|
||||
// GitCommand creates a new GitCommand.
|
||||
GitCommand(repo api.RepoName, args ...string) GitCommand
|
||||
@ -290,10 +290,10 @@ type Client interface {
|
||||
|
||||
// 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, repo api.RepoName, sourceCommit, targetCommit, path string, checker authz.SubRepoPermissionChecker) ([]*diff.Hunk, error)
|
||||
DiffPath(ctx context.Context, checker authz.SubRepoPermissionChecker, repo api.RepoName, sourceCommit, targetCommit, path string) ([]*diff.Hunk, error)
|
||||
|
||||
// ReadDir reads the contents of the named directory at commit.
|
||||
ReadDir(ctx context.Context, db database.DB, checker authz.SubRepoPermissionChecker, repo api.RepoName, commit api.CommitID, path string, recurse bool) ([]fs.FileInfo, error)
|
||||
ReadDir(ctx context.Context, checker authz.SubRepoPermissionChecker, repo api.RepoName, commit api.CommitID, path string, recurse bool) ([]fs.FileInfo, error)
|
||||
}
|
||||
|
||||
func (c *ClientImplementor) Addrs() []string {
|
||||
|
||||
@ -30,7 +30,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/database"
|
||||
"github.com/sourcegraph/sourcegraph/internal/gitserver/gitdomain"
|
||||
"github.com/sourcegraph/sourcegraph/internal/gitserver/protocol"
|
||||
"github.com/sourcegraph/sourcegraph/internal/honey"
|
||||
@ -300,7 +299,7 @@ func (c *ClientImplementor) CommitGraph(ctx context.Context, repo api.RepoName,
|
||||
// the root commit.
|
||||
const DevNullSHA = "4b825dc642cb6eb9a060e54bf8d69288fbee4904"
|
||||
|
||||
func (c *ClientImplementor) DiffPath(ctx context.Context, repo api.RepoName, sourceCommit, targetCommit, path string, checker authz.SubRepoPermissionChecker) ([]*diff.Hunk, error) {
|
||||
func (c *ClientImplementor) DiffPath(ctx context.Context, checker authz.SubRepoPermissionChecker, 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
|
||||
@ -335,15 +334,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,
|
||||
db database.DB,
|
||||
checker authz.SubRepoPermissionChecker,
|
||||
repo api.RepoName,
|
||||
commit api.CommitID,
|
||||
path string,
|
||||
recurse bool,
|
||||
) ([]fs.FileInfo, error) {
|
||||
func (c *ClientImplementor) ReadDir(ctx context.Context, checker authz.SubRepoPermissionChecker, repo api.RepoName, commit api.CommitID, path string, recurse bool) ([]fs.FileInfo, error) {
|
||||
if Mocks.ReadDir != nil {
|
||||
return Mocks.ReadDir(commit, path, recurse)
|
||||
}
|
||||
@ -361,7 +352,7 @@ func (c *ClientImplementor) ReadDir(
|
||||
if path != "" {
|
||||
// Trailing slash is necessary to ls-tree under the dir (not just
|
||||
// to list the dir's tree entry in its parent dir).
|
||||
path = filepath.Clean(util.Rel(path)) + "/"
|
||||
path = filepath.Clean(rel(path)) + "/"
|
||||
}
|
||||
files, err := c.lsTree(ctx, repo, commit, path, recurse)
|
||||
|
||||
@ -433,10 +424,10 @@ type objectInfo gitdomain.OID
|
||||
|
||||
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.
|
||||
// TODO(sashaostrikov): make private when git.Stat is moved here as well
|
||||
func (c *ClientImplementor) LStat(ctx context.Context, checker authz.SubRepoPermissionChecker, repo api.RepoName, commit api.CommitID, path string) (fs.FileInfo, error) {
|
||||
// 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, error) {
|
||||
span, ctx := ot.StartSpanFromContext(ctx, "Git: lStat")
|
||||
span.SetTag("Commit", commit)
|
||||
span.SetTag("Path", path)
|
||||
@ -446,7 +437,7 @@ func (c *ClientImplementor) LStat(ctx context.Context, checker authz.SubRepoPerm
|
||||
return nil, err
|
||||
}
|
||||
|
||||
path = filepath.Clean(util.Rel(path))
|
||||
path = filepath.Clean(rel(path))
|
||||
|
||||
if path == "." {
|
||||
// Special case root, which is not returned by `git ls-tree`.
|
||||
@ -672,7 +663,7 @@ type Hunk struct {
|
||||
}
|
||||
|
||||
// BlameFile returns Git blame information about a file.
|
||||
func (c *ClientImplementor) BlameFile(ctx context.Context, repo api.RepoName, path string, opt *BlameOptions, checker authz.SubRepoPermissionChecker) ([]*Hunk, error) {
|
||||
func (c *ClientImplementor) BlameFile(ctx context.Context, checker authz.SubRepoPermissionChecker, repo api.RepoName, path string, opt *BlameOptions) ([]*Hunk, error) {
|
||||
span, ctx := ot.StartSpanFromContext(ctx, "Git: BlameFile")
|
||||
span.SetTag("repo", repo)
|
||||
span.SetTag("path", path)
|
||||
@ -1355,7 +1346,7 @@ func (c *ClientImplementor) NewFileReader(ctx context.Context, repo api.RepoName
|
||||
span.SetTag("Name", name)
|
||||
defer span.Finish()
|
||||
|
||||
name = util.Rel(name)
|
||||
name = rel(name)
|
||||
br, err := c.newBlobReader(ctx, repo, commit, name)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "getting blobReader for %q", name)
|
||||
@ -1449,9 +1440,9 @@ func (c *ClientImplementor) Stat(ctx context.Context, checker authz.SubRepoPermi
|
||||
return nil, err
|
||||
}
|
||||
|
||||
path = util.Rel(path)
|
||||
path = rel(path)
|
||||
|
||||
fi, err := c.LStat(ctx, checker, repo, commit, path)
|
||||
fi, err := c.lStat(ctx, checker, repo, commit, path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -2581,3 +2572,16 @@ func (c *ClientImplementor) showRef(ctx context.Context, repo api.RepoName, args
|
||||
}
|
||||
return refs, nil
|
||||
}
|
||||
|
||||
// rel strips the leading "/" prefix from the path string, effectively turning
|
||||
// an absolute path into one relative to the root directory. A path that is just
|
||||
// "/" is treated specially, returning just ".".
|
||||
//
|
||||
// The elements in a file path are separated by slash ('/', U+002F) characters,
|
||||
// regardless of host operating system convention.
|
||||
func rel(path string) string {
|
||||
if path == "/" {
|
||||
return "."
|
||||
}
|
||||
return strings.TrimPrefix(path, "/")
|
||||
}
|
||||
|
||||
@ -268,7 +268,7 @@ index 51a59ef1c..493090958 100644
|
||||
ctx = actor.WithActor(ctx, &actor.Actor{
|
||||
UID: 1,
|
||||
})
|
||||
hunks, err := client.DiffPath(ctx, "", "sourceCommit", "", "file", checker)
|
||||
hunks, err := client.DiffPath(ctx, checker, "", "sourceCommit", "", "file")
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %s", err)
|
||||
}
|
||||
@ -296,7 +296,7 @@ index 51a59ef1c..493090958 100644
|
||||
}
|
||||
return authz.Read, nil
|
||||
})
|
||||
hunks, err := client.DiffPath(ctx, "", "sourceCommit", "", fileName, checker)
|
||||
hunks, err := client.DiffPath(ctx, checker, "", "sourceCommit", "", fileName)
|
||||
if !reflect.DeepEqual(err, os.ErrNotExist) {
|
||||
t.Errorf("unexpected error: %s", err)
|
||||
}
|
||||
@ -399,7 +399,7 @@ func runBlameFileTest(ctx context.Context, t *testing.T, repo api.RepoName, path
|
||||
checker authz.SubRepoPermissionChecker, label string, wantHunks []*Hunk,
|
||||
) {
|
||||
t.Helper()
|
||||
hunks, err := NewClient(database.NewMockDB()).BlameFile(ctx, repo, path, opt, checker)
|
||||
hunks, err := NewClient(database.NewMockDB()).BlameFile(ctx, checker, repo, path, opt)
|
||||
if err != nil {
|
||||
t.Errorf("%s: BlameFile(%s, %+v): %s", label, path, opt, err)
|
||||
return
|
||||
@ -1034,7 +1034,7 @@ func TestRepository_FileSystem_Symlinks(t *testing.T) {
|
||||
|
||||
// Check symlinks are links
|
||||
for symlink := range symlinks {
|
||||
fi, err := client.LStat(ctx, authz.DefaultSubRepoPermsChecker, repo, commitID, symlink)
|
||||
fi, err := client.lStat(ctx, authz.DefaultSubRepoPermsChecker, repo, commitID, symlink)
|
||||
if err != nil {
|
||||
t.Fatalf("fs.lStat(%s): %s", symlink, err)
|
||||
}
|
||||
@ -1046,7 +1046,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, db, authz.DefaultSubRepoPermsChecker, repo, commitID, ".", false)
|
||||
entries, err := client.ReadDir(ctx, authz.DefaultSubRepoPermsChecker, repo, commitID, ".", false)
|
||||
if err != nil {
|
||||
t.Fatalf("fs.ReadDir(.): %s", err)
|
||||
}
|
||||
|
||||
@ -60,7 +60,7 @@ func TestReadDir_SubRepoFiltering(t *testing.T) {
|
||||
|
||||
db := database.NewMockDB()
|
||||
client := gitserver.NewClient(db)
|
||||
files, err := client.ReadDir(ctx, db, checker, repo, commitID, "", false)
|
||||
files, err := client.ReadDir(ctx, checker, repo, commitID, "", false)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %s", err)
|
||||
}
|
||||
@ -140,7 +140,7 @@ func TestRepository_FileSystem(t *testing.T) {
|
||||
client := gitserver.NewClient(db)
|
||||
|
||||
// dir1 should contain one entry: file1.
|
||||
dir1Entries, err := client.ReadDir(ctx, db, authz.DefaultSubRepoPermsChecker, test.repo, test.first, "dir1", false)
|
||||
dir1Entries, err := client.ReadDir(ctx, authz.DefaultSubRepoPermsChecker, test.repo, test.first, "dir1", false)
|
||||
if err != nil {
|
||||
t.Errorf("%s: fs1.ReadDir(dir1): %s", label, err)
|
||||
continue
|
||||
@ -161,7 +161,7 @@ func TestRepository_FileSystem(t *testing.T) {
|
||||
}
|
||||
|
||||
// dir2 should not exist
|
||||
_, err = client.ReadDir(ctx, db, authz.DefaultSubRepoPermsChecker, test.repo, test.first, "dir2", false)
|
||||
_, err = client.ReadDir(ctx, authz.DefaultSubRepoPermsChecker, test.repo, test.first, "dir2", false)
|
||||
if !os.IsNotExist(err) {
|
||||
t.Errorf("%s: fs1.ReadDir(dir2): should not exist: %s", label, err)
|
||||
continue
|
||||
@ -225,7 +225,7 @@ func TestRepository_FileSystem(t *testing.T) {
|
||||
}
|
||||
|
||||
// root should have 2 entries: dir1 and file 2.
|
||||
rootEntries, err := client.ReadDir(ctx, db, authz.DefaultSubRepoPermsChecker, test.repo, test.second, ".", false)
|
||||
rootEntries, err := client.ReadDir(ctx, authz.DefaultSubRepoPermsChecker, test.repo, test.second, ".", false)
|
||||
if err != nil {
|
||||
t.Errorf("%s: fs2.ReadDir(.): %s", label, err)
|
||||
continue
|
||||
@ -242,7 +242,7 @@ func TestRepository_FileSystem(t *testing.T) {
|
||||
}
|
||||
|
||||
// dir1 should still only contain one entry: file1.
|
||||
dir1Entries, err = client.ReadDir(ctx, db, authz.DefaultSubRepoPermsChecker, test.repo, test.second, "dir1", false)
|
||||
dir1Entries, err = client.ReadDir(ctx, authz.DefaultSubRepoPermsChecker, test.repo, test.second, "dir1", false)
|
||||
if err != nil {
|
||||
t.Errorf("%s: fs1.ReadDir(dir1): %s", label, err)
|
||||
continue
|
||||
@ -256,7 +256,7 @@ func TestRepository_FileSystem(t *testing.T) {
|
||||
}
|
||||
|
||||
// rootEntries should be empty for third commit
|
||||
rootEntries, err = client.ReadDir(ctx, db, authz.DefaultSubRepoPermsChecker, test.repo, test.third, ".", false)
|
||||
rootEntries, err = client.ReadDir(ctx, authz.DefaultSubRepoPermsChecker, test.repo, test.third, ".", false)
|
||||
if err != nil {
|
||||
t.Errorf("%s: fs3.ReadDir(.): %s", label, err)
|
||||
continue
|
||||
@ -311,7 +311,7 @@ func TestRepository_FileSystem_quoteChars(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
entries, err := client.ReadDir(ctx, db, authz.DefaultSubRepoPermsChecker, test.repo, commitID, ".", false)
|
||||
entries, err := client.ReadDir(ctx, authz.DefaultSubRepoPermsChecker, test.repo, commitID, ".", false)
|
||||
if err != nil {
|
||||
t.Errorf("%s: fs.ReadDir(.): %s", label, err)
|
||||
continue
|
||||
@ -407,7 +407,7 @@ func TestRepository_FileSystem_gitSubmodules(t *testing.T) {
|
||||
continue
|
||||
}
|
||||
checkSubmoduleFileInfo(label+" (Stat)", submod)
|
||||
entries, err := client.ReadDir(ctx, db, authz.DefaultSubRepoPermsChecker, test.repo, commitID, ".", false)
|
||||
entries, err := client.ReadDir(ctx, authz.DefaultSubRepoPermsChecker, test.repo, commitID, ".", false)
|
||||
if err != nil {
|
||||
t.Errorf("%s: fs.ReadDir(.): %s", label, err)
|
||||
continue
|
||||
|
||||
@ -17,7 +17,6 @@ import (
|
||||
diff "github.com/sourcegraph/go-diff/diff"
|
||||
api "github.com/sourcegraph/sourcegraph/internal/api"
|
||||
authz "github.com/sourcegraph/sourcegraph/internal/authz"
|
||||
database "github.com/sourcegraph/sourcegraph/internal/database"
|
||||
gitolite "github.com/sourcegraph/sourcegraph/internal/extsvc/gitolite"
|
||||
gitdomain "github.com/sourcegraph/sourcegraph/internal/gitserver/gitdomain"
|
||||
protocol "github.com/sourcegraph/sourcegraph/internal/gitserver/protocol"
|
||||
@ -155,7 +154,7 @@ func NewMockClient() *MockClient {
|
||||
},
|
||||
},
|
||||
BlameFileFunc: &ClientBlameFileFunc{
|
||||
defaultHook: func(context.Context, api.RepoName, string, *BlameOptions, authz.SubRepoPermissionChecker) (r0 []*Hunk, r1 error) {
|
||||
defaultHook: func(context.Context, authz.SubRepoPermissionChecker, api.RepoName, string, *BlameOptions) (r0 []*Hunk, r1 error) {
|
||||
return
|
||||
},
|
||||
},
|
||||
@ -165,7 +164,7 @@ func NewMockClient() *MockClient {
|
||||
},
|
||||
},
|
||||
DiffPathFunc: &ClientDiffPathFunc{
|
||||
defaultHook: func(context.Context, api.RepoName, string, string, string, authz.SubRepoPermissionChecker) (r0 []*diff.Hunk, r1 error) {
|
||||
defaultHook: func(context.Context, authz.SubRepoPermissionChecker, api.RepoName, string, string, string) (r0 []*diff.Hunk, r1 error) {
|
||||
return
|
||||
},
|
||||
},
|
||||
@ -225,7 +224,7 @@ func NewMockClient() *MockClient {
|
||||
},
|
||||
},
|
||||
ReadDirFunc: &ClientReadDirFunc{
|
||||
defaultHook: func(context.Context, database.DB, authz.SubRepoPermissionChecker, api.RepoName, api.CommitID, string, bool) (r0 []fs.FileInfo, r1 error) {
|
||||
defaultHook: func(context.Context, authz.SubRepoPermissionChecker, api.RepoName, api.CommitID, string, bool) (r0 []fs.FileInfo, r1 error) {
|
||||
return
|
||||
},
|
||||
},
|
||||
@ -322,7 +321,7 @@ func NewStrictMockClient() *MockClient {
|
||||
},
|
||||
},
|
||||
BlameFileFunc: &ClientBlameFileFunc{
|
||||
defaultHook: func(context.Context, api.RepoName, string, *BlameOptions, authz.SubRepoPermissionChecker) ([]*Hunk, error) {
|
||||
defaultHook: func(context.Context, authz.SubRepoPermissionChecker, api.RepoName, string, *BlameOptions) ([]*Hunk, error) {
|
||||
panic("unexpected invocation of MockClient.BlameFile")
|
||||
},
|
||||
},
|
||||
@ -332,7 +331,7 @@ func NewStrictMockClient() *MockClient {
|
||||
},
|
||||
},
|
||||
DiffPathFunc: &ClientDiffPathFunc{
|
||||
defaultHook: func(context.Context, api.RepoName, string, string, string, authz.SubRepoPermissionChecker) ([]*diff.Hunk, error) {
|
||||
defaultHook: func(context.Context, authz.SubRepoPermissionChecker, api.RepoName, string, string, string) ([]*diff.Hunk, error) {
|
||||
panic("unexpected invocation of MockClient.DiffPath")
|
||||
},
|
||||
},
|
||||
@ -392,7 +391,7 @@ func NewStrictMockClient() *MockClient {
|
||||
},
|
||||
},
|
||||
ReadDirFunc: &ClientReadDirFunc{
|
||||
defaultHook: func(context.Context, database.DB, authz.SubRepoPermissionChecker, api.RepoName, api.CommitID, string, bool) ([]fs.FileInfo, error) {
|
||||
defaultHook: func(context.Context, authz.SubRepoPermissionChecker, api.RepoName, api.CommitID, string, bool) ([]fs.FileInfo, error) {
|
||||
panic("unexpected invocation of MockClient.ReadDir")
|
||||
},
|
||||
},
|
||||
@ -1100,15 +1099,15 @@ func (c ClientBatchLogFuncCall) Results() []interface{} {
|
||||
// ClientBlameFileFunc describes the behavior when the BlameFile method of
|
||||
// the parent MockClient instance is invoked.
|
||||
type ClientBlameFileFunc struct {
|
||||
defaultHook func(context.Context, api.RepoName, string, *BlameOptions, authz.SubRepoPermissionChecker) ([]*Hunk, error)
|
||||
hooks []func(context.Context, api.RepoName, string, *BlameOptions, authz.SubRepoPermissionChecker) ([]*Hunk, error)
|
||||
defaultHook func(context.Context, authz.SubRepoPermissionChecker, api.RepoName, string, *BlameOptions) ([]*Hunk, error)
|
||||
hooks []func(context.Context, authz.SubRepoPermissionChecker, api.RepoName, string, *BlameOptions) ([]*Hunk, error)
|
||||
history []ClientBlameFileFuncCall
|
||||
mutex sync.Mutex
|
||||
}
|
||||
|
||||
// BlameFile delegates to the next hook function in the queue and stores the
|
||||
// parameter and result values of this invocation.
|
||||
func (m *MockClient) BlameFile(v0 context.Context, v1 api.RepoName, v2 string, v3 *BlameOptions, v4 authz.SubRepoPermissionChecker) ([]*Hunk, error) {
|
||||
func (m *MockClient) BlameFile(v0 context.Context, v1 authz.SubRepoPermissionChecker, v2 api.RepoName, v3 string, v4 *BlameOptions) ([]*Hunk, error) {
|
||||
r0, r1 := m.BlameFileFunc.nextHook()(v0, v1, v2, v3, v4)
|
||||
m.BlameFileFunc.appendCall(ClientBlameFileFuncCall{v0, v1, v2, v3, v4, r0, r1})
|
||||
return r0, r1
|
||||
@ -1116,7 +1115,7 @@ func (m *MockClient) BlameFile(v0 context.Context, v1 api.RepoName, v2 string, v
|
||||
|
||||
// SetDefaultHook sets function that is called when the BlameFile method of
|
||||
// the parent MockClient instance is invoked and the hook queue is empty.
|
||||
func (f *ClientBlameFileFunc) SetDefaultHook(hook func(context.Context, api.RepoName, string, *BlameOptions, authz.SubRepoPermissionChecker) ([]*Hunk, error)) {
|
||||
func (f *ClientBlameFileFunc) SetDefaultHook(hook func(context.Context, authz.SubRepoPermissionChecker, api.RepoName, string, *BlameOptions) ([]*Hunk, error)) {
|
||||
f.defaultHook = hook
|
||||
}
|
||||
|
||||
@ -1124,7 +1123,7 @@ func (f *ClientBlameFileFunc) SetDefaultHook(hook func(context.Context, api.Repo
|
||||
// BlameFile method of the parent MockClient instance invokes the hook at
|
||||
// the front of the queue and discards it. After the queue is empty, the
|
||||
// default hook function is invoked for any future action.
|
||||
func (f *ClientBlameFileFunc) PushHook(hook func(context.Context, api.RepoName, string, *BlameOptions, authz.SubRepoPermissionChecker) ([]*Hunk, error)) {
|
||||
func (f *ClientBlameFileFunc) PushHook(hook func(context.Context, authz.SubRepoPermissionChecker, api.RepoName, string, *BlameOptions) ([]*Hunk, error)) {
|
||||
f.mutex.Lock()
|
||||
f.hooks = append(f.hooks, hook)
|
||||
f.mutex.Unlock()
|
||||
@ -1133,19 +1132,19 @@ func (f *ClientBlameFileFunc) PushHook(hook func(context.Context, api.RepoName,
|
||||
// SetDefaultReturn calls SetDefaultHook with a function that returns the
|
||||
// given values.
|
||||
func (f *ClientBlameFileFunc) SetDefaultReturn(r0 []*Hunk, r1 error) {
|
||||
f.SetDefaultHook(func(context.Context, api.RepoName, string, *BlameOptions, authz.SubRepoPermissionChecker) ([]*Hunk, error) {
|
||||
f.SetDefaultHook(func(context.Context, authz.SubRepoPermissionChecker, api.RepoName, string, *BlameOptions) ([]*Hunk, error) {
|
||||
return r0, r1
|
||||
})
|
||||
}
|
||||
|
||||
// PushReturn calls PushHook with a function that returns the given values.
|
||||
func (f *ClientBlameFileFunc) PushReturn(r0 []*Hunk, r1 error) {
|
||||
f.PushHook(func(context.Context, api.RepoName, string, *BlameOptions, authz.SubRepoPermissionChecker) ([]*Hunk, error) {
|
||||
f.PushHook(func(context.Context, authz.SubRepoPermissionChecker, api.RepoName, string, *BlameOptions) ([]*Hunk, error) {
|
||||
return r0, r1
|
||||
})
|
||||
}
|
||||
|
||||
func (f *ClientBlameFileFunc) nextHook() func(context.Context, api.RepoName, string, *BlameOptions, authz.SubRepoPermissionChecker) ([]*Hunk, error) {
|
||||
func (f *ClientBlameFileFunc) nextHook() func(context.Context, authz.SubRepoPermissionChecker, api.RepoName, string, *BlameOptions) ([]*Hunk, error) {
|
||||
f.mutex.Lock()
|
||||
defer f.mutex.Unlock()
|
||||
|
||||
@ -1183,16 +1182,16 @@ type ClientBlameFileFuncCall struct {
|
||||
Arg0 context.Context
|
||||
// Arg1 is the value of the 2nd argument passed to this method
|
||||
// invocation.
|
||||
Arg1 api.RepoName
|
||||
Arg1 authz.SubRepoPermissionChecker
|
||||
// Arg2 is the value of the 3rd argument passed to this method
|
||||
// invocation.
|
||||
Arg2 string
|
||||
Arg2 api.RepoName
|
||||
// Arg3 is the value of the 4th argument passed to this method
|
||||
// invocation.
|
||||
Arg3 *BlameOptions
|
||||
Arg3 string
|
||||
// Arg4 is the value of the 5th argument passed to this method
|
||||
// invocation.
|
||||
Arg4 authz.SubRepoPermissionChecker
|
||||
Arg4 *BlameOptions
|
||||
// Result0 is the value of the 1st result returned from this method
|
||||
// invocation.
|
||||
Result0 []*Hunk
|
||||
@ -1325,15 +1324,15 @@ func (c ClientCreateCommitFromPatchFuncCall) Results() []interface{} {
|
||||
// ClientDiffPathFunc describes the behavior when the DiffPath method of the
|
||||
// parent MockClient instance is invoked.
|
||||
type ClientDiffPathFunc struct {
|
||||
defaultHook func(context.Context, api.RepoName, string, string, string, authz.SubRepoPermissionChecker) ([]*diff.Hunk, error)
|
||||
hooks []func(context.Context, api.RepoName, string, string, string, authz.SubRepoPermissionChecker) ([]*diff.Hunk, error)
|
||||
defaultHook func(context.Context, authz.SubRepoPermissionChecker, api.RepoName, string, string, string) ([]*diff.Hunk, error)
|
||||
hooks []func(context.Context, authz.SubRepoPermissionChecker, api.RepoName, string, string, string) ([]*diff.Hunk, error)
|
||||
history []ClientDiffPathFuncCall
|
||||
mutex sync.Mutex
|
||||
}
|
||||
|
||||
// DiffPath delegates to the next hook function in the queue and stores the
|
||||
// parameter and result values of this invocation.
|
||||
func (m *MockClient) DiffPath(v0 context.Context, v1 api.RepoName, v2 string, v3 string, v4 string, v5 authz.SubRepoPermissionChecker) ([]*diff.Hunk, error) {
|
||||
func (m *MockClient) DiffPath(v0 context.Context, v1 authz.SubRepoPermissionChecker, v2 api.RepoName, v3 string, v4 string, v5 string) ([]*diff.Hunk, error) {
|
||||
r0, r1 := m.DiffPathFunc.nextHook()(v0, v1, v2, v3, v4, v5)
|
||||
m.DiffPathFunc.appendCall(ClientDiffPathFuncCall{v0, v1, v2, v3, v4, v5, r0, r1})
|
||||
return r0, r1
|
||||
@ -1341,7 +1340,7 @@ func (m *MockClient) DiffPath(v0 context.Context, v1 api.RepoName, v2 string, v3
|
||||
|
||||
// SetDefaultHook sets function that is called when the DiffPath method of
|
||||
// the parent MockClient instance is invoked and the hook queue is empty.
|
||||
func (f *ClientDiffPathFunc) SetDefaultHook(hook func(context.Context, api.RepoName, string, string, string, authz.SubRepoPermissionChecker) ([]*diff.Hunk, error)) {
|
||||
func (f *ClientDiffPathFunc) SetDefaultHook(hook func(context.Context, authz.SubRepoPermissionChecker, api.RepoName, string, string, string) ([]*diff.Hunk, error)) {
|
||||
f.defaultHook = hook
|
||||
}
|
||||
|
||||
@ -1349,7 +1348,7 @@ func (f *ClientDiffPathFunc) SetDefaultHook(hook func(context.Context, api.RepoN
|
||||
// DiffPath method of the parent MockClient instance invokes the hook at the
|
||||
// front of the queue and discards it. After the queue is empty, the default
|
||||
// hook function is invoked for any future action.
|
||||
func (f *ClientDiffPathFunc) PushHook(hook func(context.Context, api.RepoName, string, string, string, authz.SubRepoPermissionChecker) ([]*diff.Hunk, error)) {
|
||||
func (f *ClientDiffPathFunc) PushHook(hook func(context.Context, authz.SubRepoPermissionChecker, api.RepoName, string, string, string) ([]*diff.Hunk, error)) {
|
||||
f.mutex.Lock()
|
||||
f.hooks = append(f.hooks, hook)
|
||||
f.mutex.Unlock()
|
||||
@ -1358,19 +1357,19 @@ func (f *ClientDiffPathFunc) PushHook(hook func(context.Context, api.RepoName, s
|
||||
// SetDefaultReturn calls SetDefaultHook with a function that returns the
|
||||
// given values.
|
||||
func (f *ClientDiffPathFunc) SetDefaultReturn(r0 []*diff.Hunk, r1 error) {
|
||||
f.SetDefaultHook(func(context.Context, api.RepoName, string, string, string, authz.SubRepoPermissionChecker) ([]*diff.Hunk, error) {
|
||||
f.SetDefaultHook(func(context.Context, authz.SubRepoPermissionChecker, api.RepoName, string, string, string) ([]*diff.Hunk, error) {
|
||||
return r0, r1
|
||||
})
|
||||
}
|
||||
|
||||
// PushReturn calls PushHook with a function that returns the given values.
|
||||
func (f *ClientDiffPathFunc) PushReturn(r0 []*diff.Hunk, r1 error) {
|
||||
f.PushHook(func(context.Context, api.RepoName, string, string, string, authz.SubRepoPermissionChecker) ([]*diff.Hunk, error) {
|
||||
f.PushHook(func(context.Context, authz.SubRepoPermissionChecker, api.RepoName, string, string, string) ([]*diff.Hunk, error) {
|
||||
return r0, r1
|
||||
})
|
||||
}
|
||||
|
||||
func (f *ClientDiffPathFunc) nextHook() func(context.Context, api.RepoName, string, string, string, authz.SubRepoPermissionChecker) ([]*diff.Hunk, error) {
|
||||
func (f *ClientDiffPathFunc) nextHook() func(context.Context, authz.SubRepoPermissionChecker, api.RepoName, string, string, string) ([]*diff.Hunk, error) {
|
||||
f.mutex.Lock()
|
||||
defer f.mutex.Unlock()
|
||||
|
||||
@ -1408,10 +1407,10 @@ type ClientDiffPathFuncCall struct {
|
||||
Arg0 context.Context
|
||||
// Arg1 is the value of the 2nd argument passed to this method
|
||||
// invocation.
|
||||
Arg1 api.RepoName
|
||||
Arg1 authz.SubRepoPermissionChecker
|
||||
// Arg2 is the value of the 3rd argument passed to this method
|
||||
// invocation.
|
||||
Arg2 string
|
||||
Arg2 api.RepoName
|
||||
// Arg3 is the value of the 4th argument passed to this method
|
||||
// invocation.
|
||||
Arg3 string
|
||||
@ -1420,7 +1419,7 @@ type ClientDiffPathFuncCall struct {
|
||||
Arg4 string
|
||||
// Arg5 is the value of the 6th argument passed to this method
|
||||
// invocation.
|
||||
Arg5 authz.SubRepoPermissionChecker
|
||||
Arg5 string
|
||||
// Result0 is the value of the 1st result returned from this method
|
||||
// invocation.
|
||||
Result0 []*diff.Hunk
|
||||
@ -2655,23 +2654,23 @@ func (c ClientP4ExecFuncCall) Results() []interface{} {
|
||||
// ClientReadDirFunc describes the behavior when the ReadDir method of the
|
||||
// parent MockClient instance is invoked.
|
||||
type ClientReadDirFunc struct {
|
||||
defaultHook func(context.Context, database.DB, authz.SubRepoPermissionChecker, api.RepoName, api.CommitID, string, bool) ([]fs.FileInfo, error)
|
||||
hooks []func(context.Context, database.DB, authz.SubRepoPermissionChecker, api.RepoName, api.CommitID, string, bool) ([]fs.FileInfo, error)
|
||||
defaultHook func(context.Context, authz.SubRepoPermissionChecker, api.RepoName, api.CommitID, string, bool) ([]fs.FileInfo, error)
|
||||
hooks []func(context.Context, authz.SubRepoPermissionChecker, api.RepoName, api.CommitID, string, bool) ([]fs.FileInfo, error)
|
||||
history []ClientReadDirFuncCall
|
||||
mutex sync.Mutex
|
||||
}
|
||||
|
||||
// ReadDir delegates to the next hook function in the queue and stores the
|
||||
// parameter and result values of this invocation.
|
||||
func (m *MockClient) ReadDir(v0 context.Context, v1 database.DB, v2 authz.SubRepoPermissionChecker, v3 api.RepoName, v4 api.CommitID, v5 string, v6 bool) ([]fs.FileInfo, error) {
|
||||
r0, r1 := m.ReadDirFunc.nextHook()(v0, v1, v2, v3, v4, v5, v6)
|
||||
m.ReadDirFunc.appendCall(ClientReadDirFuncCall{v0, v1, v2, v3, v4, v5, v6, r0, r1})
|
||||
func (m *MockClient) ReadDir(v0 context.Context, v1 authz.SubRepoPermissionChecker, v2 api.RepoName, v3 api.CommitID, v4 string, v5 bool) ([]fs.FileInfo, error) {
|
||||
r0, r1 := m.ReadDirFunc.nextHook()(v0, v1, v2, v3, v4, v5)
|
||||
m.ReadDirFunc.appendCall(ClientReadDirFuncCall{v0, v1, v2, v3, v4, v5, r0, r1})
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// SetDefaultHook sets function that is called when the ReadDir method of
|
||||
// the parent MockClient instance is invoked and the hook queue is empty.
|
||||
func (f *ClientReadDirFunc) SetDefaultHook(hook func(context.Context, database.DB, authz.SubRepoPermissionChecker, api.RepoName, api.CommitID, string, bool) ([]fs.FileInfo, error)) {
|
||||
func (f *ClientReadDirFunc) SetDefaultHook(hook func(context.Context, authz.SubRepoPermissionChecker, api.RepoName, api.CommitID, string, bool) ([]fs.FileInfo, error)) {
|
||||
f.defaultHook = hook
|
||||
}
|
||||
|
||||
@ -2679,7 +2678,7 @@ func (f *ClientReadDirFunc) SetDefaultHook(hook func(context.Context, database.D
|
||||
// ReadDir method of the parent MockClient instance invokes the hook at the
|
||||
// front of the queue and discards it. After the queue is empty, the default
|
||||
// hook function is invoked for any future action.
|
||||
func (f *ClientReadDirFunc) PushHook(hook func(context.Context, database.DB, authz.SubRepoPermissionChecker, api.RepoName, api.CommitID, string, bool) ([]fs.FileInfo, error)) {
|
||||
func (f *ClientReadDirFunc) PushHook(hook func(context.Context, authz.SubRepoPermissionChecker, api.RepoName, api.CommitID, string, bool) ([]fs.FileInfo, error)) {
|
||||
f.mutex.Lock()
|
||||
f.hooks = append(f.hooks, hook)
|
||||
f.mutex.Unlock()
|
||||
@ -2688,19 +2687,19 @@ func (f *ClientReadDirFunc) PushHook(hook func(context.Context, database.DB, aut
|
||||
// SetDefaultReturn calls SetDefaultHook with a function that returns the
|
||||
// given values.
|
||||
func (f *ClientReadDirFunc) SetDefaultReturn(r0 []fs.FileInfo, r1 error) {
|
||||
f.SetDefaultHook(func(context.Context, database.DB, authz.SubRepoPermissionChecker, api.RepoName, api.CommitID, string, bool) ([]fs.FileInfo, error) {
|
||||
f.SetDefaultHook(func(context.Context, authz.SubRepoPermissionChecker, api.RepoName, api.CommitID, string, bool) ([]fs.FileInfo, error) {
|
||||
return r0, r1
|
||||
})
|
||||
}
|
||||
|
||||
// PushReturn calls PushHook with a function that returns the given values.
|
||||
func (f *ClientReadDirFunc) PushReturn(r0 []fs.FileInfo, r1 error) {
|
||||
f.PushHook(func(context.Context, database.DB, authz.SubRepoPermissionChecker, api.RepoName, api.CommitID, string, bool) ([]fs.FileInfo, error) {
|
||||
f.PushHook(func(context.Context, authz.SubRepoPermissionChecker, api.RepoName, api.CommitID, string, bool) ([]fs.FileInfo, error) {
|
||||
return r0, r1
|
||||
})
|
||||
}
|
||||
|
||||
func (f *ClientReadDirFunc) nextHook() func(context.Context, database.DB, authz.SubRepoPermissionChecker, api.RepoName, api.CommitID, string, bool) ([]fs.FileInfo, error) {
|
||||
func (f *ClientReadDirFunc) nextHook() func(context.Context, authz.SubRepoPermissionChecker, api.RepoName, api.CommitID, string, bool) ([]fs.FileInfo, error) {
|
||||
f.mutex.Lock()
|
||||
defer f.mutex.Unlock()
|
||||
|
||||
@ -2738,22 +2737,19 @@ type ClientReadDirFuncCall struct {
|
||||
Arg0 context.Context
|
||||
// Arg1 is the value of the 2nd argument passed to this method
|
||||
// invocation.
|
||||
Arg1 database.DB
|
||||
Arg1 authz.SubRepoPermissionChecker
|
||||
// Arg2 is the value of the 3rd argument passed to this method
|
||||
// invocation.
|
||||
Arg2 authz.SubRepoPermissionChecker
|
||||
Arg2 api.RepoName
|
||||
// Arg3 is the value of the 4th argument passed to this method
|
||||
// invocation.
|
||||
Arg3 api.RepoName
|
||||
Arg3 api.CommitID
|
||||
// Arg4 is the value of the 5th argument passed to this method
|
||||
// invocation.
|
||||
Arg4 api.CommitID
|
||||
Arg4 string
|
||||
// Arg5 is the value of the 6th argument passed to this method
|
||||
// invocation.
|
||||
Arg5 string
|
||||
// Arg6 is the value of the 7th argument passed to this method
|
||||
// invocation.
|
||||
Arg6 bool
|
||||
Arg5 bool
|
||||
// Result0 is the value of the 1st result returned from this method
|
||||
// invocation.
|
||||
Result0 []fs.FileInfo
|
||||
@ -2765,7 +2761,7 @@ type ClientReadDirFuncCall struct {
|
||||
// Args returns an interface slice containing the arguments of this
|
||||
// invocation.
|
||||
func (c ClientReadDirFuncCall) Args() []interface{} {
|
||||
return []interface{}{c.Arg0, c.Arg1, c.Arg2, c.Arg3, c.Arg4, c.Arg5, c.Arg6}
|
||||
return []interface{}{c.Arg0, c.Arg1, c.Arg2, c.Arg3, c.Arg4, c.Arg5}
|
||||
}
|
||||
|
||||
// Results returns an interface slice containing the results of this
|
||||
|
||||
@ -32,7 +32,7 @@ func New(listener net.Listener, httpServer *http.Server, options ...ServerOption
|
||||
return newServer(httpServer, makeListener, options...)
|
||||
}
|
||||
|
||||
// New returns a BackgroundRoutine that serves the given handler on the given address.
|
||||
// NewFromAddr returns a BackgroundRoutine that serves the given handler on the given address.
|
||||
func NewFromAddr(addr string, httpServer *http.Server, options ...ServerOptions) goroutine.BackgroundRoutine {
|
||||
makeListener := func() (net.Listener, error) { return NewListener(addr) }
|
||||
return newServer(httpServer, makeListener, options...)
|
||||
|
||||
@ -1,16 +0,0 @@
|
||||
package util
|
||||
|
||||
import "strings"
|
||||
|
||||
// Rel strips the leading "/" prefix from the path string, effectively turning
|
||||
// an absolute path into one relative to the root directory. A path that is just
|
||||
// "/" is treated specially, returning just ".".
|
||||
//
|
||||
// The elements in a file path are separated by slash ('/', U+002F) characters,
|
||||
// regardless of host operating system convention.
|
||||
func Rel(path string) string {
|
||||
if path == "/" {
|
||||
return "."
|
||||
}
|
||||
return strings.TrimPrefix(path, "/")
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user