Skip to content

Commit be73860

Browse files
peffgitster
authored andcommitted
log: load decorations with --simplify-by-decoration
It's possible to specify --simplify-by-decoration but not --decorate. In this case we do respect the simplification, but we don't actually show any decorations. However, it works by lazy-loading the decorations when needed; this is discussed in more detail in 0cc7380 (log-tree: call load_ref_decorations() in get_name_decoration(), 2019-09-08). This works for basic cases, but will fail to respect any --decorate-refs option (or its variants). Those are handled only when cmd_log_init() loads the ref decorations up front, which is only when --decorate is specified explicitly (or as of the previous commit, when the userformat asks for %d or similar). We can solve this by making sure to load the decorations if we're going to simplify using them but they're not otherwise going to be displayed. The new test shows a simple case that fails without this patch. Note that we expect two commits in the output: the one we asked for by --decorate-refs, and the initial commit. The latter is just a quirk of how --simplify-by-decoration works. Arguably it may be a bug, but it's unrelated to this patch (which is just about the loading of the decorations; you get the same behavior before this patch with an explicit --decorate). Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 14b9c2b commit be73860

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

builtin/log.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ static void cmd_log_init_finish(int argc, const char **argv, const char *prefix,
262262
}
263263
}
264264

265-
if (decoration_style) {
265+
if (decoration_style || rev->simplify_by_decoration) {
266266
const struct string_list *config_exclude =
267267
repo_config_get_value_multi(the_repository,
268268
"log.excludeDecoration");
@@ -274,7 +274,8 @@ static void cmd_log_init_finish(int argc, const char **argv, const char *prefix,
274274
item->string);
275275
}
276276

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

279280
load_ref_decorations(&decoration_filter, decoration_style);
280281
}

t/t4202-log.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -974,6 +974,21 @@ test_expect_success 'implied decorate does not override option' '
974974
test_cmp expect actual
975975
'
976976

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+
977992
test_expect_success 'log.decorate config parsing' '
978993
git log --oneline --decorate=full >expect.full &&
979994
git log --oneline --decorate=short >expect.short &&

0 commit comments

Comments
 (0)