Convert many resolve_ref() calls to read_ref*() and ref_exists()
resolve_ref() may return a pointer to a static buffer, which is not safe for long-term use because if another resolve_ref() call happens, the buffer may be changed. Many call sites though do not care about this buffer. They simply check if the return value is NULL or not. Convert all these call sites to new wrappers to reduce resolve_ref() calls from 57 to 34. If we change resolve_ref() prototype later on to avoid passing static buffer out, this helps reduce changes. 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:

committed by
Junio C Hamano

parent
bc1bbe0c19
commit
c689332391
@ -420,7 +420,7 @@ static struct object *want_commit(const char *name)
|
||||
static void merge_name(const char *remote, struct strbuf *msg)
|
||||
{
|
||||
struct object *remote_head;
|
||||
unsigned char branch_head[20], buf_sha[20];
|
||||
unsigned char branch_head[20];
|
||||
struct strbuf buf = STRBUF_INIT;
|
||||
struct strbuf bname = STRBUF_INIT;
|
||||
const char *ptr;
|
||||
@ -479,7 +479,7 @@ static void merge_name(const char *remote, struct strbuf *msg)
|
||||
strbuf_addstr(&truname, "refs/heads/");
|
||||
strbuf_addstr(&truname, remote);
|
||||
strbuf_setlen(&truname, truname.len - len);
|
||||
if (resolve_ref(truname.buf, buf_sha, 1, NULL)) {
|
||||
if (ref_exists(truname.buf)) {
|
||||
strbuf_addf(msg,
|
||||
"%s\t\tbranch '%s'%s of .\n",
|
||||
sha1_to_hex(remote_head->sha1),
|
||||
|
Reference in New Issue
Block a user