* [PATCH] git-describe: Die early if there are no possible descriptions
@ 2009-08-05 14:17 Björn Steinbrink
2009-08-05 15:34 ` Shawn O. Pearce
0 siblings, 1 reply; 4+ messages in thread
From: Björn Steinbrink @ 2009-08-05 14:17 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Shawn O. Pearce, git
If we found no refs that may be used for git-describe with the current
options, then die early instead of pointlessly walking the whole history.
Signed-off-by: Björn Steinbrink <B.Steinbrink@gmx.de>
---
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" which calls describe with increasing levels of allowed
refs to be matched. 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 thing anyway.
I'm not particularly sure about found_names actually counting the found
names, it was just out of the thought that maybe the walking code could
make use of it, but I didn't actually check that and ran out of time, so
I'm sending this version, hoping that it doesn't suck too much.
builtin-describe.c | 6 ++++++
1 files changed, 6 insertions(+), 0 deletions(-)
diff --git a/builtin-describe.c b/builtin-describe.c
index 7a66298..cf802d1 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;
@@ -39,6 +40,8 @@ static void add_to_known_names(const char *path,
const unsigned char *sha1)
{
struct commit_name *e = commit->util;
+ if (!e)
+ found_names++;
if (!e || e->prio < prio) {
size_t len = strlen(path)+1;
free(e);
@@ -195,6 +198,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.19.g42af.dirty
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] git-describe: Die early if there are no possible descriptions
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
0 siblings, 1 reply; 4+ messages in thread
From: Shawn O. Pearce @ 2009-08-05 15:34 UTC (permalink / raw)
To: Bj?rn Steinbrink; +Cc: Junio C Hamano, git
Bj?rn Steinbrink <B.Steinbrink@gmx.de> wrote:
> If we found no refs that may be used for git-describe with the current
> options, then die early instead of pointlessly walking the whole history.
>
> Signed-off-by: Bj?rn Steinbrink <B.Steinbrink@gmx.de>
> ---
> 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" which calls describe with increasing levels of allowed
> refs to be matched. 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 thing anyway.
>
> I'm not particularly sure about found_names actually counting the found
> names, it was just out of the thought that maybe the walking code could
> make use of it, but I didn't actually check that and ran out of time, so
> I'm sending this version, hoping that it doesn't suck too much.
This seems reasonable to me. Really you don't need found_names
to be a counter, but could just always set it to 1 every time the
add_to_known_names function is called. All you care about is that
add_to_known_names was invoked at least once.
Also, I really think that first paragraph after the --- should
have been part of the commit message. The message above doesn't
justify the change, even if it is fairly trivial, without that
additional explanation.
> @@ -39,6 +40,8 @@ static void add_to_known_names(const char *path,
> const unsigned char *sha1)
> {
> struct commit_name *e = commit->util;
> + if (!e)
> + found_names++;
> if (!e || e->prio < prio) {
> size_t len = strlen(path)+1;
> free(e);
--
Shawn.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] git-describe: Die early if there are no possible descriptions
2009-08-05 15:34 ` Shawn O. Pearce
@ 2009-08-05 15:42 ` Björn Steinbrink
2009-08-06 12:15 ` [PATCH v2] " Björn Steinbrink
0 siblings, 1 reply; 4+ messages in thread
From: Björn Steinbrink @ 2009-08-05 15:42 UTC (permalink / raw)
To: Shawn O. Pearce; +Cc: Junio C Hamano, git
On 2009.08.05 08:34:12 -0700, Shawn O. Pearce wrote:
> Bj?rn Steinbrink <B.Steinbrink@gmx.de> wrote:
> > If we found no refs that may be used for git-describe with the current
> > options, then die early instead of pointlessly walking the whole history.
> >
> > Signed-off-by: Bj?rn Steinbrink <B.Steinbrink@gmx.de>
> > ---
> > 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" which calls describe with increasing levels of allowed
> > refs to be matched. 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 thing anyway.
> >
> > I'm not particularly sure about found_names actually counting the found
> > names, it was just out of the thought that maybe the walking code could
> > make use of it, but I didn't actually check that and ran out of time, so
> > I'm sending this version, hoping that it doesn't suck too much.
>
> This seems reasonable to me. Really you don't need found_names
> to be a counter, but could just always set it to 1 every time the
> add_to_known_names function is called. All you care about is that
> add_to_known_names was invoked at least once.
OK.
> Also, I really think that first paragraph after the --- should
> have been part of the commit message. The message above doesn't
> justify the change, even if it is fairly trivial, without that
> additional explanation.
Oh, d'oh, that's even what I intended to do (the original commit message
was written in even more of a hurry than the mail itself), but messed
up. Will re-send (also with found_names turned boolean)
Thanks,
Björn
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2] git-describe: Die early if there are no possible descriptions
2009-08-05 15:42 ` Björn Steinbrink
@ 2009-08-06 12:15 ` Björn Steinbrink
0 siblings, 0 replies; 4+ messages in thread
From: Björn Steinbrink @ 2009-08-06 12:15 UTC (permalink / raw)
To: Shawn O. Pearce; +Cc: Junio C Hamano, git
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
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2009-08-06 12:15 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [PATCH v2] " Björn Steinbrink
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).