Skip to content

Commit 1444bfe

Browse files
mhaggergitster
authored andcommitted
files_initial_transaction_commit(): use a transaction for packed refs
Use a `packed_ref_store` transaction in the implementation of `files_initial_transaction_commit()` rather than using internal features of the packed ref store. This further decouples `files_ref_store` from `packed_ref_store`. Signed-off-by: Michael Haggerty <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 22b09cd commit 1444bfe

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

refs/files-backend.c

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2669,6 +2669,7 @@ static int files_initial_transaction_commit(struct ref_store *ref_store,
26692669
size_t i;
26702670
int ret = 0;
26712671
struct string_list affected_refnames = STRING_LIST_INIT_NODUP;
2672+
struct ref_transaction *packed_transaction = NULL;
26722673

26732674
assert(err);
26742675

@@ -2701,6 +2702,12 @@ static int files_initial_transaction_commit(struct ref_store *ref_store,
27012702
&affected_refnames))
27022703
die("BUG: initial ref transaction called with existing refs");
27032704

2705+
packed_transaction = ref_store_transaction_begin(refs->packed_ref_store, err);
2706+
if (!packed_transaction) {
2707+
ret = TRANSACTION_GENERIC_ERROR;
2708+
goto cleanup;
2709+
}
2710+
27042711
for (i = 0; i < transaction->nr; i++) {
27052712
struct ref_update *update = transaction->updates[i];
27062713

@@ -2713,28 +2720,30 @@ static int files_initial_transaction_commit(struct ref_store *ref_store,
27132720
ret = TRANSACTION_NAME_CONFLICT;
27142721
goto cleanup;
27152722
}
2723+
2724+
/*
2725+
* Add a reference creation for this reference to the
2726+
* packed-refs transaction:
2727+
*/
2728+
ref_transaction_add_update(packed_transaction, update->refname,
2729+
update->flags & ~REF_HAVE_OLD,
2730+
update->new_oid.hash, update->old_oid.hash,
2731+
NULL);
27162732
}
27172733

27182734
if (packed_refs_lock(refs->packed_ref_store, 0, err)) {
27192735
ret = TRANSACTION_GENERIC_ERROR;
27202736
goto cleanup;
27212737
}
27222738

2723-
for (i = 0; i < transaction->nr; i++) {
2724-
struct ref_update *update = transaction->updates[i];
2725-
2726-
if ((update->flags & REF_HAVE_NEW) &&
2727-
!is_null_oid(&update->new_oid))
2728-
add_packed_ref(refs->packed_ref_store, update->refname,
2729-
&update->new_oid);
2730-
}
2731-
2732-
if (commit_packed_refs(refs->packed_ref_store, err)) {
2739+
if (initial_ref_transaction_commit(packed_transaction, err)) {
27332740
ret = TRANSACTION_GENERIC_ERROR;
27342741
goto cleanup;
27352742
}
27362743

27372744
cleanup:
2745+
if (packed_transaction)
2746+
ref_transaction_free(packed_transaction);
27382747
packed_refs_unlock(refs->packed_ref_store);
27392748
transaction->state = REF_TRANSACTION_CLOSED;
27402749
string_list_clear(&affected_refnames, 0);

0 commit comments

Comments
 (0)