Merge branch 'nd/fetch-status-alignment'
authorJunio C Hamano <gitster@pobox.com>
Tue, 18 Sep 2012 21:35:54 +0000 (14:35 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 18 Sep 2012 21:35:55 +0000 (14:35 -0700)
The status report from "git fetch", when messages like 'up-to-date'
are translated, did not align the branch names well.

* nd/fetch-status-alignment:
fetch: align per-ref summary report in UTF-8 locales

1  2 
builtin/fetch.c
gettext.h
diff --combined builtin/fetch.c
index d0dcc8888f14e8305250afcab7eb4ca7a3f6648c,85e291fa6e3d9652669ce05ef779ff4380e58ad3..4b5a89839b66f201bda42f06cabdf781d44f0192
  #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>...]]",
 -      "git fetch [<options>] <group>",
 -      "git fetch --multiple [<options>] [(<repository> | <group>)...]",
 -      "git fetch --all [<options>]",
 +      N_("git fetch [<options>] [<repository> [<refspec>...]]"),
 +      N_("git fetch [<options>] <group>"),
 +      N_("git fetch --multiple [<options>] [(<repository> | <group>)...]"),
 +      N_("git fetch --all [<options>]"),
        NULL
  };
  
@@@ -57,36 -56,36 +57,36 @@@ static int option_parse_recurse_submodu
  static struct option builtin_fetch_options[] = {
        OPT__VERBOSITY(&verbosity),
        OPT_BOOLEAN(0, "all", &all,
 -                  "fetch from all remotes"),
 +                  N_("fetch from all remotes")),
        OPT_BOOLEAN('a', "append", &append,
 -                  "append to .git/FETCH_HEAD instead of overwriting"),
 -      OPT_STRING(0, "upload-pack", &upload_pack, "path",
 -                 "path to upload pack on remote end"),
 -      OPT__FORCE(&force, "force overwrite of local branch"),
 +                  N_("append to .git/FETCH_HEAD instead of overwriting")),
 +      OPT_STRING(0, "upload-pack", &upload_pack, N_("path"),
 +                 N_("path to upload pack on remote end")),
 +      OPT__FORCE(&force, N_("force overwrite of local branch")),
        OPT_BOOLEAN('m', "multiple", &multiple,
 -                  "fetch from multiple remotes"),
 +                  N_("fetch from multiple remotes")),
        OPT_SET_INT('t', "tags", &tags,
 -                  "fetch all tags and associated objects", TAGS_SET),
 +                  N_("fetch all tags and associated objects"), TAGS_SET),
        OPT_SET_INT('n', NULL, &tags,
 -                  "do not fetch all tags (--no-tags)", TAGS_UNSET),
 +                  N_("do not fetch all tags (--no-tags)"), TAGS_UNSET),
        OPT_BOOLEAN('p', "prune", &prune,
 -                  "prune remote-tracking branches no longer on remote"),
 -      { OPTION_CALLBACK, 0, "recurse-submodules", NULL, "on-demand",
 -                  "control recursive fetching of submodules",
 +                  N_("prune remote-tracking branches no longer on remote")),
 +      { OPTION_CALLBACK, 0, "recurse-submodules", NULL, N_("on-demand"),
 +                  N_("control recursive fetching of submodules"),
                    PARSE_OPT_OPTARG, option_parse_recurse_submodules },
        OPT_BOOLEAN(0, "dry-run", &dry_run,
 -                  "dry run"),
 -      OPT_BOOLEAN('k', "keep", &keep, "keep downloaded pack"),
 +                  N_("dry run")),
 +      OPT_BOOLEAN('k', "keep", &keep, N_("keep downloaded pack")),
        OPT_BOOLEAN('u', "update-head-ok", &update_head_ok,
 -                  "allow updating of HEAD ref"),
 -      OPT_BOOL(0, "progress", &progress, "force progress reporting"),
 -      OPT_STRING(0, "depth", &depth, "depth",
 -                 "deepen history of shallow clone"),
 -      { OPTION_STRING, 0, "submodule-prefix", &submodule_prefix, "dir",
 -                 "prepend this to submodule path output", PARSE_OPT_HIDDEN },
 +                  N_("allow updating of HEAD ref")),
 +      OPT_BOOL(0, "progress", &progress, N_("force progress reporting")),
 +      OPT_STRING(0, "depth", &depth, N_("depth"),
 +                 N_("deepen history of shallow clone")),
 +      { OPTION_STRING, 0, "submodule-prefix", &submodule_prefix, N_("dir"),
 +                 N_("prepend this to submodule path output"), PARSE_OPT_HIDDEN },
        { OPTION_STRING, 0, "recurse-submodules-default",
                   &recurse_submodules_default, NULL,
 -                 "default mode for recursion", PARSE_OPT_HIDDEN },
 +                 N_("default mode for recursion"), PARSE_OPT_HIDDEN },
        OPT_END()
  };
  
@@@ -256,9 -255,8 +256,8 @@@ static int update_local_ref(struct ref 
        if (!hashcmp(ref->old_sha1, ref->new_sha1)) {
                if (verbosity > 0)
                        strbuf_addf(display, "= %-*s %-*s -> %s",
-                                   TRANSPORT_SUMMARY_WIDTH,
-                                   _("[up to date]"), REFCOL_WIDTH,
-                                   remote, pretty_ref);
+                                   TRANSPORT_SUMMARY(_("[up to date]")),
+                                   REFCOL_WIDTH, remote, pretty_ref);
                return 0;
        }
  
                 */
                strbuf_addf(display,
                            _("! %-*s %-*s -> %s  (can't fetch in current branch)"),
-                           TRANSPORT_SUMMARY_WIDTH, _("[rejected]"),
+                           TRANSPORT_SUMMARY(_("[rejected]")),
                            REFCOL_WIDTH, remote, pretty_ref);
                return 1;
        }
                r = s_update_ref("updating tag", ref, 0);
                strbuf_addf(display, "%c %-*s %-*s -> %s%s",
                            r ? '!' : '-',
-                           TRANSPORT_SUMMARY_WIDTH, _("[tag update]"),
+                           TRANSPORT_SUMMARY(_("[tag update]")),
                            REFCOL_WIDTH, remote, pretty_ref,
                            r ? _("  (unable to update local ref)") : "");
                return r;
                r = s_update_ref(msg, ref, 0);
                strbuf_addf(display, "%c %-*s %-*s -> %s%s",
                            r ? '!' : '*',
-                           TRANSPORT_SUMMARY_WIDTH, what,
+                           TRANSPORT_SUMMARY(what),
                            REFCOL_WIDTH, remote, pretty_ref,
                            r ? _("  (unable to update local ref)") : "");
                return r;
        }
  
 -      if (in_merge_bases(current, &updated, 1)) {
 +      if (in_merge_bases(current, updated)) {
                char quickref[83];
                int r;
                strcpy(quickref, find_unique_abbrev(current->object.sha1, DEFAULT_ABBREV));
                return r;
        } else {
                strbuf_addf(display, "! %-*s %-*s -> %s  %s",
-                           TRANSPORT_SUMMARY_WIDTH, _("[rejected]"),
+                           TRANSPORT_SUMMARY(_("[rejected]")),
                            REFCOL_WIDTH, remote, pretty_ref,
                            _("(non-fast-forward)"));
                return 1;
@@@ -555,7 -553,7 +554,7 @@@ static int prune_refs(struct refspec *r
                        result |= delete_ref(ref->name, NULL, 0);
                if (verbosity >= 0) {
                        fprintf(stderr, " x %-*s %-*s -> %s\n",
-                               TRANSPORT_SUMMARY_WIDTH, _("[deleted]"),
+                               TRANSPORT_SUMMARY(_("[deleted]")),
                                REFCOL_WIDTH, _("(none)"), prettify_refname(ref->name));
                        warn_dangling_symref(stderr, dangling_msg, ref->name);
                }
@@@ -842,39 -840,38 +841,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;
  }
  
@@@ -1013,14 -1006,13 +1012,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 gettext.h
index 376297bf730d421fa13237350d2beeb525be5ec4,e44d8bcda90239d513b6819bcd90b0d42cdd5606..7671d09d04bb87541b11209b5cdbddbb9e4e59b8
+++ b/gettext.h
  
  #ifndef NO_GETTEXT
  extern void git_setup_gettext(void);
+ extern int gettext_width(const char *s);
  #else
  static inline void git_setup_gettext(void)
  {
  }
+ static inline int gettext_width(const char *s)
+ {
+       return strlen(s);
+ }
  #endif
  
  #ifdef GETTEXT_POISON
@@@ -44,8 -49,6 +49,8 @@@ extern int use_gettext_poison(void)
  
  static inline FORMAT_PRESERVING(1) const char *_(const char *msgid)
  {
 +      if (!*msgid)
 +              return "";
        return use_gettext_poison() ? "# GETTEXT POISON #" : gettext(msgid);
  }