]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Use promisor_remote_get_direct() and has_promisor_remote()
authorChristian Couder <christian.couder@gmail.com>
Tue, 25 Jun 2019 13:40:31 +0000 (15:40 +0200)
committerJunio C Hamano <gitster@pobox.com>
Tue, 25 Jun 2019 21:05:37 +0000 (14:05 -0700)
Instead of using the repository_format_partial_clone global
and fetch_objects() directly, let's use has_promisor_remote()
and promisor_remote_get_direct().

This way all the configured promisor remotes will be taken
into account, not only the one specified by
extensions.partialClone.

Also when cloning or fetching using a partial clone filter,
remote.origin.promisor will be set to "true" instead of
setting extensions.partialClone to "origin". This makes it
possible to use many promisor remote just by fetching from
them.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
14 files changed:
builtin/cat-file.c
builtin/fetch.c
builtin/gc.c
builtin/index-pack.c
builtin/repack.c
cache-tree.c
connected.c
diff.c
list-objects-filter-options.c
packfile.c
sha1-file.c
t/t5601-clone.sh
t/t5616-partial-clone.sh
unpack-trees.c

index 0f092382e175cf7ebe43d2f53ef1c5c79c338568..85ae10bf0b81bf2bb536548528dc177517f3fb49 100644 (file)
@@ -15,6 +15,7 @@
 #include "sha1-array.h"
 #include "packfile.h"
 #include "object-store.h"
+#include "promisor-remote.h"
 
 struct batch_options {
        int enabled;
@@ -523,8 +524,8 @@ static int batch_objects(struct batch_options *opt)
        if (opt->all_objects) {
                struct object_cb_data cb;
 
-               if (repository_format_partial_clone)
-                       warning("This repository has extensions.partialClone set. Some objects may not be loaded.");
+               if (has_promisor_remote())
+                       warning("This repository uses promisor remotes. Some objects may not be loaded.");
 
                cb.opt = opt;
                cb.expand = &data;
index 4ba63d5ac642844832a5c832cea93ddf99507764..f74bd78144b1fb96af74b73cb4e8818047c99d74 100644 (file)
@@ -23,6 +23,7 @@
 #include "packfile.h"
 #include "list-objects-filter-options.h"
 #include "commit-reach.h"
+#include "promisor-remote.h"
 
 static const char * const builtin_fetch_usage[] = {
        N_("git fetch [<options>] [<repository> [<refspec>...]]"),
@@ -1460,7 +1461,7 @@ static inline void fetch_one_setup_partial(struct remote *remote)
         * If no prior partial clone/fetch and the current fetch DID NOT
         * request a partial-fetch, do a normal fetch.
         */
-       if (!repository_format_partial_clone && !filter_options.choice)
+       if (!has_promisor_remote() && !filter_options.choice)
                return;
 
        /*
@@ -1468,7 +1469,7 @@ static inline void fetch_one_setup_partial(struct remote *remote)
         * on this repo and remember the given filter-spec as the default
         * for subsequent fetches to this remote.
         */
-       if (!repository_format_partial_clone && filter_options.choice) {
+       if (!has_promisor_remote() && filter_options.choice) {
                partial_clone_register(remote->name, &filter_options);
                return;
        }
@@ -1477,7 +1478,7 @@ static inline void fetch_one_setup_partial(struct remote *remote)
         * We are currently limited to only ONE promisor remote and only
         * allow partial-fetches from the promisor remote.
         */
-       if (strcmp(remote->name, repository_format_partial_clone)) {
+       if (!promisor_remote_find(remote->name)) {
                if (filter_options.choice)
                        die(_("--filter can only be used with the remote "
                              "configured in extensions.partialClone"));
@@ -1611,7 +1612,7 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
        if (depth || deepen_since || deepen_not.nr)
                deepen = 1;
 
-       if (filter_options.choice && !repository_format_partial_clone)
+       if (filter_options.choice && !has_promisor_remote())
                die("--filter can only be used when extensions.partialClone is set");
 
        if (all) {
@@ -1645,7 +1646,7 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
        }
 
        if (remote) {
-               if (filter_options.choice || repository_format_partial_clone)
+               if (filter_options.choice || has_promisor_remote())
                        fetch_one_setup_partial(remote);
                result = fetch_one(remote, argc, argv, prune_tags_ok);
        } else {
index 8943bcc300d4a2ce6786857908e189c374373906..824a8832b5293c3e204cdd3f3cf183ee001833b1 100644 (file)
@@ -27,6 +27,7 @@
 #include "pack-objects.h"
 #include "blob.h"
 #include "tree.h"
+#include "promisor-remote.h"
 
 #define FAILED_RUN "failed to run %s"
 
@@ -661,7 +662,7 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
                        argv_array_push(&prune, prune_expire);
                        if (quiet)
                                argv_array_push(&prune, "--no-progress");
-                       if (repository_format_partial_clone)
+                       if (has_promisor_remote())
                                argv_array_push(&prune,
                                                "--exclude-promisor-objects");
                        if (run_command_v_opt(prune.argv, RUN_GIT_CMD))
index 0d55f73b0b443b60dccc31096675d40691b3eb56..a23454da6ef9b3a219a48971ef9045772d328155 100644 (file)
@@ -14,7 +14,7 @@
 #include "thread-utils.h"
 #include "packfile.h"
 #include "object-store.h"
-#include "fetch-object.h"
+#include "promisor-remote.h"
 
 static const char index_pack_usage[] =
 "git index-pack [-v] [-o <index-file>] [--keep | --keep=<msg>] [--verify] [--strict] (<pack-file> | --stdin [--fix-thin] [<pack-file>])";
@@ -1352,7 +1352,7 @@ static void fix_unresolved_deltas(struct hashfile *f)
                sorted_by_pos[i] = &ref_deltas[i];
        QSORT(sorted_by_pos, nr_ref_deltas, delta_pos_compare);
 
-       if (repository_format_partial_clone) {
+       if (has_promisor_remote()) {
                /*
                 * Prefetch the delta bases.
                 */
@@ -1366,8 +1366,8 @@ static void fix_unresolved_deltas(struct hashfile *f)
                        oid_array_append(&to_fetch, &d->oid);
                }
                if (to_fetch.nr)
-                       fetch_objects(repository_format_partial_clone,
-                                     to_fetch.oid, to_fetch.nr);
+                       promisor_remote_get_direct(the_repository,
+                                                  to_fetch.oid, to_fetch.nr);
                oid_array_clear(&to_fetch);
        }
 
index caca11392713eb92816d1e503f286bfe0d9be78a..df9a32c9060e46d9e33d2f1aa7599e63a01763aa 100644 (file)
@@ -11,6 +11,7 @@
 #include "midx.h"
 #include "packfile.h"
 #include "object-store.h"
+#include "promisor-remote.h"
 
 static int delta_base_offset = 1;
 static int pack_kept_objects = -1;
@@ -369,7 +370,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
        argv_array_push(&cmd.args, "--all");
        argv_array_push(&cmd.args, "--reflog");
        argv_array_push(&cmd.args, "--indexed-objects");
-       if (repository_format_partial_clone)
+       if (has_promisor_remote())
                argv_array_push(&cmd.args, "--exclude-promisor-objects");
        if (write_bitmaps)
                argv_array_push(&cmd.args, "--write-bitmap-index");
index b13bfaf71e9e1554173beca4cfd8acf5929bc9ce..64c285a746a886bc53bcc3ee0b1713ad2b50b3fc 100644 (file)
@@ -5,6 +5,7 @@
 #include "cache-tree.h"
 #include "object-store.h"
 #include "replace-object.h"
+#include "promisor-remote.h"
 
 #ifndef DEBUG
 #define DEBUG 0
@@ -357,7 +358,7 @@ static int update_one(struct cache_tree *it,
                }
 
                ce_missing_ok = mode == S_IFGITLINK || missing_ok ||
-                       (repository_format_partial_clone &&
+                       (has_promisor_remote() &&
                         ce_skip_worktree(ce));
                if (is_null_oid(oid) ||
                    (!ce_missing_ok && !has_object_file(oid))) {
index 1ab481fed69b33b48bd95c282d2c0faff897123c..b0e4968fbdfb68d9043dddf6248bb7fc03e08382 100644 (file)
@@ -5,6 +5,7 @@
 #include "connected.h"
 #include "transport.h"
 #include "packfile.h"
+#include "promisor-remote.h"
 
 /*
  * If we feed all the commits we want to verify to this command
@@ -73,7 +74,7 @@ int check_connected(oid_iterate_fn fn, void *cb_data,
        argv_array_push(&rev_list.args,"rev-list");
        argv_array_push(&rev_list.args, "--objects");
        argv_array_push(&rev_list.args, "--stdin");
-       if (repository_format_partial_clone)
+       if (has_promisor_remote())
                argv_array_push(&rev_list.args, "--exclude-promisor-objects");
        if (!opt->is_deepening_fetch) {
                argv_array_push(&rev_list.args, "--not");
diff --git a/diff.c b/diff.c
index 1ee04e321b1b5cc4e3f6bde37f49b7d3c0694aa6..249cc6eaceba6641121cbb24fc6ab61581c18bb0 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -25,7 +25,7 @@
 #include "packfile.h"
 #include "parse-options.h"
 #include "help.h"
-#include "fetch-object.h"
+#include "promisor-remote.h"
 
 #ifdef NO_FAST_WORKING_DIRECTORY
 #define FAST_WORKING_DIRECTORY 0
@@ -6514,8 +6514,7 @@ static void add_if_missing(struct repository *r,
 
 void diffcore_std(struct diff_options *options)
 {
-       if (options->repo == the_repository &&
-           repository_format_partial_clone) {
+       if (options->repo == the_repository && has_promisor_remote()) {
                /*
                 * Prefetch the diff pairs that are about to be flushed.
                 */
@@ -6532,8 +6531,8 @@ void diffcore_std(struct diff_options *options)
                        /*
                         * NEEDSWORK: Consider deduplicating the OIDs sent.
                         */
-                       fetch_objects(repository_format_partial_clone,
-                                     to_fetch.oid, to_fetch.nr);
+                       promisor_remote_get_direct(options->repo,
+                                                  to_fetch.oid, to_fetch.nr);
                oid_array_clear(&to_fetch);
        }
 
index 1cb20c659c82b151a652da0528d0673ac629cc6c..b0de7d3c176ab793c654e19314e84264ffe2966c 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.
@@ -146,30 +147,31 @@ 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;
 
-       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.
+        *
+        * TODO: record it into remote.<name>.partialclonefilter
         */
        core_partial_clone_filter_default =
                xstrdup(filter_options->filter_spec);
        git_config_set("core.partialclonefilter",
                       core_partial_clone_filter_default);
+
+       /* Make sure the config info are reset */
+       promisor_remote_reinit();
 }
 
 void partial_clone_get_default_filter_spec(
index d786ec731202e5d623a7558bec2168194db11514..50aaf93bc36cc43999de4f7785a6a9c54eafbf37 100644 (file)
@@ -16,6 +16,7 @@
 #include "tree.h"
 #include "object-store.h"
 #include "midx.h"
+#include "promisor-remote.h"
 
 char *odb_pack_name(struct strbuf *buf,
                    const unsigned char *sha1,
@@ -2119,7 +2120,7 @@ int is_promisor_object(const struct object_id *oid)
        static int promisor_objects_prepared;
 
        if (!promisor_objects_prepared) {
-               if (repository_format_partial_clone) {
+               if (has_promisor_remote()) {
                        for_each_packed_object(add_promisor_object,
                                               &promisor_objects,
                                               FOR_EACH_OBJECT_PROMISOR_ONLY);
index 819d32cdb8dbe6d2adddb1b4b69a1639db594471..fe250c4b6eb704a6eb22b4242e22be5d665116cd 100644 (file)
@@ -30,8 +30,8 @@
 #include "mergesort.h"
 #include "quote.h"
 #include "packfile.h"
-#include "fetch-object.h"
 #include "object-store.h"
+#include "promisor-remote.h"
 
 /* The maximum size for an object header. */
 #define MAX_HEADER_LEN 32
@@ -1377,16 +1377,17 @@ int oid_object_info_extended(struct repository *r, const struct object_id *oid,
                }
 
                /* Check if it is a missing object */
-               if (fetch_if_missing && repository_format_partial_clone &&
+               if (fetch_if_missing && has_promisor_remote() &&
                    !already_retried && r == the_repository &&
                    !(flags & OBJECT_INFO_SKIP_FETCH_OBJECT)) {
                        /*
-                        * TODO Investigate checking fetch_object() return
-                        * TODO value and stopping on error here.
-                        * TODO Pass a repository struct through fetch_object,
-                        * such that arbitrary repositories work.
+                        * TODO Investigate checking promisor_remote_get_direct()
+                        * TODO return value and stopping on error here.
+                        * TODO Pass a repository struct through
+                        * promisor_remote_get_direct(), such that arbitrary
+                        * repositories work.
                         */
-                       fetch_objects(repository_format_partial_clone, real, 1);
+                       promisor_remote_get_direct(r, real, 1);
                        already_retried = 1;
                        continue;
                }
index 37d76808d4a74b101f0606fc7a114fed6a8afa91..534d03a4d787ae2b9911c0171c91ba1493d2556d 100755 (executable)
@@ -654,7 +654,7 @@ partial_clone () {
        git -C client fsck &&
 
        # Ensure that unneeded blobs are not inadvertently fetched.
-       test_config -C client extensions.partialclone "not a remote" &&
+       test_config -C client remote.origin.promisor "false" &&
        test_must_fail git -C client cat-file -e "$HASH1" &&
 
        # But this blob was fetched, because clone performs an initial checkout
index b91ef548f86b0e250b8fdcd1b8b764c780218931..8f9a62aac0b9a5cf83eb17e50a16f7690ebf356e 100755 (executable)
@@ -42,7 +42,7 @@ test_expect_success 'do partial clone 1' '
 
        test_cmp expect_1.oids observed.oids &&
        test "$(git -C pc1 config --local core.repositoryformatversion)" = "1" &&
-       test "$(git -C pc1 config --local extensions.partialclone)" = "origin" &&
+       test "$(git -C pc1 config --local remote.origin.promisor)" = "true" &&
        test "$(git -C pc1 config --local core.partialclonefilter)" = "blob:none"
 '
 
index 50189909b86d6ab48a0aa15893f5b66c2e9ce613..aebd865ef6bd270f9a99b2043a51f476c1247c2d 100644 (file)
@@ -16,7 +16,7 @@
 #include "submodule-config.h"
 #include "fsmonitor.h"
 #include "object-store.h"
-#include "fetch-object.h"
+#include "promisor-remote.h"
 
 /*
  * Error messages expected by scripts out of plumbing commands such as
@@ -400,7 +400,7 @@ static int check_updates(struct unpack_trees_options *o)
                load_gitmodules_file(index, &state);
 
        enable_delayed_checkout(&state);
-       if (repository_format_partial_clone && o->update && !o->dry_run) {
+       if (has_promisor_remote() && o->update && !o->dry_run) {
                /*
                 * Prefetch the objects that are to be checked out in the loop
                 * below.
@@ -419,8 +419,8 @@ static int check_updates(struct unpack_trees_options *o)
                        oid_array_append(&to_fetch, &ce->oid);
                }
                if (to_fetch.nr)
-                       fetch_objects(repository_format_partial_clone,
-                                     to_fetch.oid, to_fetch.nr);
+                       promisor_remote_get_direct(the_repository,
+                                                  to_fetch.oid, to_fetch.nr);
                oid_array_clear(&to_fetch);
        }
        for (i = 0; i < index->cache_nr; i++) {