gitserver: Clarify what RepositoryLock indicates (#61862)

After refactoring to use the same locker for both tasks, this no longer only resembles cloneInProgress, so cleaned this up a little.

Test plan:

Existing test suites.
This commit is contained in:
Erik Seliger 2024-04-19 00:00:49 +02:00 committed by GitHub
parent f04f859ba8
commit a2b170dc9e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 14 additions and 6 deletions

View File

@ -20,11 +20,15 @@ func repoCloneProgress(fs gitserverfs.FS, locker RepositoryLocker, repo api.Repo
resp := protocol.RepoCloneProgress{
Cloned: cloned,
}
resp.CloneProgress, resp.CloneInProgress = locker.Status(repo)
cloneProgress, locked := locker.Status(repo)
if isAlwaysCloningTest(repo) {
resp.CloneInProgress = true
resp.CloneProgress = "This will never finish cloning"
}
if !cloned && locked {
resp.CloneInProgress = true
resp.CloneProgress = cloneProgress
}
return &resp, nil
}

View File

@ -1422,7 +1422,11 @@ func (gs *grpcServer) checkRepoExists(ctx context.Context, repo api.RepoName) er
}
}
cloneProgress, cloneInProgress := gs.locker.Status(repo)
cloneProgress, locked := gs.locker.Status(repo)
// We checked above that the repo is not cloned. So if the repo is currently
// locked, it must be a clone in progress.
cloneInProgress := locked
return newRepoNotFoundError(repo, cloneInProgress, cloneProgress)
}

View File

@ -14,11 +14,11 @@ import (
"github.com/sourcegraph/sourcegraph/internal/types"
)
func cloneStatus(cloned, cloning bool) types.CloneStatus {
func cloneStatus(cloned, locked bool) types.CloneStatus {
switch {
case cloned:
return types.CloneStatusCloned
case cloning:
case locked:
return types.CloneStatusCloning
}
return types.CloneStatusNotCloned

View File

@ -201,14 +201,14 @@ func syncRepoState(
// Failed to determine cloned state, we have to skip this record for now.
continue
}
_, cloning := locker.Status(repo.Name)
_, locked := locker.Status(repo.Name)
var shouldUpdate bool
if repo.ShardID != shardID {
repo.ShardID = shardID
shouldUpdate = true
}
cloneStatus := cloneStatus(cloned, cloning)
cloneStatus := cloneStatus(cloned, locked)
if repo.CloneStatus != cloneStatus {
repo.CloneStatus = cloneStatus
// Since the repo has been recloned or is being cloned