Skip to content

Commit fae2ae4

Browse files
pcloudsgitster
authored andcommitted
sha1-name.c: remove the_repo from sort_ambiguous()
Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 301b8c7 commit fae2ae4

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

sha1-name.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -383,10 +383,11 @@ static int collect_ambiguous(const struct object_id *oid, void *data)
383383
return 0;
384384
}
385385

386+
static struct repository *sort_ambiguous_repo;
386387
static int sort_ambiguous(const void *a, const void *b)
387388
{
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);
390391
int a_type_sort;
391392
int b_type_sort;
392393

@@ -411,6 +412,14 @@ static int sort_ambiguous(const void *a, const void *b)
411412
return a_type_sort > b_type_sort ? 1 : -1;
412413
}
413414

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+
414423
static enum get_oid_result get_short_oid(const char *name, int len,
415424
struct object_id *oid,
416425
unsigned flags)
@@ -458,7 +467,7 @@ static enum get_oid_result get_short_oid(const char *name, int len,
458467

459468
advise(_("The candidates are:"));
460469
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);
462471

463472
if (oid_array_for_each(&collect, show_ambiguous_object, &ds))
464473
BUG("show_ambiguous_object shouldn't return non-zero");

0 commit comments

Comments
 (0)