From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 12264 invoked from network); 20 Oct 2020 22:06:00 -0000 Received: from krantz.zx2c4.com (192.95.5.69) by inbox.vuxu.org with ESMTPUTF8; 20 Oct 2020 22:06:00 -0000 Received: by krantz.zx2c4.com (ZX2C4 Mail Server) with ESMTP id cb651e9e; Tue, 20 Oct 2020 22:04:57 +0000 (UTC) Return-Path: Received: from mx.mylinuxtime.de (mx.mylinuxtime.de [2a01:4f8:13a:16c2::25]) by krantz.zx2c4.com (ZX2C4 Mail Server) with ESMTPS id 8a811541 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Tue, 20 Oct 2020 22:04:56 +0000 (UTC) Received: from leda.eworm.de (p5085ae5d.dip0.t-ipconnect.de [80.133.174.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx.mylinuxtime.de (Postfix) with ESMTPSA id 574C11275E9; Tue, 20 Oct 2020 23:59:16 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=eworm.de; s=mail; t=1603231156; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rtI/cNaqOk6vv8FUymPGY7UBYw7LRIT/7Iz0LtzgO0I=; b=C0LsEXyXu8kv/qPWxbAX7n2ynAIubf4ieNqCtHJw1eI2rEgg+7vh03YqqpG0dDH2ikEQIW Y/GPHDlV0KLWRI1kWx94ukVuzsyG6tR1uHIXKlKF0QPkSktqNYDbysE+aYIRa/dB+AghVS oHIIakrULbCx5vMuAvl5iL9OpRKtPYM= Received: by leda.eworm.de (Postfix, from userid 1000) id EE08C1A101D; Tue, 20 Oct 2020 23:58:45 +0200 (CEST) From: Christian Hesse To: cgit@lists.zx2c4.com Cc: Christian Hesse Subject: [PATCH 2/2] global: replace hard coded hash length Date: Tue, 20 Oct 2020 23:58:37 +0200 Message-Id: <20201020215837.205649-2-list@eworm.de> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20201020215837.205649-1-list@eworm.de> References: <20201020215837.205649-1-list@eworm.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spamd-Bar: / Authentication-Results: mx.mylinuxtime.de; auth=pass smtp.auth=smtp-only@eworm.de smtp.mailfrom=eworm@leda.eworm.de X-Rspamd-Server: mx X-Stat-Signature: m6kr8ocw9fium6gsmoog9dq8imqm63go X-Rspamd-Queue-Id: 574C11275E9 X-Spamd-Result: default: False [-0.73 / 15.00]; ARC_NA(0.00)[]; GENERIC_REPUTATION(0.00)[-0.54885249850264]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; R_MISSING_CHARSET(2.50)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; BROKEN_CONTENT_TYPE(1.50)[]; NEURAL_HAM_LONG(-2.33)[-0.775]; DKIM_SIGNED(0.00)[]; NEURAL_HAM_SHORT(-0.61)[-0.608]; RCPT_COUNT_TWO(0.00)[2]; MID_CONTAINS_FROM(1.00)[]; FORGED_SENDER(0.30)[list@eworm.de,eworm@leda.eworm.de]; RCVD_COUNT_ZERO(0.00)[0]; MIME_TRACE(0.00)[0:+]; ASN(0.00)[asn:3320, ipnet:80.128.0.0/12, country:DE]; FROM_NEQ_ENVFROM(0.00)[list@eworm.de,eworm@leda.eworm.de]; BAYES_HAM(-3.00)[100.00%] X-BeenThere: cgit@lists.zx2c4.com X-Mailman-Version: 2.1.30rc1 Precedence: list List-Id: List for cgit developers and users List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: cgit-bounces@lists.zx2c4.com Sender: "CGit" From: Christian Hesse 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 --- 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|\1|g' +s|\b([0-9a-fA-F]{7,64})\b|\1|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 "file-1" tmp + grep "file-1" 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));