mirror of
https://git.zx2c4.com/cgit
synced 2024-11-08 09:38:41 +00:00
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>
This commit is contained in:
parent
779631c6dc
commit
a4de0e810b
@ -19,7 +19,7 @@ regex=''
|
|||||||
|
|
||||||
# This expression generates links to commits referenced by their SHA1.
|
# This expression generates links to commits referenced by their SHA1.
|
||||||
regex=$regex'
|
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.
|
# This expression generates links to a fictional bugtracker.
|
||||||
regex=$regex'
|
regex=$regex'
|
||||||
|
@ -127,7 +127,6 @@ static int end_of_header(const char *p)
|
|||||||
|
|
||||||
struct commitinfo *cgit_parse_commit(struct commit *commit)
|
struct commitinfo *cgit_parse_commit(struct commit *commit)
|
||||||
{
|
{
|
||||||
const int oid_hex_len = 40;
|
|
||||||
struct commitinfo *ret;
|
struct commitinfo *ret;
|
||||||
const char *p = repo_get_commit_buffer(the_repository, commit, NULL);
|
const char *p = repo_get_commit_buffer(the_repository, commit, NULL);
|
||||||
const char *t;
|
const char *t;
|
||||||
@ -140,10 +139,10 @@ struct commitinfo *cgit_parse_commit(struct commit *commit)
|
|||||||
|
|
||||||
if (!skip_prefix(p, "tree ", &p))
|
if (!skip_prefix(p, "tree ", &p))
|
||||||
die("Bad commit: %s", oid_to_hex(&commit->object.oid));
|
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))
|
while (skip_prefix(p, "parent ", &p))
|
||||||
p += oid_hex_len + 1;
|
p += the_hash_algo->hexsz + 1;
|
||||||
|
|
||||||
if (p && skip_prefix(p, "author ", &p)) {
|
if (p && skip_prefix(p, "author ", &p)) {
|
||||||
parse_user(p, &ret->author, &ret->author_email,
|
parse_user(p, &ret->author, &ret->author_email,
|
||||||
|
@ -25,7 +25,7 @@ test_expect_success 'get root commit' '
|
|||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'root commit contains diffstat' '
|
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' '
|
test_expect_success 'root commit contains diff' '
|
||||||
|
@ -61,7 +61,7 @@ void cgit_print_patch(const char *new_rev, const char *old_rev,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (is_null_oid(&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 {
|
} else {
|
||||||
xsnprintf(rev_range, REV_RANGE_LEN, "%s..%s", oid_to_hex(&old_rev_oid),
|
xsnprintf(rev_range, REV_RANGE_LEN, "%s..%s", oid_to_hex(&old_rev_oid),
|
||||||
oid_to_hex(&new_rev_oid));
|
oid_to_hex(&new_rev_oid));
|
||||||
|
Loading…
Reference in New Issue
Block a user