From cf7f9daed28fe0d72b164a86ddf7103702e1e9d1 Mon Sep 17 00:00:00 2001 From: Derrick Stolee Date: Mon, 21 Oct 2024 22:59:45 -0400 Subject: [PATCH] pack-objects: allow --shallow and --path-walk There does not appear to be anything particularly incompatible about the --shallow and --path-walk options of 'git pack-objects'. If shallow commits are to be handled differently, then it is by the revision walk that defines the commit set and which are interesting or uninteresting. However, before the previous change, a trivial removal of the warning would cause a failure in t5500-fetch-pack.sh when GIT_TEST_PACK_PATH_WALK is enabled. The shallow fetch would provide more objects than we desired, due to some incorrect behavior of the path-walk API, especially around walking uninteresting objects. To also cover the symmetrical case of pushing from a shallow clone, add a new test to t5538-push-shallow.sh that confirms the correct behavior of pushing only the new object. This works to validate both the --path-walk and --no-path-walk case when toggling the GIT_TEST_PACK_PATH_WALK environment variable. This test would have failed in the --path-walk case if we created it before the previous change. Signed-off-by: Derrick Stolee --- builtin/pack-objects.c | 7 ++----- t/t5538-push-shallow.sh | 13 +++++++++++++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c index 3073ee9a4ab442..593538123da15c 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -201,6 +201,7 @@ static int keep_unreachable, unpack_unreachable, include_tag; static timestamp_t unpack_unreachable_expiration; static int pack_loose_unreachable; static int cruft; +static int shallow = 0; static timestamp_t cruft_expiration; static int local; static int have_non_local_packs; @@ -4427,6 +4428,7 @@ static void get_object_list_path_walk(struct rev_info *revs) * base objects. */ info.prune_all_uninteresting = sparse; + info.edge_aggressive = shallow; if (walk_objects_by_path(&info)) die(_("failed to pack objects via path-walk")); @@ -4628,7 +4630,6 @@ int cmd_pack_objects(int argc, struct repository *repo UNUSED) { int use_internal_rev_list = 0; - int shallow = 0; int all_progress_implied = 0; struct strvec rp = STRVEC_INIT; int rev_list_unpacked = 0, rev_list_all = 0, rev_list_reflog = 0; @@ -4816,10 +4817,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/t5538-push-shallow.sh b/t/t5538-push-shallow.sh index e91fcc173e8116..7e34b2b74caed5 100755 --- a/t/t5538-push-shallow.sh +++ b/t/t5538-push-shallow.sh @@ -123,4 +123,17 @@ EOF git cat-file blob $(echo 1|git hash-object --stdin) >/dev/null ) ' + +test_expect_success 'push new commit from shallow clone has correct object count' ' + git init origin && + test_commit -C origin a && + test_commit -C origin b && + + git clone --depth=1 "file://$(pwd)/origin" client && + git -C client checkout -b topic && + git -C client commit --allow-empty -m "empty" && + GIT_PROGRESS_DELAY=0 git -C client push --progress origin topic 2>err && + test_grep "Enumerating objects: 1, done." err +' + test_done