Skip to content

feat: add SpecFromDigest constructor - #83

Merged
alanshaw merged 2 commits into
mainfrom
ash/feat/spec-from-digest
Oct 1, 2026
Merged

alanshaw merged 2 commits into
mainfrom
ash/feat/spec-from-digest

Conversation

@alanshaw

@alanshaw alanshaw commented Oct 1, 2026

Copy link
Copy Markdown
Member

Adds blob.SpecFromDigest(digest, size), which specifies a blob by its digest. It pairs with SpecFromDigestCode(code, size), which specifies one by the hash function that will compute its digest.

// before
blob.SpecFromBlob(blob.Blob{Digest: digest, Size: size})
// after
blob.SpecFromDigest(digest, size)

SpecFromBlob stays, for code that already holds a Blob, and now delegates to SpecFromDigest. Encoding is unchanged.

About 40 call sites across Piri, Sprue, Ingot and guppy build a Blob inline just to pass it in; they'll switch once this merges.

馃 Generated with Claude Code

SpecFromDigest(digest, size) specifies a blob by its digest, pairing with
SpecFromDigestCode(code, size). Callers that have a digest and a size no
longer build a Blob just to pass it to SpecFromBlob, which now delegates to
it.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

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.

Copilot review overview

馃煝 Approval recommended

The implementation is correct and tested; only a non-blocking documentation update remains.

Review effort: Balanced
Findings: 1 Low severity

Open (1)
What changed in this PR

Adds a direct BlobSpec constructor from a digest and size while preserving existing encoding behavior.

Changes:

  • Introduces SpecFromDigest.
  • Delegates SpecFromBlob to the new constructor.
  • Tests equivalence between both constructors.
File Description
commands/鈥媌lob/鈥媍odec.go Adds and integrates the constructor.
commands/鈥媌lob/鈥媠pec_test.go Tests constructor behavior and compatibility.

馃挕 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread commands/blob/codec.go
// SpecFromDigest returns the spec of a blob of size bytes whose digest is
// known. Its digest code is the digest's own; a digest that is not a multihash
// has code 0.
func SpecFromDigest(digest multihash.Multihash, size uint64) BlobSpec {

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.

Added SpecFromDigest to the BlobSpec constructor documentation in commit 28089c5.

Co-authored-by: alanshaw <152863+alanshaw@users.noreply.github.com>
@alanshaw
alanshaw merged commit b2db386 into main Oct 1, 2026
7 checks passed
@alanshaw
alanshaw deleted the ash/feat/spec-from-digest branch October 1, 2026 20:09
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