Skip to content

Commit

Permalink
Add log.abbrevCommit config variable
Browse files Browse the repository at this point in the history
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 635530a and 4f62c2b,
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>
  • Loading branch information
Jay Soffian authored and Junio C Hamano committed May 18, 2011
1 parent f0f90e3 commit 0c47695
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 8 deletions.
5 changes: 5 additions & 0 deletions Documentation/config.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1315,6 +1315,11 @@ interactive.singlekey::
setting is silently ignored if portable keystroke input
is not available.

log.abbrevCommit::
If true, makes linkgit:git-log[1], linkgit:git-show[1], and
linkgit:git-whatchanged[1] assume `\--abbrev-commit`. You may
override this option with `\--no-abbrev-commit`.

log.date::
Set the default date-time mode for the 'log' command.
Setting a value for log.date is similar to using 'git log''s
Expand Down
5 changes: 5 additions & 0 deletions Documentation/pretty-options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ configuration (see linkgit:git-config[1]).
This should make "--pretty=oneline" a whole lot more readable for
people using 80-column terminals.

--no-abbrev-commit::
Show the full 40-byte hexadecimal commit object name. This negates
`--abbrev-commit` and those options which imply it such as
"--oneline". It also overrides the 'log.abbrevCommit' variable.

--oneline::
This is a shorthand for "--pretty=oneline --abbrev-commit"
used together.
Expand Down
25 changes: 17 additions & 8 deletions builtin/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
/* Set a default date-time format for git log ("log.date" config variable) */
static const char *default_date_mode = NULL;

static int default_abbrev_commit;
static int default_show_root = 1;
static int decoration_style;
static int decoration_given;
Expand Down Expand Up @@ -77,6 +78,7 @@ static void cmd_log_init_defaults(struct rev_info *rev)
get_commit_format(fmt_pretty, rev);
rev->verbose_header = 1;
DIFF_OPT_SET(&rev->diffopt, RECURSIVE);
rev->abbrev_commit = default_abbrev_commit;
rev->show_root_diff = default_show_root;
rev->subject_prefix = fmt_patch_subject_prefix;
DIFF_OPT_SET(&rev->diffopt, ALLOW_TEXTCONV);
Expand Down Expand Up @@ -129,13 +131,16 @@ static void cmd_log_init_finish(int argc, const char **argv, const char *prefix,
if (source)
rev->show_source = 1;

/*
* defeat log.decorate configuration interacting with --pretty=raw
* from the command line.
*/
if (!decoration_given && rev->pretty_given
&& rev->commit_format == CMIT_FMT_RAW)
decoration_style = 0;
if (rev->pretty_given && rev->commit_format == CMIT_FMT_RAW) {
/*
* "log --pretty=raw" is special; ignore UI oriented
* configuration variables such as decoration.
*/
if (!decoration_given)
decoration_style = 0;
if (!rev->abbrev_commit_given)
rev->abbrev_commit = 0;
}

if (decoration_style) {
rev->show_decorations = 1;
Expand Down Expand Up @@ -323,6 +328,10 @@ static int git_log_config(const char *var, const char *value, void *cb)
return git_config_string(&fmt_pretty, var, value);
if (!strcmp(var, "format.subjectprefix"))
return git_config_string(&fmt_patch_subject_prefix, var, value);
if (!strcmp(var, "log.abbrevcommit")) {
default_abbrev_commit = git_config_bool(var, value);
return 0;
}
if (!strcmp(var, "log.date"))
return git_config_string(&default_date_mode, var, value);
if (!strcmp(var, "log.decorate")) {
Expand Down Expand Up @@ -516,11 +525,11 @@ int cmd_log_reflog(int argc, const char **argv, const char *prefix)

init_revisions(&rev, prefix);
init_reflog_walk(&rev.reflog_info);
rev.abbrev_commit = 1;
rev.verbose_header = 1;
memset(&opt, 0, sizeof(opt));
opt.def = "HEAD";
cmd_log_init_defaults(&rev);
rev.abbrev_commit = 1;
rev.commit_format = CMIT_FMT_ONELINE;
rev.use_terminator = 1;
rev.always_show_header = 1;
Expand Down
3 changes: 3 additions & 0 deletions revision.c
Original file line number Diff line number Diff line change
Expand Up @@ -1429,6 +1429,9 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
revs->abbrev = 40;
} else if (!strcmp(arg, "--abbrev-commit")) {
revs->abbrev_commit = 1;
revs->abbrev_commit_given = 1;
} else if (!strcmp(arg, "--no-abbrev-commit")) {
revs->abbrev_commit = 0;
} else if (!strcmp(arg, "--full-diff")) {
revs->diff = 1;
revs->full_diff = 1;
Expand Down
1 change: 1 addition & 0 deletions revision.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ struct rev_info {
show_notes_given:1,
pretty_given:1,
abbrev_commit:1,
abbrev_commit_given:1,
use_terminator:1,
missing_newline:1,
date_mode_explicit:1;
Expand Down
53 changes: 53 additions & 0 deletions t/t4202-log.sh
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,59 @@ test_expect_success 'log.decorate configuration' '
git log --oneline --decorate >actual &&
test_cmp expect.short actual
git config --unset-all log.decorate &&
git log --pretty=raw >expect.raw &&
git config log.decorate full &&
git log --pretty=raw >actual &&
test_cmp expect.raw actual
'

test_expect_success 'reflog is expected format' '
test_might_fail git config --remove-section log &&
git log -g --abbrev-commit --pretty=oneline >expect &&
git reflog >actual &&
test_cmp expect actual
'

test_expect_success 'whatchanged is expected format' '
git log --no-merges --raw >expect &&
git whatchanged >actual &&
test_cmp expect actual
'

test_expect_success 'log.abbrevCommit configuration' '
test_when_finished "git config --unset log.abbrevCommit" &&
test_might_fail git config --unset log.abbrevCommit &&
git log --abbrev-commit >expect.log.abbrev &&
git log --no-abbrev-commit >expect.log.full &&
git log --pretty=raw >expect.log.raw &&
git reflog --abbrev-commit >expect.reflog.abbrev &&
git reflog --no-abbrev-commit >expect.reflog.full &&
git whatchanged --abbrev-commit >expect.whatchanged.abbrev &&
git whatchanged --no-abbrev-commit >expect.whatchanged.full &&
git config log.abbrevCommit true &&
git log >actual &&
test_cmp expect.log.abbrev actual &&
git log --no-abbrev-commit >actual &&
test_cmp expect.log.full actual &&
git log --pretty=raw >actual &&
test_cmp expect.log.raw actual &&
git reflog >actual &&
test_cmp expect.reflog.abbrev actual &&
git reflog --no-abbrev-commit >actual &&
test_cmp expect.reflog.full actual &&
git whatchanged >actual &&
test_cmp expect.whatchanged.abbrev actual &&
git whatchanged --no-abbrev-commit >actual &&
test_cmp expect.whatchanged.full actual
'

test_expect_success 'show added path under "--follow -M"' '
Expand Down

0 comments on commit 0c47695

Please sign in to comment.