Repository: restic/restic
Pull request #4818 (2024-05-25 10:08:53)

Move cache / index / hashing / pack packages
<!--
Thank you very much for contributing code or documentation to restic! Please
fill out the following questions to make it easier for us to review your
changes.
-->

What does this PR change? What problem does it solve?
-----------------------------------------------------
The `cache` is actually a backend, thus move it there.

The `index`, `hashing` and `pack` packages are implementation details of a repository and therefore belong there.
<!--
Describe the changes and their purpose here, as detailed as needed.
-->

Was the change previously discussed in an issue or on the forum?
----------------------------------------------------------------
No.
<!--
Link issues and relevant forum posts here.

If this PR resolves an issue on GitHub, use "Closes #1234" so that the issue
is closed automatically when this PR is merged.
-->

Checklist
---------

<!--
You do not need to check all the boxes below all at once. Feel free to take
your time and add more commits. If you're done and ready for review, please
check the last box. Enable a checkbox by replacing [ ] with [x].
-->

- [x] I have read the [contribution guidelines](https://github.com/restic/restic/blob/master/CONTRIBUTING.md#providing-patches).
- [x] I have [enabled maintainer edits](https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/allowing-changes-to-a-pull-request-branch-created-from-a-fork).
- ~~[ ] I have added tests for all code changes.~~
- ~~[ ] I have added documentation for relevant changes (in the manual).~~
- ~~[ ] There's a new file in `changelog/unreleased/` that describes the changes for our users (see [template](https://github.com/restic/restic/blob/master/changelog/TEMPLATE)).~~
- [x] I have run `gofmt` on the code in all commits.
- [x] All commit messages are formatted in the same style as [the other commits in the repo](https://github.com/restic/restic/blob/master/CONTRIBUTING.md#git-commits).
- [x] I'm done! This pull request is ready for review.



Patch:
diff --git a/cmd/restic/cmd_cache.go b/cmd/restic/cmd_cache.go
index 354cec288..651c65fcf 100644
--- a/cmd/restic/cmd_cache.go
+++ b/cmd/restic/cmd_cache.go
@@ -8,7 +8,7 @@ import (
 	"strings"
 	"time"
 
-	"github.com/restic/restic/internal/cache"
+	"github.com/restic/restic/internal/backend/cache"
 	"github.com/restic/restic/internal/errors"
 	"github.com/restic/restic/internal/fs"
 	"github.com/restic/restic/internal/ui"
diff --git a/cmd/restic/cmd_check.go b/cmd/restic/cmd_check.go
index 671cab0e6..11a1c7cb5 100644
--- a/cmd/restic/cmd_check.go
+++ b/cmd/restic/cmd_check.go
@@ -11,7 +11,7 @@ import (
 
 	"github.com/spf13/cobra"
 
-	"github.com/restic/restic/internal/cache"
+	"github.com/restic/restic/internal/backend/cache"
 	"github.com/restic/restic/internal/checker"
 	"github.com/restic/restic/internal/errors"
 	"github.com/restic/restic/internal/fs"
diff --git a/cmd/restic/cmd_debug.go b/cmd/restic/cmd_debug.go
index 7b0cdb53e..1a42995fd 100644
--- a/cmd/restic/cmd_debug.go
+++ b/cmd/restic/cmd_debug.go
@@ -22,9 +22,9 @@ import (
 
 	"github.com/restic/restic/internal/crypto"
 	"github.com/restic/restic/internal/errors"
-	"github.com/restic/restic/internal/index"
-	"github.com/restic/restic/internal/pack"
 	"github.com/restic/restic/internal/repository"
+	"github.com/restic/restic/internal/repository/index"
+	"github.com/restic/restic/internal/repository/pack"
 	"github.com/restic/restic/internal/restic"
 )
 
diff --git a/cmd/restic/cmd_list.go b/cmd/restic/cmd_list.go
index 27f59b4ab..6f4430420 100644
--- a/cmd/restic/cmd_list.go
+++ b/cmd/restic/cmd_list.go
@@ -4,7 +4,7 @@ import (
 	"context"
 
 	"github.com/restic/restic/internal/errors"
-	"github.com/restic/restic/internal/index"
+	"github.com/restic/restic/internal/repository/index"
 	"github.com/restic/restic/internal/restic"
 
 	"github.com/spf13/cobra"
diff --git a/cmd/restic/global.go b/cmd/restic/global.go
index 9671f2a26..144445cc0 100644
--- a/cmd/restic/global.go
+++ b/cmd/restic/global.go
@@ -15,6 +15,7 @@ import (
 	"github.com/restic/restic/internal/backend"
 	"github.com/restic/restic/internal/backend/azure"
 	"github.com/restic/restic/internal/backend/b2"
+	"github.com/restic/restic/internal/backend/cache"
 	"github.com/restic/restic/internal/backend/gs"
 	"github.com/restic/restic/internal/backend/limiter"
 	"github.com/restic/restic/internal/backend/local"
@@ -27,7 +28,6 @@ import (
 	"github.com/restic/restic/internal/backend/sema"
 	"github.com/restic/restic/internal/backend/sftp"
 	"github.com/restic/restic/internal/backend/swift"
-	"github.com/restic/restic/internal/cache"
 	"github.com/restic/restic/internal/debug"
 	"github.com/restic/restic/internal/fs"
 	"github.com/restic/restic/internal/options"
diff --git a/internal/cache/backend.go b/internal/backend/cache/backend.go
similarity index 100%
rename from internal/cache/backend.go
rename to internal/backend/cache/backend.go
diff --git a/internal/cache/backend_test.go b/internal/backend/cache/backend_test.go
similarity index 100%
rename from internal/cache/backend_test.go
rename to internal/backend/cache/backend_test.go
diff --git a/internal/cache/cache.go b/internal/backend/cache/cache.go
similarity index 100%
rename from internal/cache/cache.go
rename to internal/backend/cache/cache.go
diff --git a/internal/cache/cache_test.go b/internal/backend/cache/cache_test.go
similarity index 100%
rename from internal/cache/cache_test.go
rename to internal/backend/cache/cache_test.go
diff --git a/internal/cache/dir.go b/internal/backend/cache/dir.go
similarity index 100%
rename from internal/cache/dir.go
rename to internal/backend/cache/dir.go
diff --git a/internal/cache/dir_test.go b/internal/backend/cache/dir_test.go
similarity index 100%
rename from internal/cache/dir_test.go
rename to internal/backend/cache/dir_test.go
diff --git a/internal/cache/file.go b/internal/backend/cache/file.go
similarity index 100%
rename from internal/cache/file.go
rename to internal/backend/cache/file.go
diff --git a/internal/cache/file_test.go b/internal/backend/cache/file_test.go
similarity index 100%
rename from internal/cache/file_test.go
rename to internal/backend/cache/file_test.go
diff --git a/internal/cache/testing.go b/internal/backend/cache/testing.go
similarity index 100%
rename from internal/cache/testing.go
rename to internal/backend/cache/testing.go
diff --git a/internal/checker/checker.go b/internal/checker/checker.go
index 61c017414..82348c7ea 100644
--- a/internal/checker/checker.go
+++ b/internal/checker/checker.go
@@ -12,9 +12,9 @@ import (
 	"github.com/restic/restic/internal/backend/s3"
 	"github.com/restic/restic/internal/debug"
 	"github.com/restic/restic/internal/errors"
-	"github.com/restic/restic/internal/index"
-	"github.com/restic/restic/internal/pack"
 	"github.com/restic/restic/internal/repository"
+	"github.com/restic/restic/internal/repository/index"
+	"github.com/restic/restic/internal/repository/pack"
 	"github.com/restic/restic/internal/restic"
 	"github.com/restic/restic/internal/ui/progress"
 	"golang.org/x/sync/errgroup"
diff --git a/internal/repository/check.go b/internal/repository/check.go
index f16cd7492..27eb11d71 100644
--- a/internal/repository/check.go
+++ b/internal/repository/check.go
@@ -13,8 +13,8 @@ import (
 	"github.com/restic/restic/internal/backend"
 	"github.com/restic/restic/internal/debug"
 	"github.com/restic/restic/internal/errors"
-	"github.com/restic/restic/internal/hashing"
-	"github.com/restic/restic/internal/pack"
+	"github.com/restic/restic/internal/repository/hashing"
+	"github.com/restic/restic/internal/repository/pack"
 	"github.com/restic/restic/internal/restic"
 )
 
diff --git a/internal/repository/packer_manager.go b/internal/repository/packer_manager.go
index 76734fb87..213a3df41 100644
--- a/internal/repository/packer_manager.go
+++ b/internal/repository/packer_manager.go
@@ -10,13 +10,13 @@ import (
 
 	"github.com/restic/restic/internal/backend"
 	"github.com/restic/restic/internal/errors"
-	"github.com/restic/restic/internal/hashing"
+	"github.com/restic/restic/internal/repository/hashing"
 	"github.com/restic/restic/internal/restic"
 
 	"github.com/restic/restic/internal/crypto"
 	"github.com/restic/restic/internal/debug"
 	"github.com/restic/restic/internal/fs"
-	"github.com/restic/restic/internal/pack"
+	"github.com/restic/restic/internal/repository/pack"
 
 	"github.com/minio/sha256-simd"
 )
diff --git a/internal/repository/prune.go b/internal/repository/prune.go
index 1dae68c15..b8d3ba97b 100644
--- a/internal/repository/prune.go
+++ b/internal/repository/prune.go
@@ -7,8 +7,8 @@ import (
 	"sort"
 
 	"github.com/restic/restic/internal/errors"
-	"github.com/restic/restic/internal/index"
-	"github.com/restic/restic/internal/pack"
+	"github.com/restic/restic/internal/repository/index"
+	"github.com/restic/restic/internal/repository/pack"
 	"github.com/restic/restic/internal/restic"
 	"github.com/restic/restic/internal/ui/progress"
 )
diff --git a/internal/repository/repair_index.go b/internal/repository/repair_index.go
index e01131923..770809254 100644
--- a/internal/repository/repair_index.go
+++ b/internal/repository/repair_index.go
@@ -3,8 +3,8 @@ package repository
 import (
 	"context"
 
-	"github.com/restic/restic/internal/index"
-	"github.com/restic/restic/internal/pack"
+	"github.com/restic/restic/internal/repository/index"
+	"github.com/restic/restic/internal/repository/pack"
 	"github.com/restic/restic/internal/restic"
 	"github.com/restic/restic/internal/ui/progress"
 )
diff --git a/internal/repository/repository.go b/internal/repository/repository.go
index 34a362c55..f2c28cece 100644
--- a/internal/repository/repository.go
+++ b/internal/repository/repository.go
@@ -14,13 +14,13 @@ import (
 	"github.com/klauspost/compress/zstd"
 	"github.com/restic/chunker"
 	"github.com/restic/restic/internal/backend"
+	"github.com/restic/restic/internal/backend/cache"
 	"github.com/restic/restic/internal/backend/dryrun"
-	"github.com/restic/restic/internal/cache"
 	"github.com/restic/restic/internal/crypto"
 	"github.com/restic/restic/internal/debug"
 	"github.com/restic/restic/internal/errors"
-	"github.com/restic/restic/internal/index"
-	"github.com/restic/restic/internal/pack"
+	"github.com/restic/restic/internal/repository/index"
+	"github.com/restic/restic/internal/repository/pack"
 	"github.com/restic/restic/internal/restic"
 	"github.com/restic/restic/internal/ui/progress"
 


Test patch:
diff --git a/cmd/restic/cmd_repair_index_integration_test.go b/cmd/restic/cmd_repair_index_integration_test.go
index e11b2f91b..9bfc93b40 100644
--- a/cmd/restic/cmd_repair_index_integration_test.go
+++ b/cmd/restic/cmd_repair_index_integration_test.go
@@ -10,7 +10,7 @@ import (
 
 	"github.com/restic/restic/internal/backend"
 	"github.com/restic/restic/internal/errors"
-	"github.com/restic/restic/internal/index"
+	"github.com/restic/restic/internal/repository/index"
 	"github.com/restic/restic/internal/restic"
 	rtest "github.com/restic/restic/internal/test"
 	"github.com/restic/restic/internal/ui/termstatus"
diff --git a/internal/checker/checker_test.go b/internal/checker/checker_test.go
index 1219f4e2b..5eaf550ba 100644
--- a/internal/checker/checker_test.go
+++ b/internal/checker/checker_test.go
@@ -17,8 +17,8 @@ import (
 	"github.com/restic/restic/internal/backend"
 	"github.com/restic/restic/internal/checker"
 	"github.com/restic/restic/internal/errors"
-	"github.com/restic/restic/internal/hashing"
 	"github.com/restic/restic/internal/repository"
+	"github.com/restic/restic/internal/repository/hashing"
 	"github.com/restic/restic/internal/restic"
 	"github.com/restic/restic/internal/test"
 	"golang.org/x/sync/errgroup"
diff --git a/internal/hashing/reader.go b/internal/repository/hashing/reader.go
similarity index 100%
rename from internal/hashing/reader.go
rename to internal/repository/hashing/reader.go
diff --git a/internal/hashing/reader_test.go b/internal/repository/hashing/reader_test.go
similarity index 100%
rename from internal/hashing/reader_test.go
rename to internal/repository/hashing/reader_test.go
diff --git a/internal/hashing/writer.go b/internal/repository/hashing/writer.go
similarity index 100%
rename from internal/hashing/writer.go
rename to internal/repository/hashing/writer.go
diff --git a/internal/hashing/writer_test.go b/internal/repository/hashing/writer_test.go
similarity index 100%
rename from internal/hashing/writer_test.go
rename to internal/repository/hashing/writer_test.go
diff --git a/internal/index/associated_data.go b/internal/repository/index/associated_data.go
similarity index 100%
rename from internal/index/associated_data.go
rename to internal/repository/index/associated_data.go
diff --git a/internal/index/associated_data_test.go b/internal/repository/index/associated_data_test.go
similarity index 100%
rename from internal/index/associated_data_test.go
rename to internal/repository/index/associated_data_test.go
diff --git a/internal/index/index.go b/internal/repository/index/index.go
similarity index 100%
rename from internal/index/index.go
rename to internal/repository/index/index.go
diff --git a/internal/index/index_parallel.go b/internal/repository/index/index_parallel.go
similarity index 100%
rename from internal/index/index_parallel.go
rename to internal/repository/index/index_parallel.go
diff --git a/internal/index/index_parallel_test.go b/internal/repository/index/index_parallel_test.go
similarity index 90%
rename from internal/index/index_parallel_test.go
rename to internal/repository/index/index_parallel_test.go
index 61b0aad63..38dafb507 100644
--- a/internal/index/index_parallel_test.go
+++ b/internal/repository/index/index_parallel_test.go
@@ -6,13 +6,13 @@ import (
 	"testing"
 
 	"github.com/restic/restic/internal/errors"
-	"github.com/restic/restic/internal/index"
 	"github.com/restic/restic/internal/repository"
+	"github.com/restic/restic/internal/repository/index"
 	"github.com/restic/restic/internal/restic"
 	rtest "github.com/restic/restic/internal/test"
 )
 
-var repoFixture = filepath.Join("..", "repository", "testdata", "test-repo.tar.gz")
+var repoFixture = filepath.Join("..", "testdata", "test-repo.tar.gz")
 
 func TestRepositoryForAllIndexes(t *testing.T) {
 	repo, _, cleanup := repository.TestFromFixture(t, repoFixture)
diff --git a/internal/index/index_test.go b/internal/repository/index/index_test.go
similarity index 99%
rename from internal/index/index_test.go
rename to internal/repository/index/index_test.go
index 1a487f82f..bf752d3d3 100644
--- a/internal/index/index_test.go
+++ b/internal/repository/index/index_test.go
@@ -9,7 +9,7 @@ import (
 	"testing"
 
 	"github.com/restic/restic/internal/feature"
-	"github.com/restic/restic/internal/index"
+	"github.com/restic/restic/internal/repository/index"
 	"github.com/restic/restic/internal/restic"
 	rtest "github.com/restic/restic/internal/test"
 )
diff --git a/internal/index/indexmap.go b/internal/repository/index/indexmap.go
similarity index 100%
rename from internal/index/indexmap.go
rename to internal/repository/index/indexmap.go
diff --git a/internal/index/indexmap_test.go b/internal/repository/index/indexmap_test.go
similarity index 100%
rename from internal/index/indexmap_test.go
rename to internal/repository/index/indexmap_test.go
diff --git a/internal/index/master_index.go b/internal/repository/index/master_index.go
similarity index 100%
rename from internal/index/master_index.go
rename to internal/repository/index/master_index.go
diff --git a/internal/index/master_index_test.go b/internal/repository/index/master_index_test.go
similarity index 99%
rename from internal/index/master_index_test.go
rename to internal/repository/index/master_index_test.go
index 7a2487cd4..23185962e 100644
--- a/internal/index/master_index_test.go
+++ b/internal/repository/index/master_index_test.go
@@ -10,8 +10,8 @@ import (
 
 	"github.com/restic/restic/internal/checker"
 	"github.com/restic/restic/internal/crypto"
-	"github.com/restic/restic/internal/index"
 	"github.com/restic/restic/internal/repository"
+	"github.com/restic/restic/internal/repository/index"
 	"github.com/restic/restic/internal/restic"
 	rtest "github.com/restic/restic/internal/test"
 )
diff --git a/internal/index/testing.go b/internal/repository/index/testing.go
similarity index 100%
rename from internal/index/testing.go
rename to internal/repository/index/testing.go
diff --git a/internal/pack/doc.go b/internal/repository/pack/doc.go
similarity index 100%
rename from internal/pack/doc.go
rename to internal/repository/pack/doc.go
diff --git a/internal/pack/pack.go b/internal/repository/pack/pack.go
similarity index 100%
rename from internal/pack/pack.go
rename to internal/repository/pack/pack.go
diff --git a/internal/pack/pack_internal_test.go b/internal/repository/pack/pack_internal_test.go
similarity index 100%
rename from internal/pack/pack_internal_test.go
rename to internal/repository/pack/pack_internal_test.go
diff --git a/internal/pack/pack_test.go b/internal/repository/pack/pack_test.go
similarity index 98%
rename from internal/pack/pack_test.go
rename to internal/repository/pack/pack_test.go
index 76ff5c127..5ac146348 100644
--- a/internal/pack/pack_test.go
+++ b/internal/repository/pack/pack_test.go
@@ -12,7 +12,7 @@ import (
 	"github.com/restic/restic/internal/backend"
 	"github.com/restic/restic/internal/backend/mem"
 	"github.com/restic/restic/internal/crypto"
-	"github.com/restic/restic/internal/pack"
+	"github.com/restic/restic/internal/repository/pack"
 	"github.com/restic/restic/internal/restic"
 	rtest "github.com/restic/restic/internal/test"
 )
diff --git a/internal/repository/raw_test.go b/internal/repository/raw_test.go
index 28786dbcd..ac65a8dc8 100644
--- a/internal/repository/raw_test.go
+++ b/internal/repository/raw_test.go
@@ -7,9 +7,9 @@ import (
 	"testing"
 
 	"github.com/restic/restic/internal/backend"
+	"github.com/restic/restic/internal/backend/cache"
 	"github.com/restic/restic/internal/backend/mem"
 	"github.com/restic/restic/internal/backend/mock"
-	"github.com/restic/restic/internal/cache"
 	"github.com/restic/restic/internal/errors"
 	"github.com/restic/restic/internal/repository"
 	"github.com/restic/restic/internal/restic"
diff --git a/internal/repository/repository_test.go b/internal/repository/repository_test.go
index 92eb1bbae..c06d4f25b 100644
--- a/internal/repository/repository_test.go
+++ b/internal/repository/repository_test.go
@@ -14,13 +14,13 @@ import (
 	"time"
 
 	"github.com/restic/restic/internal/backend"
+	"github.com/restic/restic/internal/backend/cache"
 	"github.com/restic/restic/internal/backend/local"
 	"github.com/restic/restic/internal/backend/mem"
-	"github.com/restic/restic/internal/cache"
 	"github.com/restic/restic/internal/crypto"
 	"github.com/restic/restic/internal/errors"
-	"github.com/restic/restic/internal/index"
 	"github.com/restic/restic/internal/repository"
+	"github.com/restic/restic/internal/repository/index"
 	"github.com/restic/restic/internal/restic"
 	"github.com/restic/restic/internal/test"
 	rtest "github.com/restic/restic/internal/test"