resolve_ref_unsafe(): ensure flags is always set
If the caller passes flags==NULL, then set it to point at a local scratch variable. This removes the need for a lot of "if (flags)" guards in resolve_ref_1() and resolve_missing_loose_ref(). Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: David Turner <dturner@twopensource.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
37da4227b2
commit
a70a93b794
@ -1383,7 +1383,6 @@ static int resolve_missing_loose_ref(const char *refname,
|
|||||||
entry = get_packed_ref(refname);
|
entry = get_packed_ref(refname);
|
||||||
if (entry) {
|
if (entry) {
|
||||||
hashcpy(sha1, entry->u.value.oid.hash);
|
hashcpy(sha1, entry->u.value.oid.hash);
|
||||||
if (flags)
|
|
||||||
*flags |= REF_ISPACKED;
|
*flags |= REF_ISPACKED;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -1403,11 +1402,9 @@ static const char *resolve_ref_1(const char *refname,
|
|||||||
int bad_name = 0;
|
int bad_name = 0;
|
||||||
int symref_count;
|
int symref_count;
|
||||||
|
|
||||||
if (flags)
|
|
||||||
*flags = 0;
|
*flags = 0;
|
||||||
|
|
||||||
if (check_refname_format(refname, REFNAME_ALLOW_ONELEVEL)) {
|
if (check_refname_format(refname, REFNAME_ALLOW_ONELEVEL)) {
|
||||||
if (flags)
|
|
||||||
*flags |= REF_BAD_NAME;
|
*flags |= REF_BAD_NAME;
|
||||||
|
|
||||||
if (!(resolve_flags & RESOLVE_REF_ALLOW_BAD_NAME) ||
|
if (!(resolve_flags & RESOLVE_REF_ALLOW_BAD_NAME) ||
|
||||||
@ -1458,7 +1455,6 @@ static const char *resolve_ref_1(const char *refname,
|
|||||||
}
|
}
|
||||||
if (bad_name) {
|
if (bad_name) {
|
||||||
hashclr(sha1);
|
hashclr(sha1);
|
||||||
if (flags)
|
|
||||||
*flags |= REF_ISBROKEN;
|
*flags |= REF_ISBROKEN;
|
||||||
}
|
}
|
||||||
return refname;
|
return refname;
|
||||||
@ -1478,7 +1474,6 @@ static const char *resolve_ref_1(const char *refname,
|
|||||||
!check_refname_format(sb_contents->buf, 0)) {
|
!check_refname_format(sb_contents->buf, 0)) {
|
||||||
strbuf_swap(sb_refname, sb_contents);
|
strbuf_swap(sb_refname, sb_contents);
|
||||||
refname = sb_refname->buf;
|
refname = sb_refname->buf;
|
||||||
if (flags)
|
|
||||||
*flags |= REF_ISSYMREF;
|
*flags |= REF_ISSYMREF;
|
||||||
if (resolve_flags & RESOLVE_REF_NO_RECURSE) {
|
if (resolve_flags & RESOLVE_REF_NO_RECURSE) {
|
||||||
hashclr(sha1);
|
hashclr(sha1);
|
||||||
@ -1526,19 +1521,16 @@ static const char *resolve_ref_1(const char *refname,
|
|||||||
*/
|
*/
|
||||||
if (get_sha1_hex(sb_contents->buf, sha1) ||
|
if (get_sha1_hex(sb_contents->buf, sha1) ||
|
||||||
(sb_contents->buf[40] != '\0' && !isspace(sb_contents->buf[40]))) {
|
(sb_contents->buf[40] != '\0' && !isspace(sb_contents->buf[40]))) {
|
||||||
if (flags)
|
|
||||||
*flags |= REF_ISBROKEN;
|
*flags |= REF_ISBROKEN;
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (bad_name) {
|
if (bad_name) {
|
||||||
hashclr(sha1);
|
hashclr(sha1);
|
||||||
if (flags)
|
|
||||||
*flags |= REF_ISBROKEN;
|
*flags |= REF_ISBROKEN;
|
||||||
}
|
}
|
||||||
return refname;
|
return refname;
|
||||||
}
|
}
|
||||||
if (flags)
|
|
||||||
*flags |= REF_ISSYMREF;
|
*flags |= REF_ISSYMREF;
|
||||||
buf = sb_contents->buf + 4;
|
buf = sb_contents->buf + 4;
|
||||||
while (isspace(*buf))
|
while (isspace(*buf))
|
||||||
@ -1551,7 +1543,6 @@ static const char *resolve_ref_1(const char *refname,
|
|||||||
return refname;
|
return refname;
|
||||||
}
|
}
|
||||||
if (check_refname_format(buf, REFNAME_ALLOW_ONELEVEL)) {
|
if (check_refname_format(buf, REFNAME_ALLOW_ONELEVEL)) {
|
||||||
if (flags)
|
|
||||||
*flags |= REF_ISBROKEN;
|
*flags |= REF_ISBROKEN;
|
||||||
|
|
||||||
if (!(resolve_flags & RESOLVE_REF_ALLOW_BAD_NAME) ||
|
if (!(resolve_flags & RESOLVE_REF_ALLOW_BAD_NAME) ||
|
||||||
@ -1573,8 +1564,12 @@ const char *resolve_ref_unsafe(const char *refname, int resolve_flags,
|
|||||||
static struct strbuf sb_refname = STRBUF_INIT;
|
static struct strbuf sb_refname = STRBUF_INIT;
|
||||||
struct strbuf sb_contents = STRBUF_INIT;
|
struct strbuf sb_contents = STRBUF_INIT;
|
||||||
struct strbuf sb_path = STRBUF_INIT;
|
struct strbuf sb_path = STRBUF_INIT;
|
||||||
|
int unused_flags;
|
||||||
const char *ret;
|
const char *ret;
|
||||||
|
|
||||||
|
if (!flags)
|
||||||
|
flags = &unused_flags;
|
||||||
|
|
||||||
ret = resolve_ref_1(refname, resolve_flags, sha1, flags,
|
ret = resolve_ref_1(refname, resolve_flags, sha1, flags,
|
||||||
&sb_refname, &sb_path, &sb_contents);
|
&sb_refname, &sb_path, &sb_contents);
|
||||||
strbuf_release(&sb_path);
|
strbuf_release(&sb_path);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user