Skip to content

Commit ee0f2f6

Browse files
committed
Merge branch 'ps/odb-stop-registering-in-memory-sources' into jch
The mechanism to register in-memory alternate object sources has been removed, as submodule object databases are now accessed natively via their own repository structures. This simplifies object database management and prepares the codebase for migrating alternate tracking into the files backend. * ps/odb-stop-registering-in-memory-sources: odb: remove the ability to link sources ad-hoc t/helper: stop registering alternates in "ref-store" command t/helper: adapt read-midx to not link ad-hoc source anymore builtin/multi-pack-index: refuse unknown sources with "--object-dir=" odb/packed: fix memory leaks when freeing source tmp-objdir: drop unused function to register alternate odb: remove infrastructure to register submodule sources builtin/grep: stop registering submodule ODB as source submodule-config: stop registering submodule sources submodule-config: stop using `the_hash_algo` submodule-config: remove uses of `the_repository` cache-tree: remove dependency on `the_repository` cache-tree: drop `the_repository` in `cache_tree_fully_valid()`
2 parents 752a530 + 1bb7f1a commit ee0f2f6

33 files changed

Lines changed: 168 additions & 247 deletions

‎builtin/checkout.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -921,7 +921,7 @@ static int merge_working_tree(const struct checkout_opts *opts,
921921
}
922922
}
923923

924-
if (!cache_tree_fully_valid(the_repository->index->cache_tree))
924+
if (!cache_tree_fully_valid(the_repository->index))
925925
cache_tree_update(the_repository->index, WRITE_TREE_SILENT | WRITE_TREE_REPAIR);
926926

927927
if (write_locked_index(the_repository->index, &lock_file, COMMIT_LOCK))

‎builtin/commit.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ static const char *prepare_index(const char **argv, const char *prefix,
484484
LOCK_DIE_ON_ERROR);
485485
refresh_cache_or_die(refresh_flags);
486486
if (the_repository->index->cache_changed
487-
|| !cache_tree_fully_valid(the_repository->index->cache_tree))
487+
|| !cache_tree_fully_valid(the_repository->index))
488488
cache_tree_update(the_repository->index, WRITE_TREE_SILENT);
489489
if (write_locked_index(the_repository->index, &index_lock,
490490
COMMIT_LOCK | SKIP_IF_UNCHANGED))

‎builtin/fetch.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2681,7 +2681,7 @@ int cmd_fetch(int argc,
26812681
int *rs = config.recurse_submodules == RECURSE_SUBMODULES_DEFAULT
26822682
? &config.recurse_submodules : NULL;
26832683

2684-
fetch_config_from_gitmodules(sfjc, rs);
2684+
fetch_config_from_gitmodules(the_repository, sfjc, rs);
26852685
}
26862686

26872687

‎builtin/grep.c‎

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -463,16 +463,6 @@ static int grep_submodule(struct grep_opt *opt,
463463
ALLOC_GROW(repos_to_free, repos_to_free_nr + 1, repos_to_free_alloc);
464464
repos_to_free[repos_to_free_nr++] = subrepo;
465465

466-
/*
467-
* NEEDSWORK: repo_read_gitmodules() might call
468-
* odb_add_to_alternates_memory() via config_from_gitmodules(). This
469-
* operation causes a race condition with concurrent object readings
470-
* performed by the worker threads. That's why we need obj_read_lock()
471-
* here. It should be removed once it's no longer necessary to add the
472-
* subrepo's odbs to the in-memory alternates list.
473-
*/
474-
obj_read_lock();
475-
476466
/*
477467
* NEEDSWORK: when reading a submodule, the sparsity settings in the
478468
* superproject are incorrectly forgotten or misused. For example:
@@ -498,18 +488,14 @@ static int grep_submodule(struct grep_opt *opt,
498488
* ditto.
499489
*
500490
* Note that this list is not exhaustive.
491+
*
492+
* NEEDSWORK: initializing the subrepository is not thread-safe,
493+
* either, as it may cause us to race around `get_main_ref_store()`. We
494+
* thus need to hold the object-read lock to serialize all readers with
495+
* one another.
501496
*/
497+
obj_read_lock();
502498
repo_read_gitmodules(subrepo, 0);
503-
504-
/*
505-
* All code paths tested by test code no longer need submodule ODBs to
506-
* be added as alternates, but add it to the list just in case.
507-
* Submodule ODBs added through add_submodule_odb_by_path() will be
508-
* lazily registered as alternates when needed (and except in an
509-
* unexpected code interaction, it won't be needed).
510-
*/
511-
odb_add_submodule_source_by_path(the_repository->objects,
512-
subrepo->objects->sources->path);
513499
obj_read_unlock();
514500

515501
memcpy(&subopt, opt, sizeof(subopt));
@@ -897,7 +883,7 @@ static int grep_objects(struct grep_opt *opt, const struct pathspec *pathspec,
897883
if (recurse_submodules) {
898884
submodule_free(opt->repo);
899885
obj_read_lock();
900-
gitmodules_config_oid(&real_obj->oid);
886+
gitmodules_config_oid(the_repository, &real_obj->oid);
901887
obj_read_unlock();
902888
}
903889
if (grep_object(opt, pathspec, real_obj, list->objects[i].name,

‎builtin/multi-pack-index.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ static struct odb_source_files *handle_object_dir_option(struct repository *repo
9090
{
9191
struct odb_source *source = odb_find_source(repo->objects, opts.object_dir);
9292
if (!source)
93-
source = odb_add_to_alternates_memory(repo->objects, opts.object_dir);
93+
die(_("object directory is not an alternate of the current repository: '%s'"),
94+
opts.object_dir);
9495
return odb_source_files_downcast(source);
9596
}
9697

‎builtin/submodule--helper.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3045,7 +3045,7 @@ static int module_update(int argc, const char **argv, const char *prefix,
30453045
NULL
30463046
};
30473047

3048-
update_clone_config_from_gitmodules(&opt.max_jobs);
3048+
update_clone_config_from_gitmodules(the_repository, &opt.max_jobs);
30493049
repo_config(the_repository, git_update_clone_config, &opt.max_jobs);
30503050

30513051
argc = parse_options(argc, argv, prefix, module_update_options,
@@ -3259,7 +3259,7 @@ static int module_set_url(int argc, const char **argv, const char *prefix,
32593259
path);
32603260

32613261
config_name = xstrfmt("submodule.%s.url", sub->name);
3262-
ret = config_set_in_gitmodules_file_gently(config_name, newurl);
3262+
ret = config_set_in_gitmodules_file_gently(the_repository, config_name, newurl);
32633263

32643264
if (!ret) {
32653265
repo_read_gitmodules(the_repository, 0);
@@ -3315,7 +3315,7 @@ static int module_set_branch(int argc, const char **argv, const char *prefix,
33153315
path);
33163316

33173317
config_name = xstrfmt("submodule.%s.branch", sub->name);
3318-
ret = config_set_in_gitmodules_file_gently(config_name, opt_branch);
3318+
ret = config_set_in_gitmodules_file_gently(the_repository, config_name, opt_branch);
33193319

33203320
free(config_name);
33213321
return !!ret;
@@ -3515,7 +3515,7 @@ static int config_submodule_in_gitmodules(const char *name, const char *var, con
35153515
die(_("please make sure that the .gitmodules file is in the working tree"));
35163516

35173517
key = xstrfmt("submodule.%s.%s", name, var);
3518-
ret = config_set_in_gitmodules_file_gently(key, value);
3518+
ret = config_set_in_gitmodules_file_gently(the_repository, key, value);
35193519
free(key);
35203520

35213521
return ret;

0 commit comments

Comments
 (0)