Skip to content

Commit 23a3a30

Browse files
neerajsi-msftgitster
authored andcommitted
update-index: use the bulk-checkin infrastructure
The update-index functionality is used internally by 'git stash push' to setup the internal stashed commit. This change enables odb-transactions for update-index infrastructure to speed up adding new objects to the object database by leveraging the batch fsync functionality. There is some risk with this change, since under batch fsync, the object files will be in a tmp-objdir until update-index is complete, so callers using the --stdin option will not see them until update-index is done. This risk is mitigated by flushing the ODB transaction prior to reporting any verbose output so that objects will be visible to callers that are synchronizing with update-index by snooping its output. Signed-off-by: Neeraj Singh <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b4a0c6d commit 23a3a30

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

builtin/update-index.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
#define USE_THE_INDEX_COMPATIBILITY_MACROS
77
#include "cache.h"
8+
#include "bulk-checkin.h"
89
#include "config.h"
910
#include "lockfile.h"
1011
#include "quote.h"
@@ -57,6 +58,14 @@ static void report(const char *fmt, ...)
5758
if (!verbose)
5859
return;
5960

61+
/*
62+
* It is possible, though unlikely, that a caller could use the verbose
63+
* output to synchronize with addition of objects to the object
64+
* database. The current implementation of ODB transactions leaves
65+
* objects invisible while a transaction is active, so flush the
66+
* transaction here before reporting a change made by update-index.
67+
*/
68+
flush_odb_transaction();
6069
va_start(vp, fmt);
6170
vprintf(fmt, vp);
6271
putchar('\n');
@@ -1116,6 +1125,12 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
11161125
*/
11171126
parse_options_start(&ctx, argc, argv, prefix,
11181127
options, PARSE_OPT_STOP_AT_NON_OPTION);
1128+
1129+
/*
1130+
* Allow the object layer to optimize adding multiple objects in
1131+
* a batch.
1132+
*/
1133+
begin_odb_transaction();
11191134
while (ctx.argc) {
11201135
if (parseopt_state != PARSE_OPT_DONE)
11211136
parseopt_state = parse_options_step(&ctx, options,
@@ -1190,6 +1205,11 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
11901205
strbuf_release(&buf);
11911206
}
11921207

1208+
/*
1209+
* By now we have added all of the new objects
1210+
*/
1211+
end_odb_transaction();
1212+
11931213
if (split_index > 0) {
11941214
if (git_config_get_split_index() == 0)
11951215
warning(_("core.splitIndex is set to false; "

0 commit comments

Comments
 (0)