remote: add promisor and partial clone config to the doc
[gitweb.git] / list-objects-filter-options.c
index 1cb20c659c82b151a652da0528d0673ac629cc6c..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(
@@ -146,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);
 }