Merge branch 'mm/status-porcelain-format-i18n-fix'
authorJunio C Hamano <gitster@pobox.com>
Mon, 31 Mar 2014 23:31:25 +0000 (16:31 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 31 Mar 2014 23:31:25 +0000 (16:31 -0700)
* mm/status-porcelain-format-i18n-fix:
status: disable translation when --porcelain is used

1  2 
wt-status.c
wt-status.h
diff --combined wt-status.c
index e1827faf073ce384bea6a697dd903ffc643bdfdc,b53ce330b9f63974a2f64f28a0697757861fef05..ec7344e50834f18821692d7e38f634778d632080
@@@ -15,9 -15,8 +15,9 @@@
  #include "submodule.h"
  #include "column.h"
  #include "strbuf.h"
 +#include "utf8.h"
  
 -static char cut_line[] =
 +static const char cut_line[] =
  "------------------------ >8 ------------------------\n";
  
  static char default_wt_status_colors[][COLOR_MAXLEN] = {
@@@ -245,89 -244,26 +245,89 @@@ static void wt_status_print_trailer(str
  
  #define quote_path quote_path_relative
  
 +static const char *wt_status_unmerged_status_string(int stagemask)
 +{
 +      switch (stagemask) {
 +      case 1:
 +              return _("both deleted:");
 +      case 2:
 +              return _("added by us:");
 +      case 3:
 +              return _("deleted by them:");
 +      case 4:
 +              return _("added by them:");
 +      case 5:
 +              return _("deleted by us:");
 +      case 6:
 +              return _("both added:");
 +      case 7:
 +              return _("both modified:");
 +      default:
 +              die(_("bug: unhandled unmerged status %x"), stagemask);
 +      }
 +}
 +
 +static const char *wt_status_diff_status_string(int status)
 +{
 +      switch (status) {
 +      case DIFF_STATUS_ADDED:
 +              return _("new file:");
 +      case DIFF_STATUS_COPIED:
 +              return _("copied:");
 +      case DIFF_STATUS_DELETED:
 +              return _("deleted:");
 +      case DIFF_STATUS_MODIFIED:
 +              return _("modified:");
 +      case DIFF_STATUS_RENAMED:
 +              return _("renamed:");
 +      case DIFF_STATUS_TYPE_CHANGED:
 +              return _("typechange:");
 +      case DIFF_STATUS_UNKNOWN:
 +              return _("unknown:");
 +      case DIFF_STATUS_UNMERGED:
 +              return _("unmerged:");
 +      default:
 +              return NULL;
 +      }
 +}
 +
 +static int maxwidth(const char *(*label)(int), int minval, int maxval)
 +{
 +      int result = 0, i;
 +
 +      for (i = minval; i <= maxval; i++) {
 +              const char *s = label(i);
 +              int len = s ? utf8_strwidth(s) : 0;
 +              if (len > result)
 +                      result = len;
 +      }
 +      return result;
 +}
 +
  static void wt_status_print_unmerged_data(struct wt_status *s,
                                          struct string_list_item *it)
  {
        const char *c = color(WT_STATUS_UNMERGED, s);
        struct wt_status_change_data *d = it->util;
        struct strbuf onebuf = STRBUF_INIT;
 -      const char *one, *how = _("bug");
 +      static char *padding;
 +      static int label_width;
 +      const char *one, *how;
 +      int len;
 +
 +      if (!padding) {
 +              label_width = maxwidth(wt_status_unmerged_status_string, 1, 7);
 +              label_width += strlen(" ");
 +              padding = xmallocz(label_width);
 +              memset(padding, ' ', label_width);
 +      }
  
        one = quote_path(it->string, s->prefix, &onebuf);
        status_printf(s, color(WT_STATUS_HEADER, s), "\t");
 -      switch (d->stagemask) {
 -      case 1: how = _("both deleted:"); break;
 -      case 2: how = _("added by us:"); break;
 -      case 3: how = _("deleted by them:"); break;
 -      case 4: how = _("added by them:"); break;
 -      case 5: how = _("deleted by us:"); break;
 -      case 6: how = _("both added:"); break;
 -      case 7: how = _("both modified:"); break;
 -      }
 -      status_printf_more(s, c, "%-20s%s\n", how, one);
 +
 +      how = wt_status_unmerged_status_string(d->stagemask);
 +      len = label_width - utf8_strwidth(how);
 +      status_printf_more(s, c, "%s%.*s%s\n", how, len, padding, one);
        strbuf_release(&onebuf);
  }
  
@@@ -343,18 -279,6 +343,18 @@@ static void wt_status_print_change_data
        const char *one, *two;
        struct strbuf onebuf = STRBUF_INIT, twobuf = STRBUF_INIT;
        struct strbuf extra = STRBUF_INIT;
 +      static char *padding;
 +      static int label_width;
 +      const char *what;
 +      int len;
 +
 +      if (!padding) {
 +              /* If DIFF_STATUS_* uses outside the range [A..Z], we're in trouble */
 +              label_width = maxwidth(wt_status_diff_status_string, 'A', 'Z');
 +              label_width += strlen(" ");
 +              padding = xmallocz(label_width);
 +              memset(padding, ' ', label_width);
 +      }
  
        one_name = two_name = it->string;
        switch (change_type) {
        two = quote_path(two_name, s->prefix, &twobuf);
  
        status_printf(s, color(WT_STATUS_HEADER, s), "\t");
 -      switch (status) {
 -      case DIFF_STATUS_ADDED:
 -              status_printf_more(s, c, _("new file:   %s"), one);
 -              break;
 -      case DIFF_STATUS_COPIED:
 -              status_printf_more(s, c, _("copied:     %s -> %s"), one, two);
 -              break;
 -      case DIFF_STATUS_DELETED:
 -              status_printf_more(s, c, _("deleted:    %s"), one);
 -              break;
 -      case DIFF_STATUS_MODIFIED:
 -              status_printf_more(s, c, _("modified:   %s"), one);
 -              break;
 -      case DIFF_STATUS_RENAMED:
 -              status_printf_more(s, c, _("renamed:    %s -> %s"), one, two);
 -              break;
 -      case DIFF_STATUS_TYPE_CHANGED:
 -              status_printf_more(s, c, _("typechange: %s"), one);
 -              break;
 -      case DIFF_STATUS_UNKNOWN:
 -              status_printf_more(s, c, _("unknown:    %s"), one);
 -              break;
 -      case DIFF_STATUS_UNMERGED:
 -              status_printf_more(s, c, _("unmerged:   %s"), one);
 -              break;
 -      default:
 +      what = wt_status_diff_status_string(status);
 +      if (!what)
                die(_("bug: unhandled diff status %c"), status);
 -      }
 +      len = label_width - utf8_strwidth(what);
 +      assert(len >= 0);
 +      if (status == DIFF_STATUS_COPIED || status == DIFF_STATUS_RENAMED)
 +              status_printf_more(s, c, "%s%.*s%s -> %s",
 +                                 what, len, padding, one, two);
 +      else
 +              status_printf_more(s, c, "%s%.*s%s",
 +                                 what, len, padding, one);
        if (extra.len) {
                status_printf_more(s, color(WT_STATUS_HEADER, s), "%s", extra.buf);
                strbuf_release(&extra);
@@@ -543,7 -484,7 +543,7 @@@ static void wt_status_collect_changes_i
                struct wt_status_change_data *d;
                const struct cache_entry *ce = active_cache[i];
  
 -              if (!ce_path_match(ce, &s->pathspec))
 +              if (!ce_path_match(ce, &s->pathspec, NULL))
                        continue;
                it = string_list_insert(&s->change, ce->name);
                d = it->util;
@@@ -585,7 -526,7 +585,7 @@@ static void wt_status_collect_untracked
        for (i = 0; i < dir.nr; i++) {
                struct dir_entry *ent = dir.entries[i];
                if (cache_name_is_other(ent->name, ent->len) &&
 -                  match_pathspec_depth(&s->pathspec, ent->name, ent->len, 0, NULL))
 +                  dir_path_match(ent, &s->pathspec, 0, NULL))
                        string_list_insert(&s->untracked, ent->name);
                free(ent);
        }
        for (i = 0; i < dir.ignored_nr; i++) {
                struct dir_entry *ent = dir.ignored[i];
                if (cache_name_is_other(ent->name, ent->len) &&
 -                  match_pathspec_depth(&s->pathspec, ent->name, ent->len, 0, NULL))
 +                  dir_path_match(ent, &s->pathspec, 0, NULL))
                        string_list_insert(&s->ignored, ent->name);
                free(ent);
        }
@@@ -841,17 -782,6 +841,17 @@@ void wt_status_truncate_message_at_cut_
        strbuf_release(&pattern);
  }
  
 +void wt_status_add_cut_line(FILE *fp)
 +{
 +      const char *explanation = _("Do not touch the line above.\nEverything below will be removed.");
 +      struct strbuf buf = STRBUF_INIT;
 +
 +      fprintf(fp, "%c %s", comment_line_char, cut_line);
 +      strbuf_add_commented_lines(&buf, explanation, strlen(explanation));
 +      fputs(buf.buf, fp);
 +      strbuf_release(&buf);
 +}
 +
  static void wt_status_print_verbose(struct wt_status *s)
  {
        struct rev_info rev;
         * diff before committing.
         */
        if (s->fp != stdout) {
 -              const char *explanation = _("Do not touch the line above.\nEverything below will be removed.");
 -              struct strbuf buf = STRBUF_INIT;
 -
                rev.diffopt.use_color = 0;
 -              fprintf(s->fp, "%c %s", comment_line_char, cut_line);
 -              strbuf_add_commented_lines(&buf, explanation, strlen(explanation));
 -              fputs(buf.buf, s->fp);
 -              strbuf_release(&buf);
 +              wt_status_add_cut_line(s->fp);
        }
        run_diff_index(&rev, 1);
  }
@@@ -892,7 -828,7 +892,7 @@@ static void wt_status_print_tracking(st
        int i;
  
        assert(s->branch && !s->is_initial);
 -      if (prefixcmp(s->branch, "refs/heads/"))
 +      if (!starts_with(s->branch, "refs/heads/"))
                return;
        branch = branch_get(s->branch + 11);
        if (!format_tracking_info(branch, &sb))
@@@ -1151,9 -1087,9 +1151,9 @@@ static char *read_and_strip_branch(cons
                strbuf_setlen(&sb, sb.len - 1);
        if (!sb.len)
                goto got_nothing;
 -      if (!prefixcmp(sb.buf, "refs/heads/"))
 +      if (starts_with(sb.buf, "refs/heads/"))
                strbuf_remove(&sb,0, strlen("refs/heads/"));
 -      else if (!prefixcmp(sb.buf, "refs/"))
 +      else if (starts_with(sb.buf, "refs/"))
                ;
        else if (!get_sha1_hex(sb.buf, sha1)) {
                const char *abbrev;
@@@ -1183,7 -1119,7 +1183,7 @@@ static int grab_1st_switch(unsigned cha
        struct grab_1st_switch_cbdata *cb = cb_data;
        const char *target = NULL, *end;
  
 -      if (prefixcmp(message, "checkout: moving from "))
 +      if (!starts_with(message, "checkout: moving from "))
                return 0;
        message += strlen("checkout: moving from ");
        target = strstr(message, " to ");
@@@ -1218,9 -1154,9 +1218,9 @@@ static void wt_status_get_detached_from
             ((commit = lookup_commit_reference_gently(sha1, 1)) != NULL &&
              !hashcmp(cb.nsha1, commit->object.sha1)))) {
                int ofs;
 -              if (!prefixcmp(ref, "refs/tags/"))
 +              if (starts_with(ref, "refs/tags/"))
                        ofs = strlen("refs/tags/");
 -              else if (!prefixcmp(ref, "refs/remotes/"))
 +              else if (starts_with(ref, "refs/remotes/"))
                        ofs = strlen("refs/remotes/");
                else
                        ofs = 0;
@@@ -1309,7 -1245,7 +1309,7 @@@ void wt_status_print(struct wt_status *
        if (s->branch) {
                const char *on_what = _("On branch ");
                const char *branch_name = s->branch;
 -              if (!prefixcmp(branch_name, "refs/heads/"))
 +              if (starts_with(branch_name, "refs/heads/"))
                        branch_name += 11;
                else if (!strcmp(branch_name, "HEAD")) {
                        branch_status_color = color(WT_STATUS_NOBRANCH, s);
@@@ -1510,7 -1446,7 +1510,7 @@@ static void wt_shortstatus_print_tracki
                return;
        branch_name = s->branch;
  
 -      if (!prefixcmp(branch_name, "refs/heads/"))
 +      if (starts_with(branch_name, "refs/heads/"))
                branch_name += 11;
        else if (!strcmp(branch_name, "HEAD")) {
                branch_name = _("HEAD (no branch)");
                return;
        }
  
+ #define LABEL(string) (s->no_gettext ? (string) : _(string))
        color_fprintf(s->fp, header_color, " [");
        if (upstream_is_gone) {
-               color_fprintf(s->fp, header_color, _("gone"));
+               color_fprintf(s->fp, header_color, LABEL(N_("gone")));
        } else if (!num_ours) {
-               color_fprintf(s->fp, header_color, _("behind "));
+               color_fprintf(s->fp, header_color, LABEL(N_("behind ")));
                color_fprintf(s->fp, branch_color_remote, "%d", num_theirs);
        } else if (!num_theirs) {
-               color_fprintf(s->fp, header_color, _("ahead "));
+               color_fprintf(s->fp, header_color, LABEL(N_(("ahead "))));
                color_fprintf(s->fp, branch_color_local, "%d", num_ours);
        } else {
-               color_fprintf(s->fp, header_color, _("ahead "));
+               color_fprintf(s->fp, header_color, LABEL(N_(("ahead "))));
                color_fprintf(s->fp, branch_color_local, "%d", num_ours);
-               color_fprintf(s->fp, header_color, _(", behind "));
+               color_fprintf(s->fp, header_color, ", %s", LABEL(N_("behind ")));
                color_fprintf(s->fp, branch_color_remote, "%d", num_theirs);
        }
  
@@@ -1604,5 -1542,6 +1606,6 @@@ void wt_porcelain_print(struct wt_statu
        s->use_color = 0;
        s->relative_paths = 0;
        s->prefix = NULL;
+       s->no_gettext = 1;
        wt_shortstatus_print(s);
  }
diff --combined wt-status.h
index b56ce3f0355f3a1e188c7d9bd44ea90f0d06d76f,82f6ce64f8312f9d02e6dc08d46ec8af96a311a3..283a9fef0335ce272c6799a5af17274e4798e15f
@@@ -50,6 -50,7 +50,7 @@@ struct wt_status 
        enum commit_whence whence;
        int nowarn;
        int use_color;
+       int no_gettext;
        int display_comment_prefix;
        int relative_paths;
        int submodule_summary;
@@@ -92,7 -93,6 +93,7 @@@ struct wt_status_state 
  };
  
  void wt_status_truncate_message_at_cut_line(struct strbuf *);
 +void wt_status_add_cut_line(FILE *fp);
  void wt_status_prepare(struct wt_status *s);
  void wt_status_print(struct wt_status *s);
  void wt_status_collect(struct wt_status *s);