Skip to content

Commit 74722e3

Browse files
committed
path-walk: add 'edge_aggressive' option
Signed-off-by: Derrick Stolee <[email protected]>
1 parent d5c7b8c commit 74722e3

File tree

5 files changed

+40
-13
lines changed

5 files changed

+40
-13
lines changed

Documentation/technical/api-path-walk.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ better off using the revision walk API instead.
6565
the revision walk so that the walk emits commits marked with the
6666
`UNINTERESTING` flag.
6767

68+
`edge_aggressive`::
69+
For performance reasons, usually only the boundary commits are
70+
explored to find UNINITERESTING objects. However, in the case of
71+
shallow clones it can be helpful to mark all trees and blobs
72+
reachable from UNINTERESTING tip commits as UNINTERESTING. This
73+
matches the behavior of `--objects-edge-aggressive` in the
74+
revision API.
75+
6876
`pl`::
6977
This pattern list pointer allows focusing the path-walk search to
7078
a set of patterns, only emitting paths that match the given

builtin/pack-objects.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ static int keep_unreachable, unpack_unreachable, include_tag;
201201
static timestamp_t unpack_unreachable_expiration;
202202
static int pack_loose_unreachable;
203203
static int cruft;
204+
int shallow = 0;
204205
static timestamp_t cruft_expiration;
205206
static int local;
206207
static int have_non_local_packs;
@@ -4438,6 +4439,7 @@ static void get_object_list_path_walk(struct rev_info *revs)
44384439
* base objects.
44394440
*/
44404441
info.prune_all_uninteresting = sparse;
4442+
info.edge_aggressive = shallow;
44414443

44424444
if (walk_objects_by_path(&info))
44434445
die(_("failed to pack objects via path-walk"));
@@ -4627,7 +4629,6 @@ int cmd_pack_objects(int argc,
46274629
struct repository *repo UNUSED)
46284630
{
46294631
int use_internal_rev_list = 0;
4630-
int shallow = 0;
46314632
int all_progress_implied = 0;
46324633
struct strvec rp = STRVEC_INIT;
46334634
int rev_list_unpacked = 0, rev_list_all = 0, rev_list_reflog = 0;

path-walk.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,28 @@ int walk_objects_by_path(struct path_walk_info *info)
280280
if (prepare_revision_walk(info->revs))
281281
die(_("failed to setup revision walk"));
282282

283+
if (info->edge_aggressive) {
284+
for (struct commit_list *list = info->revs->commits;
285+
list;
286+
list = list->next) {
287+
struct commit *commit = list->item;
288+
if (commit->object.flags & UNINTERESTING) {
289+
struct tree *t = repo_get_commit_tree(info->revs->repo, commit);
290+
mark_tree_uninteresting(info->revs->repo, t);
291+
if (!(commit->object.flags & SHOWN))
292+
commit->object.flags |= SHOWN;
293+
}
294+
}
295+
for (size_t i = 0; i < info->revs->cmdline.nr; i++) {
296+
struct object *obj = info->revs->cmdline.rev[i].item;
297+
struct commit *commit = (struct commit *)obj;
298+
if (obj->type != OBJ_COMMIT || !(obj->flags & UNINTERESTING))
299+
continue;
300+
mark_tree_uninteresting(info->revs->repo,
301+
repo_get_commit_tree(info->revs->repo, commit));
302+
}
303+
}
304+
283305
info->revs->blob_objects = info->revs->tree_objects = 0;
284306

285307
if (info->tags) {

path-walk.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ struct path_walk_info {
4848
*/
4949
int prune_all_uninteresting;
5050

51+
/**
52+
* When 'edge_aggressive' is set, then the revision walk will use
53+
* the '--object-edge-aggressive' option to mark even more objects
54+
* as uniniteresting.
55+
*/
56+
int edge_aggressive;
57+
5158
/**
5259
* Specify a sparse-checkout definition to match our paths to. Do not
5360
* walk outside of this sparse definition. If the patterns are in

t/t5500-fetch-pack.sh

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -464,17 +464,6 @@ test_expect_success 'fetch in shallow repo unreachable shallow objects' '
464464
)
465465
'
466466

467-
# At the moment, the --path-walk option may provide more objects
468-
# when combined with --shallow than the --no-path-walk option.
469-
if test_bool_env GIT_TEST_PACK_PATH_WALK false
470-
then
471-
EXPECTED_SHALLOW_OBJECTS=3 &&
472-
export EXPECTED_SHALLOW_OBJECTS
473-
else
474-
EXPECTED_SHALLOW_OBJECTS=1 &&
475-
export EXPECTED_SHALLOW_OBJECTS
476-
fi
477-
478467
test_expect_success 'fetch creating new shallow root' '
479468
(
480469
git clone "file://$(pwd)/." shallow10 &&
@@ -483,7 +472,7 @@ test_expect_success 'fetch creating new shallow root' '
483472
git fetch --depth=1 --progress 2>actual &&
484473
# This should fetch only the empty commit, no tree or
485474
# blob objects
486-
test_grep "remote: Total $EXPECTED_SHALLOW_OBJECTS" actual
475+
test_grep "remote: Total 1" actual
487476
)
488477
'
489478

0 commit comments

Comments
 (0)