]> git.ipfire.org Git - thirdparty/git.git/blobdiff - builtin/submodule--helper.c
reftable: signal overflow
[thirdparty/git.git] / builtin / submodule--helper.c
index b45fa78c06b7dc072a2e867fffa601e80a14654d..9b25a508e6a7bb6116b48b36ab4b15e8f670552b 100644 (file)
@@ -307,7 +307,7 @@ struct module_list {
        const struct cache_entry **entries;
        int alloc, nr;
 };
-#define MODULE_LIST_INIT { NULL, 0, 0 }
+#define MODULE_LIST_INIT { 0 }
 
 static int module_list_compute(int argc, const char **argv,
                               const char *prefix,
@@ -588,7 +588,7 @@ struct init_cb {
        const char *prefix;
        unsigned int flags;
 };
-#define INIT_CB_INIT { NULL, 0 }
+#define INIT_CB_INIT { 0 }
 
 static void init_submodule(const char *path, const char *prefix,
                           unsigned int flags)
@@ -717,7 +717,7 @@ struct status_cb {
        const char *prefix;
        unsigned int flags;
 };
-#define STATUS_CB_INIT { NULL, 0 }
+#define STATUS_CB_INIT { 0 }
 
 static void print_status(unsigned int flags, char state, const char *path,
                         const struct object_id *oid, const char *displaypath)
@@ -911,13 +911,13 @@ struct module_cb {
        char status;
        const char *sm_path;
 };
-#define MODULE_CB_INIT { 0, 0, NULL, NULL, '\0', NULL }
+#define MODULE_CB_INIT { 0 }
 
 struct module_cb_list {
        struct module_cb **entries;
        int alloc, nr;
 };
-#define MODULE_CB_LIST_INIT { NULL, 0, 0 }
+#define MODULE_CB_LIST_INIT { 0 }
 
 struct summary_cb {
        int argc;
@@ -928,7 +928,7 @@ struct summary_cb {
        unsigned int files: 1;
        int summary_limit;
 };
-#define SUMMARY_CB_INIT { 0, NULL, NULL, 0, 0, 0, 0 }
+#define SUMMARY_CB_INIT { 0 }
 
 enum diff_cmd {
        DIFF_INDEX,
@@ -1334,7 +1334,7 @@ struct sync_cb {
        const char *prefix;
        unsigned int flags;
 };
-#define SYNC_CB_INIT { NULL, 0 }
+#define SYNC_CB_INIT { 0 }
 
 static void sync_submodule(const char *path, const char *prefix,
                           unsigned int flags)
@@ -1480,7 +1480,7 @@ struct deinit_cb {
        const char *prefix;
        unsigned int flags;
 };
-#define DEINIT_CB_INIT { NULL, 0 }
+#define DEINIT_CB_INIT { 0 }
 
 static void deinit_submodule(const char *path, const char *prefix,
                             unsigned int flags)
@@ -1648,8 +1648,9 @@ struct submodule_alternate_setup {
        } error_mode;
        struct string_list *reference;
 };
-#define SUBMODULE_ALTERNATE_SETUP_INIT { NULL, \
-       SUBMODULE_ALTERNATE_ERROR_IGNORE, NULL }
+#define SUBMODULE_ALTERNATE_SETUP_INIT { \
+       .error_mode = SUBMODULE_ALTERNATE_ERROR_IGNORE, \
+}
 
 static const char alternate_error_advice[] = N_(
 "An alternate computed from a superproject's alternate is invalid.\n"
@@ -2999,7 +3000,7 @@ struct add_data {
 };
 #define ADD_DATA_INIT { .depth = -1 }
 
-static void show_fetch_remotes(FILE *output, const char *git_dir_path)
+static void append_fetch_remotes(struct strbuf *msg, const char *git_dir_path)
 {
        struct child_process cp_remote = CHILD_PROCESS_INIT;
        struct strbuf sb_remote_out = STRBUF_INIT;
@@ -3015,7 +3016,7 @@ static void show_fetch_remotes(FILE *output, const char *git_dir_path)
                while ((next_line = strchr(line, '\n')) != NULL) {
                        size_t len = next_line - line;
                        if (strip_suffix_mem(line, &len, " (fetch)"))
-                               fprintf(output, "  %.*s\n", (int)len, line);
+                               strbuf_addf(msg, "  %.*s\n", (int)len, line);
                        line = next_line + 1;
                }
        }
@@ -3047,19 +3048,27 @@ static int add_submodule(const struct add_data *add_data)
 
                if (is_directory(submod_gitdir_path)) {
                        if (!add_data->force) {
-                               fprintf(stderr, _("A git directory for '%s' is found "
-                                                 "locally with remote(s):"),
-                                       add_data->sm_name);
-                               show_fetch_remotes(stderr, submod_gitdir_path);
+                               struct strbuf msg = STRBUF_INIT;
+                               char *die_msg;
+
+                               strbuf_addf(&msg, _("A git directory for '%s' is found "
+                                                   "locally with remote(s):\n"),
+                                           add_data->sm_name);
+
+                               append_fetch_remotes(&msg, submod_gitdir_path);
                                free(submod_gitdir_path);
-                               die(_("If you want to reuse this local git "
-                                     "directory instead of cloning again from\n"
-                                     "  %s\n"
-                                     "use the '--force' option. If the local git "
-                                     "directory is not the correct repo\n"
-                                     "or if you are unsure what this means, choose "
-                                     "another name with the '--name' option.\n"),
-                                   add_data->realrepo);
+
+                               strbuf_addf(&msg, _("If you want to reuse this local git "
+                                                   "directory instead of cloning again from\n"
+                                                   "  %s\n"
+                                                   "use the '--force' option. If the local git "
+                                                   "directory is not the correct repo\n"
+                                                   "or you are unsure what this means choose "
+                                                   "another name with the '--name' option."),
+                                           add_data->realrepo);
+
+                               die_msg = strbuf_detach(&msg, NULL);
+                               die("%s", die_msg);
                        } else {
                                printf(_("Reactivating local git directory for "
                                         "submodule '%s'\n"), add_data->sm_name);
@@ -3086,6 +3095,10 @@ static int add_submodule(const struct add_data *add_data)
                prepare_submodule_repo_env(&cp.env_array);
                cp.git_cmd = 1;
                cp.dir = add_data->sm_path;
+               /*
+                * NOTE: we only get here if add_data->force is true, so
+                * passing --force to checkout is reasonable.
+                */
                strvec_pushl(&cp.args, "checkout", "-f", "-q", NULL);
 
                if (add_data->branch) {
@@ -3216,6 +3229,7 @@ static void die_on_index_match(const char *path, int force)
                }
                free(ps_matched);
        }
+       clear_pathspec(&ps);
 }
 
 static void die_on_repo_without_commits(const char *path)
@@ -3227,6 +3241,7 @@ static void die_on_repo_without_commits(const char *path)
                if (resolve_gitlink_ref(path, "HEAD", &oid) < 0)
                        die(_("'%s' does not have a commit checked out"), path);
        }
+       strbuf_release(&sb);
 }
 
 static int module_add(int argc, const char **argv, const char *prefix)