diff mbox series

[v2] partial-clone: add a partial-clone test case

Message ID pull.1175.v2.git.1647423969576.gitgitgadget@gmail.com (mailing list archive)
State Accepted
Commit ab3892e48f138e9c519383bb9f48fc48f5ebba65
Headers show
Series [v2] partial-clone: add a partial-clone test case | expand

Commit Message

Abhradeep Chakraborty March 16, 2022, 9:46 a.m. UTC
From: Abhradeep Chakraborty <chakrabortyabhradeep79@gmail.com>

In a blobless-cloned repo, `git log --follow -- <path>` (`<path>` have
an exact OID rename) shouldn't download blob of the file from where the
new file is renamed.

Add a test case to verify it.

Signed-off-by: Abhradeep Chakraborty <chakrabortyabhradeep79@gmail.com>
---
    partial-clone: add a partial-clone test case
    
    changes since v1:
    
     1. remove the event track method to detect the downloading as it is not
        future proof ( and buggy).
     2. Instead see if the file is missing initially and after running the
        git log --follow ... command.
    
    Fixes #827 [1]
    
    [1] https://github.com/gitgitgadget/git/issues/827

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1175%2FAbhra303%2Fcheck_partial_clone-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1175/Abhra303/check_partial_clone-v2
Pull-Request: https://github.com/gitgitgadget/git/pull/1175

Range-diff vs v1:

 1:  6b80b981977 ! 1:  52df433ad5e partial-clone: add a partial-clone test case
     @@ Commit message
          partial-clone: add a partial-clone test case
      
          In a blobless-cloned repo, `git log --follow -- <path>` (`<path>` have
     -    an exact OID rename) doesn't download blob of the file from where the
     +    an exact OID rename) shouldn't download blob of the file from where the
          new file is renamed.
      
          Add a test case to verify it.
     @@ t/t0410-partial-clone.sh: test_expect_success 'do not fetch when checking existe
       	git -C repo cherry-pick side1
       '
       
     -+test_expect_success 'git log --follow does not download blobs if an exact OID rename found (blobless clone)' '
     ++test_expect_success 'exact rename does not need to fetch the blob lazily' '
      +	rm -rf repo partial.git &&
      +	test_create_repo repo &&
      +	content="some dummy content" &&
      +	test_commit -C repo create-a-file file.txt "$content" &&
      +	git -C repo mv file.txt new-file.txt &&
      +	git -C repo commit -m rename-the-file &&
     ++	FILE_HASH=$(git -C repo rev-parse HEAD:new-file.txt) &&
      +	test_config -C repo uploadpack.allowfilter 1 &&
      +	test_config -C repo uploadpack.allowanysha1inwant 1 &&
      +
     -+	git clone --filter=blob:none "file://$(pwd)/repo" partial.git &&
     -+	GIT_TRACE2_EVENT="$(pwd)/trace.txt" \
     -+		git -C partial.git log --follow -- new-file.txt > "$(pwd)/trace.txt" &&
     -+	! test_subcommand_inexact fetch <trace.txt
     ++	git clone --filter=blob:none --bare "file://$(pwd)/repo" partial.git &&
     ++	git -C partial.git rev-list --objects --missing=print HEAD >out &&
     ++	grep "[?]$FILE_HASH" out &&
     ++	git -C partial.git log --follow -- new-file.txt &&
     ++	git -C partial.git rev-list --objects --missing=print HEAD >out &&
     ++	grep "[?]$FILE_HASH" out
      +'
      +
       test_expect_success 'lazy-fetch when accessing object not in the_repository' '
       	rm -rf full partial.git &&
       	test_create_repo full &&
     -
     - ## t/test-lib-functions.sh ##
     -@@ t/test-lib-functions.sh: test_subcommand_inexact () {
     - 		shift
     - 	fi
     - 
     --	local expr=$(printf '"%s".*' "$@")
     -+	local expr=$(printf '.*"%s".*' "$@")
     - 	expr="${expr%,}"
     - 
     - 	if test -n "$negate"


 t/t0410-partial-clone.sh | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)


base-commit: 1a4874565fa3b6668042216189551b98b4dc0b1b

Comments

Derrick Stolee March 21, 2022, 3:26 p.m. UTC | #1
On 3/16/2022 5:46 AM, Abhradeep Chakraborty via GitGitGadget wrote:
> From: Abhradeep Chakraborty <chakrabortyabhradeep79@gmail.com>
> 
> In a blobless-cloned repo, `git log --follow -- <path>` (`<path>` have
> an exact OID rename) shouldn't download blob of the file from where the
> new file is renamed.
> 
> Add a test case to verify it.
> 
> Signed-off-by: Abhradeep Chakraborty <chakrabortyabhradeep79@gmail.com>
> ---
>     partial-clone: add a partial-clone test case
>     
>     changes since v1:
>     
>      1. remove the event track method to detect the downloading as it is not
>         future proof ( and buggy).
>      2. Instead see if the file is missing initially and after running the
>         git log --follow ... command.

> +test_expect_success 'exact rename does not need to fetch the blob lazily' '
> +	rm -rf repo partial.git &&
> +	test_create_repo repo &&
> +	content="some dummy content" &&
> +	test_commit -C repo create-a-file file.txt "$content" &&
> +	git -C repo mv file.txt new-file.txt &&
> +	git -C repo commit -m rename-the-file &&
> +	FILE_HASH=$(git -C repo rev-parse HEAD:new-file.txt) &&
> +	test_config -C repo uploadpack.allowfilter 1 &&
> +	test_config -C repo uploadpack.allowanysha1inwant 1 &&
> +
> +	git clone --filter=blob:none --bare "file://$(pwd)/repo" partial.git &&
> +	git -C partial.git rev-list --objects --missing=print HEAD >out &&
> +	grep "[?]$FILE_HASH" out &&
> +	git -C partial.git log --follow -- new-file.txt &&
> +	git -C partial.git rev-list --objects --missing=print HEAD >out &&
> +	grep "[?]$FILE_HASH" out
> +'
> +

Thanks for taking the feedback and turning it into a good test!

I'm adding it as a TODO to go fix the buggy helper as discussed.

Thanks,
-Stolee
diff mbox series

Patch

diff --git a/t/t0410-partial-clone.sh b/t/t0410-partial-clone.sh
index f17abd298c8..1e864cf3172 100755
--- a/t/t0410-partial-clone.sh
+++ b/t/t0410-partial-clone.sh
@@ -618,6 +618,25 @@  test_expect_success 'do not fetch when checking existence of tree we construct o
 	git -C repo cherry-pick side1
 '
 
+test_expect_success 'exact rename does not need to fetch the blob lazily' '
+	rm -rf repo partial.git &&
+	test_create_repo repo &&
+	content="some dummy content" &&
+	test_commit -C repo create-a-file file.txt "$content" &&
+	git -C repo mv file.txt new-file.txt &&
+	git -C repo commit -m rename-the-file &&
+	FILE_HASH=$(git -C repo rev-parse HEAD:new-file.txt) &&
+	test_config -C repo uploadpack.allowfilter 1 &&
+	test_config -C repo uploadpack.allowanysha1inwant 1 &&
+
+	git clone --filter=blob:none --bare "file://$(pwd)/repo" partial.git &&
+	git -C partial.git rev-list --objects --missing=print HEAD >out &&
+	grep "[?]$FILE_HASH" out &&
+	git -C partial.git log --follow -- new-file.txt &&
+	git -C partial.git rev-list --objects --missing=print HEAD >out &&
+	grep "[?]$FILE_HASH" out
+'
+
 test_expect_success 'lazy-fetch when accessing object not in the_repository' '
 	rm -rf full partial.git &&
 	test_create_repo full &&