From patchwork Tue Feb 12 01:22:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "brian m. carlson" X-Patchwork-Id: 10807115 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3E8091575 for ; Tue, 12 Feb 2019 01:23:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2EEE32AC23 for ; Tue, 12 Feb 2019 01:23:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 235DC2AC2D; Tue, 12 Feb 2019 01:23:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A8DB12AC23 for ; Tue, 12 Feb 2019 01:23:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726892AbfBLBXR (ORCPT ); Mon, 11 Feb 2019 20:23:17 -0500 Received: from injection.crustytoothpaste.net ([192.241.140.119]:34234 "EHLO injection.crustytoothpaste.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726147AbfBLBXR (ORCPT ); Mon, 11 Feb 2019 20:23:17 -0500 Received: from genre.crustytoothpaste.net (unknown [IPv6:2001:470:b978:101:3dc7:72ec:75fa:fee5]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by injection.crustytoothpaste.net (Postfix) with ESMTPSA id 0A22760737; Tue, 12 Feb 2019 01:23:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=crustytoothpaste.net; s=default; t=1549934594; bh=ZFRPsfG+yT0mApt1qAPwTtLm8ysGF/Ohp04syb0QkcI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Reply-To: Subject:Date:To:CC:Resent-Date:Resent-From:Resent-To:Resent-Cc: In-Reply-To:References:Content-Type:Content-Disposition; b=YOv3S3+v/Czf+V0m4WxCHBvnBUVbR3ov6KFAOERZMhPwZ5lthzNKNxP54RM7dmEvK 9W6nN5CJU50L5gpe3gy6iY0k/4UN4t+iOUSFfsXCubw7PSiLKD+5UK77j/GrrN5QGE m8cynziSGcoiRCJrg0RpNnbDt0pY5tJfHpRfflqz1GB41k21W4IjZ28lBUERlcqGOz eft3rJ8oizkrLyPK3Q+dvaVcMEsK3dWI+uST95hARNhhoZDU54CQh1HL44Vu6CGG9r gyl5qi/i9LNmQOac2xLbPZd3F9tLbC/N6/5B9RxBA46KMxWKLZ9eNz5jzMUGMOFWI0 G7nfgHjNn4VLDDeUIaIrW6bygOiPduKxefeSjPjHNcOfyC9V73k0zNZNEHg2Po6est x88CZKXAOt9ASMQDLZnAN3uGN7ImjLOMagBU1eJ+qHbKFZ7CUYe3gUfSpZ8SX0U/RI w+QICpTDVK3IN6/+BoIMzJ6tRBTYs6diixP6YJ3m5dy2FNeLI8S From: "brian m. carlson" To: Cc: =?utf-8?q?Ren=C3=A9_Scharfe?= , Duy Nguyen Subject: [PATCH 01/31] t/lib-submodule-update: use appropriate length constant Date: Tue, 12 Feb 2019 01:22:26 +0000 Message-Id: <20190212012256.1005924-2-sandals@crustytoothpaste.net> X-Mailer: git-send-email 2.20.1.791.gb4d0f1c61a In-Reply-To: <20190212012256.1005924-1-sandals@crustytoothpaste.net> References: <20190212012256.1005924-1-sandals@crustytoothpaste.net> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 127.0.1.1 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Instead of using a specific invalid hard-coded object ID, produce one of the appropriate length by using test_oid. Signed-off-by: brian m. carlson --- t/lib-submodule-update.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/t/lib-submodule-update.sh b/t/lib-submodule-update.sh index 5b56b23166..1dd17fc03e 100755 --- a/t/lib-submodule-update.sh +++ b/t/lib-submodule-update.sh @@ -139,7 +139,7 @@ create_lib_submodule_repo () { git revert HEAD && git checkout -b invalid_sub1 add_sub1 && - git update-index --cacheinfo 160000 0123456789012345678901234567890123456789 sub1 && + git update-index --cacheinfo 160000 $(test_oid numeric) sub1 && git commit -m "Invalid sub1 commit" && git checkout -b valid_sub1 && git revert HEAD && @@ -196,6 +196,7 @@ test_git_directory_exists() { # the submodule repo if it doesn't exist and configures the most problematic # settings for diff.ignoreSubmodules. prolog () { + test_oid_init && (test -d submodule_update_repo || create_lib_submodule_repo) && test_config_global diff.ignoreSubmodules all && test_config diff.ignoreSubmodules all From patchwork Tue Feb 12 01:22:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "brian m. carlson" X-Patchwork-Id: 10807119 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6017813A4 for ; Tue, 12 Feb 2019 01:23:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 50CF02AC23 for ; Tue, 12 Feb 2019 01:23:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 455932AC2D; Tue, 12 Feb 2019 01:23:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E6D6C2AC23 for ; Tue, 12 Feb 2019 01:23:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726940AbfBLBXS (ORCPT ); Mon, 11 Feb 2019 20:23:18 -0500 Received: from injection.crustytoothpaste.net ([192.241.140.119]:34238 "EHLO injection.crustytoothpaste.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726337AbfBLBXS (ORCPT ); Mon, 11 Feb 2019 20:23:18 -0500 Received: from genre.crustytoothpaste.net (unknown [IPv6:2001:470:b978:101:3dc7:72ec:75fa:fee5]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by injection.crustytoothpaste.net (Postfix) with ESMTPSA id 670D860897; Tue, 12 Feb 2019 01:23:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=crustytoothpaste.net; s=default; t=1549934596; bh=VGJW+syuTlUQ1JiMelAd2KeGi1GkwrWiTo4ZH3HNkOc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Reply-To: Subject:Date:To:CC:Resent-Date:Resent-From:Resent-To:Resent-Cc: In-Reply-To:References:Content-Type:Content-Disposition; b=hjLvVfnhe+bJRr+FdwoILo5xuD7WrTIetRxSDLzVXto1nRkqAtuKtRTFWBSuy41nm clTT+WCrkanlGjFxtHZ3TSLEP951FRlI4rTqhVB8HMlo25FtPfCvoO/SY3XBW5WxvA SDgCzVpb3bF5P0M4F8bV7b8Kp4H7a47N3WiZgKvW7NRSogfMoctNebqaRDpjwrikmh QlcoPyQGVh5HQkTX7aiOoS9jP0HWNPcMSYctX+IJQ0+n5NZ7BFLYgXIdEPy9TeJ0j+ +3dSJmzJ6MeqvzO0DVyOQYUTLSPEyOxg29yp6YUnxqIvrxCSh6+kIJciYTC1X2+RRd yq9q0iPQGbdGKN6eKUhVUVYbcjl0rfw0LSxqWTn2+QZdnwZQDA0ef9jRewPVrD4YwC 1xeoCI3fkPw8YEup0eICMouMb8oILTv9OCDhngJwc/eS5ZUcomEJgtmVmGfmfl5UtB ufL6C/402z5o3PbBipfW6mxL8ZfcYMBaY1ITR5iGLiAo6CZFGL/ From: "brian m. carlson" To: Cc: =?utf-8?q?Ren=C3=A9_Scharfe?= , Duy Nguyen Subject: [PATCH 02/31] pack-bitmap: make bitmap header handling hash agnostic Date: Tue, 12 Feb 2019 01:22:27 +0000 Message-Id: <20190212012256.1005924-3-sandals@crustytoothpaste.net> X-Mailer: git-send-email 2.20.1.791.gb4d0f1c61a In-Reply-To: <20190212012256.1005924-1-sandals@crustytoothpaste.net> References: <20190212012256.1005924-1-sandals@crustytoothpaste.net> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 127.0.1.1 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Increase the checksum field in struct bitmap_disk_header to be GIT_MAX_RAWSZ bytes in length and ensure that we hash the proper number of bytes out when computing the bitmap checksum. Signed-off-by: brian m. carlson --- pack-bitmap-write.c | 2 +- pack-bitmap.c | 2 +- pack-bitmap.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pack-bitmap-write.c b/pack-bitmap-write.c index 5566e94abe..c82fb01fd7 100644 --- a/pack-bitmap-write.c +++ b/pack-bitmap-write.c @@ -535,7 +535,7 @@ void bitmap_writer_finish(struct pack_idx_entry **index, header.entry_count = htonl(writer.selected_nr); hashcpy(header.checksum, writer.pack_checksum); - hashwrite(f, &header, sizeof(header)); + hashwrite(f, &header, sizeof(header) - GIT_MAX_RAWSZ + the_hash_algo->rawsz); dump_bitmap(f, writer.commits); dump_bitmap(f, writer.trees); dump_bitmap(f, writer.blobs); diff --git a/pack-bitmap.c b/pack-bitmap.c index 4695aaf6b4..b53f37243c 100644 --- a/pack-bitmap.c +++ b/pack-bitmap.c @@ -163,7 +163,7 @@ static int load_bitmap_header(struct bitmap_index *index) } index->entry_count = ntohl(header->entry_count); - index->map_pos += sizeof(*header); + index->map_pos += sizeof(*header) - GIT_MAX_RAWSZ + the_hash_algo->rawsz; return 0; } diff --git a/pack-bitmap.h b/pack-bitmap.h index 8418ba8c79..344ba23af9 100644 --- a/pack-bitmap.h +++ b/pack-bitmap.h @@ -14,7 +14,7 @@ struct bitmap_disk_header { uint16_t version; uint16_t options; uint32_t entry_count; - unsigned char checksum[20]; + unsigned char checksum[GIT_MAX_RAWSZ]; }; static const char BITMAP_IDX_SIGNATURE[] = {'B', 'I', 'T', 'M'}; From patchwork Tue Feb 12 01:22:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "brian m. carlson" X-Patchwork-Id: 10807117 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 798E11575 for ; Tue, 12 Feb 2019 01:23:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6AF432AC23 for ; Tue, 12 Feb 2019 01:23:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5F7EF2AC2D; Tue, 12 Feb 2019 01:23:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 11EA12AC23 for ; Tue, 12 Feb 2019 01:23:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726961AbfBLBXT (ORCPT ); Mon, 11 Feb 2019 20:23:19 -0500 Received: from injection.crustytoothpaste.net ([192.241.140.119]:34244 "EHLO injection.crustytoothpaste.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726147AbfBLBXS (ORCPT ); Mon, 11 Feb 2019 20:23:18 -0500 Received: from genre.crustytoothpaste.net (unknown [IPv6:2001:470:b978:101:3dc7:72ec:75fa:fee5]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by injection.crustytoothpaste.net (Postfix) with ESMTPSA id 2036060898; Tue, 12 Feb 2019 01:23:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=crustytoothpaste.net; s=default; t=1549934597; bh=ns5OIlmI+Q9VJxVLCbPsvywGa+K6IjsuT4RgI4txHJI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Reply-To: Subject:Date:To:CC:Resent-Date:Resent-From:Resent-To:Resent-Cc: In-Reply-To:References:Content-Type:Content-Disposition; b=X52Iz/sqT3sWACYXftlpMS/uMrSo966ssFk+0ayk71qZen1mnNYVPMYJqde2hPCsD cYox8MN8PbdFpy2U2thhrQ6YYQHzinrexNoyvtLfh76lwG+cw2jVIYZz0qK2WrBHqD EhrjHaxEcTVB4Z0PA/tK0uqQEW4PQ5fNOjRKKxQP6TFhJuP/ysTeJncQEPSaCIYqZc XBlJcWbgkDP8Twq9Fz9FycE3XBlWGcY0EnKOi6qz2BLunWRF0fxYc40ZPeLpEho/cK ci/eGF5pJeauP9Zmm5TrFEmymVJyumdwbp/YyiHAkS0CN+8McINc16pbbg3fse78kb FyyTLnNadcREacbeAm3FnPj45T6aJo5Ksqr4AOs/9sXofJKuBTR0A8dpqrGJyKytrC 8ttcLTStYl3R/QWjYCx4wqyb+voPOE1h/6gDejGAVp7lGDZmLrjAaRQgtGkU+sBttU +YN4JNoiDEKi5LOLWkCwZIOhMtF4kmLU/zpJwrUWXgI8bvCQY5U From: "brian m. carlson" To: Cc: =?utf-8?q?Ren=C3=A9_Scharfe?= , Duy Nguyen Subject: [PATCH 03/31] pack-bitmap: convert struct stored_bitmap to object_id Date: Tue, 12 Feb 2019 01:22:28 +0000 Message-Id: <20190212012256.1005924-4-sandals@crustytoothpaste.net> X-Mailer: git-send-email 2.20.1.791.gb4d0f1c61a In-Reply-To: <20190212012256.1005924-1-sandals@crustytoothpaste.net> References: <20190212012256.1005924-1-sandals@crustytoothpaste.net> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 127.0.1.1 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Convert struct stored_bitmap to use struct object_id. Signed-off-by: brian m. carlson --- pack-bitmap.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pack-bitmap.c b/pack-bitmap.c index b53f37243c..c760913cea 100644 --- a/pack-bitmap.c +++ b/pack-bitmap.c @@ -18,7 +18,7 @@ * commit. */ struct stored_bitmap { - unsigned char sha1[20]; + struct object_id oid; struct ewah_bitmap *root; struct stored_bitmap *xor; int flags; @@ -181,9 +181,9 @@ static struct stored_bitmap *store_bitmap(struct bitmap_index *index, stored->root = root; stored->xor = xor_with; stored->flags = flags; - hashcpy(stored->sha1, sha1); + oidread(&stored->oid, sha1); - hash_pos = kh_put_sha1(index->bitmaps, stored->sha1, &ret); + hash_pos = kh_put_sha1(index->bitmaps, stored->oid.hash, &ret); /* a 0 return code means the insertion succeeded with no changes, * because the SHA1 already existed on the map. this is bad, there @@ -1080,7 +1080,7 @@ int rebuild_existing_bitmaps(struct bitmap_index *bitmap_git, lookup_stored_bitmap(stored), rebuild)) { hash_pos = kh_put_sha1(reused_bitmaps, - stored->sha1, + stored->oid.hash, &hash_ret); kh_value(reused_bitmaps, hash_pos) = bitmap_to_ewah(rebuild); From patchwork Tue Feb 12 01:22:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "brian m. carlson" X-Patchwork-Id: 10807123 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A51FD1575 for ; Tue, 12 Feb 2019 01:23:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 95C942AC23 for ; Tue, 12 Feb 2019 01:23:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8A4272AC2D; Tue, 12 Feb 2019 01:23:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2E0AD2AC23 for ; Tue, 12 Feb 2019 01:23:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726997AbfBLBXW (ORCPT ); Mon, 11 Feb 2019 20:23:22 -0500 Received: from injection.crustytoothpaste.net ([192.241.140.119]:34250 "EHLO injection.crustytoothpaste.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726949AbfBLBXU (ORCPT ); Mon, 11 Feb 2019 20:23:20 -0500 Received: from genre.crustytoothpaste.net (unknown [IPv6:2001:470:b978:101:3dc7:72ec:75fa:fee5]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by injection.crustytoothpaste.net (Postfix) with ESMTPSA id D058360737; Tue, 12 Feb 2019 01:23:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=crustytoothpaste.net; s=default; t=1549934598; bh=2J0p3k1C4WeqnaBhIcuvMunKCzVGO3+S7hPfdtIQOBI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Reply-To: Subject:Date:To:CC:Resent-Date:Resent-From:Resent-To:Resent-Cc: In-Reply-To:References:Content-Type:Content-Disposition; b=DvwzQod8mp0edw/NrosfWJCLPahk3Rdu4wTRGOUMd8T/Ha/cbtETTSXgWuiLEgCxK g+vBYydY1UReD+9Zb0jse3cKVI/82Jz8nbYwJmGg5mvKpPNJjSblraGYzOGMuomWDZ gkVH+jTSIY+88sfX529BdDByngTnh5fUfKZoBOe21sx4/L/tRz8psUfXFanIu14dI5 XmvQhRmwM1Wz+2Pj3aUpt7uA+/D87JUPAMEZJB0HLm+LHgC0aDl8Qhrg1mBMFXNXho Rxnh7EafBjvcqs35IR8HVZuRG/YzW+khQC0IIeQZNiUaZbjBZkv64p0YH8cqmnHQi7 GMDuYYdo2ZySTrJywoSHAJEDRaiqc5A1YsZ1hgv5kJzr4HnTDt45QPKo6/VXT5xrgW /FM+afc7XTblYf8joh3VvhKjPuXS5HRZWHhBJRudiNJSWZm+82dGOD6KqWBrDyA8tb yJAZI2KX2r69Bw10ev+C1zTHQBi7A8t361UxG6eIYLuGfvkvm3d From: "brian m. carlson" To: Cc: =?utf-8?q?Ren=C3=A9_Scharfe?= , Duy Nguyen Subject: [PATCH 04/31] pack-bitmap: replace sha1_to_hex Date: Tue, 12 Feb 2019 01:22:29 +0000 Message-Id: <20190212012256.1005924-5-sandals@crustytoothpaste.net> X-Mailer: git-send-email 2.20.1.791.gb4d0f1c61a In-Reply-To: <20190212012256.1005924-1-sandals@crustytoothpaste.net> References: <20190212012256.1005924-1-sandals@crustytoothpaste.net> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 127.0.1.1 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Replace the uses of sha1_to_hex in the pack bitmap code with hash_to_hex to allow the use of SHA-256 as well. Rename a few variables since they are no longer limited to SHA-1. Signed-off-by: brian m. carlson --- pack-bitmap-write.c | 6 +++--- pack-bitmap.c | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pack-bitmap-write.c b/pack-bitmap-write.c index c82fb01fd7..802ed62677 100644 --- a/pack-bitmap-write.c +++ b/pack-bitmap-write.c @@ -142,13 +142,13 @@ static inline void reset_all_seen(void) seen_objects_nr = 0; } -static uint32_t find_object_pos(const unsigned char *sha1) +static uint32_t find_object_pos(const unsigned char *hash) { - struct object_entry *entry = packlist_find(writer.to_pack, sha1, NULL); + struct object_entry *entry = packlist_find(writer.to_pack, hash, NULL); if (!entry) { die("Failed to write bitmap index. Packfile doesn't have full closure " - "(object %s is missing)", sha1_to_hex(sha1)); + "(object %s is missing)", hash_to_hex(hash)); } return oe_in_pack_pos(writer.to_pack, entry); diff --git a/pack-bitmap.c b/pack-bitmap.c index c760913cea..6d6fa68563 100644 --- a/pack-bitmap.c +++ b/pack-bitmap.c @@ -169,7 +169,7 @@ static int load_bitmap_header(struct bitmap_index *index) static struct stored_bitmap *store_bitmap(struct bitmap_index *index, struct ewah_bitmap *root, - const unsigned char *sha1, + const unsigned char *hash, struct stored_bitmap *xor_with, int flags) { @@ -181,7 +181,7 @@ static struct stored_bitmap *store_bitmap(struct bitmap_index *index, stored->root = root; stored->xor = xor_with; stored->flags = flags; - oidread(&stored->oid, sha1); + oidread(&stored->oid, hash); hash_pos = kh_put_sha1(index->bitmaps, stored->oid.hash, &ret); @@ -189,7 +189,7 @@ static struct stored_bitmap *store_bitmap(struct bitmap_index *index, * because the SHA1 already existed on the map. this is bad, there * shouldn't be duplicated commits in the index */ if (ret == 0) { - error("Duplicate entry in bitmap index: %s", sha1_to_hex(sha1)); + error("Duplicate entry in bitmap index: %s", hash_to_hex(hash)); return NULL; } @@ -805,7 +805,7 @@ int reuse_partial_packfile_from_bitmap(struct bitmap_index *bitmap_git, fprintf(stderr, "Failed to reuse at %d (%016llx)\n", reuse_objects, result->words[i]); - fprintf(stderr, " %s\n", sha1_to_hex(sha1)); + fprintf(stderr, " %s\n", hash_to_hex(sha1)); } #endif From patchwork Tue Feb 12 01:22:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "brian m. carlson" X-Patchwork-Id: 10807121 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DEDFF13A4 for ; Tue, 12 Feb 2019 01:23:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CF5142AC23 for ; Tue, 12 Feb 2019 01:23:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C3A2C2AC2D; Tue, 12 Feb 2019 01:23:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7A9BC2AC23 for ; Tue, 12 Feb 2019 01:23:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727024AbfBLBXW (ORCPT ); Mon, 11 Feb 2019 20:23:22 -0500 Received: from injection.crustytoothpaste.net ([192.241.140.119]:34244 "EHLO injection.crustytoothpaste.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726969AbfBLBXU (ORCPT ); Mon, 11 Feb 2019 20:23:20 -0500 Received: from genre.crustytoothpaste.net (unknown [IPv6:2001:470:b978:101:3dc7:72ec:75fa:fee5]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by injection.crustytoothpaste.net (Postfix) with ESMTPSA id A49BB60897; Tue, 12 Feb 2019 01:23:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=crustytoothpaste.net; s=default; t=1549934599; bh=dirQ7xr11Sisxi8H2UaPZ7PLORagH7dGcrdo9rD/WUw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Reply-To: Subject:Date:To:CC:Resent-Date:Resent-From:Resent-To:Resent-Cc: In-Reply-To:References:Content-Type:Content-Disposition; b=A/ykujYDBPKXWAf/R+h2ibmAx4qovrQ6I1Qp5Hr1pXQrCvnJ6Z5ctXpqYJYXQOObY oHlkupBkjSTXnkeApsAgT1E0q3FXeOX0JULfZRkCKQ0IzTubaR02pvrTURvjtsNViI +b4xpnJbAcGf7nDJbjTPCgU9jwUvmx5oxWQ4u3o77EdtpFUOcyzmVlkXDaBCwqJ74S tKJ/RlaogHBuCXtDQWaP5kBnLyAJBT0oKvgfUXnWuj54vRIN+hAGqVjbMecN5Drl4Y cONwFwLlczNqcQ8IOyJqpX9QGdG9lbv+H1N6Ot2a6Rut4ZUxpFRU2On6Phdozhxr5Q sMBZRV82jKsPolP/ERfHScE3Yo4pqU6NwW27/odZfIGx2U9xsWpbqFtTBGE7gfLOz0 swWidmnqhFfcYy7cl+SRgO2mzOJEQNALNXZUkkoSBUdTt/lu86/TX+yjoNqivG9X4c YJ2zypSMsy5Xf1XgfOTq8NB/z8d+kIGSZvc0lk5VVAftq4l0SYV From: "brian m. carlson" To: Cc: =?utf-8?q?Ren=C3=A9_Scharfe?= , Duy Nguyen Subject: [PATCH 05/31] pack-bitmap: switch hard-coded constants to the_hash_algo Date: Tue, 12 Feb 2019 01:22:30 +0000 Message-Id: <20190212012256.1005924-6-sandals@crustytoothpaste.net> X-Mailer: git-send-email 2.20.1.791.gb4d0f1c61a In-Reply-To: <20190212012256.1005924-1-sandals@crustytoothpaste.net> References: <20190212012256.1005924-1-sandals@crustytoothpaste.net> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 127.0.1.1 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Switch two hard-coded uses of 20 to references to the_hash_algo. Signed-off-by: brian m. carlson --- pack-bitmap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pack-bitmap.c b/pack-bitmap.c index 6d6fa68563..603492c237 100644 --- a/pack-bitmap.c +++ b/pack-bitmap.c @@ -138,7 +138,7 @@ static int load_bitmap_header(struct bitmap_index *index) { struct bitmap_disk_header *header = (void *)index->map; - if (index->map_size < sizeof(*header) + 20) + if (index->map_size < sizeof(*header) + the_hash_algo->rawsz) return error("Corrupted bitmap index (missing header data)"); if (memcmp(header->magic, BITMAP_IDX_SIGNATURE, sizeof(BITMAP_IDX_SIGNATURE)) != 0) @@ -157,7 +157,7 @@ static int load_bitmap_header(struct bitmap_index *index) "(Git requires BITMAP_OPT_FULL_DAG)"); if (flags & BITMAP_OPT_HASH_CACHE) { - unsigned char *end = index->map + index->map_size - 20; + unsigned char *end = index->map + index->map_size - the_hash_algo->rawsz; index->hashes = ((uint32_t *)end) - index->pack->num_objects; } } From patchwork Tue Feb 12 01:22:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "brian m. carlson" X-Patchwork-Id: 10807129 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8066D1575 for ; Tue, 12 Feb 2019 01:23:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 708AB2AC25 for ; Tue, 12 Feb 2019 01:23:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6438F2AC31; Tue, 12 Feb 2019 01:23:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1AA112AC25 for ; Tue, 12 Feb 2019 01:23:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727106AbfBLBX0 (ORCPT ); Mon, 11 Feb 2019 20:23:26 -0500 Received: from injection.crustytoothpaste.net ([192.241.140.119]:34260 "EHLO injection.crustytoothpaste.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726147AbfBLBXV (ORCPT ); Mon, 11 Feb 2019 20:23:21 -0500 Received: from genre.crustytoothpaste.net (unknown [IPv6:2001:470:b978:101:3dc7:72ec:75fa:fee5]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by injection.crustytoothpaste.net (Postfix) with ESMTPSA id 50D0360898; Tue, 12 Feb 2019 01:23:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=crustytoothpaste.net; s=default; t=1549934599; bh=xY01/f579AhsVZN/bnBj89/b9ShunR77xSLUR7h63b0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Reply-To: Subject:Date:To:CC:Resent-Date:Resent-From:Resent-To:Resent-Cc: In-Reply-To:References:Content-Type:Content-Disposition; b=PrkBM3bmEihV+o0AzY1NLMgs24iANEWXjo/YYSjZmWL+J4eew4FPmfz/wYyOkjliV OeUI7C6L5cof8wGxDkoOlZnpgyRIm0U4wzRQZfzdIjL9Ij6AuPNZetjaXin2Qiqy/k QIAgQoUuIVMi37maIEKP+UjKBdFzxsQlKFI3Py/zFysEnruuVALATGnFKt0Sp0HAHN fFEAcZLG943RahruRtNfDCdY7Rb11dTR9tyxj5AU9USzlyfFCL+af8ZVltMCI9g8Zi FM92BIqfQRbx26uQ9U/wtEo15tqAKMEvhQaaGtc3RBmjM1x9V902txuMCxzxbtgvaz FYtpZ/st/f1aBwLzekJFYqV1Tu+wPB95HN/ZYgDgp5INYSUTe0PqpSoL9Ut3Cvm31N G0idCndVZeuknA3IlqP0zHXZ/v71ruXBVWUmsdfuWzoEYCpRjR9ckv3QzrJJkGmRF2 Rfyh8cVILENKavncFbEPRgUr45niIsYlEqjX9vqjl+EbcfuWMpH From: "brian m. carlson" To: Cc: =?utf-8?q?Ren=C3=A9_Scharfe?= , Duy Nguyen Subject: [PATCH 06/31] submodule: avoid hard-coded constants Date: Tue, 12 Feb 2019 01:22:31 +0000 Message-Id: <20190212012256.1005924-7-sandals@crustytoothpaste.net> X-Mailer: git-send-email 2.20.1.791.gb4d0f1c61a In-Reply-To: <20190212012256.1005924-1-sandals@crustytoothpaste.net> References: <20190212012256.1005924-1-sandals@crustytoothpaste.net> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 127.0.1.1 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Instead of using hard-coded 40-based constants, express these values in terms of the_hash_algo and GIT_MAX_HEXSZ. Signed-off-by: brian m. carlson --- merge-recursive.c | 2 +- submodule.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/merge-recursive.c b/merge-recursive.c index 4851825aeb..b8bd5d4f8d 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -1122,7 +1122,7 @@ static int find_first_merges(struct repository *repo, struct commit *commit; int contains_another; - char merged_revision[42]; + char merged_revision[GIT_MAX_HEXSZ + 2]; const char *rev_args[] = { "rev-list", "--merges", "--ancestry-path", "--all", merged_revision, NULL }; struct rev_info revs; diff --git a/submodule.c b/submodule.c index 934ecfa294..0e2faaa41b 100644 --- a/submodule.c +++ b/submodule.c @@ -990,7 +990,7 @@ static int submodule_needs_pushing(struct repository *r, if (start_command(&cp)) die("Could not run 'git rev-list --not --remotes -n 1' command in submodule %s", path); - if (strbuf_read(&buf, cp.out, 41)) + if (strbuf_read(&buf, cp.out, the_hash_algo->hexsz + 1)) needs_pushing = 1; finish_command(&cp); close(cp.out); From patchwork Tue Feb 12 01:22:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "brian m. carlson" X-Patchwork-Id: 10807175 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4B49013A4 for ; Tue, 12 Feb 2019 01:24:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3C8A72A41A for ; Tue, 12 Feb 2019 01:24:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 308022AC6A; Tue, 12 Feb 2019 01:24:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DD3B92A41A for ; Tue, 12 Feb 2019 01:23:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727054AbfBLBXZ (ORCPT ); Mon, 11 Feb 2019 20:23:25 -0500 Received: from injection.crustytoothpaste.net ([192.241.140.119]:34250 "EHLO injection.crustytoothpaste.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726177AbfBLBXV (ORCPT ); Mon, 11 Feb 2019 20:23:21 -0500 Received: from genre.crustytoothpaste.net (unknown [IPv6:2001:470:b978:101:3dc7:72ec:75fa:fee5]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by injection.crustytoothpaste.net (Postfix) with ESMTPSA id 023EB60E51; Tue, 12 Feb 2019 01:23:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=crustytoothpaste.net; s=default; t=1549934600; bh=HMx0XwcuzIG10NLQ1Reh03cO6a4KnQFfr4gzx9GgN9g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Reply-To: Subject:Date:To:CC:Resent-Date:Resent-From:Resent-To:Resent-Cc: In-Reply-To:References:Content-Type:Content-Disposition; b=oDv5XLh818clWtBvzPF9ysFHIf5To/BCztmIw/D77Kyo9ytunDihezcJJhEbv2nK6 +IbUwpZpfGmWIrOv9bprFZMsJJCQojJMs74g+xAyfkXAMYfqUqMav14n9JGTf+0+8g dmoq6JhRY7WMZ6/Dqur+zI3fAZ2p6oLsl7iyoH8pCeWGOYLpLxFx3SxFBTI/t9fdkh CGMNWtoCUmPq/10bA44xks2QPh58Zwx55R8OW5wQs9gpQXJaWWokuEs7rMrv1sQP3S qrXq5w2Vd0ymKj47Vai+ig2VxI50xQBJK6cpQ1PAvzMl0rAdCKDCaIx0uj1+09ASQS 7JJZSA9FJX+PLyeqgJbkUJongKP9A+jkevwrDToalwBJTQ1TsTQZo9OAA09/tSIT1R 1rybHqP6kIrEfa9dsU9vWWNh67B9jifKvuBPWa83cC1Y/CPSjZpfnbZQ4F9G+MMJhj 8jBVUn5Et8wUTV1FWD7cVdC/sabCGjIxazoQybwBfRUOQ1NyY5y From: "brian m. carlson" To: Cc: =?utf-8?q?Ren=C3=A9_Scharfe?= , Duy Nguyen Subject: [PATCH 07/31] notes-merge: switch to use the_hash_algo Date: Tue, 12 Feb 2019 01:22:32 +0000 Message-Id: <20190212012256.1005924-8-sandals@crustytoothpaste.net> X-Mailer: git-send-email 2.20.1.791.gb4d0f1c61a In-Reply-To: <20190212012256.1005924-1-sandals@crustytoothpaste.net> References: <20190212012256.1005924-1-sandals@crustytoothpaste.net> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 127.0.1.1 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Switch from using GIT_SHA1_HEXSZ to GIT_MAX_HEXSZ and the_hash_algo so that the code works with any hash algorithm. Signed-off-by: brian m. carlson --- notes-merge.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/notes-merge.c b/notes-merge.c index 280aa8e6c1..2fe724f1cf 100644 --- a/notes-merge.c +++ b/notes-merge.c @@ -29,14 +29,14 @@ void init_notes_merge_options(struct repository *r, static int path_to_oid(const char *path, struct object_id *oid) { - char hex_oid[GIT_SHA1_HEXSZ]; + char hex_oid[GIT_MAX_HEXSZ]; int i = 0; - while (*path && i < GIT_SHA1_HEXSZ) { + while (*path && i < the_hash_algo->hexsz) { if (*path != '/') hex_oid[i++] = *path; path++; } - if (*path || i != GIT_SHA1_HEXSZ) + if (*path || i != the_hash_algo->hexsz) return -1; return get_oid_hex(hex_oid, oid); } From patchwork Tue Feb 12 01:22:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "brian m. carlson" X-Patchwork-Id: 10807125 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4B29A1575 for ; Tue, 12 Feb 2019 01:23:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3637D2AC23 for ; Tue, 12 Feb 2019 01:23:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2A8782AC2D; Tue, 12 Feb 2019 01:23:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9F0682AC23 for ; Tue, 12 Feb 2019 01:23:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727036AbfBLBXY (ORCPT ); Mon, 11 Feb 2019 20:23:24 -0500 Received: from injection.crustytoothpaste.net ([192.241.140.119]:34244 "EHLO injection.crustytoothpaste.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726986AbfBLBXW (ORCPT ); Mon, 11 Feb 2019 20:23:22 -0500 Received: from genre.crustytoothpaste.net (unknown [IPv6:2001:470:b978:101:3dc7:72ec:75fa:fee5]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by injection.crustytoothpaste.net (Postfix) with ESMTPSA id 396D360897; Tue, 12 Feb 2019 01:23:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=crustytoothpaste.net; s=default; t=1549934601; bh=vPJQFoEed+gFMdDdENrb6x7nOF3lkGvACfB9M9gcPUA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Reply-To: Subject:Date:To:CC:Resent-Date:Resent-From:Resent-To:Resent-Cc: In-Reply-To:References:Content-Type:Content-Disposition; b=fDRuUdErjnVkvCKDJD9aA4RWg5DYVlFQNvUKrgtsC6UAOwJrBqr0gxzjjxjotbIZ5 EJEMlEhh1/By4zqGvoHjme+JxlHY6xr97V+vhmzPhLilueGtAb51yRvQE24Gsjz9B1 293u/ZUavD9ZHhi2rHh604b2zlEGDoTkgtLYUY/pH+tuIj75YyzlZH+rXz6ibxYK0X wDaJ6+FLJ5REde6s5FYdkNlCg32/nx7GqLgHbXbqwVo4w8KE5/vRUQ0tJd0kMOh0HP DxqbpdsgtqHFxAQOI8ILCl4ToQdrFNpzKgH1OmRyQvdjq3n0V0tu2G6WGkGnlDFPk2 395cZu/kiMfX+WFKABo06bbYc3wXPTuRbYRJ5xhNyrm4nJTgSh8R5YeQG7KnGFjKMK xp3jDhWer9reznshQ3gkcd9X3S58jVPe0xHIv7eadj/spoxiFbYqX4KzE9XRIGnssX fYXWenCA5z8vGhNT5qihIXrOo9vsqEbmaifszijPX72Jh0F85GF From: "brian m. carlson" To: Cc: =?utf-8?q?Ren=C3=A9_Scharfe?= , Duy Nguyen Subject: [PATCH 08/31] notes: make hash size independent Date: Tue, 12 Feb 2019 01:22:33 +0000 Message-Id: <20190212012256.1005924-9-sandals@crustytoothpaste.net> X-Mailer: git-send-email 2.20.1.791.gb4d0f1c61a In-Reply-To: <20190212012256.1005924-1-sandals@crustytoothpaste.net> References: <20190212012256.1005924-1-sandals@crustytoothpaste.net> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 127.0.1.1 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Switch out various uses of the GIT_SHA1_* constants with GIT_MAX_* constants for allocations and the_hash_algo for general parsing. Update a comment to no longer be SHA-1 specific. Signed-off-by: brian m. carlson --- notes.c | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/notes.c b/notes.c index 7f7cc4d511..96647f1d2d 100644 --- a/notes.c +++ b/notes.c @@ -67,8 +67,9 @@ struct non_note { #define GET_NIBBLE(n, sha1) ((((sha1)[(n) >> 1]) >> ((~(n) & 0x01) << 2)) & 0x0f) -#define KEY_INDEX (GIT_SHA1_RAWSZ - 1) -#define FANOUT_PATH_SEPARATORS ((GIT_SHA1_HEXSZ / 2) - 1) +#define KEY_INDEX (the_hash_algo->rawsz - 1) +#define FANOUT_PATH_SEPARATORS (the_hash_algo->rawsz - 1) +#define FANOUT_PATH_SEPARATORS_MAX ((GIT_MAX_HEXSZ / 2) - 1) #define SUBTREE_SHA1_PREFIXCMP(key_sha1, subtree_sha1) \ (memcmp(key_sha1, subtree_sha1, subtree_sha1[KEY_INDEX])) @@ -198,7 +199,7 @@ static void note_tree_remove(struct notes_tree *t, struct leaf_node *entry) { struct leaf_node *l; - struct int_node *parent_stack[GIT_SHA1_RAWSZ]; + struct int_node *parent_stack[GIT_MAX_RAWSZ]; unsigned char i, j; void **p = note_tree_search(t, &tree, &n, entry->key_oid.hash); @@ -394,6 +395,7 @@ static void load_subtree(struct notes_tree *t, struct leaf_node *subtree, void *buf; struct tree_desc desc; struct name_entry entry; + const unsigned hashsz = the_hash_algo->rawsz; buf = fill_tree_descriptor(&desc, &subtree->val_oid); if (!buf) @@ -401,7 +403,7 @@ static void load_subtree(struct notes_tree *t, struct leaf_node *subtree, oid_to_hex(&subtree->val_oid)); prefix_len = subtree->key_oid.hash[KEY_INDEX]; - if (prefix_len >= GIT_SHA1_RAWSZ) + if (prefix_len >= hashsz) BUG("prefix_len (%"PRIuMAX") is out of range", (uintmax_t)prefix_len); if (prefix_len * 2 < n) BUG("prefix_len (%"PRIuMAX") is too small", (uintmax_t)prefix_len); @@ -411,7 +413,7 @@ static void load_subtree(struct notes_tree *t, struct leaf_node *subtree, struct leaf_node *l; size_t path_len = strlen(entry.path); - if (path_len == 2 * (GIT_SHA1_RAWSZ - prefix_len)) { + if (path_len == 2 * (hashsz - prefix_len)) { /* This is potentially the remainder of the SHA-1 */ if (!S_ISREG(entry.mode)) @@ -419,7 +421,7 @@ static void load_subtree(struct notes_tree *t, struct leaf_node *subtree, goto handle_non_note; if (hex_to_bytes(object_oid.hash + prefix_len, entry.path, - GIT_SHA1_RAWSZ - prefix_len)) + hashsz - prefix_len)) goto handle_non_note; /* entry.path is not a SHA1 */ type = PTR_TYPE_NOTE; @@ -439,7 +441,7 @@ static void load_subtree(struct notes_tree *t, struct leaf_node *subtree, * except for the last byte, where we write * the length: */ - memset(object_oid.hash + len, 0, GIT_SHA1_RAWSZ - len - 1); + memset(object_oid.hash + len, 0, hashsz - len - 1); object_oid.hash[KEY_INDEX] = (unsigned char)len; type = PTR_TYPE_SUBTREE; @@ -527,15 +529,15 @@ static unsigned char determine_fanout(struct int_node *tree, unsigned char n, return fanout + 1; } -/* hex SHA1 + 19 * '/' + NUL */ -#define FANOUT_PATH_MAX GIT_SHA1_HEXSZ + FANOUT_PATH_SEPARATORS + 1 +/* hex oid + one slash between each pair + NUL */ +#define FANOUT_PATH_MAX GIT_MAX_HEXSZ + FANOUT_PATH_SEPARATORS_MAX + 1 static void construct_path_with_fanout(const unsigned char *sha1, unsigned char fanout, char *path) { unsigned int i = 0, j = 0; const char *hex_sha1 = sha1_to_hex(sha1); - assert(fanout < GIT_SHA1_RAWSZ); + assert(fanout < the_hash_algo->rawsz); while (fanout) { path[i++] = hex_sha1[j++]; path[i++] = hex_sha1[j++]; @@ -637,10 +639,10 @@ static inline int matches_tree_write_stack(struct tree_write_stack *tws, static void write_tree_entry(struct strbuf *buf, unsigned int mode, const char *path, unsigned int path_len, const - unsigned char *sha1) + unsigned char *hash) { strbuf_addf(buf, "%o %.*s%c", mode, path_len, path, '\0'); - strbuf_add(buf, sha1, GIT_SHA1_RAWSZ); + strbuf_add(buf, hash, the_hash_algo->rawsz); } static void tree_write_stack_init_subtree(struct tree_write_stack *tws, @@ -652,7 +654,7 @@ static void tree_write_stack_init_subtree(struct tree_write_stack *tws, n = (struct tree_write_stack *) xmalloc(sizeof(struct tree_write_stack)); n->next = NULL; - strbuf_init(&n->buf, 256 * (32 + GIT_SHA1_HEXSZ)); /* assume 256 entries per tree */ + strbuf_init(&n->buf, 256 * (32 + the_hash_algo->hexsz)); /* assume 256 entries per tree */ n->path[0] = n->path[1] = '\0'; tws->next = n; tws->path[0] = path[0]; @@ -757,7 +759,7 @@ static int write_each_note(const struct object_id *object_oid, note_path[note_path_len] = '\0'; mode = 040000; } - assert(note_path_len <= GIT_SHA1_HEXSZ + FANOUT_PATH_SEPARATORS); + assert(note_path_len <= GIT_MAX_HEXSZ + FANOUT_PATH_SEPARATORS); /* Weave non-note entries into note entries */ return write_each_non_note_until(note_path, d) || @@ -1137,7 +1139,7 @@ int write_notes_tree(struct notes_tree *t, struct object_id *result) /* Prepare for traversal of current notes tree */ root.next = NULL; /* last forward entry in list is grounded */ - strbuf_init(&root.buf, 256 * (32 + GIT_SHA1_HEXSZ)); /* assume 256 entries */ + strbuf_init(&root.buf, 256 * (32 + the_hash_algo->hexsz)); /* assume 256 entries */ root.path[0] = root.path[1] = '\0'; cb_data.root = &root; cb_data.next_non_note = t->first_non_note; From patchwork Tue Feb 12 01:22:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "brian m. carlson" X-Patchwork-Id: 10807127 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7B6B113A4 for ; Tue, 12 Feb 2019 01:23:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6C6872AC23 for ; Tue, 12 Feb 2019 01:23:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 60CE32AC2D; Tue, 12 Feb 2019 01:23:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 117EC2AC23 for ; Tue, 12 Feb 2019 01:23:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727067AbfBLBXZ (ORCPT ); Mon, 11 Feb 2019 20:23:25 -0500 Received: from injection.crustytoothpaste.net ([192.241.140.119]:34260 "EHLO injection.crustytoothpaste.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727027AbfBLBXY (ORCPT ); Mon, 11 Feb 2019 20:23:24 -0500 Received: from genre.crustytoothpaste.net (unknown [IPv6:2001:470:b978:101:3dc7:72ec:75fa:fee5]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by injection.crustytoothpaste.net (Postfix) with ESMTPSA id 579C960E52; Tue, 12 Feb 2019 01:23:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=crustytoothpaste.net; s=default; t=1549934602; bh=OWpABVvwG3CC3PnX6hGwinD43iXSki/R5NxyAxbG6zc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Reply-To: Subject:Date:To:CC:Resent-Date:Resent-From:Resent-To:Resent-Cc: In-Reply-To:References:Content-Type:Content-Disposition; b=V94OFbMoe4x8hSu+7kEEYzOIYY7WLibNBQBR6U8TFwAadCQhD++goyPnhFu84khrB KbTu0ADkLtBuel3qqmWEiEq9NUzIBqOSovjM0lSSUYIpUQAX5nAttM+Dhx9Y7I2YFz sCoV640Wss5RKVC6o73pf3zeyxKvJ2bJ2qL4HD6YIcf3iPHDMqOVsdbptKeqZts9wm aJJKBzjJFMo4jjq+IeHmO0XttFEvOu+bmy8Q8Vj1S9SYBxd3lIQWb5zraW3eXY7FCU RJSnozABfBPh8JWsVOfiaz/TEa1H2S4BF0bBQebbRkn5MtoT0fhezivNWZZbTVzt7k 782XH5eXs31LXOWhKJEtlL2/v7NrKGxCiYf8HCqRsaOx+l8SjNxo/0ymcHbNuXQBnl ES+TFNiLf5M+zuVXkB2cZcBzbfG03fD9mPfRQ2/RF7t9Mjy1o+S+EYkc6M5eil/6Lu nzb8wCHnVFNdOqjnLAZn+QLIRdvDyHoAihAZY8G2ShhM5clKhTT From: "brian m. carlson" To: Cc: =?utf-8?q?Ren=C3=A9_Scharfe?= , Duy Nguyen Subject: [PATCH 09/31] notes: replace sha1_to_hex Date: Tue, 12 Feb 2019 01:22:34 +0000 Message-Id: <20190212012256.1005924-10-sandals@crustytoothpaste.net> X-Mailer: git-send-email 2.20.1.791.gb4d0f1c61a In-Reply-To: <20190212012256.1005924-1-sandals@crustytoothpaste.net> References: <20190212012256.1005924-1-sandals@crustytoothpaste.net> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 127.0.1.1 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Replace the uses of sha1_to_hex in this function with hash_to_hex to allow the use of SHA-256 as well. Rename some variables since this code is no longer limited to SHA-1. Signed-off-by: brian m. carlson --- notes.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/notes.c b/notes.c index 96647f1d2d..a9a3ddd6d7 100644 --- a/notes.c +++ b/notes.c @@ -532,19 +532,19 @@ static unsigned char determine_fanout(struct int_node *tree, unsigned char n, /* hex oid + one slash between each pair + NUL */ #define FANOUT_PATH_MAX GIT_MAX_HEXSZ + FANOUT_PATH_SEPARATORS_MAX + 1 -static void construct_path_with_fanout(const unsigned char *sha1, +static void construct_path_with_fanout(const unsigned char *hash, unsigned char fanout, char *path) { unsigned int i = 0, j = 0; - const char *hex_sha1 = sha1_to_hex(sha1); + const char *hex_hash = hash_to_hex(hash); assert(fanout < the_hash_algo->rawsz); while (fanout) { - path[i++] = hex_sha1[j++]; - path[i++] = hex_sha1[j++]; + path[i++] = hex_hash[j++]; + path[i++] = hex_hash[j++]; path[i++] = '/'; fanout--; } - xsnprintf(path + i, FANOUT_PATH_MAX - i, "%s", hex_sha1 + j); + xsnprintf(path + i, FANOUT_PATH_MAX - i, "%s", hex_hash + j); } static int for_each_note_helper(struct notes_tree *t, struct int_node *tree, @@ -1167,7 +1167,7 @@ void prune_notes(struct notes_tree *t, int flags) while (l) { if (flags & NOTES_PRUNE_VERBOSE) - printf("%s\n", sha1_to_hex(l->sha1)); + printf("%s\n", hash_to_hex(l->sha1)); if (!(flags & NOTES_PRUNE_DRYRUN)) remove_note(t, l->sha1); l = l->next; From patchwork Tue Feb 12 01:22:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "brian m. carlson" X-Patchwork-Id: 10807133 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 73ED613A4 for ; Tue, 12 Feb 2019 01:23:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 631B92AC25 for ; Tue, 12 Feb 2019 01:23:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 56FF12AC31; Tue, 12 Feb 2019 01:23:32 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AD6472AC25 for ; Tue, 12 Feb 2019 01:23:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727140AbfBLBXa (ORCPT ); Mon, 11 Feb 2019 20:23:30 -0500 Received: from injection.crustytoothpaste.net ([192.241.140.119]:34244 "EHLO injection.crustytoothpaste.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726986AbfBLBXZ (ORCPT ); Mon, 11 Feb 2019 20:23:25 -0500 Received: from genre.crustytoothpaste.net (unknown [IPv6:2001:470:b978:101:3dc7:72ec:75fa:fee5]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by injection.crustytoothpaste.net (Postfix) with ESMTPSA id 9035260898; Tue, 12 Feb 2019 01:23:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=crustytoothpaste.net; s=default; t=1549934603; bh=HYNOlAF8X1nzhpR01uWWaxlZjtcyodmx+NvLuLfpqpc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Reply-To: Subject:Date:To:CC:Resent-Date:Resent-From:Resent-To:Resent-Cc: In-Reply-To:References:Content-Type:Content-Disposition; b=a1qe3TH3DS01tKQM9kksZFKWnBgBIRx4zZa2UUjfWAoC9dAA1js1JOLfYPW4L9nbP OTwSFiJyTHXJD+7oSVc74HnE+qViwFP+G0sIxhJyB5G20Jrz7Zr317qZbw92PrYQRg NTrYV4p2AwQH/pqh2XfdyFkoQ4exROADKYvTjtV4sC3z/B7br+kaOHwow05dJHcEgv T87XsnVzCMxxk4xFHKzmUOY5GSD2lGTqgYzZtYqC09Ff4cYYfJY3oD2Uw227KGevJJ RuQICdOfPQaMnC/IZGaT46CnKaYZf9aTXNlT++V2W47GdavEjQRwtCDk3VZJGMO29D /FBNGuLla+5jqA+n/Nwcu3CrIXdyL4rYAjSuhDM8LabLujTmLT4CkaGfhCyYI9cMzW 1AIW4Ovo4JQCb/5wAZY9wS44so9yGunAiE8kPs5hj1Sb6vAwtz91t9ibFDjjlVaY09 RDmoNxbllhUs18OMwQMUSmSAHXH3Lis92c0E6qKc0bk/UnfydeY From: "brian m. carlson" To: Cc: =?utf-8?q?Ren=C3=A9_Scharfe?= , Duy Nguyen Subject: [PATCH 10/31] object-store: rename and expand packed_git's sha1 member Date: Tue, 12 Feb 2019 01:22:35 +0000 Message-Id: <20190212012256.1005924-11-sandals@crustytoothpaste.net> X-Mailer: git-send-email 2.20.1.791.gb4d0f1c61a In-Reply-To: <20190212012256.1005924-1-sandals@crustytoothpaste.net> References: <20190212012256.1005924-1-sandals@crustytoothpaste.net> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 127.0.1.1 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This member is used to represent the pack checksum of the pack in question. Expand this member to be GIT_MAX_RAWSZ bytes in length so it works with longer hashes and rename it to be "hash" instead of "sha1". This transformation was made with a change to the definition and the following semantic patch: @@ struct packed_git *E1; @@ - E1->sha1 + E1->hash @@ struct packed_git E1; @@ - E1.sha1 + E1.hash Signed-off-by: brian m. carlson --- builtin/pack-redundant.c | 2 +- fast-import.c | 17 +++++++++-------- http-push.c | 3 ++- http-walker.c | 2 +- http.c | 13 +++++++------ object-store.h | 2 +- packfile.c | 6 +++--- 7 files changed, 24 insertions(+), 21 deletions(-) diff --git a/builtin/pack-redundant.c b/builtin/pack-redundant.c index 11bc514566..d9af7f5414 100644 --- a/builtin/pack-redundant.c +++ b/builtin/pack-redundant.c @@ -689,7 +689,7 @@ int cmd_pack_redundant(int argc, const char **argv, const char *prefix) pl = red = pack_list_difference(local_packs, min); while (pl) { printf("%s\n%s\n", - sha1_pack_index_name(pl->pack->sha1), + sha1_pack_index_name(pl->pack->hash), pl->pack->pack_name); pl = pl->next; } diff --git a/fast-import.c b/fast-import.c index b7ba755c2b..7c9a10a77b 100644 --- a/fast-import.c +++ b/fast-import.c @@ -742,7 +742,8 @@ static const char *create_index(void) if (c != last) die("internal consistency error creating the index"); - tmpfile = write_idx_file(NULL, idx, object_count, &pack_idx_opts, pack_data->sha1); + tmpfile = write_idx_file(NULL, idx, object_count, &pack_idx_opts, + pack_data->hash); free(idx); return tmpfile; } @@ -753,7 +754,7 @@ static char *keep_pack(const char *curr_index_name) struct strbuf name = STRBUF_INIT; int keep_fd; - odb_pack_name(&name, pack_data->sha1, "keep"); + odb_pack_name(&name, pack_data->hash, "keep"); keep_fd = odb_pack_keep(name.buf); if (keep_fd < 0) die_errno("cannot create keep file"); @@ -761,11 +762,11 @@ static char *keep_pack(const char *curr_index_name) if (close(keep_fd)) die_errno("failed to write keep file"); - odb_pack_name(&name, pack_data->sha1, "pack"); + odb_pack_name(&name, pack_data->hash, "pack"); if (finalize_object_file(pack_data->pack_name, name.buf)) die("cannot store pack file"); - odb_pack_name(&name, pack_data->sha1, "idx"); + odb_pack_name(&name, pack_data->hash, "idx"); if (finalize_object_file(curr_index_name, name.buf)) die("cannot store index file"); free((void *)curr_index_name); @@ -779,7 +780,7 @@ static void unkeep_all_packs(void) for (k = 0; k < pack_id; k++) { struct packed_git *p = all_packs[k]; - odb_pack_name(&name, p->sha1, "keep"); + odb_pack_name(&name, p->hash, "keep"); unlink_or_warn(name.buf); } strbuf_release(&name); @@ -821,9 +822,9 @@ static void end_packfile(void) close_pack_windows(pack_data); finalize_hashfile(pack_file, cur_pack_oid.hash, 0); - fixup_pack_header_footer(pack_data->pack_fd, pack_data->sha1, - pack_data->pack_name, object_count, - cur_pack_oid.hash, pack_size); + fixup_pack_header_footer(pack_data->pack_fd, pack_data->hash, + pack_data->pack_name, object_count, + cur_pack_oid.hash, pack_size); if (object_count <= unpack_limit) { if (!loosen_small_pack(pack_data)) { diff --git a/http-push.c b/http-push.c index b22c7caea0..b313ada515 100644 --- a/http-push.c +++ b/http-push.c @@ -315,7 +315,8 @@ static void start_fetch_packed(struct transfer_request *request) return; } - fprintf(stderr, "Fetching pack %s\n", sha1_to_hex(target->sha1)); + fprintf(stderr, "Fetching pack %s\n", + sha1_to_hex(target->hash)); fprintf(stderr, " which contains %s\n", oid_to_hex(&request->obj->oid)); preq = new_http_pack_request(target, repo->url); diff --git a/http-walker.c b/http-walker.c index 8ae5d76c6a..8063896cf6 100644 --- a/http-walker.c +++ b/http-walker.c @@ -434,7 +434,7 @@ static int http_fetch_pack(struct walker *walker, struct alt_base *repo, unsigne if (walker->get_verbosely) { fprintf(stderr, "Getting pack %s\n", - sha1_to_hex(target->sha1)); + sha1_to_hex(target->hash)); fprintf(stderr, " which contains %s\n", sha1_to_hex(sha1)); } diff --git a/http.c b/http.c index a32ad36ddf..a09adc518f 100644 --- a/http.c +++ b/http.c @@ -2236,10 +2236,10 @@ int finish_http_pack_request(struct http_pack_request *preq) return -1; } - unlink(sha1_pack_index_name(p->sha1)); + unlink(sha1_pack_index_name(p->hash)); - if (finalize_object_file(preq->tmpfile.buf, sha1_pack_name(p->sha1)) - || finalize_object_file(tmp_idx, sha1_pack_index_name(p->sha1))) { + if (finalize_object_file(preq->tmpfile.buf, sha1_pack_name(p->hash)) + || finalize_object_file(tmp_idx, sha1_pack_index_name(p->hash))) { free(tmp_idx); return -1; } @@ -2262,10 +2262,10 @@ struct http_pack_request *new_http_pack_request( end_url_with_slash(&buf, base_url); strbuf_addf(&buf, "objects/pack/pack-%s.pack", - sha1_to_hex(target->sha1)); + sha1_to_hex(target->hash)); preq->url = strbuf_detach(&buf, NULL); - strbuf_addf(&preq->tmpfile, "%s.temp", sha1_pack_name(target->sha1)); + strbuf_addf(&preq->tmpfile, "%s.temp", sha1_pack_name(target->hash)); preq->packfile = fopen(preq->tmpfile.buf, "a"); if (!preq->packfile) { error("Unable to open local file %s for pack", @@ -2289,7 +2289,8 @@ struct http_pack_request *new_http_pack_request( if (http_is_verbose) fprintf(stderr, "Resuming fetch of pack %s at byte %"PRIuMAX"\n", - sha1_to_hex(target->sha1), (uintmax_t)prev_posn); + sha1_to_hex(target->hash), + (uintmax_t)prev_posn); http_opt_request_remainder(preq->slot->curl, prev_posn); } diff --git a/object-store.h b/object-store.h index 14fc935bd1..56f8aea1cc 100644 --- a/object-store.h +++ b/object-store.h @@ -77,7 +77,7 @@ struct packed_git { freshened:1, do_not_close:1, pack_promisor:1; - unsigned char sha1[20]; + unsigned char hash[GIT_MAX_RAWSZ]; struct revindex_entry *revindex; /* something like ".git/objects/pack/xxxxx.pack" */ char pack_name[FLEX_ARRAY]; /* more */ diff --git a/packfile.c b/packfile.c index 16bcb75262..e6e8861650 100644 --- a/packfile.c +++ b/packfile.c @@ -235,7 +235,7 @@ struct packed_git *parse_pack_index(unsigned char *sha1, const char *idx_path) struct packed_git *p = alloc_packed_git(alloc); memcpy(p->pack_name, path, alloc); /* includes NUL */ - hashcpy(p->sha1, sha1); + hashcpy(p->hash, sha1); if (check_packed_git_idx(idx_path, p)) { free(p); return NULL; @@ -722,8 +722,8 @@ struct packed_git *add_packed_git(const char *path, size_t path_len, int local) p->pack_local = local; p->mtime = st.st_mtime; if (path_len < the_hash_algo->hexsz || - get_sha1_hex(path + path_len - the_hash_algo->hexsz, p->sha1)) - hashclr(p->sha1); + get_sha1_hex(path + path_len - the_hash_algo->hexsz, p->hash)) + hashclr(p->hash); return p; } From patchwork Tue Feb 12 01:22:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "brian m. carlson" X-Patchwork-Id: 10807131 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6AB4A1575 for ; Tue, 12 Feb 2019 01:23:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5B8AE2AC25 for ; Tue, 12 Feb 2019 01:23:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4FA472AC31; Tue, 12 Feb 2019 01:23:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ED6C32AC25 for ; Tue, 12 Feb 2019 01:23:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727122AbfBLBX2 (ORCPT ); Mon, 11 Feb 2019 20:23:28 -0500 Received: from injection.crustytoothpaste.net ([192.241.140.119]:34260 "EHLO injection.crustytoothpaste.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727091AbfBLBX0 (ORCPT ); Mon, 11 Feb 2019 20:23:26 -0500 Received: from genre.crustytoothpaste.net (unknown [IPv6:2001:470:b978:101:3dc7:72ec:75fa:fee5]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by injection.crustytoothpaste.net (Postfix) with ESMTPSA id 0567F60899; Tue, 12 Feb 2019 01:23:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=crustytoothpaste.net; s=default; t=1549934605; bh=AKJws+q6ssiLC0vGt7JoLJPhSwxoO7sqP72foWMRhw4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Reply-To: Subject:Date:To:CC:Resent-Date:Resent-From:Resent-To:Resent-Cc: In-Reply-To:References:Content-Type:Content-Disposition; b=DbgXtOXlECdM+8Jb7hC+xMbOIf4QZNygCDsZBYGa5L9Cvh83nVWa+Dd7I69e+FSVM IAE5TgKQSRTF3AU2arAm1xGJuAoZVX4/m2XXv1WH4fvxSsbIdXtGFJRLSgYq2Yc+qT b3W5xxI3+KCk+y7OuoetT+EHMeH6S8S+uYxMrccNUiIsj9fRehJZerw8Gr7Wdy2NBu uIF9TGCEPUfjg3dcU/JAWxDy2Tt5puQeQSl8HaZ0TrFpAS2wQ/YJSkNB3+glpNIWa7 /rTqxjqoIrM8v+8oD8I7qKWoKAE7rSVzz7mmhYahnJdmlf+itf4BWqsfe1fjzDD7Ud wcq2I7vl7iHtN+qAGkONYjlWwkkZgrNP5P2NKTOa1SCTtNp10UdyVz3lsNuCiwdINL tmXzbF6TidxeFTZ2rcGMfeup2fwRaP6zLq+M4lyAtlckapauphw+2BuDJdULy8M1Pa amFHE+8LBFXRBQhSBZ4V+2c3w/C3benDbbzIWAERW26H9T2YQb5 From: "brian m. carlson" To: Cc: =?utf-8?q?Ren=C3=A9_Scharfe?= , Duy Nguyen Subject: [PATCH 11/31] builtin/name-rev: make hash-size independent Date: Tue, 12 Feb 2019 01:22:36 +0000 Message-Id: <20190212012256.1005924-12-sandals@crustytoothpaste.net> X-Mailer: git-send-email 2.20.1.791.gb4d0f1c61a In-Reply-To: <20190212012256.1005924-1-sandals@crustytoothpaste.net> References: <20190212012256.1005924-1-sandals@crustytoothpaste.net> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 127.0.1.1 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Use the_hash_algo when parsing instead of GIT_SHA1_HEXSZ so that this function works with any size hash. Rename the variable forty to counter, as this is a better name and is independent of the hash size. Signed-off-by: brian m. carlson --- builtin/name-rev.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/builtin/name-rev.c b/builtin/name-rev.c index f1cb45c227..05ccf53e00 100644 --- a/builtin/name-rev.c +++ b/builtin/name-rev.c @@ -361,23 +361,25 @@ static char const * const name_rev_usage[] = { static void name_rev_line(char *p, struct name_ref_data *data) { struct strbuf buf = STRBUF_INIT; - int forty = 0; + int counter = 0; char *p_start; + const unsigned hexsz = the_hash_algo->hexsz; + for (p_start = p; *p; p++) { #define ishex(x) (isdigit((x)) || ((x) >= 'a' && (x) <= 'f')) if (!ishex(*p)) - forty = 0; - else if (++forty == GIT_SHA1_HEXSZ && + counter = 0; + else if (++counter == hexsz && !ishex(*(p+1))) { struct object_id oid; const char *name = NULL; char c = *(p+1); int p_len = p - p_start + 1; - forty = 0; + counter = 0; *(p+1) = 0; - if (!get_oid(p - (GIT_SHA1_HEXSZ - 1), &oid)) { + if (!get_oid(p - (hexsz - 1), &oid)) { struct object *o = lookup_object(the_repository, oid.hash); @@ -390,7 +392,7 @@ static void name_rev_line(char *p, struct name_ref_data *data) continue; if (data->name_only) - printf("%.*s%s", p_len - GIT_SHA1_HEXSZ, p_start, name); + printf("%.*s%s", p_len - hexsz, p_start, name); else printf("%.*s (%s)", p_len, p_start, name); p_start = p + 1; From patchwork Tue Feb 12 01:22:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "brian m. carlson" X-Patchwork-Id: 10807145 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E6DED1575 for ; Tue, 12 Feb 2019 01:23:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D758B2AC25 for ; Tue, 12 Feb 2019 01:23:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CBED22AC31; Tue, 12 Feb 2019 01:23:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5B3682AC25 for ; Tue, 12 Feb 2019 01:23:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727211AbfBLBXh (ORCPT ); Mon, 11 Feb 2019 20:23:37 -0500 Received: from injection.crustytoothpaste.net ([192.241.140.119]:34286 "EHLO injection.crustytoothpaste.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727117AbfBLBX3 (ORCPT ); Mon, 11 Feb 2019 20:23:29 -0500 Received: from genre.crustytoothpaste.net (unknown [IPv6:2001:470:b978:101:3dc7:72ec:75fa:fee5]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by injection.crustytoothpaste.net (Postfix) with ESMTPSA id 3D50860E56; Tue, 12 Feb 2019 01:23:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=crustytoothpaste.net; s=default; t=1549934606; bh=W+BwfM3vhYynj0RTz/3+OCP3aiC/NWJ/DDb0jzsbWEQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Reply-To: Subject:Date:To:CC:Resent-Date:Resent-From:Resent-To:Resent-Cc: In-Reply-To:References:Content-Type:Content-Disposition; b=kIxu4Hlx0dvYYoE99vokiGkVYtcADlxX+r8QKI0jSPTuT1ivNPidWylmFLbJ6vFYu R3fI44TEUi/aHKR7mr58ZREdDV9HuLzn2W7MI1F+a34KaWkkupugijC+L6KQoNDQaV Lt7XtnHUMPftXOZK3DII72S2jUfEg4gJkQe5Vi2ki9N6q5KWibu2vWP9t3JCbo4vrE Bcs9XWKCcMjk/XY1Q5Wo8+Q0YU0pD0wScPCiSCI8o4yD3jhxbMCdFrCg/zNGk4r3Ii X72gpG9rS12ItoyHPnB+22CXK9VDOZ0sY9bXS/KMpN1Pc5DQ3i0xX/msrXyfvhzmJz V9HVM2MNjF3a5gn4iCbu/hOsTgUHt23Z8yBp5ClBJskiDrj8yoUpVvuNfHV7pQNxfw AgPXusJkZALE6G596a0Txyzl3BEQzSxfiYmiPU12AtUT0+RGucLpdY0C1V7pumS3Zi kgrD3kLGutsovpsuP/EVUoeMo3HRuyfoiv13mMCvuS6fBLtB2RB From: "brian m. carlson" To: Cc: =?utf-8?q?Ren=C3=A9_Scharfe?= , Duy Nguyen Subject: [PATCH 12/31] fast-import: make hash-size independent Date: Tue, 12 Feb 2019 01:22:37 +0000 Message-Id: <20190212012256.1005924-13-sandals@crustytoothpaste.net> X-Mailer: git-send-email 2.20.1.791.gb4d0f1c61a In-Reply-To: <20190212012256.1005924-1-sandals@crustytoothpaste.net> References: <20190212012256.1005924-1-sandals@crustytoothpaste.net> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 127.0.1.1 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Replace several uses of GIT_SHA1_HEXSZ and 40-based constants with references to the_hash_algo. Update the note handling code here to compute path sizes based on GIT_MAX_RAWSZ as well. Signed-off-by: brian m. carlson --- fast-import.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/fast-import.c b/fast-import.c index 7c9a10a77b..eba8c8c919 100644 --- a/fast-import.c +++ b/fast-import.c @@ -1241,7 +1241,7 @@ static void load_tree(struct tree_entry *root) c += e->name->str_len + 1; hashcpy(e->versions[0].oid.hash, (unsigned char *)c); hashcpy(e->versions[1].oid.hash, (unsigned char *)c); - c += GIT_SHA1_RAWSZ; + c += the_hash_algo->rawsz; } free(buf); } @@ -1288,7 +1288,7 @@ static void mktree(struct tree_content *t, int v, struct strbuf *b) strbuf_addf(b, "%o %s%c", (unsigned int)(e->versions[v].mode & ~NO_DELTA), e->name->str_dat, '\0'); - strbuf_add(b, e->versions[v].oid.hash, GIT_SHA1_RAWSZ); + strbuf_add(b, e->versions[v].oid.hash, the_hash_algo->rawsz); } } @@ -2047,7 +2047,8 @@ static uintmax_t do_change_note_fanout( unsigned int i, tmp_hex_oid_len, tmp_fullpath_len; uintmax_t num_notes = 0; struct object_id oid; - char realpath[60]; + char realpath[GIT_MAX_RAWSZ * 3]; + const unsigned hexsz = the_hash_algo->hexsz; if (!root->tree) load_tree(root); @@ -2067,7 +2068,7 @@ static uintmax_t do_change_note_fanout( * of 2 chars. */ if (!e->versions[1].mode || - tmp_hex_oid_len > GIT_SHA1_HEXSZ || + tmp_hex_oid_len > hexsz || e->name->str_len % 2) continue; @@ -2081,7 +2082,7 @@ static uintmax_t do_change_note_fanout( tmp_fullpath_len += e->name->str_len; fullpath[tmp_fullpath_len] = '\0'; - if (tmp_hex_oid_len == GIT_SHA1_HEXSZ && !get_oid_hex(hex_oid, &oid)) { + if (tmp_hex_oid_len == hexsz && !get_oid_hex(hex_oid, &oid)) { /* This is a note entry */ if (fanout == 0xff) { /* Counting mode, no rename */ @@ -2352,7 +2353,7 @@ static void note_change_n(const char *p, struct branch *b, unsigned char *old_fa struct object_entry *oe; struct branch *s; struct object_id oid, commit_oid; - char path[60]; + char path[GIT_MAX_RAWSZ * 3]; uint16_t inline_data = 0; unsigned char new_fanout; @@ -2405,7 +2406,7 @@ static void note_change_n(const char *p, struct branch *b, unsigned char *old_fa char *buf = read_object_with_reference(&commit_oid, commit_type, &size, &commit_oid); - if (!buf || size < 46) + if (!buf || size < the_hash_algo->hexsz) die("Not a valid commit: %s", p); free(buf); } else @@ -2456,7 +2457,7 @@ static void file_change_deleteall(struct branch *b) static void parse_from_commit(struct branch *b, char *buf, unsigned long size) { - if (!buf || size < GIT_SHA1_HEXSZ + 6) + if (!buf || size < the_hash_algo->hexsz + 6) die("Not a valid commit: %s", oid_to_hex(&b->oid)); if (memcmp("tree ", buf, 5) || get_oid_hex(buf + 5, &b->branch_tree.versions[1].oid)) @@ -2555,7 +2556,7 @@ static struct hash_list *parse_merge(unsigned int *count) char *buf = read_object_with_reference(&n->oid, commit_type, &size, &n->oid); - if (!buf || size < 46) + if (!buf || size < the_hash_algo->hexsz) die("Not a valid commit: %s", from); free(buf); } else @@ -2842,7 +2843,7 @@ static void parse_get_mark(const char *p) die("Unknown mark: %s", command_buf.buf); xsnprintf(output, sizeof(output), "%s\n", oid_to_hex(&oe->idx.oid)); - cat_blob_write(output, GIT_SHA1_HEXSZ + 1); + cat_blob_write(output, the_hash_algo->hexsz + 1); } static void parse_cat_blob(const char *p) @@ -2872,6 +2873,8 @@ static struct object_entry *dereference(struct object_entry *oe, { unsigned long size; char *buf = NULL; + const unsigned hexsz = the_hash_algo->hexsz; + if (!oe) { enum object_type type = oid_object_info(the_repository, oid, NULL); @@ -2905,12 +2908,12 @@ static struct object_entry *dereference(struct object_entry *oe, /* Peel one layer. */ switch (oe->type) { case OBJ_TAG: - if (size < GIT_SHA1_HEXSZ + strlen("object ") || + if (size < hexsz + strlen("object ") || get_oid_hex(buf + strlen("object "), oid)) die("Invalid SHA1 in tag: %s", command_buf.buf); break; case OBJ_COMMIT: - if (size < GIT_SHA1_HEXSZ + strlen("tree ") || + if (size < hexsz + strlen("tree ") || get_oid_hex(buf + strlen("tree "), oid)) die("Invalid SHA1 in commit: %s", command_buf.buf); } From patchwork Tue Feb 12 01:22:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "brian m. carlson" X-Patchwork-Id: 10807139 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0190F13A4 for ; Tue, 12 Feb 2019 01:23:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E57CB2AC25 for ; Tue, 12 Feb 2019 01:23:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D6F6A2AC31; Tue, 12 Feb 2019 01:23:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7CFE92AC25 for ; Tue, 12 Feb 2019 01:23:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727176AbfBLBXe (ORCPT ); Mon, 11 Feb 2019 20:23:34 -0500 Received: from injection.crustytoothpaste.net ([192.241.140.119]:34292 "EHLO injection.crustytoothpaste.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727123AbfBLBX3 (ORCPT ); Mon, 11 Feb 2019 20:23:29 -0500 Received: from genre.crustytoothpaste.net (unknown [IPv6:2001:470:b978:101:3dc7:72ec:75fa:fee5]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by injection.crustytoothpaste.net (Postfix) with ESMTPSA id 8E44360898; Tue, 12 Feb 2019 01:23:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=crustytoothpaste.net; s=default; t=1549934607; bh=41e+mPmFDq+zgs24fej382Kgg/rdvHZ54iDFuzriLR8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Reply-To: Subject:Date:To:CC:Resent-Date:Resent-From:Resent-To:Resent-Cc: In-Reply-To:References:Content-Type:Content-Disposition; b=KtBjUpPjF8QfTKtYn8hZ7eVRquefVC/NsoFnwB7BN9Tr64A+ChtmQKCVX2WDQd4Ne +rIoImGrWGAXPQKDm3NrwNe5jggSsbh5Pw9ZXvwsyp9sKwucsIfq67+LmsitkxOWpq Ewz/dzJ8J1Tcru+TxPLqsUuooI4mgsV8kdnz6YGzM3mTzKecXIfyLriyD79xkAq7pn T9RARuGkBmb4TkLZs5hGeQ/dYNVGOBcOy8qN2S8w1j4Db76JkquM7EUZf8cy15bDbO L9r+sYC6zoaOh8izv/ooUZOtxj6STfkAyOJRDun7L4sJ/LX4Tt+ItGISWK0JnsIbJ2 deLMFTZhwEE66+TlP4lHjhHxyx4JJZIcIYNz71iFh4OWt4kdvvH/hTJ5oasef8bRxt +UYY2/t+Z7HZ7lZ4otJhH0MfQrSZc+YlGlo/g4hzyNqOrrOGsMRv+LPPKxaqySEr6b 2DIxR+y0h40zRs2j9YJXiXfdKEXCSSQNg5iJmm/G5O51JTtSLh1 From: "brian m. carlson" To: Cc: =?utf-8?q?Ren=C3=A9_Scharfe?= , Duy Nguyen Subject: [PATCH 13/31] fast-import: replace sha1_to_hex Date: Tue, 12 Feb 2019 01:22:38 +0000 Message-Id: <20190212012256.1005924-14-sandals@crustytoothpaste.net> X-Mailer: git-send-email 2.20.1.791.gb4d0f1c61a In-Reply-To: <20190212012256.1005924-1-sandals@crustytoothpaste.net> References: <20190212012256.1005924-1-sandals@crustytoothpaste.net> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 127.0.1.1 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Replace the uses of sha1_to_hex in this function with hash_to_hex to allow the use of SHA-256 as well. Rename a variable since it is no longer limited to SHA-1. Signed-off-by: brian m. carlson --- fast-import.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fast-import.c b/fast-import.c index eba8c8c919..3d6e2bfa4d 100644 --- a/fast-import.c +++ b/fast-import.c @@ -2945,7 +2945,7 @@ static struct object_entry *parse_treeish_dataref(const char **p) return e; } -static void print_ls(int mode, const unsigned char *sha1, const char *path) +static void print_ls(int mode, const unsigned char *hash, const char *path) { static struct strbuf line = STRBUF_INIT; @@ -2965,7 +2965,7 @@ static void print_ls(int mode, const unsigned char *sha1, const char *path) /* mode SP type SP object_name TAB path LF */ strbuf_reset(&line); strbuf_addf(&line, "%06o %s %s\t", - mode & ~NO_DELTA, type, sha1_to_hex(sha1)); + mode & ~NO_DELTA, type, hash_to_hex(hash)); quote_c_style(path, &line, NULL, 0); strbuf_addch(&line, '\n'); } From patchwork Tue Feb 12 01:22:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "brian m. carlson" X-Patchwork-Id: 10807135 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 608FE1575 for ; Tue, 12 Feb 2019 01:23:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 51CA92AC25 for ; Tue, 12 Feb 2019 01:23:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 45EE92AC31; Tue, 12 Feb 2019 01:23:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E71C02AC25 for ; Tue, 12 Feb 2019 01:23:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727152AbfBLBXb (ORCPT ); Mon, 11 Feb 2019 20:23:31 -0500 Received: from injection.crustytoothpaste.net ([192.241.140.119]:34300 "EHLO injection.crustytoothpaste.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727091AbfBLBXa (ORCPT ); Mon, 11 Feb 2019 20:23:30 -0500 Received: from genre.crustytoothpaste.net (unknown [IPv6:2001:470:b978:101:3dc7:72ec:75fa:fee5]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by injection.crustytoothpaste.net (Postfix) with ESMTPSA id 3323660899; Tue, 12 Feb 2019 01:23:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=crustytoothpaste.net; s=default; t=1549934608; bh=ZgJiDZe71IdN0eGb4vsIIvfqbAhK+NM/W4cs2L7qU7Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Reply-To: Subject:Date:To:CC:Resent-Date:Resent-From:Resent-To:Resent-Cc: In-Reply-To:References:Content-Type:Content-Disposition; b=RyY0LgQ+AotDIbWIP7G9X5AaAskwIcKYl2sS7qwn+1hvg0avBKL+2/+hx+jHhdCnQ 4M2x3VirzEGU3DbCXj1Lz0xhd9ihFcmdMX8V+HtGtdWIHEM+kYt5zv9Y6BIgOfUqzD GOI9mxj7M4whCLwkHX426XsS9wgaUcB5IZi+S293/hxO6DPK3bExMFBipmByXLOQi2 TagbuIYzGseZi8hY52BAQc1a3IOe46blu4vTOqym/vBIwcLMaxfK5jC2giRCTr/6xi sedkK8QAMCGrDJ6jQj7GMblaTj0RLS1Xd4j+roS77lnZLeDbAN4RdgOJgnDMSyaZif uxF4C2Gcfsm4gtuyl1Qo5P9nrHjIrxML3pbk0ouxw2XuPgGGDErO8EHoS4vfe7OnEl M5Lv2UwgSWdMh0CbdJnGGNM3K+MjlyLOvlcS29J9BtXbpbmk3FQcO/9ymgXI3C5hJe 6FpYPEbOaWR2dY3drVugg8QxKHbYl21qV6VztNXCiafAESEUcfV From: "brian m. carlson" To: Cc: =?utf-8?q?Ren=C3=A9_Scharfe?= , Duy Nguyen Subject: [PATCH 14/31] builtin/am: make hash size independent Date: Tue, 12 Feb 2019 01:22:39 +0000 Message-Id: <20190212012256.1005924-15-sandals@crustytoothpaste.net> X-Mailer: git-send-email 2.20.1.791.gb4d0f1c61a In-Reply-To: <20190212012256.1005924-1-sandals@crustytoothpaste.net> References: <20190212012256.1005924-1-sandals@crustytoothpaste.net> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 127.0.1.1 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Instead of using GIT_SHA1_HEXSZ, switch to using the_hash_algo and parse_oid_hex to parse the lines involved in rebasing notes. Signed-off-by: brian m. carlson --- builtin/am.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/builtin/am.c b/builtin/am.c index 58a2aef28b..584baf1c7e 100644 --- a/builtin/am.c +++ b/builtin/am.c @@ -485,23 +485,24 @@ static int copy_notes_for_rebase(const struct am_state *state) while (!strbuf_getline_lf(&sb, fp)) { struct object_id from_obj, to_obj; + const char *p; - if (sb.len != GIT_SHA1_HEXSZ * 2 + 1) { + if (sb.len != the_hash_algo->hexsz * 2 + 1) { ret = error(invalid_line, sb.buf); goto finish; } - if (get_oid_hex(sb.buf, &from_obj)) { + if (parse_oid_hex(sb.buf, &from_obj, &p)) { ret = error(invalid_line, sb.buf); goto finish; } - if (sb.buf[GIT_SHA1_HEXSZ] != ' ') { + if (*p != ' ') { ret = error(invalid_line, sb.buf); goto finish; } - if (get_oid_hex(sb.buf + GIT_SHA1_HEXSZ + 1, &to_obj)) { + if (get_oid_hex(p + 1, &to_obj)) { ret = error(invalid_line, sb.buf); goto finish; } From patchwork Tue Feb 12 01:22:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "brian m. carlson" X-Patchwork-Id: 10807137 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 172D71575 for ; Tue, 12 Feb 2019 01:23:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 080F12AC25 for ; Tue, 12 Feb 2019 01:23:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F095F2AC31; Tue, 12 Feb 2019 01:23:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A66FA2AC25 for ; Tue, 12 Feb 2019 01:23:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727172AbfBLBXc (ORCPT ); Mon, 11 Feb 2019 20:23:32 -0500 Received: from injection.crustytoothpaste.net ([192.241.140.119]:34304 "EHLO injection.crustytoothpaste.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727137AbfBLBXb (ORCPT ); Mon, 11 Feb 2019 20:23:31 -0500 Received: from genre.crustytoothpaste.net (unknown [IPv6:2001:470:b978:101:3dc7:72ec:75fa:fee5]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by injection.crustytoothpaste.net (Postfix) with ESMTPSA id 4FE3C60E54; Tue, 12 Feb 2019 01:23:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=crustytoothpaste.net; s=default; t=1549934609; bh=6/MpCrAvByESSVRztzgd2v91iFyfOXnmCzNrwVKOTDE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Reply-To: Subject:Date:To:CC:Resent-Date:Resent-From:Resent-To:Resent-Cc: In-Reply-To:References:Content-Type:Content-Disposition; b=prEqiEAPb03q9XNrv+c4zB4tM3ib4HwdUh/dxA37/hxfACAMIbJYLxXGSs9WPrRi4 bxRC9K4QoWceyLn3n9VIWSoNDyqWwVfWphj1ooTtiuKjzXCi/Neaa6K2+/n1JXjprt 5hPb8avjmxQCy6wXI9ZHfs/Gpr2cl3H58KHDDgrX/RiufEa+SC28Euo6yjOHSgFrQH u462nLys1O5y7qjths+xtuV3ISTgTfeTCrJ6ySRS2p73CCGuGdrPRQYcrvdAU/A9vI OiG6KhjikuaKKpsgoJIz13AN4WwzNXFe4Q3t94xt2PUDNYANoWkUjUG5v5EF3SU5t2 rn5+SIcbikdr+StC2epeQfkJUecqBoKQDwR9y4GryLIDl6F7szVvPD0ZxSLSlivyw8 99r/KAgYr2oi8Xc4lw6lFvQIkaNiV+6qS3ZtLkhMQ2y0Hjn/foqqwm3T6KE3mcKCHc wJCQYuNwEOuaZ7ivsJNn+4vowWeGyjkTOOK37sCrRVFZZ25McO2 From: "brian m. carlson" To: Cc: =?utf-8?q?Ren=C3=A9_Scharfe?= , Duy Nguyen Subject: [PATCH 15/31] builtin/pull: make hash-size independent Date: Tue, 12 Feb 2019 01:22:40 +0000 Message-Id: <20190212012256.1005924-16-sandals@crustytoothpaste.net> X-Mailer: git-send-email 2.20.1.791.gb4d0f1c61a In-Reply-To: <20190212012256.1005924-1-sandals@crustytoothpaste.net> References: <20190212012256.1005924-1-sandals@crustytoothpaste.net> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 127.0.1.1 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Instead of using get_oid_hex and GIT_SHA1_HEXSZ, use parse_oid_hex to avoid the need for a constant and simplify the code. Signed-off-by: brian m. carlson --- builtin/pull.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/builtin/pull.c b/builtin/pull.c index 701d1473dc..52d93c1e3b 100644 --- a/builtin/pull.c +++ b/builtin/pull.c @@ -365,9 +365,10 @@ static void get_merge_heads(struct oid_array *merge_heads) fp = xfopen(filename, "r"); while (strbuf_getline_lf(&sb, fp) != EOF) { - if (get_oid_hex(sb.buf, &oid)) + const char *p; + if (parse_oid_hex(sb.buf, &oid, &p)) continue; /* invalid line: does not start with SHA1 */ - if (starts_with(sb.buf + GIT_SHA1_HEXSZ, "\tnot-for-merge\t")) + if (starts_with(p, "\tnot-for-merge\t")) continue; /* ref is not-for-merge */ oid_array_append(merge_heads, &oid); } From patchwork Tue Feb 12 01:22:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "brian m. carlson" X-Patchwork-Id: 10807143 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D82461575 for ; Tue, 12 Feb 2019 01:23:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C955D2AC25 for ; Tue, 12 Feb 2019 01:23:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BE0942AC31; Tue, 12 Feb 2019 01:23:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5E5722AC25 for ; Tue, 12 Feb 2019 01:23:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727208AbfBLBXg (ORCPT ); Mon, 11 Feb 2019 20:23:36 -0500 Received: from injection.crustytoothpaste.net ([192.241.140.119]:34310 "EHLO injection.crustytoothpaste.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726140AbfBLBXd (ORCPT ); Mon, 11 Feb 2019 20:23:33 -0500 Received: from genre.crustytoothpaste.net (unknown [IPv6:2001:470:b978:101:3dc7:72ec:75fa:fee5]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by injection.crustytoothpaste.net (Postfix) with ESMTPSA id 86C4160E53; Tue, 12 Feb 2019 01:23:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=crustytoothpaste.net; s=default; t=1549934610; bh=ew3v3skWNpv8fDanCbUgTUbaHGFtLSUN80DuTfv7fUw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Reply-To: Subject:Date:To:CC:Resent-Date:Resent-From:Resent-To:Resent-Cc: In-Reply-To:References:Content-Type:Content-Disposition; b=cv6ZH9U/QkBDoDwLdhENyH7lHNbJ2YRdm3pfl3rXlSo/5H4/UlLXhHhaSO+zraH4Y rheYLJRVnOOUD6mc1hGnTF+6WoSYdpZFAcbzYyOH5VIiMQci6GwNQME8+9+GxvtqbW IBveCXT+BwiCVoKlYVVVzUbR5w7HhJHtI8sXXmjjxjESWvFh16xXXqxsytV60j++AT zrwq3mtWvQs1SOuSltYoU0VN5ZpkTGT5kLXw3/l68yBgpbMqJ0S83JVB3gt1kkILNB TWbc+WYsOnJ9ZlbclbNp5ehmHifbsXmU7INZFwBNZTJuiWXGrHHGaR2m04u53hq8uQ +sAG0zSmFGYNprcMo59PwMukQMw+H302vpjQlLgJTyLFc2o3sJgfcDGspQQXObUma8 SiPfXZYoMF8CCapqcS4nQ6uZpP4UjbULxZ8MCZ7p/OxNDZrwqESd0wifsKhwgppSCE 6usbgj74OBIostk3daF1Vb3N+SQo0klcwCLvqVVemHv/jQ7ng1A From: "brian m. carlson" To: Cc: =?utf-8?q?Ren=C3=A9_Scharfe?= , Duy Nguyen Subject: [PATCH 16/31] http-push: convert to use the_hash_algo Date: Tue, 12 Feb 2019 01:22:41 +0000 Message-Id: <20190212012256.1005924-17-sandals@crustytoothpaste.net> X-Mailer: git-send-email 2.20.1.791.gb4d0f1c61a In-Reply-To: <20190212012256.1005924-1-sandals@crustytoothpaste.net> References: <20190212012256.1005924-1-sandals@crustytoothpaste.net> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 127.0.1.1 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Switch the lock token code to use the_hash_algo and increase its buffers to be allocated using GIT_MAX_* constants. Update the parsing of object paths to use the_hash_algo as well. Signed-off-by: brian m. carlson --- http-push.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/http-push.c b/http-push.c index b313ada515..c4e5142bc9 100644 --- a/http-push.c +++ b/http-push.c @@ -145,7 +145,7 @@ struct remote_lock { char *url; char *owner; char *token; - char tmpfile_suffix[41]; + char tmpfile_suffix[GIT_MAX_HEXSZ + 1]; time_t start_time; long timeout; int refreshing; @@ -399,7 +399,7 @@ static void start_put(struct transfer_request *request) request->dest = strbuf_detach(&buf, NULL); append_remote_object_url(&buf, repo->url, hex, 0); - strbuf_add(&buf, request->lock->tmpfile_suffix, 41); + strbuf_add(&buf, request->lock->tmpfile_suffix, the_hash_algo->hexsz + 1); request->url = strbuf_detach(&buf, NULL); slot = get_active_slot(); @@ -758,8 +758,8 @@ static void handle_lockprop_ctx(struct xml_ctx *ctx, int tag_closed) static void handle_new_lock_ctx(struct xml_ctx *ctx, int tag_closed) { struct remote_lock *lock = (struct remote_lock *)ctx->userData; - git_SHA_CTX sha_ctx; - unsigned char lock_token_sha1[20]; + git_hash_ctx hash_ctx; + unsigned char lock_token_hash[GIT_MAX_RAWSZ]; if (tag_closed && ctx->cdata) { if (!strcmp(ctx->name, DAV_ACTIVELOCK_OWNER)) { @@ -771,12 +771,12 @@ static void handle_new_lock_ctx(struct xml_ctx *ctx, int tag_closed) } else if (!strcmp(ctx->name, DAV_ACTIVELOCK_TOKEN)) { lock->token = xstrdup(ctx->cdata); - git_SHA1_Init(&sha_ctx); - git_SHA1_Update(&sha_ctx, lock->token, strlen(lock->token)); - git_SHA1_Final(lock_token_sha1, &sha_ctx); + the_hash_algo->init_fn(&hash_ctx); + the_hash_algo->update_fn(&hash_ctx, lock->token, strlen(lock->token)); + the_hash_algo->final_fn(lock_token_hash, &hash_ctx); lock->tmpfile_suffix[0] = '_'; - memcpy(lock->tmpfile_suffix + 1, sha1_to_hex(lock_token_sha1), 40); + memcpy(lock->tmpfile_suffix + 1, hash_to_hex(lock_token_hash), the_hash_algo->hexsz); } } } @@ -1018,7 +1018,7 @@ static void remote_ls(const char *path, int flags, /* extract hex from sharded "xx/x{38}" filename */ static int get_oid_hex_from_objpath(const char *path, struct object_id *oid) { - if (strlen(path) != GIT_SHA1_HEXSZ + 1) + if (strlen(path) != the_hash_algo->hexsz + 1) return -1; if (hex_to_bytes(oid->hash, path, 1)) @@ -1026,7 +1026,7 @@ static int get_oid_hex_from_objpath(const char *path, struct object_id *oid) path += 2; path++; /* skip '/' */ - return hex_to_bytes(oid->hash + 1, path, GIT_SHA1_RAWSZ - 1); + return hex_to_bytes(oid->hash + 1, path, the_hash_algo->rawsz - 1); } static void process_ls_object(struct remote_ls_ctx *ls) From patchwork Tue Feb 12 01:22:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "brian m. carlson" X-Patchwork-Id: 10807141 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1063513A4 for ; Tue, 12 Feb 2019 01:23:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 01B2B2AC25 for ; Tue, 12 Feb 2019 01:23:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EA14E2AC31; Tue, 12 Feb 2019 01:23:36 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9EC582AC25 for ; Tue, 12 Feb 2019 01:23:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727188AbfBLBXe (ORCPT ); Mon, 11 Feb 2019 20:23:34 -0500 Received: from injection.crustytoothpaste.net ([192.241.140.119]:34316 "EHLO injection.crustytoothpaste.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727168AbfBLBXd (ORCPT ); Mon, 11 Feb 2019 20:23:33 -0500 Received: from genre.crustytoothpaste.net (unknown [IPv6:2001:470:b978:101:3dc7:72ec:75fa:fee5]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by injection.crustytoothpaste.net (Postfix) with ESMTPSA id 0CFBD60E54; Tue, 12 Feb 2019 01:23:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=crustytoothpaste.net; s=default; t=1549934612; bh=+5fh+FR9PRQDRolK2uH6wkevzO/rfiLlvMVrulPvglI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Reply-To: Subject:Date:To:CC:Resent-Date:Resent-From:Resent-To:Resent-Cc: In-Reply-To:References:Content-Type:Content-Disposition; b=SE8yK/ISp0FxOKocWl30aadQDr6to/YQemn0VwtFwkvbTF0VGq8TNxX4qUvcEK9Ql DKqMojUCGGsYyAxV5ixysKacutxwIde7bNCFJJk6RKq18rPrPlfiVsXNcJO7qTxCGH /J+Rx+w987HOZonP/Kv+Oa+4fgSJ9ovtPoHvlA+zlUTPDRv+X31LCwdQDd4VV4KIzt Bwv4KOV92Yu2fhNML4FcrsWSwHHgutT74kSGQGREbKH0ZlsZQWDamcP+7zZfE/WZOK 9cAEy8ckeFn1+0uhkZvFtz2lF0Ne8Gnj24U22VnHXlDq8ifYaeeXDu2fBnohhF+X+t sui6u/3wEB77iy8AWJXApKbtcOxqzIjGCdyXB4UzNmt3yDIqxZhAZLxY/FvpVziKyi edn6J6z2pHsYvzcQrnGy0LI5XIrFp+rdYo6RFdf6uJ62QsKxvDYRiA1u+v3VUPv45c k3BFd4jFMw2SKBnmVz1zLdoRpI2p/h8oRDGC1tbiZSL0kcJddkk From: "brian m. carlson" To: Cc: =?utf-8?q?Ren=C3=A9_Scharfe?= , Duy Nguyen Subject: [PATCH 17/31] http-backend: allow 64-character hex names Date: Tue, 12 Feb 2019 01:22:42 +0000 Message-Id: <20190212012256.1005924-18-sandals@crustytoothpaste.net> X-Mailer: git-send-email 2.20.1.791.gb4d0f1c61a In-Reply-To: <20190212012256.1005924-1-sandals@crustytoothpaste.net> References: <20190212012256.1005924-1-sandals@crustytoothpaste.net> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 127.0.1.1 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP In an SHA-256-backed repository using the http-backend handler for dumb protocol clients, it may be necessary to access the raw packs using their full SHA-256-specified names. Allow packs and loose objects to be accessed using their full SHA-256-specified 64-character hex names. Signed-off-by: brian m. carlson --- http-backend.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/http-backend.c b/http-backend.c index 29e68e38b5..ec3144b444 100644 --- a/http-backend.c +++ b/http-backend.c @@ -711,8 +711,11 @@ static struct service_cmd { {"GET", "/objects/info/http-alternates$", get_text_file}, {"GET", "/objects/info/packs$", get_info_packs}, {"GET", "/objects/[0-9a-f]{2}/[0-9a-f]{38}$", get_loose_object}, + {"GET", "/objects/[0-9a-f]{2}/[0-9a-f]{62}$", get_loose_object}, {"GET", "/objects/pack/pack-[0-9a-f]{40}\\.pack$", get_pack_file}, + {"GET", "/objects/pack/pack-[0-9a-f]{64}\\.pack$", get_pack_file}, {"GET", "/objects/pack/pack-[0-9a-f]{40}\\.idx$", get_idx_file}, + {"GET", "/objects/pack/pack-[0-9a-f]{64}\\.idx$", get_idx_file}, {"POST", "/git-upload-pack$", service_rpc}, {"POST", "/git-receive-pack$", service_rpc} From patchwork Tue Feb 12 01:22:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "brian m. carlson" X-Patchwork-Id: 10807147 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9073213A4 for ; Tue, 12 Feb 2019 01:23:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 80E992AC25 for ; Tue, 12 Feb 2019 01:23:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 75AD82AC31; Tue, 12 Feb 2019 01:23:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 222102AC25 for ; Tue, 12 Feb 2019 01:23:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727215AbfBLBXh (ORCPT ); Mon, 11 Feb 2019 20:23:37 -0500 Received: from injection.crustytoothpaste.net ([192.241.140.119]:34322 "EHLO injection.crustytoothpaste.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727137AbfBLBXf (ORCPT ); Mon, 11 Feb 2019 20:23:35 -0500 Received: from genre.crustytoothpaste.net (unknown [IPv6:2001:470:b978:101:3dc7:72ec:75fa:fee5]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by injection.crustytoothpaste.net (Postfix) with ESMTPSA id A74AC60899; Tue, 12 Feb 2019 01:23:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=crustytoothpaste.net; s=default; t=1549934613; bh=u4Oz/WO5+HhIy4BmxYdkaenf1TjVyDZL9RnBd377Dvw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Reply-To: Subject:Date:To:CC:Resent-Date:Resent-From:Resent-To:Resent-Cc: In-Reply-To:References:Content-Type:Content-Disposition; b=Pcng5MEFTaZ7rcXILUoxAW2ONMNVeN6GqWEayfdpTdFJD/A1+FPe+sEiEBpa7ezGh 53eE6yBZTgL77rpBtJD1oTE+fA/5TSvZ6nodFegIaSmu9O7gtkxXEEqYqGEY+fp1IB lslPjqm16ttUGtlIf+muQLgCp1uE5BWSKtg0rENIfUOt3sLpRTToha1ji/OVzCjYFE ia2sryZR7ktnA4EfHoR/kWulZe8sphoKhn5qj0xRVu+dMyTzoFGzGohG36/d/vX/nj saim8U/In7rY/YshF9Ig7viwvVXGDAx4QLLYz1c1GtP7BTcdejRfUt1DQgI2BvczOz r/Sq1nvto3jWpZa0/TPzxmdCROaSWC7gqwEzBCCzSJ6Q4GgKrClDkTYSa72uTiuNGC E9TdLfdIUs6kNUXXZLWrkC2BL1Hv5dMe1PZacTQGy41hMKOpI9Rm6+xC/9Ay98trDQ D4QQ85L+yEuAi27vSJ4qZ9jLKIhmdFtOalvgSbsX7vi2SeMlOr0 From: "brian m. carlson" To: Cc: =?utf-8?q?Ren=C3=A9_Scharfe?= , Duy Nguyen Subject: [PATCH 18/31] http-push: remove remaining uses of sha1_to_hex Date: Tue, 12 Feb 2019 01:22:43 +0000 Message-Id: <20190212012256.1005924-19-sandals@crustytoothpaste.net> X-Mailer: git-send-email 2.20.1.791.gb4d0f1c61a In-Reply-To: <20190212012256.1005924-1-sandals@crustytoothpaste.net> References: <20190212012256.1005924-1-sandals@crustytoothpaste.net> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 127.0.1.1 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Since sha1_to_hex is limited to SHA-1, switch all remaining uses of it in this file to hash_to_hex or oid_to_hex. Modify update_remote to take a pointer to struct object_id, and since we don't modify that parameter in the function, set it to be const as well. Signed-off-by: brian m. carlson --- http-push.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/http-push.c b/http-push.c index c4e5142bc9..f675a96316 100644 --- a/http-push.c +++ b/http-push.c @@ -316,7 +316,7 @@ static void start_fetch_packed(struct transfer_request *request) } fprintf(stderr, "Fetching pack %s\n", - sha1_to_hex(target->hash)); + hash_to_hex(target->hash)); fprintf(stderr, " which contains %s\n", oid_to_hex(&request->obj->oid)); preq = new_http_pack_request(target, repo->url); @@ -1374,7 +1374,7 @@ static int get_delta(struct rev_info *revs, struct remote_lock *lock) return count; } -static int update_remote(unsigned char *sha1, struct remote_lock *lock) +static int update_remote(const struct object_id *oid, struct remote_lock *lock) { struct active_request_slot *slot; struct slot_results results; @@ -1383,7 +1383,7 @@ static int update_remote(unsigned char *sha1, struct remote_lock *lock) dav_headers = get_dav_token_headers(lock, DAV_HEADER_IF); - strbuf_addf(&out_buffer.buf, "%s\n", sha1_to_hex(sha1)); + strbuf_addf(&out_buffer.buf, "%s\n", oid_to_hex(oid)); slot = get_active_slot(); slot->results = &results; @@ -1948,7 +1948,7 @@ int cmd_main(int argc, const char **argv) run_request_queue(); /* Update the remote branch if all went well */ - if (aborted || !update_remote(ref->new_oid.hash, ref_lock)) + if (aborted || !update_remote(&ref->new_oid, ref_lock)) rc = 1; if (!rc) From patchwork Tue Feb 12 01:22:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "brian m. carlson" X-Patchwork-Id: 10807157 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B13C613A4 for ; Tue, 12 Feb 2019 01:23:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A1E692AC25 for ; Tue, 12 Feb 2019 01:23:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 967172AC31; Tue, 12 Feb 2019 01:23:48 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3B80E2AC25 for ; Tue, 12 Feb 2019 01:23:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727273AbfBLBXp (ORCPT ); Mon, 11 Feb 2019 20:23:45 -0500 Received: from injection.crustytoothpaste.net ([192.241.140.119]:34330 "EHLO injection.crustytoothpaste.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727200AbfBLBXf (ORCPT ); Mon, 11 Feb 2019 20:23:35 -0500 Received: from genre.crustytoothpaste.net (unknown [IPv6:2001:470:b978:101:3dc7:72ec:75fa:fee5]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by injection.crustytoothpaste.net (Postfix) with ESMTPSA id CED6B60E58; Tue, 12 Feb 2019 01:23:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=crustytoothpaste.net; s=default; t=1549934614; bh=bmlpTh1QMtR816yG8bEjpctnZspsdFW0f7T20uzxib0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Reply-To: Subject:Date:To:CC:Resent-Date:Resent-From:Resent-To:Resent-Cc: In-Reply-To:References:Content-Type:Content-Disposition; b=mpgHnfXpp9SywvBb3HbxnjX+40AX1bnuu3tX4CX5DkG1NPUXnwrssJ8VOBx1YXN8c WV2L0i1dA+6aPhi1tXY2F0qbKedG8KZ+pFeqy6OPqOY3kjknF0dgGDFp8RSHsFsjhR 7x9zIHFIlx5VTb/aslsJEuw6jOrSAD/lPMoV1jb7S7P+5AWcuxx6Qjew6CngGoJlEB dTcmWntarLL9CtAI29ZtG1MqLErt8RFrb+S5aPuBsfzyAm53e/K7yF1Cw7qBzoWZra GPqSc60S6NjYOgQQ3gRWy2JXC6QcNnqvuuxM4mXD2TSQ3RxNC97Ld5cR8JNFqLZ04J j+8E/XWFBjzEnk45c3hftJuKGI+rlRqsiCNzACXhXLK5i3C5d3EzhQjUe6Il+/uqyB GkiACgJqx0QFf87lkNghAKalWSkqIbuJBa6SpmsOMiAuOmQKlrEJju7Dq6qZBjDsAw D5LEccaGe/RHnHRwlBaz0kPVtCp85kRdvaXy47No9mTV0zh53f0 From: "brian m. carlson" To: Cc: =?utf-8?q?Ren=C3=A9_Scharfe?= , Duy Nguyen Subject: [PATCH 19/31] http-walker: replace sha1_to_hex Date: Tue, 12 Feb 2019 01:22:44 +0000 Message-Id: <20190212012256.1005924-20-sandals@crustytoothpaste.net> X-Mailer: git-send-email 2.20.1.791.gb4d0f1c61a In-Reply-To: <20190212012256.1005924-1-sandals@crustytoothpaste.net> References: <20190212012256.1005924-1-sandals@crustytoothpaste.net> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 127.0.1.1 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Since sha1_to_hex is limited to SHA-1, replace the uses of it in this file with hasH_to_hex. Rename several variables accordingly to reflect that they are no longer limited to SHA-1. Signed-off-by: brian m. carlson --- http-walker.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/http-walker.c b/http-walker.c index 8063896cf6..e11670eee2 100644 --- a/http-walker.c +++ b/http-walker.c @@ -434,9 +434,9 @@ static int http_fetch_pack(struct walker *walker, struct alt_base *repo, unsigne if (walker->get_verbosely) { fprintf(stderr, "Getting pack %s\n", - sha1_to_hex(target->hash)); + hash_to_hex(target->hash)); fprintf(stderr, " which contains %s\n", - sha1_to_hex(sha1)); + hash_to_hex(sha1)); } preq = new_http_pack_request(target, repo->base); @@ -473,9 +473,9 @@ static void abort_object_request(struct object_request *obj_req) release_object_request(obj_req); } -static int fetch_object(struct walker *walker, unsigned char *sha1) +static int fetch_object(struct walker *walker, unsigned char *hash) { - char *hex = sha1_to_hex(sha1); + char *hex = hash_to_hex(hash); int ret = 0; struct object_request *obj_req = NULL; struct http_object_request *req; @@ -483,7 +483,7 @@ static int fetch_object(struct walker *walker, unsigned char *sha1) list_for_each(pos, head) { obj_req = list_entry(pos, struct object_request, node); - if (hasheq(obj_req->oid.hash, sha1)) + if (hasheq(obj_req->oid.hash, hash)) break; } if (obj_req == NULL) @@ -557,20 +557,20 @@ static int fetch_object(struct walker *walker, unsigned char *sha1) return ret; } -static int fetch(struct walker *walker, unsigned char *sha1) +static int fetch(struct walker *walker, unsigned char *hash) { struct walker_data *data = walker->data; struct alt_base *altbase = data->alt; - if (!fetch_object(walker, sha1)) + if (!fetch_object(walker, hash)) return 0; while (altbase) { - if (!http_fetch_pack(walker, altbase, sha1)) + if (!http_fetch_pack(walker, altbase, hash)) return 0; fetch_alternates(walker, data->alt->base); altbase = altbase->next; } - return error("Unable to find %s under %s", sha1_to_hex(sha1), + return error("Unable to find %s under %s", hash_to_hex(hash), data->alt->base); } From patchwork Tue Feb 12 01:22:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "brian m. carlson" X-Patchwork-Id: 10807149 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A59B21575 for ; Tue, 12 Feb 2019 01:23:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9761B2AC25 for ; Tue, 12 Feb 2019 01:23:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8BABE2AC31; Tue, 12 Feb 2019 01:23:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3A7262AC25 for ; Tue, 12 Feb 2019 01:23:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727237AbfBLBXj (ORCPT ); Mon, 11 Feb 2019 20:23:39 -0500 Received: from injection.crustytoothpaste.net ([192.241.140.119]:34334 "EHLO injection.crustytoothpaste.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727212AbfBLBXi (ORCPT ); Mon, 11 Feb 2019 20:23:38 -0500 Received: from genre.crustytoothpaste.net (unknown [IPv6:2001:470:b978:101:3dc7:72ec:75fa:fee5]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by injection.crustytoothpaste.net (Postfix) with ESMTPSA id 0E12160E57; Tue, 12 Feb 2019 01:23:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=crustytoothpaste.net; s=default; t=1549934615; bh=hXIxm2OltYi/N9VgtHCQFReQEeiQbRf+hi6+lBEL08E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Reply-To: Subject:Date:To:CC:Resent-Date:Resent-From:Resent-To:Resent-Cc: In-Reply-To:References:Content-Type:Content-Disposition; b=oeqDz0u5FGsjsNjGcM5YsFT07m+Qt6STTHntrY7tOX4I/MoCOXWM9s6rDwSBLgkOB bwicmOjBKGeZ5HIf3+P16IOT352+YYOQT9aILtcKsFHlyIToBD59x0dcEFXQqqE+2p K5F3wLbqC+9q+OaHU8HxryaiKoK25w4p6aAG1gGnDDe+KW9zKa46vxKqQRS/znrTOr C6LmRXUEvZgarbZORib6zFOQ1fQUcEm/aQ7F1uhWJVB6vBRYLO847u9MKYRzxUNJ3v JLNhz6rmyh+ML/8+Rra3upagFEjzXy56x4H3GPWO7igrs+40/cpkhIoZQabqcEdgGO EKmtG035jLmYdYNk/xeQyAOAJYjv1Q1Xc065ZgvKwny6sJqYiWODeVBnnotUHhcjE5 00GeSVotLsDEzX7NQOdZlg/wiLCtfpcwBjRMwRwTRyKz74NRBV+Rg7hkZeVGfUXAnQ vIFZEtx4vuXOfTJCK3aHsLbvesMnUr9oS2RQDO0/vt0a/ySCis8 From: "brian m. carlson" To: Cc: =?utf-8?q?Ren=C3=A9_Scharfe?= , Duy Nguyen Subject: [PATCH 20/31] http: replace hard-coded constant with the_hash_algo Date: Tue, 12 Feb 2019 01:22:45 +0000 Message-Id: <20190212012256.1005924-21-sandals@crustytoothpaste.net> X-Mailer: git-send-email 2.20.1.791.gb4d0f1c61a In-Reply-To: <20190212012256.1005924-1-sandals@crustytoothpaste.net> References: <20190212012256.1005924-1-sandals@crustytoothpaste.net> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 127.0.1.1 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Replace a hard-coded 40 with a reference to the_hash_algo. Signed-off-by: brian m. carlson --- http.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/http.c b/http.c index a09adc518f..993ddc956a 100644 --- a/http.c +++ b/http.c @@ -2065,7 +2065,7 @@ int http_fetch_ref(const char *base, struct ref *ref) url = quote_ref_url(base, ref->name); if (http_get_strbuf(url, &buffer, &options) == HTTP_OK) { strbuf_rtrim(&buffer); - if (buffer.len == 40) + if (buffer.len == the_hash_algo->hexsz) ret = get_oid_hex(buffer.buf, &ref->old_oid); else if (starts_with(buffer.buf, "ref: ")) { ref->symref = xstrdup(buffer.buf + 5); From patchwork Tue Feb 12 01:22:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "brian m. carlson" X-Patchwork-Id: 10807153 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0240513A4 for ; Tue, 12 Feb 2019 01:23:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E3E1B2AC25 for ; Tue, 12 Feb 2019 01:23:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D866E2AC31; Tue, 12 Feb 2019 01:23:43 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 840712AC25 for ; Tue, 12 Feb 2019 01:23:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727261AbfBLBXm (ORCPT ); Mon, 11 Feb 2019 20:23:42 -0500 Received: from injection.crustytoothpaste.net ([192.241.140.119]:34342 "EHLO injection.crustytoothpaste.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727224AbfBLBXi (ORCPT ); Mon, 11 Feb 2019 20:23:38 -0500 Received: from genre.crustytoothpaste.net (unknown [IPv6:2001:470:b978:101:3dc7:72ec:75fa:fee5]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by injection.crustytoothpaste.net (Postfix) with ESMTPSA id 4C63E60E59; Tue, 12 Feb 2019 01:23:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=crustytoothpaste.net; s=default; t=1549934617; bh=IIAQhUwViuOnvBSSz5YI0UAy07LU+dsMBhJXScJ5C68=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Reply-To: Subject:Date:To:CC:Resent-Date:Resent-From:Resent-To:Resent-Cc: In-Reply-To:References:Content-Type:Content-Disposition; b=b8LR1rO+8ziV9EeyyRzKsDeHftJeCHzT9x0QWcyQMqHQItssDy2rdBKg20QXIVezO 4qpfZCNfDTslU+ce8ddeL05nBInVAFxPiIB6V7h8Aiz4wHTwRj4RprAtLGHoQpPi8t IKPYHyCImD2kKINzobx9cyOzsPRRWA+U2CSaNQy9QdVLXJB1EvP5SEMTYIDHwP0FYX bw40QloXAbE1mqjMD1x4htcanPiQQYVklCMYVax2uHjvHKakdsph5T+vV8FlfHLRry h64wQjnu1kqKxSWrx4WGR2oPrPSQqqwAADPOGYyfPkrKuwM8/zM9OCoswE14z1fddL 8pI+b8RG8U0lJgf8yLHotLfUu+BO5CkmAtBsiQWpy/bqHiPzyVTXS30hV4h+JKfXrw c1xk6TS+USlkW1PDmcCN7EmgXSMvbQ/HXW6tIFvLVf1W2jxFKMr+weDVlE3hnbhJAH QPKVCUvJtLDCpWVbMmTqlLXTmeJ70BM3Q9UoZu3Q4qBZt7mN1t2 From: "brian m. carlson" To: Cc: =?utf-8?q?Ren=C3=A9_Scharfe?= , Duy Nguyen Subject: [PATCH 21/31] http: compute hash of downloaded objects using the_hash_algo Date: Tue, 12 Feb 2019 01:22:46 +0000 Message-Id: <20190212012256.1005924-22-sandals@crustytoothpaste.net> X-Mailer: git-send-email 2.20.1.791.gb4d0f1c61a In-Reply-To: <20190212012256.1005924-1-sandals@crustytoothpaste.net> References: <20190212012256.1005924-1-sandals@crustytoothpaste.net> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 127.0.1.1 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: brian m. carlson --- http.c | 10 +++++----- http.h | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/http.c b/http.c index 993ddc956a..458d07fabb 100644 --- a/http.c +++ b/http.c @@ -2337,8 +2337,8 @@ static size_t fwrite_sha1_file(char *ptr, size_t eltsize, size_t nmemb, freq->stream.next_out = expn; freq->stream.avail_out = sizeof(expn); freq->zret = git_inflate(&freq->stream, Z_SYNC_FLUSH); - git_SHA1_Update(&freq->c, expn, - sizeof(expn) - freq->stream.avail_out); + the_hash_algo->update_fn(&freq->c, expn, + sizeof(expn) - freq->stream.avail_out); } while (freq->stream.avail_in && freq->zret == Z_OK); return size; } @@ -2396,7 +2396,7 @@ struct http_object_request *new_http_object_request(const char *base_url, git_inflate_init(&freq->stream); - git_SHA1_Init(&freq->c); + the_hash_algo->init_fn(&freq->c); freq->url = get_remote_object_url(base_url, hex, 0); @@ -2431,7 +2431,7 @@ struct http_object_request *new_http_object_request(const char *base_url, if (prev_read == -1) { memset(&freq->stream, 0, sizeof(freq->stream)); git_inflate_init(&freq->stream); - git_SHA1_Init(&freq->c); + the_hash_algo->init_fn(&freq->c); if (prev_posn>0) { prev_posn = 0; lseek(freq->localfile, 0, SEEK_SET); @@ -2502,7 +2502,7 @@ int finish_http_object_request(struct http_object_request *freq) } git_inflate_end(&freq->stream); - git_SHA1_Final(freq->real_oid.hash, &freq->c); + the_hash_algo->final_fn(freq->real_oid.hash, &freq->c); if (freq->zret != Z_STREAM_END) { unlink_or_warn(freq->tmpfile.buf); return -1; diff --git a/http.h b/http.h index 4eb4e808e5..10d3cfdb80 100644 --- a/http.h +++ b/http.h @@ -225,7 +225,7 @@ struct http_object_request { long http_code; struct object_id oid; struct object_id real_oid; - git_SHA_CTX c; + git_hash_ctx c; git_zstream stream; int zret; int rename; From patchwork Tue Feb 12 01:22:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "brian m. carlson" X-Patchwork-Id: 10807151 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 513B41575 for ; Tue, 12 Feb 2019 01:23:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4136A2AC25 for ; Tue, 12 Feb 2019 01:23:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 358D92AC31; Tue, 12 Feb 2019 01:23:43 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D68702AC25 for ; Tue, 12 Feb 2019 01:23:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727255AbfBLBXl (ORCPT ); Mon, 11 Feb 2019 20:23:41 -0500 Received: from injection.crustytoothpaste.net ([192.241.140.119]:34346 "EHLO injection.crustytoothpaste.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727227AbfBLBXk (ORCPT ); Mon, 11 Feb 2019 20:23:40 -0500 Received: from genre.crustytoothpaste.net (unknown [IPv6:2001:470:b978:101:3dc7:72ec:75fa:fee5]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by injection.crustytoothpaste.net (Postfix) with ESMTPSA id EB9FF60E5A; Tue, 12 Feb 2019 01:23:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=crustytoothpaste.net; s=default; t=1549934618; bh=6lFN0qiDIfVD5kLeIIGjcDrmBFAO3vCq4WNSLzWU0TQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Reply-To: Subject:Date:To:CC:Resent-Date:Resent-From:Resent-To:Resent-Cc: In-Reply-To:References:Content-Type:Content-Disposition; b=ry2O1s2Q5SMnCq4IjjsRmRbsV/pjmRtb7NbjjgStHBmX7uzX5ivM4mMlMjSU1Z/Tm VfWgBI5yYwb4NVQ8STCPHSGqwRb8pbuC1vj8fqtkvfb0nXuisGCp9zOrBhHfUc4zat LKU61YcDz4DNBiQwphNm43reEMcnF60HVhoi037MrV9xb0uTwYYyH8n381PqxgXC0M 9c7OX8tEmCU5bXUpOOqMjoWQA7MMUifpWg90Yd/iHLUASogks5vhRe+zi71saKvQzS X7WBmHOsLouXZVxTBW0jcsKeHKktP1uQJA7GwTbfcQuTulq0W1mY+SUEsctsr/V1J/ EYndJ4eAIY8CThWNOZsZWMSwFtkeFzRc/wbenl3kVQDdU0Vj0QitFl4qDUpXzTFcC1 bCqdzyFtlOdgOI+731a8qUgmGj0IyURW+ra9+5+dv6U7AytXFSKAMSL7QKCzHB31Na VxKhCPbGjh5Fr72eHfy9LO/H8HgBz5XtDxCZnWAjuX5kACDMDSh From: "brian m. carlson" To: Cc: =?utf-8?q?Ren=C3=A9_Scharfe?= , Duy Nguyen Subject: [PATCH 22/31] http: replace sha1_to_hex Date: Tue, 12 Feb 2019 01:22:47 +0000 Message-Id: <20190212012256.1005924-23-sandals@crustytoothpaste.net> X-Mailer: git-send-email 2.20.1.791.gb4d0f1c61a In-Reply-To: <20190212012256.1005924-1-sandals@crustytoothpaste.net> References: <20190212012256.1005924-1-sandals@crustytoothpaste.net> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 127.0.1.1 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Since sha1_to_hex is limited to SHA-1, replace it with hash_to_hex. Signed-off-by: brian m. carlson --- http.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/http.c b/http.c index 458d07fabb..8ab07458e4 100644 --- a/http.c +++ b/http.c @@ -2079,19 +2079,19 @@ int http_fetch_ref(const char *base, struct ref *ref) } /* Helpers for fetching packs */ -static char *fetch_pack_index(unsigned char *sha1, const char *base_url) +static char *fetch_pack_index(unsigned char *hash, const char *base_url) { char *url, *tmp; struct strbuf buf = STRBUF_INIT; if (http_is_verbose) - fprintf(stderr, "Getting index for pack %s\n", sha1_to_hex(sha1)); + fprintf(stderr, "Getting index for pack %s\n", hash_to_hex(hash)); end_url_with_slash(&buf, base_url); - strbuf_addf(&buf, "objects/pack/pack-%s.idx", sha1_to_hex(sha1)); + strbuf_addf(&buf, "objects/pack/pack-%s.idx", hash_to_hex(hash)); url = strbuf_detach(&buf, NULL); - strbuf_addf(&buf, "%s.temp", sha1_pack_index_name(sha1)); + strbuf_addf(&buf, "%s.temp", sha1_pack_index_name(hash)); tmp = strbuf_detach(&buf, NULL); if (http_get_file(url, tmp, NULL) != HTTP_OK) { @@ -2262,7 +2262,7 @@ struct http_pack_request *new_http_pack_request( end_url_with_slash(&buf, base_url); strbuf_addf(&buf, "objects/pack/pack-%s.pack", - sha1_to_hex(target->hash)); + hash_to_hex(target->hash)); preq->url = strbuf_detach(&buf, NULL); strbuf_addf(&preq->tmpfile, "%s.temp", sha1_pack_name(target->hash)); @@ -2289,7 +2289,7 @@ struct http_pack_request *new_http_pack_request( if (http_is_verbose) fprintf(stderr, "Resuming fetch of pack %s at byte %"PRIuMAX"\n", - sha1_to_hex(target->hash), + hash_to_hex(target->hash), (uintmax_t)prev_posn); http_opt_request_remainder(preq->slot->curl, prev_posn); } From patchwork Tue Feb 12 01:22:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "brian m. carlson" X-Patchwork-Id: 10807155 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 25BFB1575 for ; Tue, 12 Feb 2019 01:23:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 16B662AC25 for ; Tue, 12 Feb 2019 01:23:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0ACE02AC31; Tue, 12 Feb 2019 01:23:47 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AC5032AC25 for ; Tue, 12 Feb 2019 01:23:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727300AbfBLBXp (ORCPT ); Mon, 11 Feb 2019 20:23:45 -0500 Received: from injection.crustytoothpaste.net ([192.241.140.119]:34352 "EHLO injection.crustytoothpaste.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727212AbfBLBXl (ORCPT ); Mon, 11 Feb 2019 20:23:41 -0500 Received: from genre.crustytoothpaste.net (unknown [IPv6:2001:470:b978:101:3dc7:72ec:75fa:fee5]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by injection.crustytoothpaste.net (Postfix) with ESMTPSA id 2571D60E58; Tue, 12 Feb 2019 01:23:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=crustytoothpaste.net; s=default; t=1549934619; bh=LmHmNgau81+JRvB1Fm95hA1U/DnQxiJww3/uJR+Nepg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Reply-To: Subject:Date:To:CC:Resent-Date:Resent-From:Resent-To:Resent-Cc: In-Reply-To:References:Content-Type:Content-Disposition; b=n3En/ZtRo/dpiJejOOMdZF75Zn8bwq5BMd1JG6xoNkWMbRc3XzNcf91LfHLRdQv9s fr/Czegam1O2RFkzhbWnAL/6q86UO+Jip7hQEQBsnhDlOgxhXdC+ZquSmRg31nXe61 C+ZV/J74KfRKTvgmrQcq25QF4SxSzY8XA8bA2sxo463D/8hznrbCbnUsiAbwFCXZSm 4A9OzhIh3MDS7XTjomdvpf+y1fP763LxQoI81ZsvIfMNupnlpVFeJMIDthdvGMJMGQ Qtc9y9yyYWXntyEKTNFl90y488ukOtRuiq9cMNUt7RiF34GUPdRX7BcWQWSQPrF85i dRArf85YD28YZ0Zu4E4lH7CuV9xBjxjpGb8d0ecmOo3GzILhll9ZSY1WE1q6vI1DdN J4ebyA0DANpd9AWyFRYXVRXM+LN1xfXbGAdLvNnOHJJpBxp8NgvOK1fVSaTHerDVCv LiEM62y++XJbDhMT/OxiavYGt+hoUeb8M4ooXxSGZ/7HgGpFQJf From: "brian m. carlson" To: Cc: =?utf-8?q?Ren=C3=A9_Scharfe?= , Duy Nguyen Subject: [PATCH 23/31] remote-curl: make hash size independent Date: Tue, 12 Feb 2019 01:22:48 +0000 Message-Id: <20190212012256.1005924-24-sandals@crustytoothpaste.net> X-Mailer: git-send-email 2.20.1.791.gb4d0f1c61a In-Reply-To: <20190212012256.1005924-1-sandals@crustytoothpaste.net> References: <20190212012256.1005924-1-sandals@crustytoothpaste.net> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 127.0.1.1 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Change one hard-coded use of the constant 40 to a reference to the_hash_algo. In addition, switch a use of get_oid_hex to parse_oid_hex to avoid the need to use a constant. Signed-off-by: brian m. carlson --- remote-curl.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/remote-curl.c b/remote-curl.c index bb7421023b..8395b71bbb 100644 --- a/remote-curl.c +++ b/remote-curl.c @@ -249,7 +249,7 @@ static struct ref *parse_info_refs(struct discovery *heads) if (data[i] == '\t') mid = &data[i]; if (data[i] == '\n') { - if (mid - start != 40) + if (mid - start != the_hash_algo->hexsz) die("%sinfo/refs not valid: is this a git repository?", url.buf); data[i] = 0; @@ -1013,12 +1013,13 @@ static void parse_fetch(struct strbuf *buf) const char *name; struct ref *ref; struct object_id old_oid; + const char *q; - if (get_oid_hex(p, &old_oid)) + if (parse_oid_hex(p, &old_oid, &q)) die("protocol error: expected sha/ref, got %s'", p); - if (p[GIT_SHA1_HEXSZ] == ' ') - name = p + GIT_SHA1_HEXSZ + 1; - else if (!p[GIT_SHA1_HEXSZ]) + if (*q == ' ') + name = q + 1; + else if (!*q) name = ""; else die("protocol error: expected sha/ref, got %s'", p); From patchwork Tue Feb 12 01:22:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "brian m. carlson" X-Patchwork-Id: 10807171 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0033913A4 for ; Tue, 12 Feb 2019 01:23:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E292F2A41A for ; Tue, 12 Feb 2019 01:23:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D72F12AC6A; Tue, 12 Feb 2019 01:23:57 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7E6EB2A41A for ; Tue, 12 Feb 2019 01:23:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727337AbfBLBX4 (ORCPT ); Mon, 11 Feb 2019 20:23:56 -0500 Received: from injection.crustytoothpaste.net ([192.241.140.119]:34346 "EHLO injection.crustytoothpaste.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727241AbfBLBXl (ORCPT ); Mon, 11 Feb 2019 20:23:41 -0500 Received: from genre.crustytoothpaste.net (unknown [IPv6:2001:470:b978:101:3dc7:72ec:75fa:fee5]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by injection.crustytoothpaste.net (Postfix) with ESMTPSA id C21B960E5C; Tue, 12 Feb 2019 01:23:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=crustytoothpaste.net; s=default; t=1549934620; bh=ziH3vD+j52i23ChYgEf+ntbHm11sJbqsLbaTMyUMFBA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Reply-To: Subject:Date:To:CC:Resent-Date:Resent-From:Resent-To:Resent-Cc: In-Reply-To:References:Content-Type:Content-Disposition; b=cYYbuhPoe4xBj9O1OAZrRx8LGRdVaB3lX25FihcVQ1VyNOxGfZdLWq6nXIxspzmw3 Cdxs9UcqpW8vJvmbzTHQeC9N8XdsxReHJ9miG+mGQY6QK2JktdHICDfFQoM3JKILhn 8ou/4NJcwlA/HvURNzrWH3g129pKxq0xlLFbzEHDAmvTHVeNo37JDBquLLAhY4Eifn K4G1WWqHh76ckzo3Cg3agcj5ottKZ1YPE3ROQsJ5YBn95+lx8U3bZ9wFX/khDc8idb Hc9Uw/IniTAZ/qqUFGMl9V4Ro0+cerOuaE4xCIzOU1VnE4T36MyzaDhyZJUPROHaWu xwmJfX8KzI4C9yrcLbEE8DwH18y8U+NQWnizP5LMSl+9zieq4Ym0SR/T6YmGNmVAJv Xjn5YnIOoLbMzfjcYuz+f6BEeDliWHCbf/DIw9DHroWhq9C37owNd0LRLFy8yapdLs Bka5vKskRoYeqOUToZv6Ij7sq3lfR48haywwo2L5/5xrsEJccO1 From: "brian m. carlson" To: Cc: =?utf-8?q?Ren=C3=A9_Scharfe?= , Duy Nguyen Subject: [PATCH 24/31] archive-tar: make hash size independent Date: Tue, 12 Feb 2019 01:22:49 +0000 Message-Id: <20190212012256.1005924-25-sandals@crustytoothpaste.net> X-Mailer: git-send-email 2.20.1.791.gb4d0f1c61a In-Reply-To: <20190212012256.1005924-1-sandals@crustytoothpaste.net> References: <20190212012256.1005924-1-sandals@crustytoothpaste.net> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 127.0.1.1 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Make the tar generation code hash size independent by using the_hash_algo. Make the tar parsing code compute the header value based on the hash algorithm in use. Update a variable name and switch to hash_to_hex. Signed-off-by: brian m. carlson Signed-off-by: Rene Scharfe --- archive-tar.c | 7 ++++--- builtin/get-tar-commit-id.c | 11 +++++++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/archive-tar.c b/archive-tar.c index 4aabd566fb..a5ba55c11e 100644 --- a/archive-tar.c +++ b/archive-tar.c @@ -326,14 +326,15 @@ static int write_tar_entry(struct archiver_args *args, static void write_global_extended_header(struct archiver_args *args) { - const unsigned char *sha1 = args->commit_sha1; + const unsigned char *hash = args->commit_sha1; struct strbuf ext_header = STRBUF_INIT; struct ustar_header header; unsigned int mode; - if (sha1) + if (hash) strbuf_append_ext_header(&ext_header, "comment", - sha1_to_hex(sha1), 40); + hash_to_hex(hash), + the_hash_algo->hexsz); if (args->time > USTAR_MAX_MTIME) { strbuf_append_ext_header_uint(&ext_header, "mtime", args->time); diff --git a/builtin/get-tar-commit-id.c b/builtin/get-tar-commit-id.c index 2706fcfaf2..2760549e91 100644 --- a/builtin/get-tar-commit-id.c +++ b/builtin/get-tar-commit-id.c @@ -5,6 +5,7 @@ #include "commit.h" #include "tar.h" #include "builtin.h" +#include "strbuf.h" #include "quote.h" static const char builtin_get_tar_commit_id_usage[] = @@ -21,6 +22,8 @@ int cmd_get_tar_commit_id(int argc, const char **argv, const char *prefix) char *content = buffer + RECORDSIZE; const char *comment; ssize_t n; + char *hdrprefix; + int ret; if (argc != 1) usage(builtin_get_tar_commit_id_usage); @@ -32,10 +35,14 @@ int cmd_get_tar_commit_id(int argc, const char **argv, const char *prefix) die_errno("git get-tar-commit-id: EOF before reading tar header"); if (header->typeflag[0] != 'g') return 1; - if (!skip_prefix(content, "52 comment=", &comment)) + + hdrprefix = xstrfmt("%zu comment=", the_hash_algo->hexsz + strlen(" comment=") + 2 + 1); + ret = skip_prefix(content, hdrprefix, &comment); + free(hdrprefix); + if (!ret) return 1; - if (write_in_full(1, comment, 41) < 0) + if (write_in_full(1, comment, the_hash_algo->hexsz + 1) < 0) die_errno("git get-tar-commit-id: write error"); return 0; From patchwork Tue Feb 12 01:22:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "brian m. carlson" X-Patchwork-Id: 10807163 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 314EE1575 for ; Tue, 12 Feb 2019 01:23:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1D3532793B for ; Tue, 12 Feb 2019 01:23:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 107252AC2D; Tue, 12 Feb 2019 01:23:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 98BEA2AC33 for ; Tue, 12 Feb 2019 01:23:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727319AbfBLBXt (ORCPT ); Mon, 11 Feb 2019 20:23:49 -0500 Received: from injection.crustytoothpaste.net ([192.241.140.119]:34362 "EHLO injection.crustytoothpaste.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727259AbfBLBXn (ORCPT ); Mon, 11 Feb 2019 20:23:43 -0500 Received: from genre.crustytoothpaste.net (unknown [IPv6:2001:470:b978:101:3dc7:72ec:75fa:fee5]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by injection.crustytoothpaste.net (Postfix) with ESMTPSA id F36FF60E59; Tue, 12 Feb 2019 01:23:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=crustytoothpaste.net; s=default; t=1549934621; bh=SRAkzt22seKEh5pn4oaphfXHekT+q2Jm8m9IG0k53B4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Reply-To: Subject:Date:To:CC:Resent-Date:Resent-From:Resent-To:Resent-Cc: In-Reply-To:References:Content-Type:Content-Disposition; b=nsI0Kt27Gwo9d69Bl7oLLlhHfAN7ZWO0JHzVjXruPAK/VkFa6EGnvca+FGMqux+2V GYdsLvK/MMNexZbXoh4liayh7xvYAyS1pMqSngvvuvNn0ocSOZpKiaJCIMWxo1cpz4 GENH4O3oFk4QCCZNo283xcgXt1M3E/23iWTW9VD+fUJp/DW8HQ4Re9QGY+zyAZTfwj XRaE+XGpTv597GJvNHRP9wfnHMu9voWBy/BAqvCEQQNucxzbkF2aPaFWUm+AKKVCzf zICCD20XG+nMcCT/O55L9AqGo/ezHQPC3cunKwcgs+EfW2a1Mrm7HT1JYff5cs7Go6 bVnZEw6AsILUtmf9Q3MCTB4AiDnC6JRw/nW88wOKHdentXzk0ziCbI+AaW7rN6VJEY PJP3ZsV0GcVE7jtR2erADwAHS7Yrk/l5mPEM63fUyIci+BGwHwuG4P9hQTYa3cWBOm kDLoCxPba1wr0sqsrg4a1X1ZEulCOiuLOaW4x7rvbXA3zACqYei From: "brian m. carlson" To: Cc: =?utf-8?q?Ren=C3=A9_Scharfe?= , Duy Nguyen Subject: [PATCH 25/31] archive: convert struct archiver_args to object_id Date: Tue, 12 Feb 2019 01:22:50 +0000 Message-Id: <20190212012256.1005924-26-sandals@crustytoothpaste.net> X-Mailer: git-send-email 2.20.1.791.gb4d0f1c61a In-Reply-To: <20190212012256.1005924-1-sandals@crustytoothpaste.net> References: <20190212012256.1005924-1-sandals@crustytoothpaste.net> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 127.0.1.1 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Change the commit_sha1 member to be called "commit_oid" and change it to be a pointer to struct object_id. Additionally, update two uses of GIT_SHA1_HEXSZ to use the_hash_algo instead. Signed-off-by: brian m. carlson --- archive-tar.c | 6 +++--- archive-zip.c | 10 +++++----- archive.c | 8 ++++---- archive.h | 2 +- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/archive-tar.c b/archive-tar.c index a5ba55c11e..3e53aac1e6 100644 --- a/archive-tar.c +++ b/archive-tar.c @@ -326,14 +326,14 @@ static int write_tar_entry(struct archiver_args *args, static void write_global_extended_header(struct archiver_args *args) { - const unsigned char *hash = args->commit_sha1; + const struct object_id *oid = args->commit_oid; struct strbuf ext_header = STRBUF_INIT; struct ustar_header header; unsigned int mode; - if (hash) + if (oid) strbuf_append_ext_header(&ext_header, "comment", - hash_to_hex(hash), + oid_to_hex(oid), the_hash_algo->hexsz); if (args->time > USTAR_MAX_MTIME) { strbuf_append_ext_header_uint(&ext_header, "mtime", diff --git a/archive-zip.c b/archive-zip.c index 155ee4a779..4d66b5be6e 100644 --- a/archive-zip.c +++ b/archive-zip.c @@ -577,7 +577,7 @@ static void write_zip64_trailer(void) write_or_die(1, &locator64, ZIP64_DIR_TRAILER_LOCATOR_SIZE); } -static void write_zip_trailer(const unsigned char *sha1) +static void write_zip_trailer(const struct object_id *oid) { struct zip_dir_trailer trailer; int clamped = 0; @@ -590,14 +590,14 @@ static void write_zip_trailer(const unsigned char *sha1) copy_le16_clamp(trailer.entries, zip_dir_entries, &clamped); copy_le32(trailer.size, zip_dir.len); copy_le32_clamp(trailer.offset, zip_offset, &clamped); - copy_le16(trailer.comment_length, sha1 ? GIT_SHA1_HEXSZ : 0); + copy_le16(trailer.comment_length, oid ? the_hash_algo->hexsz : 0); write_or_die(1, zip_dir.buf, zip_dir.len); if (clamped) write_zip64_trailer(); write_or_die(1, &trailer, ZIP_DIR_TRAILER_SIZE); - if (sha1) - write_or_die(1, sha1_to_hex(sha1), GIT_SHA1_HEXSZ); + if (oid) + write_or_die(1, oid_to_hex(oid), the_hash_algo->hexsz); } static void dos_time(timestamp_t *timestamp, int *dos_date, int *dos_time) @@ -635,7 +635,7 @@ static int write_zip_archive(const struct archiver *ar, err = write_archive_entries(args, write_zip_entry); if (!err) - write_zip_trailer(args->commit_sha1); + write_zip_trailer(args->commit_oid); strbuf_release(&zip_dir); diff --git a/archive.c b/archive.c index 1f98324a93..f2c78a2712 100644 --- a/archive.c +++ b/archive.c @@ -380,7 +380,7 @@ static void parse_treeish_arg(const char **argv, int remote) { const char *name = argv[0]; - const unsigned char *commit_sha1; + const struct object_id *commit_oid; time_t archive_time; struct tree *tree; const struct commit *commit; @@ -402,10 +402,10 @@ static void parse_treeish_arg(const char **argv, commit = lookup_commit_reference_gently(ar_args->repo, &oid, 1); if (commit) { - commit_sha1 = commit->object.oid.hash; + commit_oid = &commit->object.oid; archive_time = commit->date; } else { - commit_sha1 = NULL; + commit_oid = NULL; archive_time = time(NULL); } @@ -426,7 +426,7 @@ static void parse_treeish_arg(const char **argv, tree = parse_tree_indirect(&tree_oid); } ar_args->tree = tree; - ar_args->commit_sha1 = commit_sha1; + ar_args->commit_oid = commit_oid; ar_args->commit = commit; ar_args->time = archive_time; } diff --git a/archive.h b/archive.h index 21ac010699..dd022a6b46 100644 --- a/archive.h +++ b/archive.h @@ -11,7 +11,7 @@ struct archiver_args { const char *base; size_t baselen; struct tree *tree; - const unsigned char *commit_sha1; + const struct object_id *commit_oid; const struct commit *commit; timestamp_t time; struct pathspec pathspec; From patchwork Tue Feb 12 01:22:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "brian m. carlson" X-Patchwork-Id: 10807165 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6BA8413A4 for ; Tue, 12 Feb 2019 01:23:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5A5D52A41A for ; Tue, 12 Feb 2019 01:23:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4DCAF2AC6A; Tue, 12 Feb 2019 01:23:55 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 06B002A41A for ; Tue, 12 Feb 2019 01:23:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727328AbfBLBXx (ORCPT ); Mon, 11 Feb 2019 20:23:53 -0500 Received: from injection.crustytoothpaste.net ([192.241.140.119]:34366 "EHLO injection.crustytoothpaste.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727265AbfBLBXn (ORCPT ); Mon, 11 Feb 2019 20:23:43 -0500 Received: from genre.crustytoothpaste.net (unknown [IPv6:2001:470:b978:101:3dc7:72ec:75fa:fee5]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by injection.crustytoothpaste.net (Postfix) with ESMTPSA id B346960E5D; Tue, 12 Feb 2019 01:23:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=crustytoothpaste.net; s=default; t=1549934622; bh=R+M5dowM78UrTslSQWMskTM3dmdYk2a7spt8mNSWcP8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Reply-To: Subject:Date:To:CC:Resent-Date:Resent-From:Resent-To:Resent-Cc: In-Reply-To:References:Content-Type:Content-Disposition; b=Oa10VZFhDBmzm6oO9JtuGAworfVrW0vjtAghtfuI8faYJfFGHaFV8ZAHvnmPZSM4o zwx1XNDjVTftl5zv55jpvP1BzsaHdASuO+MBAM2fb94geQOQ/ga/x7HbXVRY5aA8pZ abOKbu7TxX/F0/eHx2SoTT5gq9OmxJ+s02tsyqVKhs/6JHqPb7mfkq+j0GXgPti2I/ yoB+YDqGZj/xazP3jVYfr+h67s+WCahr8iKtkTC/L3YtmtK2nJzpqVOFBvQX+y860U zYH0jDlmRy53Hp/wKE5dxPf318DNCPqQyQTyhXQehuKrxhsZs2hdu4p99ue2CuWs5J jo3psEX25W2pG9AtBRZ909LybnkBzuT9hrsMAPfuNG5529yYVQAOEUMXJwcW55H3PB 3ggtcnTcPqNxRIGGX2Y+8JtEvdcUvznNzXAmQ3QKHsQCfV1wSgpwIjTW+SKo6+f47H yYTd8WiG/cqpASFiGKt+H+5S4chY+WHlCi2tcav2xiP7MeJwQ6G From: "brian m. carlson" To: Cc: =?utf-8?q?Ren=C3=A9_Scharfe?= , Duy Nguyen Subject: [PATCH 26/31] refspec: make hash size independent Date: Tue, 12 Feb 2019 01:22:51 +0000 Message-Id: <20190212012256.1005924-27-sandals@crustytoothpaste.net> X-Mailer: git-send-email 2.20.1.791.gb4d0f1c61a In-Reply-To: <20190212012256.1005924-1-sandals@crustytoothpaste.net> References: <20190212012256.1005924-1-sandals@crustytoothpaste.net> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 127.0.1.1 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Switch a use of GIT_SHA1_HEXSZ to use the_hash_algo. Signed-off-by: brian m. carlson --- refspec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/refspec.c b/refspec.c index f529092fd6..9a9bf21934 100644 --- a/refspec.c +++ b/refspec.c @@ -72,7 +72,7 @@ static int parse_refspec(struct refspec_item *item, const char *refspec, int fet /* LHS */ if (!*item->src) ; /* empty is ok; it means "HEAD" */ - else if (llen == GIT_SHA1_HEXSZ && !get_oid_hex(item->src, &unused)) + else if (llen == the_hash_algo->hexsz && !get_oid_hex(item->src, &unused)) item->exact_sha1 = 1; /* ok */ else if (!check_refname_format(item->src, flags)) ; /* valid looking ref is ok */ From patchwork Tue Feb 12 01:22:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "brian m. carlson" X-Patchwork-Id: 10807173 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C4A2B13A4 for ; Tue, 12 Feb 2019 01:23:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B5AB92A41A for ; Tue, 12 Feb 2019 01:23:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AA1032AC6A; Tue, 12 Feb 2019 01:23:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 492092A41A for ; Tue, 12 Feb 2019 01:23:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727350AbfBLBX5 (ORCPT ); Mon, 11 Feb 2019 20:23:57 -0500 Received: from injection.crustytoothpaste.net ([192.241.140.119]:34370 "EHLO injection.crustytoothpaste.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727224AbfBLBXn (ORCPT ); Mon, 11 Feb 2019 20:23:43 -0500 Received: from genre.crustytoothpaste.net (unknown [IPv6:2001:470:b978:101:3dc7:72ec:75fa:fee5]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by injection.crustytoothpaste.net (Postfix) with ESMTPSA id 82E3260E5B; Tue, 12 Feb 2019 01:23:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=crustytoothpaste.net; s=default; t=1549934622; bh=i8oMIBFk1M7HDWz+nRmVOvycOU4QF3MXjsZSqwjhY68=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Reply-To: Subject:Date:To:CC:Resent-Date:Resent-From:Resent-To:Resent-Cc: In-Reply-To:References:Content-Type:Content-Disposition; b=N9ghY7vgJLmOmyzOrc5lwjuyPsqBCOl8xk8aSzMPM0sJQmjv8/0L/Zv96NTetJy1w h43gf0gULXs+2K/WS/otwqaCJSPZArSmRz/8pSa4nXYId3j03vPE2kdEp3e6rZ/0IZ 1HGIhXj8JErr9V7Cl0mDDbvkrtNDlrwo/deWzP7Nkw7S5A6tBLAc9M1PgNzeUnms5d Mv00EgfOfsIjiusfF4IKvs08FN4djvANCJ2leH9xqwU7IWrXjtc7TxVNId0LO+w9Gz BDawTnNnJPYfbqUOw7gWB8FTRBCLJacpvitqcasfOCDEgimovhZE34HpTCe3zgUdht GemUFs7R3RWX1IIcr8M1JlShgLt4Qrhu9hiGqzZ1CMxH9rtbQPeR1gUjElWSrxVitU Z1Gr9nWFjWtoTjxy1Gen1r48FBYCafsxnAFu9xqv+pfXWl6ZMm8PL/R2+XOxA62PhO GfUUaopOLwFHuhjz+8L8aB72wX6LNfvlSOwzqNLMszWc1DLTugg From: "brian m. carlson" To: Cc: =?utf-8?q?Ren=C3=A9_Scharfe?= , Duy Nguyen Subject: [PATCH 27/31] builtin/difftool: use parse_oid_hex Date: Tue, 12 Feb 2019 01:22:52 +0000 Message-Id: <20190212012256.1005924-28-sandals@crustytoothpaste.net> X-Mailer: git-send-email 2.20.1.791.gb4d0f1c61a In-Reply-To: <20190212012256.1005924-1-sandals@crustytoothpaste.net> References: <20190212012256.1005924-1-sandals@crustytoothpaste.net> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 127.0.1.1 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Instead of using get_oid_hex and adding constants to the result, use parse_oid_hex to make this code independent of the hash size. Signed-off-by: brian m. carlson --- builtin/difftool.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/builtin/difftool.c b/builtin/difftool.c index a3ea60ea71..1b648226dc 100644 --- a/builtin/difftool.c +++ b/builtin/difftool.c @@ -65,14 +65,12 @@ static int parse_index_info(char *p, int *mode1, int *mode2, *mode2 = (int)strtol(p + 1, &p, 8); if (*p != ' ') return error("expected ' ', got '%c'", *p); - if (get_oid_hex(++p, oid1)) + if (parse_oid_hex(++p, oid1, (const char **)&p)) return error("expected object ID, got '%s'", p + 1); - p += GIT_SHA1_HEXSZ; if (*p != ' ') return error("expected ' ', got '%c'", *p); - if (get_oid_hex(++p, oid2)) + if (parse_oid_hex(++p, oid2, (const char **)&p)) return error("expected object ID, got '%s'", p + 1); - p += GIT_SHA1_HEXSZ; if (*p != ' ') return error("expected ' ', got '%c'", *p); *status = *++p; From patchwork Tue Feb 12 01:22:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "brian m. carlson" X-Patchwork-Id: 10807161 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9DBD013A4 for ; Tue, 12 Feb 2019 01:23:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8E5A52AC25 for ; Tue, 12 Feb 2019 01:23:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 82F432AC31; Tue, 12 Feb 2019 01:23:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1D35F2AC25 for ; Tue, 12 Feb 2019 01:23:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727305AbfBLBXs (ORCPT ); Mon, 11 Feb 2019 20:23:48 -0500 Received: from injection.crustytoothpaste.net ([192.241.140.119]:34380 "EHLO injection.crustytoothpaste.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727269AbfBLBXp (ORCPT ); Mon, 11 Feb 2019 20:23:45 -0500 Received: from genre.crustytoothpaste.net (unknown [IPv6:2001:470:b978:101:3dc7:72ec:75fa:fee5]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by injection.crustytoothpaste.net (Postfix) with ESMTPSA id 26CF660E5E; Tue, 12 Feb 2019 01:23:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=crustytoothpaste.net; s=default; t=1549934623; bh=2TtYrNMb/kzBAydNMsK0aKUC/eRRWFYRlEz1ei0ENP0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Reply-To: Subject:Date:To:CC:Resent-Date:Resent-From:Resent-To:Resent-Cc: In-Reply-To:References:Content-Type:Content-Disposition; b=PlFvxd6YRabT1QOOIfIbQVk9N4uaxjWQNi0jspawaBJg0IREa6l+Rv7O7y8GY7sbl LUmikA37+ZTm4CPBWlDRe8hd7ucFJUWgOb81yq3ilx2hFICzu0OI8b+Pd/0Vb9Ds0y CiIWpaP1FgX109dC1gfiK5+VnqU/HuMrNHvL3/i62izFd7SR79ToGj/JO3nAsRqic8 rCCtOxt/6EPDXoTOETk9q2HlTPLlRzvHQrTJn/e7l+2Bjf6utS2KbMJpjlXxqSb5Hn 73x2sK0ujdi02WBH0U5OTTzwotG4FJd2qNb6wRwsknBAbkwqy5tCxDfomTysCrag/l AvmI90vlsOGjsBaJKdW7gLhQQ6MajMB4LDLMCw8+syFFAlOffiJ3PMZJPI0i/8LcTJ bXt1RAE1UqWfPsSvV5W1sfeVYAv10q18xbN/TtikLmVDeNCUFc9O9qCFbIbGNV1xCm vhhTJJAJu630di1Azl9up6q+iOSVY41WrqjdE7MEiPynAr8f3sW From: "brian m. carlson" To: Cc: =?utf-8?q?Ren=C3=A9_Scharfe?= , Duy Nguyen Subject: [PATCH 28/31] dir: make untracked cache extension hash size independent Date: Tue, 12 Feb 2019 01:22:53 +0000 Message-Id: <20190212012256.1005924-29-sandals@crustytoothpaste.net> X-Mailer: git-send-email 2.20.1.791.gb4d0f1c61a In-Reply-To: <20190212012256.1005924-1-sandals@crustytoothpaste.net> References: <20190212012256.1005924-1-sandals@crustytoothpaste.net> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 127.0.1.1 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Instead of using a struct with a flex array member to read and write the untracked cache extension, use a shorter, fixed-length struct and add the name and hash data explicitly. Signed-off-by: brian m. carlson --- dir.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/dir.c b/dir.c index b2cabadf25..7503b56918 100644 --- a/dir.c +++ b/dir.c @@ -2545,13 +2545,9 @@ struct ondisk_untracked_cache { struct stat_data info_exclude_stat; struct stat_data excludes_file_stat; uint32_t dir_flags; - unsigned char info_exclude_sha1[20]; - unsigned char excludes_file_sha1[20]; - char exclude_per_dir[FLEX_ARRAY]; }; #define ouc_offset(x) offsetof(struct ondisk_untracked_cache, x) -#define ouc_size(len) (ouc_offset(exclude_per_dir) + len + 1) struct write_data { int index; /* number of written untracked_cache_dir */ @@ -2634,20 +2630,21 @@ void write_untracked_extension(struct strbuf *out, struct untracked_cache *untra struct write_data wd; unsigned char varbuf[16]; int varint_len; - size_t len = strlen(untracked->exclude_per_dir); + const unsigned hashsz = the_hash_algo->rawsz; - FLEX_ALLOC_MEM(ouc, exclude_per_dir, untracked->exclude_per_dir, len); + ouc = xcalloc(1, sizeof(*ouc)); stat_data_to_disk(&ouc->info_exclude_stat, &untracked->ss_info_exclude.stat); stat_data_to_disk(&ouc->excludes_file_stat, &untracked->ss_excludes_file.stat); - hashcpy(ouc->info_exclude_sha1, untracked->ss_info_exclude.oid.hash); - hashcpy(ouc->excludes_file_sha1, untracked->ss_excludes_file.oid.hash); ouc->dir_flags = htonl(untracked->dir_flags); varint_len = encode_varint(untracked->ident.len, varbuf); strbuf_add(out, varbuf, varint_len); strbuf_addbuf(out, &untracked->ident); - strbuf_add(out, ouc, ouc_size(len)); + strbuf_add(out, ouc, sizeof(*ouc)); + strbuf_add(out, untracked->ss_info_exclude.oid.hash, hashsz); + strbuf_add(out, untracked->ss_excludes_file.oid.hash, hashsz); + strbuf_add(out, untracked->exclude_per_dir, strlen(untracked->exclude_per_dir) + 1); FREE_AND_NULL(ouc); if (!untracked->root) { @@ -2834,6 +2831,9 @@ struct untracked_cache *read_untracked_extension(const void *data, unsigned long int ident_len; ssize_t len; const char *exclude_per_dir; + const unsigned hashsz = the_hash_algo->rawsz; + const unsigned offset = sizeof(struct ondisk_untracked_cache); + const unsigned exclude_per_dir_offset = offset + 2 * hashsz; if (sz <= 1 || end[-1] != '\0') return NULL; @@ -2845,7 +2845,7 @@ struct untracked_cache *read_untracked_extension(const void *data, unsigned long ident = (const char *)next; next += ident_len; - if (next + ouc_size(0) > end) + if (next + exclude_per_dir_offset + 1 > end) return NULL; uc = xcalloc(1, sizeof(*uc)); @@ -2853,15 +2853,15 @@ struct untracked_cache *read_untracked_extension(const void *data, unsigned long strbuf_add(&uc->ident, ident, ident_len); load_oid_stat(&uc->ss_info_exclude, next + ouc_offset(info_exclude_stat), - next + ouc_offset(info_exclude_sha1)); + next + offset); load_oid_stat(&uc->ss_excludes_file, next + ouc_offset(excludes_file_stat), - next + ouc_offset(excludes_file_sha1)); + next + offset + hashsz); uc->dir_flags = get_be32(next + ouc_offset(dir_flags)); - exclude_per_dir = (const char *)next + ouc_offset(exclude_per_dir); + exclude_per_dir = (const char *)next + exclude_per_dir_offset; uc->exclude_per_dir = xstrdup(exclude_per_dir); /* NUL after exclude_per_dir is covered by sizeof(*ouc) */ - next += ouc_size(strlen(exclude_per_dir)); + next += exclude_per_dir_offset + strlen(exclude_per_dir) + 1; if (next >= end) goto done2; From patchwork Tue Feb 12 01:22:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "brian m. carlson" X-Patchwork-Id: 10807159 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D263713A4 for ; Tue, 12 Feb 2019 01:23:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C395B2AC25 for ; Tue, 12 Feb 2019 01:23:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B85852AC31; Tue, 12 Feb 2019 01:23:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 32BB22AC25 for ; Tue, 12 Feb 2019 01:23:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727301AbfBLBXr (ORCPT ); Mon, 11 Feb 2019 20:23:47 -0500 Received: from injection.crustytoothpaste.net ([192.241.140.119]:34384 "EHLO injection.crustytoothpaste.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727270AbfBLBXq (ORCPT ); Mon, 11 Feb 2019 20:23:46 -0500 Received: from genre.crustytoothpaste.net (unknown [IPv6:2001:470:b978:101:3dc7:72ec:75fa:fee5]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by injection.crustytoothpaste.net (Postfix) with ESMTPSA id 75EA36042D; Tue, 12 Feb 2019 01:23:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=crustytoothpaste.net; s=default; t=1549934624; bh=hXdBQmxKcdp38XPH0Yx4qOCZOiLkrEgT+oxVjBoJJH4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Reply-To: Subject:Date:To:CC:Resent-Date:Resent-From:Resent-To:Resent-Cc: In-Reply-To:References:Content-Type:Content-Disposition; b=D2EbhrGQYP3K4/dG9qEJEFCXGEyaU8I1TFk43d8fYNyxPlchJUAIXiGTJqGQq3UVF o966d/Ay/cy0JUC99xdPuuPZuTcBt9QGFMoYn3F/nJYkJIJ0JYY6FxWO+S/SwIuEAQ FNX5KNP8aHmKK89zjmDKlG2YfN5yhnNca5zf4ZTPSt9Zild0iHmlr0IavPyil9fOmS gvQ1Jhah2bE9e+VFWo8ZaFV026yAIdHJPZSNDxUQ+uD/w6LNNf6q6ZyCpiC8U/mtRl H3dkIfDUeHn5hME7poI3A6XaXisnkURI9+gLQPSdQVnEc29GNCNIdnP2qshO7stmhq fqFUhesgLN9FwWRv/gbqC9YMHqk2YaNpSefIuTec04r96FW3Sw2euaT4Bd9huq513g LUKIX51ogY7PsbA2IRgyj7nU3a6tCMck6I+ivtbaaQr7zmIepdoiVyoBkPmqTbusVg JL3PUYaOLIhslOg8yEJ3/WkpbhfYuTgwtXzrG3xyC4VAL+lzYed From: "brian m. carlson" To: Cc: =?utf-8?q?Ren=C3=A9_Scharfe?= , Duy Nguyen Subject: [PATCH 29/31] read-cache: read data in a hash-independent way Date: Tue, 12 Feb 2019 01:22:54 +0000 Message-Id: <20190212012256.1005924-30-sandals@crustytoothpaste.net> X-Mailer: git-send-email 2.20.1.791.gb4d0f1c61a In-Reply-To: <20190212012256.1005924-1-sandals@crustytoothpaste.net> References: <20190212012256.1005924-1-sandals@crustytoothpaste.net> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 127.0.1.1 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Index entries are structured with a variety of fields up front, followed by a hash and one or two flags fields. Because the hash field is stored in the middle of the structure, it's difficult to use one fixed-size structure that easily allows access to the hash and flags fields. Adjust the structure to hold the maximum amount of data that may be needed using a member called "data" and read and write this field independently in the various places that need to read and write the structure. Signed-off-by: brian m. carlson --- read-cache.c | 74 ++++++++++++++++++++-------------------------------- 1 file changed, 29 insertions(+), 45 deletions(-) diff --git a/read-cache.c b/read-cache.c index 0e0c93edc9..d9f12c568f 100644 --- a/read-cache.c +++ b/read-cache.c @@ -1634,39 +1634,24 @@ struct ondisk_cache_entry { uint32_t uid; uint32_t gid; uint32_t size; - unsigned char sha1[20]; - uint16_t flags; - char name[FLEX_ARRAY]; /* more */ -}; - -/* - * This struct is used when CE_EXTENDED bit is 1 - * The struct must match ondisk_cache_entry exactly from - * ctime till flags - */ -struct ondisk_cache_entry_extended { - struct cache_time ctime; - struct cache_time mtime; - uint32_t dev; - uint32_t ino; - uint32_t mode; - uint32_t uid; - uint32_t gid; - uint32_t size; - unsigned char sha1[20]; - uint16_t flags; - uint16_t flags2; - char name[FLEX_ARRAY]; /* more */ + /* + * unsigned char hash[hashsz]; + * uint16_t flags; + * if (flags & CE_EXTENDED) + * uint16_t flags2; + */ + unsigned char data[GIT_MAX_RAWSZ + 2 * sizeof(uint16_t)]; + char name[FLEX_ARRAY]; }; /* These are only used for v3 or lower */ #define align_padding_size(size, len) ((size + (len) + 8) & ~7) - (size + len) -#define align_flex_name(STRUCT,len) ((offsetof(struct STRUCT,name) + (len) + 8) & ~7) +#define align_flex_name(STRUCT,len) ((offsetof(struct STRUCT,data) + (len) + 8) & ~7) #define ondisk_cache_entry_size(len) align_flex_name(ondisk_cache_entry,len) -#define ondisk_cache_entry_extended_size(len) align_flex_name(ondisk_cache_entry_extended,len) -#define ondisk_ce_size(ce) (((ce)->ce_flags & CE_EXTENDED) ? \ - ondisk_cache_entry_extended_size(ce_namelen(ce)) : \ - ondisk_cache_entry_size(ce_namelen(ce))) +#define ondisk_data_size(flags, len) (the_hash_algo->rawsz + \ + ((flags & CE_EXTENDED) ? 2 : 1) * sizeof(uint16_t) + len) +#define ondisk_data_size_max(len) (ondisk_data_size(CE_EXTENDED, len)) +#define ondisk_ce_size(ce) (ondisk_cache_entry_size(ondisk_data_size((ce)->ce_flags, ce_namelen(ce)))) /* Allow fsck to force verification of the index checksum. */ int verify_index_checksum; @@ -1740,6 +1725,8 @@ static struct cache_entry *create_from_disk(struct mem_pool *ce_mem_pool, struct cache_entry *ce; size_t len; const char *name; + const unsigned hashsz = the_hash_algo->rawsz; + const uint16_t *flagsp = (const uint16_t *)(ondisk->data + hashsz); unsigned int flags; size_t copy_len = 0; /* @@ -1752,22 +1739,20 @@ static struct cache_entry *create_from_disk(struct mem_pool *ce_mem_pool, int expand_name_field = version == 4; /* On-disk flags are just 16 bits */ - flags = get_be16(&ondisk->flags); + flags = get_be16(flagsp); len = flags & CE_NAMEMASK; if (flags & CE_EXTENDED) { - struct ondisk_cache_entry_extended *ondisk2; int extended_flags; - ondisk2 = (struct ondisk_cache_entry_extended *)ondisk; - extended_flags = get_be16(&ondisk2->flags2) << 16; + extended_flags = get_be16(flagsp + 1) << 16; /* We do not yet understand any bit out of CE_EXTENDED_FLAGS */ if (extended_flags & ~CE_EXTENDED_FLAGS) die(_("unknown index entry format 0x%08x"), extended_flags); flags |= extended_flags; - name = ondisk2->name; + name = (const char *)(flagsp + 2); } else - name = ondisk->name; + name = (const char *)(flagsp + 1); if (expand_name_field) { const unsigned char *cp = (const unsigned char *)name; @@ -1806,7 +1791,9 @@ static struct cache_entry *create_from_disk(struct mem_pool *ce_mem_pool, ce->ce_flags = flags & ~CE_NAMEMASK; ce->ce_namelen = len; ce->index = 0; - hashcpy(ce->oid.hash, ondisk->sha1); + hashcpy(ce->oid.hash, ondisk->data); + memcpy(ce->name, name, len); + ce->name[len] = '\0'; if (expand_name_field) { if (copy_len) @@ -2528,6 +2515,8 @@ static void copy_cache_entry_to_ondisk(struct ondisk_cache_entry *ondisk, struct cache_entry *ce) { short flags; + const unsigned hashsz = the_hash_algo->rawsz; + uint16_t *flagsp = (uint16_t *)(ondisk->data + hashsz); ondisk->ctime.sec = htonl(ce->ce_stat_data.sd_ctime.sec); ondisk->mtime.sec = htonl(ce->ce_stat_data.sd_mtime.sec); @@ -2539,15 +2528,13 @@ static void copy_cache_entry_to_ondisk(struct ondisk_cache_entry *ondisk, ondisk->uid = htonl(ce->ce_stat_data.sd_uid); ondisk->gid = htonl(ce->ce_stat_data.sd_gid); ondisk->size = htonl(ce->ce_stat_data.sd_size); - hashcpy(ondisk->sha1, ce->oid.hash); + hashcpy(ondisk->data, ce->oid.hash); flags = ce->ce_flags & ~CE_NAMEMASK; flags |= (ce_namelen(ce) >= CE_NAMEMASK ? CE_NAMEMASK : ce_namelen(ce)); - ondisk->flags = htons(flags); + flagsp[0] = htons(flags); if (ce->ce_flags & CE_EXTENDED) { - struct ondisk_cache_entry_extended *ondisk2; - ondisk2 = (struct ondisk_cache_entry_extended *)ondisk; - ondisk2->flags2 = htons((ce->ce_flags & CE_EXTENDED_FLAGS) >> 16); + flagsp[1] = htons((ce->ce_flags & CE_EXTENDED_FLAGS) >> 16); } } @@ -2566,10 +2553,7 @@ static int ce_write_entry(git_hash_ctx *c, int fd, struct cache_entry *ce, stripped_name = 1; } - if (ce->ce_flags & CE_EXTENDED) - size = offsetof(struct ondisk_cache_entry_extended, name); - else - size = offsetof(struct ondisk_cache_entry, name); + size = offsetof(struct ondisk_cache_entry,data) + ondisk_data_size(ce->ce_flags, 0); if (!previous_name) { int len = ce_namelen(ce); @@ -2727,7 +2711,7 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile, struct cache_entry **cache = istate->cache; int entries = istate->cache_nr; struct stat st; - struct ondisk_cache_entry_extended ondisk; + struct ondisk_cache_entry ondisk; struct strbuf previous_name_buf = STRBUF_INIT, *previous_name; int drop_cache_tree = istate->drop_cache_tree; off_t offset; From patchwork Tue Feb 12 01:22:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "brian m. carlson" X-Patchwork-Id: 10807167 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4C5CA13A4 for ; Tue, 12 Feb 2019 01:23:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3E6852AC67 for ; Tue, 12 Feb 2019 01:23:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 32A5E2AC84; Tue, 12 Feb 2019 01:23:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D5FDD2AC67 for ; Tue, 12 Feb 2019 01:23:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727324AbfBLBXw (ORCPT ); Mon, 11 Feb 2019 20:23:52 -0500 Received: from injection.crustytoothpaste.net ([192.241.140.119]:34352 "EHLO injection.crustytoothpaste.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726107AbfBLBXq (ORCPT ); Mon, 11 Feb 2019 20:23:46 -0500 Received: from genre.crustytoothpaste.net (unknown [IPv6:2001:470:b978:101:3dc7:72ec:75fa:fee5]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by injection.crustytoothpaste.net (Postfix) with ESMTPSA id 4857360E60; Tue, 12 Feb 2019 01:23:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=crustytoothpaste.net; s=default; t=1549934625; bh=SW5OJPhBLpqJ3hRLr4aeX6PSfsTg2E9HV5uvCFjbuCQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Reply-To: Subject:Date:To:CC:Resent-Date:Resent-From:Resent-To:Resent-Cc: In-Reply-To:References:Content-Type:Content-Disposition; b=eiH3pM71TET9eGOkBMO5T6AEQ/AzOAfmhfiquoI8Mh0IMbsGVpVTXyU7RCuI0ubbz dgdXvFF+pMexBLNW2pFJNZOPyXPHOp+To19z9CbN6JHlECTRTrJIher84ItYUSLBGr v2FZXN53/4+KO3cU2mwJaYd4YMUUmnUsVMw0guKUU6PrEzIBJVISRfEMsvzhzalrNE HqiL6yWKW5b2qTbb4EN1aJN/bdaMCREWZlpVEhwQmPDpqREPa3Dc9q57HPdQIgPn9T TnpT08lEjrINYofLjzApH/sl8JGOciwHtHzOr1uT1KDlSRSJtfvQFeetTqqOg9nswe o5V8ovLqVUyQWJfKCtx0KOBFFZcsrQzKb/5VuNa5SDD1jqlXyhpBGMgtRGcoIA0YJ6 xLDvRXvarFNROYfwCFp/tKbI0DEmp1eooye4E71G7xd9/5Dl2pTGGd0NaESag1o+Sh fdncF9w6OV9Sg+NLHWX5n2UgtnXPmaCJ7HBCa9uOLEN/DLBHz9d From: "brian m. carlson" To: Cc: =?utf-8?q?Ren=C3=A9_Scharfe?= , Duy Nguyen Subject: [PATCH 30/31] Git.pm: make hash size independent Date: Tue, 12 Feb 2019 01:22:55 +0000 Message-Id: <20190212012256.1005924-31-sandals@crustytoothpaste.net> X-Mailer: git-send-email 2.20.1.791.gb4d0f1c61a In-Reply-To: <20190212012256.1005924-1-sandals@crustytoothpaste.net> References: <20190212012256.1005924-1-sandals@crustytoothpaste.net> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 127.0.1.1 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The cat_blob function was matching on exactly 40 hex characters. This won't work with SHA-256, which uses 64-character hex object IDs. While it should be fine to simply match any number of hex characters since the output is space delimited, be extra safe by matching either exactly 40 or exactly 64 hex characters. Signed-off-by: brian m. carlson --- perl/Git.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/perl/Git.pm b/perl/Git.pm index d856930b2e..62c472e0ce 100644 --- a/perl/Git.pm +++ b/perl/Git.pm @@ -980,7 +980,7 @@ sub cat_blob { return -1; } - if ($description !~ /^[0-9a-fA-F]{40} \S+ (\d+)$/) { + if ($description !~ /^[0-9a-fA-F]{40}(?:[0-9a-fA-F]{24})? \S+ (\d+)$/) { carp "Unexpected result returned from git cat-file"; return -1; } From patchwork Tue Feb 12 01:22:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "brian m. carlson" X-Patchwork-Id: 10807169 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 94A9F1575 for ; Tue, 12 Feb 2019 01:23:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 848D82A41A for ; Tue, 12 Feb 2019 01:23:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7901F2AC6A; Tue, 12 Feb 2019 01:23:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A01CE2A41A for ; Tue, 12 Feb 2019 01:23:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727320AbfBLBXw (ORCPT ); Mon, 11 Feb 2019 20:23:52 -0500 Received: from injection.crustytoothpaste.net ([192.241.140.119]:34384 "EHLO injection.crustytoothpaste.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726838AbfBLBXs (ORCPT ); Mon, 11 Feb 2019 20:23:48 -0500 Received: from genre.crustytoothpaste.net (unknown [IPv6:2001:470:b978:101:3dc7:72ec:75fa:fee5]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by injection.crustytoothpaste.net (Postfix) with ESMTPSA id 80A3360E5F; Tue, 12 Feb 2019 01:23:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=crustytoothpaste.net; s=default; t=1549934626; bh=3C3h/fIQfXA/AFv15A/3H8cLzP84LKw7aAbzdZ3Em+4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Reply-To: Subject:Date:To:CC:Resent-Date:Resent-From:Resent-To:Resent-Cc: In-Reply-To:References:Content-Type:Content-Disposition; b=phxB8hqb+xT5FSqhep5XF7M76acueKI1wF+DeI3LWswg2wcbhp1t6NLg4elCxQJDt zWHMghYDd+Rf39euDQllX5exATNS+zlJOwp1Mj/3Gwy2tQlsFOhiWV3flDRfV8fubK oBL5VjrIb47F6KM9eTd3QZ2UhQ0Afo6NU+xpZj+h9isMbNsc9rFZ/m2bJiBOaa3wNa GNuyLScRW6KrtimnPCnW8XP10L6aeo3UQ3oeF62gdX1F6H4Rrz5tF4KAalo173Jc9a i3RY82Xrnicpr9nErjvLUZ6ot8lwRhG86+b1qAe+6YGQ6znrptzwcKK+YbfzFDzI3f lYH7ATloPI8mAMJ4a7niZrhcA+MI+SiCTdXnSN5C0IqPmL4EZCRoev5R2t5knubae8 pe59Ju7OqRmlnv4aW/iniIbFBZVXKGbBumL4ap7+6wsZh/1N2qUj61dvJ06aK0kWWg thWMZrlQN5AI+6YLZ2Gir31dhk6DlsO15P4RapeMARdiy5KfbST From: "brian m. carlson" To: Cc: =?utf-8?q?Ren=C3=A9_Scharfe?= , Duy Nguyen Subject: [PATCH 31/31] gitweb: make hash size independent Date: Tue, 12 Feb 2019 01:22:56 +0000 Message-Id: <20190212012256.1005924-32-sandals@crustytoothpaste.net> X-Mailer: git-send-email 2.20.1.791.gb4d0f1c61a In-Reply-To: <20190212012256.1005924-1-sandals@crustytoothpaste.net> References: <20190212012256.1005924-1-sandals@crustytoothpaste.net> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 127.0.1.1 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Gitweb has several hard-coded 40 values throughout it to check for values that are passed in or acquired from Git. To simplify the code, introduce a regex variable that matches either exactly 40 or exactly 64 hex characters, and use this variable anywhere we would have previously hard-coded a 40 in a regex. Similarly, switch the code that looks for deleted diffinfo information to look for either 40 or 64 zeros, and update one piece of code to use this function. Finally, when formatting a log line, allow an abbreviated describe output to contain up to 64 characters. Signed-off-by: brian m. carlson --- gitweb/gitweb.perl | 63 ++++++++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 30 deletions(-) diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index 2594a4badb..aec8ca3256 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -788,6 +788,9 @@ sub check_loadavg { # ====================================================================== # input validation and dispatch +# A regex matching a valid object ID. +our $oid_regex = qr/(?:[0-9a-fA-F]{40}(?:[0-9a-fA-F]{24})?)/; + # input parameters can be collected from a variety of sources (presently, CGI # and PATH_INFO), so we define an %input_params hash that collects them all # together during validation: this allows subsequent uses (e.g. href()) to be @@ -1516,7 +1519,7 @@ sub is_valid_refname { return undef unless defined $input; # textual hashes are O.K. - if ($input =~ m/^[0-9a-fA-F]{40}$/) { + if ($input =~ m/^$oid_regex$/) { return 1; } # it must be correct pathname @@ -2037,10 +2040,10 @@ sub format_log_line_html { (?'; } # match - if ($line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) { + if ($line =~ m/^index $oid_regex,$oid_regex/) { # can match only for combined diff $line = 'index '; for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) { @@ -2308,7 +2311,7 @@ sub format_extended_diff_header_line { $line .= '0' x 7; } - } elsif ($line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) { + } elsif ($line =~ m/^index $oid_regex..$oid_regex/) { # can match only for ordinary diff my ($from_link, $to_link); if ($from->{'href'}) { @@ -2834,7 +2837,7 @@ sub git_get_hash_by_path { } #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c' - $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/; + $line =~ m/^([0-9]+) (.+) ($oid_regex)\t/; if (defined $type && $type ne $2) { # type doesn't match return undef; @@ -3333,7 +3336,7 @@ sub git_get_references { while (my $line = <$fd>) { chomp $line; - if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type.*)$!) { + if ($line =~ m!^($oid_regex)\srefs/($type.*)$!) { if (defined $refs{$1}) { push @{$refs{$1}}, $2; } else { @@ -3407,7 +3410,7 @@ sub parse_tag { $tag{'id'} = $tag_id; while (my $line = <$fd>) { chomp $line; - if ($line =~ m/^object ([0-9a-fA-F]{40})$/) { + if ($line =~ m/^object ($oid_regex)$/) { $tag{'object'} = $1; } elsif ($line =~ m/^type (.+)$/) { $tag{'type'} = $1; @@ -3451,15 +3454,15 @@ sub parse_commit_text { } my $header = shift @commit_lines; - if ($header !~ m/^[0-9a-fA-F]{40}/) { + if ($header !~ m/^$oid_regex/) { return; } ($co{'id'}, my @parents) = split ' ', $header; while (my $line = shift @commit_lines) { last if $line eq "\n"; - if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) { + if ($line =~ m/^tree ($oid_regex)$/) { $co{'tree'} = $1; - } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) { + } elsif ((!defined $withparents) && ($line =~ m/^parent ($oid_regex)$/)) { push @parents, $1; } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) { $co{'author'} = to_utf8($1); @@ -3591,7 +3594,7 @@ sub parse_difftree_raw_line { # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c' # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c' - if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) { + if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ($oid_regex) ($oid_regex) (.)([0-9]{0,3})\t(.*)$/) { $res{'from_mode'} = $1; $res{'to_mode'} = $2; $res{'from_id'} = $3; @@ -3606,7 +3609,7 @@ sub parse_difftree_raw_line { } # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh' # combined diff (for merge commit) - elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) { + elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:$oid_regex )+)([a-zA-Z]+)\t(.*)$//) { $res{'nparents'} = length($1); $res{'from_mode'} = [ split(' ', $2) ]; $res{'to_mode'} = pop @{$res{'from_mode'}}; @@ -3616,7 +3619,7 @@ sub parse_difftree_raw_line { $res{'to_file'} = unquote($5); } # 'c512b523472485aef4fff9e57b229d9d243c967f' - elsif ($line =~ m/^([0-9a-fA-F]{40})$/) { + elsif ($line =~ m/^($oid_regex)$/) { $res{'commit'} = $1; } @@ -3644,7 +3647,7 @@ sub parse_ls_tree_line { if ($opts{'-l'}) { #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa 16717 panic.c' - $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40}) +(-|[0-9]+)\t(.+)$/s; + $line =~ m/^([0-9]+) (.+) ($oid_regex) +(-|[0-9]+)\t(.+)$/s; $res{'mode'} = $1; $res{'type'} = $2; @@ -3657,7 +3660,7 @@ sub parse_ls_tree_line { } } else { #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c' - $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s; + $line =~ m/^([0-9]+) (.+) ($oid_regex)\t(.+)$/s; $res{'mode'} = $1; $res{'type'} = $2; @@ -4799,7 +4802,7 @@ sub fill_from_file_info { sub is_deleted { my $diffinfo = shift; - return $diffinfo->{'to_id'} eq ('0' x 40); + return $diffinfo->{'to_id'} eq ('0' x 40) || $diffinfo->{'to_id'} eq ('0' x 64); } # does patch correspond to [previous] difftree raw line @@ -6285,7 +6288,7 @@ sub git_search_changes { -class => "list subject"}, chop_and_escape_str($co{'title'}, 50) . "
"); } elsif (defined $set{'to_id'}) { - next if ($set{'to_id'} =~ m/^0{40}$/); + next if is_deleted(\%set); print $cgi->a({-href => href(action=>"blob", hash_base=>$co{'id'}, hash=>$set{'to_id'}, file_name=>$set{'to_file'}), @@ -6829,7 +6832,7 @@ sub git_blame_common { # the header: [] # no for subsequent lines in group of lines my ($full_rev, $orig_lineno, $lineno, $group_size) = - ($line =~ /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/); + ($line =~ /^($oid_regex) (\d+) (\d+)(?: (\d+))?$/); if (!exists $metainfo{$full_rev}) { $metainfo{$full_rev} = { 'nprevious' => 0 }; } @@ -6879,7 +6882,7 @@ sub git_blame_common { } # 'previous' if (exists $meta->{'previous'} && - $meta->{'previous'} =~ /^([a-fA-F0-9]{40}) (.*)$/) { + $meta->{'previous'} =~ /^($oid_regex) (.*)$/) { $meta->{'parent'} = $1; $meta->{'file_parent'} = unquote($2); } @@ -6996,7 +6999,7 @@ sub git_blob_plain { } else { die_error(400, "No file name defined"); } - } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) { + } elsif ($hash =~ m/^$oid_regex$/) { # blobs defined by non-textual hash id's can be cached $expires = "+1d"; } @@ -7057,7 +7060,7 @@ sub git_blob { } else { die_error(400, "No file name defined"); } - } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) { + } elsif ($hash =~ m/^$oid_regex$/) { # blobs defined by non-textual hash id's can be cached $expires = "+1d"; } @@ -7515,7 +7518,7 @@ sub git_commit { # non-textual hash id's can be cached my $expires; - if ($hash =~ m/^[0-9a-fA-F]{40}$/) { + if ($hash =~ m/^$oid_regex$/) { $expires = "+1d"; } my $refs = git_get_references(); @@ -7609,7 +7612,7 @@ sub git_object { close $fd; #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c' - unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) { + unless ($line && $line =~ m/^([0-9]+) (.+) ($oid_regex)\t/) { die_error(404, "File or directory for given base does not exist"); } $type = $2; @@ -7649,7 +7652,7 @@ sub git_blobdiff { or die_error(404, "Blob diff not found"); } elsif (defined $hash && - $hash =~ /[0-9a-fA-F]{40}/) { + $hash =~ $oid_regex) { # try to find filename from $hash # read filtered raw output @@ -7659,7 +7662,7 @@ sub git_blobdiff { @difftree = # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c' # $hash == to_id - grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ } + grep { /^:[0-7]{6} [0-7]{6} $oid_regex $hash/ } map { chomp; $_ } <$fd>; close $fd or die_error(404, "Reading git-diff-tree failed"); @@ -7682,8 +7685,8 @@ sub git_blobdiff { $hash ||= $diffinfo{'to_id'}; # non-textual hash id's can be cached - if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ && - $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) { + if ($hash_base =~ m/^$oid_regex$/ && + $hash_parent_base =~ m/^$oid_regex$/) { $expires = '+1d'; } @@ -7819,7 +7822,7 @@ sub git_commitdiff { $hash_parent ne '-c' && $hash_parent ne '--cc') { # commitdiff with two commits given my $hash_parent_short = $hash_parent; - if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) { + if ($hash_parent =~ m/^$oid_regex$/) { $hash_parent_short = substr($hash_parent, 0, 7); } $formats_nav .= @@ -7928,7 +7931,7 @@ sub git_commitdiff { # non-textual hash id's can be cached my $expires; - if ($hash =~ m/^[0-9a-fA-F]{40}$/) { + if ($hash =~ m/^$oid_regex$/) { $expires = "+1d"; }