mirror of
https://github.com/git/git
synced 2024-08-27 19:49:21 +00:00
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>
This commit is contained in:
parent
d668d16ca7
commit
de7e86f522
|
@ -1679,8 +1679,9 @@ static int tree_content_get(
|
||||||
static int update_branch(struct branch *b)
|
static int update_branch(struct branch *b)
|
||||||
{
|
{
|
||||||
static const char *msg = "fast-import";
|
static const char *msg = "fast-import";
|
||||||
struct ref_lock *lock;
|
struct ref_transaction *transaction;
|
||||||
unsigned char old_sha1[20];
|
unsigned char old_sha1[20];
|
||||||
|
struct strbuf err = STRBUF_INIT;
|
||||||
|
|
||||||
if (read_ref(b->name, old_sha1))
|
if (read_ref(b->name, old_sha1))
|
||||||
hashclr(old_sha1);
|
hashclr(old_sha1);
|
||||||
|
@ -1689,29 +1690,33 @@ static int update_branch(struct branch *b)
|
||||||
delete_ref(b->name, old_sha1, 0);
|
delete_ref(b->name, old_sha1, 0);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
lock = lock_any_ref_for_update(b->name, old_sha1, 0, NULL);
|
|
||||||
if (!lock)
|
|
||||||
return error("Unable to lock %s", b->name);
|
|
||||||
if (!force_update && !is_null_sha1(old_sha1)) {
|
if (!force_update && !is_null_sha1(old_sha1)) {
|
||||||
struct commit *old_cmit, *new_cmit;
|
struct commit *old_cmit, *new_cmit;
|
||||||
|
|
||||||
old_cmit = lookup_commit_reference_gently(old_sha1, 0);
|
old_cmit = lookup_commit_reference_gently(old_sha1, 0);
|
||||||
new_cmit = lookup_commit_reference_gently(b->sha1, 0);
|
new_cmit = lookup_commit_reference_gently(b->sha1, 0);
|
||||||
if (!old_cmit || !new_cmit) {
|
if (!old_cmit || !new_cmit)
|
||||||
unlock_ref(lock);
|
|
||||||
return error("Branch %s is missing commits.", b->name);
|
return error("Branch %s is missing commits.", b->name);
|
||||||
}
|
|
||||||
|
|
||||||
if (!in_merge_bases(old_cmit, new_cmit)) {
|
if (!in_merge_bases(old_cmit, new_cmit)) {
|
||||||
unlock_ref(lock);
|
|
||||||
warning("Not updating %s"
|
warning("Not updating %s"
|
||||||
" (new tip %s does not contain %s)",
|
" (new tip %s does not contain %s)",
|
||||||
b->name, sha1_to_hex(b->sha1), sha1_to_hex(old_sha1));
|
b->name, sha1_to_hex(b->sha1), sha1_to_hex(old_sha1));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (write_ref_sha1(lock, b->sha1, msg) < 0)
|
transaction = ref_transaction_begin(&err);
|
||||||
return error("Unable to update %s", b->name);
|
if (!transaction ||
|
||||||
|
ref_transaction_update(transaction, b->name, b->sha1, old_sha1,
|
||||||
|
0, 1, &err) ||
|
||||||
|
ref_transaction_commit(transaction, msg, &err)) {
|
||||||
|
ref_transaction_free(transaction);
|
||||||
|
error("%s", err.buf);
|
||||||
|
strbuf_release(&err);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
ref_transaction_free(transaction);
|
||||||
|
strbuf_release(&err);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue