From: Han-Wen Nienhuys <hanwen@xxxxxxxxxx> This prepares for taking locks on constructing the transaction. Signed-off-by: Han-Wen Nienhuys <hanwen@xxxxxxxxxx> --- refs.c | 8 +++----- refs/debug.c | 8 ++++++++ refs/files-backend.c | 8 ++++++++ refs/packed-backend.c | 9 +++++++++ refs/refs-internal.h | 4 ++++ 5 files changed, 32 insertions(+), 5 deletions(-) diff --git a/refs.c b/refs.c index fcae5dddc60..f7ba3e56284 100644 --- a/refs.c +++ b/refs.c @@ -1129,11 +1129,9 @@ int read_ref_at(struct ref_store *refs, const char *refname, struct ref_transaction *ref_store_transaction_begin(struct ref_store *refs, struct strbuf *err) { - struct ref_transaction *tr; - assert(err); - - CALLOC_ARRAY(tr, 1); - tr->ref_store = refs; + struct ref_transaction *tr = refs->be->transaction_begin(refs, err); + if (tr) + tr->ref_store = refs; return tr; } diff --git a/refs/debug.c b/refs/debug.c index b7ffc4ce67e..95fb3eb4430 100644 --- a/refs/debug.c +++ b/refs/debug.c @@ -41,6 +41,13 @@ static int debug_init_db(struct ref_store *refs, struct strbuf *err) return res; } +static struct ref_transaction *debug_transaction_begin(struct ref_store *ref_store, + struct strbuf *err) { + struct ref_transaction *tr; + CALLOC_ARRAY(tr, 1); + return tr; +} + static int debug_transaction_prepare(struct ref_store *refs, struct ref_transaction *transaction, struct strbuf *err) @@ -451,6 +458,7 @@ struct ref_storage_be refs_be_debug = { * has a function we should also have a wrapper for it here. * Test the output with "GIT_TRACE_REFS=1". */ + .transaction_begin = debug_transaction_begin, .transaction_prepare = debug_transaction_prepare, .transaction_finish = debug_transaction_finish, .transaction_abort = debug_transaction_abort, diff --git a/refs/files-backend.c b/refs/files-backend.c index 341354182bb..d83eea8b408 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -2681,6 +2681,13 @@ static void files_transaction_cleanup(struct files_ref_store *refs, transaction->state = REF_TRANSACTION_CLOSED; } +static struct ref_transaction *files_transaction_begin(struct ref_store *ref_store, + struct strbuf *err) { + struct ref_transaction *tr; + CALLOC_ARRAY(tr, 1); + return tr; +} + static int files_transaction_prepare(struct ref_store *ref_store, struct ref_transaction *transaction, struct strbuf *err) @@ -3297,6 +3304,7 @@ struct ref_storage_be refs_be_files = { .name = "files", .init = files_ref_store_create, .init_db = files_init_db, + .transaction_begin = files_transaction_begin, .transaction_prepare = files_transaction_prepare, .transaction_finish = files_transaction_finish, .transaction_abort = files_transaction_abort, diff --git a/refs/packed-backend.c b/refs/packed-backend.c index 59c78d7941f..4f5b1025605 100644 --- a/refs/packed-backend.c +++ b/refs/packed-backend.c @@ -1580,6 +1580,14 @@ static void packed_transaction_cleanup(struct packed_ref_store *refs, transaction->state = REF_TRANSACTION_CLOSED; } + +static struct ref_transaction *packed_transaction_begin(struct ref_store *ref_store, + struct strbuf *err) { + struct ref_transaction *tr; + CALLOC_ARRAY(tr, 1); + return tr; +} + static int packed_transaction_prepare(struct ref_store *ref_store, struct ref_transaction *transaction, struct strbuf *err) @@ -1758,6 +1766,7 @@ struct ref_storage_be refs_be_packed = { .name = "packed", .init = packed_ref_store_create, .init_db = packed_init_db, + .transaction_begin = packed_transaction_begin, .transaction_prepare = packed_transaction_prepare, .transaction_finish = packed_transaction_finish, .transaction_abort = packed_transaction_abort, diff --git a/refs/refs-internal.h b/refs/refs-internal.h index 9db8aec4da8..0a15e8a2ac8 100644 --- a/refs/refs-internal.h +++ b/refs/refs-internal.h @@ -531,6 +531,9 @@ typedef struct ref_store *ref_store_init_fn(struct repository *repo, typedef int ref_init_db_fn(struct ref_store *refs, struct strbuf *err); +typedef struct ref_transaction *ref_transaction_begin_fn(struct ref_store *refs, + struct strbuf *err); + typedef int ref_transaction_prepare_fn(struct ref_store *refs, struct ref_transaction *transaction, struct strbuf *err); @@ -670,6 +673,7 @@ struct ref_storage_be { ref_store_init_fn *init; ref_init_db_fn *init_db; + ref_transaction_begin_fn *transaction_begin; ref_transaction_prepare_fn *transaction_prepare; ref_transaction_finish_fn *transaction_finish; ref_transaction_abort_fn *transaction_abort; -- gitgitgadget