about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorChristian Hesse2020-10-20 23:46:09 +0200
committerChristian Hesse2020-10-20 23:57:12 +0200
commita4de0e810b69710c3b32f6d253d80d16dec09f36 (patch)
treebae0b334de05e134d06b48aeb888a3bf134a705a
parentglobal: replace references to 'sha1' with 'oid' (diff)
downloadcgit-a4de0e810b69710c3b32f6d253d80d16dec09f36.tar.gz
cgit-a4de0e810b69710c3b32f6d253d80d16dec09f36.zip
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>
-rwxr-xr-xfilters/commit-links.sh2
-rw-r--r--parsing.c5
-rwxr-xr-xtests/t0105-commit.sh2
-rw-r--r--ui-patch.c2
4 files changed, 5 insertions, 6 deletions
diff --git a/filters/commit-links.sh b/filters/commit-links.sh index 5881952..796ac30 100755 --- a/filters/commit-links.sh +++ b/filters/commit-links.sh
@@ -19,7 +19,7 @@ regex=''
19 19
20# This expression generates links to commits referenced by their SHA1. 20# This expression generates links to commits referenced by their SHA1.
21regex=$regex' 21regex=$regex'
22s|\b([0-9a-fA-F]{7,40})\b|<a href="./?id=\1">\1</a>|g' 22s|\b([0-9a-fA-F]{7,64})\b|<a href="./?id=\1">\1</a>|g'
23 23
24# This expression generates links to a fictional bugtracker. 24# This expression generates links to a fictional bugtracker.
25regex=$regex' 25regex=$regex'
diff --git a/parsing.c b/parsing.c index e647dba..72b59b3 100644 --- a/parsing.c +++ b/parsing.c
@@ -127,7 +127,6 @@ static int end_of_header(const char *p)
127 127
128struct commitinfo *cgit_parse_commit(struct commit *commit) 128struct commitinfo *cgit_parse_commit(struct commit *commit)
129{ 129{
130 const int oid_hex_len = 40;
131 struct commitinfo *ret; 130 struct commitinfo *ret;
132 const char *p = repo_get_commit_buffer(the_repository, commit, NULL); 131 const char *p = repo_get_commit_buffer(the_repository, commit, NULL);
133 const char *t; 132 const char *t;
@@ -140,10 +139,10 @@ struct commitinfo *cgit_parse_commit(struct commit *commit)
140 139
141 if (!skip_prefix(p, "tree ", &p)) 140 if (!skip_prefix(p, "tree ", &p))
142 die("Bad commit: %s", oid_to_hex(&commit->object.oid)); 141 die("Bad commit: %s", oid_to_hex(&commit->object.oid));
143 p += oid_hex_len + 1; 142 p += the_hash_algo->hexsz + 1;
144 143
145 while (skip_prefix(p, "parent ", &p)) 144 while (skip_prefix(p, "parent ", &p))
146 p += oid_hex_len + 1; 145 p += the_hash_algo->hexsz + 1;
147 146
148 if (p && skip_prefix(p, "author ", &p)) { 147 if (p && skip_prefix(p, "author ", &p)) {
149 parse_user(p, &ret->author, &ret->author_email, 148 parse_user(p, &ret->author, &ret->author_email,
diff --git a/tests/t0105-commit.sh b/tests/t0105-commit.sh index 9cdf55c..1a12ee3 100755 --- a/tests/t0105-commit.sh +++ b/tests/t0105-commit.sh
@@ -25,7 +25,7 @@ test_expect_success 'get root commit' '
25' 25'
26 26
27test_expect_success 'root commit contains diffstat' ' 27test_expect_success 'root commit contains diffstat' '
28 grep "<a href=./foo/diff/file-1.id=[0-9a-f]\{40\}.>file-1</a>" tmp 28 grep "<a href=./foo/diff/file-1.id=[0-9a-f]\{40,64\}.>file-1</a>" tmp
29' 29'
30 30
31test_expect_success 'root commit contains diff' ' 31test_expect_success 'root commit contains diff' '
diff --git a/ui-patch.c b/ui-patch.c index 5a96410..4ac03cb 100644 --- a/ui-patch.c +++ b/ui-patch.c
@@ -61,7 +61,7 @@ void cgit_print_patch(const char *new_rev, const char *old_rev,
61 } 61 }
62 62
63 if (is_null_oid(&old_rev_oid)) { 63 if (is_null_oid(&old_rev_oid)) {
64 memcpy(rev_range, oid_to_hex(&new_rev_oid), GIT_SHA1_HEXSZ + 1); 64 memcpy(rev_range, oid_to_hex(&new_rev_oid), the_hash_algo->hexsz + 1);
65 } else { 65 } else {
66 xsnprintf(rev_range, REV_RANGE_LEN, "%s..%s", oid_to_hex(&old_rev_oid), 66 xsnprintf(rev_range, REV_RANGE_LEN, "%s..%s", oid_to_hex(&old_rev_oid),
67 oid_to_hex(&new_rev_oid)); 67 oid_to_hex(&new_rev_oid));