diff: index-line: respect --abbrev in object's name
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 <congdanhqx@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Đoàn Trần Công Danh committedAug 21, 2020 at 18:51 UTC3046c7f69a6337a971b219d047b8110e3f9ea971
6 files changed+90-5
Documentation/diff-options.txt
+5-4
index 7987d72b02..de3f16b3e9 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+ 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=<n>`. -B[<n>][/<m>]:: --break-rewrites[=[<n>][/<m>]]::
diff.c
+4-1
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;