Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Fargher <jfargher@gitlab.com>2023-04-18 01:24:15 +0300
committerJames Fargher <jfargher@gitlab.com>2023-04-18 01:25:10 +0300
commit445c2db73af949f4f7145ffdd4d444ee8b0ab45b (patch)
tree99a7a859c0fc3622933b47519617360196314535
parentd711b0367ad9f487636517d7f6c1d0c7e3223d21 (diff)
backup: Change ListRefs to GetReferences
Changing ListRefs to GetReferences on remoteRepo in order to exactly match the interface on localrepo.Repo.
-rw-r--r--internal/backup/backup.go6
-rw-r--r--internal/backup/repository.go15
2 files changed, 13 insertions, 8 deletions
diff --git a/internal/backup/backup.go b/internal/backup/backup.go
index 23dbbe523..7d1c0506c 100644
--- a/internal/backup/backup.go
+++ b/internal/backup/backup.go
@@ -79,8 +79,8 @@ type Repository interface {
// HasBranches determines whether there is at least one branch in the
// repository.
HasBranches(ctx context.Context) (bool, error)
- // ListRefs fetches the full set of refs and targets for the repository.
- ListRefs(ctx context.Context) ([]git.Reference, error)
+ // GetReferences returns references matching any of the given patterns.
+ GetReferences(ctx context.Context, patterns ...string) ([]git.Reference, error)
// GetCustomHooks fetches the custom hooks archive.
GetCustomHooks(ctx context.Context) (io.Reader, error)
// CreateBundle fetches a bundle that contains refs matching patterns.
@@ -198,7 +198,7 @@ func (mgr *Manager) Create(ctx context.Context, req *CreateRequest) error {
step = mgr.locator.BeginFull(ctx, req.Repository, mgr.backupID)
}
- refs, err := repo.ListRefs(ctx)
+ refs, err := repo.GetReferences(ctx, "refs/")
if err != nil {
return fmt.Errorf("manager: %w", err)
}
diff --git a/internal/backup/repository.go b/internal/backup/repository.go
index 8ee48e0b8..60ae03448 100644
--- a/internal/backup/repository.go
+++ b/internal/backup/repository.go
@@ -47,16 +47,21 @@ func (rr *remoteRepository) HasBranches(ctx context.Context) (bool, error) {
return hasLocalBranches.GetValue(), nil
}
-// ListRefs fetches the full set of refs and targets for the repository
-func (rr *remoteRepository) ListRefs(ctx context.Context) ([]git.Reference, error) {
+// GetReferences returns references matching any of the given patterns.
+func (rr *remoteRepository) GetReferences(ctx context.Context, patterns ...string) ([]git.Reference, error) {
+ bytePatterns := make([][]byte, len(patterns))
+ for i := range patterns {
+ bytePatterns[i] = []byte(patterns[i])
+ }
+
refClient := rr.newRefClient()
stream, err := refClient.ListRefs(ctx, &gitalypb.ListRefsRequest{
Repository: rr.repo,
Head: true,
- Patterns: [][]byte{[]byte("refs/")},
+ Patterns: bytePatterns,
})
if err != nil {
- return nil, fmt.Errorf("remote repository: list refs: %w", err)
+ return nil, fmt.Errorf("remote repository: get references: %w", err)
}
var refs []git.Reference
@@ -66,7 +71,7 @@ func (rr *remoteRepository) ListRefs(ctx context.Context) ([]git.Reference, erro
if errors.Is(err, io.EOF) {
break
} else if err != nil {
- return nil, fmt.Errorf("remote repository: list refs: %w", err)
+ return nil, fmt.Errorf("remote repository: get references: %w", err)
}
for _, ref := range resp.GetReferences() {
refs = append(refs, git.NewReference(git.ReferenceName(ref.GetName()), ref.GetTarget()))