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
@ -131,7 +131,8 @@ static int branch_merged(int kind, const char *name,
|
||||
branch->merge[0] &&
|
||||
branch->merge[0]->dst &&
|
||||
(reference_name = reference_name_to_free =
|
||||
resolve_refdup(branch->merge[0]->dst, sha1, 1, NULL)) != NULL)
|
||||
resolve_refdup(branch->merge[0]->dst, RESOLVE_REF_READING,
|
||||
sha1, NULL)) != NULL)
|
||||
reference_rev = lookup_commit_reference(sha1);
|
||||
}
|
||||
if (!reference_rev)
|
||||
@ -235,7 +236,7 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
|
||||
free(name);
|
||||
|
||||
name = mkpathdup(fmt, bname.buf);
|
||||
target = resolve_ref_unsafe(name, sha1, 0, &flags);
|
||||
target = resolve_ref_unsafe(name, 0, sha1, &flags);
|
||||
if (!target ||
|
||||
(!(flags & REF_ISSYMREF) && is_null_sha1(sha1))) {
|
||||
error(remote_branch
|
||||
@ -299,7 +300,7 @@ static char *resolve_symref(const char *src, const char *prefix)
|
||||
int flag;
|
||||
const char *dst;
|
||||
|
||||
dst = resolve_ref_unsafe(src, sha1, 0, &flag);
|
||||
dst = resolve_ref_unsafe(src, 0, sha1, &flag);
|
||||
if (!(dst && (flag & REF_ISSYMREF)))
|
||||
return NULL;
|
||||
if (prefix)
|
||||
@ -869,7 +870,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
|
||||
|
||||
track = git_branch_track;
|
||||
|
||||
head = resolve_refdup("HEAD", head_sha1, 0, NULL);
|
||||
head = resolve_refdup("HEAD", 0, head_sha1, NULL);
|
||||
if (!head)
|
||||
die(_("Failed to resolve HEAD as a valid ref."));
|
||||
if (!strcmp(head, "HEAD"))
|
||||
|
Reference in New Issue
Block a user