remote: add promisor and partial clone config to the doc
[gitweb.git] / list-objects-filter-options.c
index c0036f73789d1a6a3ff88a76c3838241e65ca868..28c571f922e46cd6ff7aff659677d9003cf3c948 100644 (file)
@@ -6,6 +6,7 @@
 #include "list-objects.h"
 #include "list-objects-filter.h"
 #include "list-objects-filter-options.h"
+#include "promisor-remote.h"
 
 /*
  * Parse value of the argument to the "filter" keyword.
@@ -29,6 +30,9 @@ static int gently_parse_list_objects_filter(
 {
        const char *v0;
 
+       if (!arg)
+               return 0;
+
        if (filter_options->choice) {
                if (errbuf) {
                        strbuf_addstr(
@@ -78,9 +82,12 @@ static int gently_parse_list_objects_filter(
                return 0;
 
        } else if (skip_prefix(arg, "sparse:path=", &v0)) {
-               filter_options->choice = LOFC_SPARSE_PATH;
-               filter_options->sparse_path_value = strdup(v0);
-               return 0;
+               if (errbuf) {
+                       strbuf_addstr(
+                               errbuf,
+                               _("sparse:path filters support has been dropped"));
+               }
+               return 1;
        }
        /*
         * Please update _git_fetch() in git-completion.bash when you
@@ -88,7 +95,7 @@ static int gently_parse_list_objects_filter(
         */
 
        if (errbuf)
-               strbuf_addf(errbuf, "invalid filter-spec '%s'", arg);
+               strbuf_addf(errbuf, _("invalid filter-spec '%s'"), arg);
 
        memset(filter_options, 0, sizeof(*filter_options));
        return 1;
@@ -136,7 +143,6 @@ void list_objects_filter_release(
 {
        free(filter_options->filter_spec);
        free(filter_options->sparse_oid_value);
-       free(filter_options->sparse_path_value);
        memset(filter_options, 0, sizeof(*filter_options));
 }
 
@@ -144,41 +150,42 @@ void partial_clone_register(
        const char *remote,
        const 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(filter_options->filter_spec);
-       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);
+       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);
+
        /*
         * Parse default value, but silently ignore it if it is invalid.
         */
-       if (!core_partial_clone_filter_default)
-               return;
-       gently_parse_list_objects_filter(filter_options,
-                                        core_partial_clone_filter_default,
-                                        NULL);
+       if (promisor)
+               gently_parse_list_objects_filter(filter_options,
+                                                promisor->partial_clone_filter,
+                                                NULL);
 }