Skip to content

Commit 84da3e2

Browse files
committed
Merge branch 'js/log-abbrev-commit-config'
* js/log-abbrev-commit-config: Add log.abbrevCommit config variable "git log -h": typofix misspelled 'suppress'
2 parents 6741c2e + 0c47695 commit 84da3e2

File tree

6 files changed

+85
-9
lines changed

6 files changed

+85
-9
lines changed

Documentation/config.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1315,6 +1315,11 @@ interactive.singlekey::
13151315
setting is silently ignored if portable keystroke input
13161316
is not available.
13171317

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+
13181323
log.date::
13191324
Set the default date-time mode for the 'log' command.
13201325
Setting a value for log.date is similar to using 'git log''s

Documentation/pretty-options.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ configuration (see linkgit:git-config[1]).
1919
This should make "--pretty=oneline" a whole lot more readable for
2020
people using 80-column terminals.
2121

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+
2227
--oneline::
2328
This is a shorthand for "--pretty=oneline --abbrev-commit"
2429
used together.

builtin/log.c

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
/* Set a default date-time format for git log ("log.date" config variable) */
2424
static const char *default_date_mode = NULL;
2525

26+
static int default_abbrev_commit;
2627
static int default_show_root = 1;
2728
static int decoration_style;
2829
static int decoration_given;
@@ -77,6 +78,7 @@ static void cmd_log_init_defaults(struct rev_info *rev)
7778
get_commit_format(fmt_pretty, rev);
7879
rev->verbose_header = 1;
7980
DIFF_OPT_SET(&rev->diffopt, RECURSIVE);
81+
rev->abbrev_commit = default_abbrev_commit;
8082
rev->show_root_diff = default_show_root;
8183
rev->subject_prefix = fmt_patch_subject_prefix;
8284
DIFF_OPT_SET(&rev->diffopt, ALLOW_TEXTCONV);
@@ -92,7 +94,7 @@ static void cmd_log_init_finish(int argc, const char **argv, const char *prefix,
9294
int quiet = 0, source = 0;
9395

9496
const struct option builtin_log_options[] = {
95-
OPT_BOOLEAN(0, "quiet", &quiet, "supress diff output"),
97+
OPT_BOOLEAN(0, "quiet", &quiet, "suppress diff output"),
9698
OPT_BOOLEAN(0, "source", &source, "show source"),
9799
{ OPTION_CALLBACK, 0, "decorate", NULL, NULL, "decorate options",
98100
PARSE_OPT_OPTARG, decorate_callback},
@@ -129,13 +131,16 @@ static void cmd_log_init_finish(int argc, const char **argv, const char *prefix,
129131
if (source)
130132
rev->show_source = 1;
131133

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+
}
139144

140145
if (decoration_style) {
141146
rev->show_decorations = 1;
@@ -323,6 +328,10 @@ static int git_log_config(const char *var, const char *value, void *cb)
323328
return git_config_string(&fmt_pretty, var, value);
324329
if (!strcmp(var, "format.subjectprefix"))
325330
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+
}
326335
if (!strcmp(var, "log.date"))
327336
return git_config_string(&default_date_mode, var, value);
328337
if (!strcmp(var, "log.decorate")) {
@@ -516,11 +525,11 @@ int cmd_log_reflog(int argc, const char **argv, const char *prefix)
516525

517526
init_revisions(&rev, prefix);
518527
init_reflog_walk(&rev.reflog_info);
519-
rev.abbrev_commit = 1;
520528
rev.verbose_header = 1;
521529
memset(&opt, 0, sizeof(opt));
522530
opt.def = "HEAD";
523531
cmd_log_init_defaults(&rev);
532+
rev.abbrev_commit = 1;
524533
rev.commit_format = CMIT_FMT_ONELINE;
525534
rev.use_terminator = 1;
526535
rev.always_show_header = 1;

revision.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1428,6 +1428,9 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
14281428
revs->abbrev = 40;
14291429
} else if (!strcmp(arg, "--abbrev-commit")) {
14301430
revs->abbrev_commit = 1;
1431+
revs->abbrev_commit_given = 1;
1432+
} else if (!strcmp(arg, "--no-abbrev-commit")) {
1433+
revs->abbrev_commit = 0;
14311434
} else if (!strcmp(arg, "--full-diff")) {
14321435
revs->diff = 1;
14331436
revs->full_diff = 1;

revision.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ struct rev_info {
9090
show_notes_given:1,
9191
pretty_given:1,
9292
abbrev_commit:1,
93+
abbrev_commit_given:1,
9394
use_terminator:1,
9495
missing_newline:1,
9596
date_mode_explicit:1;

t/t4202-log.sh

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,59 @@ test_expect_success 'log.decorate configuration' '
448448
git log --oneline --decorate >actual &&
449449
test_cmp expect.short actual
450450
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
451504
'
452505

453506
test_expect_success 'show added path under "--follow -M"' '

0 commit comments

Comments
 (0)