通常のハッシュの3倍
This is a Rust tool that recalculates the hashes of all of the commit ids in a repository using SHA-256 instead of SHA-1.
Git calculates the hash of a commit by first concatenating the following and then hashing:
- Commit source tree SHA-1 (subtrees, blobs)
- Parent SHA-1 hash
- Author info
- Committer info
- Commit message
- A string containing "commit <size of 1-5 in bytes>NULL"
- SHA-1 performed on 1-6
This corresponds to, in git commands:
git cat-file commit HEAD
printf "commit %s\0" $(git cat-file commit HEAD | wc -c
- pipe to
sha1sum
That's all right, but we need to replace the hashes with SHA-256. That appears
in three locations: the source tree, the parent commit hash, and the hash of the
concatenated view above. The last one is easy: just use sha256sum
. The parent
commit hash can be similarly replaced in a recursive fashion. However, the git
commands don't expose a slot where you can insert a sha256sum
pipe after tree
construction--we have to do that ourselves.
Tree formation is given in the git source code.