]> git.ipfire.org Git - thirdparty/git.git/commitdiff
tree:<depth>: skip some trees even when collecting omits
authorMatthew DeVore <matvore@google.com>
Wed, 9 Jan 2019 02:59:14 +0000 (18:59 -0800)
committerJunio C Hamano <gitster@pobox.com>
Tue, 15 Jan 2019 23:39:34 +0000 (15:39 -0800)
If a tree has already been recorded as omitted, we don't need to
traverse it again just to collect its omits. Stop traversing trees a
second time when collecting omits.

Signed-off-by: Matthew DeVore <matvore@google.com>
Reviewed-by: Jonathan Tan <jonathantanmy@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
list-objects-filter.c
t/t6112-rev-list-filters-objects.sh

index 786e0dd0b15a6d959515312cb9ceea8410c398a1..ee449de3f77e2b8663d1ae2d43da049f15269249 100644 (file)
@@ -107,18 +107,19 @@ struct seen_map_entry {
        size_t depth;
 };
 
-static void filter_trees_update_omits(
+/* Returns 1 if the oid was in the omits set before it was invoked. */
+static int filter_trees_update_omits(
        struct object *obj,
        struct filter_trees_depth_data *filter_data,
        int include_it)
 {
        if (!filter_data->omits)
-               return;
+               return 0;
 
        if (include_it)
-               oidset_remove(filter_data->omits, &obj->oid);
+               return oidset_remove(filter_data->omits, &obj->oid);
        else
-               oidset_insert(filter_data->omits, &obj->oid);
+               return oidset_insert(filter_data->omits, &obj->oid);
 }
 
 static enum list_objects_filter_result filter_trees_depth(
@@ -171,12 +172,17 @@ static enum list_objects_filter_result filter_trees_depth(
                if (already_seen) {
                        filter_res = LOFR_SKIP_TREE;
                } else {
+                       int been_omitted = filter_trees_update_omits(
+                               obj, filter_data, include_it);
                        seen_info->depth = filter_data->current_depth;
-                       filter_trees_update_omits(obj, filter_data, include_it);
 
                        if (include_it)
                                filter_res = LOFR_DO_SHOW;
-                       else if (filter_data->omits)
+                       else if (filter_data->omits && !been_omitted)
+                               /*
+                                * Must update omit information of children
+                                * recursively; they have not been omitted yet.
+                                */
                                filter_res = LOFR_ZERO;
                        else
                                filter_res = LOFR_SKIP_TREE;
index 706845f1d9f8f8031031785129a7042049c4f1a9..eb9e4119e2d5b77415e77b14ff23abe659180313 100755 (executable)
@@ -283,7 +283,7 @@ test_expect_success 'verify tree:0 includes trees in "filtered" output' '
 
 # Make sure tree:0 does not iterate through any trees.
 
-test_expect_success 'filter a GIANT tree through tree:0' '
+test_expect_success 'verify skipping tree iteration when not collecting omits' '
        GIT_TRACE=1 git -C r3 rev-list \
                --objects --filter=tree:0 HEAD 2>filter_trace &&
        grep "Skipping contents of tree [.][.][.]" filter_trace >actual &&
@@ -377,6 +377,15 @@ test_expect_success 'test tree:# filter provisional omit for blob and tree' '
        expect_has_with_different_name r4 filt/subdir
 '
 
+test_expect_success 'verify skipping tree iteration when collecting omits' '
+       GIT_TRACE=1 git -C r4 rev-list --filter-print-omitted \
+               --objects --filter=tree:0 HEAD 2>filter_trace &&
+       grep "^Skipping contents of tree " filter_trace >actual &&
+
+       echo "Skipping contents of tree subdir/..." >expect &&
+       test_cmp expect actual
+'
+
 # Test tree:<depth> where a tree is iterated to twice - once where a subentry is
 # too deep to be included, and again where the blob inside it is shallow enough
 # to be included. This makes sure we don't use LOFR_MARK_SEEN incorrectly (we