Merge branch 'md/list-objects-filter-combo'
authorJunio C Hamano <gitster@pobox.com>
Wed, 18 Sep 2019 18:50:09 +0000 (11:50 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 18 Sep 2019 18:50:09 +0000 (11:50 -0700)
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

14 files changed:
1  2 
Documentation/rev-list-options.txt
builtin/clone.c
builtin/fetch.c
builtin/rev-list.c
cache.h
fetch-pack.c
list-objects-filter-options.c
list-objects-filter-options.h
strbuf.c
strbuf.h
t/t5616-partial-clone.sh
transport-helper.c
transport.c
upload-pack.c
Simple merge
diff --cc builtin/clone.c
Simple merge
diff --cc builtin/fetch.c
Simple merge
Simple merge
diff --cc cache.h
Simple merge
diff --cc fetch-pack.c
Simple merge
index 28c571f922e46cd6ff7aff659677d9003cf3c948,ba1425cb4a071f02e9daae57f3f7ce4194b12408..4d88bfe64ad230b4055a77b79432ae2db8af87f6
@@@ -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 (filter_options->choice) {
-               if (errbuf) {
-                       strbuf_addstr(
-                               errbuf,
-                               _("multiple filter-specs cannot be combined"));
-               }
-               return 1;
-       }
-       filter_options->filter_spec = strdup(arg);
 +      if (!arg)
 +              return 0;
 +
+       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);
  }
index 8deaa287b57cbbfd290ce4aa040883b8a5ebcd42,db37dfb34a17402860eddd01607e610b751311f0..b63c5ee1a368aa4d34cda8bbc41fce905692495b
@@@ -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 d30f916858883aa312bd824a53516cb099a2e922,60ab5144f2ff1f53ad7755c68a8447f113e0e777..aa48d179a9aec236069fc88501c5c26c3569d502
+++ 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) {
diff --cc strbuf.h
Simple merge
Simple merge
Simple merge
diff --cc transport.c
Simple merge
diff --cc upload-pack.c
Simple merge