range-diff: let '--abbrev' option takes effect
As mentioned in 'git-range-diff.txt': "`git range-diff` also accepts the
regular diff options (see linkgit:git-diff[1])...", but '--abbrev' is not
in the "regular" scope.
In Git, the "abbrev" of an object may not be a fixed value in different
repositories, depending on the needs of the them(Linus mentioned in
e6c587c7
in 2016: "the Linux kernel project needs 11 to 12 hexdigits"
at that time ), that's why a user may want to display abbrev according
to a specified length.
Although a similar effect can be achieved through configuration (like:
git -c core.abbrev=<abbrev>), but based on ease of use (many users may not
know that the -c option can be specified) and the description in existing
document, supporting users to directly use '--abbrev', could be a good way.
Signed-off-by: Teng Long <dyroneteng@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
d9d677b2d8
commit
2b15969f61
11
range-diff.c
11
range-diff.c
@ -383,11 +383,14 @@ static void output_pair_header(struct diff_options *diffopt,
|
||||
const char *color_new = diff_get_color_opt(diffopt, DIFF_FILE_NEW);
|
||||
const char *color_commit = diff_get_color_opt(diffopt, DIFF_COMMIT);
|
||||
const char *color;
|
||||
char abbrev = diffopt->abbrev;
|
||||
|
||||
if (abbrev < 0)
|
||||
abbrev = DEFAULT_ABBREV;
|
||||
|
||||
if (!dashes->len)
|
||||
strbuf_addchars(dashes, '-',
|
||||
strlen(find_unique_abbrev(oid,
|
||||
DEFAULT_ABBREV)));
|
||||
strlen(find_unique_abbrev(oid, abbrev)));
|
||||
|
||||
if (!b_util) {
|
||||
color = color_old;
|
||||
@ -409,7 +412,7 @@ static void output_pair_header(struct diff_options *diffopt,
|
||||
strbuf_addf(buf, "%*s: %s ", patch_no_width, "-", dashes->buf);
|
||||
else
|
||||
strbuf_addf(buf, "%*d: %s ", patch_no_width, a_util->i + 1,
|
||||
find_unique_abbrev(&a_util->oid, DEFAULT_ABBREV));
|
||||
find_unique_abbrev(&a_util->oid, abbrev));
|
||||
|
||||
if (status == '!')
|
||||
strbuf_addf(buf, "%s%s", color_reset, color);
|
||||
@ -421,7 +424,7 @@ static void output_pair_header(struct diff_options *diffopt,
|
||||
strbuf_addf(buf, " %*s: %s", patch_no_width, "-", dashes->buf);
|
||||
else
|
||||
strbuf_addf(buf, " %*d: %s", patch_no_width, b_util->i + 1,
|
||||
find_unique_abbrev(&b_util->oid, DEFAULT_ABBREV));
|
||||
find_unique_abbrev(&b_util->oid, abbrev));
|
||||
|
||||
commit = lookup_commit_reference(the_repository, oid);
|
||||
if (commit) {
|
||||
|
Reference in New Issue
Block a user