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-27 23:43:49 +0300
committerJames Fargher <jfargher@gitlab.com>2023-04-27 23:43:49 +0300
commit6976ed71b547371fb5096ab3e1ace79666c9eace (patch)
treeff3faae4262383ac8d0545f7da5db12f7ed17c7a
parentcf1ebbe25f2201887a1fdedb2c984b01f2ea19a1 (diff)
backup: Accept io.Writer in backup.Repository.GetCustomHooks
Soon we will be implementing backup.Repository using localrepo and that version of GetCustomHooks accepts an io.Writer. It isn't very efficient to convert an io.Writer into a io.Reader so instead we adjust the interface.
-rw-r--r--internal/backup/backup.go8
-rw-r--r--internal/backup/repository.go13
2 files changed, 11 insertions, 10 deletions
diff --git a/internal/backup/backup.go b/internal/backup/backup.go
index 92358fea6..dc4f1ae06 100644
--- a/internal/backup/backup.go
+++ b/internal/backup/backup.go
@@ -81,7 +81,7 @@ type Repository interface {
// ListRefs fetches the full set of refs and targets for the repository.
ListRefs(ctx context.Context) ([]git.Reference, error)
// GetCustomHooks fetches the custom hooks archive.
- GetCustomHooks(ctx context.Context) (io.Reader, error)
+ GetCustomHooks(ctx context.Context, out io.Writer) error
// CreateBundle fetches a bundle that contains refs matching patterns.
CreateBundle(ctx context.Context, out io.Writer, patterns io.Reader) error
}
@@ -457,14 +457,10 @@ func (mgr *Manager) restoreBundle(ctx context.Context, path string, server stora
}
func (mgr *Manager) writeCustomHooks(ctx context.Context, repo Repository, path string) error {
- hooks, err := repo.GetCustomHooks(ctx)
- if err != nil {
- return fmt.Errorf("write custom hooks: %w", err)
- }
w := NewLazyWriter(func() (io.WriteCloser, error) {
return mgr.sink.GetWriter(ctx, path)
})
- if _, err := io.Copy(w, hooks); err != nil {
+ if err := repo.GetCustomHooks(ctx, w); err != nil {
return fmt.Errorf("write custom hooks: %w", err)
}
return nil
diff --git a/internal/backup/repository.go b/internal/backup/repository.go
index 1249d214b..13335d2a6 100644
--- a/internal/backup/repository.go
+++ b/internal/backup/repository.go
@@ -76,17 +76,22 @@ func (rr *remoteRepository) ListRefs(ctx context.Context) ([]git.Reference, erro
}
// GetCustomHooks fetches the custom hooks archive.
-func (rr *remoteRepository) GetCustomHooks(ctx context.Context) (io.Reader, error) {
+func (rr *remoteRepository) GetCustomHooks(ctx context.Context, out io.Writer) error {
repoClient := rr.newRepoClient()
stream, err := repoClient.GetCustomHooks(ctx, &gitalypb.GetCustomHooksRequest{Repository: rr.repo})
if err != nil {
- return nil, fmt.Errorf("remote repository: get custom hooks: %w", err)
+ return fmt.Errorf("remote repository: get custom hooks: %w", err)
}
- return streamio.NewReader(func() ([]byte, error) {
+ hooks := streamio.NewReader(func() ([]byte, error) {
resp, err := stream.Recv()
return resp.GetData(), err
- }), nil
+ })
+ if _, err := io.Copy(out, hooks); err != nil {
+ return fmt.Errorf("remote repository: get custom hooks: %w", err)
+ }
+
+ return nil
}
// CreateBundle fetches a bundle that contains refs matching patterns.