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. The recently-added tests in t5538-push-shallow.sh help to confirm this behavior is working with the --path-walk option if GIT_TEST_PACK_PATH_WALK is enabled. These tests passed previously due to the --path-walk feature being disabled in the presence of a shallow clone. Signed-off-by: Derrick Stolee <stolee@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Derrick Stolee committed May 16, 2025 at 18:12 UTC c178b02e29f7e3d4033893af9fad8477c9b99be9
2 files changed +11 -4
builtin/pack-objects.c
+2 -3
@@ -210,6 +210,7 @@ static int keep_unreachable, unpack_unreachable, include_tag;
210 static timestamp_t unpack_unreachable_expiration;
211 static int pack_loose_unreachable;
212 static int cruft;
213 +static int shallow = 0;
214 static timestamp_t cruft_expiration;
215 static int local;
216 static int have_non_local_packs;
@@ -4490,6 +4491,7 @@ static void get_object_list_path_walk(struct rev_info *revs)
4491 * base objects.
4492 */
4493 info.prune_all_uninteresting = sparse;
4494 + info.edge_aggressive = shallow;
4495
4496 trace2_region_enter("pack-objects", "path-walk", revs->repo);
4497 result = walk_objects_by_path(&info);
@@ -4695,7 +4697,6 @@ int cmd_pack_objects(int argc,
4697 struct repository *repo UNUSED)
4698 {
4699 int use_internal_rev_list = 0;
4698 - int shallow = 0;
4700 int all_progress_implied = 0;
4701 struct strvec rp = STRVEC_INIT;
4702 int rev_list_unpacked = 0, rev_list_all = 0, rev_list_reflog = 0;
@@ -4881,8 +4882,6 @@ int cmd_pack_objects(int argc,
4882 option = "--filter";
4883 else if (use_delta_islands)
4884 option = "--delta-islands";
4884 - else if (shallow)
4885 - option = "--shallow";
4885
4886 if (option) {
4887 warning(_("cannot use %s with %s"),
t/t5538-push-shallow.sh
+9 -1
@@ -153,7 +153,15 @@ test_expect_success 'push new commit from shallow clone has good deltas' '
153
154 # If the delta base is found, then this message uses "bytes".
155 # If the delta base is not found, then this message uses "KiB".
156 - test_grep "Writing objects: .* bytes" err
156 + test_grep "Writing objects: .* bytes" err &&
157 +
158 + git -C deltas commit --amend -m "changed message" &&
159 + GIT_TRACE2_EVENT="$(pwd)/config-push.txt" \
160 + GIT_PROGRESS_DELAY=0 git -C deltas -c pack.usePathWalk=true \
161 + push --progress -f origin deltas 2>err &&
162 +
163 + test_grep "Enumerating objects: 1, done" err &&
164 + test_region pack-objects path-walk config-push.txt
165 '
166
167 test_done