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 <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Michael Haggerty committed
Sep 8, 2017 at 15:51 UTC
1444bfe0271a1dd46283a298e1a43c6565c38271
1 file changed
+19
-10
refs/files-backend.c
+19
-10
@@ -2669,6 +2669,7 @@ static int files_initial_transaction_commit(struct ref_store *ref_store,
2669
size_t i;
2670
int ret = 0;
2671
struct string_list affected_refnames = STRING_LIST_INIT_NODUP;
2672
+ struct ref_transaction *packed_transaction = NULL;
2673
2674
assert(err);
2675
@@ -2701,6 +2702,12 @@ static int files_initial_transaction_commit(struct ref_store *ref_store,
2702
&affected_refnames))
2703
die("BUG: initial ref transaction called with existing refs");
2704
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
+
2711
for (i = 0; i < transaction->nr; i++) {
2712
struct ref_update *update = transaction->updates[i];
2713
@@ -2713,6 +2720,15 @@ static int files_initial_transaction_commit(struct ref_store *ref_store,
2720
ret = TRANSACTION_NAME_CONFLICT;
2721
goto cleanup;
2722
}
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);
2732
}
2733
2734
if (packed_refs_lock(refs->packed_ref_store, 0, err)) {
@@ -2720,21 +2736,14 @@ static int files_initial_transaction_commit(struct ref_store *ref_store,
2736
goto cleanup;
2737
}
2738
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)) {
2740
ret = TRANSACTION_GENERIC_ERROR;
2741
goto cleanup;
2742
}
2743
2744
cleanup:
2745
+ if (packed_transaction)
2746
+ ref_transaction_free(packed_transaction);
2747
packed_refs_unlock(refs->packed_ref_store);
2748
transaction->state = REF_TRANSACTION_CLOSED;
2749
string_list_clear(&affected_refnames, 0);