plumbing: objfile, Pass object format into Reader#2077
Merged
Conversation
Thread the repository's object format through objfile.NewReader so SHA-256 loose objects are hashed with SHA-256 instead of being hard-coded to SHA-1. Update callers in dotgit, filesystem object storage, and the dumb HTTP transport, and extend reader/writer tests with SHA-256 round-trip coverage. Assisted-by: Claude Opus 4.7 <[email protected]> Signed-off-by: Paulo Gomes <[email protected]>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR threads the repository’s configured object format (SHA-1 vs SHA-256) into plumbing/format/objfile.Reader so loose-object hashing uses the correct algorithm, and updates key callers and tests to cover SHA-256 round-trips.
Changes:
- Change
objfile.NewReaderto accept anObjectFormatand hash accordingly. - Update filesystem storage and dumb HTTP transport call sites to pass an object format.
- Extend objfile reader/writer tests to validate SHA-256 hashing behavior.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
storage/filesystem/object.go |
Passes storage object format into objfile.NewReader for loose object reads. |
storage/filesystem/dotgit/reader.go |
Passes dotgit object format into objfile.NewReader when exposing encoded objects. |
plumbing/transport/http/dumb.go |
Infers object format from hash length and passes it into objfile.NewReader. |
plumbing/format/objfile/reader.go |
Makes Reader hashing depend on the passed-in object format. |
plumbing/format/objfile/reader_test.go |
Runs objfile reader tests for both SHA-1 and SHA-256 hashing. |
plumbing/format/objfile/writer_test.go |
Adds SHA-256 writer round-trip coverage and updates reader calls. |
Comments suppressed due to low confidence (3)
storage/filesystem/object.go:404
encodedObjectSizeFromUnpackedopensfbut only closes the objfile Reader;objfile.Reader.Close()does not close the underlying file, sofis leaked on both success and error paths. Add adeferto closef(or otherwise ensure it is closed) alongside closingr.
func (s *ObjectStorage) encodedObjectSizeFromUnpacked(h plumbing.Hash) (size int64, err error) {
f, err := s.dir.Object(h)
if err != nil {
if os.IsNotExist(err) {
return 0, plumbing.ErrObjectNotFound
}
return 0, err
}
r, err := objfile.NewReader(f, s.options.ObjectFormat)
if err != nil {
return 0, err
}
defer ioutil.CheckClose(r, &err)
storage/filesystem/dotgit/reader.go:47
- If
objfile.NewReaderorHeader()fails, the opened filefis not closed (andr.Close()does not close the underlying file). Ensuref.Close()is called on all error paths, not only in the success case wrapped byNewReadCloserWithCloser.
r, err := objfile.NewReader(f, e.dir.options.ObjectFormat)
if err != nil {
return nil, err
}
t, size, err := r.Header()
if err != nil {
_ = r.Close()
return nil, err
}
plumbing/transport/http/dumb.go:266
ioutil.CheckCloseis being called withoutdefer, which closesrd(and laterw) immediately before they are used. These should be deferred (or replaced with explicit close-at-end logic) soHeader()/copying can read/write successfully and still capture close errors viaerr.
rd, err := objfile.NewReader(res.Body, objectFormatFromHash(objHash))
if err != nil {
return err
}
ioutil.CheckClose(rd, &err)
hiddeco
approved these changes
May 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Thread the repository's object format through
objfile.NewReadersoSHA-256loose objects are hashed withSHA-256instead of being hard-coded toSHA-1. Update callers in dotgit, filesystem object storage, and the dumb HTTP transport, and extend reader/writer tests withSHA-256round-trip coverage.