Merge branch 'dj/fetch-all-tags' into maint
authorJunio C Hamano <gitster@pobox.com>
Mon, 24 Sep 2012 19:39:21 +0000 (12:39 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 24 Sep 2012 19:39:21 +0000 (12:39 -0700)
"git fetch --all", when passed "--no-tags", did not honor the
"--no-tags" option while fetching from individual remotes (the same
issue existed with "--tags", but combination "--all --tags" makes
much less sense than "--all --no-tags").

* dj/fetch-all-tags:
fetch --all: pass --tags/--no-tags through to each remote
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

1  2 
builtin/fetch.c
submodule.c
diff --combined builtin/fetch.c
index bb9a0743ff565f3002eb0fede8e35b7f01a73b75,4494aed0c757085f5728afa82ebfa3a0fb66876d..f483352fe57c200415463078d834bd0712c22705
@@@ -14,6 -14,7 +14,7 @@@
  #include "transport.h"
  #include "submodule.h"
  #include "connected.h"
+ #include "argv-array.h"
  
  static const char * const builtin_fetch_usage[] = {
        "git fetch [<options>] [<repository> [<refspec>...]]",
@@@ -546,8 -547,8 +547,8 @@@ static int prune_refs(struct refspec *r
        int result = 0;
        struct ref *ref, *stale_refs = get_stale_heads(refs, ref_count, ref_map);
        const char *dangling_msg = dry_run
 -              ? _("   (%s will become dangling)\n")
 -              : _("   (%s has become dangling)\n");
 +              ? _("   (%s will become dangling)")
 +              : _("   (%s has become dangling)");
  
        for (ref = stale_refs; ref; ref = ref->next) {
                if (!dry_run)
@@@ -841,38 -842,39 +842,39 @@@ static int add_remote_or_group(const ch
        return 1;
  }
  
- static void add_options_to_argv(int *argc, const char **argv)
+ static void add_options_to_argv(struct argv_array *argv)
  {
        if (dry_run)
-               argv[(*argc)++] = "--dry-run";
+               argv_array_push(argv, "--dry-run");
        if (prune)
-               argv[(*argc)++] = "--prune";
+               argv_array_push(argv, "--prune");
        if (update_head_ok)
-               argv[(*argc)++] = "--update-head-ok";
+               argv_array_push(argv, "--update-head-ok");
        if (force)
-               argv[(*argc)++] = "--force";
+               argv_array_push(argv, "--force");
        if (keep)
-               argv[(*argc)++] = "--keep";
+               argv_array_push(argv, "--keep");
        if (recurse_submodules == RECURSE_SUBMODULES_ON)
-               argv[(*argc)++] = "--recurse-submodules";
+               argv_array_push(argv, "--recurse-submodules");
        else if (recurse_submodules == RECURSE_SUBMODULES_ON_DEMAND)
-               argv[(*argc)++] = "--recurse-submodules=on-demand";
+               argv_array_push(argv, "--recurse-submodules=on-demand");
+       if (tags == TAGS_SET)
+               argv_array_push(argv, "--tags");
+       else if (tags == TAGS_UNSET)
+               argv_array_push(argv, "--no-tags");
        if (verbosity >= 2)
-               argv[(*argc)++] = "-v";
+               argv_array_push(argv, "-v");
        if (verbosity >= 1)
-               argv[(*argc)++] = "-v";
+               argv_array_push(argv, "-v");
        else if (verbosity < 0)
-               argv[(*argc)++] = "-q";
+               argv_array_push(argv, "-q");
  
  }
  
  static int fetch_multiple(struct string_list *list)
  {
        int i, result = 0;
-       const char *argv[12] = { "fetch", "--append" };
-       int argc = 2;
-       add_options_to_argv(&argc, argv);
+       struct argv_array argv = ARGV_ARRAY_INIT;
  
        if (!append && !dry_run) {
                int errcode = truncate_fetch_head();
                        return errcode;
        }
  
+       argv_array_pushl(&argv, "fetch", "--append", NULL);
+       add_options_to_argv(&argv);
        for (i = 0; i < list->nr; i++) {
                const char *name = list->items[i].string;
-               argv[argc] = name;
-               argv[argc + 1] = NULL;
+               argv_array_push(&argv, name);
                if (verbosity >= 0)
                        printf(_("Fetching %s\n"), name);
-               if (run_command_v_opt(argv, RUN_GIT_CMD)) {
+               if (run_command_v_opt(argv.argv, RUN_GIT_CMD)) {
                        error(_("Could not fetch %s"), name);
                        result = 1;
                }
+               argv_array_pop(&argv);
        }
  
+       argv_array_clear(&argv);
        return result;
  }
  
@@@ -1007,13 -1013,14 +1013,14 @@@ int cmd_fetch(int argc, const char **ar
        }
  
        if (!result && (recurse_submodules != RECURSE_SUBMODULES_OFF)) {
-               const char *options[10];
-               int num_options = 0;
-               add_options_to_argv(&num_options, options);
-               result = fetch_populated_submodules(num_options, options,
+               struct argv_array options = ARGV_ARRAY_INIT;
+               add_options_to_argv(&options);
+               result = fetch_populated_submodules(&options,
                                                    submodule_prefix,
                                                    recurse_submodules,
                                                    verbosity < 0);
+               argv_array_clear(&options);
        }
  
        /* All names were strdup()ed or strndup()ed */
diff --combined submodule.c
index 19dc6a6c0d5cf7d9a4c80c61e160290b4462665d,83e157d8d5af8567b93801f0503dcf609d09a1cf..51d48c21217d12c9b654310ba192606a695a8584
@@@ -63,9 -63,6 +63,9 @@@ static int add_submodule_odb(const cha
        alt_odb->name[40] = '\0';
        alt_odb->name[41] = '\0';
        alt_odb_list = alt_odb;
 +
 +      /* add possible alternates from the submodule */
 +      read_info_alternates(objects_directory.buf, 0);
        prepare_alt_odb();
  done:
        strbuf_release(&objects_directory);
@@@ -574,7 -571,8 +574,7 @@@ static void calculate_changed_submodule
                        DIFF_OPT_SET(&diff_opts, RECURSIVE);
                        diff_opts.output_format |= DIFF_FORMAT_CALLBACK;
                        diff_opts.format_callback = submodule_collect_changed_cb;
 -                      if (diff_setup_done(&diff_opts) < 0)
 -                              die("diff_setup_done failed");
 +                      diff_setup_done(&diff_opts);
                        diff_tree_sha1(parent->item->object.sha1, commit->object.sha1, "", &diff_opts);
                        diffcore_std(&diff_opts);
                        diff_flush(&diff_opts);
        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)
                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;
                        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;