summaryrefslogtreecommitdiff
path: root/submodule.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2012-09-11 11:36:18 -0700
committerJunio C Hamano <gitster@pobox.com>2012-09-11 11:36:18 -0700
commit871313c35851e85a58c4012c02a806890c671813 (patch)
treeeaaa4fbcf1042f07494190122abd12a21966aaad /submodule.c
parent34f5130af84f7a37fba327d5a5be4f4427dc6886 (diff)
parent50d89ad6542c8acafefa6d42f8b42dfa9b8fafe1 (diff)
downloadgit-871313c35851e85a58c4012c02a806890c671813.tar.gz
Merge branch 'jk/argv-array'
Use argv-array API in "git fetch" implementation. * jk/argv-array: submodule: use argv_array instead of hand-building arrays fetch: use argv_array instead of hand-building arrays argv-array: fix bogus cast when freeing array argv-array: add pop function
Diffstat (limited to 'submodule.c')
-rw-r--r--submodule.c31
1 files changed, 16 insertions, 15 deletions
diff --git a/submodule.c b/submodule.c
index d133796c9c..50f213e926 100644
--- a/submodule.c
+++ b/submodule.c
@@ -588,13 +588,13 @@ static void calculate_changed_submodule_paths(void)
initialized_fetch_ref_tips = 0;
}
-int fetch_populated_submodules(int num_options, const char **options,
+int fetch_populated_submodules(const struct argv_array *options,
const char *prefix, int command_line_option,
int quiet)
{
- int i, result = 0, argc = 0, default_argc;
+ int i, result = 0;
struct child_process cp;
- const char **argv;
+ struct argv_array argv = ARGV_ARRAY_INIT;
struct string_list_item *name_for_path;
const char *work_tree = get_git_work_tree();
if (!work_tree)
@@ -604,17 +604,13 @@ int fetch_populated_submodules(int num_options, const char **options,
if (read_cache() < 0)
die("index file corrupt");
- /* 6: "fetch" (options) --recurse-submodules-default default "--submodule-prefix" prefix NULL */
- argv = xcalloc(num_options + 6, sizeof(const char *));
- argv[argc++] = "fetch";
- for (i = 0; i < num_options; i++)
- argv[argc++] = options[i];
- argv[argc++] = "--recurse-submodules-default";
- default_argc = argc++;
- argv[argc++] = "--submodule-prefix";
+ argv_array_push(&argv, "fetch");
+ for (i = 0; i < options->argc; i++)
+ argv_array_push(&argv, options->argv[i]);
+ argv_array_push(&argv, "--recurse-submodules-default");
+ /* default value, "--submodule-prefix" and its value are added later */
memset(&cp, 0, sizeof(cp));
- cp.argv = argv;
cp.env = local_repo_env;
cp.git_cmd = 1;
cp.no_stdin = 1;
@@ -674,16 +670,21 @@ int fetch_populated_submodules(int num_options, const char **options,
if (!quiet)
printf("Fetching submodule %s%s\n", prefix, ce->name);
cp.dir = submodule_path.buf;
- argv[default_argc] = default_argv;
- argv[argc] = submodule_prefix.buf;
+ argv_array_push(&argv, default_argv);
+ argv_array_push(&argv, "--submodule-prefix");
+ argv_array_push(&argv, submodule_prefix.buf);
+ cp.argv = argv.argv;
if (run_command(&cp))
result = 1;
+ argv_array_pop(&argv);
+ argv_array_pop(&argv);
+ argv_array_pop(&argv);
}
strbuf_release(&submodule_path);
strbuf_release(&submodule_git_dir);
strbuf_release(&submodule_prefix);
}
- free(argv);
+ argv_array_clear(&argv);
out:
string_list_clear(&changed_submodule_paths, 1);
return result;