From 1974ad7ce2c981e89cd1337d9de9333fa2ae6c6f Mon Sep 17 00:00:00 2001
From: Michael Eischer <michael.eischer@fau.de>
Date: Thu, 26 May 2022 15:43:04 +0200
Subject: [PATCH] repository: hide MasterIndex.FinalizeFullIndexes /
 FinalizeNotFinalIndexes

---
 internal/repository/master_index.go      | 13 ++++++-------
 internal/repository/master_index_test.go |  6 +-----
 internal/repository/testing.go           |  2 +-
 3 files changed, 8 insertions(+), 13 deletions(-)

diff --git a/internal/repository/master_index.go b/internal/repository/master_index.go
index 43888bf77..3dd627c6c 100644
--- a/internal/repository/master_index.go
+++ b/internal/repository/master_index.go
@@ -188,9 +188,9 @@ func (mi *MasterIndex) StorePack(id restic.ID, blobs []restic.Blob) {
 	mi.idx = append(mi.idx, newIdx)
 }
 
-// FinalizeNotFinalIndexes finalizes all indexes that
+// finalizeNotFinalIndexes finalizes all indexes that
 // have not yet been saved and returns that list
-func (mi *MasterIndex) FinalizeNotFinalIndexes() []*Index {
+func (mi *MasterIndex) finalizeNotFinalIndexes() []*Index {
 	mi.idxMutex.Lock()
 	defer mi.idxMutex.Unlock()
 
@@ -207,8 +207,8 @@ func (mi *MasterIndex) FinalizeNotFinalIndexes() []*Index {
 	return list
 }
 
-// FinalizeFullIndexes finalizes all indexes that are full and returns that list.
-func (mi *MasterIndex) FinalizeFullIndexes() []*Index {
+// finalizeFullIndexes finalizes all indexes that are full and returns that list.
+func (mi *MasterIndex) finalizeFullIndexes() []*Index {
 	mi.idxMutex.Lock()
 	defer mi.idxMutex.Unlock()
 
@@ -217,7 +217,6 @@ func (mi *MasterIndex) FinalizeFullIndexes() []*Index {
 	debug.Log("checking %d indexes", len(mi.idx))
 	for _, idx := range mi.idx {
 		if idx.Final() {
-			debug.Log("index %p is final", idx)
 			continue
 		}
 
@@ -425,12 +424,12 @@ func (mi *MasterIndex) saveIndex(ctx context.Context, r restic.SaverUnpacked, in
 
 // SaveIndex saves all new indexes in the backend.
 func (mi *MasterIndex) SaveIndex(ctx context.Context, r restic.SaverUnpacked) error {
-	return mi.saveIndex(ctx, r, mi.FinalizeNotFinalIndexes()...)
+	return mi.saveIndex(ctx, r, mi.finalizeNotFinalIndexes()...)
 }
 
 // SaveFullIndex saves all full indexes in the backend.
 func (mi *MasterIndex) SaveFullIndex(ctx context.Context, r restic.SaverUnpacked) error {
-	return mi.saveIndex(ctx, r, mi.FinalizeFullIndexes()...)
+	return mi.saveIndex(ctx, r, mi.finalizeFullIndexes()...)
 }
 
 // ListPacks returns the blobs of the specified pack files grouped by pack file.
diff --git a/internal/repository/master_index_test.go b/internal/repository/master_index_test.go
index ffdaf7af9..d7e4f1678 100644
--- a/internal/repository/master_index_test.go
+++ b/internal/repository/master_index_test.go
@@ -209,11 +209,7 @@ func createRandomMasterIndex(t testing.TB, rng *rand.Rand, num, size int) (*repo
 	idx1, lookupBh := createRandomIndex(rng, size)
 	mIdx.Insert(idx1)
 
-	mIdx.FinalizeNotFinalIndexes()
-	err := mIdx.MergeFinalIndexes()
-	if err != nil {
-		t.Fatal(err)
-	}
+	repository.TestMergeIndex(t, mIdx)
 
 	return mIdx, lookupBh
 }
diff --git a/internal/repository/testing.go b/internal/repository/testing.go
index a24148a1b..b9b38b1f4 100644
--- a/internal/repository/testing.go
+++ b/internal/repository/testing.go
@@ -134,7 +134,7 @@ func BenchmarkAllVersions(b *testing.B, bench VersionedBenchmark) {
 }
 
 func TestMergeIndex(t testing.TB, mi *MasterIndex) ([]*Index, int) {
-	finalIndexes := mi.FinalizeNotFinalIndexes()
+	finalIndexes := mi.finalizeNotFinalIndexes()
 	for _, idx := range finalIndexes {
 		test.OK(t, idx.SetID(restic.NewRandomID()))
 	}