diff options
author | Sami Hiltunen <shiltunen@gitlab.com> | 2023-07-12 16:26:08 +0300 |
---|---|---|
committer | Sami Hiltunen <shiltunen@gitlab.com> | 2023-07-18 08:19:57 +0300 |
commit | 2160e1c31437d5e3c1b544c794df9140aed1050c (patch) | |
tree | a2830f84f2e59d104800af43a553490257ea716d | |
parent | 0edce29afa26faf93c63a1f9ef451349709a892b (diff) |
Add only the configured object directory as an alternate
Quarantining works by pointing the object directory to the quarantine
directory and setting the original object directroy as an alternate.
This way all object writes will end up in the quarantine but the
original objects remain available through the alternate.
Apply is currently unconditionally setting 'objects' as an alternate.
If a repository that has already been quarantined is quarantined again,
this leads to adding duplicate 'objects' entries in the alternates. Fix
this by adding 'objects' as an alternate only if the repository didn't
have another object directory already configured.
-rw-r--r-- | internal/git/quarantine/quarantine.go | 13 | ||||
-rw-r--r-- | internal/git/quarantine/quarantine_test.go | 4 |
2 files changed, 11 insertions, 6 deletions
diff --git a/internal/git/quarantine/quarantine.go b/internal/git/quarantine/quarantine.go index 4d2c0463e..0adbeab58 100644 --- a/internal/git/quarantine/quarantine.go +++ b/internal/git/quarantine/quarantine.go @@ -59,7 +59,7 @@ func New(ctx context.Context, repo *gitalypb.Repository, locator storage.Locator } // Apply applies the quarantine on the repository. This is done by setting the quarantineDirectory -// as the repository's object directory, and configuring the original object directory as an alternate. +// as the repository's object directory, and configuring the repository's object directory as an alternate. func Apply(repoPath string, repo *gitalypb.Repository, quarantineDir string) (*gitalypb.Repository, error) { relativePath, err := filepath.Rel(repoPath, quarantineDir) if err != nil { @@ -67,10 +67,15 @@ func Apply(repoPath string, repo *gitalypb.Repository, quarantineDir string) (*g } // All paths are relative to the repository root. - alternateObjectDirs := []string{"objects"} - if repo.GetGitObjectDirectory() != "" { - alternateObjectDirs = append(alternateObjectDirs, repo.GetGitObjectDirectory()) + objectDir := repo.GitObjectDirectory + if objectDir == "" { + // Set the default object directory as an alternate if the repository didn't + // have the object directory overwritten yet. + objectDir = "objects" } + + alternateObjectDirs := make([]string, 0, len(repo.GetGitAlternateObjectDirectories())+1) + alternateObjectDirs = append(alternateObjectDirs, objectDir) alternateObjectDirs = append(alternateObjectDirs, repo.GetGitAlternateObjectDirectories()...) quarantinedRepo := proto.Clone(repo).(*gitalypb.Repository) diff --git a/internal/git/quarantine/quarantine_test.go b/internal/git/quarantine/quarantine_test.go index 87ed71db7..9f74a9b71 100644 --- a/internal/git/quarantine/quarantine_test.go +++ b/internal/git/quarantine/quarantine_test.go @@ -180,7 +180,7 @@ func TestApply(t *testing.T) { expectedRepo: &gitalypb.Repository{ StorageName: repo.StorageName, GitObjectDirectory: relPath, - GitAlternateObjectDirectories: []string{"objects", "custom_directory"}, + GitAlternateObjectDirectories: []string{"custom_directory"}, RelativePath: repo.RelativePath, GlProjectPath: repo.GlProjectPath, GlRepository: repo.GlRepository, @@ -193,7 +193,7 @@ func TestApply(t *testing.T) { expectedRepo: &gitalypb.Repository{ StorageName: repo.StorageName, GitObjectDirectory: relPath, - GitAlternateObjectDirectories: []string{"objects", "custom_directory", "alternate_directory"}, + GitAlternateObjectDirectories: []string{"custom_directory", "alternate_directory"}, RelativePath: repo.RelativePath, GlProjectPath: repo.GlProjectPath, GlRepository: repo.GlRepository, |