Skip to content

Commit ce1661f

Browse files
jltoblergitster
authored andcommitted
odb: add transaction interface
Transactions are managed via the {begin,end}_odb_transaction() function in the object-file subsystem and its implementation is specific to the files object source. Introduce odb_transaction_{begin,commit}() in the odb subsystem to provide an eventual object source agnostic means to manage transactions. Update call sites to instead manage transactions through the odb subsystem. Also rename {begin,end}_odb_transaction() functions to object_file_transaction_{begin,commit}() to clarify the object source it supports. Signed-off-by: Justin Tobler <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ed0f5f9 commit ce1661f

File tree

9 files changed

+46
-19
lines changed

9 files changed

+46
-19
lines changed

builtin/add.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "pathspec.h"
1616
#include "run-command.h"
1717
#include "object-file.h"
18+
#include "odb.h"
1819
#include "parse-options.h"
1920
#include "path.h"
2021
#include "preload-index.h"
@@ -575,7 +576,7 @@ int cmd_add(int argc,
575576
string_list_clear(&only_match_skip_worktree, 0);
576577
}
577578

578-
transaction = begin_odb_transaction(repo->objects);
579+
transaction = odb_transaction_begin(repo->objects);
579580

580581
ps_matched = xcalloc(pathspec.nr, 1);
581582
if (add_renormalize)
@@ -594,7 +595,7 @@ int cmd_add(int argc,
594595

595596
if (chmod_arg && pathspec.nr)
596597
exit_status |= chmod_pathspec(repo, &pathspec, chmod_arg[0], show_only);
597-
end_odb_transaction(transaction);
598+
odb_transaction_commit(transaction);
598599

599600
finish:
600601
if (write_locked_index(repo->index, &lock_file,

builtin/unpack-objects.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -599,12 +599,12 @@ static void unpack_all(void)
599599
progress = start_progress(the_repository,
600600
_("Unpacking objects"), nr_objects);
601601
CALLOC_ARRAY(obj_list, nr_objects);
602-
transaction = begin_odb_transaction(the_repository->objects);
602+
transaction = odb_transaction_begin(the_repository->objects);
603603
for (i = 0; i < nr_objects; i++) {
604604
unpack_one(i);
605605
display_progress(progress, i + 1);
606606
}
607-
end_odb_transaction(transaction);
607+
odb_transaction_commit(transaction);
608608
stop_progress(&progress);
609609

610610
if (delta_list)

builtin/update-index.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "cache-tree.h"
1919
#include "tree-walk.h"
2020
#include "object-file.h"
21+
#include "odb.h"
2122
#include "refs.h"
2223
#include "resolve-undo.h"
2324
#include "parse-options.h"
@@ -1122,7 +1123,7 @@ int cmd_update_index(int argc,
11221123
* Allow the object layer to optimize adding multiple objects in
11231124
* a batch.
11241125
*/
1125-
transaction = begin_odb_transaction(the_repository->objects);
1126+
transaction = odb_transaction_begin(the_repository->objects);
11261127
while (ctx.argc) {
11271128
if (parseopt_state != PARSE_OPT_DONE)
11281129
parseopt_state = parse_options_step(&ctx, options,
@@ -1152,7 +1153,7 @@ int cmd_update_index(int argc,
11521153
* a transaction.
11531154
*/
11541155
if (transaction && verbose) {
1155-
end_odb_transaction(transaction);
1156+
odb_transaction_commit(transaction);
11561157
transaction = NULL;
11571158
}
11581159

@@ -1220,7 +1221,7 @@ int cmd_update_index(int argc,
12201221
/*
12211222
* By now we have added all of the new objects
12221223
*/
1223-
end_odb_transaction(transaction);
1224+
odb_transaction_commit(transaction);
12241225

12251226
if (split_index > 0) {
12261227
if (repo_config_get_split_index(the_repository) == 0)

cache-tree.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -489,10 +489,10 @@ int cache_tree_update(struct index_state *istate, int flags)
489489

490490
trace_performance_enter();
491491
trace2_region_enter("cache_tree", "update", the_repository);
492-
transaction = begin_odb_transaction(the_repository->objects);
492+
transaction = odb_transaction_begin(the_repository->objects);
493493
i = update_one(istate->cache_tree, istate->cache, istate->cache_nr,
494494
"", 0, &skip, flags);
495-
end_odb_transaction(transaction);
495+
odb_transaction_commit(transaction);
496496
trace2_region_leave("cache_tree", "update", the_repository);
497497
trace_performance_leave("cache_tree_update");
498498
if (i < 0)

object-file.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ static void prepare_loose_object_transaction(struct odb_transaction *transaction
691691
* We lazily create the temporary object directory
692692
* the first time an object might be added, since
693693
* callers may not know whether any objects will be
694-
* added at the time they call begin_odb_transaction.
694+
* added at the time they call object_file_transaction_begin.
695695
*/
696696
if (!transaction || transaction->objdir)
697697
return;
@@ -1622,12 +1622,12 @@ int index_fd(struct index_state *istate, struct object_id *oid,
16221622
} else {
16231623
struct odb_transaction *transaction;
16241624

1625-
transaction = begin_odb_transaction(the_repository->objects);
1625+
transaction = odb_transaction_begin(the_repository->objects);
16261626
ret = index_blob_packfile_transaction(the_repository->objects->transaction,
16271627
oid, fd,
16281628
xsize_t(st->st_size),
16291629
path, flags);
1630-
end_odb_transaction(transaction);
1630+
odb_transaction_commit(transaction);
16311631
}
16321632

16331633
close(fd);
@@ -1967,8 +1967,10 @@ int read_loose_object(struct repository *repo,
19671967
return ret;
19681968
}
19691969

1970-
struct odb_transaction *begin_odb_transaction(struct object_database *odb)
1970+
struct odb_transaction *object_file_transaction_begin(struct odb_source *source)
19711971
{
1972+
struct object_database *odb = source->odb;
1973+
19721974
if (odb->transaction)
19731975
return NULL;
19741976

@@ -1978,7 +1980,7 @@ struct odb_transaction *begin_odb_transaction(struct object_database *odb)
19781980
return odb->transaction;
19791981
}
19801982

1981-
void end_odb_transaction(struct odb_transaction *transaction)
1983+
void object_file_transaction_commit(struct odb_transaction *transaction)
19821984
{
19831985
if (!transaction)
19841986
return;

object-file.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,16 +222,16 @@ struct odb_transaction;
222222

223223
/*
224224
* Tell the object database to optimize for adding
225-
* multiple objects. end_odb_transaction must be called
225+
* multiple objects. object_file_transaction_commit must be called
226226
* to make new objects visible. If a transaction is already
227227
* pending, NULL is returned.
228228
*/
229-
struct odb_transaction *begin_odb_transaction(struct object_database *odb);
229+
struct odb_transaction *object_file_transaction_begin(struct odb_source *source);
230230

231231
/*
232232
* Tell the object database to make any objects from the
233233
* current transaction visible.
234234
*/
235-
void end_odb_transaction(struct odb_transaction *transaction);
235+
void object_file_transaction_commit(struct odb_transaction *transaction);
236236

237237
#endif /* OBJECT_FILE_H */

odb.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,3 +1051,13 @@ void odb_clear(struct object_database *o)
10511051
hashmap_clear(&o->pack_map);
10521052
string_list_clear(&o->submodule_source_paths, 0);
10531053
}
1054+
1055+
struct odb_transaction *odb_transaction_begin(struct object_database *odb)
1056+
{
1057+
return object_file_transaction_begin(odb->sources);
1058+
}
1059+
1060+
void odb_transaction_commit(struct odb_transaction *transaction)
1061+
{
1062+
object_file_transaction_commit(transaction);
1063+
}

odb.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,19 @@ struct object_database {
185185
struct object_database *odb_new(struct repository *repo);
186186
void odb_clear(struct object_database *o);
187187

188+
/*
189+
* Starts an ODB transaction. Subsequent objects are written to the transaction
190+
* and not committed until odb_transaction_commit() is invoked on the
191+
* transaction. If the ODB already has a pending transaction, NULL is returned.
192+
*/
193+
struct odb_transaction *odb_transaction_begin(struct object_database *odb);
194+
195+
/*
196+
* Commits an ODB transaction making the written objects visible. If the
197+
* specified transaction is NULL, the function is a no-op.
198+
*/
199+
void odb_transaction_commit(struct odb_transaction *transaction);
200+
188201
/*
189202
* Find source by its object directory path. Dies in case the source couldn't
190203
* be found.

read-cache.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3972,9 +3972,9 @@ int add_files_to_cache(struct repository *repo, const char *prefix,
39723972
* This function is invoked from commands other than 'add', which
39733973
* may not have their own transaction active.
39743974
*/
3975-
transaction = begin_odb_transaction(repo->objects);
3975+
transaction = odb_transaction_begin(repo->objects);
39763976
run_diff_files(&rev, DIFF_RACY_IS_MODIFIED);
3977-
end_odb_transaction(transaction);
3977+
odb_transaction_commit(transaction);
39783978

39793979
release_revisions(&rev);
39803980
return !!data.add_errors;

0 commit comments

Comments
 (0)