git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Johannes Schindelin <Johannes.Schindelin@gmx.de>
To: Jeff King <peff@peff.net>
Cc: git@vger.kernel.org, Derrick Stolee <dstolee@microsoft.com>
Subject: Re: [PATCH] t/perf: handle worktrees as test repos
Date: Tue, 16 Feb 2021 22:13:49 +0100 (CET)	[thread overview]
Message-ID: <nycvar.QRO.7.76.6.2102162211050.52@tvgsbejvaqbjf.bet> (raw)
In-Reply-To: <YCwnPVFsYDa0SNmG@coredump.intra.peff.net>

Hi Peff,

On Tue, 16 Feb 2021, Jeff King wrote:

> The perf suite gets confused when test_perf_default_repo is pointed at a
> worktree (which includes when it is run from within a worktree at all,
> since the default is to use the current repository).
>
> Here's an example:
>
>   $ git worktree add ~/foo
>   Preparing worktree (new branch 'foo')
>   HEAD is now at 328c109303 The eighth batch
>   $ cd ~/foo
>   $ make
>   [...build output...]
>   $ cd t/perf
>   $ ./p0000-perf-lib-sanity.sh -v -i
>   [...]
>   perf 1 - test_perf_default_repo works:
>   running:
>   	foo=$(git rev-parse HEAD) &&
>   	test_export foo
>
>   fatal: ambiguous argument 'HEAD': unknown revision or path not in the working tree.
>   Use '--' to separate paths from revisions, like this:
>   'git <command> [<revision>...] -- [<file>...]'
>
> The problem is that we didn't copy all of the necessary files from the
> source repository (in this case we got HEAD, but we have no refs!). We
> discover the git-dir with "rev-parse --git-dir", but this points to the
> worktree's partial repository in .../.git/worktrees/foo.
>
> That partial repository has a "commondir" file which points to the main
> repository, where the actual refs are stored, but we don't copy it. This
> is the correct thing to do, though! If we did copy it, then our scratch
> test repo would be pointing back to the original main repo, and any ref
> updates we made in the tests would impact that original repo.
>
> Instead, we need to either:
>
>   1. Make a scratch copy of the original main repo (in addition to the
>      worktree repo), and point the scratch worktree repo's commondir at
>      it. This preserves the original relationship, but it's doubtful any
>      script really cares (if they are testing worktree performance,
>      they'd probably make their own worktrees). And it's trickier to get
>      right.
>
>   2. Collapse the main and worktree repos into a single scratch repo.
>      This can be done by copying everything from both, preferring any
>      files from the worktree repo.
>
> This patch does the second one. With this applied, the example above
> results in p0000 running successfully.
>
> Reported-by: Derrick Stolee <dstolee@microsoft.com>
> Signed-off-by: Jeff King <peff@peff.net>
> ---

I think you'll also need the equivalent of:

-- snip --
diff --git a/t/perf/perf-lib.sh b/t/perf/perf-lib.sh
index 22d727cef83..0949c360ec4 100644
--- a/t/perf/perf-lib.sh
+++ b/t/perf/perf-lib.sh
@@ -84,7 +84,7 @@ test_perf_create_repo_from () {
 			cp -R "$objects_dir" "$repo/.git/"; } &&
 		for stuff in "$source_git"/*; do
 			case "$stuff" in
-				*/objects|*/hooks|*/config|*/commondir)
+				*/objects|*/hooks|*/config|*/commondir|*/gitdir)
 					;;
 				*)
 					cp -R "$stuff" "$repo/.git/" || exit 1
-- snap --

> Having written that, it occurs to me that an even simpler solution is to
> just always use the commondir as the source of the scratch repo. It does
> not produce the same outcome, but the point is generally just to find a
> suitable starting point for a repository. Grabbing the main repo instead
> of one of its worktrees is probably OK for most tests.

Good point: we probably also need to exclude `*/worktrees/*`, but that is
a bit trickier as we would not want to exclude, say,
`refs/heads/worktrees/cleanup`.

Ciao,
Dscho

>
>  t/perf/perf-lib.sh | 31 ++++++++++++++++++++++---------
>  1 file changed, 22 insertions(+), 9 deletions(-)
>
> diff --git a/t/perf/perf-lib.sh b/t/perf/perf-lib.sh
> index e385c6896f..1226be4005 100644
> --- a/t/perf/perf-lib.sh
> +++ b/t/perf/perf-lib.sh
> @@ -70,27 +70,40 @@ test_perf_do_repo_symlink_config_ () {
>  	test_have_prereq SYMLINKS || git config core.symlinks false
>  }
>
> +test_perf_copy_repo_contents () {
> +	for stuff in "$1"/*
> +	do
> +		case "$stuff" in
> +		*/objects|*/hooks|*/config|*/commondir)
> +			;;
> +		*)
> +			cp -R "$stuff" "$repo/.git/" || exit 1
> +			;;
> +		esac
> +	done
> +}
> +
>  test_perf_create_repo_from () {
>  	test "$#" = 2 ||
>  	BUG "not 2 parameters to test-create-repo"
>  	repo="$1"
>  	source="$2"
>  	source_git="$("$MODERN_GIT" -C "$source" rev-parse --git-dir)"
>  	objects_dir="$("$MODERN_GIT" -C "$source" rev-parse --git-path objects)"
> +	common_dir="$("$MODERN_GIT" -C "$source" rev-parse --git-common-dir)"
>  	mkdir -p "$repo/.git"
>  	(
>  		cd "$source" &&
>  		{ cp -Rl "$objects_dir" "$repo/.git/" 2>/dev/null ||
>  			cp -R "$objects_dir" "$repo/.git/"; } &&
> -		for stuff in "$source_git"/*; do
> -			case "$stuff" in
> -				*/objects|*/hooks|*/config|*/commondir)
> -					;;
> -				*)
> -					cp -R "$stuff" "$repo/.git/" || exit 1
> -					;;
> -			esac
> -		done
> +
> +		# common_dir must come first here, since we want source_git to
> +		# take precedence and overwrite any overlapping files
> +		test_perf_copy_repo_contents "$common_dir"
> +		if test "$source_git" != "$common_dir"
> +		then
> +			test_perf_copy_repo_contents "$source_git"
> +		fi
>  	) &&
>  	(
>  		cd "$repo" &&
> --
> 2.30.1.989.g5e01c2f281
>
>

  parent reply	other threads:[~2021-02-16 21:15 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-16 20:12 [PATCH] t/perf: handle worktrees as test repos Jeff King
2021-02-16 20:16 ` Jeff King
2021-02-16 20:36   ` Derrick Stolee
2021-02-16 22:52   ` Junio C Hamano
2021-02-16 22:56     ` Jeff King
2021-02-16 21:13 ` Johannes Schindelin [this message]
2021-02-16 21:38   ` Jeff King
2021-02-26  7:09 ` [PATCH v2] t/perf worktree improvements Jeff King
2021-02-26  7:11   ` [PATCH v2 1/2] t/perf: handle worktrees as test repos Jeff King
2021-02-26  7:13   ` [PATCH v2 2/2] t/perf: avoid copying worktree files from test repo Jeff King
2021-02-26 15:43   ` [PATCH v2] t/perf worktree improvements Derrick Stolee
2021-03-01 22:03     ` Johannes Schindelin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=nycvar.QRO.7.76.6.2102162211050.52@tvgsbejvaqbjf.bet \
    --to=johannes.schindelin@gmx.de \
    --cc=dstolee@microsoft.com \
    --cc=git@vger.kernel.org \
    --cc=peff@peff.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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 NNTP newsgroup(s).