diff options
author | Justin Tobler <jtobler@gitlab.com> | 2023-08-30 00:12:15 +0300 |
---|---|---|
committer | Justin Tobler <jtobler@gitlab.com> | 2023-08-30 00:12:15 +0300 |
commit | 6e5e61165e08bbdccc2250d21b7c95006fa0272e (patch) | |
tree | 8ba37b00cdfc12b42205ddd5734a41867214a607 | |
parent | e5b9614de0ce665f2e5262e3f2dcd5ff00278c11 (diff) | |
parent | 94aaaf71d4be9f07315e8de1a5ce340012ceb3cd (diff) |
Merge branch 'smh-repoutil-no-locator' into 'master'
Pass repository path directly in GetCustomHooks
See merge request https://gitlab.com/gitlab-org/gitaly/-/merge_requests/6224
Merged-by: Justin Tobler <jtobler@gitlab.com>
Approved-by: Justin Tobler <jtobler@gitlab.com>
Co-authored-by: Sami Hiltunen <shiltunen@gitlab.com>
-rw-r--r-- | internal/backup/repository.go | 7 | ||||
-rw-r--r-- | internal/gitaly/repoutil/custom_hooks.go | 8 | ||||
-rw-r--r-- | internal/gitaly/repoutil/custom_hooks_test.go | 15 | ||||
-rw-r--r-- | internal/gitaly/service/repository/get_custom_hooks.go | 16 |
4 files changed, 27 insertions, 19 deletions
diff --git a/internal/backup/repository.go b/internal/backup/repository.go index 12762d496..65207cf78 100644 --- a/internal/backup/repository.go +++ b/internal/backup/repository.go @@ -299,7 +299,12 @@ func (r *localRepository) ListRefs(ctx context.Context) ([]git.Reference, error) // GetCustomHooks fetches the custom hooks archive. func (r *localRepository) GetCustomHooks(ctx context.Context, out io.Writer) error { - if err := repoutil.GetCustomHooks(ctx, r.locator, out, r.repo); err != nil { + repoPath, err := r.locator.GetRepoPath(r.repo) + if err != nil { + return fmt.Errorf("get repo path: %w", err) + } + + if err := repoutil.GetCustomHooks(ctx, repoPath, out); err != nil { return fmt.Errorf("local repository: get custom hooks: %w", err) } return nil diff --git a/internal/gitaly/repoutil/custom_hooks.go b/internal/gitaly/repoutil/custom_hooks.go index ebf60d585..b355ff924 100644 --- a/internal/gitaly/repoutil/custom_hooks.go +++ b/internal/gitaly/repoutil/custom_hooks.go @@ -34,15 +34,9 @@ const CustomHooksDir = "custom_hooks" // hooks are present in the repository, the response will have no data. func GetCustomHooks( ctx context.Context, - locator storage.Locator, + repoPath string, writer io.Writer, - repo storage.Repository, ) error { - repoPath, err := locator.GetRepoPath(repo) - if err != nil { - return fmt.Errorf("getting repo path: %w", err) - } - if _, err := os.Lstat(filepath.Join(repoPath, CustomHooksDir)); os.IsNotExist(err) { return nil } diff --git a/internal/gitaly/repoutil/custom_hooks_test.go b/internal/gitaly/repoutil/custom_hooks_test.go index cc97954ee..6151e9613 100644 --- a/internal/gitaly/repoutil/custom_hooks_test.go +++ b/internal/gitaly/repoutil/custom_hooks_test.go @@ -32,8 +32,7 @@ func TestGetCustomHooks_successful(t *testing.T) { ctx := testhelper.Context(t) cfg := testcfg.Build(t) - locator := config.NewLocator(cfg) - repo, repoPath := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{ + _, repoPath := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{ SkipCreationViaService: true, }) @@ -49,7 +48,7 @@ func TestGetCustomHooks_successful(t *testing.T) { } var hooks bytes.Buffer - require.NoError(t, GetCustomHooks(ctx, locator, &hooks, repo)) + require.NoError(t, GetCustomHooks(ctx, repoPath, &hooks)) reader := tar.NewReader(&hooks) fileLength := 0 @@ -70,8 +69,7 @@ func TestGetCustomHooks_symlink(t *testing.T) { ctx := testhelper.Context(t) cfg := testcfg.Build(t) - locator := config.NewLocator(cfg) - repo, repoPath := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{ + _, repoPath := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{ SkipCreationViaService: true, }) @@ -79,7 +77,7 @@ func TestGetCustomHooks_symlink(t *testing.T) { require.NoError(t, os.Symlink(linkTarget, filepath.Join(repoPath, "custom_hooks")), "Could not create custom_hooks symlink") var hooks bytes.Buffer - require.NoError(t, GetCustomHooks(ctx, locator, &hooks, repo)) + require.NoError(t, GetCustomHooks(ctx, repoPath, &hooks)) reader := tar.NewReader(&hooks) file, err := reader.Next() @@ -98,13 +96,12 @@ func TestGetCustomHooks_nonexistentHooks(t *testing.T) { ctx := testhelper.Context(t) cfg := testcfg.Build(t) - locator := config.NewLocator(cfg) - repo, _ := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{ + _, repoPath := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{ SkipCreationViaService: true, }) var hooks bytes.Buffer - require.NoError(t, GetCustomHooks(ctx, locator, &hooks, repo)) + require.NoError(t, GetCustomHooks(ctx, repoPath, &hooks)) reader := tar.NewReader(&hooks) buf := bytes.NewBuffer(nil) diff --git a/internal/gitaly/service/repository/get_custom_hooks.go b/internal/gitaly/service/repository/get_custom_hooks.go index 0e67f353c..caa916149 100644 --- a/internal/gitaly/service/repository/get_custom_hooks.go +++ b/internal/gitaly/service/repository/get_custom_hooks.go @@ -1,6 +1,8 @@ package repository import ( + "fmt" + "gitlab.com/gitlab-org/gitaly/v16/internal/gitaly/repoutil" "gitlab.com/gitlab-org/gitaly/v16/internal/structerr" "gitlab.com/gitlab-org/gitaly/v16/proto/go/gitalypb" @@ -21,7 +23,12 @@ func (s *server) GetCustomHooks(in *gitalypb.GetCustomHooksRequest, stream gital return stream.Send(&gitalypb.GetCustomHooksResponse{Data: p}) }) - if err := repoutil.GetCustomHooks(ctx, s.locator, writer, in.Repository); err != nil { + repoPath, err := s.locator.GetRepoPath(in.GetRepository()) + if err != nil { + return fmt.Errorf("get repo path: %w", err) + } + + if err := repoutil.GetCustomHooks(ctx, repoPath, writer); err != nil { return structerr.NewInternal("reading custom hooks: %w", err) } @@ -42,7 +49,12 @@ func (s *server) BackupCustomHooks(in *gitalypb.BackupCustomHooksRequest, stream return stream.Send(&gitalypb.BackupCustomHooksResponse{Data: p}) }) - if err := repoutil.GetCustomHooks(ctx, s.locator, writer, in.Repository); err != nil { + repoPath, err := s.locator.GetRepoPath(in.GetRepository()) + if err != nil { + return fmt.Errorf("get repo path: %w", err) + } + + if err := repoutil.GetCustomHooks(ctx, repoPath, writer); err != nil { return structerr.NewInternal("reading custom hooks: %w", err) } |