MCPcopy Create free account
hub / github.com/git/git / sort_ambiguous

Function sort_ambiguous

object-name.c:417–449  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

415}
416
417static int sort_ambiguous(const void *va, const void *vb, void *ctx)
418{
419 struct repository *sort_ambiguous_repo = ctx;
420 const struct object_id *a = va, *b = vb;
421 int a_type = odb_read_object_info(sort_ambiguous_repo->objects, a, NULL);
422 int b_type = odb_read_object_info(sort_ambiguous_repo->objects, b, NULL);
423 int a_type_sort;
424 int b_type_sort;
425
426 /*
427 * Sorts by hash within the same object type, just as
428 * oid_array_for_each_unique() would do.
429 */
430 if (a_type == b_type) {
431 if (a->algo == b->algo)
432 return oidcmp(a, b);
433 else
434 return a->algo > b->algo ? 1 : -1;
435 }
436
437 /*
438 * Between object types show tags, then commits, and finally
439 * trees and blobs.
440 *
441 * The object_type enum is commit, tree, blob, tag, but we
442 * want tag, commit, tree blob. Cleverly (perhaps too
443 * cleverly) do that with modulus, since the enum assigns 1 to
444 * commit, so tag becomes 0.
445 */
446 a_type_sort = a_type % 4;
447 b_type_sort = b_type % 4;
448 return a_type_sort > b_type_sort ? 1 : -1;
449}
450
451static void sort_ambiguous_oid_array(struct repository *r, struct oid_array *a)
452{

Callers

nothing calls this directly

Calls 2

odb_read_object_infoFunction · 0.85
oidcmpFunction · 0.85

Tested by

no test coverage detected