]> git.ipfire.org Git - thirdparty/git.git/commitdiff
log: avoid loading decorations for userformats that don't need it
authorJeff King <peff@peff.net>
Tue, 22 Jun 2021 16:04:50 +0000 (12:04 -0400)
committerJunio C Hamano <gitster@pobox.com>
Tue, 29 Jun 2021 03:30:17 +0000 (20:30 -0700)
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 <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/log.c
pretty.c
pretty.h

index 6102893fccb96cf2203b524664c3b2c88c84d9b1..6ba7f207264b8dc90078550be203c4779a2b320f 100644 (file)
@@ -245,6 +245,9 @@ 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 (decoration_style) {
                const struct string_list *config_exclude =
                        repo_config_get_value_multi(the_repository,
index b1ecd039cef29ecc77edd894c500dfadf49058c8..9631529c10a072a21acb76d65545d61a80b337d4 100644 (file)
--- a/pretty.c
+++ b/pretty.c
@@ -1735,6 +1735,10 @@ static size_t userformat_want_item(struct strbuf *sb, const char *placeholder,
        case 'S':
                w->source = 1;
                break;
+       case 'd':
+       case 'D':
+               w->decorate = 1;
+               break;
        }
        return 0;
 }
index c81cf40d387b95592b7ce9f895d70c75e687f34d..2f16acd213d6d70c6055472f4f4d6b0e3e4b6f9e 100644 (file)
--- a/pretty.h
+++ b/pretty.h
@@ -73,6 +73,7 @@ static inline int cmit_fmt_is_mail(enum cmit_fmt fmt)
 struct userformat_want {
        unsigned notes:1;
        unsigned source:1;
+       unsigned decorate:1;
 };
 void userformat_find_requirements(const char *fmt, struct userformat_want *w);