Skip to content

Commit

Permalink
path-walk: add 'edge_aggressive' option
Browse files Browse the repository at this point in the history
Signed-off-by: Derrick Stolee <stolee@gmail.com>
  • Loading branch information
derrickstolee committed Oct 21, 2024
1 parent d5c7b8c commit 74722e3
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 13 deletions.
8 changes: 8 additions & 0 deletions Documentation/technical/api-path-walk.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ better off using the revision walk API instead.
the revision walk so that the walk emits commits marked with the
`UNINTERESTING` flag.

`edge_aggressive`::
For performance reasons, usually only the boundary commits are
explored to find UNINITERESTING objects. However, in the case of
shallow clones it can be helpful to mark all trees and blobs
reachable from UNINTERESTING tip commits as UNINTERESTING. This
matches the behavior of `--objects-edge-aggressive` in the
revision API.

`pl`::
This pattern list pointer allows focusing the path-walk search to
a set of patterns, only emitting paths that match the given
Expand Down
3 changes: 2 additions & 1 deletion 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;
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
22 changes: 22 additions & 0 deletions path-walk.c
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,28 @@ int walk_objects_by_path(struct path_walk_info *info)
if (prepare_revision_walk(info->revs))
die(_("failed to setup revision walk"));

if (info->edge_aggressive) {
for (struct commit_list *list = info->revs->commits;
list;
list = list->next) {
struct commit *commit = list->item;
if (commit->object.flags & UNINTERESTING) {
struct tree *t = repo_get_commit_tree(info->revs->repo, commit);
mark_tree_uninteresting(info->revs->repo, t);
if (!(commit->object.flags & SHOWN))
commit->object.flags |= SHOWN;
}
}
for (size_t i = 0; i < info->revs->cmdline.nr; i++) {
struct object *obj = info->revs->cmdline.rev[i].item;
struct commit *commit = (struct commit *)obj;
if (obj->type != OBJ_COMMIT || !(obj->flags & UNINTERESTING))
continue;
mark_tree_uninteresting(info->revs->repo,
repo_get_commit_tree(info->revs->repo, commit));
}
}

info->revs->blob_objects = info->revs->tree_objects = 0;

if (info->tags) {
Expand Down
7 changes: 7 additions & 0 deletions path-walk.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ struct path_walk_info {
*/
int prune_all_uninteresting;

/**
* When 'edge_aggressive' is set, then the revision walk will use
* the '--object-edge-aggressive' option to mark even more objects
* as uniniteresting.
*/
int edge_aggressive;

/**
* Specify a sparse-checkout definition to match our paths to. Do not
* walk outside of this sparse definition. If the patterns are in
Expand Down
13 changes: 1 addition & 12 deletions t/t5500-fetch-pack.sh
Original file line number Diff line number Diff line change
Expand Up @@ -464,17 +464,6 @@ test_expect_success 'fetch in shallow repo unreachable shallow objects' '
)
'

# 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 @@ -483,7 +472,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 $EXPECTED_SHALLOW_OBJECTS" actual
test_grep "remote: Total 1" actual
)
'

Expand Down

0 comments on commit 74722e3

Please sign in to comment.