Skip to content

Commit 17740a1

Browse files
neerajsi-msftdscho
authored andcommitted
bulk-checkin: rebrand plug/unplug APIs as 'odb transactions'
Make it clearer in the naming and documentation of the plug_bulk_checkin and unplug_bulk_checkin APIs that they can be thought of as a "transaction" to optimize operations on the object database. These transactions may be nested so that subsystems like the cache-tree writing code can optimize their operations without caring whether the top-level code has a transaction active. Signed-off-by: Neeraj Singh <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent aa747da commit 17740a1

File tree

3 files changed

+26
-12
lines changed

3 files changed

+26
-12
lines changed

builtin/add.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
670670
string_list_clear(&only_match_skip_worktree, 0);
671671
}
672672

673-
plug_bulk_checkin();
673+
begin_odb_transaction();
674674

675675
if (add_renormalize)
676676
exit_status |= renormalize_tracked_files(&pathspec, flags);
@@ -682,7 +682,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
682682

683683
if (chmod_arg && pathspec.nr)
684684
exit_status |= chmod_pathspec(&pathspec, chmod_arg[0], show_only);
685-
unplug_bulk_checkin();
685+
end_odb_transaction();
686686

687687
finish:
688688
if (write_locked_index(&the_index, &lock_file,

bulk-checkin.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include "packfile.h"
1111
#include "object-store.h"
1212

13-
static int bulk_checkin_plugged;
13+
static int odb_transaction_nesting;
1414

1515
static struct bulk_checkin_state {
1616
char *pack_tmp_name;
@@ -280,21 +280,25 @@ int index_bulk_checkin(struct object_id *oid,
280280
{
281281
int status = deflate_to_pack(&bulk_checkin_state, oid, fd, size, type,
282282
path, flags);
283-
if (!bulk_checkin_plugged)
283+
if (!odb_transaction_nesting)
284284
finish_bulk_checkin(&bulk_checkin_state);
285285
return status;
286286
}
287287

288-
void plug_bulk_checkin(void)
288+
void begin_odb_transaction(void)
289289
{
290-
assert(!bulk_checkin_plugged);
291-
bulk_checkin_plugged = 1;
290+
odb_transaction_nesting += 1;
292291
}
293292

294-
void unplug_bulk_checkin(void)
293+
void end_odb_transaction(void)
295294
{
296-
assert(bulk_checkin_plugged);
297-
bulk_checkin_plugged = 0;
295+
odb_transaction_nesting -= 1;
296+
if (odb_transaction_nesting < 0)
297+
BUG("Unbalanced ODB transaction nesting");
298+
299+
if (odb_transaction_nesting)
300+
return;
301+
298302
if (bulk_checkin_state.f)
299303
finish_bulk_checkin(&bulk_checkin_state);
300304
}

bulk-checkin.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,17 @@ int index_bulk_checkin(struct object_id *oid,
1010
int fd, size_t size, enum object_type type,
1111
const char *path, unsigned flags);
1212

13-
void plug_bulk_checkin(void);
14-
void unplug_bulk_checkin(void);
13+
/*
14+
* Tell the object database to optimize for adding
15+
* multiple objects. end_odb_transaction must be called
16+
* to make new objects visible.
17+
*/
18+
void begin_odb_transaction(void);
19+
20+
/*
21+
* Tell the object database to make any objects from the
22+
* current transaction visible.
23+
*/
24+
void end_odb_transaction(void);
1525

1626
#endif

0 commit comments

Comments
 (0)