All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] maintenance: test commit-graph auto condition
@ 2020-10-07 12:55 Derrick Stolee via GitGitGadget
  2020-10-07 20:22 ` Junio C Hamano
  2020-10-08  0:50 ` [PATCH v2] " Derrick Stolee via GitGitGadget
  0 siblings, 2 replies; 4+ messages in thread
From: Derrick Stolee via GitGitGadget @ 2020-10-07 12:55 UTC (permalink / raw)
  To: git; +Cc: Derrick Stolee, Derrick Stolee

From: Derrick Stolee <dstolee@microsoft.com>

The auto condition for the commit-graph maintenance task walks refs
looking for commits that are not in the commit-graph file. This was
added in 4ddc79b2 (maintenance: add auto condition for commit-graph
task, 2020-09-17) but was left untested.

The initial goal of this change was to demonstrate the feature works
properly by adding tests. However, there was an off-by-one error that
caused the basic tests around maintenance.commit-graph.auto=1 to fail
when it should work.

The subtlety is that if a ref tip is not in the commit-graph, then we
were not adding that to the total count. In the test, we see that we
have only added one commit since our last commit-graph write, so the
auto condition would say there is nothing to do.

The fix is simple: add the check for the commit-graph position to see
that the tip is not in the commit-graph file before starting our walk.
Since this happens before adding to the DFS stack, we do not need to
clear our (currently empty) commit list.

This does add some extra complexity for the test, because we also want
to verify that the walk along the parents actually does some work. This
means we need to add at least two commits in a row without writing the
commit-graph. However, we also need to make sure no additional refs are
pointing to the middle of this list or else the for_each_ref() in
should_write_commit_graph() might visit these commits as tips instead of
doing a DFS walk. Hence, the last two commits are added with "git
commit" instead of "test_commit".

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
---
    maintenance: test commit-graph auto condition
    
    As promised [1], here is a test to check that
    maintenance.commit-graph.auto behaves correctly. In the process, I found
    a small off-by-one error that is not super-critical, but worth fixing.
    
    Thanks, -Stolee
    
    [1] 
    https://lore.kernel.org/git/cfc8a8e9-f812-2cb1-f6d8-57ef585346d1@gmail.com/

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-746%2Fderrickstolee%2Fmaintenance%2Fcg-auto-test-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-746/derrickstolee/maintenance/cg-auto-test-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/746

 builtin/gc.c           |  8 +++++++-
 t/t7900-maintenance.sh | 29 +++++++++++++++++++++++++++++
 2 files changed, 36 insertions(+), 1 deletion(-)

diff --git a/builtin/gc.c b/builtin/gc.c
index 090959350e..12ddb68bba 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -737,9 +737,15 @@ static int dfs_on_ref(const char *refname,
 	commit = lookup_commit(the_repository, oid);
 	if (!commit)
 		return 0;
-	if (parse_commit(commit))
+	if (parse_commit(commit) ||
+	    commit_graph_position(commit) != COMMIT_NOT_FROM_GRAPH)
 		return 0;
 
+	data->num_not_in_graph++;
+
+	if (data->num_not_in_graph >= data->limit)
+		return 1;
+
 	commit_list_append(commit, &stack);
 
 	while (!result && stack) {
diff --git a/t/t7900-maintenance.sh b/t/t7900-maintenance.sh
index 53c883531e..3e16439bf6 100755
--- a/t/t7900-maintenance.sh
+++ b/t/t7900-maintenance.sh
@@ -52,6 +52,35 @@ test_expect_success 'run --task=<task>' '
 	test_subcommand git commit-graph write --split --reachable --no-progress <run-both.txt
 '
 
+test_expect_success 'commit-graph auto condition' '
+	COMMAND="maintenance run --task=commit-graph --auto --quiet" &&
+
+	GIT_TRACE2_EVENT="$(pwd)/cg-no.txt" \
+		git -c maintenance.commit-graph.auto=1 $COMMAND &&
+	GIT_TRACE2_EVENT="$(pwd)/cg-negative-means-yes.txt" \
+		git -c maintenance.commit-graph.auto="-1" $COMMAND &&
+
+	test_commit one &&
+
+	GIT_TRACE2_EVENT="$(pwd)/cg-zero-means-no.txt" \
+		git -c maintenance.commit-graph.auto=0 $COMMAND &&
+	GIT_TRACE2_EVENT="$(pwd)/cg-one-satisfied.txt" \
+		git -c maintenance.commit-graph.auto=1 $COMMAND &&
+
+	git commit --allow-empty -m "two" &&
+	git commit --allow-empty -m "three" &&
+
+	GIT_TRACE2_EVENT="$(pwd)/cg-two-satisfied.txt" \
+		git -c maintenance.commit-graph.auto=2 $COMMAND &&
+
+	COMMIT_GRAPH_WRITE="git commit-graph write --split --reachable --no-progress" &&
+	test_subcommand ! $COMMIT_GRAPH_WRITE <cg-no.txt &&
+	test_subcommand $COMMIT_GRAPH_WRITE <cg-negative-means-yes.txt &&
+	test_subcommand ! $COMMIT_GRAPH_WRITE <cg-zero-means-no.txt &&
+	test_subcommand $COMMIT_GRAPH_WRITE <cg-one-satisfied.txt &&
+	test_subcommand $COMMIT_GRAPH_WRITE <cg-two-satisfied.txt
+'
+
 test_expect_success 'run --task=bogus' '
 	test_must_fail git maintenance run --task=bogus 2>err &&
 	test_i18ngrep "is not a valid task" err

base-commit: 25914c4fdeefd99b06e134496dfb9bbb58a5c417
-- 
gitgitgadget

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

* Re: [PATCH] maintenance: test commit-graph auto condition
  2020-10-07 12:55 [PATCH] maintenance: test commit-graph auto condition Derrick Stolee via GitGitGadget
@ 2020-10-07 20:22 ` Junio C Hamano
  2020-10-08  0:13   ` Derrick Stolee
  2020-10-08  0:50 ` [PATCH v2] " Derrick Stolee via GitGitGadget
  1 sibling, 1 reply; 4+ messages in thread
From: Junio C Hamano @ 2020-10-07 20:22 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>
>
> The auto condition for the commit-graph maintenance task walks refs
> looking for commits that are not in the commit-graph file. This was
> added in 4ddc79b2 (maintenance: add auto condition for commit-graph
> task, 2020-09-17) but was left untested.
>
> The initial goal of this change was to demonstrate the feature works
> properly by adding tests. However, there was an off-by-one error that
> caused the basic tests around maintenance.commit-graph.auto=1 to fail
> when it should work.
>
> The subtlety is that if a ref tip is not in the commit-graph, then we
> were not adding that to the total count. In the test, we see that we
> have only added one commit since our last commit-graph write, so the
> auto condition would say there is nothing to do.
>
> The fix is simple: add the check for the commit-graph position to see
> that the tip is not in the commit-graph file before starting our walk.
> Since this happens before adding to the DFS stack, we do not need to
> clear our (currently empty) commit list.
>
> This does add some extra complexity for the test, because we also want
> to verify that the walk along the parents actually does some work. This
> means we need to add at least two commits in a row without writing the
> commit-graph. However, we also need to make sure no additional refs are
> pointing to the middle of this list or else the for_each_ref() in
> should_write_commit_graph() might visit these commits as tips instead of
> doing a DFS walk. Hence, the last two commits are added with "git
> commit" instead of "test_commit".
>
> Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
> ---
>     maintenance: test commit-graph auto condition
>     
>     As promised [1], here is a test to check that
>     maintenance.commit-graph.auto behaves correctly. In the process, I found
>     a small off-by-one error that is not super-critical, but worth fixing.
>     
>     Thanks, -Stolee
>     
>     [1] 
>     https://lore.kernel.org/git/cfc8a8e9-f812-2cb1-f6d8-57ef585346d1@gmail.com/
>
> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-746%2Fderrickstolee%2Fmaintenance%2Fcg-auto-test-v1
> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-746/derrickstolee/maintenance/cg-auto-test-v1
> Pull-Request: https://github.com/gitgitgadget/git/pull/746
>
>  builtin/gc.c           |  8 +++++++-
>  t/t7900-maintenance.sh | 29 +++++++++++++++++++++++++++++
>  2 files changed, 36 insertions(+), 1 deletion(-)

Hmph.  Something in ds/maintenance-part-2 series does not seem to
work well with this change.  I noticed it when testing today's first
integration cycle of jch and seen branches, but even when applied to
ds/maintenance-part-2 alone without any other topics in seen, it
seems to break in an unexpected place.

    $ git checkout -b ds/maintenance-commit-graph-auto-fix
    $ git am -s $this_message
    $ git checkout ds/maintenance-part-2^0
    $ git cherry-pick ds/maintenance-commit-graph-auto-fix
    $ make && (cd t && sh t7900-maintenance.sh -i -v)
    ...
    expecting success of 7900.9 'prefetch multiple remotes':
    ...
    Cloning into 'clone1'...
    done.
    Cloning into 'clone2'...
    done.
    Switched to a new branch 'one'
    Switched to a new branch 'two'
    On branch one
    nothing to commit, working tree clean
    not ok 9 - prefetch multiple remotes

Perhaps the new test added here breaks the expectation of tests
added in the other series?

> diff --git a/t/t7900-maintenance.sh b/t/t7900-maintenance.sh
> index 53c883531e..3e16439bf6 100755
> --- a/t/t7900-maintenance.sh
> +++ b/t/t7900-maintenance.sh
> @@ -52,6 +52,35 @@ test_expect_success 'run --task=<task>' '
>  	test_subcommand git commit-graph write --split --reachable --no-progress <run-both.txt
>  '
>  
> +test_expect_success 'commit-graph auto condition' '
> +	COMMAND="maintenance run --task=commit-graph --auto --quiet" &&
> +
> +	GIT_TRACE2_EVENT="$(pwd)/cg-no.txt" \
> +		git -c maintenance.commit-graph.auto=1 $COMMAND &&
> +	GIT_TRACE2_EVENT="$(pwd)/cg-negative-means-yes.txt" \
> +		git -c maintenance.commit-graph.auto="-1" $COMMAND &&
> +
> +	test_commit one &&
> +
> +	GIT_TRACE2_EVENT="$(pwd)/cg-zero-means-no.txt" \
> +		git -c maintenance.commit-graph.auto=0 $COMMAND &&
> +	GIT_TRACE2_EVENT="$(pwd)/cg-one-satisfied.txt" \
> +		git -c maintenance.commit-graph.auto=1 $COMMAND &&
> +
> +	git commit --allow-empty -m "two" &&
> +	git commit --allow-empty -m "three" &&
> +
> +	GIT_TRACE2_EVENT="$(pwd)/cg-two-satisfied.txt" \
> +		git -c maintenance.commit-graph.auto=2 $COMMAND &&
> +
> +	COMMIT_GRAPH_WRITE="git commit-graph write --split --reachable --no-progress" &&
> +	test_subcommand ! $COMMIT_GRAPH_WRITE <cg-no.txt &&
> +	test_subcommand $COMMIT_GRAPH_WRITE <cg-negative-means-yes.txt &&
> +	test_subcommand ! $COMMIT_GRAPH_WRITE <cg-zero-means-no.txt &&
> +	test_subcommand $COMMIT_GRAPH_WRITE <cg-one-satisfied.txt &&
> +	test_subcommand $COMMIT_GRAPH_WRITE <cg-two-satisfied.txt
> +'
> +
>  test_expect_success 'run --task=bogus' '
>  	test_must_fail git maintenance run --task=bogus 2>err &&
>  	test_i18ngrep "is not a valid task" err
>
> base-commit: 25914c4fdeefd99b06e134496dfb9bbb58a5c417

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

* Re: [PATCH] maintenance: test commit-graph auto condition
  2020-10-07 20:22 ` Junio C Hamano
@ 2020-10-08  0:13   ` Derrick Stolee
  0 siblings, 0 replies; 4+ messages in thread
From: Derrick Stolee @ 2020-10-08  0:13 UTC (permalink / raw)
  To: Junio C Hamano, Derrick Stolee via GitGitGadget
  Cc: git, Derrick Stolee, Derrick Stolee

On 10/7/2020 4:22 PM, Junio C Hamano wrote:
> Hmph.  Something in ds/maintenance-part-2 series does not seem to
> work well with this change.  I noticed it when testing today's first
> integration cycle of jch and seen branches, but even when applied to
> ds/maintenance-part-2 alone without any other topics in seen, it
> seems to break in an unexpected place.

Thank you for alerting me to this. I should have ran the tests after
merging with the other branches in progress.

It seems my issue is that I use "test_commit one" in two places now,
so the second complains that nothing is new to commit.

The simplest fix is to use "first", "second", and "third" in this
patch, so I'll send a v2 soon with that change.

Thanks,
-Stolee


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

* [PATCH v2] maintenance: test commit-graph auto condition
  2020-10-07 12:55 [PATCH] maintenance: test commit-graph auto condition Derrick Stolee via GitGitGadget
  2020-10-07 20:22 ` Junio C Hamano
@ 2020-10-08  0:50 ` Derrick Stolee via GitGitGadget
  1 sibling, 0 replies; 4+ messages in thread
From: Derrick Stolee via GitGitGadget @ 2020-10-08  0:50 UTC (permalink / raw)
  To: git; +Cc: Derrick Stolee, Derrick Stolee, Derrick Stolee

From: Derrick Stolee <dstolee@microsoft.com>

The auto condition for the commit-graph maintenance task walks refs
looking for commits that are not in the commit-graph file. This was
added in 4ddc79b2 (maintenance: add auto condition for commit-graph
task, 2020-09-17) but was left untested.

The initial goal of this change was to demonstrate the feature works
properly by adding tests. However, there was an off-by-one error that
caused the basic tests around maintenance.commit-graph.auto=1 to fail
when it should work.

The subtlety is that if a ref tip is not in the commit-graph, then we
were not adding that to the total count. In the test, we see that we
have only added one commit since our last commit-graph write, so the
auto condition would say there is nothing to do.

The fix is simple: add the check for the commit-graph position to see
that the tip is not in the commit-graph file before starting our walk.
Since this happens before adding to the DFS stack, we do not need to
clear our (currently empty) commit list.

This does add some extra complexity for the test, because we also want
to verify that the walk along the parents actually does some work. This
means we need to add at least two commits in a row without writing the
commit-graph. However, we also need to make sure no additional refs are
pointing to the middle of this list or else the for_each_ref() in
should_write_commit_graph() might visit these commits as tips instead of
doing a DFS walk. Hence, the last two commits are added with "git
commit" instead of "test_commit".

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
---
    maintenance: test commit-graph auto condition
    
    As promised [1], here is a test to check that
    maintenance.commit-graph.auto behaves correctly. In the process, I found
    a small off-by-one error that is not super-critical, but worth fixing.
    
    This is based on ds/maintenance-part-1, but my GGG pull request targets
    ds/maintenance-part-3 to make sure it merges cleanly and the result
    builds & tests cleanly.
    
    Thanks, -Stolee
    
    [1] 
    https://lore.kernel.org/git/cfc8a8e9-f812-2cb1-f6d8-57ef585346d1@gmail.com/

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-746%2Fderrickstolee%2Fmaintenance%2Fcg-auto-test-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-746/derrickstolee/maintenance/cg-auto-test-v2
Pull-Request: https://github.com/gitgitgadget/git/pull/746

Range-diff vs v1:

 1:  39223f21fb ! 1:  984ee2d9c0 maintenance: test commit-graph auto condition
     @@ t/t7900-maintenance.sh: test_expect_success 'run --task=<task>' '
      +	GIT_TRACE2_EVENT="$(pwd)/cg-negative-means-yes.txt" \
      +		git -c maintenance.commit-graph.auto="-1" $COMMAND &&
      +
     -+	test_commit one &&
     ++	test_commit first &&
      +
      +	GIT_TRACE2_EVENT="$(pwd)/cg-zero-means-no.txt" \
      +		git -c maintenance.commit-graph.auto=0 $COMMAND &&
      +	GIT_TRACE2_EVENT="$(pwd)/cg-one-satisfied.txt" \
      +		git -c maintenance.commit-graph.auto=1 $COMMAND &&
      +
     -+	git commit --allow-empty -m "two" &&
     -+	git commit --allow-empty -m "three" &&
     ++	git commit --allow-empty -m "second" &&
     ++	git commit --allow-empty -m "third" &&
      +
      +	GIT_TRACE2_EVENT="$(pwd)/cg-two-satisfied.txt" \
      +		git -c maintenance.commit-graph.auto=2 $COMMAND &&


 builtin/gc.c           |  8 +++++++-
 t/t7900-maintenance.sh | 29 +++++++++++++++++++++++++++++
 2 files changed, 36 insertions(+), 1 deletion(-)

diff --git a/builtin/gc.c b/builtin/gc.c
index 090959350e..12ddb68bba 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -737,9 +737,15 @@ static int dfs_on_ref(const char *refname,
 	commit = lookup_commit(the_repository, oid);
 	if (!commit)
 		return 0;
-	if (parse_commit(commit))
+	if (parse_commit(commit) ||
+	    commit_graph_position(commit) != COMMIT_NOT_FROM_GRAPH)
 		return 0;
 
+	data->num_not_in_graph++;
+
+	if (data->num_not_in_graph >= data->limit)
+		return 1;
+
 	commit_list_append(commit, &stack);
 
 	while (!result && stack) {
diff --git a/t/t7900-maintenance.sh b/t/t7900-maintenance.sh
index 53c883531e..ee1f4a7ae4 100755
--- a/t/t7900-maintenance.sh
+++ b/t/t7900-maintenance.sh
@@ -52,6 +52,35 @@ test_expect_success 'run --task=<task>' '
 	test_subcommand git commit-graph write --split --reachable --no-progress <run-both.txt
 '
 
+test_expect_success 'commit-graph auto condition' '
+	COMMAND="maintenance run --task=commit-graph --auto --quiet" &&
+
+	GIT_TRACE2_EVENT="$(pwd)/cg-no.txt" \
+		git -c maintenance.commit-graph.auto=1 $COMMAND &&
+	GIT_TRACE2_EVENT="$(pwd)/cg-negative-means-yes.txt" \
+		git -c maintenance.commit-graph.auto="-1" $COMMAND &&
+
+	test_commit first &&
+
+	GIT_TRACE2_EVENT="$(pwd)/cg-zero-means-no.txt" \
+		git -c maintenance.commit-graph.auto=0 $COMMAND &&
+	GIT_TRACE2_EVENT="$(pwd)/cg-one-satisfied.txt" \
+		git -c maintenance.commit-graph.auto=1 $COMMAND &&
+
+	git commit --allow-empty -m "second" &&
+	git commit --allow-empty -m "third" &&
+
+	GIT_TRACE2_EVENT="$(pwd)/cg-two-satisfied.txt" \
+		git -c maintenance.commit-graph.auto=2 $COMMAND &&
+
+	COMMIT_GRAPH_WRITE="git commit-graph write --split --reachable --no-progress" &&
+	test_subcommand ! $COMMIT_GRAPH_WRITE <cg-no.txt &&
+	test_subcommand $COMMIT_GRAPH_WRITE <cg-negative-means-yes.txt &&
+	test_subcommand ! $COMMIT_GRAPH_WRITE <cg-zero-means-no.txt &&
+	test_subcommand $COMMIT_GRAPH_WRITE <cg-one-satisfied.txt &&
+	test_subcommand $COMMIT_GRAPH_WRITE <cg-two-satisfied.txt
+'
+
 test_expect_success 'run --task=bogus' '
 	test_must_fail git maintenance run --task=bogus 2>err &&
 	test_i18ngrep "is not a valid task" err

base-commit: 25914c4fdeefd99b06e134496dfb9bbb58a5c417
-- 
gitgitgadget

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

end of thread, other threads:[~2020-10-08  0:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-07 12:55 [PATCH] maintenance: test commit-graph auto condition Derrick Stolee via GitGitGadget
2020-10-07 20:22 ` Junio C Hamano
2020-10-08  0:13   ` Derrick Stolee
2020-10-08  0:50 ` [PATCH v2] " Derrick Stolee via GitGitGadget

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.