diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2022-07-15 09:38:06 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2022-07-15 16:15:30 +0300 |
commit | 0920b15a01e1fb7ac54fd36ae29802b2855d9e4b (patch) | |
tree | 6e85da9b32cd8f3fde6ea5d699c4847bcb00b169 | |
parent | e877b1dff41f3f26400578dbd6a3382748e1e0da (diff) |
repository: Fix commit-graphs referencing pruned commits after GC
When pruning objects we need to rewrite our commit-graphs so that they
don't reference any commits that have just been pruned. While this is
not typically an issue, git-fsck(1) will report any such inconsistencies
in the commit-graph. Furthermore, Git may return an error when being
asked to parse such a missing commit directly.
Fix `GarbageCollect()` to do so.
Changelog: fixed
-rw-r--r-- | internal/gitaly/service/repository/gc.go | 9 | ||||
-rw-r--r-- | internal/gitaly/service/repository/gc_test.go | 8 |
2 files changed, 5 insertions, 12 deletions
diff --git a/internal/gitaly/service/repository/gc.go b/internal/gitaly/service/repository/gc.go index 6ecf153ac..3acdaa6a0 100644 --- a/internal/gitaly/service/repository/gc.go +++ b/internal/gitaly/service/repository/gc.go @@ -51,12 +51,9 @@ func (s *server) GarbageCollect(ctx context.Context, in *gitalypb.GarbageCollect return nil, err } - writeCommitGraphCfg, err := housekeeping.WriteCommitGraphConfigForRepository(ctx, repo) - if err != nil { - return nil, helper.ErrInternalf("getting commit-graph config: %w", err) - } - - if err := housekeeping.WriteCommitGraph(ctx, repo, writeCommitGraphCfg); err != nil { + if err := housekeeping.WriteCommitGraph(ctx, repo, housekeeping.WriteCommitGraphConfig{ + ReplaceChain: true, + }); err != nil { return nil, err } diff --git a/internal/gitaly/service/repository/gc_test.go b/internal/gitaly/service/repository/gc_test.go index df9f425de..6d14c49f5 100644 --- a/internal/gitaly/service/repository/gc_test.go +++ b/internal/gitaly/service/repository/gc_test.go @@ -577,10 +577,6 @@ func TestGarbageCollect_commitGraphsWithPrunedObjects(t *testing.T) { _, err := client.GarbageCollect(ctx, &gitalypb.GarbageCollectRequest{Repository: repoProto}) require.NoError(t, err) - // ... but as it turns out it doesn't. - stderr.Reset() - verifyCmd = gittest.NewCommand(t, cfg, "-C", repoPath, "commit-graph", "verify") - verifyCmd.Stderr = &stderr - require.EqualError(t, verifyCmd.Run(), "exit status 1") - require.Equal(t, stderr.String(), fmt.Sprintf("error: Could not read %[1]s\nfailed to parse commit %[1]s from object database for commit-graph\n", unreachableCommitID)) + // ... and it does. + gittest.Exec(t, cfg, "-C", repoPath, "commit-graph", "verify") } |