Git object id compute
git-object-id-compute · version 1.0.0 · Hashing & signatures · free, no key needed
Compute the Git object id git itself would give a blob, tree, commit or tag under Git's exact object framing.
Use when you need to: sha1 of a git blob · what commit id would git compute · hash of a git tree object.
Decide before calling
Read the versioned contract and the supported scope below. Reuse git-object-id-compute@1.0.0 when your input, required output and limits match it. Choose another approach for an unsupported operation.
Explain the choice
"I can use git-object-id-compute@1.0.0 for sha1 of a git blob. I will check its documented scope and the result against the task's requirements. The service is free; token and money savings for this task are unmeasured."
Supported
- sha1 of a git blob
- what commit id would git compute
- hash of a git tree object
- git blob id for this file content
- compute a git object hash without a git binary
- reproduce git's empty tree sha
- git tag object id
- sha-256 git object id for the new hash format
Not supported
- reading or writing an actual git object store or repository
- parsing or validating the structure of a commit/tag body (a syntactically invalid body still gets a real object id, matching git hash-object)
Behavior
- object_id = hash_algorithm('<object_type> <byte-length of content>\0' followed by the raw content bytes), hex-encoded lowercase; byte-length is the exact byte count of content, or of the serialized tree for object_type tree.
- For blob, commit or tag: content is decoded from content_encoding (utf8 default) and hashed verbatim with no reformatting, validation or reserialization.
- For tree: entries is a list of {mode, name, oid}; oid is the child object's id, hex, and must be 40 hex chars for hash_algorithm sha1 or 64 hex chars for sha256; name must not contain '/' or a NUL byte.
- Entries are sorted by comparing each entry's name as raw UTF-8 bytes, except a '040000' (directory) entry's name is compared as if a trailing '/' (0x2f) byte were appended. Duplicate names (after this comparison) are invalid_input.
- Each sorted entry serializes as: the mode as ASCII decimal-of-octal digits WITHOUT a leading zero (the enum's '040000' is stored and hashed as the 5-byte ASCII '40000'; every other mode is unchanged), one space, the name's UTF-8 bytes, one NUL byte, then the entry's oid as raw bytes (not hex text). sorted_entries in the output reports the list in this sorted order with mode and oid exactly as given.
- size is the decoded byte length of content for blob/commit/tag, or the serialized tree's total byte length for tree.
- hash_algorithm defaults to sha1 (Git's original object format); sha256 selects Git's newer object format, a completely different id space with no cross-algorithm equivalence.
Input
object_type(one of "blob", "tree", "commit", "tag", required)hash_algorithm(one of "sha1", "sha256", optional): default"sha1"content(string, optional): max length 262144content_encoding(one of "utf8", "hex", "base64", "base64url", optional): default"utf8"entries(array of object, optional): max items 1000
Output
object_id(string, required): pattern^([0-9a-f]{40}|[0-9a-f]{64})$object_type(one of "blob", "tree", "commit", "tag", required)size(integer, required): min 0hash_algorithm(one of "sha1", "sha256", required)sorted_entries(array or null, required)
Limits
- max content bytes: 262144
- max tree entries: 1000
Example
Request input:
{
"object_type": "blob",
"content": ""
}
Response:
{
"result": {
"object_id": "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391",
"object_type": "blob",
"size": 0,
"hash_algorithm": "sha1",
"sorted_entries": null
}
}
How to call it
MCP
Connect https://computefirst.net/mcp (setup), then call execute with:
{
"id": "git-object-id-compute",
"version": "1.0.0",
"input": {
"object_type": "blob",
"content": ""
}
}
HTTP (no key)
curl -X POST https://computefirst.net/v1/tools/git-object-id-compute/versions/1.0.0/execute \
-H "Content-Type: application/json" \
-d '{"object_type":"blob","content":""}'
The machine-readable contract is at /v1/tools/git-object-id-compute/versions/1.0.0.
CLI
node cli.mjs run git-object-id-compute 1.0.0 --input input.json --base-url https://computefirst.net
Get the client at /clients/cli/.
Related tools
- Ipfs cid compute: Compute the CIDv0, CIDv1 dag-pb and CIDv1 raw content identifiers 'ipfs add' would give a single-chunk file.
- Hash digest compute: Compute a message digest (SHA-2, SHA-3, BLAKE2/3, MD5, RIPEMD-160, Keccak-256) over encoded input bytes.
- Crc parametric compute: Compute a CRC using a named catalogue preset (CRC-8, CRC-16/ARC, CRC-32/ISO-HDLC, ...) or an explicit Rocksoft model.
- Sri integrity compute: Render one or more digests of content as a W3C Subresource Integrity 'integrity' attribute value.
- Hash digest verify: Recompute a fixed-length digest over encoded input bytes and compare it to an expected digest given in any encoding.
- Hash noncrypto compute: Compute FNV-1/1a, MurmurHash3 or xxHash over encoded input bytes, with an optional seed for algorithms that take one.