list-objects-filter: put omits set in filter struct
The oidset *omits pointer must be accessed by the combine filter in a type-agnostic way once the graph traversal is over. Store that pointer in the general `filter` struct. This will be used in a follow-up patch to implement the combine filter. Signed-off-by: Matthew DeVore <matvore@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
9430147ca0
commit
7a7c7f4a6d
@ -33,18 +33,14 @@ struct filter {
|
||||
struct object *obj,
|
||||
const char *pathname,
|
||||
const char *filename,
|
||||
struct oidset *omits,
|
||||
void *filter_data);
|
||||
|
||||
void (*free_fn)(void *filter_data);
|
||||
|
||||
void *filter_data;
|
||||
};
|
||||
|
||||
/*
|
||||
* A filter for list-objects to omit ALL blobs from the traversal.
|
||||
* And to OPTIONALLY collect a list of the omitted OIDs.
|
||||
*/
|
||||
struct filter_blobs_none_data {
|
||||
/* If non-NULL, the filter collects a list of the omitted OIDs here. */
|
||||
struct oidset *omits;
|
||||
};
|
||||
|
||||
@ -54,10 +50,9 @@ static enum list_objects_filter_result filter_blobs_none(
|
||||
struct object *obj,
|
||||
const char *pathname,
|
||||
const char *filename,
|
||||
struct oidset *omits,
|
||||
void *filter_data_)
|
||||
{
|
||||
struct filter_blobs_none_data *filter_data = filter_data_;
|
||||
|
||||
switch (filter_situation) {
|
||||
default:
|
||||
BUG("unknown filter_situation: %d", filter_situation);
|
||||
@ -75,21 +70,16 @@ static enum list_objects_filter_result filter_blobs_none(
|
||||
assert(obj->type == OBJ_BLOB);
|
||||
assert((obj->flags & SEEN) == 0);
|
||||
|
||||
if (filter_data->omits)
|
||||
oidset_insert(filter_data->omits, &obj->oid);
|
||||
if (omits)
|
||||
oidset_insert(omits, &obj->oid);
|
||||
return LOFR_MARK_SEEN; /* but not LOFR_DO_SHOW (hard omit) */
|
||||
}
|
||||
}
|
||||
|
||||
static void filter_blobs_none__init(
|
||||
struct oidset *omitted,
|
||||
struct list_objects_filter_options *filter_options,
|
||||
struct filter *filter)
|
||||
{
|
||||
struct filter_blobs_none_data *d = xcalloc(1, sizeof(*d));
|
||||
d->omits = omitted;
|
||||
|
||||
filter->filter_data = d;
|
||||
filter->filter_object_fn = filter_blobs_none;
|
||||
filter->free_fn = free;
|
||||
}
|
||||
@ -99,8 +89,6 @@ static void filter_blobs_none__init(
|
||||
* Can OPTIONALLY collect a list of the omitted OIDs.
|
||||
*/
|
||||
struct filter_trees_depth_data {
|
||||
struct oidset *omits;
|
||||
|
||||
/*
|
||||
* Maps trees to the minimum depth at which they were seen. It is not
|
||||
* necessary to re-traverse a tree at deeper or equal depths than it has
|
||||
@ -123,16 +111,16 @@ struct seen_map_entry {
|
||||
/* 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,
|
||||
struct oidset *omits,
|
||||
int include_it)
|
||||
{
|
||||
if (!filter_data->omits)
|
||||
if (!omits)
|
||||
return 0;
|
||||
|
||||
if (include_it)
|
||||
return oidset_remove(filter_data->omits, &obj->oid);
|
||||
return oidset_remove(omits, &obj->oid);
|
||||
else
|
||||
return oidset_insert(filter_data->omits, &obj->oid);
|
||||
return oidset_insert(omits, &obj->oid);
|
||||
}
|
||||
|
||||
static enum list_objects_filter_result filter_trees_depth(
|
||||
@ -141,6 +129,7 @@ static enum list_objects_filter_result filter_trees_depth(
|
||||
struct object *obj,
|
||||
const char *pathname,
|
||||
const char *filename,
|
||||
struct oidset *omits,
|
||||
void *filter_data_)
|
||||
{
|
||||
struct filter_trees_depth_data *filter_data = filter_data_;
|
||||
@ -165,7 +154,7 @@ static enum list_objects_filter_result filter_trees_depth(
|
||||
return LOFR_ZERO;
|
||||
|
||||
case LOFS_BLOB:
|
||||
filter_trees_update_omits(obj, filter_data, include_it);
|
||||
filter_trees_update_omits(obj, omits, include_it);
|
||||
return include_it ? LOFR_MARK_SEEN | LOFR_DO_SHOW : LOFR_ZERO;
|
||||
|
||||
case LOFS_BEGIN_TREE:
|
||||
@ -186,12 +175,12 @@ static enum list_objects_filter_result filter_trees_depth(
|
||||
filter_res = LOFR_SKIP_TREE;
|
||||
} else {
|
||||
int been_omitted = filter_trees_update_omits(
|
||||
obj, filter_data, include_it);
|
||||
obj, omits, include_it);
|
||||
seen_info->depth = filter_data->current_depth;
|
||||
|
||||
if (include_it)
|
||||
filter_res = LOFR_DO_SHOW;
|
||||
else if (filter_data->omits && !been_omitted)
|
||||
else if (omits && !been_omitted)
|
||||
/*
|
||||
* Must update omit information of children
|
||||
* recursively; they have not been omitted yet.
|
||||
@ -215,12 +204,10 @@ static void filter_trees_free(void *filter_data) {
|
||||
}
|
||||
|
||||
static void filter_trees_depth__init(
|
||||
struct oidset *omitted,
|
||||
struct list_objects_filter_options *filter_options,
|
||||
struct filter *filter)
|
||||
{
|
||||
struct filter_trees_depth_data *d = xcalloc(1, sizeof(*d));
|
||||
d->omits = omitted;
|
||||
oidmap_init(&d->seen_at_depth, 0);
|
||||
d->exclude_depth = filter_options->tree_exclude_depth;
|
||||
d->current_depth = 0;
|
||||
@ -235,7 +222,6 @@ static void filter_trees_depth__init(
|
||||
* And to OPTIONALLY collect a list of the omitted OIDs.
|
||||
*/
|
||||
struct filter_blobs_limit_data {
|
||||
struct oidset *omits;
|
||||
unsigned long max_bytes;
|
||||
};
|
||||
|
||||
@ -245,6 +231,7 @@ static enum list_objects_filter_result filter_blobs_limit(
|
||||
struct object *obj,
|
||||
const char *pathname,
|
||||
const char *filename,
|
||||
struct oidset *omits,
|
||||
void *filter_data_)
|
||||
{
|
||||
struct filter_blobs_limit_data *filter_data = filter_data_;
|
||||
@ -282,24 +269,22 @@ static enum list_objects_filter_result filter_blobs_limit(
|
||||
if (object_length < filter_data->max_bytes)
|
||||
goto include_it;
|
||||
|
||||
if (filter_data->omits)
|
||||
oidset_insert(filter_data->omits, &obj->oid);
|
||||
if (omits)
|
||||
oidset_insert(omits, &obj->oid);
|
||||
return LOFR_MARK_SEEN; /* but not LOFR_DO_SHOW (hard omit) */
|
||||
}
|
||||
|
||||
include_it:
|
||||
if (filter_data->omits)
|
||||
oidset_remove(filter_data->omits, &obj->oid);
|
||||
if (omits)
|
||||
oidset_remove(omits, &obj->oid);
|
||||
return LOFR_MARK_SEEN | LOFR_DO_SHOW;
|
||||
}
|
||||
|
||||
static void filter_blobs_limit__init(
|
||||
struct oidset *omitted,
|
||||
struct list_objects_filter_options *filter_options,
|
||||
struct filter *filter)
|
||||
{
|
||||
struct filter_blobs_limit_data *d = xcalloc(1, sizeof(*d));
|
||||
d->omits = omitted;
|
||||
d->max_bytes = filter_options->blob_limit_value;
|
||||
|
||||
filter->filter_data = d;
|
||||
@ -337,7 +322,6 @@ struct frame {
|
||||
};
|
||||
|
||||
struct filter_sparse_data {
|
||||
struct oidset *omits;
|
||||
struct exclude_list el;
|
||||
|
||||
size_t nr, alloc;
|
||||
@ -350,6 +334,7 @@ static enum list_objects_filter_result filter_sparse(
|
||||
struct object *obj,
|
||||
const char *pathname,
|
||||
const char *filename,
|
||||
struct oidset *omits,
|
||||
void *filter_data_)
|
||||
{
|
||||
struct filter_sparse_data *filter_data = filter_data_;
|
||||
@ -431,8 +416,8 @@ static enum list_objects_filter_result filter_sparse(
|
||||
if (val < 0)
|
||||
val = frame->defval;
|
||||
if (val > 0) {
|
||||
if (filter_data->omits)
|
||||
oidset_remove(filter_data->omits, &obj->oid);
|
||||
if (omits)
|
||||
oidset_remove(omits, &obj->oid);
|
||||
return LOFR_MARK_SEEN | LOFR_DO_SHOW;
|
||||
}
|
||||
|
||||
@ -446,8 +431,8 @@ static enum list_objects_filter_result filter_sparse(
|
||||
* Leave the LOFR_ bits unset so that if the blob appears
|
||||
* again in the traversal, we will be asked again.
|
||||
*/
|
||||
if (filter_data->omits)
|
||||
oidset_insert(filter_data->omits, &obj->oid);
|
||||
if (omits)
|
||||
oidset_insert(omits, &obj->oid);
|
||||
|
||||
/*
|
||||
* Remember that at least 1 blob in this tree was
|
||||
@ -468,12 +453,10 @@ static void filter_sparse_free(void *filter_data)
|
||||
}
|
||||
|
||||
static void filter_sparse_oid__init(
|
||||
struct oidset *omitted,
|
||||
struct list_objects_filter_options *filter_options,
|
||||
struct filter *filter)
|
||||
{
|
||||
struct filter_sparse_data *d = xcalloc(1, sizeof(*d));
|
||||
d->omits = omitted;
|
||||
if (add_excludes_from_blob_to_list(filter_options->sparse_oid_value,
|
||||
NULL, 0, &d->el) < 0)
|
||||
die("could not load filter specification");
|
||||
@ -489,7 +472,6 @@ static void filter_sparse_oid__init(
|
||||
}
|
||||
|
||||
typedef void (*filter_init_fn)(
|
||||
struct oidset *omitted,
|
||||
struct list_objects_filter_options *filter_options,
|
||||
struct filter *filter);
|
||||
|
||||
@ -522,7 +504,8 @@ struct filter *list_objects_filter__init(
|
||||
return NULL;
|
||||
|
||||
filter = xcalloc(1, sizeof(*filter));
|
||||
init_fn(omitted, filter_options, filter);
|
||||
filter->omits = omitted;
|
||||
init_fn(filter_options, filter);
|
||||
return filter;
|
||||
}
|
||||
|
||||
@ -537,6 +520,7 @@ enum list_objects_filter_result list_objects_filter__filter_object(
|
||||
if (filter && (obj->flags & NOT_USER_GIVEN))
|
||||
return filter->filter_object_fn(r, filter_situation, obj,
|
||||
pathname, filename,
|
||||
filter->omits,
|
||||
filter->filter_data);
|
||||
/*
|
||||
* No filter is active or user gave object explicitly. In this case,
|
||||
|
Loading…
Reference in New Issue
Block a user