Skip to content

Commit 72d9b22

Browse files
committed
Merge branch 'sd/log-decorate'
* sd/log-decorate: log.decorate: only ignore it under "log --pretty=raw" script with rev-list instead of log log --pretty/--oneline: ignore log.decorate log.decorate: usability fixes Add `log.decorate' configuration variable. git_config_maybe_bool() Conflicts: builtin/log.c
2 parents e251a7b + 4f62c2b commit 72d9b22

File tree

8 files changed

+118
-13
lines changed

8 files changed

+118
-13
lines changed

Documentation/config.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,6 +1270,13 @@ log.date::
12701270
following alternatives: {relative,local,default,iso,rfc,short}.
12711271
See linkgit:git-log[1].
12721272

1273+
log.decorate::
1274+
Print out the ref names of any commits that are shown by the log
1275+
command. If 'short' is specified, the ref name prefixes 'refs/heads/',
1276+
'refs/tags/' and 'refs/remotes/' will not be printed. If 'full' is
1277+
specified, the full ref name (including prefix) will be printed.
1278+
This is the same as the log commands '--decorate' option.
1279+
12731280
log.showroot::
12741281
If true, the initial commit will be shown as a big creation event.
12751282
This is equivalent to a diff against an empty tree.

Documentation/git-log.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ include::diff-options.txt[]
3737
and <until>, see "SPECIFYING REVISIONS" section in
3838
linkgit:git-rev-parse[1].
3939

40-
--decorate[=short|full]::
40+
--no-decorate::
41+
--decorate[=short|full|no]::
4142
Print out the ref names of any commits that are shown. If 'short' is
4243
specified, the ref name prefixes 'refs/heads/', 'refs/tags/' and
4344
'refs/remotes/' will not be printed. If 'full' is specified, the

builtin/log.c

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,36 @@
2424
static const char *default_date_mode = NULL;
2525

2626
static int default_show_root = 1;
27+
static int decoration_style;
2728
static const char *fmt_patch_subject_prefix = "PATCH";
2829
static const char *fmt_pretty;
2930

3031
static const char * const builtin_log_usage =
3132
"git log [<options>] [<since>..<until>] [[--] <path>...]\n"
3233
" or: git show [options] <object>...";
3334

35+
static int parse_decoration_style(const char *var, const char *value)
36+
{
37+
switch (git_config_maybe_bool(var, value)) {
38+
case 1:
39+
return DECORATE_SHORT_REFS;
40+
case 0:
41+
return 0;
42+
default:
43+
break;
44+
}
45+
if (!strcmp(value, "full"))
46+
return DECORATE_FULL_REFS;
47+
else if (!strcmp(value, "short"))
48+
return DECORATE_SHORT_REFS;
49+
return -1;
50+
}
51+
3452
static void cmd_log_init(int argc, const char **argv, const char *prefix,
3553
struct rev_info *rev, struct setup_revision_opt *opt)
3654
{
3755
int i;
38-
int decoration_style = 0;
56+
int decoration_given = 0;
3957
struct userformat_want w;
4058

4159
rev->abbrev = DEFAULT_ABBREV;
@@ -78,21 +96,31 @@ static void cmd_log_init(int argc, const char **argv, const char *prefix,
7896
const char *arg = argv[i];
7997
if (!strcmp(arg, "--decorate")) {
8098
decoration_style = DECORATE_SHORT_REFS;
99+
decoration_given = 1;
81100
} else if (!prefixcmp(arg, "--decorate=")) {
82101
const char *v = skip_prefix(arg, "--decorate=");
83-
if (!strcmp(v, "full"))
84-
decoration_style = DECORATE_FULL_REFS;
85-
else if (!strcmp(v, "short"))
86-
decoration_style = DECORATE_SHORT_REFS;
87-
else
102+
decoration_style = parse_decoration_style(arg, v);
103+
if (decoration_style < 0)
88104
die("invalid --decorate option: %s", arg);
105+
decoration_given = 1;
106+
} else if (!strcmp(arg, "--no-decorate")) {
107+
decoration_style = 0;
89108
} else if (!strcmp(arg, "--source")) {
90109
rev->show_source = 1;
91110
} else if (!strcmp(arg, "-h")) {
92111
usage(builtin_log_usage);
93112
} else
94113
die("unrecognized argument: %s", arg);
95114
}
115+
116+
/*
117+
* defeat log.decorate configuration interacting with --pretty=raw
118+
* from the command line.
119+
*/
120+
if (!decoration_given && rev->pretty_given
121+
&& rev->commit_format == CMIT_FMT_RAW)
122+
decoration_style = 0;
123+
96124
if (decoration_style) {
97125
rev->show_decorations = 1;
98126
load_ref_decorations(decoration_style);
@@ -258,6 +286,12 @@ static int git_log_config(const char *var, const char *value, void *cb)
258286
return git_config_string(&fmt_patch_subject_prefix, var, value);
259287
if (!strcmp(var, "log.date"))
260288
return git_config_string(&default_date_mode, var, value);
289+
if (!strcmp(var, "log.decorate")) {
290+
decoration_style = parse_decoration_style(var, value);
291+
if (decoration_style < 0)
292+
decoration_style = 0; /* maybe warn? */
293+
return 0;
294+
}
261295
if (!strcmp(var, "log.showroot")) {
262296
default_show_root = git_config_bool(var, value);
263297
return 0;

cache.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -944,6 +944,7 @@ extern int git_config_int(const char *, const char *);
944944
extern unsigned long git_config_ulong(const char *, const char *);
945945
extern int git_config_bool_or_int(const char *, const char *, int *);
946946
extern int git_config_bool(const char *, const char *);
947+
extern int git_config_maybe_bool(const char *, const char *);
947948
extern int git_config_string(const char **, const char *, const char *);
948949
extern int git_config_pathname(const char **, const char *, const char *);
949950
extern int git_config_set(const char *, const char *);

config.c

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -322,17 +322,30 @@ unsigned long git_config_ulong(const char *name, const char *value)
322322
return ret;
323323
}
324324

325-
int git_config_bool_or_int(const char *name, const char *value, int *is_bool)
325+
int git_config_maybe_bool(const char *name, const char *value)
326326
{
327-
*is_bool = 1;
328327
if (!value)
329328
return 1;
330329
if (!*value)
331330
return 0;
332-
if (!strcasecmp(value, "true") || !strcasecmp(value, "yes") || !strcasecmp(value, "on"))
331+
if (!strcasecmp(value, "true")
332+
|| !strcasecmp(value, "yes")
333+
|| !strcasecmp(value, "on"))
333334
return 1;
334-
if (!strcasecmp(value, "false") || !strcasecmp(value, "no") || !strcasecmp(value, "off"))
335+
if (!strcasecmp(value, "false")
336+
|| !strcasecmp(value, "no")
337+
|| !strcasecmp(value, "off"))
335338
return 0;
339+
return -1;
340+
}
341+
342+
int git_config_bool_or_int(const char *name, const char *value, int *is_bool)
343+
{
344+
int v = git_config_maybe_bool(name, value);
345+
if (0 <= v) {
346+
*is_bool = 1;
347+
return v;
348+
}
336349
*is_bool = 0;
337350
return git_config_int(name, value);
338351
}

git-stash.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ create_stash () {
5757
# state of the base commit
5858
if b_commit=$(git rev-parse --verify HEAD)
5959
then
60-
head=$(git log --no-color --abbrev-commit --pretty=oneline -n 1 HEAD --)
60+
head=$(git rev-list --oneline -n 1 HEAD --)
6161
else
6262
die "You do not have the initial commit yet"
6363
fi

git-submodule.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ cmd_summary() {
650650
range=$sha1_dst
651651
fi
652652
GIT_DIR="$name/.git" \
653-
git log --pretty=oneline --first-parent $range | wc -l
653+
git rev-list --first-parent $range -- | wc -l
654654
)
655655
total_commits=" ($(($total_commits + 0)))"
656656
;;

t/t4202-log.sh

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,5 +387,54 @@ test_expect_success 'log --graph with merge' '
387387
test_cmp expect actual
388388
'
389389

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 &&
396+
397+
echo "[log] decorate" >>.git/config &&
398+
git log --oneline >actual &&
399+
test_cmp expect.short actual &&
400+
401+
git config --unset-all log.decorate &&
402+
git config log.decorate true &&
403+
git log --oneline >actual &&
404+
test_cmp expect.short actual &&
405+
git log --oneline --decorate=full >actual &&
406+
test_cmp expect.full actual &&
407+
git log --oneline --decorate=no >actual &&
408+
test_cmp expect.none actual &&
409+
410+
git config --unset-all log.decorate &&
411+
git config log.decorate no &&
412+
git log --oneline >actual &&
413+
test_cmp expect.none actual &&
414+
git log --oneline --decorate >actual &&
415+
test_cmp expect.short actual &&
416+
git log --oneline --decorate=full >actual &&
417+
test_cmp expect.full actual &&
418+
419+
git config --unset-all log.decorate &&
420+
git config log.decorate short &&
421+
git log --oneline >actual &&
422+
test_cmp expect.short actual &&
423+
git log --oneline --no-decorate >actual &&
424+
test_cmp expect.none actual &&
425+
git log --oneline --decorate=full >actual &&
426+
test_cmp expect.full actual &&
427+
428+
git config --unset-all log.decorate &&
429+
git config log.decorate full &&
430+
git log --oneline >actual &&
431+
test_cmp expect.full actual &&
432+
git log --oneline --no-decorate >actual &&
433+
test_cmp expect.none actual &&
434+
git log --oneline --decorate >actual &&
435+
test_cmp expect.short actual
436+
437+
'
438+
390439
test_done
391440

0 commit comments

Comments
 (0)