{"thread":{"id":"36144","subject":"[PATCH v2 0/4] status: allow label strings to be translated","startedAt":"2014-03-12T21:19:30Z","lastAt":"2014-03-12T21:19:34Z","messageCount":5,"participants":["Junio C Hamano"],"isPatch":true,"patchVersion":2,"patchTotal":4},"messages":[{"id":"236634","messageId":"1394659174-9143-1-git-send-email-gitster@pobox.com","threadId":"36144","inReplyTo":null,"subject":"[PATCH v2 0/4] status: allow label strings to be translated","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-03-12T21:19:30Z","receivedAt":"2014-03-12T21:19:30Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"So here is my attempt to clean-up what Jonathan posted in\n$gmane/239537 as \"how about this?\" patch.\n\nThe first one (full label string) fixes up 3651e45c (wt-status: take\nthe alignment burden off translators, 2013-11-05) to include colon\nback to translatable string again, while retaining its label alignment\nlogic.\n\nThe second (extract the code) is taken from Jonathan's $gmane/239537\nas a separate patch.\n\nThe third is essentially the remainder of Jonathan's $gmane/239537,\nwith one small fix s/strlen/utf8_width/; to teach the code that\nshows unmerged paths the same label alignment logic Duy added in\n3651e45c for the tracked paths, while retaining the \"at least 20\ncolumns\" floor to avoid the churn to the tests.\n\nAnd the last lifts the \"at least 20 columns\" floor.\n\nJonathan Nieder (2):\n  wt-status: extract the code to compute width for labels\n  wt-status: i18n of section labels\n\nJunio C Hamano (2):\n  wt-status: make full label string to be subject to l10n\n  wt-status: lift the artificual \"at least 20 columns\" floor\n\n t/t7060-wtstatus.sh    |  14 +++---\n t/t7512-status-help.sh |  12 ++---\n wt-status.c            | 117 +++++++++++++++++++++++++++++++------------------\n 3 files changed, 88 insertions(+), 55 deletions(-)\n\n-- \n1.9.0-293-gd838d6f\n"},{"id":"236635","messageId":"1394659174-9143-2-git-send-email-gitster@pobox.com","threadId":"36144","inReplyTo":"1394659174-9143-1-git-send-email-gitster@pobox.com","subject":"[PATCH v2 1/4] wt-status: make full label string to be subject to l10n","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-03-12T21:19:31Z","receivedAt":"2014-03-12T21:19:31Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Earlier in 3651e45c (wt-status: take the alignment burden off\ntranslators, 2013-11-05), we assumed that it is OK to make the\nstring before the colon in a label string we give as the section\nheader of various kinds of changes (e.g. \"new file:\") translatable.\n\nThis assumption apparently does not hold for some languages,\ne.g. ones that want to have spaces around the colon.\n\nAlso introduce a static label_width to avoid having to run\nstrlen(padding) over and over.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n wt-status.c | 35 +++++++++++++++++------------------\n 1 file changed, 17 insertions(+), 18 deletions(-)\n\ndiff --git a/wt-status.c b/wt-status.c\nindex 4e55810..9cf7028 100644\n--- a/wt-status.c\n+++ b/wt-status.c\n@@ -272,21 +272,21 @@ static const char *wt_status_diff_status_string(int status)\n {\n \tswitch (status) {\n \tcase DIFF_STATUS_ADDED:\n-\t\treturn _(\"new file\");\n+\t\treturn _(\"new file:\");\n \tcase DIFF_STATUS_COPIED:\n-\t\treturn _(\"copied\");\n+\t\treturn _(\"copied:\");\n \tcase DIFF_STATUS_DELETED:\n-\t\treturn _(\"deleted\");\n+\t\treturn _(\"deleted:\");\n \tcase DIFF_STATUS_MODIFIED:\n-\t\treturn _(\"modified\");\n+\t\treturn _(\"modified:\");\n \tcase DIFF_STATUS_RENAMED:\n-\t\treturn _(\"renamed\");\n+\t\treturn _(\"renamed:\");\n \tcase DIFF_STATUS_TYPE_CHANGED:\n-\t\treturn _(\"typechange\");\n+\t\treturn _(\"typechange:\");\n \tcase DIFF_STATUS_UNKNOWN:\n-\t\treturn _(\"unknown\");\n+\t\treturn _(\"unknown:\");\n \tcase DIFF_STATUS_UNMERGED:\n-\t\treturn _(\"unmerged\");\n+\t\treturn _(\"unmerged:\");\n \tdefault:\n \t\treturn NULL;\n \t}\n@@ -305,21 +305,21 @@ static void wt_status_print_change_data(struct wt_status *s,\n \tstruct strbuf onebuf = STRBUF_INIT, twobuf = STRBUF_INIT;\n \tstruct strbuf extra = STRBUF_INIT;\n \tstatic char *padding;\n+\tstatic int label_width;\n \tconst char *what;\n \tint len;\n \n \tif (!padding) {\n-\t\tint width = 0;\n \t\t/* If DIFF_STATUS_* uses outside this range, we're in trouble */\n \t\tfor (status = 'A'; status <= 'Z'; status++) {\n \t\t\twhat = wt_status_diff_status_string(status);\n \t\t\tlen = what ? strlen(what) : 0;\n-\t\t\tif (len > width)\n-\t\t\t\twidth = len;\n+\t\t\tif (len > label_width)\n+\t\t\t\tlabel_width = len;\n \t\t}\n-\t\twidth += 2;\t/* colon and a space */\n-\t\tpadding = xmallocz(width);\n-\t\tmemset(padding, ' ', width);\n+\t\tlabel_width += strlen(\" \");\n+\t\tpadding = xmallocz(label_width);\n+\t\tmemset(padding, ' ', label_width);\n \t}\n \n \tone_name = two_name = it->string;\n@@ -355,14 +355,13 @@ static void wt_status_print_change_data(struct wt_status *s,\n \twhat = wt_status_diff_status_string(status);\n \tif (!what)\n \t\tdie(_(\"bug: unhandled diff status %c\"), status);\n-\t/* 1 for colon, which is not part of \"what\" */\n-\tlen = strlen(padding) - (utf8_strwidth(what) + 1);\n+\tlen = label_width - utf8_strwidth(what);\n \tassert(len >= 0);\n \tif (status == DIFF_STATUS_COPIED || status == DIFF_STATUS_RENAMED)\n-\t\tstatus_printf_more(s, c, \"%s:%.*s%s -> %s\",\n+\t\tstatus_printf_more(s, c, \"%s%.*s%s -> %s\",\n \t\t\t\t   what, len, padding, one, two);\n \telse\n-\t\tstatus_printf_more(s, c, \"%s:%.*s%s\",\n+\t\tstatus_printf_more(s, c, \"%s%.*s%s\",\n \t\t\t\t   what, len, padding, one);\n \tif (extra.len) {\n \t\tstatus_printf_more(s, color(WT_STATUS_HEADER, s), \"%s\", extra.buf);\n-- \n1.9.0-293-gd838d6f\n"},{"id":"236637","messageId":"1394659174-9143-3-git-send-email-gitster@pobox.com","threadId":"36144","inReplyTo":"1394659174-9143-1-git-send-email-gitster@pobox.com","subject":"[PATCH v2 2/4] wt-status: extract the code to compute width for labels","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-03-12T21:19:32Z","receivedAt":"2014-03-12T21:19:32Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"From: Jonathan Nieder <jrnieder@gmail.com>\n\nFrom: Jonathan Nieder <jrnieder@gmail.com>\nDate: Thu, 19 Dec 2013 11:43:19 -0800\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n wt-status.c | 22 +++++++++++++++-------\n 1 file changed, 15 insertions(+), 7 deletions(-)\n\ndiff --git a/wt-status.c b/wt-status.c\nindex 9cf7028..db98c52 100644\n--- a/wt-status.c\n+++ b/wt-status.c\n@@ -292,6 +292,19 @@ static const char *wt_status_diff_status_string(int status)\n \t}\n }\n \n+static int maxwidth(const char *(*label)(int), int minval, int maxval)\n+{\n+\tint result = 0, i;\n+\n+\tfor (i = minval; i <= maxval; i++) {\n+\t\tconst char *s = label(i);\n+\t\tint len = s ? utf8_strwidth(s) : 0;\n+\t\tif (len > result)\n+\t\t\tresult = len;\n+\t}\n+\treturn result;\n+}\n+\n static void wt_status_print_change_data(struct wt_status *s,\n \t\t\t\t\tint change_type,\n \t\t\t\t\tstruct string_list_item *it)\n@@ -310,13 +323,8 @@ static void wt_status_print_change_data(struct wt_status *s,\n \tint len;\n \n \tif (!padding) {\n-\t\t/* If DIFF_STATUS_* uses outside this range, we're in trouble */\n-\t\tfor (status = 'A'; status <= 'Z'; status++) {\n-\t\t\twhat = wt_status_diff_status_string(status);\n-\t\t\tlen = what ? strlen(what) : 0;\n-\t\t\tif (len > label_width)\n-\t\t\t\tlabel_width = len;\n-\t\t}\n+\t\t/* If DIFF_STATUS_* uses outside the range [A..Z], we're in trouble */\n+\t\tlabel_width = maxwidth(wt_status_diff_status_string, 'A', 'Z');\n \t\tlabel_width += strlen(\" \");\n \t\tpadding = xmallocz(label_width);\n \t\tmemset(padding, ' ', label_width);\n-- \n1.9.0-293-gd838d6f\n"},{"id":"236636","messageId":"1394659174-9143-4-git-send-email-gitster@pobox.com","threadId":"36144","inReplyTo":"1394659174-9143-1-git-send-email-gitster@pobox.com","subject":"[PATCH v2 3/4] wt-status: i18n of section labels","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-03-12T21:19:33Z","receivedAt":"2014-03-12T21:19:33Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"From: Jonathan Nieder <jrnieder@gmail.com>\n\nFrom: Jonathan Nieder <jrnieder@gmail.com>\nDate: Thu, 19 Dec 2013 11:43:19 -0800\n\nThe original code assumes that:\n\n (1) the number of bytes written is the width of a string, so they\n     can line up;\n\n (2) the \"how\" string is always <= 19 bytes.\n\nNeither of which we should assume.\n\nUsing the same approach as the earlier 3651e45c (wt-status: take the\nalignment burden off translators, 2013-11-05), compute the necessary\ncolumn width to hold the longest label and use that for alignment.\n\ncf. http://bugs.debian.org/725777\n\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\nHelped-by: Sandy Carter\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n wt-status.c | 66 +++++++++++++++++++++++++++++++++++++++++++------------------\n 1 file changed, 47 insertions(+), 19 deletions(-)\n\ndiff --git a/wt-status.c b/wt-status.c\nindex db98c52..b1b018e 100644\n--- a/wt-status.c\n+++ b/wt-status.c\n@@ -245,27 +245,26 @@ static void wt_status_print_trailer(struct wt_status *s)\n \n #define quote_path quote_path_relative\n \n-static void wt_status_print_unmerged_data(struct wt_status *s,\n-\t\t\t\t\t  struct string_list_item *it)\n+static const char *wt_status_unmerged_status_string(int stagemask)\n {\n-\tconst char *c = color(WT_STATUS_UNMERGED, s);\n-\tstruct wt_status_change_data *d = it->util;\n-\tstruct strbuf onebuf = STRBUF_INIT;\n-\tconst char *one, *how = _(\"bug\");\n-\n-\tone = quote_path(it->string, s->prefix, &onebuf);\n-\tstatus_printf(s, color(WT_STATUS_HEADER, s), \"\\t\");\n-\tswitch (d->stagemask) {\n-\tcase 1: how = _(\"both deleted:\"); break;\n-\tcase 2: how = _(\"added by us:\"); break;\n-\tcase 3: how = _(\"deleted by them:\"); break;\n-\tcase 4: how = _(\"added by them:\"); break;\n-\tcase 5: how = _(\"deleted by us:\"); break;\n-\tcase 6: how = _(\"both added:\"); break;\n-\tcase 7: how = _(\"both modified:\"); break;\n+\tswitch (stagemask) {\n+\tcase 1:\n+\t\treturn _(\"both deleted:\");\n+\tcase 2:\n+\t\treturn _(\"added by us:\");\n+\tcase 3:\n+\t\treturn _(\"deleted by them:\");\n+\tcase 4:\n+\t\treturn _(\"added by them:\");\n+\tcase 5:\n+\t\treturn _(\"deleted by us:\");\n+\tcase 6:\n+\t\treturn _(\"both added:\");\n+\tcase 7:\n+\t\treturn _(\"both modified:\");\n+\tdefault:\n+\t\tdie(_(\"bug: unhandled unmerged status %x\"), stagemask);\n \t}\n-\tstatus_printf_more(s, c, \"%-20s%s\\n\", how, one);\n-\tstrbuf_release(&onebuf);\n }\n \n static const char *wt_status_diff_status_string(int status)\n@@ -305,6 +304,35 @@ static int maxwidth(const char *(*label)(int), int minval, int maxval)\n \treturn result;\n }\n \n+static void wt_status_print_unmerged_data(struct wt_status *s,\n+\t\t\t\t\t  struct string_list_item *it)\n+{\n+\tconst char *c = color(WT_STATUS_UNMERGED, s);\n+\tstruct wt_status_change_data *d = it->util;\n+\tstruct strbuf onebuf = STRBUF_INIT;\n+\tstatic char *padding;\n+\tstatic int label_width;\n+\tconst char *one, *how;\n+\tint len;\n+\n+\tif (!padding) {\n+\t\tlabel_width = maxwidth(wt_status_unmerged_status_string, 1, 7);\n+\t\tlabel_width += strlen(\" \");\n+\t\tif (label_width < 20)\n+\t\t\tlabel_width = 20;\n+\t\tpadding = xmallocz(label_width);\n+\t\tmemset(padding, ' ', label_width);\n+\t}\n+\n+\tone = quote_path(it->string, s->prefix, &onebuf);\n+\tstatus_printf(s, color(WT_STATUS_HEADER, s), \"\\t\");\n+\n+\thow = wt_status_unmerged_status_string(d->stagemask);\n+\tlen = label_width - utf8_strwidth(how);\n+\tstatus_printf_more(s, c, \"%s%.*s%s\\n\", how, len, padding, one);\n+\tstrbuf_release(&onebuf);\n+}\n+\n static void wt_status_print_change_data(struct wt_status *s,\n \t\t\t\t\tint change_type,\n \t\t\t\t\tstruct string_list_item *it)\n-- \n1.9.0-293-gd838d6f\n"},{"id":"236638","messageId":"1394659174-9143-5-git-send-email-gitster@pobox.com","threadId":"36144","inReplyTo":"1394659174-9143-1-git-send-email-gitster@pobox.com","subject":"[PATCH v2 4/4] wt-status: lift the artificual \"at least 20 columns\" floor","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-03-12T21:19:34Z","receivedAt":"2014-03-12T21:19:34Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"When we show unmerged paths, we had an artificial 20 columns floor\nfor the width of labels (e.g. \"both deleted:\") shown next to the\npathnames.  Depending on the locale, this may result in a label that\nis too wide when all the label strings are way shorter than 20\ncolumns, or no-op when a label string is longer than 20 columns.\n\nJust drop the artificial floor.  The screen real estate is better\nutilized this way when all the strings are shorter.\n\nAdjust the tests to this change.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n t/t7060-wtstatus.sh    | 14 +++++++-------\n t/t7512-status-help.sh | 12 ++++++------\n wt-status.c            |  2 --\n 3 files changed, 13 insertions(+), 15 deletions(-)\n\ndiff --git a/t/t7060-wtstatus.sh b/t/t7060-wtstatus.sh\nindex 7d467c0..741ec08 100755\n--- a/t/t7060-wtstatus.sh\n+++ b/t/t7060-wtstatus.sh\n@@ -38,7 +38,7 @@ You have unmerged paths.\n Unmerged paths:\n   (use \"git add/rm <file>...\" as appropriate to mark resolution)\n \n-\tdeleted by us:      foo\n+\tdeleted by us:   foo\n \n no changes added to commit (use \"git add\" and/or \"git commit -a\")\n EOF\n@@ -142,8 +142,8 @@ You have unmerged paths.\n Unmerged paths:\n   (use \"git add/rm <file>...\" as appropriate to mark resolution)\n \n-\tboth added:         conflict.txt\n-\tdeleted by them:    main.txt\n+\tboth added:      conflict.txt\n+\tdeleted by them: main.txt\n \n no changes added to commit (use \"git add\" and/or \"git commit -a\")\n EOF\n@@ -175,9 +175,9 @@ You have unmerged paths.\n Unmerged paths:\n   (use \"git add/rm <file>...\" as appropriate to mark resolution)\n \n-\tboth deleted:       main.txt\n-\tadded by them:      sub_master.txt\n-\tadded by us:        sub_second.txt\n+\tboth deleted:    main.txt\n+\tadded by them:   sub_master.txt\n+\tadded by us:     sub_second.txt\n \n no changes added to commit (use \"git add\" and/or \"git commit -a\")\n EOF\n@@ -203,7 +203,7 @@ Changes to be committed:\n Unmerged paths:\n   (use \"git rm <file>...\" to mark resolution)\n \n-\tboth deleted:       main.txt\n+\tboth deleted:    main.txt\n \n Untracked files not listed (use -u option to show untracked files)\n EOF\ndiff --git a/t/t7512-status-help.sh b/t/t7512-status-help.sh\nindex 3cec57a..68ad2d7 100755\n--- a/t/t7512-status-help.sh\n+++ b/t/t7512-status-help.sh\n@@ -33,7 +33,7 @@ You have unmerged paths.\n Unmerged paths:\n   (use \"git add <file>...\" to mark resolution)\n \n-\tboth modified:      main.txt\n+\tboth modified:   main.txt\n \n no changes added to commit (use \"git add\" and/or \"git commit -a\")\n EOF\n@@ -87,7 +87,7 @@ Unmerged paths:\n   (use \"git reset HEAD <file>...\" to unstage)\n   (use \"git add <file>...\" to mark resolution)\n \n-\tboth modified:      main.txt\n+\tboth modified:   main.txt\n \n no changes added to commit (use \"git add\" and/or \"git commit -a\")\n EOF\n@@ -146,7 +146,7 @@ Unmerged paths:\n   (use \"git reset HEAD <file>...\" to unstage)\n   (use \"git add <file>...\" to mark resolution)\n \n-\tboth modified:      main.txt\n+\tboth modified:   main.txt\n \n no changes added to commit (use \"git add\" and/or \"git commit -a\")\n EOF\n@@ -602,7 +602,7 @@ rebase in progress; onto $ONTO\n You are currently rebasing branch '\\''statushints_disabled'\\'' on '\\''$ONTO'\\''.\n \n Unmerged paths:\n-\tboth modified:      main.txt\n+\tboth modified:   main.txt\n \n no changes added to commit\n EOF\n@@ -636,7 +636,7 @@ You are currently cherry-picking commit $TO_CHERRY_PICK.\n Unmerged paths:\n   (use \"git add <file>...\" to mark resolution)\n \n-\tboth modified:      main.txt\n+\tboth modified:   main.txt\n \n no changes added to commit (use \"git add\" and/or \"git commit -a\")\n EOF\n@@ -707,7 +707,7 @@ Unmerged paths:\n   (use \"git reset HEAD <file>...\" to unstage)\n   (use \"git add <file>...\" to mark resolution)\n \n-\tboth modified:      to-revert.txt\n+\tboth modified:   to-revert.txt\n \n no changes added to commit (use \"git add\" and/or \"git commit -a\")\n EOF\ndiff --git a/wt-status.c b/wt-status.c\nindex b1b018e..6f3ed67 100644\n--- a/wt-status.c\n+++ b/wt-status.c\n@@ -318,8 +318,6 @@ static void wt_status_print_unmerged_data(struct wt_status *s,\n \tif (!padding) {\n \t\tlabel_width = maxwidth(wt_status_unmerged_status_string, 1, 7);\n \t\tlabel_width += strlen(\" \");\n-\t\tif (label_width < 20)\n-\t\t\tlabel_width = 20;\n \t\tpadding = xmallocz(label_width);\n \t\tmemset(padding, ' ', label_width);\n \t}\n-- \n1.9.0-293-gd838d6f\n"}]}