From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH] branch -v: align even when the first column is in UTF-8
Date: Fri, 24 Aug 2012 21:17:52 +0700 [thread overview]
Message-ID: <1345817872-7943-1-git-send-email-pclouds@gmail.com> (raw)
Branch names are usually in ASCII so they are not the problem. The
problem most likely comes from "(no branch)" translation, which is in
UTF-8 and makes length calculation just wrong.
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
So far all git translations are utf-8 compatible. Branch names may
use filesystem encoding, but then packed-refs specifies no encoding.
Anyway branch names should be in utf-8.. at least internally, imo.
builtin/branch.c | 8 +++++---
1 tập tin đã bị thay đổi, 5 được thêm vào(+), 3 bị xóa(-)
diff --git a/builtin/branch.c b/builtin/branch.c
index 0e060f2..7c1ffa8 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -17,6 +17,7 @@
#include "revision.h"
#include "string-list.h"
#include "column.h"
+#include "utf8.h"
static const char * const builtin_branch_usage[] = {
"git branch [options] [-r | -a] [--merged | --no-merged]",
@@ -490,11 +491,12 @@ static void print_ref_item(struct ref_item *item, int maxwidth, int verbose,
}
strbuf_addf(&name, "%s%s", prefix, item->name);
- if (verbose)
+ if (verbose) {
+ int utf8_compensation = strlen(name.buf) - utf8_strwidth(name.buf);
strbuf_addf(&out, "%c %s%-*s%s", c, branch_get_color(color),
- maxwidth, name.buf,
+ maxwidth + utf8_compensation, name.buf,
branch_get_color(BRANCH_COLOR_RESET));
- else
+ } else
strbuf_addf(&out, "%c %s%s%s", c, branch_get_color(color),
name.buf, branch_get_color(BRANCH_COLOR_RESET));
--
1.7.12.rc2.18.g61b472e
next reply other threads:[~2012-08-24 14:24 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-08-24 14:17 Nguyễn Thái Ngọc Duy [this message]
2012-08-24 17:25 ` [PATCH] branch -v: align even when the first column is in UTF-8 Junio C Hamano
2012-08-25 18:17 ` [PATCH v2] branch -v: align even when branch names are " Nguyễn Thái Ngọc Duy
2012-08-26 18:04 ` Junio C Hamano
2012-08-25 10:48 ` [PATCH] branch -v: align even when the first column is " Erik Faye-Lund
2012-08-25 11:19 ` Nguyen Thai Ngoc Duy
2012-08-26 18:28 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1345817872-7943-1-git-send-email-pclouds@gmail.com \
--to=pclouds@gmail.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.