aboutsummaryrefslogtreecommitdiffstats
path: root/builtin/submodule--helper.c
diff options
context:
space:
mode:
Diffstat (limited to 'builtin/submodule--helper.c')
-rw-r--r--builtin/submodule--helper.c99
1 files changed, 71 insertions, 28 deletions
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index a46ffd49b3..19e5878381 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -1,9 +1,10 @@
+#define USE_THE_REPOSITORY_VARIABLE
#include "builtin.h"
#include "abspath.h"
#include "environment.h"
#include "gettext.h"
#include "hex.h"
-#include "repository.h"
+
#include "config.h"
#include "parse-options.h"
#include "quote.h"
@@ -363,9 +364,13 @@ static void runcommand_in_submodule_cb(const struct cache_entry *list_item,
if (!info->quiet)
printf(_("Entering '%s'\n"), displaypath);
- if (info->argv[0] && run_command(&cp))
- die(_("run_command returned non-zero status for %s\n."),
- displaypath);
+ if (info->argv[0]) {
+ if (run_command(&cp))
+ die(_("run_command returned non-zero status for %s\n."),
+ displaypath);
+ } else {
+ child_process_clear(&cp);
+ }
if (info->recursive) {
struct child_process cpr = CHILD_PROCESS_INIT;
@@ -394,7 +399,8 @@ cleanup:
free(displaypath);
}
-static int module_foreach(int argc, const char **argv, const char *prefix)
+static int module_foreach(int argc, const char **argv, const char *prefix,
+ struct repository *repo UNUSED)
{
struct foreach_cb info = FOREACH_CB_INIT;
struct pathspec pathspec = { 0 };
@@ -539,7 +545,8 @@ static void init_submodule_cb(const struct cache_entry *list_item, void *cb_data
info->flags);
}
-static int module_init(int argc, const char **argv, const char *prefix)
+static int module_init(int argc, const char **argv, const char *prefix,
+ struct repository *repo UNUSED)
{
struct init_cb info = INIT_CB_INIT;
struct pathspec pathspec = { 0 };
@@ -672,7 +679,7 @@ static void status_submodule(const char *path, const struct object_id *ce_oid,
setup_revisions(diff_files_args.nr, diff_files_args.v, &rev, &opt);
run_diff_files(&rev, 0);
- if (!diff_result_code(&rev.diffopt)) {
+ if (!diff_result_code(&rev)) {
print_status(flags, ' ', path, ce_oid,
displaypath);
} else if (!(flags & OPT_CACHED)) {
@@ -695,6 +702,7 @@ static void status_submodule(const char *path, const struct object_id *ce_oid,
if (flags & OPT_RECURSIVE) {
struct child_process cpr = CHILD_PROCESS_INIT;
+ int res;
cpr.git_cmd = 1;
cpr.dir = path;
@@ -710,7 +718,10 @@ static void status_submodule(const char *path, const struct object_id *ce_oid,
if (flags & OPT_QUIET)
strvec_push(&cpr.args, "--quiet");
- if (run_command(&cpr))
+ res = run_command(&cpr);
+ if (res == SIGPIPE + 128)
+ raise(SIGPIPE);
+ else if (res)
die(_("failed to recurse into submodule '%s'"), path);
}
@@ -729,7 +740,8 @@ static void status_submodule_cb(const struct cache_entry *list_item,
info->prefix, info->super_prefix, info->flags);
}
-static int module_status(int argc, const char **argv, const char *prefix)
+static int module_status(int argc, const char **argv, const char *prefix,
+ struct repository *repo UNUSED)
{
struct status_cb info = STATUS_CB_INIT;
struct pathspec pathspec = { 0 };
@@ -1154,7 +1166,8 @@ cleanup:
return ret;
}
-static int module_summary(int argc, const char **argv, const char *prefix)
+static int module_summary(int argc, const char **argv, const char *prefix,
+ struct repository *repo UNUSED)
{
struct summary_cb info = SUMMARY_CB_INIT;
int cached = 0;
@@ -1330,7 +1343,8 @@ static void sync_submodule_cb(const struct cache_entry *list_item, void *cb_data
info->flags);
}
-static int module_sync(int argc, const char **argv, const char *prefix)
+static int module_sync(int argc, const char **argv, const char *prefix,
+ struct repository *repo UNUSED)
{
struct sync_cb info = SYNC_CB_INIT;
struct pathspec pathspec = { 0 };
@@ -1476,7 +1490,8 @@ static void deinit_submodule_cb(const struct cache_entry *list_item,
deinit_submodule(list_item->name, info->prefix, info->flags);
}
-static int module_deinit(int argc, const char **argv, const char *prefix)
+static int module_deinit(int argc, const char **argv, const char *prefix,
+ struct repository *repo UNUSED)
{
struct deinit_cb info = DEINIT_CB_INIT;
struct pathspec pathspec = { 0 };
@@ -1617,6 +1632,8 @@ static int add_possible_reference_from_superproject(
; /* nothing */
}
}
+
+ strbuf_release(&err);
strbuf_release(&sb);
}
@@ -1709,7 +1726,7 @@ static int clone_submodule(const struct module_clone_data *clone_data,
exit(128);
if (!is_absolute_path(clone_data->path))
- clone_data_path = to_free = xstrfmt("%s/%s", get_git_work_tree(),
+ clone_data_path = to_free = xstrfmt("%s/%s", repo_get_work_tree(the_repository),
clone_data->path);
if (validate_submodule_git_dir(sm_gitdir, clone_data->name) < 0)
@@ -1831,7 +1848,8 @@ static int clone_submodule(const struct module_clone_data *clone_data,
return 0;
}
-static int module_clone(int argc, const char **argv, const char *prefix)
+static int module_clone(int argc, const char **argv, const char *prefix,
+ struct repository *repo UNUSED)
{
int dissociate = 0, quiet = 0, progress = 0, require_init = 0;
struct module_clone_data clone_data = MODULE_CLONE_DATA_INIT;
@@ -2021,6 +2039,7 @@ struct update_data {
static void update_data_release(struct update_data *ud)
{
free(ud->displaypath);
+ submodule_update_strategy_release(&ud->update_strategy);
module_list_release(&ud->list);
}
@@ -2321,7 +2340,14 @@ static int fetch_in_submodule(const char *module_path, int depth, int quiet,
strvec_pushf(&cp.args, "--depth=%d", depth);
if (oid) {
char *hex = oid_to_hex(oid);
- char *remote = get_default_remote();
+ char *remote;
+ int code;
+
+ code = get_default_remote_submodule(module_path, &remote);
+ if (code) {
+ child_process_clear(&cp);
+ return code;
+ }
strvec_pushl(&cp.args, remote, hex, NULL);
free(remote);
@@ -2641,15 +2667,20 @@ static int update_submodule(struct update_data *update_data)
if (!update_data->nofetch) {
if (fetch_in_submodule(update_data->sm_path, update_data->depth,
- 0, NULL))
+ 0, NULL)) {
+ free(remote_ref);
return die_message(_("Unable to fetch in submodule path '%s'"),
update_data->sm_path);
+ }
}
if (repo_resolve_gitlink_ref(the_repository, update_data->sm_path,
- remote_ref, &update_data->oid))
- return die_message(_("Unable to find %s revision in submodule path '%s'"),
- remote_ref, update_data->sm_path);
+ remote_ref, &update_data->oid)) {
+ ret = die_message(_("Unable to find %s revision in submodule path '%s'"),
+ remote_ref, update_data->sm_path);
+ free(remote_ref);
+ return ret;
+ }
free(remote_ref);
}
@@ -2755,7 +2786,8 @@ cleanup:
return ret;
}
-static int module_update(int argc, const char **argv, const char *prefix)
+static int module_update(int argc, const char **argv, const char *prefix,
+ struct repository *repo UNUSED)
{
struct pathspec pathspec = { 0 };
struct pathspec pathspec2 = { 0 };
@@ -2887,7 +2919,8 @@ cleanup:
return ret;
}
-static int push_check(int argc, const char **argv, const char *prefix UNUSED)
+static int push_check(int argc, const char **argv, const char *prefix UNUSED,
+ struct repository *repo UNUSED)
{
struct remote *remote;
const char *superproject_head;
@@ -2958,14 +2991,17 @@ static int push_check(int argc, const char **argv, const char *prefix UNUSED)
rs->src);
}
}
+
refspec_clear(&refspec);
+ free_refs(local_refs);
}
free(head);
return 0;
}
-static int absorb_git_dirs(int argc, const char **argv, const char *prefix)
+static int absorb_git_dirs(int argc, const char **argv, const char *prefix,
+ struct repository *repo UNUSED)
{
int i;
struct pathspec pathspec = { 0 };
@@ -2998,7 +3034,8 @@ cleanup:
return ret;
}
-static int module_set_url(int argc, const char **argv, const char *prefix)
+static int module_set_url(int argc, const char **argv, const char *prefix,
+ struct repository *repo UNUSED)
{
int quiet = 0, ret;
const char *newurl;
@@ -3037,7 +3074,8 @@ static int module_set_url(int argc, const char **argv, const char *prefix)
return !!ret;
}
-static int module_set_branch(int argc, const char **argv, const char *prefix)
+static int module_set_branch(int argc, const char **argv, const char *prefix,
+ struct repository *repo UNUSED)
{
int opt_default = 0, ret;
const char *opt_branch = NULL;
@@ -3087,7 +3125,8 @@ static int module_set_branch(int argc, const char **argv, const char *prefix)
return !!ret;
}
-static int module_create_branch(int argc, const char **argv, const char *prefix)
+static int module_create_branch(int argc, const char **argv, const char *prefix,
+ struct repository *repo UNUSED)
{
enum branch_track track;
int quiet = 0, force = 0, reflog = 0, dry_run = 0;
@@ -3398,7 +3437,8 @@ static void die_on_repo_without_commits(const char *path)
strbuf_release(&sb);
}
-static int module_add(int argc, const char **argv, const char *prefix)
+static int module_add(int argc, const char **argv, const char *prefix,
+ struct repository *repo UNUSED)
{
int force = 0, quiet = 0, progress = 0, dissociate = 0;
struct add_data add_data = ADD_DATA_INIT;
@@ -3528,7 +3568,10 @@ cleanup:
return ret;
}
-int cmd_submodule__helper(int argc, const char **argv, const char *prefix)
+int cmd_submodule__helper(int argc,
+ const char **argv,
+ const char *prefix,
+ struct repository *repo)
{
parse_opt_subcommand_fn *fn = NULL;
const char *const usage[] = {
@@ -3554,5 +3597,5 @@ int cmd_submodule__helper(int argc, const char **argv, const char *prefix)
};
argc = parse_options(argc, argv, prefix, options, usage, 0);
- return fn(argc, argv, prefix);
+ return fn(argc, argv, prefix, repo);
}