Repository: kopia/kopia
Pull request #4167 (2024-10-10 07:08:19)

refactor(repository): Following up code adjustment for on-use-builder
A following up PR of #4139 to address comment https://github.com/kopia/kopia/pull/4139#discussion_r1793663722 and https://github.com/kopia/kopia/pull/4139#discussion_r1793665281.

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/kopia/kopia/pull/4167?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kopia) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Project coverage is 77.25%. Comparing base [(`cb455c6`)](https://app.codecov.io/gh/kopia/kopia/commit/cb455c699a04e54cb47e25a676d7d65063ce883e?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kopia) to head [(`b4a2b68`)](https://app.codecov.io/gh/kopia/kopia/commit/b4a2b68ddcfb686da2c055faf5433ffb6c81e172?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kopia).
> Report is 290 commits behind head on master.

<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff             @@
##           master    #4167      +/-   ##
==========================================
+ Coverage   75.86%   77.25%   +1.38%     
==========================================
  Files         470      500      +30     
  Lines       37301    29255    -8046     
==========================================
- Hits        28299    22601    -5698     
+ Misses       7071     4709    -2362     
- Partials     1931     1945      +14     
```

</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/kopia/kopia/pull/4167?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kopia).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kopia).

Lyndon-Li: https://github.com/kopia/kopia/actions/runs/11285623924/job/31389954180?pr=4167
This CI error seems not to be caused by this PR.
Lyndon-Li: @jkowalski
Could you help to check this CI failure https://github.com/kopia/kopia/actions/runs/11285623924/job/31389954180?pr=4167?
It seems timeout happened for test `TestByteRepresentation`, but I didn't reproduce it locally.
And the timeout of snapshot creation doesn't look related to the code changes of this PR.

Patch:
diff --git a/repo/content/index/one_use_index_builder.go b/repo/content/index/one_use_index_builder.go
index 52c3c8a0..56cdee1c 100644
--- a/repo/content/index/one_use_index_builder.go
+++ b/repo/content/index/one_use_index_builder.go
@@ -31,22 +31,9 @@ func NewOneUseBuilder() *OneUseBuilder {
 
 // Add adds a new entry to the builder or conditionally replaces it if the timestamp is greater.
 func (b *OneUseBuilder) Add(i Info) {
-	cid := i.ContentID
-
-	found := b.indexStore.Get(&Info{ContentID: cid})
+	found := b.indexStore.Get(&i)
 	if found == nil || contentInfoGreaterThanStruct(&i, found.(*Info)) { //nolint:forcetypeassert
-		_ = b.indexStore.ReplaceOrInsert(&Info{
-			PackBlobID:          i.PackBlobID,
-			ContentID:           cid,
-			TimestampSeconds:    i.TimestampSeconds,
-			OriginalLength:      i.OriginalLength,
-			PackedLength:        i.PackedLength,
-			PackOffset:          i.PackOffset,
-			CompressionHeaderID: i.CompressionHeaderID,
-			Deleted:             i.Deleted,
-			FormatVersion:       i.FormatVersion,
-			EncryptionKeyID:     i.EncryptionKeyID,
-		})
+		_ = b.indexStore.ReplaceOrInsert(&i)
 	}
 }
 


Test patch:
diff --git a/repo/content/index/packindex_test.go b/repo/content/index/packindex_test.go
index bd08894f..86644bfc 100644
--- a/repo/content/index/packindex_test.go
+++ b/repo/content/index/packindex_test.go
@@ -156,21 +156,17 @@ func testPackIndex(t *testing.T, version int) {
 
 	var buf1, buf2, buf3, buf4 bytes.Buffer
 
-	if err := b1.Build(&buf1, version); err != nil {
-		t.Fatalf("unable to build: %v", err)
-	}
+	err := b1.Build(&buf1, version)
+	require.NoError(t, err)
 
-	if err := b2.Build(&buf2, version); err != nil {
-		t.Fatalf("unable to build: %v", err)
-	}
+	err = b2.Build(&buf2, version)
+	require.NoError(t, err)
 
-	if err := b3.BuildStable(&buf3, version); err != nil {
-		t.Fatalf("unable to build: %v", err)
-	}
+	err = b3.BuildStable(&buf3, version)
+	require.NoError(t, err)
 
-	if err := b4.BuildStable(&buf4, version); err != nil {
-		t.Fatalf("unable to build: %v", err)
-	}
+	err = b4.BuildStable(&buf4, version)
+	require.NoError(t, err)
 
 	data1 := buf1.Bytes()
 	data2 := buf2.Bytes()