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>
raw | patch | inline | side by side (parent: 0f05154 )
commit->date = now;
parent_tail = &commit->parents;
commit->date = now;
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");
parent_tail = append_parent(parent_tail, &head_oid);
die("no such ref: HEAD");
parent_tail = append_parent(parent_tail, &head_oid);
return NULL;
/* Do we have HEAD? */
return NULL;
/* 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;
head_commit = lookup_commit_reference_gently(&head_oid, 1);
if (!head_commit)
return NULL;
head_commit = lookup_commit_reference_gently(&head_oid, 1);
if (!head_commit)
if (verbose)
fprintf(stderr, "Checking HEAD link\n");
if (verbose)
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) {
errors_found |= ERROR_REFS;
return error("Invalid HEAD");
if (!head_points_at) {
errors_found |= ERROR_REFS;
return error("Invalid HEAD");
const char *result;
result = refs_resolve_ref_unsafe(refs, refname, resolve_flags,
const char *result;
result = refs_resolve_ref_unsafe(refs, refname, resolve_flags,
return xstrdup_or_null(result);
}
return xstrdup_or_null(result);
}
int refs_read_ref_full(struct ref_store *refs, const char *refname,
int resolve_flags, struct object_id *oid, int *flags)
{
int refs_read_ref_full(struct ref_store *refs, const char *refname,
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))
strbuf_reset(&fullref);
strbuf_addf(&fullref, *p, len, str);
r = resolve_ref_unsafe(fullref.buf, RESOLVE_REF_READING,
strbuf_reset(&fullref);
strbuf_addf(&fullref, *p, len, str);
r = resolve_ref_unsafe(fullref.buf, RESOLVE_REF_READING,
- this_result ? this_result->hash : NULL,
- &flag);
if (r) {
if (!refs_found++)
*ref = xstrdup(r);
if (r) {
if (!refs_found++)
*ref = xstrdup(r);
strbuf_reset(&path);
strbuf_addf(&path, *p, len, str);
ref = resolve_ref_unsafe(path.buf, RESOLVE_REF_READING,
strbuf_reset(&path);
strbuf_addf(&path, *p, len, str);
ref = resolve_ref_unsafe(path.buf, RESOLVE_REF_READING,
if (!ref)
continue;
if (reflog_exists(path.buf))
if (!ref)
continue;
if (reflog_exists(path.buf))
const char *refs_resolve_ref_unsafe(struct ref_store *refs,
const char *refname,
int resolve_flags,
const char *refs_resolve_ref_unsafe(struct ref_store *refs,
const char *refname,
int resolve_flags,
- unsigned char *sha1 , int *flags)
+ struct object_id *oid , int *flags)
{
static struct strbuf sb_refname = STRBUF_INIT;
struct object_id unused_oid;
int unused_flags;
int symref_count;
{
static struct strbuf sb_refname = STRBUF_INIT;
struct object_id unused_oid;
int unused_flags;
int symref_count;
- if (!sha1 )
- sha1 = unused_oid.hash ;
+ if (!oid )
+ oid = &unused_oid ;
if (!flags)
flags = &unused_flags;
if (!flags)
flags = &unused_flags;
unsigned int read_flags = 0;
if (refs_read_raw_ref(refs, refname,
unsigned int read_flags = 0;
if (refs_read_raw_ref(refs, refname,
- sha1 , &sb_refname, &read_flags)) {
+ oid->hash , &sb_refname, &read_flags)) {
*flags |= read_flags;
/* In reading mode, refs must eventually resolve */
*flags |= read_flags;
/* In reading mode, refs must eventually resolve */
errno != ENOTDIR)
return NULL;
errno != ENOTDIR)
return NULL;
if (*flags & REF_BAD_NAME)
*flags |= REF_ISBROKEN;
return refname;
if (*flags & REF_BAD_NAME)
*flags |= REF_ISBROKEN;
return refname;
if (!(read_flags & REF_ISSYMREF)) {
if (*flags & REF_BAD_NAME) {
if (!(read_flags & REF_ISSYMREF)) {
if (*flags & REF_BAD_NAME) {
*flags |= REF_ISBROKEN;
}
return refname;
*flags |= REF_ISBROKEN;
}
return refname;
refname = sb_refname.buf;
if (resolve_flags & RESOLVE_REF_NO_RECURSE) {
refname = sb_refname.buf;
if (resolve_flags & RESOLVE_REF_NO_RECURSE) {
return refname;
}
if (check_refname_format(refname, REFNAME_ALLOW_ONELEVEL)) {
return refname;
}
if (check_refname_format(refname, REFNAME_ALLOW_ONELEVEL)) {
}
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,
- 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))
return -1;
return 0;
is_null_oid(oid))
return -1;
return 0;
* at the resolved object name. The return value, if not NULL, is a
* pointer into either a static buffer or the input ref.
*
* at the resolved object name. The return value, if not NULL, is a
* 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
* depends on the RESOLVE_REF_READING flag:
*
* - If RESOLVE_REF_READING is set, return NULL.
*
*
* If the reference cannot be resolved to an object, the behavior
* depends on the RESOLVE_REF_READING flag:
*
* - 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
* reference or an undefined reference. If this is a prelude to
* "writing" to the ref, the return value is the name of the ref
* that will actually be created or changed.
*
* If the RESOLVE_REF_NO_RECURSE flag is passed, only resolves one
* 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
* "writing" to the ref, the return value is the name of the ref
* that will actually be created or changed.
*
* If the RESOLVE_REF_NO_RECURSE flag is passed, only resolves one
- * level of symbolic reference. The value stored in sha1 for a symbolic
- * reference will always be null_sha1 in this case, and the return
+ * level of symbolic reference. The value stored in oid for a symbolic
+ * reference will always be null_oid in this case, and the return
* value is the reference that the symref refers to directly.
*
* If flags is non-NULL, set the value that it points to the
* value is the reference that the symref refers to directly.
*
* If flags is non-NULL, set the value that it points to the
*
* RESOLVE_REF_ALLOW_BAD_NAME allows resolving refs even when their
* name is invalid according to git-check-ref-format(1). If the name
*
* RESOLVE_REF_ALLOW_BAD_NAME allows resolving refs even when their
* 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.
*
* Even with RESOLVE_REF_ALLOW_BAD_NAME, names that escape the refs/
* flags REF_ISBROKEN and REF_BAD_NAME will be set.
*
* Even with RESOLVE_REF_ALLOW_BAD_NAME, names that escape the refs/
const char *refs_resolve_ref_unsafe(struct ref_store *refs,
const char *refname,
int resolve_flags,
const char *refs_resolve_ref_unsafe(struct ref_store *refs,
const char *refname,
int resolve_flags,
int *flags);
const char *resolve_ref_unsafe(const char *refname, int resolve_flags,
int *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,
const char *refname, int resolve_flags,
char *refs_resolve_refdup(struct ref_store *refs,
const char *refname, int resolve_flags,
if (!refs_resolve_ref_unsafe(&refs->base,
refname.buf,
RESOLVE_REF_READING,
if (!refs_resolve_ref_unsafe(&refs->base,
refname.buf,
RESOLVE_REF_READING,
oidclr(&oid);
flag |= REF_ISBROKEN;
} else if (is_null_oid(&oid)) {
oidclr(&oid);
flag |= REF_ISBROKEN;
} else if (is_null_oid(&oid)) {
files_ref_path(refs, &ref_file, refname);
resolved = !!refs_resolve_ref_unsafe(&refs->base,
refname, resolve_flags,
files_ref_path(refs, &ref_file, refname);
resolved = !!refs_resolve_ref_unsafe(&refs->base,
refname, resolve_flags,
- lock->old_oid.hash , type);
if (!resolved && errno == EISDIR) {
/*
* we are trying to lock foo but we used to
if (!resolved && errno == EISDIR) {
/*
* we are trying to lock foo but we used to
}
resolved = !!refs_resolve_ref_unsafe(&refs->base,
refname, resolve_flags,
}
resolved = !!refs_resolve_ref_unsafe(&refs->base,
refname, resolve_flags,
- lock->old_oid.hash , type);
}
if (!resolved) {
last_errno = errno;
}
if (!resolved) {
last_errno = errno;
if (!refs_resolve_ref_unsafe(&refs->base, oldrefname,
RESOLVE_REF_READING | RESOLVE_REF_NO_RECURSE,
if (!refs_resolve_ref_unsafe(&refs->base, oldrefname,
RESOLVE_REF_READING | RESOLVE_REF_NO_RECURSE,
- orig_oid.hash , &flag)) {
ret = error("refname %s not found", oldrefname);
goto out;
}
ret = error("refname %s not found", oldrefname);
goto out;
}
struct object_id head_oid;
struct commit *head_commit;
struct object_id head_oid;
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"));
head_commit = lookup_commit(&head_oid);
return error(_("could not resolve HEAD commit\n"));
head_commit = lookup_commit(&head_oid);
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] ;
const char *refname = notnull(*argv++, "refname");
int resolve_flags = arg_flags(*argv++, "resolve-flags");
int flags;
const char *ref;
ref = refs_resolve_ref_unsafe(refs, refname, resolve_flags,
const char *refname = notnull(*argv++, "refname");
int resolve_flags = arg_flags(*argv++, "resolve-flags");
int flags;
const char *ref;
ref = refs_resolve_ref_unsafe(refs, refname, resolve_flags,
- sha1 , &flags);
- printf("%s %s 0x%x\n", sha1_to_hex(sha1 ), ref, flags);
+ &oid , &flags);
+ printf("%s %s 0x%x\n", oid_to_hex(&oid ), ref, flags);
int flag;
/* Follow symbolic refs (mainly for HEAD). */
int flag;
/* Follow symbolic refs (mainly for HEAD). */
- name = resolve_ref_unsafe(
- ref->peer_ref->name,
- RESOLVE_REF_READING,
- oid.hash, &flag);
+ name = resolve_ref_unsafe(ref->peer_ref->name,
+ RESOLVE_REF_READING,
+ &oid, &flag);
if (!name || !(flag & REF_ISSYMREF))
name = ref->peer_ref->name;
if (!name || !(flag & REF_ISSYMREF))
name = ref->peer_ref->name;
target = refs_resolve_ref_unsafe(get_worktree_ref_store(wt),
"HEAD",
0,
target = refs_resolve_ref_unsafe(get_worktree_ref_store(wt),
"HEAD",
0,
- wt->head_oid.hash , &flags);
+ &wt->head_oid , &flags);