Skip to content

Commit de7e86f

Browse files
rsahlberggitster
authored andcommitted
fast-import.c: change update_branch to use ref transactions
Change update_branch() to use ref transactions for updates. Signed-off-by: Ronnie Sahlberg <sahlberg@google.com> Reviewed-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent d668d16 commit de7e86f

1 file changed

Lines changed: 15 additions & 10 deletions

File tree

fast-import.c

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1679,8 +1679,9 @@ static int tree_content_get(
16791679
static int update_branch(struct branch *b)
16801680
{
16811681
static const char *msg = "fast-import";
1682-
struct ref_lock *lock;
1682+
struct ref_transaction *transaction;
16831683
unsigned char old_sha1[20];
1684+
struct strbuf err = STRBUF_INIT;
16841685

16851686
if (read_ref(b->name, old_sha1))
16861687
hashclr(old_sha1);
@@ -1689,29 +1690,33 @@ static int update_branch(struct branch *b)
16891690
delete_ref(b->name, old_sha1, 0);
16901691
return 0;
16911692
}
1692-
lock = lock_any_ref_for_update(b->name, old_sha1, 0, NULL);
1693-
if (!lock)
1694-
return error("Unable to lock %s", b->name);
16951693
if (!force_update && !is_null_sha1(old_sha1)) {
16961694
struct commit *old_cmit, *new_cmit;
16971695

16981696
old_cmit = lookup_commit_reference_gently(old_sha1, 0);
16991697
new_cmit = lookup_commit_reference_gently(b->sha1, 0);
1700-
if (!old_cmit || !new_cmit) {
1701-
unlock_ref(lock);
1698+
if (!old_cmit || !new_cmit)
17021699
return error("Branch %s is missing commits.", b->name);
1703-
}
17041700

17051701
if (!in_merge_bases(old_cmit, new_cmit)) {
1706-
unlock_ref(lock);
17071702
warning("Not updating %s"
17081703
" (new tip %s does not contain %s)",
17091704
b->name, sha1_to_hex(b->sha1), sha1_to_hex(old_sha1));
17101705
return -1;
17111706
}
17121707
}
1713-
if (write_ref_sha1(lock, b->sha1, msg) < 0)
1714-
return error("Unable to update %s", b->name);
1708+
transaction = ref_transaction_begin(&err);
1709+
if (!transaction ||
1710+
ref_transaction_update(transaction, b->name, b->sha1, old_sha1,
1711+
0, 1, &err) ||
1712+
ref_transaction_commit(transaction, msg, &err)) {
1713+
ref_transaction_free(transaction);
1714+
error("%s", err.buf);
1715+
strbuf_release(&err);
1716+
return -1;
1717+
}
1718+
ref_transaction_free(transaction);
1719+
strbuf_release(&err);
17151720
return 0;
17161721
}
17171722

0 commit comments

Comments
 (0)