2023-04-11 07:41:56 +00:00
|
|
|
#include "git-compat-util.h"
|
2023-02-24 00:09:24 +00:00
|
|
|
#include "alloc.h"
|
2017-11-21 20:58:50 +00:00
|
|
|
#include "dir.h"
|
2023-03-21 06:25:54 +00:00
|
|
|
#include "gettext.h"
|
2023-02-24 00:09:27 +00:00
|
|
|
#include "hex.h"
|
2017-11-21 20:58:50 +00:00
|
|
|
#include "tag.h"
|
|
|
|
#include "commit.h"
|
|
|
|
#include "tree.h"
|
|
|
|
#include "blob.h"
|
|
|
|
#include "diff.h"
|
|
|
|
#include "tree-walk.h"
|
|
|
|
#include "revision.h"
|
|
|
|
#include "list-objects.h"
|
|
|
|
#include "list-objects-filter.h"
|
|
|
|
#include "list-objects-filter-options.h"
|
2019-01-09 02:59:13 +00:00
|
|
|
#include "oidmap.h"
|
2017-11-21 20:58:50 +00:00
|
|
|
#include "oidset.h"
|
2023-04-11 07:41:49 +00:00
|
|
|
#include "object-name.h"
|
2018-05-15 23:42:15 +00:00
|
|
|
#include "object-store.h"
|
2017-11-21 20:58:50 +00:00
|
|
|
|
|
|
|
/* Remember to update object flag allocation in object.h */
|
|
|
|
/*
|
|
|
|
* FILTER_SHOWN_BUT_REVISIT -- we set this bit on tree objects
|
|
|
|
* that have been shown, but should be revisited if they appear
|
|
|
|
* in the traversal (until we mark it SEEN). This is a way to
|
|
|
|
* let us silently de-dup calls to show() in the caller. This
|
|
|
|
* is subtly different from the "revision.h:SHOWN" and the
|
2020-12-31 11:56:20 +00:00
|
|
|
* "object-name.c:ONELINE_SEEN" bits. And also different from
|
2017-11-21 20:58:50 +00:00
|
|
|
* the non-de-dup usage in pack-bitmap.c
|
|
|
|
*/
|
|
|
|
#define FILTER_SHOWN_BUT_REVISIT (1<<21)
|
|
|
|
|
2019-06-27 22:54:08 +00:00
|
|
|
struct subfilter {
|
|
|
|
struct filter *filter;
|
|
|
|
struct oidset seen;
|
|
|
|
struct oidset omits;
|
|
|
|
struct object_id skip_tree;
|
|
|
|
unsigned is_skipping_tree : 1;
|
|
|
|
};
|
|
|
|
|
2019-06-27 22:54:05 +00:00
|
|
|
struct filter {
|
|
|
|
enum list_objects_filter_result (*filter_object_fn)(
|
|
|
|
struct repository *r,
|
|
|
|
enum list_objects_filter_situation filter_situation,
|
|
|
|
struct object *obj,
|
|
|
|
const char *pathname,
|
|
|
|
const char *filename,
|
2019-06-27 22:54:06 +00:00
|
|
|
struct oidset *omits,
|
2019-06-27 22:54:05 +00:00
|
|
|
void *filter_data);
|
|
|
|
|
2019-06-27 22:54:08 +00:00
|
|
|
/*
|
|
|
|
* Optional. If this function is supplied and the filter needs
|
|
|
|
* to collect omits, then this function is called once before
|
|
|
|
* free_fn is called.
|
|
|
|
*
|
|
|
|
* This is required because the following two conditions hold:
|
|
|
|
*
|
|
|
|
* a. A tree filter can add and remove objects as an object
|
|
|
|
* graph is traversed.
|
|
|
|
* b. A combine filter's omit set is the union of all its
|
|
|
|
* subfilters, which may include tree: filters.
|
|
|
|
*
|
|
|
|
* As such, the omits sets must be separate sets, and can only
|
|
|
|
* be unioned after the traversal is completed.
|
|
|
|
*/
|
|
|
|
void (*finalize_omits_fn)(struct oidset *omits, void *filter_data);
|
|
|
|
|
2019-06-27 22:54:05 +00:00
|
|
|
void (*free_fn)(void *filter_data);
|
|
|
|
|
|
|
|
void *filter_data;
|
|
|
|
|
2019-06-27 22:54:06 +00:00
|
|
|
/* If non-NULL, the filter collects a list of the omitted OIDs here. */
|
2017-11-21 20:58:50 +00:00
|
|
|
struct oidset *omits;
|
|
|
|
};
|
|
|
|
|
|
|
|
static enum list_objects_filter_result filter_blobs_none(
|
2022-12-13 11:14:23 +00:00
|
|
|
struct repository *r UNUSED,
|
2017-11-21 20:58:50 +00:00
|
|
|
enum list_objects_filter_situation filter_situation,
|
|
|
|
struct object *obj,
|
2022-12-13 11:14:23 +00:00
|
|
|
const char *pathname UNUSED,
|
|
|
|
const char *filename UNUSED,
|
2019-06-27 22:54:06 +00:00
|
|
|
struct oidset *omits,
|
2022-12-13 11:14:23 +00:00
|
|
|
void *filter_data_ UNUSED)
|
2017-11-21 20:58:50 +00:00
|
|
|
{
|
|
|
|
switch (filter_situation) {
|
|
|
|
default:
|
2018-10-05 21:31:25 +00:00
|
|
|
BUG("unknown filter_situation: %d", filter_situation);
|
2017-11-21 20:58:50 +00:00
|
|
|
|
2021-04-12 13:37:35 +00:00
|
|
|
case LOFS_TAG:
|
|
|
|
assert(obj->type == OBJ_TAG);
|
|
|
|
/* always include all tag objects */
|
|
|
|
return LOFR_MARK_SEEN | LOFR_DO_SHOW;
|
|
|
|
|
|
|
|
case LOFS_COMMIT:
|
|
|
|
assert(obj->type == OBJ_COMMIT);
|
|
|
|
/* always include all commit objects */
|
|
|
|
return LOFR_MARK_SEEN | LOFR_DO_SHOW;
|
|
|
|
|
2017-11-21 20:58:50 +00:00
|
|
|
case LOFS_BEGIN_TREE:
|
|
|
|
assert(obj->type == OBJ_TREE);
|
|
|
|
/* always include all tree objects */
|
|
|
|
return LOFR_MARK_SEEN | LOFR_DO_SHOW;
|
|
|
|
|
|
|
|
case LOFS_END_TREE:
|
|
|
|
assert(obj->type == OBJ_TREE);
|
|
|
|
return LOFR_ZERO;
|
|
|
|
|
|
|
|
case LOFS_BLOB:
|
|
|
|
assert(obj->type == OBJ_BLOB);
|
|
|
|
assert((obj->flags & SEEN) == 0);
|
|
|
|
|
2019-06-27 22:54:06 +00:00
|
|
|
if (omits)
|
|
|
|
oidset_insert(omits, &obj->oid);
|
2017-11-21 20:58:50 +00:00
|
|
|
return LOFR_MARK_SEEN; /* but not LOFR_DO_SHOW (hard omit) */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-27 22:54:05 +00:00
|
|
|
static void filter_blobs_none__init(
|
2022-12-13 11:14:23 +00:00
|
|
|
struct list_objects_filter_options *filter_options UNUSED,
|
2019-06-27 22:54:05 +00:00
|
|
|
struct filter *filter)
|
2017-11-21 20:58:50 +00:00
|
|
|
{
|
2019-06-27 22:54:05 +00:00
|
|
|
filter->filter_object_fn = filter_blobs_none;
|
|
|
|
filter->free_fn = free;
|
2017-11-21 20:58:50 +00:00
|
|
|
}
|
|
|
|
|
2018-10-05 21:31:27 +00:00
|
|
|
/*
|
|
|
|
* A filter for list-objects to omit ALL trees and blobs from the traversal.
|
|
|
|
* Can OPTIONALLY collect a list of the omitted OIDs.
|
|
|
|
*/
|
2019-01-09 02:59:13 +00:00
|
|
|
struct filter_trees_depth_data {
|
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
* already been traversed.
|
|
|
|
*
|
|
|
|
* We can't use LOFR_MARK_SEEN for tree objects since this will prevent
|
|
|
|
* it from being traversed at shallower depths.
|
|
|
|
*/
|
|
|
|
struct oidmap seen_at_depth;
|
|
|
|
|
|
|
|
unsigned long exclude_depth;
|
|
|
|
unsigned long current_depth;
|
2018-10-05 21:31:27 +00:00
|
|
|
};
|
|
|
|
|
2019-01-09 02:59:13 +00:00
|
|
|
struct seen_map_entry {
|
|
|
|
struct oidmap_entry base;
|
|
|
|
size_t depth;
|
|
|
|
};
|
|
|
|
|
2019-01-09 02:59:14 +00:00
|
|
|
/* Returns 1 if the oid was in the omits set before it was invoked. */
|
|
|
|
static int filter_trees_update_omits(
|
2019-01-09 02:59:13 +00:00
|
|
|
struct object *obj,
|
2019-06-27 22:54:06 +00:00
|
|
|
struct oidset *omits,
|
2019-01-09 02:59:13 +00:00
|
|
|
int include_it)
|
|
|
|
{
|
2019-06-27 22:54:06 +00:00
|
|
|
if (!omits)
|
2019-01-09 02:59:14 +00:00
|
|
|
return 0;
|
2019-01-09 02:59:13 +00:00
|
|
|
|
|
|
|
if (include_it)
|
2019-06-27 22:54:06 +00:00
|
|
|
return oidset_remove(omits, &obj->oid);
|
2019-01-09 02:59:13 +00:00
|
|
|
else
|
2019-06-27 22:54:06 +00:00
|
|
|
return oidset_insert(omits, &obj->oid);
|
2019-01-09 02:59:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static enum list_objects_filter_result filter_trees_depth(
|
2022-12-13 11:14:23 +00:00
|
|
|
struct repository *r UNUSED,
|
2018-10-05 21:31:27 +00:00
|
|
|
enum list_objects_filter_situation filter_situation,
|
|
|
|
struct object *obj,
|
2022-12-13 11:14:23 +00:00
|
|
|
const char *pathname UNUSED,
|
|
|
|
const char *filename UNUSED,
|
2019-06-27 22:54:06 +00:00
|
|
|
struct oidset *omits,
|
2018-10-05 21:31:27 +00:00
|
|
|
void *filter_data_)
|
|
|
|
{
|
2019-01-09 02:59:13 +00:00
|
|
|
struct filter_trees_depth_data *filter_data = filter_data_;
|
|
|
|
struct seen_map_entry *seen_info;
|
|
|
|
int include_it = filter_data->current_depth <
|
|
|
|
filter_data->exclude_depth;
|
|
|
|
int filter_res;
|
|
|
|
int already_seen;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Note that we do not use _MARK_SEEN in order to allow re-traversal in
|
|
|
|
* case we encounter a tree or blob again at a shallower depth.
|
|
|
|
*/
|
2018-10-05 21:31:27 +00:00
|
|
|
|
|
|
|
switch (filter_situation) {
|
|
|
|
default:
|
|
|
|
BUG("unknown filter_situation: %d", filter_situation);
|
|
|
|
|
2021-04-12 13:37:35 +00:00
|
|
|
case LOFS_TAG:
|
|
|
|
assert(obj->type == OBJ_TAG);
|
|
|
|
/* always include all tag objects */
|
|
|
|
return LOFR_MARK_SEEN | LOFR_DO_SHOW;
|
|
|
|
|
|
|
|
case LOFS_COMMIT:
|
|
|
|
assert(obj->type == OBJ_COMMIT);
|
|
|
|
/* always include all commit objects */
|
|
|
|
return LOFR_MARK_SEEN | LOFR_DO_SHOW;
|
|
|
|
|
2019-01-09 02:59:13 +00:00
|
|
|
case LOFS_END_TREE:
|
|
|
|
assert(obj->type == OBJ_TREE);
|
|
|
|
filter_data->current_depth--;
|
|
|
|
return LOFR_ZERO;
|
|
|
|
|
2018-10-05 21:31:27 +00:00
|
|
|
case LOFS_BLOB:
|
2019-06-27 22:54:06 +00:00
|
|
|
filter_trees_update_omits(obj, omits, include_it);
|
2019-01-09 02:59:13 +00:00
|
|
|
return include_it ? LOFR_MARK_SEEN | LOFR_DO_SHOW : LOFR_ZERO;
|
|
|
|
|
|
|
|
case LOFS_BEGIN_TREE:
|
|
|
|
seen_info = oidmap_get(
|
|
|
|
&filter_data->seen_at_depth, &obj->oid);
|
|
|
|
if (!seen_info) {
|
2021-03-13 16:17:22 +00:00
|
|
|
CALLOC_ARRAY(seen_info, 1);
|
2019-01-09 02:59:13 +00:00
|
|
|
oidcpy(&seen_info->base.oid, &obj->oid);
|
|
|
|
seen_info->depth = filter_data->current_depth;
|
|
|
|
oidmap_put(&filter_data->seen_at_depth, seen_info);
|
|
|
|
already_seen = 0;
|
2018-10-18 00:39:15 +00:00
|
|
|
} else {
|
2019-01-09 02:59:13 +00:00
|
|
|
already_seen =
|
|
|
|
filter_data->current_depth >= seen_info->depth;
|
2018-10-18 00:39:15 +00:00
|
|
|
}
|
2018-10-05 21:31:27 +00:00
|
|
|
|
2019-01-09 02:59:13 +00:00
|
|
|
if (already_seen) {
|
|
|
|
filter_res = LOFR_SKIP_TREE;
|
|
|
|
} else {
|
2019-01-09 02:59:14 +00:00
|
|
|
int been_omitted = filter_trees_update_omits(
|
2019-06-27 22:54:06 +00:00
|
|
|
obj, omits, include_it);
|
2019-01-09 02:59:13 +00:00
|
|
|
seen_info->depth = filter_data->current_depth;
|
|
|
|
|
|
|
|
if (include_it)
|
|
|
|
filter_res = LOFR_DO_SHOW;
|
2019-06-27 22:54:06 +00:00
|
|
|
else if (omits && !been_omitted)
|
2019-01-09 02:59:14 +00:00
|
|
|
/*
|
|
|
|
* Must update omit information of children
|
|
|
|
* recursively; they have not been omitted yet.
|
|
|
|
*/
|
2019-01-09 02:59:13 +00:00
|
|
|
filter_res = LOFR_ZERO;
|
|
|
|
else
|
|
|
|
filter_res = LOFR_SKIP_TREE;
|
|
|
|
}
|
2018-10-05 21:31:27 +00:00
|
|
|
|
2019-01-09 02:59:13 +00:00
|
|
|
filter_data->current_depth++;
|
|
|
|
return filter_res;
|
2018-10-05 21:31:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-09 02:59:13 +00:00
|
|
|
static void filter_trees_free(void *filter_data) {
|
|
|
|
struct filter_trees_depth_data *d = filter_data;
|
|
|
|
if (!d)
|
|
|
|
return;
|
|
|
|
oidmap_free(&d->seen_at_depth, 1);
|
|
|
|
free(d);
|
|
|
|
}
|
|
|
|
|
2019-06-27 22:54:05 +00:00
|
|
|
static void filter_trees_depth__init(
|
2018-10-05 21:31:27 +00:00
|
|
|
struct list_objects_filter_options *filter_options,
|
2019-06-27 22:54:05 +00:00
|
|
|
struct filter *filter)
|
2018-10-05 21:31:27 +00:00
|
|
|
{
|
2019-01-09 02:59:13 +00:00
|
|
|
struct filter_trees_depth_data *d = xcalloc(1, sizeof(*d));
|
|
|
|
oidmap_init(&d->seen_at_depth, 0);
|
|
|
|
d->exclude_depth = filter_options->tree_exclude_depth;
|
|
|
|
d->current_depth = 0;
|
2018-10-05 21:31:27 +00:00
|
|
|
|
2019-06-27 22:54:05 +00:00
|
|
|
filter->filter_data = d;
|
|
|
|
filter->filter_object_fn = filter_trees_depth;
|
|
|
|
filter->free_fn = filter_trees_free;
|
2018-10-05 21:31:27 +00:00
|
|
|
}
|
|
|
|
|
2017-11-21 20:58:50 +00:00
|
|
|
/*
|
|
|
|
* A filter for list-objects to omit large blobs.
|
|
|
|
* And to OPTIONALLY collect a list of the omitted OIDs.
|
|
|
|
*/
|
|
|
|
struct filter_blobs_limit_data {
|
|
|
|
unsigned long max_bytes;
|
|
|
|
};
|
|
|
|
|
|
|
|
static enum list_objects_filter_result filter_blobs_limit(
|
2018-11-10 05:48:51 +00:00
|
|
|
struct repository *r,
|
2017-11-21 20:58:50 +00:00
|
|
|
enum list_objects_filter_situation filter_situation,
|
|
|
|
struct object *obj,
|
2022-12-13 11:14:23 +00:00
|
|
|
const char *pathname UNUSED,
|
|
|
|
const char *filename UNUSED,
|
2019-06-27 22:54:06 +00:00
|
|
|
struct oidset *omits,
|
2017-11-21 20:58:50 +00:00
|
|
|
void *filter_data_)
|
|
|
|
{
|
|
|
|
struct filter_blobs_limit_data *filter_data = filter_data_;
|
|
|
|
unsigned long object_length;
|
|
|
|
enum object_type t;
|
|
|
|
|
|
|
|
switch (filter_situation) {
|
|
|
|
default:
|
2018-10-05 21:31:25 +00:00
|
|
|
BUG("unknown filter_situation: %d", filter_situation);
|
2017-11-21 20:58:50 +00:00
|
|
|
|
2021-04-12 13:37:35 +00:00
|
|
|
case LOFS_TAG:
|
|
|
|
assert(obj->type == OBJ_TAG);
|
|
|
|
/* always include all tag objects */
|
|
|
|
return LOFR_MARK_SEEN | LOFR_DO_SHOW;
|
|
|
|
|
|
|
|
case LOFS_COMMIT:
|
|
|
|
assert(obj->type == OBJ_COMMIT);
|
|
|
|
/* always include all commit objects */
|
|
|
|
return LOFR_MARK_SEEN | LOFR_DO_SHOW;
|
|
|
|
|
2017-11-21 20:58:50 +00:00
|
|
|
case LOFS_BEGIN_TREE:
|
|
|
|
assert(obj->type == OBJ_TREE);
|
|
|
|
/* always include all tree objects */
|
|
|
|
return LOFR_MARK_SEEN | LOFR_DO_SHOW;
|
|
|
|
|
|
|
|
case LOFS_END_TREE:
|
|
|
|
assert(obj->type == OBJ_TREE);
|
|
|
|
return LOFR_ZERO;
|
|
|
|
|
|
|
|
case LOFS_BLOB:
|
|
|
|
assert(obj->type == OBJ_BLOB);
|
|
|
|
assert((obj->flags & SEEN) == 0);
|
|
|
|
|
2018-11-10 05:48:51 +00:00
|
|
|
t = oid_object_info(r, &obj->oid, &object_length);
|
2017-11-21 20:58:50 +00:00
|
|
|
if (t != OBJ_BLOB) { /* probably OBJ_NONE */
|
|
|
|
/*
|
|
|
|
* We DO NOT have the blob locally, so we cannot
|
|
|
|
* apply the size filter criteria. Be conservative
|
|
|
|
* and force show it (and let the caller deal with
|
|
|
|
* the ambiguity).
|
|
|
|
*/
|
|
|
|
goto include_it;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (object_length < filter_data->max_bytes)
|
|
|
|
goto include_it;
|
|
|
|
|
2019-06-27 22:54:06 +00:00
|
|
|
if (omits)
|
|
|
|
oidset_insert(omits, &obj->oid);
|
2017-11-21 20:58:50 +00:00
|
|
|
return LOFR_MARK_SEEN; /* but not LOFR_DO_SHOW (hard omit) */
|
|
|
|
}
|
|
|
|
|
|
|
|
include_it:
|
2019-06-27 22:54:06 +00:00
|
|
|
if (omits)
|
|
|
|
oidset_remove(omits, &obj->oid);
|
2017-11-21 20:58:50 +00:00
|
|
|
return LOFR_MARK_SEEN | LOFR_DO_SHOW;
|
|
|
|
}
|
|
|
|
|
2019-06-27 22:54:05 +00:00
|
|
|
static void filter_blobs_limit__init(
|
2017-11-21 20:58:50 +00:00
|
|
|
struct list_objects_filter_options *filter_options,
|
2019-06-27 22:54:05 +00:00
|
|
|
struct filter *filter)
|
2017-11-21 20:58:50 +00:00
|
|
|
{
|
|
|
|
struct filter_blobs_limit_data *d = xcalloc(1, sizeof(*d));
|
|
|
|
d->max_bytes = filter_options->blob_limit_value;
|
|
|
|
|
2019-06-27 22:54:05 +00:00
|
|
|
filter->filter_data = d;
|
|
|
|
filter->filter_object_fn = filter_blobs_limit;
|
|
|
|
filter->free_fn = free;
|
2017-11-21 20:58:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* A filter driven by a sparse-checkout specification to only
|
|
|
|
* include blobs that a sparse checkout would populate.
|
|
|
|
*
|
|
|
|
* The sparse-checkout spec can be loaded from a blob with the
|
|
|
|
* given OID or from a local pathname. We allow an OID because
|
|
|
|
* the repo may be bare or we may be doing the filtering on the
|
|
|
|
* server.
|
|
|
|
*/
|
|
|
|
struct frame {
|
|
|
|
/*
|
2019-09-03 18:04:58 +00:00
|
|
|
* default_match is the usual default include/exclude value that
|
2017-11-21 20:58:50 +00:00
|
|
|
* should be inherited as we recurse into directories based
|
|
|
|
* upon pattern matching of the directory itself or of a
|
|
|
|
* containing directory.
|
|
|
|
*/
|
2019-09-03 18:04:58 +00:00
|
|
|
enum pattern_match_result default_match;
|
2017-11-21 20:58:50 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 1 if the directory (recursively) contains any provisionally
|
|
|
|
* omitted objects.
|
|
|
|
*
|
|
|
|
* 0 if everything (recursively) contained in this directory
|
|
|
|
* has been explicitly included (SHOWN) in the result and
|
|
|
|
* the directory may be short-cut later in the traversal.
|
|
|
|
*/
|
|
|
|
unsigned child_prov_omit : 1;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct filter_sparse_data {
|
2019-09-03 18:04:56 +00:00
|
|
|
struct pattern_list pl;
|
2017-11-21 20:58:50 +00:00
|
|
|
|
|
|
|
size_t nr, alloc;
|
|
|
|
struct frame *array_frame;
|
|
|
|
};
|
|
|
|
|
|
|
|
static enum list_objects_filter_result filter_sparse(
|
2018-11-10 05:48:51 +00:00
|
|
|
struct repository *r,
|
2017-11-21 20:58:50 +00:00
|
|
|
enum list_objects_filter_situation filter_situation,
|
|
|
|
struct object *obj,
|
|
|
|
const char *pathname,
|
|
|
|
const char *filename,
|
2019-06-27 22:54:06 +00:00
|
|
|
struct oidset *omits,
|
2017-11-21 20:58:50 +00:00
|
|
|
void *filter_data_)
|
|
|
|
{
|
|
|
|
struct filter_sparse_data *filter_data = filter_data_;
|
2019-09-03 18:04:58 +00:00
|
|
|
int dtype;
|
2017-11-21 20:58:50 +00:00
|
|
|
struct frame *frame;
|
2019-09-03 18:04:58 +00:00
|
|
|
enum pattern_match_result match;
|
2017-11-21 20:58:50 +00:00
|
|
|
|
|
|
|
switch (filter_situation) {
|
|
|
|
default:
|
2018-10-05 21:31:25 +00:00
|
|
|
BUG("unknown filter_situation: %d", filter_situation);
|
2017-11-21 20:58:50 +00:00
|
|
|
|
2021-04-12 13:37:35 +00:00
|
|
|
case LOFS_TAG:
|
|
|
|
assert(obj->type == OBJ_TAG);
|
|
|
|
/* always include all tag objects */
|
|
|
|
return LOFR_MARK_SEEN | LOFR_DO_SHOW;
|
|
|
|
|
|
|
|
case LOFS_COMMIT:
|
|
|
|
assert(obj->type == OBJ_COMMIT);
|
|
|
|
/* always include all commit objects */
|
|
|
|
return LOFR_MARK_SEEN | LOFR_DO_SHOW;
|
|
|
|
|
2017-11-21 20:58:50 +00:00
|
|
|
case LOFS_BEGIN_TREE:
|
|
|
|
assert(obj->type == OBJ_TREE);
|
|
|
|
dtype = DT_DIR;
|
2019-09-03 18:04:58 +00:00
|
|
|
match = path_matches_pattern_list(pathname, strlen(pathname),
|
|
|
|
filename, &dtype, &filter_data->pl,
|
|
|
|
r->index);
|
|
|
|
if (match == UNDECIDED)
|
|
|
|
match = filter_data->array_frame[filter_data->nr - 1].default_match;
|
2017-11-21 20:58:50 +00:00
|
|
|
|
|
|
|
ALLOC_GROW(filter_data->array_frame, filter_data->nr + 1,
|
|
|
|
filter_data->alloc);
|
2019-09-03 18:04:58 +00:00
|
|
|
filter_data->array_frame[filter_data->nr].default_match = match;
|
2017-11-21 20:58:50 +00:00
|
|
|
filter_data->array_frame[filter_data->nr].child_prov_omit = 0;
|
2019-05-31 18:46:06 +00:00
|
|
|
filter_data->nr++;
|
2017-11-21 20:58:50 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* A directory with this tree OID may appear in multiple
|
|
|
|
* places in the tree. (Think of a directory move or copy,
|
|
|
|
* with no other changes, so the OID is the same, but the
|
|
|
|
* full pathnames of objects within this directory are new
|
|
|
|
* and may match is_excluded() patterns differently.)
|
|
|
|
* So we cannot mark this directory as SEEN (yet), since
|
|
|
|
* that will prevent process_tree() from revisiting this
|
|
|
|
* tree object with other pathname prefixes.
|
|
|
|
*
|
|
|
|
* Only _DO_SHOW the tree object the first time we visit
|
|
|
|
* this tree object.
|
|
|
|
*
|
|
|
|
* We always show all tree objects. A future optimization
|
|
|
|
* may want to attempt to narrow this.
|
|
|
|
*/
|
|
|
|
if (obj->flags & FILTER_SHOWN_BUT_REVISIT)
|
|
|
|
return LOFR_ZERO;
|
|
|
|
obj->flags |= FILTER_SHOWN_BUT_REVISIT;
|
|
|
|
return LOFR_DO_SHOW;
|
|
|
|
|
|
|
|
case LOFS_END_TREE:
|
|
|
|
assert(obj->type == OBJ_TREE);
|
2019-05-31 18:46:06 +00:00
|
|
|
assert(filter_data->nr > 1);
|
2017-11-21 20:58:50 +00:00
|
|
|
|
2019-05-31 18:46:06 +00:00
|
|
|
frame = &filter_data->array_frame[--filter_data->nr];
|
2017-11-21 20:58:50 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Tell our parent directory if any of our children were
|
|
|
|
* provisionally omitted.
|
|
|
|
*/
|
2019-05-31 18:46:06 +00:00
|
|
|
filter_data->array_frame[filter_data->nr - 1].child_prov_omit |=
|
2017-11-21 20:58:50 +00:00
|
|
|
frame->child_prov_omit;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If there are NO provisionally omitted child objects (ALL child
|
|
|
|
* objects in this folder were INCLUDED), then we can mark the
|
|
|
|
* folder as SEEN (so we will not have to revisit it again).
|
|
|
|
*/
|
|
|
|
if (!frame->child_prov_omit)
|
|
|
|
return LOFR_MARK_SEEN;
|
|
|
|
return LOFR_ZERO;
|
|
|
|
|
|
|
|
case LOFS_BLOB:
|
|
|
|
assert(obj->type == OBJ_BLOB);
|
|
|
|
assert((obj->flags & SEEN) == 0);
|
|
|
|
|
2019-05-31 18:46:06 +00:00
|
|
|
frame = &filter_data->array_frame[filter_data->nr - 1];
|
2017-11-21 20:58:50 +00:00
|
|
|
|
|
|
|
dtype = DT_REG;
|
2019-09-03 18:04:58 +00:00
|
|
|
match = path_matches_pattern_list(pathname, strlen(pathname),
|
2019-09-03 18:04:56 +00:00
|
|
|
filename, &dtype, &filter_data->pl,
|
2018-11-10 05:48:51 +00:00
|
|
|
r->index);
|
2019-09-03 18:04:58 +00:00
|
|
|
if (match == UNDECIDED)
|
|
|
|
match = frame->default_match;
|
|
|
|
if (match == MATCHED) {
|
2019-06-27 22:54:06 +00:00
|
|
|
if (omits)
|
|
|
|
oidset_remove(omits, &obj->oid);
|
2017-11-21 20:58:50 +00:00
|
|
|
return LOFR_MARK_SEEN | LOFR_DO_SHOW;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Provisionally omit it. We've already established that
|
|
|
|
* this pathname is not in the sparse-checkout specification
|
|
|
|
* with the CURRENT pathname, so we *WANT* to omit this blob.
|
|
|
|
*
|
|
|
|
* However, a pathname elsewhere in the tree may also
|
|
|
|
* reference this same blob, so we cannot reject it yet.
|
|
|
|
* Leave the LOFR_ bits unset so that if the blob appears
|
|
|
|
* again in the traversal, we will be asked again.
|
|
|
|
*/
|
2019-06-27 22:54:06 +00:00
|
|
|
if (omits)
|
|
|
|
oidset_insert(omits, &obj->oid);
|
2017-11-21 20:58:50 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Remember that at least 1 blob in this tree was
|
|
|
|
* provisionally omitted. This prevents us from short
|
|
|
|
* cutting the tree in future iterations.
|
|
|
|
*/
|
|
|
|
frame->child_prov_omit = 1;
|
|
|
|
return LOFR_ZERO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void filter_sparse_free(void *filter_data)
|
|
|
|
{
|
|
|
|
struct filter_sparse_data *d = filter_data;
|
2022-12-01 17:49:41 +00:00
|
|
|
clear_pattern_list(&d->pl);
|
2019-05-31 18:46:06 +00:00
|
|
|
free(d->array_frame);
|
2017-11-21 20:58:50 +00:00
|
|
|
free(d);
|
|
|
|
}
|
|
|
|
|
2019-06-27 22:54:05 +00:00
|
|
|
static void filter_sparse_oid__init(
|
2017-11-21 20:58:50 +00:00
|
|
|
struct list_objects_filter_options *filter_options,
|
2019-06-27 22:54:05 +00:00
|
|
|
struct filter *filter)
|
2017-11-21 20:58:50 +00:00
|
|
|
{
|
|
|
|
struct filter_sparse_data *d = xcalloc(1, sizeof(*d));
|
list-objects-filter: delay parsing of sparse oid
The list-objects-filter code has two steps to its initialization:
1. parse_list_objects_filter() makes sure the spec is a filter we know
about and is syntactically correct. This step is done by "rev-list"
or "upload-pack" that is going to apply a filter, but also by "git
clone" or "git fetch" before they send the spec across the wire.
2. list_objects_filter__init() runs the type-specific initialization
(using function pointers established in step 1). This happens at
the start of traverse_commit_list_filtered(), when we're about to
actually use the filter.
It's a good idea to parse as much as we can in step 1, in order to catch
problems early (e.g., a blob size limit that isn't a number). But one
thing we _shouldn't_ do is resolve any oids at that step (e.g., for
sparse-file contents specified by oid). In the case of a fetch, the oid
has to be resolved on the remote side.
The current code does resolve the oid during the parse phase, but
ignores any error (which we must do, because we might just be sending
the spec across the wire). This leads to two bugs:
- if we're not in a repository (e.g., because it's git-clone parsing
the spec), then we trigger a BUG() trying to resolve the name
- if we did hit the error case, we still have to notice that later and
bail. The code path in rev-list handles this, but the one in
upload-pack does not, leading to a segfault.
We can fix both by moving the oid resolution into the sparse-oid init
function. At that point we know we have a repository (because we're
about to traverse), and handling the error there fixes the segfault.
As a bonus, we can drop the NULL sparse_oid_value check in rev-list,
since this is now handled in the sparse-oid-filter init function.
Signed-off-by: Jeff King <peff@peff.net>
Acked-by: Jeff Hostetler <jeffhost@microsoft.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-09-15 16:12:44 +00:00
|
|
|
struct object_context oc;
|
|
|
|
struct object_id sparse_oid;
|
|
|
|
|
|
|
|
if (get_oid_with_context(the_repository,
|
|
|
|
filter_options->sparse_oid_name,
|
|
|
|
GET_OID_BLOB, &sparse_oid, &oc))
|
2019-09-15 01:13:47 +00:00
|
|
|
die(_("unable to access sparse blob in '%s'"),
|
list-objects-filter: delay parsing of sparse oid
The list-objects-filter code has two steps to its initialization:
1. parse_list_objects_filter() makes sure the spec is a filter we know
about and is syntactically correct. This step is done by "rev-list"
or "upload-pack" that is going to apply a filter, but also by "git
clone" or "git fetch" before they send the spec across the wire.
2. list_objects_filter__init() runs the type-specific initialization
(using function pointers established in step 1). This happens at
the start of traverse_commit_list_filtered(), when we're about to
actually use the filter.
It's a good idea to parse as much as we can in step 1, in order to catch
problems early (e.g., a blob size limit that isn't a number). But one
thing we _shouldn't_ do is resolve any oids at that step (e.g., for
sparse-file contents specified by oid). In the case of a fetch, the oid
has to be resolved on the remote side.
The current code does resolve the oid during the parse phase, but
ignores any error (which we must do, because we might just be sending
the spec across the wire). This leads to two bugs:
- if we're not in a repository (e.g., because it's git-clone parsing
the spec), then we trigger a BUG() trying to resolve the name
- if we did hit the error case, we still have to notice that later and
bail. The code path in rev-list handles this, but the one in
upload-pack does not, leading to a segfault.
We can fix both by moving the oid resolution into the sparse-oid init
function. At that point we know we have a repository (because we're
about to traverse), and handling the error there fixes the segfault.
As a bonus, we can drop the NULL sparse_oid_value check in rev-list,
since this is now handled in the sparse-oid-filter init function.
Signed-off-by: Jeff King <peff@peff.net>
Acked-by: Jeff Hostetler <jeffhost@microsoft.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-09-15 16:12:44 +00:00
|
|
|
filter_options->sparse_oid_name);
|
2019-10-07 02:32:54 +00:00
|
|
|
if (add_patterns_from_blob_to_list(&sparse_oid, "", 0, &d->pl) < 0)
|
2019-09-15 01:13:47 +00:00
|
|
|
die(_("unable to parse sparse filter data in %s"),
|
|
|
|
oid_to_hex(&sparse_oid));
|
2017-11-21 20:58:50 +00:00
|
|
|
|
|
|
|
ALLOC_GROW(d->array_frame, d->nr + 1, d->alloc);
|
2019-09-03 18:04:58 +00:00
|
|
|
d->array_frame[d->nr].default_match = 0; /* default to include */
|
2017-11-21 20:58:50 +00:00
|
|
|
d->array_frame[d->nr].child_prov_omit = 0;
|
2019-05-31 18:46:06 +00:00
|
|
|
d->nr++;
|
2017-11-21 20:58:50 +00:00
|
|
|
|
2019-06-27 22:54:05 +00:00
|
|
|
filter->filter_data = d;
|
|
|
|
filter->filter_object_fn = filter_sparse;
|
|
|
|
filter->free_fn = filter_sparse_free;
|
2017-11-21 20:58:50 +00:00
|
|
|
}
|
|
|
|
|
2021-04-19 11:46:53 +00:00
|
|
|
/*
|
|
|
|
* A filter for list-objects to omit large blobs.
|
|
|
|
* And to OPTIONALLY collect a list of the omitted OIDs.
|
|
|
|
*/
|
|
|
|
struct filter_object_type_data {
|
|
|
|
enum object_type object_type;
|
|
|
|
};
|
|
|
|
|
|
|
|
static enum list_objects_filter_result filter_object_type(
|
2022-12-13 11:14:23 +00:00
|
|
|
struct repository *r UNUSED,
|
2021-04-19 11:46:53 +00:00
|
|
|
enum list_objects_filter_situation filter_situation,
|
|
|
|
struct object *obj,
|
2022-12-13 11:14:23 +00:00
|
|
|
const char *pathname UNUSED,
|
|
|
|
const char *filename UNUSED,
|
|
|
|
struct oidset *omits UNUSED,
|
2021-04-19 11:46:53 +00:00
|
|
|
void *filter_data_)
|
|
|
|
{
|
|
|
|
struct filter_object_type_data *filter_data = filter_data_;
|
|
|
|
|
|
|
|
switch (filter_situation) {
|
|
|
|
default:
|
|
|
|
BUG("unknown filter_situation: %d", filter_situation);
|
|
|
|
|
|
|
|
case LOFS_TAG:
|
|
|
|
assert(obj->type == OBJ_TAG);
|
|
|
|
if (filter_data->object_type == OBJ_TAG)
|
|
|
|
return LOFR_MARK_SEEN | LOFR_DO_SHOW;
|
|
|
|
return LOFR_MARK_SEEN;
|
|
|
|
|
|
|
|
case LOFS_COMMIT:
|
|
|
|
assert(obj->type == OBJ_COMMIT);
|
|
|
|
if (filter_data->object_type == OBJ_COMMIT)
|
|
|
|
return LOFR_MARK_SEEN | LOFR_DO_SHOW;
|
|
|
|
return LOFR_MARK_SEEN;
|
|
|
|
|
|
|
|
case LOFS_BEGIN_TREE:
|
|
|
|
assert(obj->type == OBJ_TREE);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we only want to show commits or tags, then there is no
|
|
|
|
* need to walk down trees.
|
|
|
|
*/
|
|
|
|
if (filter_data->object_type == OBJ_COMMIT ||
|
|
|
|
filter_data->object_type == OBJ_TAG)
|
|
|
|
return LOFR_SKIP_TREE;
|
|
|
|
|
|
|
|
if (filter_data->object_type == OBJ_TREE)
|
|
|
|
return LOFR_MARK_SEEN | LOFR_DO_SHOW;
|
|
|
|
|
|
|
|
return LOFR_MARK_SEEN;
|
|
|
|
|
|
|
|
case LOFS_BLOB:
|
|
|
|
assert(obj->type == OBJ_BLOB);
|
|
|
|
|
|
|
|
if (filter_data->object_type == OBJ_BLOB)
|
|
|
|
return LOFR_MARK_SEEN | LOFR_DO_SHOW;
|
|
|
|
return LOFR_MARK_SEEN;
|
|
|
|
|
|
|
|
case LOFS_END_TREE:
|
|
|
|
return LOFR_ZERO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void filter_object_type__init(
|
|
|
|
struct list_objects_filter_options *filter_options,
|
|
|
|
struct filter *filter)
|
|
|
|
{
|
|
|
|
struct filter_object_type_data *d = xcalloc(1, sizeof(*d));
|
|
|
|
d->object_type = filter_options->object_type;
|
|
|
|
|
|
|
|
filter->filter_data = d;
|
|
|
|
filter->filter_object_fn = filter_object_type;
|
|
|
|
filter->free_fn = free;
|
|
|
|
}
|
|
|
|
|
2019-06-27 22:54:08 +00:00
|
|
|
/* A filter which only shows objects shown by all sub-filters. */
|
|
|
|
struct combine_filter_data {
|
|
|
|
struct subfilter *sub;
|
|
|
|
size_t nr;
|
|
|
|
};
|
|
|
|
|
|
|
|
static enum list_objects_filter_result process_subfilter(
|
|
|
|
struct repository *r,
|
|
|
|
enum list_objects_filter_situation filter_situation,
|
|
|
|
struct object *obj,
|
|
|
|
const char *pathname,
|
|
|
|
const char *filename,
|
|
|
|
struct subfilter *sub)
|
|
|
|
{
|
|
|
|
enum list_objects_filter_result result;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check and update is_skipping_tree before oidset_contains so
|
|
|
|
* that is_skipping_tree gets unset even when the object is
|
|
|
|
* marked as seen. As of this writing, no filter uses
|
|
|
|
* LOFR_MARK_SEEN on trees that also uses LOFR_SKIP_TREE, so the
|
|
|
|
* ordering is only theoretically important. Be cautious if you
|
|
|
|
* change the order of the below checks and more filters have
|
|
|
|
* been added!
|
|
|
|
*/
|
|
|
|
if (sub->is_skipping_tree) {
|
|
|
|
if (filter_situation == LOFS_END_TREE &&
|
|
|
|
oideq(&obj->oid, &sub->skip_tree))
|
|
|
|
sub->is_skipping_tree = 0;
|
|
|
|
else
|
|
|
|
return LOFR_ZERO;
|
|
|
|
}
|
|
|
|
if (oidset_contains(&sub->seen, &obj->oid))
|
|
|
|
return LOFR_ZERO;
|
|
|
|
|
|
|
|
result = list_objects_filter__filter_object(
|
|
|
|
r, filter_situation, obj, pathname, filename, sub->filter);
|
|
|
|
|
|
|
|
if (result & LOFR_MARK_SEEN)
|
|
|
|
oidset_insert(&sub->seen, &obj->oid);
|
|
|
|
|
|
|
|
if (result & LOFR_SKIP_TREE) {
|
|
|
|
sub->is_skipping_tree = 1;
|
|
|
|
sub->skip_tree = obj->oid;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum list_objects_filter_result filter_combine(
|
|
|
|
struct repository *r,
|
|
|
|
enum list_objects_filter_situation filter_situation,
|
|
|
|
struct object *obj,
|
|
|
|
const char *pathname,
|
|
|
|
const char *filename,
|
2022-12-13 11:14:23 +00:00
|
|
|
struct oidset *omits UNUSED,
|
2019-06-27 22:54:08 +00:00
|
|
|
void *filter_data)
|
|
|
|
{
|
|
|
|
struct combine_filter_data *d = filter_data;
|
|
|
|
enum list_objects_filter_result combined_result =
|
|
|
|
LOFR_DO_SHOW | LOFR_MARK_SEEN | LOFR_SKIP_TREE;
|
|
|
|
size_t sub;
|
|
|
|
|
|
|
|
for (sub = 0; sub < d->nr; sub++) {
|
|
|
|
enum list_objects_filter_result sub_result = process_subfilter(
|
|
|
|
r, filter_situation, obj, pathname, filename,
|
|
|
|
&d->sub[sub]);
|
|
|
|
if (!(sub_result & LOFR_DO_SHOW))
|
|
|
|
combined_result &= ~LOFR_DO_SHOW;
|
|
|
|
if (!(sub_result & LOFR_MARK_SEEN))
|
|
|
|
combined_result &= ~LOFR_MARK_SEEN;
|
|
|
|
if (!d->sub[sub].is_skipping_tree)
|
|
|
|
combined_result &= ~LOFR_SKIP_TREE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return combined_result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void filter_combine__free(void *filter_data)
|
|
|
|
{
|
|
|
|
struct combine_filter_data *d = filter_data;
|
|
|
|
size_t sub;
|
|
|
|
for (sub = 0; sub < d->nr; sub++) {
|
|
|
|
list_objects_filter__free(d->sub[sub].filter);
|
|
|
|
oidset_clear(&d->sub[sub].seen);
|
|
|
|
if (d->sub[sub].omits.set.size)
|
|
|
|
BUG("expected oidset to be cleared already");
|
|
|
|
}
|
|
|
|
free(d->sub);
|
2022-11-20 11:00:52 +00:00
|
|
|
free(d);
|
2019-06-27 22:54:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void add_all(struct oidset *dest, struct oidset *src) {
|
|
|
|
struct oidset_iter iter;
|
|
|
|
struct object_id *src_oid;
|
|
|
|
|
|
|
|
oidset_iter_init(src, &iter);
|
|
|
|
while ((src_oid = oidset_iter_next(&iter)) != NULL)
|
|
|
|
oidset_insert(dest, src_oid);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void filter_combine__finalize_omits(
|
|
|
|
struct oidset *omits,
|
|
|
|
void *filter_data)
|
|
|
|
{
|
|
|
|
struct combine_filter_data *d = filter_data;
|
|
|
|
size_t sub;
|
|
|
|
|
|
|
|
for (sub = 0; sub < d->nr; sub++) {
|
|
|
|
add_all(omits, &d->sub[sub].omits);
|
|
|
|
oidset_clear(&d->sub[sub].omits);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void filter_combine__init(
|
|
|
|
struct list_objects_filter_options *filter_options,
|
|
|
|
struct filter* filter)
|
|
|
|
{
|
|
|
|
struct combine_filter_data *d = xcalloc(1, sizeof(*d));
|
|
|
|
size_t sub;
|
|
|
|
|
|
|
|
d->nr = filter_options->sub_nr;
|
2021-03-13 16:17:22 +00:00
|
|
|
CALLOC_ARRAY(d->sub, d->nr);
|
2019-06-27 22:54:08 +00:00
|
|
|
for (sub = 0; sub < d->nr; sub++)
|
|
|
|
d->sub[sub].filter = list_objects_filter__init(
|
|
|
|
filter->omits ? &d->sub[sub].omits : NULL,
|
|
|
|
&filter_options->sub[sub]);
|
|
|
|
|
|
|
|
filter->filter_data = d;
|
|
|
|
filter->filter_object_fn = filter_combine;
|
|
|
|
filter->free_fn = filter_combine__free;
|
|
|
|
filter->finalize_omits_fn = filter_combine__finalize_omits;
|
|
|
|
}
|
|
|
|
|
2019-06-27 22:54:05 +00:00
|
|
|
typedef void (*filter_init_fn)(
|
2017-11-21 20:58:50 +00:00
|
|
|
struct list_objects_filter_options *filter_options,
|
2019-06-27 22:54:05 +00:00
|
|
|
struct filter *filter);
|
2017-11-21 20:58:50 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Must match "enum list_objects_filter_choice".
|
|
|
|
*/
|
|
|
|
static filter_init_fn s_filters[] = {
|
|
|
|
NULL,
|
|
|
|
filter_blobs_none__init,
|
|
|
|
filter_blobs_limit__init,
|
2019-01-09 02:59:13 +00:00
|
|
|
filter_trees_depth__init,
|
2017-11-21 20:58:50 +00:00
|
|
|
filter_sparse_oid__init,
|
2021-04-19 11:46:53 +00:00
|
|
|
filter_object_type__init,
|
2019-06-27 22:54:08 +00:00
|
|
|
filter_combine__init,
|
2017-11-21 20:58:50 +00:00
|
|
|
};
|
|
|
|
|
2019-06-27 22:54:05 +00:00
|
|
|
struct filter *list_objects_filter__init(
|
2017-11-21 20:58:50 +00:00
|
|
|
struct oidset *omitted,
|
2019-06-27 22:54:05 +00:00
|
|
|
struct list_objects_filter_options *filter_options)
|
2017-11-21 20:58:50 +00:00
|
|
|
{
|
2019-06-27 22:54:05 +00:00
|
|
|
struct filter *filter;
|
2017-11-21 20:58:50 +00:00
|
|
|
filter_init_fn init_fn;
|
|
|
|
|
|
|
|
assert((sizeof(s_filters) / sizeof(s_filters[0])) == LOFC__COUNT);
|
|
|
|
|
list-objects-filter: treat NULL filter_options as "disabled"
In most callers, we have an actual list_objects_filter_options struct,
and if no filtering is desired its "choice" element will be
LOFC_DISABLED. However, some code may have only a pointer to such a
struct which may be NULL (because _their_ callers didn't care about
filtering, either). Rather than forcing them to handle this explicitly
like:
if (filter_options)
traverse_commit_list_filtered(filter_options, revs,
show_commit, show_object,
show_data, NULL);
else
traverse_commit_list(revs, show_commit, show_object,
show_data);
let's just treat a NULL filter_options the same as LOFC_DISABLED. We
only need a small change, since that option struct is converted into a
real filter only in the "init" function.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-05-04 23:12:27 +00:00
|
|
|
if (!filter_options)
|
|
|
|
return NULL;
|
|
|
|
|
2017-11-21 20:58:50 +00:00
|
|
|
if (filter_options->choice >= LOFC__COUNT)
|
2018-10-05 21:31:25 +00:00
|
|
|
BUG("invalid list-objects filter choice: %d",
|
2017-11-21 20:58:50 +00:00
|
|
|
filter_options->choice);
|
|
|
|
|
|
|
|
init_fn = s_filters[filter_options->choice];
|
2019-06-27 22:54:05 +00:00
|
|
|
if (!init_fn)
|
|
|
|
return NULL;
|
|
|
|
|
2021-03-13 16:17:22 +00:00
|
|
|
CALLOC_ARRAY(filter, 1);
|
2019-06-27 22:54:06 +00:00
|
|
|
filter->omits = omitted;
|
|
|
|
init_fn(filter_options, filter);
|
2019-06-27 22:54:05 +00:00
|
|
|
return filter;
|
|
|
|
}
|
|
|
|
|
|
|
|
enum list_objects_filter_result list_objects_filter__filter_object(
|
|
|
|
struct repository *r,
|
|
|
|
enum list_objects_filter_situation filter_situation,
|
|
|
|
struct object *obj,
|
|
|
|
const char *pathname,
|
|
|
|
const char *filename,
|
|
|
|
struct filter *filter)
|
|
|
|
{
|
|
|
|
if (filter && (obj->flags & NOT_USER_GIVEN))
|
|
|
|
return filter->filter_object_fn(r, filter_situation, obj,
|
|
|
|
pathname, filename,
|
2019-06-27 22:54:06 +00:00
|
|
|
filter->omits,
|
2019-06-27 22:54:05 +00:00
|
|
|
filter->filter_data);
|
|
|
|
/*
|
|
|
|
* No filter is active or user gave object explicitly. In this case,
|
|
|
|
* always show the object (except when LOFS_END_TREE, since this tree
|
|
|
|
* had already been shown when LOFS_BEGIN_TREE).
|
|
|
|
*/
|
|
|
|
if (filter_situation == LOFS_END_TREE)
|
|
|
|
return 0;
|
|
|
|
return LOFR_MARK_SEEN | LOFR_DO_SHOW;
|
|
|
|
}
|
|
|
|
|
|
|
|
void list_objects_filter__free(struct filter *filter)
|
|
|
|
{
|
|
|
|
if (!filter)
|
|
|
|
return;
|
2019-06-27 22:54:08 +00:00
|
|
|
if (filter->finalize_omits_fn && filter->omits)
|
|
|
|
filter->finalize_omits_fn(filter->omits, filter->filter_data);
|
2019-06-27 22:54:05 +00:00
|
|
|
filter->free_fn(filter->filter_data);
|
|
|
|
free(filter);
|
2017-11-21 20:58:50 +00:00
|
|
|
}
|