Skip to content

Commit 9f0c7c7

Browse files
derrickstoleedscho
authored andcommitted
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 <[email protected]>
1 parent 93178ea commit 9f0c7c7

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

builtin/pack-objects.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ static int keep_unreachable, unpack_unreachable, include_tag;
203203
static timestamp_t unpack_unreachable_expiration;
204204
static int pack_loose_unreachable;
205205
static int cruft;
206+
static int shallow = 0;
206207
static timestamp_t cruft_expiration;
207208
static int local;
208209
static int have_non_local_packs;
@@ -4429,6 +4430,7 @@ static void get_object_list_path_walk(struct rev_info *revs)
44294430
* base objects.
44304431
*/
44314432
info.prune_all_uninteresting = sparse;
4433+
info.edge_aggressive = shallow;
44324434

44334435
if (walk_objects_by_path(&info))
44344436
die(_("failed to pack objects via path-walk"));
@@ -4630,7 +4632,6 @@ int cmd_pack_objects(int argc,
46304632
struct repository *repo UNUSED)
46314633
{
46324634
int use_internal_rev_list = 0;
4633-
int shallow = 0;
46344635
int all_progress_implied = 0;
46354636
struct strvec rp = STRVEC_INIT;
46364637
int rev_list_unpacked = 0, rev_list_all = 0, rev_list_reflog = 0;
@@ -4818,10 +4819,6 @@ int cmd_pack_objects(int argc,
48184819
warning(_("cannot use delta islands with --path-walk"));
48194820
path_walk = 0;
48204821
}
4821-
if (path_walk && shallow) {
4822-
warning(_("cannot use --shallow with --path-walk"));
4823-
path_walk = 0;
4824-
}
48254822
if (path_walk) {
48264823
strvec_push(&rp, "--boundary");
48274824
/*

t/t5538-push-shallow.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,17 @@ EOF
123123
git cat-file blob $(echo 1|git hash-object --stdin) >/dev/null
124124
)
125125
'
126+
127+
test_expect_success 'push new commit from shallow clone has correct object count' '
128+
git init origin &&
129+
test_commit -C origin a &&
130+
test_commit -C origin b &&
131+
132+
git clone --depth=1 "file://$(pwd)/origin" client &&
133+
git -C client checkout -b topic &&
134+
git -C client commit --allow-empty -m "empty" &&
135+
GIT_PROGRESS_DELAY=0 git -C client push --progress origin topic 2>err &&
136+
test_grep "Enumerating objects: 1, done." err
137+
'
138+
126139
test_done

0 commit comments

Comments
 (0)