From d5c7b8c6f383202639c179347bd5810bea8fac7a Mon Sep 17 00:00:00 2001 From: Derrick Stolee Date: Mon, 21 Oct 2024 15:40:02 -0400 Subject: [PATCH] pack-objects: allow --path-walk with --shallow The --path-walk option is important to reduce the size of pushes from certain pipelines, but many of those pipelines use shallow clones. This results in the 'git push' process passing the '--shallow' option to the underlying 'git pack-objects' process. The previous implementation would disable the --path-walk option in this case, making the feature ineffective. The only change that the --shallow option provides is that the revision walk gains the --objects-edge-aggressive option. This is not necessary for satisfying the requirements of 'git pack-objects', but helps when performing shallow fetches. We already recommend that servers do not use pack.usePathWalk=true, so there is little risk in enabling this option for clients at this time. We may consider expanding the implementation in the future to have this aggressive edge walk, but it doesn't work with the current way that the commit walk is used in the path-walk API. The only necessary change to the test suite (when running with GIT_TEST_PACK_PATH_WALK=1) is to change the number of objects fetched in an example where a new shallow commit is created and a --depth=1 fetch is run. In this case, three objects are fetched instead of one. This is due to the lack of the aggressive edge walk, but would not affect client-side pushes. Signed-off-by: Derrick Stolee --- builtin/pack-objects.c | 4 ---- t/t5500-fetch-pack.sh | 14 +++++++++++++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c index b49f5fe797a28d..224c39caa40f11 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -4812,10 +4812,6 @@ int cmd_pack_objects(int argc, warning(_("cannot use delta islands with --path-walk")); path_walk = 0; } - if (path_walk && shallow) { - warning(_("cannot use --shallow with --path-walk")); - path_walk = 0; - } if (path_walk) { strvec_push(&rp, "--boundary"); /* diff --git a/t/t5500-fetch-pack.sh b/t/t5500-fetch-pack.sh index 605f17240c191a..32746678e3b629 100755 --- a/t/t5500-fetch-pack.sh +++ b/t/t5500-fetch-pack.sh @@ -463,6 +463,18 @@ test_expect_success 'fetch in shallow repo unreachable shallow objects' ' git fsck --no-dangling ) ' + +# At the moment, the --path-walk option may provide more objects +# when combined with --shallow than the --no-path-walk option. +if test_bool_env GIT_TEST_PACK_PATH_WALK false +then + EXPECTED_SHALLOW_OBJECTS=3 && + export EXPECTED_SHALLOW_OBJECTS +else + EXPECTED_SHALLOW_OBJECTS=1 && + export EXPECTED_SHALLOW_OBJECTS +fi + test_expect_success 'fetch creating new shallow root' ' ( git clone "file://$(pwd)/." shallow10 && @@ -471,7 +483,7 @@ test_expect_success 'fetch creating new shallow root' ' git fetch --depth=1 --progress 2>actual && # This should fetch only the empty commit, no tree or # blob objects - test_grep "remote: Total 1" actual + test_grep "remote: Total $EXPECTED_SHALLOW_OBJECTS" actual ) '