Skip to content

Commit 8d4240d

Browse files
mhaggergitster
authored andcommitted
ref_transaction_commit(): check for valid transaction->state
Move the check that `transaction->state` is valid from `files_transaction_commit()` to `ref_transaction_commit()`, where other future reference backends can benefit from it as well. Signed-off-by: Michael Haggerty <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c0ca935 commit 8d4240d

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

refs.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1694,6 +1694,18 @@ int ref_transaction_commit(struct ref_transaction *transaction,
16941694
{
16951695
struct ref_store *refs = transaction->ref_store;
16961696

1697+
switch (transaction->state) {
1698+
case REF_TRANSACTION_OPEN:
1699+
/* Good. */
1700+
break;
1701+
case REF_TRANSACTION_CLOSED:
1702+
die("BUG: prepare called on a closed reference transaction");
1703+
break;
1704+
default:
1705+
die("BUG: unexpected reference transaction state");
1706+
break;
1707+
}
1708+
16971709
if (getenv(GIT_QUARANTINE_ENVIRONMENT)) {
16981710
strbuf_addstr(err,
16991711
_("ref updates forbidden inside quarantine environment"));

refs/files-backend.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2874,9 +2874,6 @@ static int files_transaction_commit(struct ref_store *ref_store,
28742874

28752875
assert(err);
28762876

2877-
if (transaction->state != REF_TRANSACTION_OPEN)
2878-
die("BUG: commit called for transaction that is not open");
2879-
28802877
if (!transaction->nr)
28812878
goto cleanup;
28822879

0 commit comments

Comments
 (0)