Skip to content

storage: filesystem, Search alternates in HashesWithPrefix#2087

Merged
pjbgf merged 2 commits into
go-git:mainfrom
andrew:hashes-with-prefix-alternates
May 7, 2026
Merged

storage: filesystem, Search alternates in HashesWithPrefix#2087
pjbgf merged 2 commits into
go-git:mainfrom
andrew:hashes-with-prefix-alternates

Conversation

@andrew

@andrew andrew commented May 7, 2026

Copy link
Copy Markdown
Contributor

EncodedObject, HasEncodedObject and EncodedObjectSize all fall back to alternate object stores, but HashesWithPrefix only consults local loose objects and packs. With alternates configured, ResolveRevision on an abbreviated hash that lives in the alternate returns ErrReferenceNotFound even though the full hash resolves.

This iterates alternates after local lookup, deduplicating against results already collected. It also marks pack hits as seen so a hash present in multiple packs or in both a pack and an alternate is returned once.

EncodedObject, HasEncodedObject and EncodedObjectSize all fall back to
alternate object stores, but HashesWithPrefix only consults local loose
objects and packs. With alternates configured, ResolveRevision on an
abbreviated hash that lives in the alternate returns
ErrReferenceNotFound even though the full hash resolves.

Iterate alternates after local lookup, deduplicating against results
already collected. Also mark pack hits as seen so a hash present in
multiple packs or in both a pack and an alternate is returned once.

Signed-off-by: Andrew Nesbitt <[email protected]>
Copilot AI review requested due to automatic review settings May 7, 2026 15:57

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates storage/filesystem.ObjectStorage.HashesWithPrefix to consult alternate object stores (matching the fallback behavior of other object-lookup APIs) and to deduplicate results so the same object hash is returned only once. This fixes cases where abbreviated hash resolution fails when the object exists only in an alternate.

Changes:

  • Mark packfile matches as “seen” to prevent duplicate hashes when the same object appears in multiple packs.
  • After local loose/pack lookup, iterate configured alternates and merge/deduplicate their HashesWithPrefix results.
  • Add a filesystem storage test covering HashesWithPrefix resolution via alternates.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
storage/filesystem/object.go Extend HashesWithPrefix to dedupe pack hits and consult alternates.
storage/filesystem/object_test.go Add regression test ensuring HashesWithPrefix finds objects stored in alternates.

Comment thread storage/filesystem/object.go
The pack entry iterator was only closed after a full iteration; an
error from Next() returned early without closing it.

Signed-off-by: Andrew Nesbitt <[email protected]>

@pjbgf pjbgf left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andrew thank you for working on this. 🙇

@pjbgf pjbgf merged commit ce8217a into go-git:main May 7, 2026
16 of 17 checks passed
@andrew andrew deleted the hashes-with-prefix-alternates branch May 7, 2026 21:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants