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

Re: [PATCH 2/2] Correct priority of lightweight tags in git-describe.

From
Junio C Hamano <junkio@cox.net>
Date
Jan 14, 2007, 19:31 UTC
Message-ID
<7vodp1flrt.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<20070114093744.GB15007@spearce.org>
How about this on top?
 * We seem to do "a_" more often than "_a" for parameter names
   we type-cast.
 * int would be enough for 'depth', not long.  Also, "return
   (a->depth - b->depth)" is kosher only when it is signed,
   although it works in practice on sane platforms.
 * I did not find mergesort(); if we want stable, explicitly do
   so.  In practice, qsort() seems stable (as you know qsort()
   does not have to be implemented as quicksort).
--
diff --git a/builtin-describe.c b/builtin-describe.c
index 45fea10..e38c899 100644
--- a/builtin-describe.c
+++ b/builtin-describe.c
@@ -121,18 +121,21 @@ static int compare_names(const void *_a, const void *_b)
 
 struct possible_tag {
 	struct commit_name *name;
-	unsigned long depth;
+	int depth;
+	int found_order;
 	unsigned flag_within;
 };
 
-static int compare_pt(const void *_a, const void *_b)
+static int compare_pt(const void *a_, const void *b_)
 {
-	struct possible_tag *a = (struct possible_tag *)_a;
-	struct possible_tag *b = (struct possible_tag *)_b;
+	struct possible_tag *a = (struct possible_tag *)a_;
+	struct possible_tag *b = (struct possible_tag *)b_;
 	if (a->name->prio != b->name->prio)
 		return b->name->prio - a->name->prio;
 	if (a->depth != b->depth)
 		return a->depth - b->depth;
+	if (a->found_order != b->found_order)
+		return a->found_order - b->found_order;
 	return 0;
 }
 
@@ -146,6 +149,7 @@ static void describe(const char *arg, int last_one)
 	struct possible_tag all_matches[MAX_TAGS];
 	unsigned int match_cnt = 0, annotated_cnt = 0, cur_match;
 	unsigned long seen_commits = 0;
+	int found = 0;
 
 	if (get_sha1(arg, sha1))
 		die("Not a valid object name %s", arg);
@@ -185,6 +189,7 @@ static void describe(const char *arg, int last_one)
 				t->name = n;
 				t->depth = seen_commits - 1;
 				t->flag_within = 1u << match_cnt;
+				t->found_order = found++;
 				c->object.flags |= t->flag_within;
 				if (n->prio == 2)
 					annotated_cnt++;
@@ -219,11 +224,11 @@ static void describe(const char *arg, int last_one)
 	if (!match_cnt)
 		die("cannot describe '%s'", sha1_to_hex(cmit->object.sha1));
 
-	mergesort(all_matches, match_cnt, sizeof(all_matches[0]), compare_pt);
+	qsort(all_matches, match_cnt, sizeof(all_matches[0]), compare_pt);
 	if (debug) {
 		for (cur_match = 0; cur_match < match_cnt; cur_match++) {
 			struct possible_tag *t = &all_matches[cur_match];
-			fprintf(stderr, " %-11s %8lu %s\n",
+			fprintf(stderr, " %-11s %8d %s\n",
 				prio_names[t->name->prio],
 				t->depth, t->name->path);
 		}
Previous: Shawn O. PearceNext: Shawn O. Pearce
Message 2 of 3 in “Correct priority of lightweight tags in git-describe.”
  1. 2/2 Correct priority of lightweight tags in git-describe.Shawn O. Pearce, Jan 14, 2007
  2. Junio C HamanoJan 14, 2007
  3. Shawn O. PearceJan 14, 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.