sha1-name.c: remove the_repo from sort_ambiguous()

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nguyễn Thái Ngọc Duy committed Apr 16, 2019 at 16:33 UTC fae2ae45df32192bb862f1d71704381d67ce81b3
1 file changed +12 -3
sha1-name.c
+12 -3
@@ -383,10 +383,11 @@ static int collect_ambiguous(const struct object_id *oid, void *data)
383 return 0;
384 }
385
386 +static struct repository *sort_ambiguous_repo;
387 static int sort_ambiguous(const void *a, const void *b)
388 {
388 - int a_type = oid_object_info(the_repository, a, NULL);
389 - int b_type = oid_object_info(the_repository, b, NULL);
389 + int a_type = oid_object_info(sort_ambiguous_repo, a, NULL);
390 + int b_type = oid_object_info(sort_ambiguous_repo, b, NULL);
391 int a_type_sort;
392 int b_type_sort;
393
@@ -411,6 +412,14 @@ static int sort_ambiguous(const void *a, const void *b)
412 return a_type_sort > b_type_sort ? 1 : -1;
413 }
414
415 +static void sort_ambiguous_oid_array(struct repository *r, struct oid_array *a)
416 +{
417 + /* mutex will be needed if this code is to be made thread safe */
418 + sort_ambiguous_repo = r;
419 + QSORT(a->oid, a->nr, sort_ambiguous);
420 + sort_ambiguous_repo = NULL;
421 +}
422 +
423 static enum get_oid_result get_short_oid(const char *name, int len,
424 struct object_id *oid,
425 unsigned flags)
@@ -458,7 +467,7 @@ static enum get_oid_result get_short_oid(const char *name, int len,
467
468 advise(_("The candidates are:"));
469 for_each_abbrev(ds.hex_pfx, collect_ambiguous, &collect);
461 - QSORT(collect.oid, collect.nr, sort_ambiguous);
470 + sort_ambiguous_oid_array(the_repository, &collect);
471
472 if (oid_array_for_each(&collect, show_ambiguous_object, &ds))
473 BUG("show_ambiguous_object shouldn't return non-zero");