Skip to content

Commit 8bb9557

Browse files
pcloudsgitster
authored andcommitted
sha1-name.c: add repo_find_unique_abbrev_r()
Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7f07c03 commit 8bb9557

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

cache.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,8 +1045,10 @@ extern void check_repository_format(void);
10451045
* Note that while this version avoids the static buffer, it is not fully
10461046
* reentrant, as it calls into other non-reentrant git code.
10471047
*/
1048-
extern const char *find_unique_abbrev(const struct object_id *oid, int len);
1049-
extern int find_unique_abbrev_r(char *hex, const struct object_id *oid, int len);
1048+
const char *repo_find_unique_abbrev(struct repository *r, const struct object_id *oid, int len);
1049+
#define find_unique_abbrev(oid, len) repo_find_unique_abbrev(the_repository, oid, len)
1050+
int repo_find_unique_abbrev_r(struct repository *r, char *hex, const struct object_id *oid, int len);
1051+
#define find_unique_abbrev_r(hex, oid, len) repo_find_unique_abbrev_r(the_repository, hex, oid, len)
10501052

10511053
extern const unsigned char null_sha1[GIT_MAX_RAWSZ];
10521054
extern const struct object_id null_oid;

sha1-name.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -626,15 +626,16 @@ static void find_abbrev_len_packed(struct min_abbrev_data *mad)
626626
find_abbrev_len_for_pack(p, mad);
627627
}
628628

629-
int find_unique_abbrev_r(char *hex, const struct object_id *oid, int len)
629+
int repo_find_unique_abbrev_r(struct repository *r, char *hex,
630+
const struct object_id *oid, int len)
630631
{
631632
struct disambiguate_state ds;
632633
struct min_abbrev_data mad;
633634
struct object_id oid_ret;
634-
const unsigned hexsz = the_hash_algo->hexsz;
635+
const unsigned hexsz = r->hash_algo->hexsz;
635636

636637
if (len < 0) {
637-
unsigned long count = approximate_object_count();
638+
unsigned long count = repo_approximate_object_count(r);
638639
/*
639640
* Add one because the MSB only tells us the highest bit set,
640641
* not including the value of all the _other_ bits (so "15"
@@ -659,7 +660,7 @@ int find_unique_abbrev_r(char *hex, const struct object_id *oid, int len)
659660
if (len == hexsz || !len)
660661
return hexsz;
661662

662-
mad.repo = the_repository;
663+
mad.repo = r;
663664
mad.init_len = len;
664665
mad.cur_len = len;
665666
mad.hex = hex;
@@ -681,13 +682,15 @@ int find_unique_abbrev_r(char *hex, const struct object_id *oid, int len)
681682
return mad.cur_len;
682683
}
683684

684-
const char *find_unique_abbrev(const struct object_id *oid, int len)
685+
const char *repo_find_unique_abbrev(struct repository *r,
686+
const struct object_id *oid,
687+
int len)
685688
{
686689
static int bufno;
687690
static char hexbuffer[4][GIT_MAX_HEXSZ + 1];
688691
char *hex = hexbuffer[bufno];
689692
bufno = (bufno + 1) % ARRAY_SIZE(hexbuffer);
690-
find_unique_abbrev_r(hex, oid, len);
693+
repo_find_unique_abbrev_r(r, hex, oid, len);
691694
return hex;
692695
}
693696

0 commit comments

Comments
 (0)