diff mbox series

[v5,06/14] builtin/add: add ODB transaction around add_files_to_cache

Message ID d514842ad493a819e3640ecb658f702e530d6e85.1648616734.git.gitgitgadget@gmail.com (mailing list archive)
State Accepted
Commit b4a0c6dc9733751788161ce3c181709be89045f9
Headers show
Series core.fsyncmethod: add 'batch' mode for faster fsyncing of multiple objects | expand

Commit Message

Neeraj Singh (WINDOWS-SFS) March 30, 2022, 5:05 a.m. UTC
From: Neeraj Singh <neerajsi@microsoft.com>

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>
---
 builtin/add.c | 9 +++++++++
 1 file changed, 9 insertions(+)

Comments

Junio C Hamano March 30, 2022, 5:47 p.m. UTC | #1
"Neeraj Singh via GitGitGadget" <gitgitgadget@gmail.com> writes:

> From: Neeraj Singh <neerajsi@microsoft.com>
>
> 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>
> ---
>  builtin/add.c | 9 +++++++++
>  1 file changed, 9 insertions(+)
>
> diff --git a/builtin/add.c b/builtin/add.c
> index 9bf37ceae8e..e39770e4746 100644
> --- a/builtin/add.c
> +++ b/builtin/add.c
> @@ -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();
> +

This one clearly is "bulk".  Makes sense.
diff mbox series

Patch

diff --git a/builtin/add.c b/builtin/add.c
index 9bf37ceae8e..e39770e4746 100644
--- a/builtin/add.c
+++ b/builtin/add.c
@@ -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;
 }