Skip to content

Commit

Permalink
pack-objects: allow --shallow and --path-walk
Browse files Browse the repository at this point in the history
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
objets than we desired, due to some incorrect behavior of the path-walk
API, especially around walking unintersting objects.

Now that these things were fixed, we can make this change. Further, we
can add a test to show that the Git client is similarly careful about
selecting the right objects during 'git push' from a shallow clone.

Signed-off-by: Derrick Stolee <[email protected]>
  • Loading branch information
derrickstolee committed Oct 22, 2024
1 parent d13133b commit 1203ee5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
7 changes: 2 additions & 5 deletions builtin/pack-objects.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -4438,6 +4439,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"));
Expand Down Expand Up @@ -4627,7 +4629,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;
Expand Down Expand Up @@ -4812,10 +4813,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
17 changes: 17 additions & 0 deletions t/t5538-push-shallow.sh
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,21 @@ EOF
git cat-file blob $(echo 1|git hash-object --stdin) >/dev/null
)
'

test_expect_success 'push new commit from shallow clone to origin is efficient' '
git init origin &&
echo a >origin/a &&
git -C origin add a &&
git -C origin commit -m "base" &&
echo b >origin/b &&
git -C origin add b &&
git -C origin commit -m "tip" &&
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

0 comments on commit 1203ee5

Please sign in to comment.