[PATCH 5/5] refs.c: write values to lock files early for committing
- From
Stefan Beller <sbeller@google.com>
- Date
- Jan 22, 2015, 23:11 UTC
- Message-ID
- <1421968297-25407-6-git-send-email-sbeller@google.com>
- In-Reply-To
- <1421968297-25407-1-git-send-email-sbeller@google.com>
By writing the values to the lock file early we have a better sequence of system calls. Before this commit we had
open(), close(), open(), fdopen(), write(), fclose(), rename()
Now there is:
open(), fdopen(), write(), fclose(), rename()
The first four operations are performed in the first loop of ref_transaction_commit ("/* Acquire all locks while verifying old values */"), while the renameing is left to the next loop.
Signed-off-by: Stefan Beller <sbeller@google.com> --- refs.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/refs.c b/refs.c index c108c95..3d1890f 100644 --- a/refs.c +++ b/refs.c @@ -3767,6 +3767,15 @@ int ref_transaction_commit(struct ref_transaction *transaction, update->refname); goto cleanup; } + if (!is_null_sha1(update->new_sha1)) { + if (write_ref_sha1(update->lock, update->new_sha1, + update->msg)) { + strbuf_addf(err, "Cannot update the ref '%s'.", + update->refname); + ret = TRANSACTION_GENERIC_ERROR; + goto cleanup; + } + } /* Do not keep all lock files open at the same time. */ close_ref(update->lock); } @@ -3776,9 +3785,7 @@ int ref_transaction_commit(struct ref_transaction *transaction, struct ref_update *update = updates[i]; if (!is_null_sha1(update->new_sha1)) { - if (write_ref_sha1(update->lock, update->new_sha1, - update->msg) - || commit_ref(update->lock, update->new_sha1)) { + if (commit_ref(update->lock, update->new_sha1)) { strbuf_addf(err, "Cannot update the ref '%s'.", update->refname); ret = TRANSACTION_GENERIC_ERROR;
-- 2.2.1.62.g3f15098