Skip to content

Commit 9c61d9a

Browse files
jltoblergitster
authored andcommitted
builtin/update-index: end ODB transaction when --verbose is specified
With 23a3a30 (update-index: use the bulk-checkin infrastructure, 2022-04-04), object database transactions were added to git-update-index(1) to facilitate writing objects in bulk. With transactions, newly added objects are instead written to a temporary object directory and migrated to the primary object database upon transaction commit. When the --verbose option is specified, the subsequent set of objects written are explicitly flushed via flush_odb_transaction() prior to reporting the update. Flushing the object database transaction migrates pending objects to the primary object database without marking the transaction as complete. This is done so objects are immediately visible to git-update-index(1) callers using the --verbose option and that rely on parsing verbose output to know when objects are written. Due to how git-update-index(1) parses arguments, options that come after a filename are not considered during the object update. Therefore, it may not be known ahead of time whether the --verbose option is present and thus object writes are considered transactional by default until a --verbose option is parsed. Flushing a transaction after individual object writes negates the benefit of writing objects to a transaction in the first place. Furthermore, the mechanism to flush a transaction without actually committing is rather awkward. Drop the call to flush_odb_transaction() in favor of ending the transaction altogether when the --verbose flag is encountered. Subsequent object writes occur outside of a transaction and are therefore immediately visible which matches the current behavior. Signed-off-by: Justin Tobler <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f3c1db4 commit 9c61d9a

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

builtin/update-index.c

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,6 @@ static void report(const char *fmt, ...)
7070
if (!verbose)
7171
return;
7272

73-
/*
74-
* It is possible, though unlikely, that a caller could use the verbose
75-
* output to synchronize with addition of objects to the object
76-
* database. The current implementation of ODB transactions leaves
77-
* objects invisible while a transaction is active, so flush the
78-
* transaction here before reporting a change made by update-index.
79-
*/
80-
flush_odb_transaction(the_repository->objects->transaction);
8173
va_start(vp, fmt);
8274
vprintf(fmt, vp);
8375
putchar('\n');
@@ -1150,6 +1142,21 @@ int cmd_update_index(int argc,
11501142
const char *path = ctx.argv[0];
11511143
char *p;
11521144

1145+
/*
1146+
* It is possible, though unlikely, that a caller could
1147+
* use the verbose output to synchronize with addition
1148+
* of objects to the object database. The current
1149+
* implementation of ODB transactions leaves objects
1150+
* invisible while a transaction is active, so end the
1151+
* transaction here early before processing the next
1152+
* update. All further updates are performed outside of
1153+
* a transaction.
1154+
*/
1155+
if (transaction && verbose) {
1156+
end_odb_transaction(transaction);
1157+
transaction = NULL;
1158+
}
1159+
11531160
setup_work_tree();
11541161
p = prefix_path(prefix, prefix_length, path);
11551162
update_one(p);

0 commit comments

Comments
 (0)