commit_packed_refs(): use a staging file separate from the lockfile
[gitweb.git] / refs / files-backend.c
index 7df974779858db1e6182ebf01f8e9621dece14a1..2810785efcfe2244847b87199fa332004607f0de 100644 (file)
@@ -28,7 +28,7 @@ struct files_ref_store {
 
        struct ref_cache *loose;
 
-       struct packed_ref_store *packed_ref_store;
+       struct ref_store *packed_ref_store;
 };
 
 static void clear_loose_ref_cache(struct files_ref_store *refs)
@@ -311,8 +311,8 @@ static int files_read_raw_ref(struct ref_store *ref_store,
        if (lstat(path, &st) < 0) {
                if (errno != ENOENT)
                        goto out;
-               if (packed_read_raw_ref(refs->packed_ref_store, refname,
-                                       sha1, referent, type)) {
+               if (refs_read_raw_ref(refs->packed_ref_store, refname,
+                                     sha1, referent, type)) {
                        errno = ENOENT;
                        goto out;
                }
@@ -351,8 +351,8 @@ static int files_read_raw_ref(struct ref_store *ref_store,
                 * ref is supposed to be, there could still be a
                 * packed ref:
                 */
-               if (packed_read_raw_ref(refs->packed_ref_store, refname,
-                                       sha1, referent, type)) {
+               if (refs_read_raw_ref(refs->packed_ref_store, refname,
+                                     sha1, referent, type)) {
                        errno = EISDIR;
                        goto out;
                }
@@ -683,7 +683,7 @@ static int files_peel_ref(struct ref_store *ref_store,
         * have REF_KNOWS_PEELED.
         */
        if (flag & REF_ISPACKED &&
-           !packed_peel_ref(refs->packed_ref_store, refname, sha1))
+           !refs_peel_ref(refs->packed_ref_store, refname, sha1))
                return 0;
 
        return peel_object(base, sha1);
@@ -804,8 +804,8 @@ static struct ref_iterator *files_ref_iterator_begin(
         * ones in files_ref_iterator_advance(), after we have merged
         * the packed and loose references.
         */
-       packed_iter = packed_ref_iterator_begin(
-                       refs->packed_ref_store, prefix,
+       packed_iter = refs_ref_iterator_begin(
+                       refs->packed_ref_store, prefix, 0,
                        DO_FOR_EACH_INCLUDE_BROKEN);
 
        iter->iter0 = overlay_ref_iterator_begin(loose_iter, packed_iter);
@@ -1094,6 +1094,7 @@ static int files_pack_refs(struct ref_store *ref_store, unsigned int flags)
        struct ref_iterator *iter;
        int ok;
        struct ref_to_prune *refs_to_prune = NULL;
+       struct strbuf err = STRBUF_INIT;
 
        lock_packed_refs(refs->packed_ref_store, LOCK_DIE_ON_ERROR);
 
@@ -1128,10 +1129,11 @@ static int files_pack_refs(struct ref_store *ref_store, unsigned int flags)
        if (ok != ITER_DONE)
                die("error while iterating over references");
 
-       if (commit_packed_refs(refs->packed_ref_store))
-               die_errno("unable to overwrite old ref-pack file");
+       if (commit_packed_refs(refs->packed_ref_store, &err))
+               die("unable to overwrite old ref-pack file: %s", err.buf);
 
        prune_refs(refs, refs_to_prune);
+       strbuf_release(&err);
        return 0;
 }
 
@@ -2693,9 +2695,7 @@ static int files_initial_transaction_commit(struct ref_store *ref_store,
                                       &update->new_oid);
        }
 
-       if (commit_packed_refs(refs->packed_ref_store)) {
-               strbuf_addf(err, "unable to commit packed-refs file: %s",
-                           strerror(errno));
+       if (commit_packed_refs(refs->packed_ref_store, err)) {
                ret = TRANSACTION_GENERIC_ERROR;
                goto cleanup;
        }