[PATCH 09/11] fast-import.c: change update_branch to use ref transactions
From: Ronnie Sahlberg <hidden>
Date: 2016-06-15 23:00:43
Subsystem:
the rest · Maintainer:
Linus Torvalds
Change update_branch() to use ref transactions for updates. Signed-off-by: Ronnie Sahlberg <redacted> --- fast-import.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-)
diff --git a/fast-import.c b/fast-import.c
index fb4738d..466dfe3 100644
--- a/fast-import.c
+++ b/fast-import.c@@ -1678,36 +1678,43 @@ found_entry: static int update_branch(struct branch *b) { static const char *msg = "fast-import"; - struct ref_lock *lock; + struct ref_transaction *transaction; unsigned char old_sha1[20]; if (is_null_sha1(b->sha1)) return 0; if (read_ref(b->name, old_sha1)) hashclr(old_sha1); - lock = lock_any_ref_for_update(b->name, old_sha1, 0, NULL); - if (!lock) - return error("Unable to lock %s", b->name); + transaction = ref_transaction_begin(); + if (!transaction) + return error("Unable to begin transaction for %s", b->name); if (!force_update && !is_null_sha1(old_sha1)) { struct commit *old_cmit, *new_cmit; old_cmit = lookup_commit_reference_gently(old_sha1, 0); new_cmit = lookup_commit_reference_gently(b->sha1, 0); if (!old_cmit || !new_cmit) { - unlock_ref(lock); + ref_transaction_rollback(transaction); return error("Branch %s is missing commits.", b->name); } if (!in_merge_bases(old_cmit, new_cmit)) { - unlock_ref(lock); + ref_transaction_rollback(transaction); warning("Not updating %s" " (new tip %s does not contain %s)", b->name, sha1_to_hex(b->sha1), sha1_to_hex(old_sha1)); return -1; } } - if (write_ref_sha1(lock, b->sha1, msg) < 0) - return error("Unable to update %s", b->name); + if (ref_transaction_update(transaction, b->name, b->sha1, old_sha1, + 0, 1)) { + ref_transaction_rollback(transaction); + return error("Unable to update transaction for %s", b->name); + } + if (ref_transaction_commit(transaction, msg, + UPDATE_REFS_QUIET_ON_ERR)) + return error("Unable to commit transaction for %s", b->name); + return 0; }
--
1.9.1.513.gd486896