]> granicus.if.org Git - cgit/commitdiff
global: replace hard coded hash length ch/sha256
authorChristian Hesse <mail@eworm.de>
Tue, 20 Oct 2020 21:46:09 +0000 (23:46 +0200)
committerChristian Hesse <mail@eworm.de>
Tue, 20 Oct 2020 21:57:12 +0000 (23:57 +0200)
With sha1 we had a guaranteed length of 40 hex chars. This changes now
that we have to support sha256 with 64 hex chars... Support both.

Signed-off-by: Christian Hesse <mail@eworm.de>
filters/commit-links.sh
parsing.c
tests/t0105-commit.sh
ui-patch.c

index 58819524ced8eb8f99bec05cfd75f730c27307dc..796ac308d237b41d1eeb01e6cb3072180c6898a1 100755 (executable)
@@ -19,7 +19,7 @@ regex=''
 
 # This expression generates links to commits referenced by their SHA1.
 regex=$regex'
-s|\b([0-9a-fA-F]{7,40})\b|<a href="./?id=\1">\1</a>|g'
+s|\b([0-9a-fA-F]{7,64})\b|<a href="./?id=\1">\1</a>|g'
 
 # This expression generates links to a fictional bugtracker.
 regex=$regex'
index e647dba018fd470578f570750ce70196c8d7682d..72b59b3c46a6c52aadd1134f215c8ce3f274d392 100644 (file)
--- a/parsing.c
+++ b/parsing.c
@@ -127,7 +127,6 @@ static int end_of_header(const char *p)
 
 struct commitinfo *cgit_parse_commit(struct commit *commit)
 {
-       const int oid_hex_len = 40;
        struct commitinfo *ret;
        const char *p = repo_get_commit_buffer(the_repository, commit, NULL);
        const char *t;
@@ -140,10 +139,10 @@ struct commitinfo *cgit_parse_commit(struct commit *commit)
 
        if (!skip_prefix(p, "tree ", &p))
                die("Bad commit: %s", oid_to_hex(&commit->object.oid));
-       p += oid_hex_len + 1;
+       p += the_hash_algo->hexsz + 1;
 
        while (skip_prefix(p, "parent ", &p))
-               p += oid_hex_len + 1;
+               p += the_hash_algo->hexsz + 1;
 
        if (p && skip_prefix(p, "author ", &p)) {
                parse_user(p, &ret->author, &ret->author_email,
index 9cdf55c02576cbcd596afcd43e41a074e5611179..1a12ee39a9e7ba579c10f16f8e619033bd14cdf4 100755 (executable)
@@ -25,7 +25,7 @@ test_expect_success 'get root commit' '
 '
 
 test_expect_success 'root commit contains diffstat' '
-       grep "<a href=./foo/diff/file-1.id=[0-9a-f]\{40\}.>file-1</a>" tmp
+       grep "<a href=./foo/diff/file-1.id=[0-9a-f]\{40,64\}.>file-1</a>" tmp
 '
 
 test_expect_success 'root commit contains diff' '
index 5a964108e51e5f553536899cb6b79922e25e1288..4ac03cbef1d810901c185aedbd7b4b58bbff998f 100644 (file)
@@ -61,7 +61,7 @@ void cgit_print_patch(const char *new_rev, const char *old_rev,
        }
 
        if (is_null_oid(&old_rev_oid)) {
-               memcpy(rev_range, oid_to_hex(&new_rev_oid), GIT_SHA1_HEXSZ + 1);
+               memcpy(rev_range, oid_to_hex(&new_rev_oid), the_hash_algo->hexsz + 1);
        } else {
                xsnprintf(rev_range, REV_RANGE_LEN, "%s..%s", oid_to_hex(&old_rev_oid),
                        oid_to_hex(&new_rev_oid));