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 (although it's better to pass it through
22 * expand_list_objects_filter_spec() first). We also "intern" the arg for the
23 * convenience of the current command.
25 static int gently_parse_list_objects_filter(
26 struct list_objects_filter_options
*filter_options
,
28 struct strbuf
*errbuf
)
32 if (filter_options
->choice
) {
36 _("multiple filter-specs cannot be combined"));
41 filter_options
->filter_spec
= strdup(arg
);
43 if (!strcmp(arg
, "blob:none")) {
44 filter_options
->choice
= LOFC_BLOB_NONE
;
47 } else if (skip_prefix(arg
, "blob:limit=", &v0
)) {
48 if (git_parse_ulong(v0
, &filter_options
->blob_limit_value
)) {
49 filter_options
->choice
= LOFC_BLOB_LIMIT
;
53 } else if (skip_prefix(arg
, "tree:", &v0
)) {
54 if (!git_parse_ulong(v0
, &filter_options
->tree_exclude_depth
)) {
58 _("expected 'tree:<depth>'"));
62 filter_options
->choice
= LOFC_TREE_DEPTH
;
65 } else if (skip_prefix(arg
, "sparse:oid=", &v0
)) {
66 filter_options
->sparse_oid_name
= xstrdup(v0
);
67 filter_options
->choice
= LOFC_SPARSE_OID
;
70 } else if (skip_prefix(arg
, "sparse:path=", &v0
)) {
74 _("sparse:path filters support has been dropped"));
79 * Please update _git_fetch() in git-completion.bash when you
84 strbuf_addf(errbuf
, _("invalid filter-spec '%s'"), arg
);
86 memset(filter_options
, 0, sizeof(*filter_options
));
90 int parse_list_objects_filter(struct list_objects_filter_options
*filter_options
,
93 struct strbuf buf
= STRBUF_INIT
;
94 if (gently_parse_list_objects_filter(filter_options
, arg
, &buf
))
99 int opt_parse_list_objects_filter(const struct option
*opt
,
100 const char *arg
, int unset
)
102 struct list_objects_filter_options
*filter_options
= opt
->value
;
105 list_objects_filter_set_no_filter(filter_options
);
109 return parse_list_objects_filter(filter_options
, arg
);
112 void expand_list_objects_filter_spec(
113 const struct list_objects_filter_options
*filter
,
114 struct strbuf
*expanded_spec
)
116 strbuf_init(expanded_spec
, strlen(filter
->filter_spec
));
117 if (filter
->choice
== LOFC_BLOB_LIMIT
)
118 strbuf_addf(expanded_spec
, "blob:limit=%lu",
119 filter
->blob_limit_value
);
120 else if (filter
->choice
== LOFC_TREE_DEPTH
)
121 strbuf_addf(expanded_spec
, "tree:%lu",
122 filter
->tree_exclude_depth
);
124 strbuf_addstr(expanded_spec
, filter
->filter_spec
);
127 void list_objects_filter_release(
128 struct list_objects_filter_options
*filter_options
)
130 free(filter_options
->filter_spec
);
131 free(filter_options
->sparse_oid_name
);
132 memset(filter_options
, 0, sizeof(*filter_options
));
135 void partial_clone_register(
137 const struct list_objects_filter_options
*filter_options
)
140 * Record the name of the partial clone remote in the
141 * config and in the global variable -- the latter is
142 * used throughout to indicate that partial clone is
143 * enabled and to expect missing objects.
145 if (repository_format_partial_clone
&&
146 *repository_format_partial_clone
&&
147 strcmp(remote
, repository_format_partial_clone
))
148 die(_("cannot change partial clone promisor remote"));
150 git_config_set("core.repositoryformatversion", "1");
151 git_config_set("extensions.partialclone", remote
);
153 repository_format_partial_clone
= xstrdup(remote
);
156 * Record the initial filter-spec in the config as
157 * the default for subsequent fetches from this remote.
159 core_partial_clone_filter_default
=
160 xstrdup(filter_options
->filter_spec
);
161 git_config_set("core.partialclonefilter",
162 core_partial_clone_filter_default
);
165 void partial_clone_get_default_filter_spec(
166 struct list_objects_filter_options
*filter_options
)
169 * Parse default value, but silently ignore it if it is invalid.
171 if (!core_partial_clone_filter_default
)
173 gently_parse_list_objects_filter(filter_options
,
174 core_partial_clone_filter_default
,