Skip to content

Commit 00cbaf9

Browse files
committed
Merge branch 'jk/log-decorate-opts-with-implicit-decorate'
When "git log" implicitly enabled the "decoration" processing without being explicitly asked with "--decorate" option, it failed to read and honor the settings given by the "--decorate-refs" option. * jk/log-decorate-opts-with-implicit-decorate: log: load decorations with --simplify-by-decoration log: handle --decorate-refs with userformat "%d"
2 parents 57f28f4 + be73860 commit 00cbaf9

File tree

2 files changed

+56
-4
lines changed

2 files changed

+56
-4
lines changed

builtin/log.c

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -245,10 +245,24 @@ static void cmd_log_init_finish(int argc, const char **argv, const char *prefix,
245245
rev->abbrev_commit = 0;
246246
}
247247

248-
if (rev->commit_format == CMIT_FMT_USERFORMAT && !w.decorate)
249-
decoration_style = 0;
248+
if (rev->commit_format == CMIT_FMT_USERFORMAT) {
249+
if (!w.decorate) {
250+
/*
251+
* Disable decoration loading if the format will not
252+
* show them anyway.
253+
*/
254+
decoration_style = 0;
255+
} else if (!decoration_style) {
256+
/*
257+
* If we are going to show them, make sure we do load
258+
* them here, but taking care not to override a
259+
* specific style set by config or --decorate.
260+
*/
261+
decoration_style = DECORATE_SHORT_REFS;
262+
}
263+
}
250264

251-
if (decoration_style) {
265+
if (decoration_style || rev->simplify_by_decoration) {
252266
const struct string_list *config_exclude =
253267
repo_config_get_value_multi(the_repository,
254268
"log.excludeDecoration");
@@ -260,7 +274,8 @@ static void cmd_log_init_finish(int argc, const char **argv, const char *prefix,
260274
item->string);
261275
}
262276

263-
rev->show_decorations = 1;
277+
if (decoration_style)
278+
rev->show_decorations = 1;
264279

265280
load_ref_decorations(&decoration_filter, decoration_style);
266281
}

t/t4202-log.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -952,6 +952,43 @@ test_expect_success 'decorate-refs-exclude and simplify-by-decoration' '
952952
test_cmp expect.decorate actual
953953
'
954954

955+
test_expect_success 'decorate-refs with implied decorate from format' '
956+
cat >expect <<-\EOF &&
957+
side-2 (tag: side-2)
958+
side-1
959+
EOF
960+
git log --no-walk --format="%s%d" \
961+
--decorate-refs="*side-2" side-1 side-2 \
962+
>actual &&
963+
test_cmp expect actual
964+
'
965+
966+
test_expect_success 'implied decorate does not override option' '
967+
cat >expect <<-\EOF &&
968+
side-2 (tag: refs/tags/side-2, refs/heads/side)
969+
side-1 (tag: refs/tags/side-1)
970+
EOF
971+
git log --no-walk --format="%s%d" \
972+
--decorate=full side-1 side-2 \
973+
>actual &&
974+
test_cmp expect actual
975+
'
976+
977+
test_expect_success 'decorate-refs and simplify-by-decoration without output' '
978+
cat >expect <<-\EOF &&
979+
side-2
980+
initial
981+
EOF
982+
# Do not just use a --format without %d here; we want to
983+
# make sure that we did not accidentally turn on displaying
984+
# the decorations, too. And that requires one of the regular
985+
# formats.
986+
git log --decorate-refs="*side-2" --oneline \
987+
--simplify-by-decoration >actual.raw &&
988+
sed "s/^[0-9a-f]* //" <actual.raw >actual &&
989+
test_cmp expect actual
990+
'
991+
955992
test_expect_success 'log.decorate config parsing' '
956993
git log --oneline --decorate=full >expect.full &&
957994
git log --oneline --decorate=short >expect.short &&

0 commit comments

Comments
 (0)