Skip to content

Commit b1240c4

Browse files
committed
Merge branch 'cc/remote-odb' into pu
* cc/remote-odb: Documentation/config: add odb.<name>.promisorRemote t0410: test fetching from many promisor remotes Use odb.origin.partialclonefilter instead of core.partialclonefilter Use remote_odb_get_direct() and has_remote_odb() remote-odb: add remote_odb_reinit() remote-odb: implement remote_odb_get_many_direct() remote-odb: implement remote_odb_get_direct() Add initial remote odb support fetch-object: make functions return an error code
2 parents 3d747bd + 2a9211c commit b1240c4

26 files changed

+342
-86
lines changed

Documentation/config.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2570,6 +2570,11 @@ This setting can be overridden with the `GIT_NOTES_REWRITE_REF`
25702570
environment variable, which must be a colon separated list of refs or
25712571
globs.
25722572

2573+
odb.<name>.promisorRemote::
2574+
The name of a promisor remote. For now promisor remotes are
2575+
the only kind of remote object database (odb) that is
2576+
supported.
2577+
25732578
pack.window::
25742579
The size of the window used by linkgit:git-pack-objects[1] when no
25752580
window size is given on the command line. Defaults to 10.

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -903,6 +903,8 @@ LIB_OBJS += notes-cache.o
903903
LIB_OBJS += notes-merge.o
904904
LIB_OBJS += notes-utils.o
905905
LIB_OBJS += object.o
906+
LIB_OBJS += odb-helper.o
907+
LIB_OBJS += remote-odb.o
906908
LIB_OBJS += oidmap.o
907909
LIB_OBJS += oidset.o
908910
LIB_OBJS += packfile.o

builtin/cat-file.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "sha1-array.h"
1515
#include "packfile.h"
1616
#include "object-store.h"
17+
#include "remote-odb.h"
1718

1819
struct batch_options {
1920
int enabled;
@@ -478,8 +479,8 @@ static int batch_objects(struct batch_options *opt)
478479

479480
for_each_loose_object(batch_loose_object, &sa, 0);
480481
for_each_packed_object(batch_packed_object, &sa, 0);
481-
if (repository_format_partial_clone)
482-
warning("This repository has extensions.partialClone set. Some objects may not be loaded.");
482+
if (has_remote_odb())
483+
warning("This repository uses an odb. Some objects may not be loaded.");
483484

484485
cb.opt = opt;
485486
cb.expand = &data;

builtin/fetch.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "utf8.h"
2323
#include "packfile.h"
2424
#include "list-objects-filter-options.h"
25+
#include "remote-odb.h"
2526

2627
static const char * const builtin_fetch_usage[] = {
2728
N_("git fetch [<options>] [<repository> [<refspec>...]]"),
@@ -1391,15 +1392,15 @@ static inline void fetch_one_setup_partial(struct remote *remote)
13911392
* If no prior partial clone/fetch and the current fetch DID NOT
13921393
* request a partial-fetch, do a normal fetch.
13931394
*/
1394-
if (!repository_format_partial_clone && !filter_options.choice)
1395+
if (!has_remote_odb() && !filter_options.choice)
13951396
return;
13961397

13971398
/*
13981399
* If this is the FIRST partial-fetch request, we enable partial
13991400
* on this repo and remember the given filter-spec as the default
14001401
* for subsequent fetches to this remote.
14011402
*/
1402-
if (!repository_format_partial_clone && filter_options.choice) {
1403+
if (!has_remote_odb() && filter_options.choice) {
14031404
partial_clone_register(remote->name, &filter_options);
14041405
return;
14051406
}
@@ -1408,7 +1409,7 @@ static inline void fetch_one_setup_partial(struct remote *remote)
14081409
* We are currently limited to only ONE promisor remote and only
14091410
* allow partial-fetches from the promisor remote.
14101411
*/
1411-
if (strcmp(remote->name, repository_format_partial_clone)) {
1412+
if (!find_odb_helper(remote->name)) {
14121413
if (filter_options.choice)
14131414
die(_("--filter can only be used with the remote configured in core.partialClone"));
14141415
return;
@@ -1420,7 +1421,7 @@ static inline void fetch_one_setup_partial(struct remote *remote)
14201421
* the config.
14211422
*/
14221423
if (!filter_options.choice)
1423-
partial_clone_get_default_filter_spec(&filter_options);
1424+
partial_clone_get_default_filter_spec(&filter_options, remote->name);
14241425
return;
14251426
}
14261427

@@ -1539,7 +1540,7 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
15391540
if (depth || deepen_since || deepen_not.nr)
15401541
deepen = 1;
15411542

1542-
if (filter_options.choice && !repository_format_partial_clone)
1543+
if (filter_options.choice && !has_remote_odb())
15431544
die("--filter can only be used when extensions.partialClone is set");
15441545

15451546
if (all) {
@@ -1573,7 +1574,7 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
15731574
}
15741575

15751576
if (remote) {
1576-
if (filter_options.choice || repository_format_partial_clone)
1577+
if (filter_options.choice || has_remote_odb())
15771578
fetch_one_setup_partial(remote);
15781579
result = fetch_one(remote, argc, argv, prune_tags_ok);
15791580
} 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 "remote-odb.h"
3031

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

@@ -623,7 +624,7 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
623624
argv_array_push(&prune, prune_expire);
624625
if (quiet)
625626
argv_array_push(&prune, "--no-progress");
626-
if (repository_format_partial_clone)
627+
if (has_remote_odb())
627628
argv_array_push(&prune,
628629
"--exclude-promisor-objects");
629630
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
@@ -8,6 +8,7 @@
88
#include "strbuf.h"
99
#include "string-list.h"
1010
#include "argv-array.h"
11+
#include "remote-odb.h"
1112

1213
static int delta_base_offset = 1;
1314
static int pack_kept_objects = -1;
@@ -249,7 +250,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
249250
argv_array_push(&cmd.args, "--all");
250251
argv_array_push(&cmd.args, "--reflog");
251252
argv_array_push(&cmd.args, "--indexed-objects");
252-
if (repository_format_partial_clone)
253+
if (has_remote_odb())
253254
argv_array_push(&cmd.args, "--exclude-promisor-objects");
254255
if (window)
255256
argv_array_pushf(&cmd.args, "--window=%s", window);

cache.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -965,13 +965,11 @@ extern int grafts_replace_parents;
965965
#define GIT_REPO_VERSION 0
966966
#define GIT_REPO_VERSION_READ 1
967967
extern int repository_format_precious_objects;
968-
extern char *repository_format_partial_clone;
969968
extern const char *core_partial_clone_filter_default;
970969

971970
struct repository_format {
972971
int version;
973972
int precious_objects;
974-
char *partial_clone; /* value of extensions.partialclone */
975973
int is_bare;
976974
int hash_algo;
977975
char *work_tree;

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 "remote-odb.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_remote_odb())
6061
argv_array_push(&rev_list.args, "--exclude-promisor-objects");
6162
if (!opt->is_deepening_fetch) {
6263
argv_array_push(&rev_list.args, "--not");

environment.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ int warn_ambiguous_refs = 1;
3030
int warn_on_object_refname_ambiguity = 1;
3131
int ref_paranoia = -1;
3232
int repository_format_precious_objects;
33-
char *repository_format_partial_clone;
3433
const char *core_partial_clone_filter_default;
3534
const char *git_commit_encoding;
3635
const char *git_log_output_encoding;

fetch-object.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
#include "transport.h"
66
#include "fetch-object.h"
77

8-
static void fetch_refs(const char *remote_name, struct ref *ref)
8+
static int fetch_refs(const char *remote_name, struct ref *ref)
99
{
1010
struct remote *remote;
1111
struct transport *transport;
1212
int original_fetch_if_missing = fetch_if_missing;
13+
int res;
1314

1415
fetch_if_missing = 0;
1516
remote = remote_get(remote_name);
@@ -19,18 +20,20 @@ static void fetch_refs(const char *remote_name, struct ref *ref)
1920

2021
transport_set_option(transport, TRANS_OPT_FROM_PROMISOR, "1");
2122
transport_set_option(transport, TRANS_OPT_NO_DEPENDENTS, "1");
22-
transport_fetch_refs(transport, ref, NULL);
23+
res = transport_fetch_refs(transport, ref, NULL);
2324
fetch_if_missing = original_fetch_if_missing;
25+
26+
return res;
2427
}
2528

26-
void fetch_object(const char *remote_name, const unsigned char *sha1)
29+
int fetch_object(const char *remote_name, const unsigned char *sha1)
2730
{
2831
struct ref *ref = alloc_ref(sha1_to_hex(sha1));
2932
hashcpy(ref->old_oid.hash, sha1);
30-
fetch_refs(remote_name, ref);
33+
return fetch_refs(remote_name, ref);
3134
}
3235

33-
void fetch_objects(const char *remote_name, const struct oid_array *to_fetch)
36+
int fetch_objects(const char *remote_name, const struct oid_array *to_fetch)
3437
{
3538
struct ref *ref = NULL;
3639
int i;
@@ -41,5 +44,5 @@ void fetch_objects(const char *remote_name, const struct oid_array *to_fetch)
4144
new_ref->next = ref;
4245
ref = new_ref;
4346
}
44-
fetch_refs(remote_name, ref);
47+
return fetch_refs(remote_name, ref);
4548
}

fetch-object.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33

44
#include "sha1-array.h"
55

6-
extern void fetch_object(const char *remote_name, const unsigned char *sha1);
6+
extern int fetch_object(const char *remote_name, const unsigned char *sha1);
77

8-
extern void fetch_objects(const char *remote_name,
9-
const struct oid_array *to_fetch);
8+
extern int fetch_objects(const char *remote_name,
9+
const struct oid_array *to_fetch);
1010

1111
#endif

list-objects-filter-options.c

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#include "list-objects.h"
77
#include "list-objects-filter.h"
88
#include "list-objects-filter-options.h"
9+
#include "remote-odb.h"
10+
#include "odb-helper.h"
911

1012
/*
1113
* Parse value of the argument to the "filter" keyword.
@@ -28,6 +30,9 @@ static int gently_parse_list_objects_filter(
2830
{
2931
const char *v0;
3032

33+
if (!arg)
34+
return 0;
35+
3136
if (filter_options->choice) {
3237
if (errbuf) {
3338
strbuf_init(errbuf, 0);
@@ -114,41 +119,43 @@ void partial_clone_register(
114119
const char *remote,
115120
const struct list_objects_filter_options *filter_options)
116121
{
117-
/*
118-
* Record the name of the partial clone remote in the
119-
* config and in the global variable -- the latter is
120-
* used throughout to indicate that partial clone is
121-
* enabled and to expect missing objects.
122-
*/
123-
if (repository_format_partial_clone &&
124-
*repository_format_partial_clone &&
125-
strcmp(remote, repository_format_partial_clone))
126-
die(_("cannot change partial clone promisor remote"));
122+
char *cfg_name;
123+
char *filter_name;
124+
125+
/* Check if it is already registered */
126+
if (find_odb_helper(remote))
127+
return;
127128

128129
git_config_set("core.repositoryformatversion", "1");
129-
git_config_set("extensions.partialclone", remote);
130130

131-
repository_format_partial_clone = xstrdup(remote);
131+
/* Add odb config for the remote */
132+
cfg_name = xstrfmt("odb.%s.promisorRemote", remote);
133+
git_config_set(cfg_name, remote);
134+
free(cfg_name);
132135

133136
/*
134137
* Record the initial filter-spec in the config as
135138
* the default for subsequent fetches from this remote.
136139
*/
137-
core_partial_clone_filter_default =
138-
xstrdup(filter_options->filter_spec);
139-
git_config_set("core.partialclonefilter",
140-
core_partial_clone_filter_default);
140+
filter_name = xstrfmt("odb.%s.partialclonefilter", remote);
141+
git_config_set(filter_name, filter_options->filter_spec);
142+
free(filter_name);
143+
144+
/* Make sure the config info are reset */
145+
remote_odb_reinit();
141146
}
142147

143148
void partial_clone_get_default_filter_spec(
144-
struct list_objects_filter_options *filter_options)
149+
struct list_objects_filter_options *filter_options,
150+
const char *remote)
145151
{
152+
struct odb_helper *helper = find_odb_helper(remote);
153+
146154
/*
147155
* Parse default value, but silently ignore it if it is invalid.
148156
*/
149-
if (!core_partial_clone_filter_default)
150-
return;
151-
gently_parse_list_objects_filter(filter_options,
152-
core_partial_clone_filter_default,
153-
NULL);
157+
if (helper)
158+
gently_parse_list_objects_filter(filter_options,
159+
helper->partial_clone_filter,
160+
NULL);
154161
}

list-objects-filter-options.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ void partial_clone_register(
7474
const char *remote,
7575
const struct list_objects_filter_options *filter_options);
7676
void partial_clone_get_default_filter_spec(
77-
struct list_objects_filter_options *filter_options);
77+
struct list_objects_filter_options *filter_options,
78+
const char *remote);
7879

7980
#endif /* LIST_OBJECTS_FILTER_OPTIONS_H */

odb-helper.c

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#include "cache.h"
2+
#include "object.h"
3+
#include "argv-array.h"
4+
#include "odb-helper.h"
5+
#include "run-command.h"
6+
#include "sha1-lookup.h"
7+
#include "fetch-object.h"
8+
9+
struct odb_helper *odb_helper_new(const char *name, int namelen)
10+
{
11+
struct odb_helper *o;
12+
13+
o = xcalloc(1, sizeof(*o));
14+
o->name = xmemdupz(name, namelen);
15+
16+
return o;
17+
}
18+
19+
int odb_helper_get_direct(struct odb_helper *o,
20+
const unsigned char *sha1)
21+
{
22+
int res;
23+
uint64_t start = getnanotime();
24+
25+
res = fetch_object(o->remote, sha1);
26+
27+
trace_performance_since(start, "odb_helper_get_direct");
28+
29+
return res;
30+
}
31+
32+
int odb_helper_get_many_direct(struct odb_helper *o,
33+
const struct oid_array *to_get)
34+
{
35+
int res;
36+
uint64_t start;
37+
38+
start = getnanotime();
39+
40+
res = fetch_objects(o->remote, to_get);
41+
42+
trace_performance_since(start, "odb_helper_get_many_direct");
43+
44+
return res;
45+
}

odb-helper.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#ifndef ODB_HELPER_H
2+
#define ODB_HELPER_H
3+
4+
/*
5+
* An odb helper is a way to access a remote odb.
6+
*
7+
* Information in its fields comes from the config file [odb "NAME"]
8+
* entries.
9+
*/
10+
struct odb_helper {
11+
const char *name; /* odb.<NAME>.* */
12+
const char *remote; /* odb.<NAME>.promisorRemote */
13+
const char *partial_clone_filter; /* odb.<NAME>.partialCloneFilter */
14+
15+
struct odb_helper *next;
16+
};
17+
18+
extern struct odb_helper *odb_helper_new(const char *name, int namelen);
19+
extern int odb_helper_get_direct(struct odb_helper *o,
20+
const unsigned char *sha1);
21+
extern int odb_helper_get_many_direct(struct odb_helper *o,
22+
const struct oid_array *to_get);
23+
24+
#endif /* ODB_HELPER_H */

0 commit comments

Comments
 (0)