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>

Matthew DeVore committed Jun 18, 2019 at 15:29 UTC 28438e84e046984afc76dc891a49bd0862d555f7
3 files changed +21 -18
ref-filter.c
+16 -16
@@ -1441,35 +1441,35 @@ char *get_head_description(void)
1441 struct wt_status_state state;
1442 memset(&state, 0, sizeof(state));
1443 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, '(');
1451 if (state.rebase_in_progress ||
1452 state.rebase_interactive_in_progress) {
1453 if (state.branch)
1447 - strbuf_addf(&desc, _("(no branch, rebasing %s)"),
1454 + strbuf_addf(&desc, _("no branch, rebasing %s"),
1455 state.branch);
1456 else
1450 - strbuf_addf(&desc, _("(no branch, rebasing detached HEAD %s)"),
1457 + strbuf_addf(&desc, _("no branch, rebasing detached HEAD %s"),
1458 state.detached_from);
1459 } 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"),
1461 state.branch);
1462 else if (state.detached_from) {
1463 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);
1465 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);
1468 }
1469 else
1472 - strbuf_addstr(&desc, _("(no branch)"));
1470 + strbuf_addstr(&desc, _("no branch"));
1471 + strbuf_addch(&desc, ')');
1472 +
1473 free(state.branch);
1474 free(state.onto);
1475 free(state.detached_from);
wt-status.c
+2 -2
@@ -1628,9 +1628,9 @@ static void wt_longstatus_print(struct wt_status *s)
1628 } else if (s->state.detached_from) {
1629 branch_name = s->state.detached_from;
1630 if (s->state.detached_at)
1631 - on_what = _("HEAD detached at ");
1631 + on_what = HEAD_DETACHED_AT;
1632 else
1633 - on_what = _("HEAD detached from ");
1633 + on_what = HEAD_DETACHED_FROM;
1634 } else {
1635 branch_name = "";
1636 on_what = _("Not currently on any branch.");
wt-status.h
+3
@@ -65,6 +65,9 @@ enum wt_status_format {
65 STATUS_FORMAT_UNSPECIFIED
66 };
67
68 +#define HEAD_DETACHED_AT _("HEAD detached at ")
69 +#define HEAD_DETACHED_FROM _("HEAD detached from ")
70 +
71 struct wt_status_state {
72 int merge_in_progress;
73 int am_in_progress;