From: "SZEDER Gábor" <szeder.dev@gmail.com>
To: "Đoàn Trần Công Danh" <congdanhqx@gmail.com>
Cc: git@vger.kernel.org, Junio C Hamano <gitster@pobox.com>,
Jeff King <peff@peff.net>
Subject: Re: [PATCH v3 2/2] diff: index-line: respect --abbrev in object's name
Date: Fri, 14 Aug 2020 17:18:15 +0200 [thread overview]
Message-ID: <20200814151815.GA29528@szeder.dev> (raw)
In-Reply-To: <760df7782dad9e9df7bb284ec57249e697a4cc92.1597364493.git.congdanhqx@gmail.com>
On Fri, Aug 14, 2020 at 07:23:10AM +0700, Đoàn Trần Công Danh wrote:
> 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 consistent 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 resolve that inconsistency.
>
> To preserve backward compatibility with old script that specify both
> `--full-index' and `--abbrev', always shows full object id
> if `--full-index' is specified.
>
> Signed-off-by: Đoàn Trần Công Danh <congdanhqx@gmail.com>
> ---
> 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 7987d72b02..c11efa7865 100644
> --- a/Documentation/diff-options.txt
> +++ b/Documentation/diff-options.txt
> @@ -441,10 +441,11 @@ endif::git-format-patch[]
> --abbrev[=<n>]::
> 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=<n>`.
> + lines, show only a partial prefix.
> + In diff-patch output format, `--full-index` takes higher
> + precedent, 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=<n>`.
>
> -B[<n>][/<m>]::
> --break-rewrites[=[<n>][/<m>]]::
> 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 3f60f7d96c..e6eb4dd4c7 100755
> --- a/t/t4013-diff-various.sh
> +++ b/t/t4013-diff-various.sh
> @@ -221,6 +221,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
> +$
All these new tests break when run with GIT_TEST_DEFAULT_HASH=sha256
with something like:
+ test_cmp expect actual
--- expect 2020-08-14 15:05:12.209285397 +0000
+++ actual 2020-08-14 15:05:12.205285279 +0000
@@ -2,7 +2,7 @@
0000000000000000000000000000000000000000000000000000000000000000
diff --git a/dir/sub b/dir/sub
new file mode ffff44
-index ffffffffff..fffffffa79
+index ffffffffff..fffffff895
--- /dev/null
+++ b/dir/sub
@@ -0,0 +1,2 @@
@@ -10,7 +10,7 @@
+B
diff --git a/file0 b/file0
new file mode ffff44
-index ffffffffff..fffffff2a8
+index ffffffffff..fffffff5d7
--- /dev/null
+++ b/file0
@@ -0,0 +1,3 @@
@@ -19,7 +19,7 @@
+3
diff --git a/file2 b/file2
new file mode ffff44
-index ffffffffff..fffffff2a8
+index ffffffffff..fffffff5d7
--- /dev/null
+++ b/file2
@@ -0,0 +1,3 @@
error: last command exited with $?=1
next prev parent reply other threads:[~2020-08-14 15:18 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-09 2:19 [RFC PATCH 0/2] extend --abbrev support to diff-patch format Đoàn Trần Công Danh
2020-08-09 2:19 ` [RFC PATCH 1/2] revision: differentiate if --no-abbrev asked explicitly Đoàn Trần Công Danh
2020-08-09 2:19 ` [RFC PATCH 2/2] diff: extend --abbrev support to diff-patch format Đoàn Trần Công Danh
2020-08-09 19:01 ` [RFC PATCH 0/2] " Junio C Hamano
2020-08-10 10:00 ` Jeff King
2020-08-10 12:31 ` Đoàn Trần Công Danh
2020-08-10 15:15 ` Junio C Hamano
2020-08-10 15:27 ` Jeff King
2020-08-11 0:33 ` Đoàn Trần Công Danh
2020-08-11 5:22 ` Jeff King
2020-08-11 12:07 ` Đoàn Trần Công Danh
2020-08-10 15:06 ` Junio C Hamano
2020-08-11 11:49 ` [PATCH v2 0/2] diff: index-line: respect --abbrev in object's name Đoàn Trần Công Danh
2020-08-11 11:49 ` [PATCH v2 1/2] revision: differentiate if --no-abbrev asked explicitly Đoàn Trần Công Danh
2020-08-11 18:54 ` Junio C Hamano
2020-08-11 11:49 ` [PATCH v2 2/2] diff: index-line: respect --abbrev in object's name Đoàn Trần Công Danh
2020-08-14 0:23 ` [PATCH v3 0/2] " Đoàn Trần Công Danh
2020-08-14 0:23 ` [PATCH v3 1/2] revision: differentiate if --no-abbrev asked explicitly Đoàn Trần Công Danh
2020-08-14 0:50 ` Junio C Hamano
2020-08-14 0:59 ` Đoàn Trần Công Danh
2020-08-14 1:06 ` Junio C Hamano
2020-08-14 14:50 ` Đoàn Trần Công Danh
2020-08-19 22:50 ` Junio C Hamano
2020-08-14 0:23 ` [PATCH v3 2/2] diff: index-line: respect --abbrev in object's name Đoàn Trần Công Danh
2020-08-14 15:18 ` SZEDER Gábor [this message]
2020-08-14 17:00 ` Junio C Hamano
2020-08-14 18:59 ` Junio C Hamano
2020-08-15 0:21 ` brian m. carlson
2020-08-15 2:27 ` Đoàn Trần Công Danh
2020-08-17 16:17 ` Junio C Hamano
2020-08-20 4:56 ` Junio C Hamano
2020-08-20 12:35 ` [PATCH v4 0/2] " Đoàn Trần Công Danh
2020-08-20 12:35 ` [PATCH v4 1/2] t4013: improve diff-post-processor logic Đoàn Trần Công Danh
2020-08-20 19:49 ` Junio C Hamano
2020-08-21 12:05 ` Đoàn Trần Công Danh
2020-08-21 15:44 ` Junio C Hamano
2020-08-20 12:35 ` [PATCH v4 2/2] diff: index-line: respect --abbrev in object's name Đoàn Trần Công Danh
2020-08-20 19:58 ` Junio C Hamano
2020-08-21 11:51 ` [PATCH v5 0/2] " Đoàn Trần Công Danh
2020-08-21 11:51 ` [PATCH v5 1/2] t4013: improve diff-post-processor logic Đoàn Trần Công Danh
2020-08-21 11:51 ` [PATCH v5 2/2] diff: index-line: respect --abbrev in object's name Đoàn Trần Công Danh
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200814151815.GA29528@szeder.dev \
--to=szeder.dev@gmail.com \
--cc=congdanhqx@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=peff@peff.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).