refs: convert resolve_ref_unsafe to struct object_id
[gitweb.git] / refs / files-backend.c
index 014dabb0bf3647b9392d6087ebf6c40e1bc68108..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)) {
@@ -782,7 +782,7 @@ static int verify_lock(struct ref_store *ref_store, struct ref_lock *lock,
 
        if (refs_read_ref_full(ref_store, lock->ref_name,
                               mustexist ? RESOLVE_REF_READING : 0,
-                              lock->old_oid.hash, NULL)) {
+                              &lock->old_oid, NULL)) {
                if (old_sha1) {
                        int save_errno = errno;
                        strbuf_addf(err, "can't verify ref '%s'", lock->ref_name);
@@ -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;
@@ -926,7 +926,7 @@ static struct ref_lock *lock_ref_sha1_basic(struct files_ref_store *refs,
 
 struct ref_to_prune {
        struct ref_to_prune *next;
-       unsigned char sha1[20];
+       struct object_id oid;
        char name[FLEX_ARRAY];
 };
 
@@ -994,7 +994,7 @@ static void prune_ref(struct files_ref_store *refs, struct ref_to_prune *r)
 
        transaction = ref_store_transaction_begin(&refs->base, &err);
        if (!transaction ||
-           ref_transaction_delete(transaction, r->name, r->sha1,
+           ref_transaction_delete(transaction, r->name, &r->oid,
                                   REF_ISPRUNING | REF_NODEREF, NULL, &err) ||
            ref_transaction_commit(transaction, &err)) {
                ref_transaction_free(transaction);
@@ -1079,7 +1079,7 @@ static int files_pack_refs(struct ref_store *ref_store, unsigned int flags)
                 * packed-refs transaction:
                 */
                if (ref_transaction_update(transaction, iter->refname,
-                                          iter->oid->hash, NULL,
+                                          iter->oid, NULL,
                                           REF_NODEREF, NULL, &err))
                        die("failure preparing to create packed reference %s: %s",
                            iter->refname, err.buf);
@@ -1088,7 +1088,7 @@ static int files_pack_refs(struct ref_store *ref_store, unsigned int flags)
                if ((flags & PACK_REFS_PRUNE)) {
                        struct ref_to_prune *n;
                        FLEX_ALLOC_STR(n, name, iter->refname);
-                       hashcpy(n->sha1, iter->oid->hash);
+                       oidcpy(&n->oid, iter->oid);
                        n->next = refs_to_prune;
                        refs_to_prune = n;
                }
@@ -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;
        }
@@ -1283,7 +1283,7 @@ static int files_copy_or_rename_ref(struct ref_store *ref_store,
        }
 
        if (!copy && refs_delete_ref(&refs->base, logmsg, oldrefname,
-                           orig_oid.hash, REF_NODEREF)) {
+                           &orig_oid, REF_NODEREF)) {
                error("unable to delete old %s", oldrefname);
                goto rollback;
        }
@@ -1297,7 +1297,7 @@ static int files_copy_or_rename_ref(struct ref_store *ref_store,
         */
        if (!copy && !refs_read_ref_full(&refs->base, newrefname,
                                RESOLVE_REF_READING | RESOLVE_REF_NO_RECURSE,
-                               oid.hash, NULL) &&
+                               &oid, NULL) &&
            refs_delete_ref(&refs->base, NULL, newrefname,
                            NULL, REF_NODEREF)) {
                if (errno == EISDIR) {
@@ -1721,7 +1721,7 @@ static void update_symref_reflog(struct files_ref_store *refs,
        struct object_id new_oid;
        if (logmsg &&
            !refs_read_ref_full(&refs->base, target,
-                               RESOLVE_REF_READING, new_oid.hash, NULL) &&
+                               RESOLVE_REF_READING, &new_oid, NULL) &&
            files_log_ref_write(refs, refname, &lock->old_oid,
                                &new_oid, logmsg, 0, &err)) {
                error("%s", err.buf);
@@ -2010,7 +2010,7 @@ static int files_reflog_iterator_advance(struct ref_iterator *ref_iterator)
 
                if (refs_read_ref_full(iter->ref_store,
                                       diter->relative_path, 0,
-                                      iter->oid.hash, &flags)) {
+                                      &iter->oid, &flags)) {
                        error("bad ref for %s", diter->path.buf);
                        continue;
                }
@@ -2148,7 +2148,7 @@ static int split_head_update(struct ref_update *update,
        new_update = ref_transaction_add_update(
                        transaction, "HEAD",
                        update->flags | REF_LOG_ONLY | REF_NODEREF,
-                       update->new_oid.hash, update->old_oid.hash,
+                       &update->new_oid, &update->old_oid,
                        update->msg);
 
        /*
@@ -2212,7 +2212,7 @@ static int split_symref_update(struct files_ref_store *refs,
 
        new_update = ref_transaction_add_update(
                        transaction, referent, new_flags,
-                       update->new_oid.hash, update->old_oid.hash,
+                       &update->new_oid, &update->old_oid,
                        update->msg);
 
        new_update->parent_update = update;
@@ -2347,7 +2347,7 @@ static int lock_ref_for_update(struct files_ref_store *refs,
                         */
                        if (refs_read_ref_full(&refs->base,
                                               referent.buf, 0,
-                                              lock->old_oid.hash, NULL)) {
+                                              &lock->old_oid, NULL)) {
                                if (update->flags & REF_HAVE_OLD) {
                                        strbuf_addf(err, "cannot lock ref '%s': "
                                                    "error reading reference",
@@ -2594,7 +2594,7 @@ static int files_transaction_prepare(struct ref_store *ref_store,
                        ref_transaction_add_update(
                                        packed_transaction, update->refname,
                                        update->flags & ~REF_HAVE_OLD,
-                                       update->new_oid.hash, update->old_oid.hash,
+                                       &update->new_oid, &update->old_oid,
                                        NULL);
                }
        }
@@ -2847,7 +2847,7 @@ static int files_initial_transaction_commit(struct ref_store *ref_store,
                 */
                ref_transaction_add_update(packed_transaction, update->refname,
                                           update->flags & ~REF_HAVE_OLD,
-                                          update->new_oid.hash, update->old_oid.hash,
+                                          &update->new_oid, &update->old_oid,
                                           NULL);
        }
 
@@ -2908,7 +2908,7 @@ static int expire_reflog_ent(struct object_id *ooid, struct object_id *noid,
 }
 
 static int files_reflog_expire(struct ref_store *ref_store,
-                              const char *refname, const unsigned char *sha1,
+                              const char *refname, const struct object_id *oid,
                               unsigned int flags,
                               reflog_expiry_prepare_fn prepare_fn,
                               reflog_expiry_should_prune_fn should_prune_fn,
@@ -2925,7 +2925,6 @@ static int files_reflog_expire(struct ref_store *ref_store,
        int status = 0;
        int type;
        struct strbuf err = STRBUF_INIT;
-       struct object_id oid;
 
        memset(&cb, 0, sizeof(cb));
        cb.flags = flags;
@@ -2937,7 +2936,7 @@ static int files_reflog_expire(struct ref_store *ref_store,
         * reference itself, plus we might need to update the
         * reference if --updateref was specified:
         */
-       lock = lock_ref_sha1_basic(refs, refname, sha1,
+       lock = lock_ref_sha1_basic(refs, refname, oid->hash,
                                   NULL, NULL, REF_NODEREF,
                                   &type, &err);
        if (!lock) {
@@ -2975,9 +2974,7 @@ static int files_reflog_expire(struct ref_store *ref_store,
                }
        }
 
-       hashcpy(oid.hash, sha1);
-
-       (*prepare_fn)(refname, &oid, cb.policy_cb);
+       (*prepare_fn)(refname, oid, cb.policy_cb);
        refs_for_each_reflog_ent(ref_store, refname, expire_reflog_ent, &cb);
        (*cleanup_fn)(cb.policy_cb);