Re: [PATCH 11/23] files_transaction_cleanup(): new helper function
- From
Michael Haggerty <mhagger@alum.mit.edu>
- Date
- May 19, 2017, 04:49 UTC
- Message-ID
- <c8eb0a01-9d7d-a8c6-c1bc-31743d677883@alum.mit.edu>
- In-Reply-To
- <20170517131958.nxb5ol3wrtwyskss@sigill.intra.peff.net>
On 05/17/2017 03:19 PM, Jeff King wrote:
Show 20 quoted lines
> On Wed, May 17, 2017 at 02:05:34PM +0200, Michael Haggerty wrote:
>
>> Extract function from `files_transaction_commit()`. It will soon have
>> another caller.
>> [...]
>> @@ -2868,10 +2889,8 @@ static int files_transaction_commit(struct ref_store *ref_store,
>> if (transaction->state != REF_TRANSACTION_OPEN)
>> die("BUG: commit called for transaction that is not open");
>>
>> - if (!transaction->nr) {
>> - transaction->state = REF_TRANSACTION_CLOSED;
>> - return 0;
>> - }
>> + if (!transaction->nr)
>> + goto cleanup;
>
> This is slightly more than it says on the tin. I guess the reason is
> that the cleanup function is going to learn about more than just
> iterating over the transaction, and we'll want to trigger it even for
> empty transactions.Mostly this is just DRY. For example, later the cleanup will be changed to set the state to `REF_TRANSACTION_PREPARED` rather than `REF_TRANSACTION_CLOSED`, and that change will be able to be made in one place rather than two. I'll mention this in the commit message.
Michael