Skip to content

Commit d71abd9

Browse files
committed
Merge branch 'nd/fetch-status-alignment'
The status report from "git fetch", when messages like 'up-to-date' are translated, did not align the branch names well. * nd/fetch-status-alignment: fetch: align per-ref summary report in UTF-8 locales
2 parents 3c7d509 + 754395d commit d71abd9

File tree

4 files changed

+26
-10
lines changed

4 files changed

+26
-10
lines changed

Diff for: builtin/fetch.c

+7-8
Original file line numberDiff line numberDiff line change
@@ -256,9 +256,8 @@ static int update_local_ref(struct ref *ref,
256256
if (!hashcmp(ref->old_sha1, ref->new_sha1)) {
257257
if (verbosity > 0)
258258
strbuf_addf(display, "= %-*s %-*s -> %s",
259-
TRANSPORT_SUMMARY_WIDTH,
260-
_("[up to date]"), REFCOL_WIDTH,
261-
remote, pretty_ref);
259+
TRANSPORT_SUMMARY(_("[up to date]")),
260+
REFCOL_WIDTH, remote, pretty_ref);
262261
return 0;
263262
}
264263

@@ -272,7 +271,7 @@ static int update_local_ref(struct ref *ref,
272271
*/
273272
strbuf_addf(display,
274273
_("! %-*s %-*s -> %s (can't fetch in current branch)"),
275-
TRANSPORT_SUMMARY_WIDTH, _("[rejected]"),
274+
TRANSPORT_SUMMARY(_("[rejected]")),
276275
REFCOL_WIDTH, remote, pretty_ref);
277276
return 1;
278277
}
@@ -283,7 +282,7 @@ static int update_local_ref(struct ref *ref,
283282
r = s_update_ref("updating tag", ref, 0);
284283
strbuf_addf(display, "%c %-*s %-*s -> %s%s",
285284
r ? '!' : '-',
286-
TRANSPORT_SUMMARY_WIDTH, _("[tag update]"),
285+
TRANSPORT_SUMMARY(_("[tag update]")),
287286
REFCOL_WIDTH, remote, pretty_ref,
288287
r ? _(" (unable to update local ref)") : "");
289288
return r;
@@ -318,7 +317,7 @@ static int update_local_ref(struct ref *ref,
318317
r = s_update_ref(msg, ref, 0);
319318
strbuf_addf(display, "%c %-*s %-*s -> %s%s",
320319
r ? '!' : '*',
321-
TRANSPORT_SUMMARY_WIDTH, what,
320+
TRANSPORT_SUMMARY(what),
322321
REFCOL_WIDTH, remote, pretty_ref,
323322
r ? _(" (unable to update local ref)") : "");
324323
return r;
@@ -358,7 +357,7 @@ static int update_local_ref(struct ref *ref,
358357
return r;
359358
} else {
360359
strbuf_addf(display, "! %-*s %-*s -> %s %s",
361-
TRANSPORT_SUMMARY_WIDTH, _("[rejected]"),
360+
TRANSPORT_SUMMARY(_("[rejected]")),
362361
REFCOL_WIDTH, remote, pretty_ref,
363362
_("(non-fast-forward)"));
364363
return 1;
@@ -555,7 +554,7 @@ static int prune_refs(struct refspec *refs, int ref_count, struct ref *ref_map)
555554
result |= delete_ref(ref->name, NULL, 0);
556555
if (verbosity >= 0) {
557556
fprintf(stderr, " x %-*s %-*s -> %s\n",
558-
TRANSPORT_SUMMARY_WIDTH, _("[deleted]"),
557+
TRANSPORT_SUMMARY(_("[deleted]")),
559558
REFCOL_WIDTH, _("(none)"), prettify_refname(ref->name));
560559
warn_dangling_symref(stderr, dangling_msg, ref->name);
561560
}

Diff for: gettext.c

+13-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
#include "git-compat-util.h"
66
#include "gettext.h"
7+
#include "strbuf.h"
8+
#include "utf8.h"
79

810
#ifndef NO_GETTEXT
911
# include <locale.h>
@@ -27,10 +29,9 @@ int use_gettext_poison(void)
2729
#endif
2830

2931
#ifndef NO_GETTEXT
32+
static const char *charset;
3033
static void init_gettext_charset(const char *domain)
3134
{
32-
const char *charset;
33-
3435
/*
3536
This trick arranges for messages to be emitted in the user's
3637
requested encoding, but avoids setting LC_CTYPE from the
@@ -128,4 +129,14 @@ void git_setup_gettext(void)
128129
init_gettext_charset("git");
129130
textdomain("git");
130131
}
132+
133+
/* return the number of columns of string 's' in current locale */
134+
int gettext_width(const char *s)
135+
{
136+
static int is_utf8 = -1;
137+
if (is_utf8 == -1)
138+
is_utf8 = !strcmp(charset, "UTF-8");
139+
140+
return is_utf8 ? utf8_strwidth(s) : strlen(s);
141+
}
131142
#endif

Diff for: gettext.h

+5
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,15 @@
3030

3131
#ifndef NO_GETTEXT
3232
extern void git_setup_gettext(void);
33+
extern int gettext_width(const char *s);
3334
#else
3435
static inline void git_setup_gettext(void)
3536
{
3637
}
38+
static inline int gettext_width(const char *s)
39+
{
40+
return strlen(s);
41+
}
3742
#endif
3843

3944
#ifdef GETTEXT_POISON

Diff for: transport.h

+1
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ struct transport {
106106
#define TRANSPORT_RECURSE_SUBMODULES_ON_DEMAND 256
107107

108108
#define TRANSPORT_SUMMARY_WIDTH (2 * DEFAULT_ABBREV + 3)
109+
#define TRANSPORT_SUMMARY(x) (int)(TRANSPORT_SUMMARY_WIDTH + strlen(x) - gettext_width(x)), (x)
109110

110111
/* Returns a transport suitable for the url */
111112
struct transport *transport_get(struct remote *, const char *);

0 commit comments

Comments
 (0)