]> git.ipfire.org Git - thirdparty/git.git/commitdiff
hash: add a constant for the default hash algorithm
authorbrian m. carlson <sandals@crustytoothpaste.net>
Fri, 20 Jun 2025 01:19:33 +0000 (01:19 +0000)
committerJunio C Hamano <gitster@pobox.com>
Fri, 20 Jun 2025 14:17:34 +0000 (07:17 -0700)
Right now, SHA-1 is the default hash algorithm in Git.  However, this
may change in the future.

We have many places in our code that use the SHA-1 constant to indicate
the default hash if none is specified, but it will end up being more
practical to specify this explicitly and clearly using a constant for
whatever the default hash algorithm is.  Then, if we decide to change it
in the future, we can simply replace the constant representing the
default with a new value.

For these reasons, introduce GIT_HASH_DEFAULT to represent the default
hash algorithm.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
hash.h

diff --git a/hash.h b/hash.h
index d6422ddf454c17d62286b8fb8ba047b4808b4234..0d3d85e04cbd5c156df86ad98ab68d24b5169245 100644 (file)
--- a/hash.h
+++ b/hash.h
@@ -174,6 +174,8 @@ static inline void git_SHA256_Clone(git_SHA256_CTX *dst, const git_SHA256_CTX *s
 #define GIT_HASH_SHA256 2
 /* Number of algorithms supported (including unknown). */
 #define GIT_HASH_NALGOS (GIT_HASH_SHA256 + 1)
+/* Default hash algorithm if unspecified. */
+#define GIT_HASH_DEFAULT GIT_HASH_SHA1
 
 /* "sha1", big-endian */
 #define GIT_SHA1_FORMAT_ID 0x73686131