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:
authorPatrick Steinhardt <psteinhardt@gitlab.com>2022-10-20 08:52:16 +0300
committerPatrick Steinhardt <psteinhardt@gitlab.com>2022-10-28 07:49:54 +0300
commit9a815299173d016a57228a4726a1e1a2f0f705aa (patch)
tree8c4e6453ac02ff2bb98eb76e84ae96276380b082
parent672962358ad5b12ed698a0cab8da1c4be7bffd82 (diff)
housekeeping: Split up policy and mechanism to pack references
The policy to determine when we need to pack references is tightly coupled with the mechanism to run git-pack-refs(1). Split up these two concerns into standalone functions so that we can easily move the policy-part into the new optimization strategy infrastructure.
-rw-r--r--internal/git/housekeeping/optimize_repository.go33
1 files changed, 23 insertions, 10 deletions
diff --git a/internal/git/housekeeping/optimize_repository.go b/internal/git/housekeeping/optimize_repository.go
index 92df972a6..0bc6fbd7d 100644
--- a/internal/git/housekeeping/optimize_repository.go
+++ b/internal/git/housekeeping/optimize_repository.go
@@ -566,6 +566,29 @@ func countLooseAndPackedRefs(ctx context.Context, repo *localrepo.Repo) (int64,
}
func packRefsIfNeeded(ctx context.Context, repo *localrepo.Repo) (bool, error) {
+ shouldPackRefs, err := needsPackRefs(ctx, repo)
+ if err != nil {
+ return false, fmt.Errorf("determining whether repo needs to pack refs: %w", err)
+ }
+
+ if !shouldPackRefs {
+ return false, nil
+ }
+
+ var stderr bytes.Buffer
+ if err := repo.ExecAndWait(ctx, git.SubCmd{
+ Name: "pack-refs",
+ Flags: []git.Option{
+ git.Flag{Name: "--all"},
+ },
+ }, git.WithStderr(&stderr)); err != nil {
+ return false, fmt.Errorf("packing refs: %w, stderr: %q", err, stderr.String())
+ }
+
+ return true, nil
+}
+
+func needsPackRefs(ctx context.Context, repo *localrepo.Repo) (bool, error) {
looseRefs, packedRefsSize, err := countLooseAndPackedRefs(ctx, repo)
if err != nil {
return false, fmt.Errorf("counting refs: %w", err)
@@ -601,15 +624,5 @@ func packRefsIfNeeded(ctx context.Context, repo *localrepo.Repo) (bool, error) {
return false, nil
}
- var stderr bytes.Buffer
- if err := repo.ExecAndWait(ctx, git.SubCmd{
- Name: "pack-refs",
- Flags: []git.Option{
- git.Flag{Name: "--all"},
- },
- }, git.WithStderr(&stderr)); err != nil {
- return false, fmt.Errorf("packing refs: %w, stderr: %q", err, stderr.String())
- }
-
return true, nil
}