refs: allow passing flags when setting up a transaction
Allow passing flags when setting up a transaction such that the behaviour of the transaction itself can be altered. This functionality will be used in a subsequent patch. Adapt callers accordingly. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>maint
parent
facbe4f633
commit
a0efef1446
2
branch.c
2
branch.c
|
@ -627,7 +627,7 @@ void create_branch(struct repository *r,
|
||||||
else
|
else
|
||||||
msg = xstrfmt("branch: Created from %s", start_name);
|
msg = xstrfmt("branch: Created from %s", start_name);
|
||||||
transaction = ref_store_transaction_begin(get_main_ref_store(the_repository),
|
transaction = ref_store_transaction_begin(get_main_ref_store(the_repository),
|
||||||
&err);
|
0, &err);
|
||||||
if (!transaction ||
|
if (!transaction ||
|
||||||
ref_transaction_update(transaction, ref.buf,
|
ref_transaction_update(transaction, ref.buf,
|
||||||
&oid, forcing ? NULL : null_oid(),
|
&oid, forcing ? NULL : null_oid(),
|
||||||
|
|
|
@ -574,7 +574,7 @@ static void write_remote_refs(const struct ref *local_refs)
|
||||||
struct strbuf err = STRBUF_INIT;
|
struct strbuf err = STRBUF_INIT;
|
||||||
|
|
||||||
t = ref_store_transaction_begin(get_main_ref_store(the_repository),
|
t = ref_store_transaction_begin(get_main_ref_store(the_repository),
|
||||||
&err);
|
0, &err);
|
||||||
if (!t)
|
if (!t)
|
||||||
die("%s", err.buf);
|
die("%s", err.buf);
|
||||||
|
|
||||||
|
|
|
@ -1634,7 +1634,7 @@ static int update_branch(struct branch *b)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
transaction = ref_store_transaction_begin(get_main_ref_store(the_repository),
|
transaction = ref_store_transaction_begin(get_main_ref_store(the_repository),
|
||||||
&err);
|
0, &err);
|
||||||
if (!transaction ||
|
if (!transaction ||
|
||||||
ref_transaction_update(transaction, b->name, &b->oid, &old_oid,
|
ref_transaction_update(transaction, b->name, &b->oid, &old_oid,
|
||||||
NULL, NULL, 0, msg, &err) ||
|
NULL, NULL, 0, msg, &err) ||
|
||||||
|
@ -1669,7 +1669,7 @@ static void dump_tags(void)
|
||||||
struct ref_transaction *transaction;
|
struct ref_transaction *transaction;
|
||||||
|
|
||||||
transaction = ref_store_transaction_begin(get_main_ref_store(the_repository),
|
transaction = ref_store_transaction_begin(get_main_ref_store(the_repository),
|
||||||
&err);
|
0, &err);
|
||||||
if (!transaction) {
|
if (!transaction) {
|
||||||
failure |= error("%s", err.buf);
|
failure |= error("%s", err.buf);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
|
@ -669,7 +669,7 @@ static int s_update_ref(const char *action,
|
||||||
*/
|
*/
|
||||||
if (!transaction) {
|
if (!transaction) {
|
||||||
transaction = our_transaction = ref_store_transaction_begin(get_main_ref_store(the_repository),
|
transaction = our_transaction = ref_store_transaction_begin(get_main_ref_store(the_repository),
|
||||||
&err);
|
0, &err);
|
||||||
if (!transaction) {
|
if (!transaction) {
|
||||||
ret = STORE_REF_ERROR_OTHER;
|
ret = STORE_REF_ERROR_OTHER;
|
||||||
goto out;
|
goto out;
|
||||||
|
@ -1671,7 +1671,7 @@ static int do_fetch(struct transport *transport,
|
||||||
|
|
||||||
if (atomic_fetch) {
|
if (atomic_fetch) {
|
||||||
transaction = ref_store_transaction_begin(get_main_ref_store(the_repository),
|
transaction = ref_store_transaction_begin(get_main_ref_store(the_repository),
|
||||||
&err);
|
0, &err);
|
||||||
if (!transaction) {
|
if (!transaction) {
|
||||||
retcode = -1;
|
retcode = -1;
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
|
@ -1849,7 +1849,7 @@ static void execute_commands_non_atomic(struct command *commands,
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
transaction = ref_store_transaction_begin(get_main_ref_store(the_repository),
|
transaction = ref_store_transaction_begin(get_main_ref_store(the_repository),
|
||||||
&err);
|
0, &err);
|
||||||
if (!transaction) {
|
if (!transaction) {
|
||||||
rp_error("%s", err.buf);
|
rp_error("%s", err.buf);
|
||||||
strbuf_reset(&err);
|
strbuf_reset(&err);
|
||||||
|
@ -1878,7 +1878,7 @@ static void execute_commands_atomic(struct command *commands,
|
||||||
const char *reported_error = "atomic push failure";
|
const char *reported_error = "atomic push failure";
|
||||||
|
|
||||||
transaction = ref_store_transaction_begin(get_main_ref_store(the_repository),
|
transaction = ref_store_transaction_begin(get_main_ref_store(the_repository),
|
||||||
&err);
|
0, &err);
|
||||||
if (!transaction) {
|
if (!transaction) {
|
||||||
rp_error("%s", err.buf);
|
rp_error("%s", err.buf);
|
||||||
strbuf_reset(&err);
|
strbuf_reset(&err);
|
||||||
|
|
|
@ -201,7 +201,7 @@ static int replace_object_oid(const char *object_ref,
|
||||||
}
|
}
|
||||||
|
|
||||||
transaction = ref_store_transaction_begin(get_main_ref_store(the_repository),
|
transaction = ref_store_transaction_begin(get_main_ref_store(the_repository),
|
||||||
&err);
|
0, &err);
|
||||||
if (!transaction ||
|
if (!transaction ||
|
||||||
ref_transaction_update(transaction, ref.buf, repl, &prev,
|
ref_transaction_update(transaction, ref.buf, repl, &prev,
|
||||||
NULL, NULL, 0, NULL, &err) ||
|
NULL, NULL, 0, NULL, &err) ||
|
||||||
|
|
|
@ -681,7 +681,7 @@ int cmd_tag(int argc,
|
||||||
}
|
}
|
||||||
|
|
||||||
transaction = ref_store_transaction_begin(get_main_ref_store(the_repository),
|
transaction = ref_store_transaction_begin(get_main_ref_store(the_repository),
|
||||||
&err);
|
0, &err);
|
||||||
if (!transaction ||
|
if (!transaction ||
|
||||||
ref_transaction_update(transaction, ref.buf, &object, &prev,
|
ref_transaction_update(transaction, ref.buf, &object, &prev,
|
||||||
NULL, NULL,
|
NULL, NULL,
|
||||||
|
|
|
@ -612,7 +612,7 @@ static void update_refs_stdin(void)
|
||||||
int i, j;
|
int i, j;
|
||||||
|
|
||||||
transaction = ref_store_transaction_begin(get_main_ref_store(the_repository),
|
transaction = ref_store_transaction_begin(get_main_ref_store(the_repository),
|
||||||
&err);
|
0, &err);
|
||||||
if (!transaction)
|
if (!transaction)
|
||||||
die("%s", err.buf);
|
die("%s", err.buf);
|
||||||
|
|
||||||
|
@ -680,7 +680,7 @@ static void update_refs_stdin(void)
|
||||||
*/
|
*/
|
||||||
state = cmd->state;
|
state = cmd->state;
|
||||||
transaction = ref_store_transaction_begin(get_main_ref_store(the_repository),
|
transaction = ref_store_transaction_begin(get_main_ref_store(the_repository),
|
||||||
&err);
|
0, &err);
|
||||||
if (!transaction)
|
if (!transaction)
|
||||||
die("%s", err.buf);
|
die("%s", err.buf);
|
||||||
|
|
||||||
|
|
12
refs.c
12
refs.c
|
@ -918,7 +918,7 @@ int refs_delete_ref(struct ref_store *refs, const char *msg,
|
||||||
struct ref_transaction *transaction;
|
struct ref_transaction *transaction;
|
||||||
struct strbuf err = STRBUF_INIT;
|
struct strbuf err = STRBUF_INIT;
|
||||||
|
|
||||||
transaction = ref_store_transaction_begin(refs, &err);
|
transaction = ref_store_transaction_begin(refs, 0, &err);
|
||||||
if (!transaction ||
|
if (!transaction ||
|
||||||
ref_transaction_delete(transaction, refname, old_oid,
|
ref_transaction_delete(transaction, refname, old_oid,
|
||||||
NULL, flags, msg, &err) ||
|
NULL, flags, msg, &err) ||
|
||||||
|
@ -1116,6 +1116,7 @@ int read_ref_at(struct ref_store *refs, const char *refname,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ref_transaction *ref_store_transaction_begin(struct ref_store *refs,
|
struct ref_transaction *ref_store_transaction_begin(struct ref_store *refs,
|
||||||
|
unsigned int flags,
|
||||||
struct strbuf *err)
|
struct strbuf *err)
|
||||||
{
|
{
|
||||||
struct ref_transaction *tr;
|
struct ref_transaction *tr;
|
||||||
|
@ -1123,6 +1124,7 @@ struct ref_transaction *ref_store_transaction_begin(struct ref_store *refs,
|
||||||
|
|
||||||
CALLOC_ARRAY(tr, 1);
|
CALLOC_ARRAY(tr, 1);
|
||||||
tr->ref_store = refs;
|
tr->ref_store = refs;
|
||||||
|
tr->flags = flags;
|
||||||
return tr;
|
return tr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1309,7 +1311,7 @@ int refs_update_ref(struct ref_store *refs, const char *msg,
|
||||||
struct strbuf err = STRBUF_INIT;
|
struct strbuf err = STRBUF_INIT;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
t = ref_store_transaction_begin(refs, &err);
|
t = ref_store_transaction_begin(refs, 0, &err);
|
||||||
if (!t ||
|
if (!t ||
|
||||||
ref_transaction_update(t, refname, new_oid, old_oid, NULL, NULL,
|
ref_transaction_update(t, refname, new_oid, old_oid, NULL, NULL,
|
||||||
flags, msg, &err) ||
|
flags, msg, &err) ||
|
||||||
|
@ -2120,7 +2122,7 @@ int refs_update_symref(struct ref_store *refs, const char *ref,
|
||||||
struct strbuf err = STRBUF_INIT;
|
struct strbuf err = STRBUF_INIT;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
transaction = ref_store_transaction_begin(refs, &err);
|
transaction = ref_store_transaction_begin(refs, 0, &err);
|
||||||
if (!transaction ||
|
if (!transaction ||
|
||||||
ref_transaction_update(transaction, ref, NULL, NULL,
|
ref_transaction_update(transaction, ref, NULL, NULL,
|
||||||
target, NULL, REF_NO_DEREF,
|
target, NULL, REF_NO_DEREF,
|
||||||
|
@ -2527,7 +2529,7 @@ int refs_delete_refs(struct ref_store *refs, const char *logmsg,
|
||||||
* individual updates can't fail, so we can pack all of the
|
* individual updates can't fail, so we can pack all of the
|
||||||
* updates into a single transaction.
|
* updates into a single transaction.
|
||||||
*/
|
*/
|
||||||
transaction = ref_store_transaction_begin(refs, &err);
|
transaction = ref_store_transaction_begin(refs, 0, &err);
|
||||||
if (!transaction) {
|
if (!transaction) {
|
||||||
ret = error("%s", err.buf);
|
ret = error("%s", err.buf);
|
||||||
goto out;
|
goto out;
|
||||||
|
@ -2833,7 +2835,7 @@ int repo_migrate_ref_storage_format(struct repository *repo,
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
transaction = ref_store_transaction_begin(new_refs, errbuf);
|
transaction = ref_store_transaction_begin(new_refs, 0, errbuf);
|
||||||
if (!transaction)
|
if (!transaction)
|
||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
|
|
3
refs.h
3
refs.h
|
@ -234,7 +234,7 @@ char *repo_default_branch_name(struct repository *r, int quiet);
|
||||||
* struct strbuf err = STRBUF_INIT;
|
* struct strbuf err = STRBUF_INIT;
|
||||||
* int ret = 0;
|
* int ret = 0;
|
||||||
*
|
*
|
||||||
* transaction = ref_store_transaction_begin(refs, &err);
|
* transaction = ref_store_transaction_begin(refs, 0, &err);
|
||||||
* if (!transaction ||
|
* if (!transaction ||
|
||||||
* ref_transaction_update(...) ||
|
* ref_transaction_update(...) ||
|
||||||
* ref_transaction_create(...) ||
|
* ref_transaction_create(...) ||
|
||||||
|
@ -584,6 +584,7 @@ enum action_on_err {
|
||||||
* be freed by calling ref_transaction_free().
|
* be freed by calling ref_transaction_free().
|
||||||
*/
|
*/
|
||||||
struct ref_transaction *ref_store_transaction_begin(struct ref_store *refs,
|
struct ref_transaction *ref_store_transaction_begin(struct ref_store *refs,
|
||||||
|
unsigned int flags,
|
||||||
struct strbuf *err);
|
struct strbuf *err);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -1252,7 +1252,7 @@ static void prune_ref(struct files_ref_store *refs, struct ref_to_prune *r)
|
||||||
if (check_refname_format(r->name, 0))
|
if (check_refname_format(r->name, 0))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
transaction = ref_store_transaction_begin(&refs->base, &err);
|
transaction = ref_store_transaction_begin(&refs->base, 0, &err);
|
||||||
if (!transaction)
|
if (!transaction)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
ref_transaction_add_update(
|
ref_transaction_add_update(
|
||||||
|
@ -1396,7 +1396,8 @@ static int files_pack_refs(struct ref_store *ref_store,
|
||||||
if (!should_pack_refs(refs, opts))
|
if (!should_pack_refs(refs, opts))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
transaction = ref_store_transaction_begin(refs->packed_ref_store, &err);
|
transaction = ref_store_transaction_begin(refs->packed_ref_store,
|
||||||
|
0, &err);
|
||||||
if (!transaction)
|
if (!transaction)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
@ -2867,7 +2868,8 @@ static int files_transaction_prepare(struct ref_store *ref_store,
|
||||||
*/
|
*/
|
||||||
if (!packed_transaction) {
|
if (!packed_transaction) {
|
||||||
packed_transaction = ref_store_transaction_begin(
|
packed_transaction = ref_store_transaction_begin(
|
||||||
refs->packed_ref_store, err);
|
refs->packed_ref_store,
|
||||||
|
transaction->flags, err);
|
||||||
if (!packed_transaction) {
|
if (!packed_transaction) {
|
||||||
ret = TRANSACTION_GENERIC_ERROR;
|
ret = TRANSACTION_GENERIC_ERROR;
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
@ -3174,7 +3176,8 @@ static int files_initial_transaction_commit(struct ref_store *ref_store,
|
||||||
&affected_refnames))
|
&affected_refnames))
|
||||||
BUG("initial ref transaction called with existing refs");
|
BUG("initial ref transaction called with existing refs");
|
||||||
|
|
||||||
packed_transaction = ref_store_transaction_begin(refs->packed_ref_store, err);
|
packed_transaction = ref_store_transaction_begin(refs->packed_ref_store,
|
||||||
|
transaction->flags, err);
|
||||||
if (!packed_transaction) {
|
if (!packed_transaction) {
|
||||||
ret = TRANSACTION_GENERIC_ERROR;
|
ret = TRANSACTION_GENERIC_ERROR;
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
|
@ -193,6 +193,7 @@ struct ref_transaction {
|
||||||
size_t nr;
|
size_t nr;
|
||||||
enum ref_transaction_state state;
|
enum ref_transaction_state state;
|
||||||
void *backend_data;
|
void *backend_data;
|
||||||
|
unsigned int flags;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -662,7 +662,7 @@ static int fast_forward_to(struct repository *r,
|
||||||
strbuf_addf(&sb, "%s: fast-forward", action_name(opts));
|
strbuf_addf(&sb, "%s: fast-forward", action_name(opts));
|
||||||
|
|
||||||
transaction = ref_store_transaction_begin(get_main_ref_store(the_repository),
|
transaction = ref_store_transaction_begin(get_main_ref_store(the_repository),
|
||||||
&err);
|
0, &err);
|
||||||
if (!transaction ||
|
if (!transaction ||
|
||||||
ref_transaction_update(transaction, "HEAD",
|
ref_transaction_update(transaction, "HEAD",
|
||||||
to, unborn && !is_rebase_i(opts) ?
|
to, unborn && !is_rebase_i(opts) ?
|
||||||
|
@ -1297,7 +1297,7 @@ int update_head_with_reflog(const struct commit *old_head,
|
||||||
}
|
}
|
||||||
|
|
||||||
transaction = ref_store_transaction_begin(get_main_ref_store(the_repository),
|
transaction = ref_store_transaction_begin(get_main_ref_store(the_repository),
|
||||||
err);
|
0, err);
|
||||||
if (!transaction ||
|
if (!transaction ||
|
||||||
ref_transaction_update(transaction, "HEAD", new_head,
|
ref_transaction_update(transaction, "HEAD", new_head,
|
||||||
old_head ? &old_head->object.oid : null_oid(),
|
old_head ? &old_head->object.oid : null_oid(),
|
||||||
|
@ -3890,7 +3890,7 @@ static int do_label(struct repository *r, const char *name, int len)
|
||||||
strbuf_addf(&ref_name, "refs/rewritten/%.*s", len, name);
|
strbuf_addf(&ref_name, "refs/rewritten/%.*s", len, name);
|
||||||
strbuf_addf(&msg, "rebase (label) '%.*s'", len, name);
|
strbuf_addf(&msg, "rebase (label) '%.*s'", len, name);
|
||||||
|
|
||||||
transaction = ref_store_transaction_begin(refs, &err);
|
transaction = ref_store_transaction_begin(refs, 0, &err);
|
||||||
if (!transaction) {
|
if (!transaction) {
|
||||||
error("%s", err.buf);
|
error("%s", err.buf);
|
||||||
ret = -1;
|
ret = -1;
|
||||||
|
|
2
walker.c
2
walker.c
|
@ -290,7 +290,7 @@ int walker_fetch(struct walker *walker, int targets, char **target,
|
||||||
|
|
||||||
if (write_ref) {
|
if (write_ref) {
|
||||||
transaction = ref_store_transaction_begin(get_main_ref_store(the_repository),
|
transaction = ref_store_transaction_begin(get_main_ref_store(the_repository),
|
||||||
&err);
|
0, &err);
|
||||||
if (!transaction) {
|
if (!transaction) {
|
||||||
error("%s", err.buf);
|
error("%s", err.buf);
|
||||||
goto done;
|
goto done;
|
||||||
|
|
Loading…
Reference in New Issue