Skip to content

Commit b2086b5

Browse files
peffgitster
authored andcommitted
log: avoid loading decorations for userformats that don't need it
If no --decorate option is given, we default to auto-decoration. And when that kicks in, cmd_log_init_finish() will unconditionally load the decoration refs. However, if we are using a user-format that does not include "%d" or "%D", we won't show the decorations at all, so we don't need to load them. We can detect this case and auto-disable them by adding a new field to our userformat_want helper. We can do this even when the user explicitly asked for --decorate, because it can't affect the output at all. This patch consistently reduces the time to run "git log -1 --format=%H" on my git.git clone (with ~2k refs) from 34ms to 7ms. On a much more extreme real-world repository (with ~220k refs), it goes from 2.5s to 4ms. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3c7e2e8 commit b2086b5

File tree

3 files changed

+8
-0
lines changed

3 files changed

+8
-0
lines changed

builtin/log.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,9 @@ 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;
250+
248251
if (decoration_style) {
249252
const struct string_list *config_exclude =
250253
repo_config_get_value_multi(the_repository,

pretty.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1735,6 +1735,10 @@ static size_t userformat_want_item(struct strbuf *sb, const char *placeholder,
17351735
case 'S':
17361736
w->source = 1;
17371737
break;
1738+
case 'd':
1739+
case 'D':
1740+
w->decorate = 1;
1741+
break;
17381742
}
17391743
return 0;
17401744
}

pretty.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ static inline int cmit_fmt_is_mail(enum cmit_fmt fmt)
7373
struct userformat_want {
7474
unsigned notes:1;
7575
unsigned source:1;
76+
unsigned decorate:1;
7677
};
7778
void userformat_find_requirements(const char *fmt, struct userformat_want *w);
7879

0 commit comments

Comments
 (0)