List for cgit developers and users
 help / color / mirror / Atom feed
From: Christian Hesse <list@eworm.de>
To: cgit@lists.zx2c4.com
Cc: Christian Hesse <mail@eworm.de>
Subject: [PATCH 2/2] global: replace hard coded hash length
Date: Tue, 20 Oct 2020 23:58:37 +0200	[thread overview]
Message-ID: <20201020215837.205649-2-list@eworm.de> (raw)
In-Reply-To: <20201020215837.205649-1-list@eworm.de>

From: Christian Hesse <mail@eworm.de>

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 +-
 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=''
 
 # 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 e647dba..72b59b3 100644
--- 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,
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' '
 '
 
 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 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,
 	}
 
 	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));

  reply	other threads:[~2020-10-20 22:06 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-20 21:58 [PATCH 1/2] global: replace references to 'sha1' with 'oid' Christian Hesse
2020-10-20 21:58 ` Christian Hesse [this message]
2020-10-21 15:35   ` [PATCH 2/2] global: replace hard coded hash length Jason A. Donenfeld
2020-10-21 15:47     ` Jason A. Donenfeld
2020-10-21 19:36     ` Christian Hesse
2020-10-21 22:06       ` Jason A. Donenfeld
2020-10-21 22:07         ` Jason A. Donenfeld

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201020215837.205649-2-list@eworm.de \
    --to=list@eworm.de \
    --cc=cgit@lists.zx2c4.com \
    --cc=mail@eworm.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).