Merge branch 'rs/ref-transaction-1'
The second batch of the transactional ref update series. * rs/ref-transaction-1: (22 commits) update-ref --stdin: pass transaction around explicitly update-ref --stdin: narrow scope of err strbuf refs.c: make delete_ref use a transaction refs.c: make prune_ref use a transaction to delete the ref refs.c: remove lock_ref_sha1 refs.c: remove the update_ref_write function refs.c: remove the update_ref_lock function refs.c: make lock_ref_sha1 static walker.c: use ref transaction for ref updates fast-import.c: use a ref transaction when dumping tags receive-pack.c: use a reference transaction for updating the refs refs.c: change update_ref to use a transaction branch.c: use ref transaction for all ref updates fast-import.c: change update_branch to use ref transactions sequencer.c: use ref transactions for all ref updates commit.c: use ref transactions for updates replace.c: use the ref transaction functions for updates tag.c: use ref transactions when doing updates refs.c: add transaction.status and track OPEN/CLOSED refs.c: make ref_transaction_begin take an err argument ...
This commit is contained in:
@ -1679,8 +1679,9 @@ 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];
|
||||
struct strbuf err = STRBUF_INIT;
|
||||
|
||||
if (read_ref(b->name, old_sha1))
|
||||
hashclr(old_sha1);
|
||||
@ -1689,29 +1690,33 @@ static int update_branch(struct branch *b)
|
||||
delete_ref(b->name, old_sha1, 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)) {
|
||||
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);
|
||||
if (!old_cmit || !new_cmit)
|
||||
return error("Branch %s is missing commits.", b->name);
|
||||
}
|
||||
|
||||
if (!in_merge_bases(old_cmit, new_cmit)) {
|
||||
unlock_ref(lock);
|
||||
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);
|
||||
transaction = ref_transaction_begin(&err);
|
||||
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;
|
||||
}
|
||||
|
||||
@ -1730,15 +1735,32 @@ static void dump_tags(void)
|
||||
{
|
||||
static const char *msg = "fast-import";
|
||||
struct tag *t;
|
||||
struct ref_lock *lock;
|
||||
char ref_name[PATH_MAX];
|
||||
struct strbuf ref_name = STRBUF_INIT;
|
||||
struct strbuf err = STRBUF_INIT;
|
||||
struct ref_transaction *transaction;
|
||||
|
||||
for (t = first_tag; t; t = t->next_tag) {
|
||||
sprintf(ref_name, "tags/%s", t->name);
|
||||
lock = lock_ref_sha1(ref_name, NULL);
|
||||
if (!lock || write_ref_sha1(lock, t->sha1, msg) < 0)
|
||||
failure |= error("Unable to update %s", ref_name);
|
||||
transaction = ref_transaction_begin(&err);
|
||||
if (!transaction) {
|
||||
failure |= error("%s", err.buf);
|
||||
goto cleanup;
|
||||
}
|
||||
for (t = first_tag; t; t = t->next_tag) {
|
||||
strbuf_reset(&ref_name);
|
||||
strbuf_addf(&ref_name, "refs/tags/%s", t->name);
|
||||
|
||||
if (ref_transaction_update(transaction, ref_name.buf, t->sha1,
|
||||
NULL, 0, 0, &err)) {
|
||||
failure |= error("%s", err.buf);
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
if (ref_transaction_commit(transaction, msg, &err))
|
||||
failure |= error("%s", err.buf);
|
||||
|
||||
cleanup:
|
||||
ref_transaction_free(transaction);
|
||||
strbuf_release(&ref_name);
|
||||
strbuf_release(&err);
|
||||
}
|
||||
|
||||
static void dump_marks_helper(FILE *f,
|
||||
|
Reference in New Issue
Block a user