5 #include "argv-array.h"
6 #include "list-objects.h"
7 #include "list-objects-filter.h"
8 #include "list-objects-filter-options.h"
11 * Parse value of the argument to the "filter" keyword.
12 * On the command line this looks like:
14 * and in the pack protocol as:
17 * The filter keyword will be used by many commands.
18 * See Documentation/rev-list-options.txt for allowed values for <arg>.
20 * Capture the given arg as the "filter_spec". This can be forwarded to
21 * subordinate commands when necessary. We also "intern" the arg for
22 * the convenience of the current command.
24 int parse_list_objects_filter(struct list_objects_filter_options *filter_options,
29 if (filter_options->choice)
30 die(_("multiple object filter types cannot be combined"));
32 filter_options->filter_spec = strdup(arg);
34 if (!strcmp(arg, "blob:none")) {
35 filter_options->choice = LOFC_BLOB_NONE;
39 if (skip_prefix(arg, "blob:limit=", &v0)) {
40 if (!git_parse_ulong(v0, &filter_options->blob_limit_value))
41 die(_("invalid filter-spec expression '%s'"), arg);
42 filter_options->choice = LOFC_BLOB_LIMIT;
46 if (skip_prefix(arg, "sparse:oid=", &v0)) {
47 struct object_context oc;
48 struct object_id sparse_oid;
51 * Try to parse <oid-expression> into an OID for the current
52 * command, but DO NOT complain if we don't have the blob or
55 if (!get_oid_with_context(v0, GET_OID_BLOB,
57 filter_options->sparse_oid_value = oiddup(&sparse_oid);
58 filter_options->choice = LOFC_SPARSE_OID;
62 if (skip_prefix(arg, "sparse:path=", &v0)) {
63 filter_options->choice = LOFC_SPARSE_PATH;
64 filter_options->sparse_path_value = strdup(v0);
68 die(_("invalid filter-spec expression '%s'"), arg);
72 int opt_parse_list_objects_filter(const struct option *opt,
73 const char *arg, int unset)
75 struct list_objects_filter_options *filter_options = opt->value;
78 list_objects_filter_release(filter_options);
82 return parse_list_objects_filter(filter_options, arg);
85 void list_objects_filter_release(
86 struct list_objects_filter_options *filter_options)
88 free(filter_options->filter_spec);
89 free(filter_options->sparse_oid_value);
90 free(filter_options->sparse_path_value);
91 memset(filter_options, 0, sizeof(*filter_options));