git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Björn Steinbrink" <B.Steinbrink@gmx.de>
To: "Shawn O. Pearce" <spearce@spearce.org>
Cc: Junio C Hamano <gitster@pobox.com>, git@vger.kernel.org
Subject: [PATCH v2] git-describe: Die early if there are no possible descriptions
Date: Thu, 6 Aug 2009 14:15:14 +0200	[thread overview]
Message-ID: <20090806121514.GA1701@atjola.homenet> (raw)
In-Reply-To: <20090805154205.GA17792@atjola.homenet>

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>
---
v2 improved the commit message and turned found_names into a boolean,
instead of a counter for the found names.

 builtin-describe.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/builtin-describe.c b/builtin-describe.c
index 7a66298..75feb11 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 = 0;
 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) {
 		/*
-- 
1.6.4.20.gd25bb.dirty

      reply	other threads:[~2009-08-06 12:15 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-05 14:17 [PATCH] git-describe: Die early if there are no possible descriptions Björn Steinbrink
2009-08-05 15:34 ` Shawn O. Pearce
2009-08-05 15:42   ` Björn Steinbrink
2009-08-06 12:15     ` Björn Steinbrink [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090806121514.GA1701@atjola.homenet \
    --to=b.steinbrink@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=spearce@spearce.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).