diff options
author | Phil Hord <phil.hord@gmail.com> | 2017-11-21 15:43:36 -0800 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2017-11-22 14:03:32 +0900 |
commit | a82fa292c366cfff4a88b8a2d2697e848317c3d9 (patch) | |
tree | 50dfbb73cf33cbd2fb828260a5df5aef5a0758f9 | |
parent | 95a731ce92c7576d927f0d8a9b27c206cb58c2e6 (diff) | |
download | git-a82fa292c366cfff4a88b8a2d2697e848317c3d9.tar.gz |
defer expensive load_ref_decorations until needed
With many thousands of references, a simple `git rev-parse HEAD` may take
more than a second to return because it first loads all the refs into
memory even though it will never use them.
Defer loading any references until we actually need them.
Signed-off-by: Phil Hord <phil.hord@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r-- | log-tree.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/log-tree.c b/log-tree.c index 580b3a98a0..fe970ce804 100644 --- a/log-tree.c +++ b/log-tree.c @@ -84,8 +84,10 @@ void add_name_decoration(enum decoration_type type, const char *name, struct obj res->next = add_decoration(&name_decoration, obj, res); } +static void maybe_load_ref_decorations(); const struct name_decoration *get_name_decoration(const struct object *obj) { + maybe_load_ref_decorations(); return lookup_decoration(&name_decoration, obj); } @@ -150,10 +152,13 @@ static int add_graft_decoration(const struct commit_graft *graft, void *cb_data) void load_ref_decorations(int flags) { - if (!decoration_loaded) { + decoration_flags = flags; +} +static void maybe_load_ref_decorations() +{ + if (!decoration_loaded) { decoration_loaded = 1; - decoration_flags = flags; for_each_ref(add_ref_decoration, NULL); head_ref(add_ref_decoration, NULL); for_each_commit_graft(add_graft_decoration, NULL); |