Skip to content
This repository was archived by the owner on Mar 1, 2019. It is now read-only.

Commit d68dc34

Browse files
dotdashgitster
authored andcommitted
git-describe: Die early if there are no possible descriptions
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4cfbe06 commit d68dc34

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

builtin-describe.c

+5
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ static int tags; /* Allow lightweight tags */
2020
static int longformat;
2121
static int abbrev = DEFAULT_ABBREV;
2222
static int max_candidates = 10;
23+
static int found_names;
2324
static const char *pattern;
2425
static int always;
2526

@@ -49,6 +50,7 @@ static void add_to_known_names(const char *path,
4950
memcpy(e->path, path, len);
5051
commit->util = e;
5152
}
53+
found_names = 1;
5254
}
5355

5456
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)
195197
for_each_ref(get_name, NULL);
196198
}
197199

200+
if (!found_names)
201+
die("cannot describe '%s'", sha1_to_hex(sha1));
202+
198203
n = cmit->util;
199204
if (n) {
200205
/*

0 commit comments

Comments
 (0)