* Bug? git status --porcelain --branch is translated
@ 2014-03-20 10:31 Anarky
2014-03-20 12:12 ` [PATCH] status: disable translation when --porcelain is used Matthieu Moy
0 siblings, 1 reply; 5+ messages in thread
From: Anarky @ 2014-03-20 10:31 UTC (permalink / raw)
To: git
Hello,
The porcelain format of git status is described as not based on user
configuration.
But with --branch, behind/ahead are translated following the user's locale.
Is it normal that scripts need to take care of that?
Thanks.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH] status: disable translation when --porcelain is used
2014-03-20 10:31 Bug? git status --porcelain --branch is translated Anarky
@ 2014-03-20 12:12 ` Matthieu Moy
2014-03-20 17:47 ` Junio C Hamano
0 siblings, 1 reply; 5+ messages in thread
From: Matthieu Moy @ 2014-03-20 12:12 UTC (permalink / raw)
To: git, gitster; +Cc: ghostanarky, Matthieu Moy
"git status --branch --porcelain" displays the status of the branch
(ahead, behind, gone), and used gettext to translate the string.
Use hardcoded strings when --porcelain is used, but keep the gettext
translation for "git status --short" which is essentially the same, but
meant to be read by a human.
Reported-by: Anarky <ghostanarky@gmail.com>
Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>
---
> The porcelain format of git status is described as not based on user
> configuration.
> But with --branch, behind/ahead are translated following the user's locale.
> Is it normal that scripts need to take care of that?
Indeed, I'd call that a bug. Here's a fix.
wt-status.c | 15 ++++++++++-----
wt-status.h | 1 +
2 files changed, 11 insertions(+), 5 deletions(-)
diff --git a/wt-status.c b/wt-status.c
index a452407..e55e5b9 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -1509,19 +1509,23 @@ static void wt_shortstatus_print_tracking(struct wt_status *s)
return;
}
+ const char *gone = s->no_gettext ? "gone" : _("gone");
+ const char *behind = s->no_gettext ? "behind " : _("behind ");
+ const char *ahead = s->no_gettext ? "ahead " : _("ahead ");
+
color_fprintf(s->fp, header_color, " [");
if (upstream_is_gone) {
- color_fprintf(s->fp, header_color, _("gone"));
+ color_fprintf(s->fp, header_color, gone);
} else if (!num_ours) {
- color_fprintf(s->fp, header_color, _("behind "));
+ color_fprintf(s->fp, header_color, 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, 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, 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", behind);
color_fprintf(s->fp, branch_color_remote, "%d", num_theirs);
}
@@ -1566,5 +1570,6 @@ void wt_porcelain_print(struct wt_status *s)
s->use_color = 0;
s->relative_paths = 0;
s->prefix = NULL;
+ s->no_gettext = 1;
wt_shortstatus_print(s);
}
diff --git a/wt-status.h b/wt-status.h
index 30a4812..82f6ce6 100644
--- a/wt-status.h
+++ b/wt-status.h
@@ -50,6 +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;
--
1.9.1.295.g2661741
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] status: disable translation when --porcelain is used
2014-03-20 12:12 ` [PATCH] status: disable translation when --porcelain is used Matthieu Moy
@ 2014-03-20 17:47 ` Junio C Hamano
2014-03-21 8:29 ` Matthieu Moy
0 siblings, 1 reply; 5+ messages in thread
From: Junio C Hamano @ 2014-03-20 17:47 UTC (permalink / raw)
To: Matthieu Moy; +Cc: git, ghostanarky
Matthieu Moy <Matthieu.Moy@imag.fr> writes:
> "git status --branch --porcelain" displays the status of the branch
> (ahead, behind, gone), and used gettext to translate the string.
>
> Use hardcoded strings when --porcelain is used, but keep the gettext
> translation for "git status --short" which is essentially the same, but
> meant to be read by a human.
>
> Reported-by: Anarky <ghostanarky@gmail.com>
> Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>
> ---
>> The porcelain format of git status is described as not based on user
>> configuration.
>> But with --branch, behind/ahead are translated following the user's locale.
>> Is it normal that scripts need to take care of that?
>
> Indeed, I'd call that a bug. Here's a fix.
Good thing to fix. Thanks.
> wt-status.c | 15 ++++++++++-----
> wt-status.h | 1 +
> 2 files changed, 11 insertions(+), 5 deletions(-)
>
> diff --git a/wt-status.c b/wt-status.c
> index a452407..e55e5b9 100644
> --- a/wt-status.c
> +++ b/wt-status.c
> @@ -1509,19 +1509,23 @@ static void wt_shortstatus_print_tracking(struct wt_status *s)
> return;
> }
>
> + const char *gone = s->no_gettext ? "gone" : _("gone");
> + const char *behind = s->no_gettext ? "behind " : _("behind ");
> + const char *ahead = s->no_gettext ? "ahead " : _("ahead ");
Having to repeat the same string constant twice (and a half for the
variable name) each is an eyesore. I wonder if we can do better,
perhaps with:
#define LABEL(string) (s->no_gettext ? (string) : _(string))
and then
color_fprintf(s->fp, header_color, LABEL(N_("gone")));
or something along those lines?
> color_fprintf(s->fp, header_color, " [");
> if (upstream_is_gone) {
> - color_fprintf(s->fp, header_color, _("gone"));
> + color_fprintf(s->fp, header_color, gone);
> } else if (!num_ours) {
> - color_fprintf(s->fp, header_color, _("behind "));
> + color_fprintf(s->fp, header_color, 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, 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, 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", behind);
> color_fprintf(s->fp, branch_color_remote, "%d", num_theirs);
> }
>
> @@ -1566,5 +1570,6 @@ void wt_porcelain_print(struct wt_status *s)
> s->use_color = 0;
> s->relative_paths = 0;
> s->prefix = NULL;
> + s->no_gettext = 1;
> wt_shortstatus_print(s);
> }
> diff --git a/wt-status.h b/wt-status.h
> index 30a4812..82f6ce6 100644
> --- a/wt-status.h
> +++ b/wt-status.h
> @@ -50,6 +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;
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] status: disable translation when --porcelain is used
2014-03-20 17:47 ` Junio C Hamano
@ 2014-03-21 8:29 ` Matthieu Moy
2014-03-21 17:38 ` Junio C Hamano
0 siblings, 1 reply; 5+ messages in thread
From: Matthieu Moy @ 2014-03-21 8:29 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git, ghostanarky
Junio C Hamano <gitster@pobox.com> writes:
>> diff --git a/wt-status.c b/wt-status.c
>> index a452407..e55e5b9 100644
>> --- a/wt-status.c
>> +++ b/wt-status.c
>> @@ -1509,19 +1509,23 @@ static void wt_shortstatus_print_tracking(struct wt_status *s)
>> return;
>> }
>>
>> + const char *gone = s->no_gettext ? "gone" : _("gone");
>> + const char *behind = s->no_gettext ? "behind " : _("behind ");
>> + const char *ahead = s->no_gettext ? "ahead " : _("ahead ");
>
> Having to repeat the same string constant twice (and a half for the
> variable name) each is an eyesore. I wonder if we can do better,
> perhaps with:
>
> #define LABEL(string) (s->no_gettext ? (string) : _(string))
>
> and then
>
> color_fprintf(s->fp, header_color, LABEL(N_("gone")));
>
> or something along those lines?
I first thought about trying something clever with the preprocessor, but
since it's only for 3 strings, I went the KISS way. I tend to prefer my
version for simplicity, but no strong opinion here.
--
Matthieu Moy
http://www-verimag.imag.fr/~moy/
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] status: disable translation when --porcelain is used
2014-03-21 8:29 ` Matthieu Moy
@ 2014-03-21 17:38 ` Junio C Hamano
0 siblings, 0 replies; 5+ messages in thread
From: Junio C Hamano @ 2014-03-21 17:38 UTC (permalink / raw)
To: Matthieu Moy; +Cc: git, ghostanarky
Matthieu Moy <Matthieu.Moy@grenoble-inp.fr> writes:
> Junio C Hamano <gitster@pobox.com> writes:
>
>>> diff --git a/wt-status.c b/wt-status.c
>>> index a452407..e55e5b9 100644
>>> --- a/wt-status.c
>>> +++ b/wt-status.c
>>> @@ -1509,19 +1509,23 @@ static void wt_shortstatus_print_tracking(struct wt_status *s)
>>> return;
>>> }
>>>
>>> + const char *gone = s->no_gettext ? "gone" : _("gone");
>>> + const char *behind = s->no_gettext ? "behind " : _("behind ");
>>> + const char *ahead = s->no_gettext ? "ahead " : _("ahead ");
>>
>> Having to repeat the same string constant twice (and a half for the
>> variable name) each is an eyesore. I wonder if we can do better,
>> perhaps with:
>>
>> #define LABEL(string) (s->no_gettext ? (string) : _(string))
>>
>> and then
>>
>> color_fprintf(s->fp, header_color, LABEL(N_("gone")));
>>
>> or something along those lines?
>
> I first thought about trying something clever with the preprocessor, but
> since it's only for 3 strings, I went the KISS way. I tend to prefer my
> version for simplicity, but no strong opinion here.
Then I'll squash 61bf9709 (SQUASH??? fix decl-after-stmt and
simplify, 2014-03-20) in before merging the patch to 'next'.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2014-03-21 17:38 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-03-20 10:31 Bug? git status --porcelain --branch is translated Anarky
2014-03-20 12:12 ` [PATCH] status: disable translation when --porcelain is used Matthieu Moy
2014-03-20 17:47 ` Junio C Hamano
2014-03-21 8:29 ` Matthieu Moy
2014-03-21 17:38 ` 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).