Skip to content

Implement support for Git hashing with SHA-256#13543

Merged
roberth merged 1 commit intoNixOS:masterfrom
obsidiansystems:git-256
Jul 28, 2025
Merged

Implement support for Git hashing with SHA-256#13543
roberth merged 1 commit intoNixOS:masterfrom
obsidiansystems:git-256

Conversation

@Ericson2314
Copy link
Member

Motivation

SHA-256 is Git's next hash algorithm. The world is still basically stuck on SHA-1 with git, but shouldn't be. We can at least do our part to get ready.

On the C++ implementation side, only a little bit of generalization was needed, and that was fairly straight-forward. The tests (unit and system) were actually bigger, and care was taken to make sure they were all cover both algorithms equally.

Context


Add 👍 to pull requests you find important.

The Nix maintainer team uses a GitHub project board to schedule and track reviews.

@Ericson2314 Ericson2314 requested a review from edolstra as a code owner July 24, 2025 18:59
@github-actions github-actions bot added with-tests Issues related to testing. PRs with tests have some priority store Issues and pull requests concerning the Nix store labels Jul 24, 2025
@Ericson2314 Ericson2314 added this to the git-hashing stabilisation milestone Jul 24, 2025
@Ericson2314 Ericson2314 force-pushed the git-256 branch 2 times, most recently from aea27b8 to 7d8596b Compare July 24, 2025 21:09
Copy link
Member

@roberth roberth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but note xokdvium's nitpick

mkSinkHook(CanonPath::root, root.hash, BlobMode::Regular);

ASSERT_EQ(files->root, files2->root);
EXPECT_EQ(files->root, files2->root);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious, why?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh ASSERT will end the test if it fails, while EXPECT will register a failure but keep on going. The two loops are independent (really should be two separate tests, but I didn't want more macros), so EXPECT is better in this case.

SHA-256 is Git's next hash algorithm. The world is still basically stuck
on SHA-1 with git, but shouldn't be. We can at least do our part to get
ready.

On the C++ implementation side, only a little bit of generalization was
needed, and that was fairly straight-forward. The tests (unit and
system) were actually bigger, and care was taken to make sure they were
all cover both algorithms equally.
@roberth roberth merged commit 5bd68f2 into NixOS:master Jul 28, 2025
13 checks passed
@Ericson2314 Ericson2314 deleted the git-256 branch July 28, 2025 19:00
@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/nix-2-31-0-released/68465/1

unreachable();
}

const StringSet hashAlgorithms = {"blake3", "md5", "sha1", "sha256", "sha512"};

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the supported git hash algorithms could be defined as subset of hashAlgorithm so it can be used in for example src/libutil-tests/git.cc line 264 and src/libutil/git.cc line 145
This would also make the parameters in src/libutil/include/nix/util/git.hh safer

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I understand what you are saying, and it makes sense to me. (Enum > string, for sure.) Would you like to make a PR for this? :)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I understand what you are saying, and it makes sense to me. (Enum > string, for sure.) Would you like to make a PR for this? :)

looks like a good point to work myself into the codebase. Hope I don't forget about it when I find the time

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

store Issues and pull requests concerning the Nix store with-tests Issues related to testing. PRs with tests have some priority

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants