Skip to content

Commit 28438e8

Browse files
matvoregitster
authored andcommitted
ref-filter: sort detached HEAD lines firstly
Before this patch, "git branch" would put "(HEAD detached...)" and "(no branch, rebasing...)" lines before all the other branches *in most cases* except for when using Chinese-language messages. zh_CN generally uses a full-width "(" symbol (codepoint FF08) to match the full-width proportions of Chinese characters, and the translated strings we had did use them. This meant that the detached HEAD line would appear after all local refs and even after the remote refs if there were any. AFAIK, it is sometimes not jarring to see the half-width parenthesis in "full-width" text as in the CJK languages, for instance when there are no characters preceding or following the parenthesized text fragment. By removing the parenthesis from the localizable text, we can share strings with wt-status.c and remove a cautionary comment to translators. Remove the ( from the localizable portion of messages so the sorting happens properly regardless of locale. Helped-by: Johannes Schindelin <Johannes.Schindelin@gmx.de> Helped-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Matthew DeVore <matvore@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent aeb582a commit 28438e8

File tree

3 files changed

+21
-18
lines changed

3 files changed

+21
-18
lines changed

ref-filter.c

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1441,35 +1441,35 @@ char *get_head_description(void)
14411441
struct wt_status_state state;
14421442
memset(&state, 0, sizeof(state));
14431443
wt_status_get_state(the_repository, &state, 1);
1444+
1445+
/*
1446+
* The ( character must be hard-coded and not part of a localizable
1447+
* string, since the description is used as a sort key and compared
1448+
* with ref names.
1449+
*/
1450+
strbuf_addch(&desc, '(');
14441451
if (state.rebase_in_progress ||
14451452
state.rebase_interactive_in_progress) {
14461453
if (state.branch)
1447-
strbuf_addf(&desc, _("(no branch, rebasing %s)"),
1454+
strbuf_addf(&desc, _("no branch, rebasing %s"),
14481455
state.branch);
14491456
else
1450-
strbuf_addf(&desc, _("(no branch, rebasing detached HEAD %s)"),
1457+
strbuf_addf(&desc, _("no branch, rebasing detached HEAD %s"),
14511458
state.detached_from);
14521459
} else if (state.bisect_in_progress)
1453-
strbuf_addf(&desc, _("(no branch, bisect started on %s)"),
1460+
strbuf_addf(&desc, _("no branch, bisect started on %s"),
14541461
state.branch);
14551462
else if (state.detached_from) {
14561463
if (state.detached_at)
1457-
/*
1458-
* TRANSLATORS: make sure this matches "HEAD
1459-
* detached at " in wt-status.c
1460-
*/
1461-
strbuf_addf(&desc, _("(HEAD detached at %s)"),
1462-
state.detached_from);
1464+
strbuf_addstr(&desc, HEAD_DETACHED_AT);
14631465
else
1464-
/*
1465-
* TRANSLATORS: make sure this matches "HEAD
1466-
* detached from " in wt-status.c
1467-
*/
1468-
strbuf_addf(&desc, _("(HEAD detached from %s)"),
1469-
state.detached_from);
1466+
strbuf_addstr(&desc, HEAD_DETACHED_FROM);
1467+
strbuf_addstr(&desc, state.detached_from);
14701468
}
14711469
else
1472-
strbuf_addstr(&desc, _("(no branch)"));
1470+
strbuf_addstr(&desc, _("no branch"));
1471+
strbuf_addch(&desc, ')');
1472+
14731473
free(state.branch);
14741474
free(state.onto);
14751475
free(state.detached_from);

wt-status.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1628,9 +1628,9 @@ static void wt_longstatus_print(struct wt_status *s)
16281628
} else if (s->state.detached_from) {
16291629
branch_name = s->state.detached_from;
16301630
if (s->state.detached_at)
1631-
on_what = _("HEAD detached at ");
1631+
on_what = HEAD_DETACHED_AT;
16321632
else
1633-
on_what = _("HEAD detached from ");
1633+
on_what = HEAD_DETACHED_FROM;
16341634
} else {
16351635
branch_name = "";
16361636
on_what = _("Not currently on any branch.");

wt-status.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ enum wt_status_format {
6565
STATUS_FORMAT_UNSPECIFIED
6666
};
6767

68+
#define HEAD_DETACHED_AT _("HEAD detached at ")
69+
#define HEAD_DETACHED_FROM _("HEAD detached from ")
70+
6871
struct wt_status_state {
6972
int merge_in_progress;
7073
int am_in_progress;

0 commit comments

Comments
 (0)