Skip to content

Commit

Permalink
pack-objects: allow --path-walk with --shallow
Browse files Browse the repository at this point in the history
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 <stolee@gmail.com>
  • Loading branch information
derrickstolee committed Oct 21, 2024
1 parent dda73ee commit d5c7b8c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
4 changes: 0 additions & 4 deletions builtin/pack-objects.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
/*
Expand Down
14 changes: 13 additions & 1 deletion t/t5500-fetch-pack.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand All @@ -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
)
'

Expand Down

0 comments on commit d5c7b8c

Please sign in to comment.