diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2022-07-08 14:04:13 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2022-07-13 14:16:15 +0300 |
commit | afdc310978b347617b61a4de18a6aef27c613041 (patch) | |
tree | 49d7d32229cf2eb31ea6fb3722168a2a5118c001 | |
parent | 125b89182dd190c73951e77c79707533909b91c3 (diff) |
repository: Fix commit-graphs referencing pruned commits after PruneUnreachableObjectspks-housekeeping-rewrite-commit-graph-on-prune
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 `PruneUnreachableObjects()` to do so.
Changelog: fixed
-rw-r--r-- | internal/gitaly/service/repository/prune_unreachable_objects.go | 9 | ||||
-rw-r--r-- | internal/gitaly/service/repository/prune_unreachable_objects_test.go | 12 |
2 files changed, 12 insertions, 9 deletions
diff --git a/internal/gitaly/service/repository/prune_unreachable_objects.go b/internal/gitaly/service/repository/prune_unreachable_objects.go index c648cbdff..2ba270830 100644 --- a/internal/gitaly/service/repository/prune_unreachable_objects.go +++ b/internal/gitaly/service/repository/prune_unreachable_objects.go @@ -4,6 +4,7 @@ import ( "context" "gitlab.com/gitlab-org/gitaly/v15/internal/git" + "gitlab.com/gitlab-org/gitaly/v15/internal/git/housekeeping" "gitlab.com/gitlab-org/gitaly/v15/internal/git/stats" "gitlab.com/gitlab-org/gitaly/v15/internal/helper" "gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb" @@ -38,6 +39,14 @@ func (s *server) PruneUnreachableObjects( return nil, helper.ErrInternalf("pruning objects: %w", err) } + // Rewrite the commit-graph so that it doesn't contain references to pruned commits + // anymore. + if err := housekeeping.WriteCommitGraph(ctx, repo, housekeeping.WriteCommitGraphConfig{ + ReplaceChain: true, + }); err != nil { + return nil, helper.ErrInternalf("rewriting commit-graph: %w", err) + } + stats.LogObjectsInfo(ctx, repo) return &gitalypb.PruneUnreachableObjectsResponse{}, nil diff --git a/internal/gitaly/service/repository/prune_unreachable_objects_test.go b/internal/gitaly/service/repository/prune_unreachable_objects_test.go index 434be71d6..440bb45dd 100644 --- a/internal/gitaly/service/repository/prune_unreachable_objects_test.go +++ b/internal/gitaly/service/repository/prune_unreachable_objects_test.go @@ -1,8 +1,6 @@ package repository import ( - "bytes" - "fmt" "os" "path/filepath" "testing" @@ -158,12 +156,8 @@ func TestPruneUnreachableObjects(t *testing.T) { }) require.NoError(t, err) - // The commit-graph chain now refers to the pruned commit, and git-commit-graph(1) - // should complain about that. - var stderr bytes.Buffer - 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)) + // The commit-graph chain should have been rewritten by PruneUnreachableObjects so + // that it doesn't refer to the pruned commit anymore. + gittest.Exec(t, cfg, "-C", repoPath, "commit-graph", "verify") }) } |