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 <gitster@pobox.com>
Junio C Hamano committed
Apr 6, 2010 at 14:48 UTC
635530a2fcd4bb3714452403f341f1317ae9c9f6
2 files changed
+39
-16
builtin-log.c
+11
@@ -53,6 +53,7 @@ static void cmd_log_init(int argc, const char **argv, const char *prefix,
53
struct rev_info *rev)
54
{
55
int i;
56
+ int decoration_given = 0;
57
58
rev->abbrev = DEFAULT_ABBREV;
59
rev->commit_format = CMIT_FMT_DEFAULT;
@@ -89,11 +90,13 @@ static void cmd_log_init(int argc, const char **argv, const char *prefix,
90
const char *arg = argv[i];
91
if (!strcmp(arg, "--decorate")) {
92
decoration_style = DECORATE_SHORT_REFS;
93
+ decoration_given = 1;
94
} else if (!prefixcmp(arg, "--decorate=")) {
95
const char *v = skip_prefix(arg, "--decorate=");
96
decoration_style = parse_decoration_style(arg, v);
97
if (decoration_style < 0)
98
die("invalid --decorate option: %s", arg);
99
+ decoration_given = 1;
100
} else if (!strcmp(arg, "--no-decorate")) {
101
decoration_style = 0;
102
} else if (!strcmp(arg, "--source")) {
@@ -103,6 +106,14 @@ static void cmd_log_init(int argc, const char **argv, const char *prefix,
106
} else
107
die("unrecognized argument: %s", arg);
108
}
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
+
117
if (decoration_style) {
118
rev->show_decorations = 1;
119
load_ref_decorations(decoration_style);
t/t4202-log.sh
+28
-16
@@ -390,50 +390,62 @@ test_expect_success 'log --graph with merge' '
390
test_expect_success 'log.decorate configuration' '
391
git config --unset-all log.decorate || :
392
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 &&
397
398
echo "[log] decorate" >>.git/config &&
398
- git log --oneline >actual &&
399
+ git log >actual &&
400
test_cmp expect.short actual &&
401
+ git log --oneline >actual &&
402
+ test_cmp expect.oneline actual &&
403
404
git config --unset-all log.decorate &&
405
git config log.decorate true &&
403
- git log --oneline >actual &&
406
+ git log >actual &&
407
test_cmp expect.short actual &&
405
- git log --oneline --decorate=full >actual &&
408
+ git log --decorate=full >actual &&
409
test_cmp expect.full actual &&
407
- git log --oneline --decorate=no >actual &&
410
+ git log --decorate=no >actual &&
411
test_cmp expect.none actual &&
412
+ git log --oneline >actual &&
413
+ test_cmp expect.oneline actual &&
414
415
git config --unset-all log.decorate &&
416
git config log.decorate no &&
412
- git log --oneline >actual &&
417
+ git log >actual &&
418
test_cmp expect.none actual &&
414
- git log --oneline --decorate >actual &&
419
+ git log --decorate >actual &&
420
test_cmp expect.short actual &&
416
- git log --oneline --decorate=full >actual &&
421
+ git log --decorate=full >actual &&
422
test_cmp expect.full actual &&
423
+ git log --oneline >actual &&
424
+ test_cmp expect.oneline actual &&
425
426
git config --unset-all log.decorate &&
427
git config log.decorate short &&
421
- git log --oneline >actual &&
428
+ git log >actual &&
429
test_cmp expect.short actual &&
423
- git log --oneline --no-decorate >actual &&
430
+ git log --no-decorate >actual &&
431
test_cmp expect.none actual &&
425
- git log --oneline --decorate=full >actual &&
432
+ git log --decorate=full >actual &&
433
test_cmp expect.full actual &&
434
+ git log --oneline >actual &&
435
+ test_cmp expect.oneline actual &&
436
437
git config --unset-all log.decorate &&
438
git config log.decorate full &&
430
- git log --oneline >actual &&
439
+ git log >actual &&
440
test_cmp expect.full actual &&
432
- git log --oneline --no-decorate >actual &&
441
+ git log --no-decorate >actual &&
442
test_cmp expect.none actual &&
434
- git log --oneline --decorate >actual &&
443
+ git log --decorate >actual &&
444
test_cmp expect.short actual
445
+ git log --oneline >actual &&
446
+ test_cmp expect.oneline actual &&
447
448
+ :
449
'
450
451
test_done