tree:<depth>: skip some trees even when collecting omits
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>
Matthew DeVore committed
Jan 8, 2019 at 18:59 UTC
8272f26034c9dbaf5cd216a137b8e91241cbc24e
2 files changed
+22
-7
list-objects-filter.c
+12
-6
@@ -107,18 +107,19 @@ struct seen_map_entry {
107
size_t depth;
108
};
109
110
-static void filter_trees_update_omits(
110
+/* Returns 1 if the oid was in the omits set before it was invoked. */
111
+static int filter_trees_update_omits(
112
struct object *obj,
113
struct filter_trees_depth_data *filter_data,
114
int include_it)
115
{
116
if (!filter_data->omits)
116
- return;
117
+ return 0;
118
119
if (include_it)
119
- oidset_remove(filter_data->omits, &obj->oid);
120
+ return oidset_remove(filter_data->omits, &obj->oid);
121
else
121
- oidset_insert(filter_data->omits, &obj->oid);
122
+ return oidset_insert(filter_data->omits, &obj->oid);
123
}
124
125
static enum list_objects_filter_result filter_trees_depth(
@@ -171,12 +172,17 @@ static enum list_objects_filter_result filter_trees_depth(
172
if (already_seen) {
173
filter_res = LOFR_SKIP_TREE;
174
} else {
175
+ int been_omitted = filter_trees_update_omits(
176
+ obj, filter_data, include_it);
177
seen_info->depth = filter_data->current_depth;
175
- filter_trees_update_omits(obj, filter_data, include_it);
178
179
if (include_it)
180
filter_res = LOFR_DO_SHOW;
179
- else if (filter_data->omits)
181
+ else if (filter_data->omits && !been_omitted)
182
+ /*
183
+ * Must update omit information of children
184
+ * recursively; they have not been omitted yet.
185
+ */
186
filter_res = LOFR_ZERO;
187
else
188
filter_res = LOFR_SKIP_TREE;
t/t6112-rev-list-filters-objects.sh
+10
-1
@@ -283,7 +283,7 @@ test_expect_success 'verify tree:0 includes trees in "filtered" output' '
283
284
# Make sure tree:0 does not iterate through any trees.
285
286
-test_expect_success 'filter a GIANT tree through tree:0' '
286
+test_expect_success 'verify skipping tree iteration when not collecting omits' '
287
GIT_TRACE=1 git -C r3 rev-list \
288
--objects --filter=tree:0 HEAD 2>filter_trace &&
289
grep "Skipping contents of tree [.][.][.]" filter_trace >actual &&
@@ -377,6 +377,15 @@ test_expect_success 'test tree:# filter provisional omit for blob and tree' '
377
expect_has_with_different_name r4 filt/subdir
378
'
379
380
+test_expect_success 'verify skipping tree iteration when collecting omits' '
381
+ GIT_TRACE=1 git -C r4 rev-list --filter-print-omitted \
382
+ --objects --filter=tree:0 HEAD 2>filter_trace &&
383
+ grep "^Skipping contents of tree " filter_trace >actual &&
384
+
385
+ echo "Skipping contents of tree subdir/..." >expect &&
386
+ test_cmp expect actual
387
+'
388
+
389
# Test tree:<depth> where a tree is iterated to twice - once where a subentry is
390
# too deep to be included, and again where the blob inside it is shallow enough
391
# to be included. This makes sure we don't use LOFR_MARK_SEEN incorrectly (we