Merge branch 'js/apply-recount-allow-noop'
[gitweb.git] / list-objects-filter.c
index a0ba78b20cc99bfcd2c41abd4f312b5649a2b9cd..765f3df3b067c5df7b98402ef4fc953edcd9179b 100644 (file)
@@ -44,8 +44,7 @@ static enum list_objects_filter_result filter_blobs_none(
 
        switch (filter_situation) {
        default:
-               die("unknown filter_situation");
-               return LOFR_ZERO;
+               BUG("unknown filter_situation: %d", filter_situation);
 
        case LOFS_BEGIN_TREE:
                assert(obj->type == OBJ_TREE);
@@ -80,6 +79,61 @@ static void *filter_blobs_none__init(
        return d;
 }
 
+/*
+ * A filter for list-objects to omit ALL trees and blobs from the traversal.
+ * Can OPTIONALLY collect a list of the omitted OIDs.
+ */
+struct filter_trees_none_data {
+       struct oidset *omits;
+};
+
+static enum list_objects_filter_result filter_trees_none(
+       enum list_objects_filter_situation filter_situation,
+       struct object *obj,
+       const char *pathname,
+       const char *filename,
+       void *filter_data_)
+{
+       struct filter_trees_none_data *filter_data = filter_data_;
+
+       switch (filter_situation) {
+       default:
+               BUG("unknown filter_situation: %d", filter_situation);
+
+       case LOFS_BEGIN_TREE:
+       case LOFS_BLOB:
+               if (filter_data->omits) {
+                       oidset_insert(filter_data->omits, &obj->oid);
+                       /* _MARK_SEEN but not _DO_SHOW (hard omit) */
+                       return LOFR_MARK_SEEN;
+               } else {
+                       /*
+                        * Not collecting omits so no need to to traverse tree.
+                        */
+                       return LOFR_SKIP_TREE | LOFR_MARK_SEEN;
+               }
+
+       case LOFS_END_TREE:
+               assert(obj->type == OBJ_TREE);
+               return LOFR_ZERO;
+
+       }
+}
+
+static void* filter_trees_none__init(
+       struct oidset *omitted,
+       struct list_objects_filter_options *filter_options,
+       filter_object_fn *filter_fn,
+       filter_free_fn *filter_free_fn)
+{
+       struct filter_trees_none_data *d = xcalloc(1, sizeof(*d));
+       d->omits = omitted;
+
+       *filter_fn = filter_trees_none;
+       *filter_free_fn = free;
+       return d;
+}
+
 /*
  * A filter for list-objects to omit large blobs.
  * And to OPTIONALLY collect a list of the omitted OIDs.
@@ -102,8 +156,7 @@ static enum list_objects_filter_result filter_blobs_limit(
 
        switch (filter_situation) {
        default:
-               die("unknown filter_situation");
-               return LOFR_ZERO;
+               BUG("unknown filter_situation: %d", filter_situation);
 
        case LOFS_BEGIN_TREE:
                assert(obj->type == OBJ_TREE);
@@ -208,8 +261,7 @@ static enum list_objects_filter_result filter_sparse(
 
        switch (filter_situation) {
        default:
-               die("unknown filter_situation");
-               return LOFR_ZERO;
+               BUG("unknown filter_situation: %d", filter_situation);
 
        case LOFS_BEGIN_TREE:
                assert(obj->type == OBJ_TREE);
@@ -374,6 +426,7 @@ static filter_init_fn s_filters[] = {
        NULL,
        filter_blobs_none__init,
        filter_blobs_limit__init,
+       filter_trees_none__init,
        filter_sparse_oid__init,
        filter_sparse_path__init,
 };
@@ -389,7 +442,7 @@ void *list_objects_filter__init(
        assert((sizeof(s_filters) / sizeof(s_filters[0])) == LOFC__COUNT);
 
        if (filter_options->choice >= LOFC__COUNT)
-               die("invalid list-objects filter choice: %d",
+               BUG("invalid list-objects filter choice: %d",
                    filter_options->choice);
 
        init_fn = s_filters[filter_options->choice];