refs: convert resolve_ref_unsafe to struct object_id
Convert resolve_ref_unsafe to take a pointer to struct object_id by converting one remaining caller to use struct object_id, removing the temporary NULL pointer check in expand_ref, converting the declaration and definition, and applying the following semantic patch: @@ expression E1, E2, E3, E4; @@ - resolve_ref_unsafe(E1, E2, E3.hash, E4) + resolve_ref_unsafe(E1, E2, &E3, E4) @@ expression E1, E2, E3, E4; @@ - resolve_ref_unsafe(E1, E2, E3->hash, E4) + resolve_ref_unsafe(E1, E2, E3, E4) Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
committed by
Junio C Hamano
parent
0f05154c70
commit
49e61479be
4
blame.c
4
blame.c
@@ -166,7 +166,7 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt,
|
|||||||
commit->date = now;
|
commit->date = now;
|
||||||
parent_tail = &commit->parents;
|
parent_tail = &commit->parents;
|
||||||
|
|
||||||
if (!resolve_ref_unsafe("HEAD", RESOLVE_REF_READING, head_oid.hash, NULL))
|
if (!resolve_ref_unsafe("HEAD", RESOLVE_REF_READING, &head_oid, NULL))
|
||||||
die("no such ref: HEAD");
|
die("no such ref: HEAD");
|
||||||
|
|
||||||
parent_tail = append_parent(parent_tail, &head_oid);
|
parent_tail = append_parent(parent_tail, &head_oid);
|
||||||
@@ -1689,7 +1689,7 @@ static struct commit *dwim_reverse_initial(struct rev_info *revs,
|
|||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
/* Do we have HEAD? */
|
/* Do we have HEAD? */
|
||||||
if (!resolve_ref_unsafe("HEAD", RESOLVE_REF_READING, head_oid.hash, NULL))
|
if (!resolve_ref_unsafe("HEAD", RESOLVE_REF_READING, &head_oid, NULL))
|
||||||
return NULL;
|
return NULL;
|
||||||
head_commit = lookup_commit_reference_gently(&head_oid, 1);
|
head_commit = lookup_commit_reference_gently(&head_oid, 1);
|
||||||
if (!head_commit)
|
if (!head_commit)
|
||||||
|
|||||||
@@ -555,7 +555,7 @@ static int fsck_head_link(void)
|
|||||||
if (verbose)
|
if (verbose)
|
||||||
fprintf(stderr, "Checking HEAD link\n");
|
fprintf(stderr, "Checking HEAD link\n");
|
||||||
|
|
||||||
head_points_at = resolve_ref_unsafe("HEAD", 0, head_oid.hash, NULL);
|
head_points_at = resolve_ref_unsafe("HEAD", 0, &head_oid, NULL);
|
||||||
if (!head_points_at) {
|
if (!head_points_at) {
|
||||||
errors_found |= ERROR_REFS;
|
errors_found |= ERROR_REFS;
|
||||||
return error("Invalid HEAD");
|
return error("Invalid HEAD");
|
||||||
|
|||||||
29
refs.c
29
refs.c
@@ -199,7 +199,7 @@ char *refs_resolve_refdup(struct ref_store *refs,
|
|||||||
const char *result;
|
const char *result;
|
||||||
|
|
||||||
result = refs_resolve_ref_unsafe(refs, refname, resolve_flags,
|
result = refs_resolve_ref_unsafe(refs, refname, resolve_flags,
|
||||||
oid->hash, flags);
|
oid, flags);
|
||||||
return xstrdup_or_null(result);
|
return xstrdup_or_null(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -221,7 +221,7 @@ struct ref_filter {
|
|||||||
int refs_read_ref_full(struct ref_store *refs, const char *refname,
|
int refs_read_ref_full(struct ref_store *refs, const char *refname,
|
||||||
int resolve_flags, struct object_id *oid, int *flags)
|
int resolve_flags, struct object_id *oid, int *flags)
|
||||||
{
|
{
|
||||||
if (refs_resolve_ref_unsafe(refs, refname, resolve_flags, oid->hash, flags))
|
if (refs_resolve_ref_unsafe(refs, refname, resolve_flags, oid, flags))
|
||||||
return 0;
|
return 0;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -480,8 +480,7 @@ int expand_ref(const char *str, int len, struct object_id *oid, char **ref)
|
|||||||
strbuf_reset(&fullref);
|
strbuf_reset(&fullref);
|
||||||
strbuf_addf(&fullref, *p, len, str);
|
strbuf_addf(&fullref, *p, len, str);
|
||||||
r = resolve_ref_unsafe(fullref.buf, RESOLVE_REF_READING,
|
r = resolve_ref_unsafe(fullref.buf, RESOLVE_REF_READING,
|
||||||
this_result ? this_result->hash : NULL,
|
this_result, &flag);
|
||||||
&flag);
|
|
||||||
if (r) {
|
if (r) {
|
||||||
if (!refs_found++)
|
if (!refs_found++)
|
||||||
*ref = xstrdup(r);
|
*ref = xstrdup(r);
|
||||||
@@ -512,7 +511,7 @@ int dwim_log(const char *str, int len, struct object_id *oid, char **log)
|
|||||||
strbuf_reset(&path);
|
strbuf_reset(&path);
|
||||||
strbuf_addf(&path, *p, len, str);
|
strbuf_addf(&path, *p, len, str);
|
||||||
ref = resolve_ref_unsafe(path.buf, RESOLVE_REF_READING,
|
ref = resolve_ref_unsafe(path.buf, RESOLVE_REF_READING,
|
||||||
hash.hash, NULL);
|
&hash, NULL);
|
||||||
if (!ref)
|
if (!ref)
|
||||||
continue;
|
continue;
|
||||||
if (reflog_exists(path.buf))
|
if (reflog_exists(path.buf))
|
||||||
@@ -1393,15 +1392,15 @@ int refs_read_raw_ref(struct ref_store *ref_store,
|
|||||||
const char *refs_resolve_ref_unsafe(struct ref_store *refs,
|
const char *refs_resolve_ref_unsafe(struct ref_store *refs,
|
||||||
const char *refname,
|
const char *refname,
|
||||||
int resolve_flags,
|
int resolve_flags,
|
||||||
unsigned char *sha1, int *flags)
|
struct object_id *oid, int *flags)
|
||||||
{
|
{
|
||||||
static struct strbuf sb_refname = STRBUF_INIT;
|
static struct strbuf sb_refname = STRBUF_INIT;
|
||||||
struct object_id unused_oid;
|
struct object_id unused_oid;
|
||||||
int unused_flags;
|
int unused_flags;
|
||||||
int symref_count;
|
int symref_count;
|
||||||
|
|
||||||
if (!sha1)
|
if (!oid)
|
||||||
sha1 = unused_oid.hash;
|
oid = &unused_oid;
|
||||||
if (!flags)
|
if (!flags)
|
||||||
flags = &unused_flags;
|
flags = &unused_flags;
|
||||||
|
|
||||||
@@ -1429,7 +1428,7 @@ const char *refs_resolve_ref_unsafe(struct ref_store *refs,
|
|||||||
unsigned int read_flags = 0;
|
unsigned int read_flags = 0;
|
||||||
|
|
||||||
if (refs_read_raw_ref(refs, refname,
|
if (refs_read_raw_ref(refs, refname,
|
||||||
sha1, &sb_refname, &read_flags)) {
|
oid->hash, &sb_refname, &read_flags)) {
|
||||||
*flags |= read_flags;
|
*flags |= read_flags;
|
||||||
|
|
||||||
/* In reading mode, refs must eventually resolve */
|
/* In reading mode, refs must eventually resolve */
|
||||||
@@ -1446,7 +1445,7 @@ const char *refs_resolve_ref_unsafe(struct ref_store *refs,
|
|||||||
errno != ENOTDIR)
|
errno != ENOTDIR)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
hashclr(sha1);
|
oidclr(oid);
|
||||||
if (*flags & REF_BAD_NAME)
|
if (*flags & REF_BAD_NAME)
|
||||||
*flags |= REF_ISBROKEN;
|
*flags |= REF_ISBROKEN;
|
||||||
return refname;
|
return refname;
|
||||||
@@ -1456,7 +1455,7 @@ const char *refs_resolve_ref_unsafe(struct ref_store *refs,
|
|||||||
|
|
||||||
if (!(read_flags & REF_ISSYMREF)) {
|
if (!(read_flags & REF_ISSYMREF)) {
|
||||||
if (*flags & REF_BAD_NAME) {
|
if (*flags & REF_BAD_NAME) {
|
||||||
hashclr(sha1);
|
oidclr(oid);
|
||||||
*flags |= REF_ISBROKEN;
|
*flags |= REF_ISBROKEN;
|
||||||
}
|
}
|
||||||
return refname;
|
return refname;
|
||||||
@@ -1464,7 +1463,7 @@ const char *refs_resolve_ref_unsafe(struct ref_store *refs,
|
|||||||
|
|
||||||
refname = sb_refname.buf;
|
refname = sb_refname.buf;
|
||||||
if (resolve_flags & RESOLVE_REF_NO_RECURSE) {
|
if (resolve_flags & RESOLVE_REF_NO_RECURSE) {
|
||||||
hashclr(sha1);
|
oidclr(oid);
|
||||||
return refname;
|
return refname;
|
||||||
}
|
}
|
||||||
if (check_refname_format(refname, REFNAME_ALLOW_ONELEVEL)) {
|
if (check_refname_format(refname, REFNAME_ALLOW_ONELEVEL)) {
|
||||||
@@ -1491,10 +1490,10 @@ int refs_init_db(struct strbuf *err)
|
|||||||
}
|
}
|
||||||
|
|
||||||
const char *resolve_ref_unsafe(const char *refname, int resolve_flags,
|
const char *resolve_ref_unsafe(const char *refname, int resolve_flags,
|
||||||
unsigned char *sha1, int *flags)
|
struct object_id *oid, int *flags)
|
||||||
{
|
{
|
||||||
return refs_resolve_ref_unsafe(get_main_ref_store(), refname,
|
return refs_resolve_ref_unsafe(get_main_ref_store(), refname,
|
||||||
resolve_flags, sha1, flags);
|
resolve_flags, oid, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
int resolve_gitlink_ref(const char *submodule, const char *refname,
|
int resolve_gitlink_ref(const char *submodule, const char *refname,
|
||||||
@@ -1508,7 +1507,7 @@ int resolve_gitlink_ref(const char *submodule, const char *refname,
|
|||||||
if (!refs)
|
if (!refs)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (!refs_resolve_ref_unsafe(refs, refname, 0, oid->hash, &flags) ||
|
if (!refs_resolve_ref_unsafe(refs, refname, 0, oid, &flags) ||
|
||||||
is_null_oid(oid))
|
is_null_oid(oid))
|
||||||
return -1;
|
return -1;
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
14
refs.h
14
refs.h
@@ -14,22 +14,22 @@ struct worktree;
|
|||||||
* at the resolved object name. The return value, if not NULL, is a
|
* at the resolved object name. The return value, if not NULL, is a
|
||||||
* pointer into either a static buffer or the input ref.
|
* pointer into either a static buffer or the input ref.
|
||||||
*
|
*
|
||||||
* If sha1 is non-NULL, store the referred-to object's name in it.
|
* If oid is non-NULL, store the referred-to object's name in it.
|
||||||
*
|
*
|
||||||
* If the reference cannot be resolved to an object, the behavior
|
* If the reference cannot be resolved to an object, the behavior
|
||||||
* depends on the RESOLVE_REF_READING flag:
|
* depends on the RESOLVE_REF_READING flag:
|
||||||
*
|
*
|
||||||
* - If RESOLVE_REF_READING is set, return NULL.
|
* - If RESOLVE_REF_READING is set, return NULL.
|
||||||
*
|
*
|
||||||
* - If RESOLVE_REF_READING is not set, clear sha1 and return the name of
|
* - If RESOLVE_REF_READING is not set, clear oid and return the name of
|
||||||
* the last reference name in the chain, which will either be a non-symbolic
|
* the last reference name in the chain, which will either be a non-symbolic
|
||||||
* reference or an undefined reference. If this is a prelude to
|
* reference or an undefined reference. If this is a prelude to
|
||||||
* "writing" to the ref, the return value is the name of the ref
|
* "writing" to the ref, the return value is the name of the ref
|
||||||
* that will actually be created or changed.
|
* that will actually be created or changed.
|
||||||
*
|
*
|
||||||
* If the RESOLVE_REF_NO_RECURSE flag is passed, only resolves one
|
* If the RESOLVE_REF_NO_RECURSE flag is passed, only resolves one
|
||||||
* level of symbolic reference. The value stored in sha1 for a symbolic
|
* level of symbolic reference. The value stored in oid for a symbolic
|
||||||
* reference will always be null_sha1 in this case, and the return
|
* reference will always be null_oid in this case, and the return
|
||||||
* value is the reference that the symref refers to directly.
|
* value is the reference that the symref refers to directly.
|
||||||
*
|
*
|
||||||
* If flags is non-NULL, set the value that it points to the
|
* If flags is non-NULL, set the value that it points to the
|
||||||
@@ -46,7 +46,7 @@ struct worktree;
|
|||||||
*
|
*
|
||||||
* RESOLVE_REF_ALLOW_BAD_NAME allows resolving refs even when their
|
* RESOLVE_REF_ALLOW_BAD_NAME allows resolving refs even when their
|
||||||
* name is invalid according to git-check-ref-format(1). If the name
|
* name is invalid according to git-check-ref-format(1). If the name
|
||||||
* is bad then the value stored in sha1 will be null_sha1 and the two
|
* is bad then the value stored in oid will be null_oid and the two
|
||||||
* flags REF_ISBROKEN and REF_BAD_NAME will be set.
|
* flags REF_ISBROKEN and REF_BAD_NAME will be set.
|
||||||
*
|
*
|
||||||
* Even with RESOLVE_REF_ALLOW_BAD_NAME, names that escape the refs/
|
* Even with RESOLVE_REF_ALLOW_BAD_NAME, names that escape the refs/
|
||||||
@@ -62,10 +62,10 @@ struct worktree;
|
|||||||
const char *refs_resolve_ref_unsafe(struct ref_store *refs,
|
const char *refs_resolve_ref_unsafe(struct ref_store *refs,
|
||||||
const char *refname,
|
const char *refname,
|
||||||
int resolve_flags,
|
int resolve_flags,
|
||||||
unsigned char *sha1,
|
struct object_id *oid,
|
||||||
int *flags);
|
int *flags);
|
||||||
const char *resolve_ref_unsafe(const char *refname, int resolve_flags,
|
const char *resolve_ref_unsafe(const char *refname, int resolve_flags,
|
||||||
unsigned char *sha1, int *flags);
|
struct object_id *oid, int *flags);
|
||||||
|
|
||||||
char *refs_resolve_refdup(struct ref_store *refs,
|
char *refs_resolve_refdup(struct ref_store *refs,
|
||||||
const char *refname, int resolve_flags,
|
const char *refname, int resolve_flags,
|
||||||
|
|||||||
@@ -189,7 +189,7 @@ static void loose_fill_ref_dir(struct ref_store *ref_store,
|
|||||||
if (!refs_resolve_ref_unsafe(&refs->base,
|
if (!refs_resolve_ref_unsafe(&refs->base,
|
||||||
refname.buf,
|
refname.buf,
|
||||||
RESOLVE_REF_READING,
|
RESOLVE_REF_READING,
|
||||||
oid.hash, &flag)) {
|
&oid, &flag)) {
|
||||||
oidclr(&oid);
|
oidclr(&oid);
|
||||||
flag |= REF_ISBROKEN;
|
flag |= REF_ISBROKEN;
|
||||||
} else if (is_null_oid(&oid)) {
|
} else if (is_null_oid(&oid)) {
|
||||||
@@ -855,7 +855,7 @@ static struct ref_lock *lock_ref_sha1_basic(struct files_ref_store *refs,
|
|||||||
files_ref_path(refs, &ref_file, refname);
|
files_ref_path(refs, &ref_file, refname);
|
||||||
resolved = !!refs_resolve_ref_unsafe(&refs->base,
|
resolved = !!refs_resolve_ref_unsafe(&refs->base,
|
||||||
refname, resolve_flags,
|
refname, resolve_flags,
|
||||||
lock->old_oid.hash, type);
|
&lock->old_oid, type);
|
||||||
if (!resolved && errno == EISDIR) {
|
if (!resolved && errno == EISDIR) {
|
||||||
/*
|
/*
|
||||||
* we are trying to lock foo but we used to
|
* we are trying to lock foo but we used to
|
||||||
@@ -874,7 +874,7 @@ static struct ref_lock *lock_ref_sha1_basic(struct files_ref_store *refs,
|
|||||||
}
|
}
|
||||||
resolved = !!refs_resolve_ref_unsafe(&refs->base,
|
resolved = !!refs_resolve_ref_unsafe(&refs->base,
|
||||||
refname, resolve_flags,
|
refname, resolve_flags,
|
||||||
lock->old_oid.hash, type);
|
&lock->old_oid, type);
|
||||||
}
|
}
|
||||||
if (!resolved) {
|
if (!resolved) {
|
||||||
last_errno = errno;
|
last_errno = errno;
|
||||||
@@ -1251,7 +1251,7 @@ static int files_copy_or_rename_ref(struct ref_store *ref_store,
|
|||||||
|
|
||||||
if (!refs_resolve_ref_unsafe(&refs->base, oldrefname,
|
if (!refs_resolve_ref_unsafe(&refs->base, oldrefname,
|
||||||
RESOLVE_REF_READING | RESOLVE_REF_NO_RECURSE,
|
RESOLVE_REF_READING | RESOLVE_REF_NO_RECURSE,
|
||||||
orig_oid.hash, &flag)) {
|
&orig_oid, &flag)) {
|
||||||
ret = error("refname %s not found", oldrefname);
|
ret = error("refname %s not found", oldrefname);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -489,7 +489,7 @@ static int is_index_unchanged(void)
|
|||||||
struct object_id head_oid;
|
struct object_id head_oid;
|
||||||
struct commit *head_commit;
|
struct commit *head_commit;
|
||||||
|
|
||||||
if (!resolve_ref_unsafe("HEAD", RESOLVE_REF_READING, head_oid.hash, NULL))
|
if (!resolve_ref_unsafe("HEAD", RESOLVE_REF_READING, &head_oid, NULL))
|
||||||
return error(_("could not resolve HEAD commit\n"));
|
return error(_("could not resolve HEAD commit\n"));
|
||||||
|
|
||||||
head_commit = lookup_commit(&head_oid);
|
head_commit = lookup_commit(&head_oid);
|
||||||
|
|||||||
@@ -127,15 +127,15 @@ static int cmd_for_each_ref(struct ref_store *refs, const char **argv)
|
|||||||
|
|
||||||
static int cmd_resolve_ref(struct ref_store *refs, const char **argv)
|
static int cmd_resolve_ref(struct ref_store *refs, const char **argv)
|
||||||
{
|
{
|
||||||
unsigned char sha1[20];
|
struct object_id oid;
|
||||||
const char *refname = notnull(*argv++, "refname");
|
const char *refname = notnull(*argv++, "refname");
|
||||||
int resolve_flags = arg_flags(*argv++, "resolve-flags");
|
int resolve_flags = arg_flags(*argv++, "resolve-flags");
|
||||||
int flags;
|
int flags;
|
||||||
const char *ref;
|
const char *ref;
|
||||||
|
|
||||||
ref = refs_resolve_ref_unsafe(refs, refname, resolve_flags,
|
ref = refs_resolve_ref_unsafe(refs, refname, resolve_flags,
|
||||||
sha1, &flags);
|
&oid, &flags);
|
||||||
printf("%s %s 0x%x\n", sha1_to_hex(sha1), ref, flags);
|
printf("%s %s 0x%x\n", oid_to_hex(&oid), ref, flags);
|
||||||
return ref ? 0 : 1;
|
return ref ? 0 : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -942,10 +942,9 @@ static int push_refs_with_export(struct transport *transport,
|
|||||||
int flag;
|
int flag;
|
||||||
|
|
||||||
/* Follow symbolic refs (mainly for HEAD). */
|
/* Follow symbolic refs (mainly for HEAD). */
|
||||||
name = resolve_ref_unsafe(
|
name = resolve_ref_unsafe(ref->peer_ref->name,
|
||||||
ref->peer_ref->name,
|
|
||||||
RESOLVE_REF_READING,
|
RESOLVE_REF_READING,
|
||||||
oid.hash, &flag);
|
&oid, &flag);
|
||||||
if (!name || !(flag & REF_ISSYMREF))
|
if (!name || !(flag & REF_ISSYMREF))
|
||||||
name = ref->peer_ref->name;
|
name = ref->peer_ref->name;
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ static void add_head_info(struct worktree *wt)
|
|||||||
target = refs_resolve_ref_unsafe(get_worktree_ref_store(wt),
|
target = refs_resolve_ref_unsafe(get_worktree_ref_store(wt),
|
||||||
"HEAD",
|
"HEAD",
|
||||||
0,
|
0,
|
||||||
wt->head_oid.hash, &flags);
|
&wt->head_oid, &flags);
|
||||||
if (!target)
|
if (!target)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user