refs.c: change resolve_ref_unsafe reading argument to be a flags field
resolve_ref_unsafe takes a boolean argument for reading (a nonexistent ref resolves successfully for writing but not for reading). Change this to be a flags field instead, and pass the new constant RESOLVE_REF_READING when we want this behaviour. While at it, swap two of the arguments in the function to put output arguments at the end. As a nice side effect, this ensures that we can catch callers that were unaware of the new API so they can be audited. Give the wrapper functions resolve_refdup and read_ref_full the same treatment for consistency. Signed-off-by: Ronnie Sahlberg <sahlberg@google.com> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
aae383db8c
commit
7695d118e5
11
remote.c
11
remote.c
@ -508,7 +508,7 @@ static void read_config(void)
|
||||
return;
|
||||
default_remote_name = "origin";
|
||||
current_branch = NULL;
|
||||
head_ref = resolve_ref_unsafe("HEAD", sha1, 0, &flag);
|
||||
head_ref = resolve_ref_unsafe("HEAD", 0, sha1, &flag);
|
||||
if (head_ref && (flag & REF_ISSYMREF) &&
|
||||
skip_prefix(head_ref, "refs/heads/", &head_ref)) {
|
||||
current_branch = make_branch(head_ref, 0);
|
||||
@ -1138,7 +1138,8 @@ static char *guess_ref(const char *name, struct ref *peer)
|
||||
struct strbuf buf = STRBUF_INIT;
|
||||
unsigned char sha1[20];
|
||||
|
||||
const char *r = resolve_ref_unsafe(peer->name, sha1, 1, NULL);
|
||||
const char *r = resolve_ref_unsafe(peer->name, RESOLVE_REF_READING,
|
||||
sha1, NULL);
|
||||
if (!r)
|
||||
return NULL;
|
||||
|
||||
@ -1199,7 +1200,9 @@ static int match_explicit(struct ref *src, struct ref *dst,
|
||||
unsigned char sha1[20];
|
||||
int flag;
|
||||
|
||||
dst_value = resolve_ref_unsafe(matched_src->name, sha1, 1, &flag);
|
||||
dst_value = resolve_ref_unsafe(matched_src->name,
|
||||
RESOLVE_REF_READING,
|
||||
sha1, &flag);
|
||||
if (!dst_value ||
|
||||
((flag & REF_ISSYMREF) &&
|
||||
!starts_with(dst_value, "refs/heads/")))
|
||||
@ -1673,7 +1676,7 @@ static int ignore_symref_update(const char *refname)
|
||||
unsigned char sha1[20];
|
||||
int flag;
|
||||
|
||||
if (!resolve_ref_unsafe(refname, sha1, 0, &flag))
|
||||
if (!resolve_ref_unsafe(refname, 0, sha1, &flag))
|
||||
return 0; /* non-existing refs are OK */
|
||||
return (flag & REF_ISSYMREF);
|
||||
}
|
||||
|
Reference in New Issue
Block a user