Skip to content

Commit cdb89a8

Browse files
KarthikNayakgitster
authored andcommitted
refs: allow reference location in refstorage config
The 'extensions.refStorage' config is used to specify the reference backend for a given repository. Both the 'files' and 'reftable' backends utilize the $GIT_DIR as the reference folder by default in `get_main_ref_store()`. Since the reference backends are pluggable, this means that they should work with out-of-tree reference directories too. Extend the 'refStorage' config to also support taking an URI input, where users can specify the reference backend and the location. Add the required changes to obtain and propagate this value to the individual backends. A follow up commit will add the required changes on the backends to parse this value. Helped-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Karthik Nayak <karthik.188@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 67ad421 commit cdb89a8

5 files changed

Lines changed: 49 additions & 9 deletions

File tree

builtin/clone.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1442,7 +1442,8 @@ int cmd_clone(int argc,
14421442
hash_algo = hash_algo_by_ptr(transport_get_hash_algo(transport));
14431443
initialize_repository_version(hash_algo, the_repository->ref_storage_format, 1);
14441444
repo_set_hash_algo(the_repository, hash_algo);
1445-
create_reference_database(the_repository->ref_storage_format, NULL, 1);
1445+
create_reference_database(the_repository->ref_storage_format,
1446+
the_repository->ref_storage_payload, NULL, 1);
14461447

14471448
/*
14481449
* Before fetching from the remote, download and install bundle

repository.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,12 @@ void repo_set_compat_hash_algo(struct repository *repo, int algo)
193193
}
194194

195195
void repo_set_ref_storage_format(struct repository *repo,
196-
enum ref_storage_format format)
196+
enum ref_storage_format format,
197+
const char *payload)
197198
{
198199
repo->ref_storage_format = format;
200+
free(repo->ref_storage_payload);
201+
repo->ref_storage_payload = xstrdup_or_null(payload);
199202
}
200203

201204
/*
@@ -277,7 +280,8 @@ int repo_init(struct repository *repo,
277280

278281
repo_set_hash_algo(repo, format.hash_algo);
279282
repo_set_compat_hash_algo(repo, format.compat_hash_algo);
280-
repo_set_ref_storage_format(repo, format.ref_storage_format);
283+
repo_set_ref_storage_format(repo, format.ref_storage_format,
284+
format.ref_storage_payload);
281285
repo->repository_format_worktree_config = format.worktree_config;
282286
repo->repository_format_relative_worktrees = format.relative_worktrees;
283287
repo->repository_format_precious_objects = format.precious_objects;
@@ -369,6 +373,7 @@ void repo_clear(struct repository *repo)
369373
FREE_AND_NULL(repo->index_file);
370374
FREE_AND_NULL(repo->worktree);
371375
FREE_AND_NULL(repo->submodule_prefix);
376+
FREE_AND_NULL(repo->ref_storage_payload);
372377

373378
odb_free(repo->objects);
374379
repo->objects = NULL;

repository.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ struct repository {
150150

151151
/* Repository's reference storage format, as serialized on disk. */
152152
enum ref_storage_format ref_storage_format;
153+
/* Reference storage information as needed for the backend. */
154+
char *ref_storage_payload;
153155

154156
/* A unique-id for tracing purposes. */
155157
int trace2_repo_id;
@@ -204,7 +206,8 @@ void repo_set_worktree(struct repository *repo, const char *path);
204206
void repo_set_hash_algo(struct repository *repo, int algo);
205207
void repo_set_compat_hash_algo(struct repository *repo, int compat_algo);
206208
void repo_set_ref_storage_format(struct repository *repo,
207-
enum ref_storage_format format);
209+
enum ref_storage_format format,
210+
const char *payload);
208211
void initialize_repository(struct repository *repo);
209212
RESULT_MUST_BE_USED
210213
int repo_init(struct repository *r, const char *gitdir, const char *worktree);

setup.c

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,21 @@ static enum extension_result handle_extension_v0(const char *var,
632632
return EXTENSION_UNKNOWN;
633633
}
634634

635+
static void parse_reference_uri(const char *value, char **format,
636+
char **payload)
637+
{
638+
char *schema_end;
639+
640+
schema_end = strstr(value, "://");
641+
if (!schema_end) {
642+
*format = xstrdup(value);
643+
*payload = NULL;
644+
} else {
645+
*format = xstrndup(value, schema_end - value);
646+
*payload = xstrdup_or_null(schema_end + 3);
647+
}
648+
}
649+
635650
/*
636651
* Record any new extensions in this function.
637652
*/
@@ -674,10 +689,17 @@ static enum extension_result handle_extension(const char *var,
674689
return EXTENSION_OK;
675690
} else if (!strcmp(ext, "refstorage")) {
676691
unsigned int format;
692+
char *format_str;
677693

678694
if (!value)
679695
return config_error_nonbool(var);
680-
format = ref_storage_format_by_name(value);
696+
697+
parse_reference_uri(value, &format_str,
698+
&data->ref_storage_payload);
699+
700+
format = ref_storage_format_by_name(format_str);
701+
free(format_str);
702+
681703
if (format == REF_STORAGE_FORMAT_UNKNOWN)
682704
return error(_("invalid value for '%s': '%s'"),
683705
"extensions.refstorage", value);
@@ -850,6 +872,7 @@ void clear_repository_format(struct repository_format *format)
850872
string_list_clear(&format->v1_only_extensions, 0);
851873
free(format->work_tree);
852874
free(format->partial_clone);
875+
free(format->ref_storage_payload);
853876
init_repository_format(format);
854877
}
855878

@@ -1942,7 +1965,8 @@ const char *setup_git_directory_gently(int *nongit_ok)
19421965
repo_set_compat_hash_algo(the_repository,
19431966
repo_fmt.compat_hash_algo);
19441967
repo_set_ref_storage_format(the_repository,
1945-
repo_fmt.ref_storage_format);
1968+
repo_fmt.ref_storage_format,
1969+
repo_fmt.ref_storage_payload);
19461970
the_repository->repository_format_worktree_config =
19471971
repo_fmt.worktree_config;
19481972
the_repository->repository_format_relative_worktrees =
@@ -2042,7 +2066,8 @@ void check_repository_format(struct repository_format *fmt)
20422066
repo_set_hash_algo(the_repository, fmt->hash_algo);
20432067
repo_set_compat_hash_algo(the_repository, fmt->compat_hash_algo);
20442068
repo_set_ref_storage_format(the_repository,
2045-
fmt->ref_storage_format);
2069+
fmt->ref_storage_format,
2070+
fmt->ref_storage_payload);
20462071
the_repository->repository_format_worktree_config =
20472072
fmt->worktree_config;
20482073
the_repository->repository_format_relative_worktrees =
@@ -2360,13 +2385,15 @@ static int is_reinit(void)
23602385
}
23612386

23622387
void create_reference_database(enum ref_storage_format ref_storage_format,
2388+
const char *ref_storage_payload,
23632389
const char *initial_branch, int quiet)
23642390
{
23652391
struct strbuf err = STRBUF_INIT;
23662392
char *to_free = NULL;
23672393
int reinit = is_reinit();
23682394

2369-
repo_set_ref_storage_format(the_repository, ref_storage_format);
2395+
repo_set_ref_storage_format(the_repository, ref_storage_format,
2396+
ref_storage_payload);
23702397
if (ref_store_create_on_disk(get_main_ref_store(the_repository), 0, &err))
23712398
die("failed to set up refs db: %s", err.buf);
23722399

@@ -2645,7 +2672,8 @@ static void repository_format_configure(struct repository_format *repo_fmt,
26452672
} else {
26462673
repo_fmt->ref_storage_format = REF_STORAGE_FORMAT_DEFAULT;
26472674
}
2648-
repo_set_ref_storage_format(the_repository, repo_fmt->ref_storage_format);
2675+
repo_set_ref_storage_format(the_repository, repo_fmt->ref_storage_format,
2676+
repo_fmt->ref_storage_payload);
26492677
}
26502678

26512679
int init_db(const char *git_dir, const char *real_git_dir,
@@ -2702,6 +2730,7 @@ int init_db(const char *git_dir, const char *real_git_dir,
27022730

27032731
if (!(flags & INIT_DB_SKIP_REFDB))
27042732
create_reference_database(repo_fmt.ref_storage_format,
2733+
repo_fmt.ref_storage_payload,
27052734
initial_branch, flags & INIT_DB_QUIET);
27062735
create_object_directory();
27072736

setup.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ struct repository_format {
171171
int hash_algo;
172172
int compat_hash_algo;
173173
enum ref_storage_format ref_storage_format;
174+
char *ref_storage_payload;
174175
int sparse_index;
175176
char *work_tree;
176177
struct string_list unknown_extensions;
@@ -241,6 +242,7 @@ void initialize_repository_version(int hash_algo,
241242
enum ref_storage_format ref_storage_format,
242243
int reinit);
243244
void create_reference_database(enum ref_storage_format ref_storage_format,
245+
const char *ref_storage_payload,
244246
const char *initial_branch, int quiet);
245247

246248
/*

0 commit comments

Comments
 (0)