From d68dc34cb41c30515e64766c303c2930994e5085 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bj=C3=B6rn=20Steinbrink?= Date: Thu, 6 Aug 2009 14:15:14 +0200 Subject: [PATCH] git-describe: Die early if there are no possible descriptions MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit If we find no refs that may be used for git-describe with the current options, then die early instead of pointlessly walking the whole history. In git.git with all the tags dropped, this makes "git describe" go down from 0.244 to 0.003 seconds for me. This is especially noticeable with "git submodule status" which calls describe with increasing levels of allowed refs to be matched. For a submodule without tags, this means that it walks the whole history in the submodule twice (first annotated, then plain tags), just to find out that it can't describe the commit anyway. Signed-off-by: Björn Steinbrink Signed-off-by: Junio C Hamano --- builtin-describe.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/builtin-describe.c b/builtin-describe.c index 7a662980d1..df67a733ae 100644 --- a/builtin-describe.c +++ b/builtin-describe.c @@ -20,6 +20,7 @@ static int tags; /* Allow lightweight tags */ static int longformat; static int abbrev = DEFAULT_ABBREV; static int max_candidates = 10; +static int found_names; static const char *pattern; static int always; @@ -49,6 +50,7 @@ static void add_to_known_names(const char *path, memcpy(e->path, path, len); commit->util = e; } + found_names = 1; } static int get_name(const char *path, const unsigned char *sha1, int flag, void *cb_data) @@ -195,6 +197,9 @@ static void describe(const char *arg, int last_one) for_each_ref(get_name, NULL); } + if (!found_names) + die("cannot describe '%s'", sha1_to_hex(sha1)); + n = cmit->util; if (n) { /* -- 2.11.4.GIT