return 0;
}
- int a_type = oid_object_info(a, NULL);
- int b_type = oid_object_info(b, NULL);
+ static int collect_ambiguous(const struct object_id *oid, void *data)
+ {
+ oid_array_append(data, oid);
+ return 0;
+ }
+
+ static int sort_ambiguous(const void *a, const void *b)
+ {
++ int a_type = oid_object_info(the_repository, a, NULL);
++ int b_type = oid_object_info(the_repository, b, NULL);
+ int a_type_sort;
+ int b_type_sort;
+
+ /*
+ * Sorts by hash within the same object type, just as
+ * oid_array_for_each_unique() would do.
+ */
+ if (a_type == b_type)
+ return oidcmp(a, b);
+
+ /*
+ * Between object types show tags, then commits, and finally
+ * trees and blobs.
+ *
+ * The object_type enum is commit, tree, blob, tag, but we
+ * want tag, commit, tree blob. Cleverly (perhaps too
+ * cleverly) do that with modulus, since the enum assigns 1 to
+ * commit, so tag becomes 0.
+ */
+ a_type_sort = a_type % 4;
+ b_type_sort = b_type % 4;
+ return a_type_sort > b_type_sort ? 1 : -1;
+ }
+
static int get_short_oid(const char *name, int len, struct object_id *oid,
unsigned flags)
{