22
int prio; /* annotated tag = 2, tag = 1, head = 0 */
23
char path[FLEX_ARRAY]; /* more */
24
} **name_array[256];
25
+static const char *prio_names[] = {
26
+ "head", "lightweight", "annotated",
27
+};
28
29
static struct commit_name *match(struct commit *cmit)
30
{
121
122
struct possible_tag {
123
struct commit_name *name;
121
- unsigned long depth;
124
+ int depth;
125
+ int found_order;
126
unsigned flag_within;
127
};
128
129
+static int compare_pt(const void *a_, const void *b_)
130
+{
131
+ struct possible_tag *a = (struct possible_tag *)a_;
132
+ struct possible_tag *b = (struct possible_tag *)b_;
133
+ if (a->name->prio != b->name->prio)
134
+ return b->name->prio - a->name->prio;
135
+ if (a->depth != b->depth)
136
+ return a->depth - b->depth;
137
+ if (a->found_order != b->found_order)
138
+ return a->found_order - b->found_order;
139
+ return 0;
140
+}
141
+
142
static void describe(const char *arg, int last_one)
143
{
144
unsigned char sha1[20];
146
struct commit_list *list;
147
static int initialized = 0;
148
struct commit_name *n;
132
- struct possible_tag all_matches[MAX_TAGS], *min_match;
149
+ struct possible_tag all_matches[MAX_TAGS];
150
unsigned int match_cnt = 0, annotated_cnt = 0, cur_match;
151
unsigned long seen_commits = 0;
152
+ int found = 0;
153
154
if (get_sha1(arg, sha1))
155
die("Not a valid object name %s", arg);
189
t->name = n;
190
t->depth = seen_commits - 1;
191
t->flag_within = 1u << match_cnt;
192
+ t->found_order = found++;
193
c->object.flags |= t->flag_within;
194
if (n->prio == 2)
195
annotated_cnt++;
224
if (!match_cnt)
225
die("cannot describe '%s'", sha1_to_hex(cmit->object.sha1));
226
208
- min_match = &all_matches[0];
209
- for (cur_match = 1; cur_match < match_cnt; cur_match++) {
210
- struct possible_tag *t = &all_matches[cur_match];
211
- if (t->depth < min_match->depth
212
- && t->name->prio >= min_match->name->prio)
213
- min_match = t;
214
- }
227
+ qsort(all_matches, match_cnt, sizeof(all_matches[0]), compare_pt);
228
if (debug) {
229
for (cur_match = 0; cur_match < match_cnt; cur_match++) {
230
struct possible_tag *t = &all_matches[cur_match];
218
- fprintf(stderr, " %c %8lu %s\n",
219
- min_match == t ? '*' : ' ',
231
+ fprintf(stderr, " %-11s %8d %s\n",
232
+ prio_names[t->name->prio],
233
t->depth, t->name->path);
234
}
235
fprintf(stderr, "traversed %lu commits\n", seen_commits);
241
sha1_to_hex(gave_up_on->object.sha1));
242
}
243
}
231
- printf("%s-g%s\n", min_match->name->path,
244
+ printf("%s-g%s\n", all_matches[0].name->path,
245
find_unique_abbrev(cmit->object.sha1, abbrev));
246
247
if (!last_one)