Skip to content

Commit 27d03d0

Browse files
mhaggergitster
authored andcommitted
files_pack_refs(): use a reference transaction to write packed refs
Now that the packed reference store supports transactions, we can use a transaction to write the packed versions of references that we want to pack. This decreases the coupling between `files_ref_store` and `packed_ref_store`. Signed-off-by: Michael Haggerty <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2fb330c commit 27d03d0

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

refs/files-backend.c

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,6 +1100,11 @@ static int files_pack_refs(struct ref_store *ref_store, unsigned int flags)
11001100
int ok;
11011101
struct ref_to_prune *refs_to_prune = NULL;
11021102
struct strbuf err = STRBUF_INIT;
1103+
struct ref_transaction *transaction;
1104+
1105+
transaction = ref_store_transaction_begin(refs->packed_ref_store, &err);
1106+
if (!transaction)
1107+
return -1;
11031108

11041109
packed_refs_lock(refs->packed_ref_store, LOCK_DIE_ON_ERROR, &err);
11051110

@@ -1115,12 +1120,14 @@ static int files_pack_refs(struct ref_store *ref_store, unsigned int flags)
11151120
continue;
11161121

11171122
/*
1118-
* Create an entry in the packed-refs cache equivalent
1119-
* to the one from the loose ref cache, except that
1120-
* we don't copy the peeled status, because we want it
1121-
* to be re-peeled.
1123+
* Add a reference creation for this reference to the
1124+
* packed-refs transaction:
11221125
*/
1123-
add_packed_ref(refs->packed_ref_store, iter->refname, iter->oid);
1126+
if (ref_transaction_update(transaction, iter->refname,
1127+
iter->oid->hash, NULL,
1128+
REF_NODEREF, NULL, &err))
1129+
die("failure preparing to create packed reference %s: %s",
1130+
iter->refname, err.buf);
11241131

11251132
/* Schedule the loose reference for pruning if requested. */
11261133
if ((flags & PACK_REFS_PRUNE)) {
@@ -1134,8 +1141,11 @@ static int files_pack_refs(struct ref_store *ref_store, unsigned int flags)
11341141
if (ok != ITER_DONE)
11351142
die("error while iterating over references");
11361143

1137-
if (commit_packed_refs(refs->packed_ref_store, &err))
1138-
die("unable to overwrite old ref-pack file: %s", err.buf);
1144+
if (ref_transaction_commit(transaction, &err))
1145+
die("unable to write new packed-refs: %s", err.buf);
1146+
1147+
ref_transaction_free(transaction);
1148+
11391149
packed_refs_unlock(refs->packed_ref_store);
11401150

11411151
prune_refs(refs, refs_to_prune);

0 commit comments

Comments
 (0)