@@ -599,6 +599,10 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
list_objects_filter_set_no_filter(&filter_options);
continue;
}
+ if (!strcmp(arg, "--filter-provided")) {
+ filter_options.filter_wants = 1;
+ continue;
+ }
if (!strcmp(arg, "--filter-print-omitted")) {
arg_print_omitted = 1;
continue;
@@ -694,6 +698,16 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
return show_bisect_vars(&info, reaches, all);
}
+ if (filter_options.filter_wants) {
+ struct commit_list *c;
+ for (i = 0; i < revs.pending.nr; i++) {
+ struct object_array_entry *pending = revs.pending.objects + i;
+ pending->item->flags |= NOT_USER_GIVEN;
+ }
+ for (c = revs.commits; c; c = c->next)
+ c->item->object.flags |= NOT_USER_GIVEN;
+ }
+
if (arg_print_omitted)
oidset_init(&omitted_objects, DEFAULT_OIDSET_SIZE);
if (arg_missing_action == MA_PRINT)
@@ -42,6 +42,12 @@ struct list_objects_filter_options {
*/
enum list_objects_filter_choice choice;
+ /*
+ * "--filter-provided" was given by the user, instructing us to also
+ * filter all explicitly provided objects.
+ */
+ unsigned int filter_wants : 1;
+
/*
* Choice is LOFC_DISABLED because "--no-filter" was requested.
*/
@@ -1101,7 +1101,8 @@ struct bitmap_index *prepare_bitmap_walk(struct rev_info *revs,
if (haves_bitmap)
bitmap_and_not(wants_bitmap, haves_bitmap);
- filter_bitmap(bitmap_git, wants, wants_bitmap, filter);
+ filter_bitmap(bitmap_git, (filter && filter->filter_wants) ? NULL : wants,
+ wants_bitmap, filter);
bitmap_git->result = wants_bitmap;
bitmap_git->haves = haves_bitmap;
@@ -207,6 +207,34 @@ test_expect_success 'verify object:type=tag prints tag' '
test_cmp expected actual
'
+test_expect_success 'verify object:type=blob prints only blob with --filter-provided' '
+ printf "%s blob\n" $(git -C object-type rev-parse HEAD:blob) >expected &&
+ git -C object-type rev-list --objects \
+ --filter=object:type=blob --filter-provided HEAD >actual &&
+ test_cmp expected actual
+'
+
+test_expect_success 'verify object:type=tree prints only tree with --filter-provided' '
+ printf "%s \n" $(git -C object-type rev-parse HEAD^{tree}) >expected &&
+ git -C object-type rev-list --objects \
+ --filter=object:type=tree HEAD --filter-provided >actual &&
+ test_cmp expected actual
+'
+
+test_expect_success 'verify object:type=commit prints only commit with --filter-provided' '
+ git -C object-type rev-parse HEAD >expected &&
+ git -C object-type rev-list --objects \
+ --filter=object:type=commit --filter-provided HEAD >actual &&
+ test_cmp expected actual
+'
+
+test_expect_success 'verify object:type=tag prints only tag with --filter-provided' '
+ printf "%s tag\n" $(git -C object-type rev-parse tag) >expected &&
+ git -C object-type rev-list --objects \
+ --filter=object:type=tag --filter-provided tag >actual &&
+ test_cmp expected actual
+'
+
# Test sparse:path=<path> filter.
# !!!!
# NOTE: sparse:path filter support has been dropped for security reasons,
@@ -98,6 +98,28 @@ test_expect_success 'object:type filter' '
test_bitmap_traversal expect actual
'
+test_expect_success 'object:type filter with --filter-provided' '
+ git rev-list --objects --filter=object:type=tag --filter-provided tag >expect &&
+ git rev-list --use-bitmap-index \
+ --objects --filter=object:type=tag --filter-provided tag >actual &&
+ test_cmp expect actual &&
+
+ git rev-list --objects --filter=object:type=commit --filter-provided tag >expect &&
+ git rev-list --use-bitmap-index \
+ --objects --filter=object:type=commit --filter-provided tag >actual &&
+ test_bitmap_traversal expect actual &&
+
+ git rev-list --objects --filter=object:type=tree --filter-provided tag >expect &&
+ git rev-list --use-bitmap-index \
+ --objects --filter=object:type=tree --filter-provided tag >actual &&
+ test_bitmap_traversal expect actual &&
+
+ git rev-list --objects --filter=object:type=blob --filter-provided tag >expect &&
+ git rev-list --use-bitmap-index \
+ --objects --filter=object:type=blob --filter-provided tag >actual &&
+ test_bitmap_traversal expect actual
+'
+
test_expect_success 'combine filter' '
git rev-list --objects --filter=blob:limit=1000 --filter=object:type=blob tag >expect &&
git rev-list --use-bitmap-index \
When providing an object filter, it is currently impossible to also filter provided items. E.g. when executing `git rev-list HEAD` , the commit this reference points to will be treated as user-provided and is thus excluded from the filtering mechanism. This makes it harder than necessary to properly use the new `--filter=object:type` filter given that even if the user wants to only see blobs, he'll still see commits of provided references. Improve this by introducing a new `--filter-provided` option to the git-rev-parse(1) command. If given, then all user-provided references will be subject to filtering. Signed-off-by: Patrick Steinhardt <ps@pks.im> --- builtin/rev-list.c | 14 ++++++++++++++ list-objects-filter-options.h | 6 ++++++ pack-bitmap.c | 3 ++- t/t6112-rev-list-filters-objects.sh | 28 ++++++++++++++++++++++++++++ t/t6113-rev-list-bitmap-filters.sh | 22 ++++++++++++++++++++++ 5 files changed, 72 insertions(+), 1 deletion(-)