Skip to content

Commit 635530a

Browse files
committed
log --pretty/--oneline: ignore log.decorate
Many scripts, most notably gitk, rely on output from the log family of command not to be molested by random user configuration. This is especially true when --pretty=raw is given. Just like we disable notes output unless the command line explicitly asks for --show-notes, disable the decoration code unless --decorate is given explicitly from the command line and --pretty or --oneline is given. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8a3d203 commit 635530a

File tree

2 files changed

+39
-16
lines changed

2 files changed

+39
-16
lines changed

builtin-log.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ static void cmd_log_init(int argc, const char **argv, const char *prefix,
5353
struct rev_info *rev)
5454
{
5555
int i;
56+
int decoration_given = 0;
5657

5758
rev->abbrev = DEFAULT_ABBREV;
5859
rev->commit_format = CMIT_FMT_DEFAULT;
@@ -89,11 +90,13 @@ static void cmd_log_init(int argc, const char **argv, const char *prefix,
8990
const char *arg = argv[i];
9091
if (!strcmp(arg, "--decorate")) {
9192
decoration_style = DECORATE_SHORT_REFS;
93+
decoration_given = 1;
9294
} else if (!prefixcmp(arg, "--decorate=")) {
9395
const char *v = skip_prefix(arg, "--decorate=");
9496
decoration_style = parse_decoration_style(arg, v);
9597
if (decoration_style < 0)
9698
die("invalid --decorate option: %s", arg);
99+
decoration_given = 1;
97100
} else if (!strcmp(arg, "--no-decorate")) {
98101
decoration_style = 0;
99102
} else if (!strcmp(arg, "--source")) {
@@ -103,6 +106,14 @@ static void cmd_log_init(int argc, const char **argv, const char *prefix,
103106
} else
104107
die("unrecognized argument: %s", arg);
105108
}
109+
110+
/*
111+
* defeat log.decorate configuration interacting with --pretty
112+
* from the command line.
113+
*/
114+
if (!decoration_given && rev->pretty_given)
115+
decoration_style = 0;
116+
106117
if (decoration_style) {
107118
rev->show_decorations = 1;
108119
load_ref_decorations(decoration_style);

t/t4202-log.sh

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -390,50 +390,62 @@ test_expect_success 'log --graph with merge' '
390390
test_expect_success 'log.decorate configuration' '
391391
git config --unset-all log.decorate || :
392392
393-
git log --oneline >expect.none &&
394-
git log --oneline --decorate >expect.short &&
395-
git log --oneline --decorate=full >expect.full &&
393+
git log >expect.none &&
394+
git log --decorate >expect.short &&
395+
git log --decorate=full >expect.full &&
396+
git log --oneline >expect.oneline &&
396397
397398
echo "[log] decorate" >>.git/config &&
398-
git log --oneline >actual &&
399+
git log >actual &&
399400
test_cmp expect.short actual &&
401+
git log --oneline >actual &&
402+
test_cmp expect.oneline actual &&
400403
401404
git config --unset-all log.decorate &&
402405
git config log.decorate true &&
403-
git log --oneline >actual &&
406+
git log >actual &&
404407
test_cmp expect.short actual &&
405-
git log --oneline --decorate=full >actual &&
408+
git log --decorate=full >actual &&
406409
test_cmp expect.full actual &&
407-
git log --oneline --decorate=no >actual &&
410+
git log --decorate=no >actual &&
408411
test_cmp expect.none actual &&
412+
git log --oneline >actual &&
413+
test_cmp expect.oneline actual &&
409414
410415
git config --unset-all log.decorate &&
411416
git config log.decorate no &&
412-
git log --oneline >actual &&
417+
git log >actual &&
413418
test_cmp expect.none actual &&
414-
git log --oneline --decorate >actual &&
419+
git log --decorate >actual &&
415420
test_cmp expect.short actual &&
416-
git log --oneline --decorate=full >actual &&
421+
git log --decorate=full >actual &&
417422
test_cmp expect.full actual &&
423+
git log --oneline >actual &&
424+
test_cmp expect.oneline actual &&
418425
419426
git config --unset-all log.decorate &&
420427
git config log.decorate short &&
421-
git log --oneline >actual &&
428+
git log >actual &&
422429
test_cmp expect.short actual &&
423-
git log --oneline --no-decorate >actual &&
430+
git log --no-decorate >actual &&
424431
test_cmp expect.none actual &&
425-
git log --oneline --decorate=full >actual &&
432+
git log --decorate=full >actual &&
426433
test_cmp expect.full actual &&
434+
git log --oneline >actual &&
435+
test_cmp expect.oneline actual &&
427436
428437
git config --unset-all log.decorate &&
429438
git config log.decorate full &&
430-
git log --oneline >actual &&
439+
git log >actual &&
431440
test_cmp expect.full actual &&
432-
git log --oneline --no-decorate >actual &&
441+
git log --no-decorate >actual &&
433442
test_cmp expect.none actual &&
434-
git log --oneline --decorate >actual &&
443+
git log --decorate >actual &&
435444
test_cmp expect.short actual
445+
git log --oneline >actual &&
446+
test_cmp expect.oneline actual &&
436447
448+
:
437449
'
438450

439451
test_done

0 commit comments

Comments
 (0)