Skip to content

Commit

Permalink
git-describe: Die early if there are no possible descriptions
Browse files Browse the repository at this point in the history
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 <B.Steinbrink@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Björn Steinbrink authored and Junio C Hamano committed Aug 6, 2009
1 parent 4cfbe06 commit d68dc34
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions builtin-describe.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
/*
Expand Down

0 comments on commit d68dc34

Please sign in to comment.