Skip to content

Commit a4de0e8

Browse files
committed
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 <[email protected]>
1 parent 779631c commit a4de0e8

File tree

4 files changed

+5
-6
lines changed

4 files changed

+5
-6
lines changed

filters/commit-links.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ regex=''
1919

2020
# This expression generates links to commits referenced by their SHA1.
2121
regex=$regex'
22-
s|\b([0-9a-fA-F]{7,40})\b|<a href="./?id=\1">\1</a>|g'
22+
s|\b([0-9a-fA-F]{7,64})\b|<a href="./?id=\1">\1</a>|g'
2323

2424
# This expression generates links to a fictional bugtracker.
2525
regex=$regex'

parsing.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ static int end_of_header(const char *p)
127127

128128
struct commitinfo *cgit_parse_commit(struct commit *commit)
129129
{
130-
const int oid_hex_len = 40;
131130
struct commitinfo *ret;
132131
const char *p = repo_get_commit_buffer(the_repository, commit, NULL);
133132
const char *t;
@@ -140,10 +139,10 @@ struct commitinfo *cgit_parse_commit(struct commit *commit)
140139

141140
if (!skip_prefix(p, "tree ", &p))
142141
die("Bad commit: %s", oid_to_hex(&commit->object.oid));
143-
p += oid_hex_len + 1;
142+
p += the_hash_algo->hexsz + 1;
144143

145144
while (skip_prefix(p, "parent ", &p))
146-
p += oid_hex_len + 1;
145+
p += the_hash_algo->hexsz + 1;
147146

148147
if (p && skip_prefix(p, "author ", &p)) {
149148
parse_user(p, &ret->author, &ret->author_email,

tests/t0105-commit.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ test_expect_success 'get root commit' '
2525
'
2626

2727
test_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
2929
'
3030

3131
test_expect_success 'root commit contains diff' '

ui-patch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ void cgit_print_patch(const char *new_rev, const char *old_rev,
6161
}
6262

6363
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);
6565
} else {
6666
xsnprintf(rev_range, REV_RANGE_LEN, "%s..%s", oid_to_hex(&old_rev_oid),
6767
oid_to_hex(&new_rev_oid));

0 commit comments

Comments
 (0)