]> git.ipfire.org Git - thirdparty/git.git/commitdiff
builtin/add: add ODB transaction around add_files_to_cache
authorNeeraj Singh <neerajsi@microsoft.com>
Tue, 5 Apr 2022 05:20:11 +0000 (22:20 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 6 Apr 2022 20:13:26 +0000 (13:13 -0700)
The add_files_to_cache function is invoked internally by
builtin/commit.c and builtin/checkout.c for their flags that stage
modified files before doing the larger operation. These commands
can benefit from batched fsyncing.

Signed-off-by: Neeraj Singh <neerajsi@microsoft.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/add.c

index 9bf37ceae8e2fc23e7fe0ddf587906a29b5dfba3..e39770e4746fc45b7cbad31247a9f46e8846229e 100644 (file)
@@ -141,7 +141,16 @@ int add_files_to_cache(const char *prefix,
        rev.diffopt.format_callback_data = &data;
        rev.diffopt.flags.override_submodule_config = 1;
        rev.max_count = 0; /* do not compare unmerged paths with stage #2 */
+
+       /*
+        * Use an ODB transaction to optimize adding multiple objects.
+        * This function is invoked from commands other than 'add', which
+        * may not have their own transaction active.
+        */
+       begin_odb_transaction();
        run_diff_files(&rev, DIFF_RACY_IS_MODIFIED);
+       end_odb_transaction();
+
        clear_pathspec(&rev.prune_data);
        return !!data.add_errors;
 }