git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: What's cooking in git.git (topics)

From
Junio C Hamano <junkio@cox.net>
Date
Jan 12, 2007, 06:15 UTC
Message-ID
<7vr6u0wz2s.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<20070112004927.GB23864@spearce.org>
"Shawn O. Pearce" <spearce@spearce.org> writes:
Show 6 quoted lines
> Only on tags which are considered possible matches.  What we do
> now is we walk back along the commit history until we find a commit
> which has a tag pointing at it.  As soon as we find that commit we
> enqueue its corresponding tag into a list and completely ignore its
> parents, aborting listing any further back.  So we really only pay
> the bare minimum price here.
This actually is QUITE bad.

With the tip of linux-2.6 repository, v1.4.4 series takes 0.03s while v1.5.0-rc1 takes about 3.6s. That is 100x fold, not just 4x.

It turns out that to describe 0404f87f (tip of linux-2.6) the new one picks up 61 tags in the posible-tag loop.

Since this loop uses the usual date-order, we can limit the number of candidate tags without losing too much precision. When limiting the candidates to only 6 (attached patch), the time drops to 0.25s.

--- 
diff --git a/builtin-describe.c b/builtin-describe.c
index a8c98ce..a1ecec2 100644
--- a/builtin-describe.c
+++ b/builtin-describe.c
@@ -12,6 +12,7 @@ static const char describe_usage[] =
 
 static int all;	/* Default to annotated tags only */
 static int tags;	/* But allow any tags if --tags is specified */
+static int debug;
 
 static int abbrev = DEFAULT_ABBREV;
 
@@ -113,6 +114,7 @@ static void describe(const char *arg, int last_one)
 	static int initialized = 0;
 	struct commit_name *n;
 	struct possible_tag *all_matches, *min_match, *cur_match;
+	int cnt;
 
 	if (get_sha1(arg, sha1))
 		die("Not a valid object name %s", arg);
@@ -136,6 +138,7 @@ static void describe(const char *arg, int last_one)
 	all_matches = NULL;
 	cur_match = NULL;
 	commit_list_insert(cmit, &list);
+	cnt = 6;
 	while (list) {
 		struct commit *c = pop_commit(&list);
 		n = match(c);
@@ -148,6 +151,8 @@ static void describe(const char *arg, int last_one)
 			else
 				all_matches = p;
 			cur_match = p;
+			if (--cnt <= 0)
+				break;
 		} else {
 			struct commit_list *parents = c->parents;
 			while (parents) {
@@ -161,6 +166,18 @@ static void describe(const char *arg, int last_one)
 			}
 		}
 	}
+	if (list)
+		free_commit_list(list);
+
+	if (debug) {
+		int cnt = 0;
+		for (cur_match = all_matches;
+		     cur_match;
+		     cur_match = cur_match->next)
+			cnt++;
+		fprintf(stderr, "%d candidates for %s\n", cnt,
+			sha1_to_hex(cmit->object.sha1));
+	}
 
 	if (!all_matches)
 		die("cannot describe '%s'", sha1_to_hex(cmit->object.sha1));
@@ -210,6 +227,8 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
 			all = 1;
 		else if (!strcmp(arg, "--tags"))
 			tags = 1;
+		else if (!strcmp(arg, "--debug"))
+			debug = 1;
 		else if (!strncmp(arg, "--abbrev=", 9)) {
 			abbrev = strtoul(arg + 9, NULL, 10);
 			if (abbrev < MINIMUM_ABBREV || 40 < abbrev)
Previous: Shawn O. PearceNext: Shawn O. Pearce
Message 9 of 18 in “What's cooking in git.git (topics)”
  1. Junio C HamanoJan 10, 2007
  2. Junio C HamanoJan 11, 2007
  3. Nicolas PitreJan 11, 2007
  4. Shawn O. PearceJan 11, 2007
  5. Andreas EricssonJan 11, 2007
  6. Nicolas PitreJan 11, 2007
  7. Andreas EricssonJan 11, 2007
  8. Shawn O. PearceJan 12, 2007
  9. Junio C HamanoJan 12, 2007
  10. Shawn O. PearceJan 12, 2007
  11. Junio C HamanoJan 11, 2007
  12. Shawn O. PearceJan 11, 2007
  13. Junio C HamanoJan 11, 2007
  14. Shawn O. PearceJan 12, 2007
  15. Jakub NarebskiJan 12, 2007
  16. Johannes SchindelinJan 11, 2007
  17. Junio C HamanoJan 11, 2007
  18. Johannes SchindelinJan 11, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.