Skip to content

Commit 9da5c2f

Browse files
author
Junio C Hamano
committed
rev-list: default to abbreviate merge parent names under --pretty.
When we prettyprint commit log messages, merge parent names were often very long and there was no way to abbreviate it. This changes them to be abbreviated by default, and non-default abbreviations can be specified with --no-abbrev or --abbrev=<n> options. Note that this affects only the prettyprinted parent names. The output from --show-parents is meant for machine consumption and is not affected by this flag.
1 parent 39556fb commit 9da5c2f

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

rev-list.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ static const char rev_list_usage[] =
3232
" --objects\n"
3333
" --unpacked\n"
3434
" --header | --pretty\n"
35+
" --abbrev=nr | --no-abbrev\n"
3536
" special purpose:\n"
3637
" --bisect"
3738
;
@@ -43,6 +44,7 @@ static int tag_objects = 0;
4344
static int tree_objects = 0;
4445
static int blob_objects = 0;
4546
static int verbose_header = 0;
47+
static int abbrev = DEFAULT_ABBREV;
4648
static int show_parents = 0;
4749
static int hdr_termination = 0;
4850
static const char *commit_prefix = "";
@@ -96,7 +98,7 @@ static void show_commit(struct commit *commit)
9698

9799
if (verbose_header) {
98100
static char pretty_header[16384];
99-
pretty_print_commit(commit_format, commit, ~0, pretty_header, sizeof(pretty_header), 0);
101+
pretty_print_commit(commit_format, commit, ~0, pretty_header, sizeof(pretty_header), abbrev);
100102
printf("%s%c", pretty_header, hdr_termination);
101103
}
102104
fflush(stdout);
@@ -795,6 +797,18 @@ int main(int argc, const char **argv)
795797
verbose_header = 1;
796798
continue;
797799
}
800+
if (!strcmp(arg, "--no-abbrev")) {
801+
abbrev = 0;
802+
continue;
803+
}
804+
if (!strncmp(arg, "--abbrev=", 9)) {
805+
abbrev = strtoul(arg + 9, NULL, 10);
806+
if (abbrev && abbrev < MINIMUM_ABBREV)
807+
abbrev = MINIMUM_ABBREV;
808+
else if (40 < abbrev)
809+
abbrev = 40;
810+
continue;
811+
}
798812
if (!strncmp(arg, "--pretty", 8)) {
799813
commit_format = get_commit_format(arg+8);
800814
verbose_header = 1;

0 commit comments

Comments
 (0)