Skip to content

Commit d9b8b8f

Browse files
pcloudsgitster
authored andcommitted
submodule-config.c: use repo_get_oid for reading .gitmodules
Since 76e9bdc (submodule: support reading .gitmodules when it's not in the working tree - 2018-10-25), every time you do git grep --recurse-submodules you are likely to see one warning line per submodule (unless all those submodules also have submodules). On a superproject with plenty of submodules (I've seen one with 67) this is really annoying. The warning was there because we could not resolve extended SHA-1 syntax on a submodule. We can now. Make use of the new API and get rid of the warning. It would be even better if config_with_options() supports multiple repositories too. But one step at a time. Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ec580ea commit d9b8b8f

File tree

2 files changed

+8
-18
lines changed

2 files changed

+8
-18
lines changed

submodule-config.c

+7-13
Original file line numberDiff line numberDiff line change
@@ -625,30 +625,24 @@ static void config_from_gitmodules(config_fn_t fn, struct repository *repo, void
625625
const struct config_options opts = { 0 };
626626
struct object_id oid;
627627
char *file;
628+
char *oidstr = NULL;
628629

629630
file = repo_worktree_path(repo, GITMODULES_FILE);
630631
if (file_exists(file)) {
631632
config_source.file = file;
632-
} else if (repo->submodule_prefix) {
633-
/*
634-
* When get_oid and config_with_options, used below,
635-
* become able to work on a specific repository, this
636-
* warning branch can be removed.
637-
*/
638-
warning("nested submodules without %s in the working tree are not supported yet",
639-
GITMODULES_FILE);
640-
goto out;
641-
} else if (get_oid(GITMODULES_INDEX, &oid) >= 0) {
642-
config_source.blob = GITMODULES_INDEX;
643-
} else if (get_oid(GITMODULES_HEAD, &oid) >= 0) {
644-
config_source.blob = GITMODULES_HEAD;
633+
} else if (repo_get_oid(repo, GITMODULES_INDEX, &oid) >= 0 ||
634+
repo_get_oid(repo, GITMODULES_HEAD, &oid) >= 0) {
635+
config_source.blob = oidstr = xstrdup(oid_to_hex(&oid));
636+
if (repo != the_repository)
637+
add_to_alternates_memory(repo->objects->odb->path);
645638
} else {
646639
goto out;
647640
}
648641

649642
config_with_options(fn, data, &config_source, &opts);
650643

651644
out:
645+
free(oidstr);
652646
free(file);
653647
}
654648
}

t/t7814-grep-recurse-submodules.sh

+1-5
Original file line numberDiff line numberDiff line change
@@ -380,11 +380,7 @@ test_expect_success 'grep --recurse-submodules should pass the pattern type alon
380380
fi
381381
'
382382

383-
# Recursing down into nested submodules which do not have .gitmodules in their
384-
# working tree does not work yet. This is because config_from_gitmodules()
385-
# uses get_oid() and the latter is still not able to get objects from an
386-
# arbitrary repository (the nested submodule, in this case).
387-
test_expect_failure 'grep --recurse-submodules with submodules without .gitmodules in the working tree' '
383+
test_expect_success 'grep --recurse-submodules with submodules without .gitmodules in the working tree' '
388384
test_when_finished "git -C submodule checkout .gitmodules" &&
389385
rm submodule/.gitmodules &&
390386
git grep --recurse-submodules -e "(.|.)[\d]" >actual &&

0 commit comments

Comments
 (0)