git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: git: problematic git status output with some translations (such as fr_FR)
       [not found] ` <20131219104613.GA18379@x230-buxy.home.ouaza.com>
@ 2013-12-19 19:43   ` Jonathan Nieder
  2013-12-19 20:46     ` Junio C Hamano
  2014-03-12 18:53     ` Junio C Hamano
  0 siblings, 2 replies; 12+ messages in thread
From: Jonathan Nieder @ 2013-12-19 19:43 UTC (permalink / raw)
  To: Raphael Hertzog
  Cc: git, Ævar Arnfjörð Bjarmason,
	Nguyễn Thái Ngọc Duy

Raphaël Hertzog wrote[1]:

> Here's an example of the problematic output:
[...]
> #	modifié des deux côtés :debian/control

Thanks for the ping, and sorry to leave this hanging before.

[...]
> --- a/wt-status.c
> +++ b/wt-status.c
> @@ -255,7 +255,7 @@ static void wt_status_print_unmerged_data(struct wt_status *s,
>  	case 6: how = _("both added:"); break;
>  	case 7: how = _("both modified:"); break;
>  	}
> -	status_printf_more(s, c, "%-20s%s\n", how, one);
> +	status_printf_more(s, c, "%-19s %s\n", how, one);

It looks like the original code is assuming that

 (1) the number of bytes written is the width of a string, so they can
     line up

 (2) the "how" string is always <= 19 bytes

Both assumptions are problematic.

Perhaps the value '20' should be dynamic (e.g.,

	min(20,
	    1 + max(utf8_strwidth(all 'how' strings
	                          in the current UI language)))

) to allow the text to always line up?  Ever since 3651e45c
(wt-status: take the alignment burden off translators, 2013-11-05),
wt_status_print_change_data() picks its width dynamically for the same
reason.  So, something like the following (untested)?

This includes the colon in the translated string, to make it easier to
remember to keep the non-breaking space before it.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>

[1] http://bugs.debian.org/725777

diff --git i/wt-status.c w/wt-status.c
index 4e55810..7b0e5b8 100644
--- i/wt-status.c
+++ w/wt-status.c
@@ -245,27 +245,26 @@ static void wt_status_print_trailer(struct wt_status *s)
 
 #define quote_path quote_path_relative
 
-static void wt_status_print_unmerged_data(struct wt_status *s,
-					  struct string_list_item *it)
+static const char *wt_status_unmerged_status_string(int stagemask)
 {
-	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");
-
-	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;
+	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:
+		return NULL;
 	}
-	status_printf_more(s, c, "%-20s%s\n", how, one);
-	strbuf_release(&onebuf);
 }
 
 static const char *wt_status_diff_status_string(int status)
@@ -292,6 +291,48 @@ static const char *wt_status_diff_status_string(int status)
 	}
 }
 
+static int maxwidth(const char *(*label)(int), int minval, int maxval)
+{
+	const char *s;
+	int result = 0, i;
+
+	for (i = minval; i <= maxval; i++) {
+		const char *s = label(i);
+		int len = s ? strlen(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;
+	static char *padding;
+	const char *one, *how;
+	int len;
+
+	if (!padding) {
+		int width = maxwidth(wt_status_unmerged_status_string, 1, 7);
+		width += strlen(" ");
+		padding = xmallocz(width);
+		memset(padding, ' ', width);
+	}
+
+	one = quote_path(it->string, s->prefix, &onebuf);
+	status_printf(s, color(WT_STATUS_HEADER, s), "\t");
+
+	how = wt_status_unmerged_status_string(d->stagemask);
+	if (!how)
+		how = _("bug");
+	len = strlen(padding) - utf8_strwidth(how);
+	status_printf_more(s, c, "%s%.*s%s\n", how, len, padding, one);
+	strbuf_release(&onebuf);
+}
+
 static void wt_status_print_change_data(struct wt_status *s,
 					int change_type,
 					struct string_list_item *it)
@@ -309,14 +350,8 @@ static void wt_status_print_change_data(struct wt_status *s,
 	int len;
 
 	if (!padding) {
-		int width = 0;
-		/* If DIFF_STATUS_* uses outside this range, we're in trouble */
-		for (status = 'A'; status <= 'Z'; status++) {
-			what = wt_status_diff_status_string(status);
-			len = what ? strlen(what) : 0;
-			if (len > width)
-				width = len;
-		}
+		/* If DIFF_STATUS_* uses outside the range [A..Z], we're in trouble */
+		int width = maxwidth(wt_status_diff_status_string, 'A', 'Z');
 		width += 2;	/* colon and a space */
 		padding = xmallocz(width);
 		memset(padding, ' ', width);

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: git: problematic git status output with some translations (such as fr_FR)
  2013-12-19 19:43   ` git: problematic git status output with some translations (such as fr_FR) Jonathan Nieder
@ 2013-12-19 20:46     ` Junio C Hamano
  2013-12-19 20:50       ` Jonathan Nieder
  2014-03-12 18:53     ` Junio C Hamano
  1 sibling, 1 reply; 12+ messages in thread
From: Junio C Hamano @ 2013-12-19 20:46 UTC (permalink / raw)
  To: Jonathan Nieder
  Cc: Raphael Hertzog, git, Ævar Arnfjörð Bjarmason,
	Nguyễn Thái Ngọc Duy

Jonathan Nieder <jrnieder@gmail.com> writes:

> This includes the colon in the translated string, to make it easier to
> remember to keep the non-breaking space before it.

Hmph, recent 3651e45c (wt-status: take the alignment burden off
translators, 2013-11-05) seems to have gone in the different
direction when it updated similar code for the non-unmerged paths.

> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
>
> [1] http://bugs.debian.org/725777
>
> diff --git i/wt-status.c w/wt-status.c
> index 4e55810..7b0e5b8 100644
> --- i/wt-status.c
> +++ w/wt-status.c
> @@ -245,27 +245,26 @@ static void wt_status_print_trailer(struct wt_status *s)
>  
>  #define quote_path quote_path_relative
>  
> -static void wt_status_print_unmerged_data(struct wt_status *s,
> -					  struct string_list_item *it)
> +static const char *wt_status_unmerged_status_string(int stagemask)
>  {
> -	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");
> -
> -	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;
> +	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:
> +		return NULL;
>  	}
> -	status_printf_more(s, c, "%-20s%s\n", how, one);
> -	strbuf_release(&onebuf);
>  }
>  
>  static const char *wt_status_diff_status_string(int status)
> @@ -292,6 +291,48 @@ static const char *wt_status_diff_status_string(int status)
>  	}
>  }
>  
> +static int maxwidth(const char *(*label)(int), int minval, int maxval)
> +{
> +	const char *s;
> +	int result = 0, i;
> +
> +	for (i = minval; i <= maxval; i++) {
> +		const char *s = label(i);
> +		int len = s ? strlen(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;
> +	static char *padding;
> +	const char *one, *how;
> +	int len;
> +
> +	if (!padding) {
> +		int width = maxwidth(wt_status_unmerged_status_string, 1, 7);
> +		width += strlen(" ");
> +		padding = xmallocz(width);
> +		memset(padding, ' ', width);
> +	}
> +
> +	one = quote_path(it->string, s->prefix, &onebuf);
> +	status_printf(s, color(WT_STATUS_HEADER, s), "\t");
> +
> +	how = wt_status_unmerged_status_string(d->stagemask);
> +	if (!how)
> +		how = _("bug");
> +	len = strlen(padding) - utf8_strwidth(how);
> +	status_printf_more(s, c, "%s%.*s%s\n", how, len, padding, one);
> +	strbuf_release(&onebuf);
> +}
> +
>  static void wt_status_print_change_data(struct wt_status *s,
>  					int change_type,
>  					struct string_list_item *it)
> @@ -309,14 +350,8 @@ static void wt_status_print_change_data(struct wt_status *s,
>  	int len;
>  
>  	if (!padding) {
> -		int width = 0;
> -		/* If DIFF_STATUS_* uses outside this range, we're in trouble */
> -		for (status = 'A'; status <= 'Z'; status++) {
> -			what = wt_status_diff_status_string(status);
> -			len = what ? strlen(what) : 0;
> -			if (len > width)
> -				width = len;
> -		}
> +		/* If DIFF_STATUS_* uses outside the range [A..Z], we're in trouble */
> +		int width = maxwidth(wt_status_diff_status_string, 'A', 'Z');
>  		width += 2;	/* colon and a space */
>  		padding = xmallocz(width);
>  		memset(padding, ' ', width);

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: git: problematic git status output with some translations (such as fr_FR)
  2013-12-19 20:46     ` Junio C Hamano
@ 2013-12-19 20:50       ` Jonathan Nieder
  2013-12-19 23:59         ` Duy Nguyen
  2014-02-08  9:51         ` Duy Nguyen
  0 siblings, 2 replies; 12+ messages in thread
From: Jonathan Nieder @ 2013-12-19 20:50 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: Raphael Hertzog, git, Ævar Arnfjörð Bjarmason,
	Nguyễn Thái Ngọc Duy

Junio C Hamano wrote:
> Jonathan Nieder <jrnieder@gmail.com> writes:

>> This includes the colon in the translated string, to make it easier to
>> remember to keep the non-breaking space before it.
>
> Hmph, recent 3651e45c (wt-status: take the alignment burden off
> translators, 2013-11-05) seems to have gone in the different
> direction when it updated similar code for the non-unmerged paths.

Yes, if this seems to go in the right direction, I'd add a follow-up
for that when rerolling.

Alternatively if there is some library function to append a colon to a
string in a locale-appropriate way, that could work, too.  Pointers
welcome.

Thanks,
Jonathan

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: git: problematic git status output with some translations (such as fr_FR)
  2013-12-19 20:50       ` Jonathan Nieder
@ 2013-12-19 23:59         ` Duy Nguyen
  2014-01-16 22:00           ` Raphael Hertzog
  2014-02-08  9:51         ` Duy Nguyen
  1 sibling, 1 reply; 12+ messages in thread
From: Duy Nguyen @ 2013-12-19 23:59 UTC (permalink / raw)
  To: Jonathan Nieder
  Cc: Junio C Hamano, Raphael Hertzog, Git Mailing List,
	Ævar Arnfjörð

On Fri, Dec 20, 2013 at 3:50 AM, Jonathan Nieder <jrnieder@gmail.com> wrote:
> Junio C Hamano wrote:
>> Jonathan Nieder <jrnieder@gmail.com> writes:
>
>>> This includes the colon in the translated string, to make it easier to
>>> remember to keep the non-breaking space before it.
>>
>> Hmph, recent 3651e45c (wt-status: take the alignment burden off
>> translators, 2013-11-05) seems to have gone in the different
>> direction when it updated similar code for the non-unmerged paths.
>
> Yes, if this seems to go in the right direction, I'd add a follow-up
> for that when rerolling.

i'm fine either way.
-- 
Duy

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: git: problematic git status output with some translations (such as fr_FR)
  2013-12-19 23:59         ` Duy Nguyen
@ 2014-01-16 22:00           ` Raphael Hertzog
  0 siblings, 0 replies; 12+ messages in thread
From: Raphael Hertzog @ 2014-01-16 22:00 UTC (permalink / raw)
  To: Duy Nguyen
  Cc: Jonathan Nieder, Junio C Hamano, Git Mailing List,
	Ævar Arnfjörð

Hi,

On Fri, 20 Dec 2013, Duy Nguyen wrote:
> On Fri, Dec 20, 2013 at 3:50 AM, Jonathan Nieder <jrnieder@gmail.com> wrote:
> > Junio C Hamano wrote:
> >> Jonathan Nieder <jrnieder@gmail.com> writes:
> >
> >>> This includes the colon in the translated string, to make it easier to
> >>> remember to keep the non-breaking space before it.
> >>
> >> Hmph, recent 3651e45c (wt-status: take the alignment burden off
> >> translators, 2013-11-05) seems to have gone in the different
> >> direction when it updated similar code for the non-unmerged paths.
> >
> > Yes, if this seems to go in the right direction, I'd add a follow-up
> > for that when rerolling.
> 
> i'm fine either way.

In both cases, the alignment burden is taken off the translators. But I
agree that it's best to keep the colon in the translatable string so that
translators can add the space required by proper typography.

So I'd favor Jonathan's approach. I just tested his patch and it
solves the immediate problem for me. Without the patch I have this
(French translation):

| Chemins non fusionnés :
|   (utilisez "git add <fichier>..." pour marquer comme résolu)
| 
| 	modifié des deux côtés :fichier

And with it:

| Chemins non fusionnés :
|   (utilisez "git add <fichier>..." pour marquer comme résolu)
| 
| 	modifié des deux côtés :     fichier

However it looks like the padding is calculated on bytes
and not on (wide) characters, so we have 3 extra spaces before
the filename (one for ô, é, and the non-breaking space).
This can be problematic for translations where all characters
require multiple bytes. :-)

The patch is also incomplete since it currently breaks
the test suite in multiple places (the unnecessary padding
before the filename goes away), for example:

--- expected	2014-01-16 21:37:11.270535950 +0000
+++ actual	2014-01-16 21:37:11.270535950 +0000
@@ -5,7 +5,7 @@
 Unmerged paths:
   (use "git add/rm <file>..." as appropriate to mark resolution)
 
-	both added:         conflict.txt
-	deleted by them:    main.txt
+	both added:      conflict.txt
+	deleted by them: main.txt
 
 no changes added to commit (use "git add" and/or "git commit -a")
not ok 11 - status when conflicts with add and rm advice (deleted by them)


That was my two euros to help get this fixed because it annoys me
quite often.

Cheers,

-- 
Raphaël Hertzog ◈ Debian Developer

Discover the Debian Administrator's Handbook:
→ http://debian-handbook.info/get/

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: git: problematic git status output with some translations (such as fr_FR)
  2013-12-19 20:50       ` Jonathan Nieder
  2013-12-19 23:59         ` Duy Nguyen
@ 2014-02-08  9:51         ` Duy Nguyen
  1 sibling, 0 replies; 12+ messages in thread
From: Duy Nguyen @ 2014-02-08  9:51 UTC (permalink / raw)
  To: Jonathan Nieder
  Cc: Junio C Hamano, Raphael Hertzog, Git Mailing List,
	Ævar Arnfjörð

On Fri, Dec 20, 2013 at 3:50 AM, Jonathan Nieder <jrnieder@gmail.com> wrote:
> Junio C Hamano wrote:
>> Jonathan Nieder <jrnieder@gmail.com> writes:
>
>>> This includes the colon in the translated string, to make it easier to
>>> remember to keep the non-breaking space before it.
>>
>> Hmph, recent 3651e45c (wt-status: take the alignment burden off
>> translators, 2013-11-05) seems to have gone in the different
>> direction when it updated similar code for the non-unmerged paths.
>
> Yes, if this seems to go in the right direction, I'd add a follow-up
> for that when rerolling.

Just checking. Did you reroll it or did my filters move some mails to
spam/trash folder again?
-- 
Duy

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: git: problematic git status output with some translations (such as fr_FR)
  2013-12-19 19:43   ` git: problematic git status output with some translations (such as fr_FR) Jonathan Nieder
  2013-12-19 20:46     ` Junio C Hamano
@ 2014-03-12 18:53     ` Junio C Hamano
  2014-03-12 19:22       ` [PATCH] wt-status: i18n of section labels Junio C Hamano
  1 sibling, 1 reply; 12+ messages in thread
From: Junio C Hamano @ 2014-03-12 18:53 UTC (permalink / raw)
  To: Jonathan Nieder
  Cc: Raphael Hertzog, git, Ævar Arnfjörð Bjarmason,
	Nguyễn Thái Ngọc Duy

Jonathan Nieder <jrnieder@gmail.com> writes:

> @@ -292,6 +291,48 @@ static const char *wt_status_diff_status_string(int status)
>  	}
>  }
>  
> +static int maxwidth(const char *(*label)(int), int minval, int maxval)
> +{
> +	const char *s;
> +	int result = 0, i;
> +
> +	for (i = minval; i <= maxval; i++) {
> +		const char *s = label(i);
> +		int len = s ? strlen(s) : 0;

Shouldn't this be a utf8_strwidth(), as the value is to count number
of display columns to be used by the leading label part?

> +		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;
> +	static char *padding;
> +	const char *one, *how;
> +	int len;
> +
> +	if (!padding) {
> +		int width = maxwidth(wt_status_unmerged_status_string, 1, 7);
> +		width += strlen(" ");
> +		padding = xmallocz(width);
> +		memset(padding, ' ', width);
> +	}
> +
> +	one = quote_path(it->string, s->prefix, &onebuf);
> +	status_printf(s, color(WT_STATUS_HEADER, s), "\t");
> +
> +	how = wt_status_unmerged_status_string(d->stagemask);
> +	if (!how)
> +		how = _("bug");

I'd rather see the callee do this _("bug") thing, not this
particular caller.

> +	len = strlen(padding) - utf8_strwidth(how);
> +	status_printf_more(s, c, "%s%.*s%s\n", how, len, padding, one);
> +	strbuf_release(&onebuf);
> +}

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH] wt-status: i18n of section labels
  2014-03-12 18:53     ` Junio C Hamano
@ 2014-03-12 19:22       ` Junio C Hamano
  2014-03-12 20:05         ` Sandy Carter
  0 siblings, 1 reply; 12+ messages in thread
From: Junio C Hamano @ 2014-03-12 19:22 UTC (permalink / raw)
  To: git
  Cc: Raphael Hertzog, Ævar Arnfjörð Bjarmason,
	Nguyễn Thái Ngọc Duy, Jonathan Nieder

From: Jonathan Nieder <jrnieder@gmail.com>
Date: Thu, 19 Dec 11:43:19 2013 -0800

The original code assumes that:

 (1) the number of bytes written is the width of a string, so they
     can line up;

 (2) the "how" string is always <= 19 bytes.

Also a recent change to a similar codepath by 3651e45c (wt-status:
take the alignment burden off translators, 2013-11-05) adds this
assumption:

 (3) the "colon" at the end of the label string does not have to be
     subject to l10n.

None of which we should assume.

Refactor the code to compute the label width for both codepaths into
a helper function, make sure label strings have the trailing colon
that can be localized, and use it when showing the section labels in
the output.

cf. http://bugs.debian.org/725777

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---

 * Differences relative to Jonathan's original in $gmane/239537 are:

   - labels made by wt_status_diff_status_string() have trailing
     colon; the caller has been adjusted (please double check)

   - a static label_width avoids repeated strlen(padding);

   - unmerged status label has "at least 20 columns wide"
     reinstated, at least for now, to keep the existing tests from
     breaking.  We may want to drop it in a separate follow-up
     patch.

 wt-status.c | 121 +++++++++++++++++++++++++++++++++++++++---------------------
 1 file changed, 78 insertions(+), 43 deletions(-)

diff --git a/wt-status.c b/wt-status.c
index 4e55810..a00861c 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -245,51 +245,92 @@ static void wt_status_print_trailer(struct wt_status *s)
 
 #define quote_path quote_path_relative
 
-static void wt_status_print_unmerged_data(struct wt_status *s,
-					  struct string_list_item *it)
+static const char *wt_status_unmerged_status_string(int stagemask)
 {
-	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");
-
-	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;
+	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:
+		return _("bug");
 	}
-	status_printf_more(s, c, "%-20s%s\n", how, one);
-	strbuf_release(&onebuf);
 }
 
 static const char *wt_status_diff_status_string(int status)
 {
 	switch (status) {
 	case DIFF_STATUS_ADDED:
-		return _("new file");
+		return _("new file:");
 	case DIFF_STATUS_COPIED:
-		return _("copied");
+		return _("copied:");
 	case DIFF_STATUS_DELETED:
-		return _("deleted");
+		return _("deleted:");
 	case DIFF_STATUS_MODIFIED:
-		return _("modified");
+		return _("modified:");
 	case DIFF_STATUS_RENAMED:
-		return _("renamed");
+		return _("renamed:");
 	case DIFF_STATUS_TYPE_CHANGED:
-		return _("typechange");
+		return _("typechange:");
 	case DIFF_STATUS_UNKNOWN:
-		return _("unknown");
+		return _("unknown:");
 	case DIFF_STATUS_UNMERGED:
-		return _("unmerged");
+		return _("unmerged:");
 	default:
-		return NULL;
+		return _("bug");
+	}
+}
+
+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;
+	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(" ");
+		if (label_width < 20)
+			label_width = 20;
+		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");
+
+	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);
 }
 
 static void wt_status_print_change_data(struct wt_status *s,
@@ -305,21 +346,16 @@ static void wt_status_print_change_data(struct wt_status *s,
 	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) {
-		int width = 0;
-		/* If DIFF_STATUS_* uses outside this range, we're in trouble */
-		for (status = 'A'; status <= 'Z'; status++) {
-			what = wt_status_diff_status_string(status);
-			len = what ? strlen(what) : 0;
-			if (len > width)
-				width = len;
-		}
-		width += 2;	/* colon and a space */
-		padding = xmallocz(width);
-		memset(padding, ' ', width);
+		/* 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;
@@ -355,14 +391,13 @@ static void wt_status_print_change_data(struct wt_status *s,
 	what = wt_status_diff_status_string(status);
 	if (!what)
 		die(_("bug: unhandled diff status %c"), status);
-	/* 1 for colon, which is not part of "what" */
-	len = strlen(padding) - (utf8_strwidth(what) + 1);
+	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",
+		status_printf_more(s, c, "%s%.*s%s -> %s",
 				   what, len, padding, one, two);
 	else
-		status_printf_more(s, c, "%s:%.*s%s",
+		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);

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH] wt-status: i18n of section labels
  2014-03-12 19:22       ` [PATCH] wt-status: i18n of section labels Junio C Hamano
@ 2014-03-12 20:05         ` Sandy Carter
  2014-03-12 20:12           ` Junio C Hamano
  0 siblings, 1 reply; 12+ messages in thread
From: Sandy Carter @ 2014-03-12 20:05 UTC (permalink / raw)
  To: Junio C Hamano, git
  Cc: Raphael Hertzog, Ævar Arnfjörð Bjarmason,
	Nguyễn Thái Ngọc Duy, Jonathan Nieder



Le 2014-03-12 15:22, Junio C Hamano a écrit :
>   static const char *wt_status_diff_status_string(int status)
>   {
>   	switch (status) {
>   	case DIFF_STATUS_ADDED:
> -		return _("new file");
> +		return _("new file:");
>   	case DIFF_STATUS_COPIED:
> -		return _("copied");
> +		return _("copied:");
>   	case DIFF_STATUS_DELETED:
> -		return _("deleted");
> +		return _("deleted:");
>   	case DIFF_STATUS_MODIFIED:
> -		return _("modified");
> +		return _("modified:");
>   	case DIFF_STATUS_RENAMED:
> -		return _("renamed");
> +		return _("renamed:");
>   	case DIFF_STATUS_TYPE_CHANGED:
> -		return _("typechange");
> +		return _("typechange:");
>   	case DIFF_STATUS_UNKNOWN:
> -		return _("unknown");
> +		return _("unknown:");
>   	case DIFF_STATUS_UNMERGED:
> -		return _("unmerged");
> +		return _("unmerged:");
>   	default:
> -		return NULL;
> +		return _("bug");
> +	}
> +}

I don't see why _("bug") is returned when, later down,

> @@ -305,21 +346,16 @@ static void wt_status_print_change_data(struct wt_status *s,
>   	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) {
> -		int width = 0;
> -		/* If DIFF_STATUS_* uses outside this range, we're in trouble */
> -		for (status = 'A'; status <= 'Z'; status++) {
> -			what = wt_status_diff_status_string(status);
> -			len = what ? strlen(what) : 0;

checks for NULL.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] wt-status: i18n of section labels
  2014-03-12 20:05         ` Sandy Carter
@ 2014-03-12 20:12           ` Junio C Hamano
  2014-03-12 20:17             ` Sandy Carter
  0 siblings, 1 reply; 12+ messages in thread
From: Junio C Hamano @ 2014-03-12 20:12 UTC (permalink / raw)
  To: Sandy Carter
  Cc: git, Raphael Hertzog, Ævar Arnfjörð Bjarmason,
	Nguyễn Thái Ngọc Duy, Jonathan Nieder

Sandy Carter <sandy.carter@savoirfairelinux.com> writes:

> Le 2014-03-12 15:22, Junio C Hamano a écrit :
>>   static const char *wt_status_diff_status_string(int status)
>>   {
>>   	switch (status) {
>>   	case DIFF_STATUS_ADDED:
>> -		return _("new file");
>> +		return _("new file:");
>>   	case DIFF_STATUS_COPIED:
>> -		return _("copied");
>> +		return _("copied:");
>>   	case DIFF_STATUS_DELETED:
>> -		return _("deleted");
>> +		return _("deleted:");
>>   	case DIFF_STATUS_MODIFIED:
>> -		return _("modified");
>> +		return _("modified:");
>>   	case DIFF_STATUS_RENAMED:
>> -		return _("renamed");
>> +		return _("renamed:");
>>   	case DIFF_STATUS_TYPE_CHANGED:
>> -		return _("typechange");
>> +		return _("typechange:");
>>   	case DIFF_STATUS_UNKNOWN:
>> -		return _("unknown");
>> +		return _("unknown:");
>>   	case DIFF_STATUS_UNMERGED:
>> -		return _("unmerged");
>> +		return _("unmerged:");
>>   	default:
>> -		return NULL;
>> +		return _("bug");
>> +	}
>> +}
>
> I don't see why _("bug") is returned when, later down,

When there is a bug in the caller.

>
>> @@ -305,21 +346,16 @@ static void wt_status_print_change_data(struct wt_status *s,
>>   	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) {
>> -		int width = 0;
>> -		/* If DIFF_STATUS_* uses outside this range, we're in trouble */
>> -		for (status = 'A'; status <= 'Z'; status++) {
>> -			what = wt_status_diff_status_string(status);
>> -			len = what ? strlen(what) : 0;
>
> checks for NULL.

That extra NULL-ness check can go, I think.  Thanks for
double-checking.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] wt-status: i18n of section labels
  2014-03-12 20:12           ` Junio C Hamano
@ 2014-03-12 20:17             ` Sandy Carter
  2014-03-13 18:01               ` Junio C Hamano
  0 siblings, 1 reply; 12+ messages in thread
From: Sandy Carter @ 2014-03-12 20:17 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: git, Raphael Hertzog, Ævar Arnfjörð Bjarmason,
	Nguyễn Thái Ngọc Duy, Jonathan Nieder

Le 2014-03-12 16:12, Junio C Hamano a écrit :
> Sandy Carter <sandy.carter@savoirfairelinux.com> writes:
>
>> Le 2014-03-12 15:22, Junio C Hamano a écrit :
>>>    static const char *wt_status_diff_status_string(int status)
>>>    {
>>>    	switch (status) {
>>>    	case DIFF_STATUS_ADDED:
>>> -		return _("new file");
>>> +		return _("new file:");
>>>    	case DIFF_STATUS_COPIED:
>>> -		return _("copied");
>>> +		return _("copied:");
>>>    	case DIFF_STATUS_DELETED:
>>> -		return _("deleted");
>>> +		return _("deleted:");
>>>    	case DIFF_STATUS_MODIFIED:
>>> -		return _("modified");
>>> +		return _("modified:");
>>>    	case DIFF_STATUS_RENAMED:
>>> -		return _("renamed");
>>> +		return _("renamed:");
>>>    	case DIFF_STATUS_TYPE_CHANGED:
>>> -		return _("typechange");
>>> +		return _("typechange:");
>>>    	case DIFF_STATUS_UNKNOWN:
>>> -		return _("unknown");
>>> +		return _("unknown:");
>>>    	case DIFF_STATUS_UNMERGED:
>>> -		return _("unmerged");
>>> +		return _("unmerged:");
>>>    	default:
>>> -		return NULL;
>>> +		return _("bug");
>>> +	}
>>> +}
>>
>> I don't see why _("bug") is returned when, later down,
>
> When there is a bug in the caller.
>
>>
>>> @@ -305,21 +346,16 @@ static void wt_status_print_change_data(struct wt_status *s,
>>>    	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) {
>>> -		int width = 0;
>>> -		/* If DIFF_STATUS_* uses outside this range, we're in trouble */
>>> -		for (status = 'A'; status <= 'Z'; status++) {
>>> -			what = wt_status_diff_status_string(status);
>>> -			len = what ? strlen(what) : 0;
>>
>> checks for NULL.
>
> That extra NULL-ness check can go, I think.  Thanks for
> double-checking.
>

I refered to the wrong lines, the ones I was refering to were:

 > +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;

Sorry about that

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] wt-status: i18n of section labels
  2014-03-12 20:17             ` Sandy Carter
@ 2014-03-13 18:01               ` Junio C Hamano
  0 siblings, 0 replies; 12+ messages in thread
From: Junio C Hamano @ 2014-03-13 18:01 UTC (permalink / raw)
  To: Sandy Carter
  Cc: git, Raphael Hertzog, Ævar Arnfjörð Bjarmason,
	Nguyễn Thái Ngọc Duy, Jonathan Nieder

Sandy Carter <sandy.carter@savoirfairelinux.com> writes:

> I refered to the wrong lines, the ones I was refering to were:
>
>> +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;
>
> Sorry about that

Oh, yes, you are right.  wt_status_diff_status_string() is meant to
be asked with a bogus status character and expected to return NULL,
so diagnosing anything it does not understand as a "bug" is indeed a
bug I added.

I think I fixed in my latest reroll ($gmane/243996).

Thanks for catching that.

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2014-03-13 18:02 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20131008085036.11434.25160.reportbug@x230-buxy.home.ouaza.com>
     [not found] ` <20131219104613.GA18379@x230-buxy.home.ouaza.com>
2013-12-19 19:43   ` git: problematic git status output with some translations (such as fr_FR) Jonathan Nieder
2013-12-19 20:46     ` Junio C Hamano
2013-12-19 20:50       ` Jonathan Nieder
2013-12-19 23:59         ` Duy Nguyen
2014-01-16 22:00           ` Raphael Hertzog
2014-02-08  9:51         ` Duy Nguyen
2014-03-12 18:53     ` Junio C Hamano
2014-03-12 19:22       ` [PATCH] wt-status: i18n of section labels Junio C Hamano
2014-03-12 20:05         ` Sandy Carter
2014-03-12 20:12           ` Junio C Hamano
2014-03-12 20:17             ` Sandy Carter
2014-03-13 18:01               ` Junio C Hamano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).