cgit

commit a4de0e810b69710c3b32f6d253d80d16dec09f36

Author: Christian Hesse <mail@eworm.de>

global: replace hard coded hash length

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 | 2 +-
 parsing.c | 5 ++---
 tests/t0105-commit.sh | 2 +-
 ui-patch.c | 2 +-


diff --git a/filters/commit-links.sh b/filters/commit-links.sh
index 58819524ced8eb8f99bec05cfd75f730c27307dc..796ac308d237b41d1eeb01e6cb3072180c6898a1 100755
--- a/filters/commit-links.sh
+++ b/filters/commit-links.sh
@@ -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'




diff --git a/parsing.c b/parsing.c
index e647dba018fd470578f570750ce70196c8d7682d..72b59b3c46a6c52aadd1134f215c8ce3f274d392 100644
--- a/parsing.c
+++ b/parsing.c
@@ -127,7 +127,6 @@ }
 
 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 @@ 		return ret;
 
 	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,




diff --git a/tests/t0105-commit.sh b/tests/t0105-commit.sh
index 9cdf55c02576cbcd596afcd43e41a074e5611179..1a12ee39a9e7ba579c10f16f8e619033bd14cdf4 100755
--- a/tests/t0105-commit.sh
+++ b/tests/t0105-commit.sh
@@ -25,7 +25,7 @@ 	grep "" tmp
 '
 
 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' '




diff --git a/ui-patch.c b/ui-patch.c
index 5a964108e51e5f553536899cb6b79922e25e1288..4ac03cbef1d810901c185aedbd7b4b58bbff998f 100644
--- a/ui-patch.c
+++ b/ui-patch.c
@@ -61,7 +61,7 @@ 		oidclr(&old_rev_oid);
 	}
 
 	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));