Skip to content

Commit e265069

Browse files
chriscoolgitster
authored andcommitted
Use promisor_remote_get_direct() and has_promisor_remote()
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7bdf092 commit e265069

12 files changed

+47
-38
lines changed

builtin/cat-file.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "sha1-array.h"
1616
#include "packfile.h"
1717
#include "object-store.h"
18+
#include "promisor-remote.h"
1819

1920
struct batch_options {
2021
int enabled;
@@ -523,8 +524,8 @@ static int batch_objects(struct batch_options *opt)
523524
if (opt->all_objects) {
524525
struct object_cb_data cb;
525526

526-
if (repository_format_partial_clone)
527-
warning("This repository has extensions.partialClone set. Some objects may not be loaded.");
527+
if (has_promisor_remote())
528+
warning("This repository uses promisor remotes. Some objects may not be loaded.");
528529

529530
cb.opt = opt;
530531
cb.expand = &data;

builtin/fetch.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "packfile.h"
2424
#include "list-objects-filter-options.h"
2525
#include "commit-reach.h"
26+
#include "promisor-remote.h"
2627

2728
static const char * const builtin_fetch_usage[] = {
2829
N_("git fetch [<options>] [<repository> [<refspec>...]]"),
@@ -1460,15 +1461,15 @@ static inline void fetch_one_setup_partial(struct remote *remote)
14601461
* If no prior partial clone/fetch and the current fetch DID NOT
14611462
* request a partial-fetch, do a normal fetch.
14621463
*/
1463-
if (!repository_format_partial_clone && !filter_options.choice)
1464+
if (!has_promisor_remote() && !filter_options.choice)
14641465
return;
14651466

14661467
/*
14671468
* If this is the FIRST partial-fetch request, we enable partial
14681469
* on this repo and remember the given filter-spec as the default
14691470
* for subsequent fetches to this remote.
14701471
*/
1471-
if (!repository_format_partial_clone && filter_options.choice) {
1472+
if (!has_promisor_remote() && filter_options.choice) {
14721473
partial_clone_register(remote->name, &filter_options);
14731474
return;
14741475
}
@@ -1477,7 +1478,7 @@ static inline void fetch_one_setup_partial(struct remote *remote)
14771478
* We are currently limited to only ONE promisor remote and only
14781479
* allow partial-fetches from the promisor remote.
14791480
*/
1480-
if (strcmp(remote->name, repository_format_partial_clone)) {
1481+
if (!promisor_remote_find(remote->name)) {
14811482
if (filter_options.choice)
14821483
die(_("--filter can only be used with the remote "
14831484
"configured in extensions.partialClone"));
@@ -1611,7 +1612,7 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
16111612
if (depth || deepen_since || deepen_not.nr)
16121613
deepen = 1;
16131614

1614-
if (filter_options.choice && !repository_format_partial_clone)
1615+
if (filter_options.choice && !has_promisor_remote())
16151616
die("--filter can only be used when extensions.partialClone is set");
16161617

16171618
if (all) {
@@ -1645,7 +1646,7 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
16451646
}
16461647

16471648
if (remote) {
1648-
if (filter_options.choice || repository_format_partial_clone)
1649+
if (filter_options.choice || has_promisor_remote())
16491650
fetch_one_setup_partial(remote);
16501651
result = fetch_one(remote, argc, argv, prune_tags_ok);
16511652
} else {

builtin/gc.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "pack-objects.h"
2828
#include "blob.h"
2929
#include "tree.h"
30+
#include "promisor-remote.h"
3031

3132
#define FAILED_RUN "failed to run %s"
3233

@@ -640,7 +641,7 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
640641
argv_array_push(&prune, prune_expire);
641642
if (quiet)
642643
argv_array_push(&prune, "--no-progress");
643-
if (repository_format_partial_clone)
644+
if (has_promisor_remote())
644645
argv_array_push(&prune,
645646
"--exclude-promisor-objects");
646647
if (run_command_v_opt(prune.argv, RUN_GIT_CMD))

builtin/repack.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "midx.h"
1212
#include "packfile.h"
1313
#include "object-store.h"
14+
#include "promisor-remote.h"
1415

1516
static int delta_base_offset = 1;
1617
static int pack_kept_objects = -1;
@@ -366,7 +367,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
366367
argv_array_push(&cmd.args, "--all");
367368
argv_array_push(&cmd.args, "--reflog");
368369
argv_array_push(&cmd.args, "--indexed-objects");
369-
if (repository_format_partial_clone)
370+
if (has_promisor_remote())
370371
argv_array_push(&cmd.args, "--exclude-promisor-objects");
371372
if (write_bitmaps)
372373
argv_array_push(&cmd.args, "--write-bitmap-index");

cache-tree.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "cache-tree.h"
66
#include "object-store.h"
77
#include "replace-object.h"
8+
#include "promisor-remote.h"
89

910
#ifndef DEBUG
1011
#define DEBUG 0
@@ -357,7 +358,7 @@ static int update_one(struct cache_tree *it,
357358
}
358359

359360
ce_missing_ok = mode == S_IFGITLINK || missing_ok ||
360-
(repository_format_partial_clone &&
361+
(has_promisor_remote() &&
361362
ce_skip_worktree(ce));
362363
if (is_null_oid(oid) ||
363364
(!ce_missing_ok && !has_object_file(oid))) {

connected.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "connected.h"
55
#include "transport.h"
66
#include "packfile.h"
7+
#include "promisor-remote.h"
78

89
/*
910
* If we feed all the commits we want to verify to this command
@@ -56,7 +57,7 @@ int check_connected(oid_iterate_fn fn, void *cb_data,
5657
argv_array_push(&rev_list.args,"rev-list");
5758
argv_array_push(&rev_list.args, "--objects");
5859
argv_array_push(&rev_list.args, "--stdin");
59-
if (repository_format_partial_clone)
60+
if (has_promisor_remote())
6061
argv_array_push(&rev_list.args, "--exclude-promisor-objects");
6162
if (!opt->is_deepening_fetch) {
6263
argv_array_push(&rev_list.args, "--not");

list-objects-filter-options.c

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "list-objects.h"
77
#include "list-objects-filter.h"
88
#include "list-objects-filter-options.h"
9+
#include "promisor-remote.h"
910

1011
/*
1112
* Parse value of the argument to the "filter" keyword.
@@ -144,30 +145,31 @@ void partial_clone_register(
144145
const char *remote,
145146
const struct list_objects_filter_options *filter_options)
146147
{
147-
/*
148-
* Record the name of the partial clone remote in the
149-
* config and in the global variable -- the latter is
150-
* used throughout to indicate that partial clone is
151-
* enabled and to expect missing objects.
152-
*/
153-
if (repository_format_partial_clone &&
154-
*repository_format_partial_clone &&
155-
strcmp(remote, repository_format_partial_clone))
156-
die(_("cannot change partial clone promisor remote"));
148+
char *cfg_name;
157149

158-
git_config_set("core.repositoryformatversion", "1");
159-
git_config_set("extensions.partialclone", remote);
150+
/* Check if it is already registered */
151+
if (!promisor_remote_find(remote)) {
152+
git_config_set("core.repositoryformatversion", "1");
160153

161-
repository_format_partial_clone = xstrdup(remote);
154+
/* Add promisor config for the remote */
155+
cfg_name = xstrfmt("remote.%s.promisor", remote);
156+
git_config_set(cfg_name, "true");
157+
free(cfg_name);
158+
}
162159

163160
/*
164161
* Record the initial filter-spec in the config as
165162
* the default for subsequent fetches from this remote.
163+
*
164+
* TODO: record it into remote.<name>.partialclonefilter
166165
*/
167166
core_partial_clone_filter_default =
168167
xstrdup(filter_options->filter_spec);
169168
git_config_set("core.partialclonefilter",
170169
core_partial_clone_filter_default);
170+
171+
/* Make sure the config info are reset */
172+
promisor_remote_reinit();
171173
}
172174

173175
void partial_clone_get_default_filter_spec(

packfile.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "tree.h"
1717
#include "object-store.h"
1818
#include "midx.h"
19+
#include "promisor-remote.h"
1920

2021
char *odb_pack_name(struct strbuf *buf,
2122
const unsigned char *sha1,
@@ -2119,7 +2120,7 @@ int is_promisor_object(const struct object_id *oid)
21192120
static int promisor_objects_prepared;
21202121

21212122
if (!promisor_objects_prepared) {
2122-
if (repository_format_partial_clone) {
2123+
if (has_promisor_remote()) {
21232124
for_each_packed_object(add_promisor_object,
21242125
&promisor_objects,
21252126
FOR_EACH_OBJECT_PROMISOR_ONLY);

sha1-file.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
#include "mergesort.h"
3131
#include "quote.h"
3232
#include "packfile.h"
33-
#include "fetch-object.h"
3433
#include "object-store.h"
34+
#include "promisor-remote.h"
3535

3636
/* The maximum size for an object header. */
3737
#define MAX_HEADER_LEN 32
@@ -1369,16 +1369,17 @@ int oid_object_info_extended(struct repository *r, const struct object_id *oid,
13691369
}
13701370

13711371
/* Check if it is a missing object */
1372-
if (fetch_if_missing && repository_format_partial_clone &&
1372+
if (fetch_if_missing && has_promisor_remote() &&
13731373
!already_retried && r == the_repository &&
13741374
!(flags & OBJECT_INFO_FOR_PREFETCH)) {
13751375
/*
1376-
* TODO Investigate checking fetch_object() return
1377-
* TODO value and stopping on error here.
1378-
* TODO Pass a repository struct through fetch_object,
1379-
* such that arbitrary repositories work.
1376+
* TODO Investigate checking promisor_remote_get_direct()
1377+
* TODO return value and stopping on error here.
1378+
* TODO Pass a repository struct through
1379+
* promisor_remote_get_direct(), such that arbitrary
1380+
* repositories work.
13801381
*/
1381-
fetch_objects(repository_format_partial_clone, real, 1);
1382+
promisor_remote_get_direct(real, 1);
13821383
already_retried = 1;
13831384
continue;
13841385
}

t/t5601-clone.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,7 @@ partial_clone () {
653653
git -C client fsck &&
654654

655655
# Ensure that unneeded blobs are not inadvertently fetched.
656-
test_config -C client extensions.partialclone "not a remote" &&
656+
test_config -C client remote.origin.promisor "false" &&
657657
test_must_fail git -C client cat-file -e "$HASH1" &&
658658

659659
# But this blob was fetched, because clone performs an initial checkout

0 commit comments

Comments
 (0)