1#include"cache.h" 2#include"commit.h" 3#include"config.h" 4#include"revision.h" 5#include"argv-array.h" 6#include"list-objects.h" 7#include"list-objects-filter.h" 8#include"list-objects-filter-options.h" 9 10/* 11 * Parse value of the argument to the "filter" keyword. 12 * On the command line this looks like: 13 * --filter=<arg> 14 * and in the pack protocol as: 15 * "filter" SP <arg> 16 * 17 * The filter keyword will be used by many commands. 18 * See Documentation/rev-list-options.txt for allowed values for <arg>. 19 * 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. 23 */ 24intparse_list_objects_filter(struct list_objects_filter_options *filter_options, 25const char*arg) 26{ 27const char*v0; 28 29if(filter_options->choice) 30die(_("multiple object filter types cannot be combined")); 31 32 filter_options->filter_spec =strdup(arg); 33 34if(!strcmp(arg,"blob:none")) { 35 filter_options->choice = LOFC_BLOB_NONE; 36return0; 37} 38 39if(skip_prefix(arg,"blob:limit=", &v0)) { 40if(!git_parse_ulong(v0, &filter_options->blob_limit_value)) 41die(_("invalid filter-spec expression '%s'"), arg); 42 filter_options->choice = LOFC_BLOB_LIMIT; 43return0; 44} 45 46if(skip_prefix(arg,"sparse:oid=", &v0)) { 47struct object_context oc; 48struct object_id sparse_oid; 49 50/* 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 53 * ref locally. 54 */ 55if(!get_oid_with_context(v0, GET_OID_BLOB, 56&sparse_oid, &oc)) 57 filter_options->sparse_oid_value =oiddup(&sparse_oid); 58 filter_options->choice = LOFC_SPARSE_OID; 59return0; 60} 61 62if(skip_prefix(arg,"sparse:path=", &v0)) { 63 filter_options->choice = LOFC_SPARSE_PATH; 64 filter_options->sparse_path_value =strdup(v0); 65return0; 66} 67 68die(_("invalid filter-spec expression '%s'"), arg); 69return0; 70} 71 72intopt_parse_list_objects_filter(const struct option *opt, 73const char*arg,int unset) 74{ 75struct list_objects_filter_options *filter_options = opt->value; 76 77if(unset || !arg) { 78list_objects_filter_release(filter_options); 79return0; 80} 81 82returnparse_list_objects_filter(filter_options, arg); 83} 84 85voidlist_objects_filter_release( 86struct list_objects_filter_options *filter_options) 87{ 88free(filter_options->filter_spec); 89free(filter_options->sparse_oid_value); 90free(filter_options->sparse_path_value); 91memset(filter_options,0,sizeof(*filter_options)); 92}