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>
This commit is contained in:
parent
7f07c033a6
commit
8bb95572b0
6
cache.h
6
cache.h
@ -1045,8 +1045,10 @@ extern void check_repository_format(void);
|
|||||||
* Note that while this version avoids the static buffer, it is not fully
|
* Note that while this version avoids the static buffer, it is not fully
|
||||||
* reentrant, as it calls into other non-reentrant git code.
|
* reentrant, as it calls into other non-reentrant git code.
|
||||||
*/
|
*/
|
||||||
extern const char *find_unique_abbrev(const struct object_id *oid, int len);
|
const char *repo_find_unique_abbrev(struct repository *r, const struct object_id *oid, int len);
|
||||||
extern int find_unique_abbrev_r(char *hex, const struct object_id *oid, int len);
|
#define find_unique_abbrev(oid, len) repo_find_unique_abbrev(the_repository, oid, len)
|
||||||
|
int repo_find_unique_abbrev_r(struct repository *r, char *hex, const struct object_id *oid, int len);
|
||||||
|
#define find_unique_abbrev_r(hex, oid, len) repo_find_unique_abbrev_r(the_repository, hex, oid, len)
|
||||||
|
|
||||||
extern const unsigned char null_sha1[GIT_MAX_RAWSZ];
|
extern const unsigned char null_sha1[GIT_MAX_RAWSZ];
|
||||||
extern const struct object_id null_oid;
|
extern const struct object_id null_oid;
|
||||||
|
15
sha1-name.c
15
sha1-name.c
@ -626,15 +626,16 @@ static void find_abbrev_len_packed(struct min_abbrev_data *mad)
|
|||||||
find_abbrev_len_for_pack(p, mad);
|
find_abbrev_len_for_pack(p, mad);
|
||||||
}
|
}
|
||||||
|
|
||||||
int find_unique_abbrev_r(char *hex, const struct object_id *oid, int len)
|
int repo_find_unique_abbrev_r(struct repository *r, char *hex,
|
||||||
|
const struct object_id *oid, int len)
|
||||||
{
|
{
|
||||||
struct disambiguate_state ds;
|
struct disambiguate_state ds;
|
||||||
struct min_abbrev_data mad;
|
struct min_abbrev_data mad;
|
||||||
struct object_id oid_ret;
|
struct object_id oid_ret;
|
||||||
const unsigned hexsz = the_hash_algo->hexsz;
|
const unsigned hexsz = r->hash_algo->hexsz;
|
||||||
|
|
||||||
if (len < 0) {
|
if (len < 0) {
|
||||||
unsigned long count = approximate_object_count();
|
unsigned long count = repo_approximate_object_count(r);
|
||||||
/*
|
/*
|
||||||
* Add one because the MSB only tells us the highest bit set,
|
* Add one because the MSB only tells us the highest bit set,
|
||||||
* not including the value of all the _other_ bits (so "15"
|
* 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)
|
|||||||
if (len == hexsz || !len)
|
if (len == hexsz || !len)
|
||||||
return hexsz;
|
return hexsz;
|
||||||
|
|
||||||
mad.repo = the_repository;
|
mad.repo = r;
|
||||||
mad.init_len = len;
|
mad.init_len = len;
|
||||||
mad.cur_len = len;
|
mad.cur_len = len;
|
||||||
mad.hex = hex;
|
mad.hex = hex;
|
||||||
@ -681,13 +682,15 @@ int find_unique_abbrev_r(char *hex, const struct object_id *oid, int len)
|
|||||||
return mad.cur_len;
|
return mad.cur_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *find_unique_abbrev(const struct object_id *oid, int len)
|
const char *repo_find_unique_abbrev(struct repository *r,
|
||||||
|
const struct object_id *oid,
|
||||||
|
int len)
|
||||||
{
|
{
|
||||||
static int bufno;
|
static int bufno;
|
||||||
static char hexbuffer[4][GIT_MAX_HEXSZ + 1];
|
static char hexbuffer[4][GIT_MAX_HEXSZ + 1];
|
||||||
char *hex = hexbuffer[bufno];
|
char *hex = hexbuffer[bufno];
|
||||||
bufno = (bufno + 1) % ARRAY_SIZE(hexbuffer);
|
bufno = (bufno + 1) % ARRAY_SIZE(hexbuffer);
|
||||||
find_unique_abbrev_r(hex, oid, len);
|
repo_find_unique_abbrev_r(r, hex, oid, len);
|
||||||
return hex;
|
return hex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user