fetch: skip on-demand checking when no submodules are configured

It makes no sense to do the - possibly very expensive - call to "rev-list <new-ref-sha1> --not --all" in check_for_new_submodule_commits() when there aren't any submodules configured. Leave check_for_new_submodule_commits() early when no name <-> path mappings for submodules are found in the configuration. To make that work reading the configuration had to be moved further up in cmd_fetch(), as doing that after the actual fetch of the superproject was too late. Reported-by: Martin Fick <mfick@codeaurora.org> Signed-off-by: Jens Lehmann <Jens.Lehmann@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jens Lehmann committed Sep 9, 2011 at 20:22 UTC 18322badc2b3b7f49f79da5273e003e9c0c4f549
2 files changed +13 -6
builtin/fetch.c
+9 -6
@@ -941,6 +941,15 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
941 argc = parse_options(argc, argv, prefix,
942 builtin_fetch_options, builtin_fetch_usage, 0);
943
944 + if (recurse_submodules != RECURSE_SUBMODULES_OFF) {
945 + if (recurse_submodules_default) {
946 + int arg = parse_fetch_recurse_submodules_arg("--recurse-submodules-default", recurse_submodules_default);
947 + set_config_fetch_recurse_submodules(arg);
948 + }
949 + gitmodules_config();
950 + git_config(submodule_config, NULL);
951 + }
952 +
953 if (all) {
954 if (argc == 1)
955 die(_("fetch --all does not take a repository argument"));
@@ -976,12 +985,6 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
985 if (!result && (recurse_submodules != RECURSE_SUBMODULES_OFF)) {
986 const char *options[10];
987 int num_options = 0;
979 - if (recurse_submodules_default) {
980 - int arg = parse_fetch_recurse_submodules_arg("--recurse-submodules-default", recurse_submodules_default);
981 - set_config_fetch_recurse_submodules(arg);
982 - }
983 - gitmodules_config();
984 - git_config(submodule_config, NULL);
988 add_options_to_argv(&num_options, options);
989 result = fetch_populated_submodules(num_options, options,
990 submodule_prefix,
submodule.c
+4
@@ -373,6 +373,10 @@ void check_for_new_submodule_commits(unsigned char new_sha1[20])
373 const char *argv[] = {NULL, NULL, "--not", "--all", NULL};
374 int argc = ARRAY_SIZE(argv) - 1;
375
376 + /* No need to check if there are no submodules configured */
377 + if (!config_name_for_path.nr)
378 + return;
379 +
380 init_revisions(&rev, NULL);
381 argv[1] = xstrdup(sha1_to_hex(new_sha1));
382 setup_revisions(argc, argv, &rev, NULL);