Skip to content

Commit 5649d5b

Browse files
neerajsi-msftdscho
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 not keeping an ODB transaction open around --stdin processing if in --verbose mode. Without --verbose mode, a caller feeding update-index via --stdin wouldn't know when update-index adds an object, event without an ODB transaction. Signed-off-by: Neeraj Singh <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 426f5b4 commit 5649d5b

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

builtin/update-index.c

Lines changed: 24 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"
@@ -1116,6 +1117,12 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
11161117
*/
11171118
parse_options_start(&ctx, argc, argv, prefix,
11181119
options, PARSE_OPT_STOP_AT_NON_OPTION);
1120+
1121+
/*
1122+
* Allow the object layer to optimize adding multiple objects in
1123+
* a batch.
1124+
*/
1125+
begin_odb_transaction();
11191126
while (ctx.argc) {
11201127
if (parseopt_state != PARSE_OPT_DONE)
11211128
parseopt_state = parse_options_step(&ctx, options,
@@ -1167,6 +1174,17 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
11671174
the_index.version = preferred_index_format;
11681175
}
11691176

1177+
/*
1178+
* It is possible, though unlikely, that a caller could use the verbose
1179+
* output to synchronize with addition of objects to the object
1180+
* database. The current implementation of ODB transactions leaves
1181+
* objects invisible while a transaction is active, so end the
1182+
* transaction here if verbose output is enabled.
1183+
*/
1184+
1185+
if (verbose)
1186+
end_odb_transaction();
1187+
11701188
if (read_from_stdin) {
11711189
struct strbuf buf = STRBUF_INIT;
11721190
struct strbuf unquoted = STRBUF_INIT;
@@ -1190,6 +1208,12 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
11901208
strbuf_release(&buf);
11911209
}
11921210

1211+
/*
1212+
* By now we have added all of the new objects
1213+
*/
1214+
if (!verbose)
1215+
end_odb_transaction();
1216+
11931217
if (split_index > 0) {
11941218
if (git_config_get_split_index() == 0)
11951219
warning(_("core.splitIndex is set to false; "

0 commit comments

Comments
 (0)