sha1-name.c: add repo_find_unique_abbrev_r()
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
8bb95572b05d70cce6ea6eef9396cdaf6b34b14f
2 files changed
+13
-8
cache.h
+4
-2
@@ -1045,8 +1045,10 @@ extern void check_repository_format(void);
1045
* Note that while this version avoids the static buffer, it is not fully
1046
* reentrant, as it calls into other non-reentrant git code.
1047
*/
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)
1052
1053
extern const unsigned char null_sha1[GIT_MAX_RAWSZ];
1054
extern const struct object_id null_oid;
sha1-name.c
+9
-6
@@ -626,15 +626,16 @@ static void find_abbrev_len_packed(struct min_abbrev_data *mad)
626
find_abbrev_len_for_pack(p, mad);
627
}
628
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)
631
{
632
struct disambiguate_state ds;
633
struct min_abbrev_data mad;
634
struct object_id oid_ret;
634
- const unsigned hexsz = the_hash_algo->hexsz;
635
+ const unsigned hexsz = r->hash_algo->hexsz;
636
637
if (len < 0) {
637
- unsigned long count = approximate_object_count();
638
+ unsigned long count = repo_approximate_object_count(r);
639
/*
640
* Add one because the MSB only tells us the highest bit set,
641
* 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)
660
if (len == hexsz || !len)
661
return hexsz;
662
662
- mad.repo = the_repository;
663
+ mad.repo = r;
664
mad.init_len = len;
665
mad.cur_len = len;
666
mad.hex = hex;
@@ -681,13 +682,15 @@ int find_unique_abbrev_r(char *hex, const struct object_id *oid, int len)
682
return mad.cur_len;
683
}
684
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)
688
{
689
static int bufno;
690
static char hexbuffer[4][GIT_MAX_HEXSZ + 1];
691
char *hex = hexbuffer[bufno];
692
bufno = (bufno + 1) % ARRAY_SIZE(hexbuffer);
690
- find_unique_abbrev_r(hex, oid, len);
693
+ repo_find_unique_abbrev_r(r, hex, oid, len);
694
return hex;
695
}
696