Skip to content

Commit e3e8bf0

Browse files
jonathantanmygitster
authored andcommitted
submodule-config: pass repo upon blob config read
When reading the config of a submodule, if reading from a blob, read using an explicitly specified repository instead of by adding the submodule's ODB as an alternate and then reading an object from the_repository. This makes the "grep --recurse-submodules with submodules without .gitmodules in the working tree" test in t7814 work when GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB is true. Signed-off-by: Jonathan Tan <[email protected]> Reviewed-by: Matheus Tavares <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0693806 commit e3e8bf0

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

config.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1796,6 +1796,7 @@ int git_config_from_mem(config_fn_t fn,
17961796

17971797
int git_config_from_blob_oid(config_fn_t fn,
17981798
const char *name,
1799+
struct repository *repo,
17991800
const struct object_id *oid,
18001801
void *data)
18011802
{
@@ -1804,7 +1805,7 @@ int git_config_from_blob_oid(config_fn_t fn,
18041805
unsigned long size;
18051806
int ret;
18061807

1807-
buf = read_object_file(oid, &type, &size);
1808+
buf = repo_read_object_file(repo, oid, &type, &size);
18081809
if (!buf)
18091810
return error(_("unable to load config blob object '%s'"), name);
18101811
if (type != OBJ_BLOB) {
@@ -1820,14 +1821,15 @@ int git_config_from_blob_oid(config_fn_t fn,
18201821
}
18211822

18221823
static int git_config_from_blob_ref(config_fn_t fn,
1824+
struct repository *repo,
18231825
const char *name,
18241826
void *data)
18251827
{
18261828
struct object_id oid;
18271829

1828-
if (get_oid(name, &oid) < 0)
1830+
if (repo_get_oid(repo, name, &oid) < 0)
18291831
return error(_("unable to resolve config blob '%s'"), name);
1830-
return git_config_from_blob_oid(fn, name, &oid, data);
1832+
return git_config_from_blob_oid(fn, name, repo, &oid, data);
18311833
}
18321834

18331835
char *git_system_config(void)
@@ -1958,12 +1960,16 @@ int config_with_options(config_fn_t fn, void *data,
19581960
* If we have a specific filename, use it. Otherwise, follow the
19591961
* regular lookup sequence.
19601962
*/
1961-
if (config_source && config_source->use_stdin)
1963+
if (config_source && config_source->use_stdin) {
19621964
return git_config_from_stdin(fn, data);
1963-
else if (config_source && config_source->file)
1965+
} else if (config_source && config_source->file) {
19641966
return git_config_from_file(fn, config_source->file, data);
1965-
else if (config_source && config_source->blob)
1966-
return git_config_from_blob_ref(fn, config_source->blob, data);
1967+
} else if (config_source && config_source->blob) {
1968+
struct repository *repo = config_source->repo ?
1969+
config_source->repo : the_repository;
1970+
return git_config_from_blob_ref(fn, repo, config_source->blob,
1971+
data);
1972+
}
19671973

19681974
return do_git_config_sequence(opts, fn, data);
19691975
}

config.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ const char *config_scope_name(enum config_scope scope);
4949
struct git_config_source {
5050
unsigned int use_stdin:1;
5151
const char *file;
52+
/* The repository if blob is not NULL; leave blank for the_repository */
53+
struct repository *repo;
5254
const char *blob;
5355
enum config_scope scope;
5456
};
@@ -136,6 +138,7 @@ int git_config_from_mem(config_fn_t fn,
136138
const char *buf, size_t len,
137139
void *data, const struct config_options *opts);
138140
int git_config_from_blob_oid(config_fn_t fn, const char *name,
141+
struct repository *repo,
139142
const struct object_id *oid, void *data);
140143
void git_config_push_parameter(const char *text);
141144
void git_config_push_env(const char *spec);

submodule-config.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -649,9 +649,10 @@ static void config_from_gitmodules(config_fn_t fn, struct repository *repo, void
649649
config_source.file = file;
650650
} else if (repo_get_oid(repo, GITMODULES_INDEX, &oid) >= 0 ||
651651
repo_get_oid(repo, GITMODULES_HEAD, &oid) >= 0) {
652+
config_source.repo = repo;
652653
config_source.blob = oidstr = xstrdup(oid_to_hex(&oid));
653654
if (repo != the_repository)
654-
add_to_alternates_memory(repo->objects->odb->path);
655+
add_submodule_odb_by_path(repo->objects->odb->path);
655656
} else {
656657
goto out;
657658
}
@@ -702,7 +703,7 @@ void gitmodules_config_oid(const struct object_id *commit_oid)
702703

703704
if (gitmodule_oid_from_commit(commit_oid, &oid, &rev)) {
704705
git_config_from_blob_oid(gitmodules_cb, rev.buf,
705-
&oid, the_repository);
706+
the_repository, &oid, the_repository);
706707
}
707708
strbuf_release(&rev);
708709

0 commit comments

Comments
 (0)