Add log.abbrevCommit config variable
Add log.abbrevCommit config variable as a convenience for users who often use --abbrev-commit with git log and friends. Allow the option to be overridden with --no-abbrev-commit. Per 635530a2fc and 4f62c2bc57, the config variable is ignored when log is given "--pretty=raw". (Also, a drive-by spelling correction in git log's short help.) Signed-off-by: Jay Soffian <jaysoffian@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jay Soffian committed
May 18, 2011 at 13:56 UTC
0c47695a69da42df4c4b7a9dad4ba083c604e3d1
6 files changed
+84
-8
Documentation/config.txt
+5
@@ -1315,6 +1315,11 @@ interactive.singlekey::
1315
setting is silently ignored if portable keystroke input
1316
is not available.
1317
1318
+log.abbrevCommit::
1319
+ If true, makes linkgit:git-log[1], linkgit:git-show[1], and
1320
+ linkgit:git-whatchanged[1] assume `\--abbrev-commit`. You may
1321
+ override this option with `\--no-abbrev-commit`.
1322
+
1323
log.date::
1324
Set the default date-time mode for the 'log' command.
1325
Setting a value for log.date is similar to using 'git log''s
Documentation/pretty-options.txt
+5
@@ -19,6 +19,11 @@ configuration (see linkgit:git-config[1]).
19
This should make "--pretty=oneline" a whole lot more readable for
20
people using 80-column terminals.
21
22
+--no-abbrev-commit::
23
+ Show the full 40-byte hexadecimal commit object name. This negates
24
+ `--abbrev-commit` and those options which imply it such as
25
+ "--oneline". It also overrides the 'log.abbrevCommit' variable.
26
+
27
--oneline::
28
This is a shorthand for "--pretty=oneline --abbrev-commit"
29
used together.
builtin/log.c
+17
-8
@@ -23,6 +23,7 @@
23
/* Set a default date-time format for git log ("log.date" config variable) */
24
static const char *default_date_mode = NULL;
25
26
+static int default_abbrev_commit;
27
static int default_show_root = 1;
28
static int decoration_style;
29
static int decoration_given;
@@ -77,6 +78,7 @@ static void cmd_log_init_defaults(struct rev_info *rev)
78
get_commit_format(fmt_pretty, rev);
79
rev->verbose_header = 1;
80
DIFF_OPT_SET(&rev->diffopt, RECURSIVE);
81
+ rev->abbrev_commit = default_abbrev_commit;
82
rev->show_root_diff = default_show_root;
83
rev->subject_prefix = fmt_patch_subject_prefix;
84
DIFF_OPT_SET(&rev->diffopt, ALLOW_TEXTCONV);
@@ -129,13 +131,16 @@ static void cmd_log_init_finish(int argc, const char **argv, const char *prefix,
131
if (source)
132
rev->show_source = 1;
133
132
- /*
133
- * defeat log.decorate configuration interacting with --pretty=raw
134
- * from the command line.
135
- */
136
- if (!decoration_given && rev->pretty_given
137
- && rev->commit_format == CMIT_FMT_RAW)
138
- decoration_style = 0;
134
+ if (rev->pretty_given && rev->commit_format == CMIT_FMT_RAW) {
135
+ /*
136
+ * "log --pretty=raw" is special; ignore UI oriented
137
+ * configuration variables such as decoration.
138
+ */
139
+ if (!decoration_given)
140
+ decoration_style = 0;
141
+ if (!rev->abbrev_commit_given)
142
+ rev->abbrev_commit = 0;
143
+ }
144
145
if (decoration_style) {
146
rev->show_decorations = 1;
@@ -323,6 +328,10 @@ static int git_log_config(const char *var, const char *value, void *cb)
328
return git_config_string(&fmt_pretty, var, value);
329
if (!strcmp(var, "format.subjectprefix"))
330
return git_config_string(&fmt_patch_subject_prefix, var, value);
331
+ if (!strcmp(var, "log.abbrevcommit")) {
332
+ default_abbrev_commit = git_config_bool(var, value);
333
+ return 0;
334
+ }
335
if (!strcmp(var, "log.date"))
336
return git_config_string(&default_date_mode, var, value);
337
if (!strcmp(var, "log.decorate")) {
@@ -516,11 +525,11 @@ int cmd_log_reflog(int argc, const char **argv, const char *prefix)
525
526
init_revisions(&rev, prefix);
527
init_reflog_walk(&rev.reflog_info);
519
- rev.abbrev_commit = 1;
528
rev.verbose_header = 1;
529
memset(&opt, 0, sizeof(opt));
530
opt.def = "HEAD";
531
cmd_log_init_defaults(&rev);
532
+ rev.abbrev_commit = 1;
533
rev.commit_format = CMIT_FMT_ONELINE;
534
rev.use_terminator = 1;
535
rev.always_show_header = 1;
revision.c
+3
@@ -1429,6 +1429,9 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
1429
revs->abbrev = 40;
1430
} else if (!strcmp(arg, "--abbrev-commit")) {
1431
revs->abbrev_commit = 1;
1432
+ revs->abbrev_commit_given = 1;
1433
+ } else if (!strcmp(arg, "--no-abbrev-commit")) {
1434
+ revs->abbrev_commit = 0;
1435
} else if (!strcmp(arg, "--full-diff")) {
1436
revs->diff = 1;
1437
revs->full_diff = 1;
revision.h
+1
@@ -90,6 +90,7 @@ struct rev_info {
90
show_notes_given:1,
91
pretty_given:1,
92
abbrev_commit:1,
93
+ abbrev_commit_given:1,
94
use_terminator:1,
95
missing_newline:1,
96
date_mode_explicit:1;
t/t4202-log.sh
+53
@@ -448,6 +448,59 @@ test_expect_success 'log.decorate configuration' '
448
git log --oneline --decorate >actual &&
449
test_cmp expect.short actual
450
451
+ git config --unset-all log.decorate &&
452
+ git log --pretty=raw >expect.raw &&
453
+ git config log.decorate full &&
454
+ git log --pretty=raw >actual &&
455
+ test_cmp expect.raw actual
456
+
457
+'
458
+
459
+test_expect_success 'reflog is expected format' '
460
+ test_might_fail git config --remove-section log &&
461
+ git log -g --abbrev-commit --pretty=oneline >expect &&
462
+ git reflog >actual &&
463
+ test_cmp expect actual
464
+'
465
+
466
+test_expect_success 'whatchanged is expected format' '
467
+ git log --no-merges --raw >expect &&
468
+ git whatchanged >actual &&
469
+ test_cmp expect actual
470
+'
471
+
472
+test_expect_success 'log.abbrevCommit configuration' '
473
+ test_when_finished "git config --unset log.abbrevCommit" &&
474
+
475
+ test_might_fail git config --unset log.abbrevCommit &&
476
+
477
+ git log --abbrev-commit >expect.log.abbrev &&
478
+ git log --no-abbrev-commit >expect.log.full &&
479
+ git log --pretty=raw >expect.log.raw &&
480
+ git reflog --abbrev-commit >expect.reflog.abbrev &&
481
+ git reflog --no-abbrev-commit >expect.reflog.full &&
482
+ git whatchanged --abbrev-commit >expect.whatchanged.abbrev &&
483
+ git whatchanged --no-abbrev-commit >expect.whatchanged.full &&
484
+
485
+ git config log.abbrevCommit true &&
486
+
487
+ git log >actual &&
488
+ test_cmp expect.log.abbrev actual &&
489
+ git log --no-abbrev-commit >actual &&
490
+ test_cmp expect.log.full actual &&
491
+
492
+ git log --pretty=raw >actual &&
493
+ test_cmp expect.log.raw actual &&
494
+
495
+ git reflog >actual &&
496
+ test_cmp expect.reflog.abbrev actual &&
497
+ git reflog --no-abbrev-commit >actual &&
498
+ test_cmp expect.reflog.full actual &&
499
+
500
+ git whatchanged >actual &&
501
+ test_cmp expect.whatchanged.abbrev actual &&
502
+ git whatchanged --no-abbrev-commit >actual &&
503
+ test_cmp expect.whatchanged.full actual
504
'
505
506
test_expect_success 'show added path under "--follow -M"' '