submodule: port subcommand 'set-url' from shell to C
Convert submodule subcommand 'set-url' to a builtin. Port 'set-url' to 'submodule--helper.c' and call the latter via 'git-submodule.sh'. Signed-off-by: Shourya Shukla <shouryashukla.oo@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Shourya Shukla committed
May 8, 2020 at 11:51 UTC
6417cf9c21e9b3f450cd78352d19f43a4dd5a495
2 files changed
+33
-21
builtin/submodule--helper.c
+32
@@ -2246,6 +2246,37 @@ static int module_config(int argc, const char **argv, const char *prefix)
2246
usage_with_options(git_submodule_helper_usage, module_config_options);
2247
}
2248
2249
+static int module_set_url(int argc, const char **argv, const char *prefix)
2250
+{
2251
+ int quiet = 0;
2252
+ const char *newurl;
2253
+ const char *path;
2254
+ char *config_name;
2255
+
2256
+ struct option options[] = {
2257
+ OPT__QUIET(&quiet, N_("Suppress output for setting url of a submodule")),
2258
+ OPT_END()
2259
+ };
2260
+ const char *const usage[] = {
2261
+ N_("git submodule--helper set-url [--quiet] <path> <newurl>"),
2262
+ NULL
2263
+ };
2264
+
2265
+ argc = parse_options(argc, argv, prefix, options, usage, 0);
2266
+
2267
+ if (argc != 2 || !(path = argv[0]) || !(newurl = argv[1]))
2268
+ usage_with_options(usage, options);
2269
+
2270
+ config_name = xstrfmt("submodule.%s.url", path);
2271
+
2272
+ config_set_in_gitmodules_file_gently(config_name, newurl);
2273
+ sync_submodule(path, prefix, quiet ? OPT_QUIET : 0);
2274
+
2275
+ free(config_name);
2276
+
2277
+ return 0;
2278
+}
2279
+
2280
#define SUPPORT_SUPER_PREFIX (1<<0)
2281
2282
struct cmd_struct {
@@ -2276,6 +2307,7 @@ static struct cmd_struct commands[] = {
2307
{"is-active", is_active, 0},
2308
{"check-name", check_name, 0},
2309
{"config", module_config, 0},
2310
+ {"set-url", module_set_url, 0},
2311
};
2312
2313
int cmd_submodule__helper(int argc, const char **argv, const char *prefix)
git-submodule.sh
+1
-21
@@ -805,27 +805,7 @@ cmd_set_url() {
805
shift
806
done
807
808
- if test $# -ne 2
809
- then
810
- usage
811
- fi
812
-
813
- # we can't use `git submodule--helper name` here because internally, it
814
- # hashes the path so a trailing slash could lead to an unintentional no match
815
- name="$(git submodule--helper list "$1" | cut -f2)"
816
- if test -z "$name"
817
- then
818
- exit 1
819
- fi
820
-
821
- url="$2"
822
- if test -z "$url"
823
- then
824
- exit 1
825
- fi
826
-
827
- git submodule--helper config submodule."$name".url "$url"
828
- git submodule--helper sync ${GIT_QUIET:+--quiet} "$name"
808
+ git ${wt_prefix:+-C "$wt_prefix"} ${prefix:+--super-prefix "$prefix"} submodule--helper set-url ${GIT_QUIET:+--quiet} -- "$@"
809
}
810
811
#