files_transaction_cleanup(): new helper function
Extract the cleanup functionality from `files_transaction_commit()` into a new function. It will soon have another caller. Use the common cleanup code even on early exit if the transaction is empty, to reduce code duplication. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
00d174489e
commit
c0ca935764
@ -2834,6 +2834,27 @@ static int lock_ref_for_update(struct files_ref_store *refs,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Unlock any references in `transaction` that are still locked, and
|
||||||
|
* mark the transaction closed.
|
||||||
|
*/
|
||||||
|
static void files_transaction_cleanup(struct ref_transaction *transaction)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
for (i = 0; i < transaction->nr; i++) {
|
||||||
|
struct ref_update *update = transaction->updates[i];
|
||||||
|
struct ref_lock *lock = update->backend_data;
|
||||||
|
|
||||||
|
if (lock) {
|
||||||
|
unlock_ref(lock);
|
||||||
|
update->backend_data = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
transaction->state = REF_TRANSACTION_CLOSED;
|
||||||
|
}
|
||||||
|
|
||||||
static int files_transaction_commit(struct ref_store *ref_store,
|
static int files_transaction_commit(struct ref_store *ref_store,
|
||||||
struct ref_transaction *transaction,
|
struct ref_transaction *transaction,
|
||||||
struct strbuf *err)
|
struct strbuf *err)
|
||||||
@ -2856,10 +2877,8 @@ static int files_transaction_commit(struct ref_store *ref_store,
|
|||||||
if (transaction->state != REF_TRANSACTION_OPEN)
|
if (transaction->state != REF_TRANSACTION_OPEN)
|
||||||
die("BUG: commit called for transaction that is not open");
|
die("BUG: commit called for transaction that is not open");
|
||||||
|
|
||||||
if (!transaction->nr) {
|
if (!transaction->nr)
|
||||||
transaction->state = REF_TRANSACTION_CLOSED;
|
goto cleanup;
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Fail if a refname appears more than once in the
|
* Fail if a refname appears more than once in the
|
||||||
@ -3005,15 +3024,11 @@ static int files_transaction_commit(struct ref_store *ref_store,
|
|||||||
clear_loose_ref_cache(refs);
|
clear_loose_ref_cache(refs);
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
|
files_transaction_cleanup(transaction);
|
||||||
strbuf_release(&sb);
|
strbuf_release(&sb);
|
||||||
transaction->state = REF_TRANSACTION_CLOSED;
|
|
||||||
|
|
||||||
for (i = 0; i < transaction->nr; i++) {
|
for (i = 0; i < transaction->nr; i++) {
|
||||||
struct ref_update *update = transaction->updates[i];
|
struct ref_update *update = transaction->updates[i];
|
||||||
struct ref_lock *lock = update->backend_data;
|
|
||||||
|
|
||||||
if (lock)
|
|
||||||
unlock_ref(lock);
|
|
||||||
|
|
||||||
if (update->flags & REF_DELETED_LOOSE) {
|
if (update->flags & REF_DELETED_LOOSE) {
|
||||||
/*
|
/*
|
||||||
|
Reference in New Issue
Block a user