From: Junio C Hamano Date: Wed, 18 Sep 2019 18:50:09 +0000 (-0700) Subject: Merge branch 'md/list-objects-filter-combo' X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/627b82683447e299fc2e20140318c276efbf7de2 Merge branch 'md/list-objects-filter-combo' The list-objects-filter API (used to create a sparse/lazy clone) learned to take a combined filter specification. * md/list-objects-filter-combo: list-objects-filter-options: make parser void list-objects-filter-options: clean up use of ALLOC_GROW list-objects-filter-options: allow mult. --filter strbuf: give URL-encoding API a char predicate fn list-objects-filter-options: make filter_spec a string_list list-objects-filter-options: move error check up list-objects-filter: implement composite filters list-objects-filter-options: always supply *errbuf list-objects-filter: put omits set in filter struct list-objects-filter: encapsulate filter components --- 627b82683447e299fc2e20140318c276efbf7de2 diff --cc list-objects-filter-options.c index 28c571f922,ba1425cb4a..4d88bfe64a --- a/list-objects-filter-options.c +++ b/list-objects-filter-options.c @@@ -6,7 -6,13 +6,14 @@@ #include "list-objects.h" #include "list-objects-filter.h" #include "list-objects-filter-options.h" +#include "promisor-remote.h" + #include "trace.h" + #include "url.h" + + static int parse_combine_filter( + struct list_objects_filter_options *filter_options, + const char *arg, + struct strbuf *errbuf); /* * Parse value of the argument to the "filter" keyword. @@@ -30,19 -36,8 +37,11 @@@ static int gently_parse_list_objects_fi { const char *v0; + if (!arg) + return 0; + - if (filter_options->choice) { - if (errbuf) { - strbuf_addstr( - errbuf, - _("multiple filter-specs cannot be combined")); - } - return 1; - } - - filter_options->filter_spec = strdup(arg); + if (filter_options->choice) + BUG("filter_options already populated"); if (!strcmp(arg, "blob:none")) { filter_options->choice = LOFC_BLOB_NONE; @@@ -148,44 -325,49 +329,52 @@@ void list_objects_filter_release void partial_clone_register( const char *remote, - const struct list_objects_filter_options *filter_options) + struct list_objects_filter_options *filter_options) { - /* - * Record the name of the partial clone remote in the - * config and in the global variable -- the latter is - * used throughout to indicate that partial clone is - * enabled and to expect missing objects. - */ - if (repository_format_partial_clone && - *repository_format_partial_clone && - strcmp(remote, repository_format_partial_clone)) - die(_("cannot change partial clone promisor remote")); + char *cfg_name; + char *filter_name; - git_config_set("core.repositoryformatversion", "1"); - git_config_set("extensions.partialclone", remote); + /* Check if it is already registered */ + if (!promisor_remote_find(remote)) { + git_config_set("core.repositoryformatversion", "1"); - repository_format_partial_clone = xstrdup(remote); + /* Add promisor config for the remote */ + cfg_name = xstrfmt("remote.%s.promisor", remote); + git_config_set(cfg_name, "true"); + free(cfg_name); + } /* * Record the initial filter-spec in the config as * the default for subsequent fetches from this remote. */ - core_partial_clone_filter_default = - xstrdup(expand_list_objects_filter_spec(filter_options)); - git_config_set("core.partialclonefilter", - core_partial_clone_filter_default); + filter_name = xstrfmt("remote.%s.partialclonefilter", remote); - git_config_set(filter_name, filter_options->filter_spec); ++ /* NEEDSWORK: 'expand' result leaking??? */ ++ git_config_set(filter_name, ++ expand_list_objects_filter_spec(filter_options)); + free(filter_name); + + /* Make sure the config info are reset */ + promisor_remote_reinit(); } void partial_clone_get_default_filter_spec( - struct list_objects_filter_options *filter_options) + struct list_objects_filter_options *filter_options, + const char *remote) { + struct promisor_remote *promisor = promisor_remote_find(remote); + struct strbuf errbuf = STRBUF_INIT; /* * Parse default value, but silently ignore it if it is invalid. */ - if (promisor) - gently_parse_list_objects_filter(filter_options, - promisor->partial_clone_filter, - NULL); - if (!core_partial_clone_filter_default) ++ if (!promisor) + return; + + string_list_append(&filter_options->filter_spec, - core_partial_clone_filter_default); ++ promisor->partial_clone_filter); + gently_parse_list_objects_filter(filter_options, - core_partial_clone_filter_default, ++ promisor->partial_clone_filter, + &errbuf); + strbuf_release(&errbuf); } diff --cc list-objects-filter-options.h index 8deaa287b5,db37dfb34a..b63c5ee1a3 --- a/list-objects-filter-options.h +++ b/list-objects-filter-options.h @@@ -85,9 -118,8 +118,9 @@@ static inline void list_objects_filter_ void partial_clone_register( const char *remote, - const struct list_objects_filter_options *filter_options); + struct list_objects_filter_options *filter_options); void partial_clone_get_default_filter_spec( - struct list_objects_filter_options *filter_options); + struct list_objects_filter_options *filter_options, + const char *remote); #endif /* LIST_OBJECTS_FILTER_OPTIONS_H */ diff --cc strbuf.c index d30f916858,60ab5144f2..aa48d179a9 --- a/strbuf.c +++ b/strbuf.c @@@ -806,21 -807,15 +807,21 @@@ static void strbuf_add_urlencode(struc } void strbuf_addstr_urlencode(struct strbuf *sb, const char *s, - int reserved) + char_predicate allow_unencoded_fn) { - strbuf_add_urlencode(sb, s, strlen(s), reserved); + strbuf_add_urlencode(sb, s, strlen(s), allow_unencoded_fn); } -void strbuf_humanise_bytes(struct strbuf *buf, off_t bytes) +static void strbuf_humanise(struct strbuf *buf, off_t bytes, + int humanise_rate) { if (bytes > 1 << 30) { - strbuf_addf(buf, "%u.%2.2u GiB", + strbuf_addf(buf, + humanise_rate == 0 ? + /* TRANSLATORS: IEC 80000-13:2008 gibibyte */ + _("%u.%2.2u GiB") : + /* TRANSLATORS: IEC 80000-13:2008 gibibyte/second */ + _("%u.%2.2u GiB/s"), (unsigned)(bytes >> 30), (unsigned)(bytes & ((1 << 30) - 1)) / 10737419); } else if (bytes > 1 << 20) {