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"
This commit is contained in:
Junio C Hamano 2021-12-21 15:03:15 -08:00
Родитель 57f28f4094 be73860793
Коммит 00cbaf9362
2 изменённых файлов: 56 добавлений и 4 удалений

Просмотреть файл

@ -245,10 +245,24 @@ static void cmd_log_init_finish(int argc, const char **argv, const char *prefix,
rev->abbrev_commit = 0;
}
if (rev->commit_format == CMIT_FMT_USERFORMAT && !w.decorate)
decoration_style = 0;
if (rev->commit_format == CMIT_FMT_USERFORMAT) {
if (!w.decorate) {
/*
* Disable decoration loading if the format will not
* show them anyway.
*/
decoration_style = 0;
} else if (!decoration_style) {
/*
* If we are going to show them, make sure we do load
* them here, but taking care not to override a
* specific style set by config or --decorate.
*/
decoration_style = DECORATE_SHORT_REFS;
}
}
if (decoration_style) {
if (decoration_style || rev->simplify_by_decoration) {
const struct string_list *config_exclude =
repo_config_get_value_multi(the_repository,
"log.excludeDecoration");
@ -260,7 +274,8 @@ static void cmd_log_init_finish(int argc, const char **argv, const char *prefix,
item->string);
}
rev->show_decorations = 1;
if (decoration_style)
rev->show_decorations = 1;
load_ref_decorations(&decoration_filter, decoration_style);
}

Просмотреть файл

@ -952,6 +952,43 @@ test_expect_success 'decorate-refs-exclude and simplify-by-decoration' '
test_cmp expect.decorate actual
'
test_expect_success 'decorate-refs with implied decorate from format' '
cat >expect <<-\EOF &&
side-2 (tag: side-2)
side-1
EOF
git log --no-walk --format="%s%d" \
--decorate-refs="*side-2" side-1 side-2 \
>actual &&
test_cmp expect actual
'
test_expect_success 'implied decorate does not override option' '
cat >expect <<-\EOF &&
side-2 (tag: refs/tags/side-2, refs/heads/side)
side-1 (tag: refs/tags/side-1)
EOF
git log --no-walk --format="%s%d" \
--decorate=full side-1 side-2 \
>actual &&
test_cmp expect actual
'
test_expect_success 'decorate-refs and simplify-by-decoration without output' '
cat >expect <<-\EOF &&
side-2
initial
EOF
# Do not just use a --format without %d here; we want to
# make sure that we did not accidentally turn on displaying
# the decorations, too. And that requires one of the regular
# formats.
git log --decorate-refs="*side-2" --oneline \
--simplify-by-decoration >actual.raw &&
sed "s/^[0-9a-f]* //" <actual.raw >actual &&
test_cmp expect actual
'
test_expect_success 'log.decorate config parsing' '
git log --oneline --decorate=full >expect.full &&
git log --oneline --decorate=short >expect.short &&