git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] maintenance: core.commitGraph=false prevents writes
@ 2020-10-12 13:28 Derrick Stolee via GitGitGadget
  2020-10-12 17:30 ` Junio C Hamano
  0 siblings, 1 reply; 3+ messages in thread
From: Derrick Stolee via GitGitGadget @ 2020-10-12 13:28 UTC (permalink / raw)
  To: git; +Cc: Derrick Stolee, Derrick Stolee

From: Derrick Stolee <dstolee@microsoft.com>

Recently, a user had an issue due to combining
fetch.writeCommitGraph=true with core.commitGraph=false. The root bug
has been resolved by preventing commit-graph writes when
core.commitGraph is disabled. This happens inside the 'git commit-graph
write' command, but we can be more aware of this situation and prevent
that process from ever starting in the 'commit-graph' maintenance task.

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
---
    maintenance: core.commitGraph=false prevents writes
    
    As requested [1], this prevents the extra process when core.commitGraph
    is disabled.
    
    This is based on ds/maintenance-commit-graph-auto-fix.
    
    [1] https://lore.kernel.org/git/xmqqft6nrtlw.fsf@gitster.c.googlers.com/
    
    Thanks, -Stolee

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-749%2Fderrickstolee%2Fmaintenance-core-commit-graph-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-749/derrickstolee/maintenance-core-commit-graph-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/749

 builtin/gc.c           | 4 ++++
 t/t7900-maintenance.sh | 8 ++++++++
 2 files changed, 12 insertions(+)

diff --git a/builtin/gc.c b/builtin/gc.c
index 12ddb68bba..e80331c4e2 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -813,6 +813,10 @@ static int run_write_commit_graph(struct maintenance_run_opts *opts)
 
 static int maintenance_task_commit_graph(struct maintenance_run_opts *opts)
 {
+	prepare_repo_settings(the_repository);
+	if (!the_repository->settings.core_commit_graph)
+		return 0;
+
 	close_object_store(the_repository->objects);
 	if (run_write_commit_graph(opts)) {
 		error(_("failed to write commit-graph"));
diff --git a/t/t7900-maintenance.sh b/t/t7900-maintenance.sh
index ee1f4a7ae4..9776154a2a 100755
--- a/t/t7900-maintenance.sh
+++ b/t/t7900-maintenance.sh
@@ -52,6 +52,14 @@ test_expect_success 'run --task=<task>' '
 	test_subcommand git commit-graph write --split --reachable --no-progress <run-both.txt
 '
 
+test_expect_success 'core.commitGraph=false prevents write process' '
+	GIT_TRACE2_EVENT="$(pwd)/no-commit-graph.txt" \
+		git -c core.commitGraph=false maintenance run \
+		--task=commit-graph 2>/dev/null &&
+	test_subcommand ! git commit-graph write --split --reachable --no-progress \
+		<no-commit-graph.txt
+'
+
 test_expect_success 'commit-graph auto condition' '
 	COMMAND="maintenance run --task=commit-graph --auto --quiet" &&
 

base-commit: 8f801804befa12a9c4ddff91275cf03612f1895d
-- 
gitgitgadget

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] maintenance: core.commitGraph=false prevents writes
  2020-10-12 13:28 [PATCH] maintenance: core.commitGraph=false prevents writes Derrick Stolee via GitGitGadget
@ 2020-10-12 17:30 ` Junio C Hamano
  2020-10-12 18:40   ` Derrick Stolee
  0 siblings, 1 reply; 3+ messages in thread
From: Junio C Hamano @ 2020-10-12 17:30 UTC (permalink / raw)
  To: Derrick Stolee via GitGitGadget; +Cc: git, Derrick Stolee, Derrick Stolee

"Derrick Stolee via GitGitGadget" <gitgitgadget@gmail.com> writes:

> From: Derrick Stolee <dstolee@microsoft.com>
>
> Recently, a user had an issue due to combining
> fetch.writeCommitGraph=true with core.commitGraph=false. The root bug
> has been resolved by preventing commit-graph writes when
> core.commitGraph is disabled. This happens inside the 'git commit-graph
> write' command, but we can be more aware of this situation and prevent
> that process from ever starting in the 'commit-graph' maintenance task.
>
> Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
> ---
>     maintenance: core.commitGraph=false prevents writes
>     
>     As requested [1], this prevents the extra process when core.commitGraph
>     is disabled.

That's not a request.  I was just wondering aloud.

If you took inspiration from my thinking aloud, that is wonderful,
but the actual work to ensure it is not an idea that horribly breaks
some underlying assumption I didn't know about in the code and
deciding it is a good idea to do so is all done by you, so please
take the credit due.

>     This is based on ds/maintenance-commit-graph-auto-fix.
>     
>     [1] https://lore.kernel.org/git/xmqqft6nrtlw.fsf@gitster.c.googlers.com/
>     
>     Thanks, -Stolee

Hmph.  

There is a call to prepare_repo_settings() in cmd_gc().

I have to wonder if it should be done much earlier and in a more
central place, perhaps in cmd_maintenance() before anything else
happens.  Even though commit-graph may feel somewhat special only
because it is relatively new, it is not hard to imagine that other
maintenance tasks (both older ones and future ones) would eventually
want to have similar access to the feature settings.

It is OK to keep "the maintenance command works only in the single
repository", and not passing a "repo" that cmd_maintenance() would
prepare by calling prepare_repo_settings() down in the callchain, at
least right now, but we might want to consider doing so in the
future.

Thanks.


> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-749%2Fderrickstolee%2Fmaintenance-core-commit-graph-v1
> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-749/derrickstolee/maintenance-core-commit-graph-v1
> Pull-Request: https://github.com/gitgitgadget/git/pull/749
>
>  builtin/gc.c           | 4 ++++
>  t/t7900-maintenance.sh | 8 ++++++++
>  2 files changed, 12 insertions(+)
>
> diff --git a/builtin/gc.c b/builtin/gc.c
> index 12ddb68bba..e80331c4e2 100644
> --- a/builtin/gc.c
> +++ b/builtin/gc.c
> @@ -813,6 +813,10 @@ static int run_write_commit_graph(struct maintenance_run_opts *opts)
>  
>  static int maintenance_task_commit_graph(struct maintenance_run_opts *opts)
>  {
> +	prepare_repo_settings(the_repository);
> +	if (!the_repository->settings.core_commit_graph)
> +		return 0;
> +
>  	close_object_store(the_repository->objects);
>  	if (run_write_commit_graph(opts)) {
>  		error(_("failed to write commit-graph"));
> diff --git a/t/t7900-maintenance.sh b/t/t7900-maintenance.sh
> index ee1f4a7ae4..9776154a2a 100755
> --- a/t/t7900-maintenance.sh
> +++ b/t/t7900-maintenance.sh
> @@ -52,6 +52,14 @@ test_expect_success 'run --task=<task>' '
>  	test_subcommand git commit-graph write --split --reachable --no-progress <run-both.txt
>  '
>  
> +test_expect_success 'core.commitGraph=false prevents write process' '
> +	GIT_TRACE2_EVENT="$(pwd)/no-commit-graph.txt" \
> +		git -c core.commitGraph=false maintenance run \
> +		--task=commit-graph 2>/dev/null &&
> +	test_subcommand ! git commit-graph write --split --reachable --no-progress \
> +		<no-commit-graph.txt
> +'
> +
>  test_expect_success 'commit-graph auto condition' '
>  	COMMAND="maintenance run --task=commit-graph --auto --quiet" &&
>  
>
> base-commit: 8f801804befa12a9c4ddff91275cf03612f1895d

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] maintenance: core.commitGraph=false prevents writes
  2020-10-12 17:30 ` Junio C Hamano
@ 2020-10-12 18:40   ` Derrick Stolee
  0 siblings, 0 replies; 3+ messages in thread
From: Derrick Stolee @ 2020-10-12 18:40 UTC (permalink / raw)
  To: Junio C Hamano, Derrick Stolee via GitGitGadget
  Cc: git, Derrick Stolee, Derrick Stolee

On 10/12/2020 1:30 PM, Junio C Hamano wrote:
> "Derrick Stolee via GitGitGadget" <gitgitgadget@gmail.com> writes:
> 
>> From: Derrick Stolee <dstolee@microsoft.com>
>>
>> Recently, a user had an issue due to combining
>> fetch.writeCommitGraph=true with core.commitGraph=false. The root bug
>> has been resolved by preventing commit-graph writes when
>> core.commitGraph is disabled. This happens inside the 'git commit-graph
>> write' command, but we can be more aware of this situation and prevent
>> that process from ever starting in the 'commit-graph' maintenance task.
>>
>> Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
>> ---
>>     maintenance: core.commitGraph=false prevents writes
>>     
>>     As requested [1], this prevents the extra process when core.commitGraph
>>     is disabled.
> 
> That's not a request.  I was just wondering aloud.
> 
> If you took inspiration from my thinking aloud, that is wonderful,
> but the actual work to ensure it is not an idea that horribly breaks
> some underlying assumption I didn't know about in the code and
> deciding it is a good idea to do so is all done by you, so please
> take the credit due.

Ok, I saw your comment and I thought "no harm in dropping an extra
process." The patch to no-op the write does more work than this one,
and the commit-graph maintenance task would automatically stop
writing the file but will output a warning.

> There is a call to prepare_repo_settings() in cmd_gc().
>
> I have to wonder if it should be done much earlier and in a more
> central place, perhaps in cmd_maintenance() before anything else
> happens.  Even though commit-graph may feel somewhat special only
> because it is relatively new, it is not hard to imagine that other
> maintenance tasks (both older ones and future ones) would eventually
> want to have similar access to the feature settings.

This "prepare_" pattern is like using "prepare_packed_git()" before
iterating on the packed_git list. We use prepare_repo_settings() to
ensure they are loaded before we use the settings. If the settings are
already loaded, then prepare_repo_settings() exits quickly.

Perhaps it is worth claiming a region of code requiring that the
settings are initialized before calling, but that may lead to issues
in the future that I'd like to avoid. Having a few extra calls to
prepare_repo_settings() is the right trade-off in my opinion.

> It is OK to keep "the maintenance command works only in the single
> repository", and not passing a "repo" that cmd_maintenance() would
> prepare by calling prepare_repo_settings() down in the callchain, at
> least right now, but we might want to consider doing so in the
> future.

Removing the use of the_repository is a worthwhile discussion to
save for another day.

Thanks,
-Stolee

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-10-12 18:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-12 13:28 [PATCH] maintenance: core.commitGraph=false prevents writes Derrick Stolee via GitGitGadget
2020-10-12 17:30 ` Junio C Hamano
2020-10-12 18:40   ` Derrick Stolee

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).