From patchwork Fri Jun 19 22:39:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "brian m. carlson" X-Patchwork-Id: 11615275 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 92B40913 for ; Fri, 19 Jun 2020 22:51:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 71F02223C6 for ; Fri, 19 Jun 2020 22:51:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (3072-bit key) header.d=crustytoothpaste.net header.i=@crustytoothpaste.net header.b="0/w5NRcu" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729765AbgFSWvj (ORCPT ); Fri, 19 Jun 2020 18:51:39 -0400 Received: from injection.crustytoothpaste.net ([192.241.140.119]:39744 "EHLO injection.crustytoothpaste.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726900AbgFSWvh (ORCPT ); Fri, 19 Jun 2020 18:51:37 -0400 Received: from camp.crustytoothpaste.net (unknown [IPv6:2001:470:b978:101:7d4e:cde:7c41:71c2]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by injection.crustytoothpaste.net (Postfix) with ESMTPSA id 86FC160A6A; Fri, 19 Jun 2020 22:51:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=crustytoothpaste.net; s=default; t=1592607095; bh=rGGLBfcx22IVYnzje3das6IhdM10H333AO2lxvPa2RQ=; 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=0/w5NRcuSizaqPK8pOZY9UYYVK98Kby5LLl50Zv0420WMaQwOufO4+XBKLjaqgLZl dtZ/gzmAf3xUmHnVXSV4XzCf2NY4guAc4T0lc5c1kGYA9TwLTdQDM+j3L6s7cBL1eJ 0tti0PLYn1tqHLV2ATHULB3xiqKeH6aGO3CVIzgNpZbbs0gPf6fkL5N4ut5y7Nmhpn ErlzCcVa9PsQczEtJMySxPU4TQPF4E/Vn3ppcL5vm2SqquU49UmMnezLSipbbwQqS9 /6h4PkrUtTwZBWvlodE2qNzUkIDu9twT2icQX5T11uYRXKmx9BMoHTsg8PgtGCoPle YUnXT7BcCIwMmLh+gkuJGBjOLHjnk3KMuLIVGHbG2HSVrAq/tZ2vtC32J2f2hSS+H4 UBVxXMK14iqgD2DEXq/yy7PcszHPariMmDUqV8ClYqtxlMseLa2rDm4DCtgqCGnNk+ erVP1H3RMTWIPFnBB5S/v64pw6ygpBB05s83tLmpnYf8jI24Ypm From: "brian m. carlson" To: Cc: Matthew DeVore , Eric Wong , Matthieu Moy Subject: [PATCH 09/14] perl: make Git::IndexInfo work with SHA-256 Date: Fri, 19 Jun 2020 22:39:42 +0000 Message-Id: <20200619223947.947067-10-sandals@crustytoothpaste.net> X-Mailer: git-send-email 2.27.0.278.ge193c7cf3a9 In-Reply-To: <20200619223947.947067-1-sandals@crustytoothpaste.net> References: <20200619223947.947067-1-sandals@crustytoothpaste.net> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Most of the Git modules, git-svn excepted, don't know anything about the hash algorithm and mostly work. However, when we're printing an all-zero object ID in Git::IndexInfo, we need to know the hash length. Since we don't want to change the API to have that information passed in, let's query the config to find the hash algorithm and compute the right value. Signed-off-by: brian m. carlson --- perl/Git/IndexInfo.pm | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/perl/Git/IndexInfo.pm b/perl/Git/IndexInfo.pm index a43108c985..2a7b4908f3 100644 --- a/perl/Git/IndexInfo.pm +++ b/perl/Git/IndexInfo.pm @@ -5,13 +5,15 @@ package Git::IndexInfo; sub new { my ($class) = @_; + my $hash_algo = Git::config('extensions.objectformat') || 'sha1'; my ($gui, $ctx) = command_input_pipe(qw/update-index -z --index-info/); - bless { gui => $gui, ctx => $ctx, nr => 0}, $class; + bless { gui => $gui, ctx => $ctx, nr => 0, hash_algo => $hash_algo}, $class; } sub remove { my ($self, $path) = @_; - if (print { $self->{gui} } '0 ', 0 x 40, "\t", $path, "\0") { + my $length = $self->{hash_algo} eq 'sha256' ? 64 : 40; + if (print { $self->{gui} } '0 ', 0 x $length, "\t", $path, "\0") { return ++$self->{nr}; } undef;