From patchwork Fri Aug 21 11:51:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?xJBvw6BuIFRy4bqnbiBDw7RuZyBEYW5o?= X-Patchwork-Id: 11729323 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 C051F722 for ; Fri, 21 Aug 2020 11:54:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A39CB204EC for ; Fri, 21 Aug 2020 11:54:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="mGunaVun" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728449AbgHULyV (ORCPT ); Fri, 21 Aug 2020 07:54:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48140 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726803AbgHULwm (ORCPT ); Fri, 21 Aug 2020 07:52:42 -0400 Received: from mail-pg1-x542.google.com (mail-pg1-x542.google.com [IPv6:2607:f8b0:4864:20::542]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B961CC061343 for ; Fri, 21 Aug 2020 04:52:00 -0700 (PDT) Received: by mail-pg1-x542.google.com with SMTP id j21so886303pgi.9 for ; Fri, 21 Aug 2020 04:52:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=7TxxN4sFutC4n7qwOG7ZDTYmhBJZYpaLLAuT1rkrSUs=; b=mGunaVunV50VgB6UzaeE5JWnPS36WzCzWg0yLap/5ctN/RVYI4AncemDVKmRTX2spp yCy9gR6GzXKnykYj6LCjuZstXF+HIR0+dSgywjXkcAY61FJHgw8Oo3tQzsOZLFgkLN5d G6pYkO6ke09+ebt27R3biHmac7muAmDTb8/6XdOxGUR6KKzqMU63Ombe6rpUNwa8pHXG +cWBcxZ/5QLyxsGuGPomdKz6FBCKtN7MtwIckhFq0bCcwIdXauMpaciOPaIyDcQeIgWN d2wMhvIyb0xJXFWx3WsWKnCN4DL1Hmbq2tKaZ4IhJdlDSUuyVLuQ8F6cmh85lkK0A7gJ fFxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=7TxxN4sFutC4n7qwOG7ZDTYmhBJZYpaLLAuT1rkrSUs=; b=sv2GS9oqmbtvzQ2gSU4NI03vx93+j3JE634YMndmU0y/5PznDsK/ww+zjCKwdFw0EP uAsnyYoJPTyh0JVsEU+3QhF3NjDjKFONjefias/2EUmlyWDDbHvj+Np9/dBoQvSNtz94 rCEVApppCULH2BYeKpbQBC4gsPFMPNiXTAB+S/1xNej6SL5C7W04svWsaovPHbi+BdE4 4aQknEgpACdSGaFMbs1mqyGWzaUMUOlAmtgGlqOfE/9Tcvb3X8jTh/dOq/aOX5xvuHXd YxnEp6YOFdkYxBaNJdC0WGYf+5wpSCHWRk+qId01hVixOSFGYMrgLjucmabinxaflfx+ u2og== X-Gm-Message-State: AOAM530tyaxCeSMdkXqeMsZq1d8L9Shq+PvoiTo1rZTUT170xAZGP9+C Q2/OxC/s56CTxxoOlmFjnTD5dVSV830= X-Google-Smtp-Source: ABdhPJzOVz7uchTr8kIbqqPUuJgsN0YJ60SC4Nl2tDsMuOKzJ0mz4UKZrhxxJY9CqYn8zkfAt8EWig== X-Received: by 2002:a63:d10a:: with SMTP id k10mr2047977pgg.382.1598010720028; Fri, 21 Aug 2020 04:52:00 -0700 (PDT) Received: from localhost.localdomain ([2402:800:63a8:cb7a:1eb1:40a4:f50c:706e]) by smtp.gmail.com with ESMTPSA id y1sm2300413pfl.136.2020.08.21.04.51.57 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Aug 2020 04:51:59 -0700 (PDT) From: =?utf-8?b?xJBvw6BuIFRy4bqnbiBDw7RuZyBEYW5o?= To: git@vger.kernel.org Cc: "brian m. carlson" , =?utf-8?q?SZEDER_G?= =?utf-8?q?=C3=A1bor?= , Junio C Hamano , Jeff King , =?utf-8?b?xJBvw6BuIFRy4bqnbiBDw7RuZyBEYW5o?= Subject: [PATCH v5 1/2] t4013: improve diff-post-processor logic Date: Fri, 21 Aug 2020 18:51:46 +0700 Message-Id: X-Mailer: git-send-email 2.28.0.143.g760df7782d.dirty In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: "brian m. carlson" From 72f936b1 (t4013: make test hash independent, 2020-02-07), we started to adjust metadata of git-diff's output in order to ignore uninteresting metadata which is dependent of underlying hash algorithm. However, we forgot to special case all-zero object names, which is special for missing objects, in consequence, we could't catch possible future bugs where object names is all-zeros including but not limited to: * show intend-to-add entry * deleted entry * diff between index and working tree with new file We also mistakenly munged file-modes as if they were object names abbreviated to 6 hexadecimal digits. In addition, in the upcoming change, we would like to test for customizing the length of abbreviated blob objects on the index line, which is not supported by current diff-processor logic. Let's fix the bug for all-zero object names, and file modes. While we're at it, support abbreviation of object names up to 16 bytes. Based-on-patch-by: Junio C Hamano Signed-off-by: Junio C Hamano Signed-off-by: brian m. carlson Signed-off-by: Đoàn Trần Công Danh --- t/t4013-diff-various.sh | 60 ++++++++++++++++++++++++++--------------- 1 file changed, 39 insertions(+), 21 deletions(-) diff --git a/t/t4013-diff-various.sh b/t/t4013-diff-various.sh index 5f97dd6d65..f6bdfc13fd 100755 --- a/t/t4013-diff-various.sh +++ b/t/t4013-diff-various.sh @@ -130,27 +130,45 @@ test_expect_success setup ' EOF process_diffs () { - _x04="[0-9a-f][0-9a-f][0-9a-f][0-9a-f]" && - _x07="$_x05[0-9a-f][0-9a-f]" && - sed -e "s/$OID_REGEX/$ZERO_OID/g" \ - -e "s/From $_x40 /From $ZERO_OID /" \ - -e "s/from $_x40)/from $ZERO_OID)/" \ - -e "s/commit $_x40\$/commit $ZERO_OID/" \ - -e "s/commit $_x40 (/commit $ZERO_OID (/" \ - -e "s/$_x40 $_x40 $_x40/$ZERO_OID $ZERO_OID $ZERO_OID/" \ - -e "s/$_x40 $_x40 /$ZERO_OID $ZERO_OID /" \ - -e "s/^$_x40 $_x40$/$ZERO_OID $ZERO_OID/" \ - -e "s/^$_x40 /$ZERO_OID /" \ - -e "s/^$_x40$/$ZERO_OID/" \ - -e "s/$_x07\.\.$_x07/fffffff..fffffff/g" \ - -e "s/$_x07,$_x07\.\.$_x07/fffffff,fffffff..fffffff/g" \ - -e "s/$_x07 $_x07 $_x07/fffffff fffffff fffffff/g" \ - -e "s/$_x07 $_x07 /fffffff fffffff /g" \ - -e "s/Merge: $_x07 $_x07/Merge: fffffff fffffff/g" \ - -e "s/$_x07\.\.\./fffffff.../g" \ - -e "s/ $_x04\.\.\./ ffff.../g" \ - -e "s/ $_x04/ ffff/g" \ - "$1" + perl -e ' + my $oid_length = length($ARGV[0]); + my $x40 = "[0-9a-f]{40}"; + my $xab = "[0-9a-f]{4,16}"; + my $orx = "[0-9a-f]" x $oid_length; + + sub munge_oid { + my ($oid) = @_; + my $x; + + return "" unless length $oid; + + if ($oid =~ /^(100644|100755|120000)$/) { + return $oid; + } + + if ($oid =~ /^0*$/) { + $x = "0"; + } else { + $x = "f"; + } + + if (length($oid) == 40) { + return $x x $oid_length; + } else { + return $x x length($oid); + } + } + + while () { + s/($orx)/munge_oid($1)/ge; + s/From ($x40)( |\))/"From " . munge_oid($1) . $2/ge; + s/commit ($x40)($| \(from )($x40?)/"commit " . munge_oid($1) . $2 . munge_oid($3)/ge; + s/\b($x40)( |\.\.|$)/munge_oid($1) . $2/ge; + s/^($x40)($| )/munge_oid($1) . $2/e; + s/($xab)(\.\.|,| |\.\.\.|$)/munge_oid($1) . $2/ge; + print; + } + ' "$ZERO_OID" <"$1" } V=$(git version | sed -e 's/^git version //' -e 's/\./\\./g') From patchwork Fri Aug 21 11:51:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?xJBvw6BuIFRy4bqnbiBDw7RuZyBEYW5o?= X-Patchwork-Id: 11729321 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 C6CD3109B for ; Fri, 21 Aug 2020 11:54:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A49CD20732 for ; Fri, 21 Aug 2020 11:54:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="tXneKQ9q" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728407AbgHULyR (ORCPT ); Fri, 21 Aug 2020 07:54:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48142 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726983AbgHULwm (ORCPT ); Fri, 21 Aug 2020 07:52:42 -0400 Received: from mail-pj1-x1042.google.com (mail-pj1-x1042.google.com [IPv6:2607:f8b0:4864:20::1042]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 87D53C061344 for ; Fri, 21 Aug 2020 04:52:03 -0700 (PDT) Received: by mail-pj1-x1042.google.com with SMTP id q93so839725pjq.0 for ; Fri, 21 Aug 2020 04:52:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=jVO9lyuEURDCJ19hMM4wSddhgvERqr+utebc1E3NsxE=; b=tXneKQ9qNoFCkq5r+w5u4qyeYlhduagfuC+L++SM1tVOHTMwDhydotudDq36ziVDtk /y2EF2+w53xCemiinx/410QJHBzxl8qs096Xp8V7apJyLCVY0QqScJ9CRk7EBbxnQIWJ 8nFbEH4ErWGsLGRIIZvZdrki4/sGGegFnnzY5XNdx0c7d9h+qZYWkgGFr3wbWup69suV 6Py/xR+kxIdyfTmGkg9OPWm2a5GuNkm86qQ6P3ZF0OSkTUF4FXzZf/mFE79M8PYAksb7 Xs9wL1qOGgIJ5khgFbuN/bYxd7lgv1XBs66GDKtvGXZ1D+02t+06RF2aoVp1FzovZ15L QaQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=jVO9lyuEURDCJ19hMM4wSddhgvERqr+utebc1E3NsxE=; b=RKFD28Dm4PJ5ft+3cM5tDy3Mk3OuTgT49MqQkZsR3svNMax/RjQLAJPAlhyh4JC3yj vth20r0I38ZUhhNIBPbFHrzlx8GmIHKptDRlJa34T/8U0L87aqfeuw21s+bNTED11EDY MQ3BCgxMQCHRcuxmF8FL1tvb3vYJyDpENt+VIjoog2TsRLI24nvDL4ejbPDC07N3HL2n sNszDk4dptAJNP8TVuzqfeiuLz9fRwPE/6V33wkudD8SPoUmWOz2t3DzDVMA2LcdxbyY 3LvvPRmUYfP6MAk4fl4znJ3BIi3z4sM5itA96ZTJpBM78q8TOzB3UduBsB3B4NhfhK6E BArQ== X-Gm-Message-State: AOAM532ZiO2DTiQj+IVWKt24+LVqtTx0HfbgT19wo48hNfR+rbbRM5wd VtNlE7cYGNZnStVMeJO3eNOMUADdH+c= X-Google-Smtp-Source: ABdhPJwXwj1+G00Hb9HEPxTRyAIfy/nizLnpbjeOcmqhsXpgQH5H4k0Lc+AcItV8399eEZqCHcG2hg== X-Received: by 2002:a17:902:7293:: with SMTP id d19mr2093786pll.303.1598010722632; Fri, 21 Aug 2020 04:52:02 -0700 (PDT) Received: from localhost.localdomain ([2402:800:63a8:cb7a:1eb1:40a4:f50c:706e]) by smtp.gmail.com with ESMTPSA id y1sm2300413pfl.136.2020.08.21.04.52.00 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Aug 2020 04:52:01 -0700 (PDT) From: =?utf-8?b?xJBvw6BuIFRy4bqnbiBDw7RuZyBEYW5o?= To: git@vger.kernel.org Cc: =?utf-8?b?xJBvw6BuIFRy4bqnbiBDw7RuZyBEYW5o?= , =?utf-8?q?SZEDER_G=C3=A1bor?= , "brian m . carlson" , Junio C Hamano , Jeff King Subject: [PATCH v5 2/2] diff: index-line: respect --abbrev in object's name Date: Fri, 21 Aug 2020 18:51:47 +0700 Message-Id: X-Mailer: git-send-email 2.28.0.143.g760df7782d.dirty In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org A handful of Git's commands respect `--abbrev' for customizing length of abbreviation of object names. For diff-family, Git supports 2 different options for 2 different purposes, `--full-index' for showing diff-patch object's name in full, and `--abbrev' to customize the length of object names in diff-raw and diff-tree header lines, without any options to customise the length of object names in diff-patch format. When working with diff-patch format, we only have two options, either full index, or default abbrev length. Although, that behaviour is documented, it doesn't stop users from trying to use `--abbrev' with the hope of customising diff-patch's objects' name's abbreviation. Let's allow the blob object names shown on the "index" line to be abbreviated to arbitrary length given via the "--abbrev" option. To preserve backward compatibility with old script that specify both `--full-index' and `--abbrev', always show full object id if `--full-index' is specified. Signed-off-by: Đoàn Trần Công Danh --- Documentation/diff-options.txt | 9 +++--- diff.c | 5 +++- t/t4013-diff-various.sh | 3 ++ ...ff.diff-tree_--root_-p_--abbrev=10_initial | 29 +++++++++++++++++++ ...--root_-p_--full-index_--abbrev=10_initial | 29 +++++++++++++++++++ ...f.diff-tree_--root_-p_--full-index_initial | 29 +++++++++++++++++++ 6 files changed, 99 insertions(+), 5 deletions(-) create mode 100644 t/t4013/diff.diff-tree_--root_-p_--abbrev=10_initial create mode 100644 t/t4013/diff.diff-tree_--root_-p_--full-index_--abbrev=10_initial create mode 100644 t/t4013/diff.diff-tree_--root_-p_--full-index_initial diff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt index b7af973d9c..573fb9bb71 100644 --- a/Documentation/diff-options.txt +++ b/Documentation/diff-options.txt @@ -446,10 +446,11 @@ endif::git-format-patch[] --abbrev[=]:: Instead of showing the full 40-byte hexadecimal object name in diff-raw format output and diff-tree header - lines, show only a partial prefix. This is - independent of the `--full-index` option above, which controls - the diff-patch output format. Non default number of - digits can be specified with `--abbrev=`. + lines, show only a partial prefix. + In diff-patch output format, `--full-index` takes higher + precedence, i.e. if `--full-index` is specified, full blob + names will be shown regardless of `--abbrev`. + Non default number of digits can be specified with `--abbrev=`. -B[][/]:: --break-rewrites[=[][/]]:: diff --git a/diff.c b/diff.c index f9709de7b4..20dedfe2a9 100644 --- a/diff.c +++ b/diff.c @@ -4319,7 +4319,10 @@ static void fill_metainfo(struct strbuf *msg, } if (one && two && !oideq(&one->oid, &two->oid)) { const unsigned hexsz = the_hash_algo->hexsz; - int abbrev = o->flags.full_index ? hexsz : DEFAULT_ABBREV; + int abbrev = o->abbrev ? o->abbrev : DEFAULT_ABBREV; + + if (o->flags.full_index) + abbrev = hexsz; if (o->flags.binary) { mmfile_t mf; diff --git a/t/t4013-diff-various.sh b/t/t4013-diff-various.sh index f6bdfc13fd..5c7b0122b4 100755 --- a/t/t4013-diff-various.sh +++ b/t/t4013-diff-various.sh @@ -239,6 +239,9 @@ diff-tree --root -r --abbrev=4 initial :noellipses diff-tree --root -r --abbrev=4 initial diff-tree -p initial diff-tree --root -p initial +diff-tree --root -p --abbrev=10 initial +diff-tree --root -p --full-index initial +diff-tree --root -p --full-index --abbrev=10 initial diff-tree --patch-with-stat initial diff-tree --root --patch-with-stat initial diff-tree --patch-with-raw initial diff --git a/t/t4013/diff.diff-tree_--root_-p_--abbrev=10_initial b/t/t4013/diff.diff-tree_--root_-p_--abbrev=10_initial new file mode 100644 index 0000000000..7518a9044e --- /dev/null +++ b/t/t4013/diff.diff-tree_--root_-p_--abbrev=10_initial @@ -0,0 +1,29 @@ +$ git diff-tree --root -p --abbrev=10 initial +444ac553ac7612cc88969031b02b3767fb8a353a +diff --git a/dir/sub b/dir/sub +new file mode 100644 +index 0000000000..35d242ba79 +--- /dev/null ++++ b/dir/sub +@@ -0,0 +1,2 @@ ++A ++B +diff --git a/file0 b/file0 +new file mode 100644 +index 0000000000..01e79c32a8 +--- /dev/null ++++ b/file0 +@@ -0,0 +1,3 @@ ++1 ++2 ++3 +diff --git a/file2 b/file2 +new file mode 100644 +index 0000000000..01e79c32a8 +--- /dev/null ++++ b/file2 +@@ -0,0 +1,3 @@ ++1 ++2 ++3 +$ diff --git a/t/t4013/diff.diff-tree_--root_-p_--full-index_--abbrev=10_initial b/t/t4013/diff.diff-tree_--root_-p_--full-index_--abbrev=10_initial new file mode 100644 index 0000000000..69f913fbe5 --- /dev/null +++ b/t/t4013/diff.diff-tree_--root_-p_--full-index_--abbrev=10_initial @@ -0,0 +1,29 @@ +$ git diff-tree --root -p --full-index --abbrev=10 initial +444ac553ac7612cc88969031b02b3767fb8a353a +diff --git a/dir/sub b/dir/sub +new file mode 100644 +index 0000000000000000000000000000000000000000..35d242ba79ae89ac695e26b3d4c27a8e6f028f9e +--- /dev/null ++++ b/dir/sub +@@ -0,0 +1,2 @@ ++A ++B +diff --git a/file0 b/file0 +new file mode 100644 +index 0000000000000000000000000000000000000000..01e79c32a8c99c557f0757da7cb6d65b3414466d +--- /dev/null ++++ b/file0 +@@ -0,0 +1,3 @@ ++1 ++2 ++3 +diff --git a/file2 b/file2 +new file mode 100644 +index 0000000000000000000000000000000000000000..01e79c32a8c99c557f0757da7cb6d65b3414466d +--- /dev/null ++++ b/file2 +@@ -0,0 +1,3 @@ ++1 ++2 ++3 +$ diff --git a/t/t4013/diff.diff-tree_--root_-p_--full-index_initial b/t/t4013/diff.diff-tree_--root_-p_--full-index_initial new file mode 100644 index 0000000000..1b0b6717fa --- /dev/null +++ b/t/t4013/diff.diff-tree_--root_-p_--full-index_initial @@ -0,0 +1,29 @@ +$ git diff-tree --root -p --full-index initial +444ac553ac7612cc88969031b02b3767fb8a353a +diff --git a/dir/sub b/dir/sub +new file mode 100644 +index 0000000000000000000000000000000000000000..35d242ba79ae89ac695e26b3d4c27a8e6f028f9e +--- /dev/null ++++ b/dir/sub +@@ -0,0 +1,2 @@ ++A ++B +diff --git a/file0 b/file0 +new file mode 100644 +index 0000000000000000000000000000000000000000..01e79c32a8c99c557f0757da7cb6d65b3414466d +--- /dev/null ++++ b/file0 +@@ -0,0 +1,3 @@ ++1 ++2 ++3 +diff --git a/file2 b/file2 +new file mode 100644 +index 0000000000000000000000000000000000000000..01e79c32a8c99c557f0757da7cb6d65b3414466d +--- /dev/null ++++ b/file2 +@@ -0,0 +1,3 @@ ++1 ++2 ++3 +$