Skip to content

plumbing: objfile, Pass object format into Reader#2077

Merged
pjbgf merged 1 commit into
mainfrom
loose-sha256
May 7, 2026
Merged

plumbing: objfile, Pass object format into Reader#2077
pjbgf merged 1 commit into
mainfrom
loose-sha256

Conversation

@pjbgf
Copy link
Copy Markdown
Member

@pjbgf pjbgf commented May 7, 2026

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.

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]>
Copilot AI review requested due to automatic review settings May 7, 2026 11:19
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 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.NewReader to accept an ObjectFormat and 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

  • encodedObjectSizeFromUnpacked opens f but only closes the objfile Reader; objfile.Reader.Close() does not close the underlying file, so f is leaked on both success and error paths. Add a defer to close f (or otherwise ensure it is closed) alongside closing r.
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.NewReader or Header() fails, the opened file f is not closed (and r.Close() does not close the underlying file). Ensure f.Close() is called on all error paths, not only in the success case wrapped by NewReadCloserWithCloser.
	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.CheckClose is being called without defer, which closes rd (and later w) immediately before they are used. These should be deferred (or replaced with explicit close-at-end logic) so Header()/copying can read/write successfully and still capture close errors via err.
	rd, err := objfile.NewReader(res.Body, objectFormatFromHash(objHash))
	if err != nil {
		return err
	}
	ioutil.CheckClose(rd, &err)

Comment thread plumbing/format/objfile/reader.go
Comment thread plumbing/format/objfile/reader_test.go
@pjbgf pjbgf merged commit 8278e46 into main May 7, 2026
21 checks passed
@pjbgf pjbgf deleted the loose-sha256 branch May 7, 2026 11:31
@pjbgf pjbgf restored the loose-sha256 branch May 7, 2026 13:17
@pjbgf pjbgf deleted the loose-sha256 branch May 7, 2026 13:25
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