]> git.ipfire.org Git - thirdparty/git.git/blobdiff - builtin/submodule--helper.c
Merge branch 'ms/submodule-foreach-fix' into maint
[thirdparty/git.git] / builtin / submodule--helper.c
index 61a5bfb1f2be0e3e31ffe99987dc3bff4b055ee6..afaf0819c981ff896bf6f0b843b594a660d85a97 100644 (file)
@@ -1,3 +1,4 @@
+#define USE_THE_INDEX_COMPATIBILITY_MACROS
 #include "builtin.h"
 #include "repository.h"
 #include "cache.h"
@@ -347,7 +348,7 @@ static int module_list_compute(int argc, const char **argv,
                        i++;
        }
 
-       if (ps_matched && report_path_error(ps_matched, pathspec, prefix))
+       if (ps_matched && report_path_error(ps_matched, pathspec))
                result = -1;
 
        free(ps_matched);
@@ -566,12 +567,12 @@ static int module_foreach(int argc, const char **argv, const char *prefix)
        };
 
        const char *const git_submodule_helper_usage[] = {
-               N_("git submodule--helper foreach [--quiet] [--recursive] <command>"),
+               N_("git submodule--helper foreach [--quiet] [--recursive] [--] <command>"),
                NULL
        };
 
        argc = parse_options(argc, argv, prefix, module_foreach_options,
-                            git_submodule_helper_usage, PARSE_OPT_KEEP_UNKNOWN);
+                            git_submodule_helper_usage, 0);
 
        if (module_list_compute(0, NULL, prefix, &pathspec, &list) < 0)
                return 1;
@@ -709,7 +710,7 @@ static int module_init(int argc, const char **argv, const char *prefix)
        };
 
        const char *const git_submodule_helper_usage[] = {
-               N_("git submodule--helper init [<path>]"),
+               N_("git submodule--helper init [<options>] [<path>]"),
                NULL
        };
 
@@ -1132,6 +1133,8 @@ static void deinit_submodule(const char *path, const char *prefix,
                if (!(flags & OPT_QUIET))
                        printf(format, displaypath);
 
+               submodule_unset_core_worktree(sub);
+
                strbuf_release(&sb_rm);
        }
 
@@ -1266,19 +1269,20 @@ struct submodule_alternate_setup {
        SUBMODULE_ALTERNATE_ERROR_IGNORE, NULL }
 
 static int add_possible_reference_from_superproject(
-               struct alternate_object_database *alt, void *sas_cb)
+               struct object_directory *odb, void *sas_cb)
 {
        struct submodule_alternate_setup *sas = sas_cb;
+       size_t len;
 
        /*
         * If the alternate object store is another repository, try the
         * standard layout with .git/(modules/<name>)+/objects
         */
-       if (ends_with(alt->path, "/objects")) {
+       if (strip_suffix(odb->path, "/objects", &len)) {
                char *sm_alternate;
                struct strbuf sb = STRBUF_INIT;
                struct strbuf err = STRBUF_INIT;
-               strbuf_add(&sb, alt->path, strlen(alt->path) - strlen("objects"));
+               strbuf_add(&sb, odb->path, len);
 
                /*
                 * We need to end the new path with '/' to mark it as a dir,
@@ -1286,7 +1290,7 @@ static int add_possible_reference_from_superproject(
                 * as the last part of a missing submodule reference would
                 * be taken as a file name.
                 */
-               strbuf_addf(&sb, "modules/%s/", sas->submodule_name);
+               strbuf_addf(&sb, "/modules/%s/", sas->submodule_name);
 
                sm_alternate = compute_alternate_path(sb.buf, &err);
                if (sm_alternate) {
@@ -1298,7 +1302,7 @@ static int add_possible_reference_from_superproject(
                                die(_("submodule '%s' cannot add alternate: %s"),
                                    sas->submodule_name, err.buf);
                        case SUBMODULE_ALTERNATE_ERROR_INFO:
-                               fprintf(stderr, _("submodule '%s' cannot add alternate: %s"),
+                               fprintf_ln(stderr, _("submodule '%s' cannot add alternate: %s"),
                                        sas->submodule_name, err.buf);
                        case SUBMODULE_ALTERNATE_ERROR_IGNORE:
                                ; /* nothing */
@@ -1552,7 +1556,7 @@ struct submodule_update_clone {
 #define SUBMODULE_UPDATE_CLONE_INIT {0, MODULE_LIST_INIT, 0, \
        SUBMODULE_UPDATE_STRATEGY_INIT, 0, 0, -1, STRING_LIST_INIT_DUP, 0, \
        NULL, NULL, NULL, \
-       NULL, 0, 0, 0, NULL, 0, 0, 0}
+       NULL, 0, 0, 0, NULL, 0, 0, 1}
 
 
 static void next_submodule_warn_missing(struct submodule_update_clone *suc,
@@ -1813,11 +1817,10 @@ static int update_submodules(struct submodule_update_clone *suc)
 {
        int i;
 
-       run_processes_parallel(suc->max_jobs,
-                              update_clone_get_next_task,
-                              update_clone_start_failure,
-                              update_clone_task_finished,
-                              suc);
+       run_processes_parallel_tr2(suc->max_jobs, update_clone_get_next_task,
+                                  update_clone_start_failure,
+                                  update_clone_task_finished, suc, "submodule",
+                                  "parallel/update");
 
        /*
         * We saved the output and put it out all at once now.
@@ -2046,7 +2049,7 @@ static int ensure_core_worktree(int argc, const char **argv, const char *prefix)
        struct repository subrepo;
 
        if (argc != 2)
-               BUG("submodule--helper connect-gitdir-workingtree <name> <path>");
+               BUG("submodule--helper ensure-core-worktree <path>");
 
        path = argv[1];
 
@@ -2054,7 +2057,7 @@ static int ensure_core_worktree(int argc, const char **argv, const char *prefix)
        if (!sub)
                BUG("We could get the submodule handle before?");
 
-       if (repo_submodule_init(&subrepo, the_repository, path))
+       if (repo_submodule_init(&subrepo, the_repository, sub))
                die(_("could not get a repository handle for submodule '%s'"), path);
 
        if (!repo_config_get_string(&subrepo, "core.worktree", &cw)) {
@@ -2094,7 +2097,7 @@ static int absorb_git_dirs(int argc, const char **argv, const char *prefix)
        };
 
        const char *const git_submodule_helper_usage[] = {
-               N_("git submodule--helper embed-git-dir [<path>...]"),
+               N_("git submodule--helper absorb-git-dirs [<options>] [<path>...]"),
                NULL
        };
 
@@ -2145,17 +2148,22 @@ static int check_name(int argc, const char **argv, const char *prefix)
 static int module_config(int argc, const char **argv, const char *prefix)
 {
        enum {
-               CHECK_WRITEABLE = 1
+               CHECK_WRITEABLE = 1,
+               DO_UNSET = 2
        } command = 0;
 
        struct option module_config_options[] = {
                OPT_CMDMODE(0, "check-writeable", &command,
                            N_("check if it is safe to write to the .gitmodules file"),
                            CHECK_WRITEABLE),
+               OPT_CMDMODE(0, "unset", &command,
+                           N_("unset the config in the .gitmodules file"),
+                           DO_UNSET),
                OPT_END()
        };
        const char *const git_submodule_helper_usage[] = {
-               N_("git submodule--helper config name [value]"),
+               N_("git submodule--helper config <name> [<value>]"),
+               N_("git submodule--helper config --unset <name>"),
                N_("git submodule--helper config --check-writeable"),
                NULL
        };
@@ -2167,15 +2175,17 @@ static int module_config(int argc, const char **argv, const char *prefix)
                return is_writing_gitmodules_ok() ? 0 : -1;
 
        /* Equivalent to ACTION_GET in builtin/config.c */
-       if (argc == 2)
+       if (argc == 2 && command != DO_UNSET)
                return print_config_from_gitmodules(the_repository, argv[1]);
 
        /* Equivalent to ACTION_SET in builtin/config.c */
-       if (argc == 3) {
+       if (argc == 3 || (argc == 2 && command == DO_UNSET)) {
+               const char *value = (argc == 3) ? argv[2] : NULL;
+
                if (!is_writing_gitmodules_ok())
                        die(_("please make sure that the .gitmodules file is in the working tree"));
 
-               return config_set_in_gitmodules_file_gently(argv[1], argv[2]);
+               return config_set_in_gitmodules_file_gently(argv[1], value);
        }
 
        usage_with_options(git_submodule_helper_usage, module_config_options);