- printf("%s-g%s\n", n->path,
- find_unique_abbrev(cmit->object.sha1, abbrev));
- if (!last_one)
- clear_commit_marks(cmit, SEEN);
- return;
+ struct possible_tag *p = xmalloc(sizeof(*p));
+ p->name = n;
+ p->next = NULL;
+ if (cur_match)
+ cur_match->next = p;
+ else
+ all_matches = p;
+ cur_match = p;
+ } else {
+ struct commit_list *parents = c->parents;
+ while (parents) {
+ struct commit *p = parents->item;
+ parse_commit(p);
+ if (!(p->object.flags & SEEN)) {
+ p->object.flags |= SEEN;
+ insert_by_date(p, &list);
+ }
+ parents = parents->next;
+ }
+ }
+ }
+
+ if (!all_matches)
+ die("cannot describe '%s'", sha1_to_hex(cmit->object.sha1));
+
+ min_match = NULL;
+ for (cur_match = all_matches; cur_match; cur_match = cur_match->next) {
+ struct rev_info revs;
+ struct commit *tagged = cur_match->name->commit;
+
+ clear_commit_marks(cmit, -1);
+ init_revisions(&revs, NULL);
+ tagged->object.flags |= UNINTERESTING;
+ add_pending_object(&revs, &tagged->object, NULL);
+ add_pending_object(&revs, &cmit->object, NULL);
+
+ prepare_revision_walk(&revs);
+ cur_match->depth = 0;
+ while ((!min_match || cur_match->depth < min_match->depth)
+ && get_revision(&revs))
+ cur_match->depth++;
+ if (!min_match || cur_match->depth < min_match->depth)
+ min_match = cur_match;
+ }
+ printf("%s-g%s\n", min_match->name->path,
+ find_unique_abbrev(cmit->object.sha1, abbrev));
+
+ if (!last_one) {
+ for (cur_match = all_matches; cur_match; cur_match = min_match) {
+ min_match = cur_match->next;
+ free(cur_match);