refs: introduce "initial" transaction flag
There are two different ways to commit a transaction: - `ref_transaction_commit()` can be used to commit a regular transaction and is what almost every caller wants. - `initial_ref_transaction_commit()` can be used when it is known that the ref store that the transaction is committed for is empty and when there are no concurrent processes. This is used when cloning a new repository. Implementing this via two separate functions has a couple of downsides. First, every reference backend needs to implement a separate callback even in the case where they don't special-case the initial transaction. Second, backends are basically forced to reimplement the whole logic for how to commit the transaction like the "files" backend does, even though backends may wish to only tweak certain behaviour of a "normal" commit. Third, it is awkward that callers must never prepare the transaction as this is somewhat different than how a transaction typically works. Refactor the code such that we instead mark initial transactions via a separate flag when starting the transaction. This addresses all of the mentioned painpoints, where the most important part is that it will allow backends to have way more leeway in how exactly they want to handle the initial transaction. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
83b8ed8bba
commit
1c299d03e5
@ -1730,13 +1730,6 @@ cleanup:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int packed_initial_transaction_commit(struct ref_store *ref_store UNUSED,
|
||||
struct ref_transaction *transaction,
|
||||
struct strbuf *err)
|
||||
{
|
||||
return ref_transaction_commit(transaction, err);
|
||||
}
|
||||
|
||||
static int packed_pack_refs(struct ref_store *ref_store UNUSED,
|
||||
struct pack_refs_opts *pack_opts UNUSED)
|
||||
{
|
||||
@ -1769,7 +1762,6 @@ struct ref_storage_be refs_be_packed = {
|
||||
.transaction_prepare = packed_transaction_prepare,
|
||||
.transaction_finish = packed_transaction_finish,
|
||||
.transaction_abort = packed_transaction_abort,
|
||||
.initial_transaction_commit = packed_initial_transaction_commit,
|
||||
|
||||
.pack_refs = packed_pack_refs,
|
||||
.rename_ref = NULL,
|
||||
|
Reference in New Issue
Block a user