Re: [PATCH 2/2] Correct priority of lightweight tags in git-describe.
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);
}