refs: convert resolve_ref_unsafe to struct object_id
authorbrian m. carlson <sandals@crustytoothpaste.net>
Sun, 15 Oct 2017 22:07:09 +0000 (22:07 +0000)
committerJunio C Hamano <gitster@pobox.com>
Mon, 16 Oct 2017 02:05:51 +0000 (11:05 +0900)
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>
blame.c
builtin/fsck.c
refs.c
refs.h
refs/files-backend.c
sequencer.c
t/helper/test-ref-store.c
transport-helper.c
worktree.c
diff --git a/blame.c b/blame.c
index f575e9cbf4e3224049fe43b7f794d2dd8770eda7..c3060de2f87f9cdc598019663186755b52a31953 100644 (file)
--- a/blame.c
+++ b/blame.c
@@ -166,7 +166,7 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt,
        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);
@@ -1689,7 +1689,7 @@ static struct commit *dwim_reverse_initial(struct rev_info *revs,
                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)
index 56afe405b8072b3099a23661ac586f673e54ff0e..5f91116d7303ec126593ce0b764f8ea4ad96155d 100644 (file)
@@ -555,7 +555,7 @@ static int fsck_head_link(void)
        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");
diff --git a/refs.c b/refs.c
index 90219d6e132eb134db9918d06d388ede0513ef80..72c45a513b967799cbfb7a94bbf9c2c4eea72663 100644 (file)
--- a/refs.c
+++ b/refs.c
@@ -199,7 +199,7 @@ char *refs_resolve_refdup(struct ref_store *refs,
        const char *result;
 
        result = refs_resolve_ref_unsafe(refs, refname, resolve_flags,
-                                        oid->hash, flags);
+                                        oid, flags);
        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 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 -1;
 }
@@ -480,8 +480,7 @@ int expand_ref(const char *str, int len, struct object_id *oid, char **ref)
                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);
+                                      this_result, &flag);
                if (r) {
                        if (!refs_found++)
                                *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_addf(&path, *p, len, str);
                ref = resolve_ref_unsafe(path.buf, RESOLVE_REF_READING,
-                                        hash.hash, NULL);
+                                        &hash, NULL);
                if (!ref)
                        continue;
                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 *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;
 
-       if (!sha1)
-               sha1 = unused_oid.hash;
+       if (!oid)
+               oid = &unused_oid;
        if (!flags)
                flags = &unused_flags;
 
@@ -1429,7 +1428,7 @@ const char *refs_resolve_ref_unsafe(struct ref_store *refs,
                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 */
@@ -1446,7 +1445,7 @@ const char *refs_resolve_ref_unsafe(struct ref_store *refs,
                            errno != ENOTDIR)
                                return NULL;
 
-                       hashclr(sha1);
+                       oidclr(oid);
                        if (*flags & REF_BAD_NAME)
                                *flags |= REF_ISBROKEN;
                        return refname;
@@ -1456,7 +1455,7 @@ const char *refs_resolve_ref_unsafe(struct ref_store *refs,
 
                if (!(read_flags & REF_ISSYMREF)) {
                        if (*flags & REF_BAD_NAME) {
-                               hashclr(sha1);
+                               oidclr(oid);
                                *flags |= REF_ISBROKEN;
                        }
                        return refname;
@@ -1464,7 +1463,7 @@ const char *refs_resolve_ref_unsafe(struct ref_store *refs,
 
                refname = sb_refname.buf;
                if (resolve_flags & RESOLVE_REF_NO_RECURSE) {
-                       hashclr(sha1);
+                       oidclr(oid);
                        return refname;
                }
                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,
-                              unsigned char *sha1, int *flags)
+                              struct object_id *oid, int *flags)
 {
        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,
@@ -1508,7 +1507,7 @@ int resolve_gitlink_ref(const char *submodule, const char *refname,
        if (!refs)
                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))
                return -1;
        return 0;
diff --git a/refs.h b/refs.h
index ee07a457af4aed413ce2a96db50f3d5ea7ea7b1e..15fd419c7d595f4c08650eb821a3d10e77688ade 100644 (file)
--- a/refs.h
+++ b/refs.h
@@ -14,22 +14,22 @@ struct worktree;
  * 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 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
- * 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
@@ -46,7 +46,7 @@ struct worktree;
  *
  * 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/
@@ -62,10 +62,10 @@ struct worktree;
 const char *refs_resolve_ref_unsafe(struct ref_store *refs,
                                    const char *refname,
                                    int resolve_flags,
-                                   unsigned char *sha1,
+                                   struct object_id *oid,
                                    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,
index 3ff5dc5b1c48f4c0044b1c3d5a69ce6b27c7a713..8bf2ef8a770fc73eeb41ea751bc2cf8673fb6b2f 100644 (file)
@@ -189,7 +189,7 @@ static void loose_fill_ref_dir(struct ref_store *ref_store,
                        if (!refs_resolve_ref_unsafe(&refs->base,
                                                     refname.buf,
                                                     RESOLVE_REF_READING,
-                                                    oid.hash, &flag)) {
+                                                    &oid, &flag)) {
                                oidclr(&oid);
                                flag |= REF_ISBROKEN;
                        } 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);
        resolved = !!refs_resolve_ref_unsafe(&refs->base,
                                             refname, resolve_flags,
-                                            lock->old_oid.hash, type);
+                                            &lock->old_oid, type);
        if (!resolved && errno == EISDIR) {
                /*
                 * 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,
                                                     refname, resolve_flags,
-                                                    lock->old_oid.hash, type);
+                                                    &lock->old_oid, type);
        }
        if (!resolved) {
                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,
                                     RESOLVE_REF_READING | RESOLVE_REF_NO_RECURSE,
-                               orig_oid.hash, &flag)) {
+                               &orig_oid, &flag)) {
                ret = error("refname %s not found", oldrefname);
                goto out;
        }
index 3031e7364d74e995297a7b8a72e04655c2ea3421..0d20ac760a3e2b0a16794ee33f496ff179d1bf5a 100644 (file)
@@ -489,7 +489,7 @@ static int is_index_unchanged(void)
        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);
index cea3285ada4bc16bf07d227e8e83c0d7eb5961ac..d846c88ed26fb985af3cb6c9c03ec978069063a4 100644 (file)
@@ -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)
 {
-       unsigned char sha1[20];
+       struct object_id oid;
        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);
        return ref ? 0 : 1;
 }
 
index 640ce5a492d1ef9dcb6c42e78e2d695069413f77..bf05a2dcf1073ad3b84b030cd9e866c6e5414792 100644 (file)
@@ -942,10 +942,9 @@ static int push_refs_with_export(struct transport *transport,
                                        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;
 
index cb35db03faf3e440ea5afe4fca27c24afb5f1a2b..2799abd555c774c7f510aba3321b669c74170941 100644 (file)
@@ -31,7 +31,7 @@ static void add_head_info(struct worktree *wt)
        target = refs_resolve_ref_unsafe(get_worktree_ref_store(wt),
                                         "HEAD",
                                         0,
-                                        wt->head_oid.hash, &flags);
+                                        &wt->head_oid, &flags);
        if (!target)
                return;