Skip to content

Commit b14ed5a

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 faf2abf commit b14ed5a

14 files changed

+56
-47
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

@@ -661,7 +662,7 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
661662
argv_array_push(&prune, prune_expire);
662663
if (quiet)
663664
argv_array_push(&prune, "--no-progress");
664-
if (repository_format_partial_clone)
665+
if (has_promisor_remote())
665666
argv_array_push(&prune,
666667
"--exclude-promisor-objects");
667668
if (run_command_v_opt(prune.argv, RUN_GIT_CMD))

builtin/index-pack.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#include "thread-utils.h"
1515
#include "packfile.h"
1616
#include "object-store.h"
17-
#include "fetch-object.h"
17+
#include "promisor-remote.h"
1818

1919
static const char index_pack_usage[] =
2020
"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)
13521352
sorted_by_pos[i] = &ref_deltas[i];
13531353
QSORT(sorted_by_pos, nr_ref_deltas, delta_pos_compare);
13541354

1355-
if (repository_format_partial_clone) {
1355+
if (has_promisor_remote()) {
13561356
/*
13571357
* Prefetch the delta bases.
13581358
*/
@@ -1366,8 +1366,8 @@ static void fix_unresolved_deltas(struct hashfile *f)
13661366
oid_array_append(&to_fetch, &d->oid);
13671367
}
13681368
if (to_fetch.nr)
1369-
fetch_objects(repository_format_partial_clone,
1370-
to_fetch.oid, to_fetch.nr);
1369+
promisor_remote_get_direct(the_repository,
1370+
to_fetch.oid, to_fetch.nr);
13711371
oid_array_clear(&to_fetch);
13721372
}
13731373

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;
@@ -369,7 +370,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
369370
argv_array_push(&cmd.args, "--all");
370371
argv_array_push(&cmd.args, "--reflog");
371372
argv_array_push(&cmd.args, "--indexed-objects");
372-
if (repository_format_partial_clone)
373+
if (has_promisor_remote())
373374
argv_array_push(&cmd.args, "--exclude-promisor-objects");
374375
if (write_bitmaps)
375376
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
@@ -5,6 +5,7 @@
55
#include "connected.h"
66
#include "transport.h"
77
#include "packfile.h"
8+
#include "promisor-remote.h"
89

910
/*
1011
* 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,
7374
argv_array_push(&rev_list.args,"rev-list");
7475
argv_array_push(&rev_list.args, "--objects");
7576
argv_array_push(&rev_list.args, "--stdin");
76-
if (repository_format_partial_clone)
77+
if (has_promisor_remote())
7778
argv_array_push(&rev_list.args, "--exclude-promisor-objects");
7879
if (!opt->is_deepening_fetch) {
7980
argv_array_push(&rev_list.args, "--not");

diff.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#include "packfile.h"
2626
#include "parse-options.h"
2727
#include "help.h"
28-
#include "fetch-object.h"
28+
#include "promisor-remote.h"
2929

3030
#ifdef NO_FAST_WORKING_DIRECTORY
3131
#define FAST_WORKING_DIRECTORY 0
@@ -6514,8 +6514,7 @@ static void add_if_missing(struct repository *r,
65146514

65156515
void diffcore_std(struct diff_options *options)
65166516
{
6517-
if (options->repo == the_repository &&
6518-
repository_format_partial_clone) {
6517+
if (options->repo == the_repository && has_promisor_remote()) {
65196518
/*
65206519
* Prefetch the diff pairs that are about to be flushed.
65216520
*/
@@ -6532,8 +6531,8 @@ void diffcore_std(struct diff_options *options)
65326531
/*
65336532
* NEEDSWORK: Consider deduplicating the OIDs sent.
65346533
*/
6535-
fetch_objects(repository_format_partial_clone,
6536-
to_fetch.oid, to_fetch.nr);
6534+
promisor_remote_get_direct(options->repo,
6535+
to_fetch.oid, to_fetch.nr);
65376536
oid_array_clear(&to_fetch);
65386537
}
65396538

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.
@@ -146,30 +147,31 @@ void partial_clone_register(
146147
const char *remote,
147148
const struct list_objects_filter_options *filter_options)
148149
{
149-
/*
150-
* Record the name of the partial clone remote in the
151-
* config and in the global variable -- the latter is
152-
* used throughout to indicate that partial clone is
153-
* enabled and to expect missing objects.
154-
*/
155-
if (repository_format_partial_clone &&
156-
*repository_format_partial_clone &&
157-
strcmp(remote, repository_format_partial_clone))
158-
die(_("cannot change partial clone promisor remote"));
150+
char *cfg_name;
159151

160-
git_config_set("core.repositoryformatversion", "1");
161-
git_config_set("extensions.partialclone", remote);
152+
/* Check if it is already registered */
153+
if (!promisor_remote_find(remote)) {
154+
git_config_set("core.repositoryformatversion", "1");
162155

163-
repository_format_partial_clone = xstrdup(remote);
156+
/* Add promisor config for the remote */
157+
cfg_name = xstrfmt("remote.%s.promisor", remote);
158+
git_config_set(cfg_name, "true");
159+
free(cfg_name);
160+
}
164161

165162
/*
166163
* Record the initial filter-spec in the config as
167164
* the default for subsequent fetches from this remote.
165+
*
166+
* TODO: record it into remote.<name>.partialclonefilter
168167
*/
169168
core_partial_clone_filter_default =
170169
xstrdup(filter_options->filter_spec);
171170
git_config_set("core.partialclonefilter",
172171
core_partial_clone_filter_default);
172+
173+
/* Make sure the config info are reset */
174+
promisor_remote_reinit();
173175
}
174176

175177
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);

0 commit comments

Comments
 (0)