ref-filter: allow porcelain to translate messages in the output

Introduce setup_ref_filter_porcelain_msg() so that the messages used in the atom %(upstream:track) can be translated if needed. By default, keep the messages untranslated, which is the right behavior for plumbing commands. This is needed as we port branch.c to use ref-filter's printing API's. Written-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr> Mentored-by: Christian Couder <christian.couder@gmail.com> Mentored-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr> Signed-off-by: Karthik Nayak <karthik.188@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Karthik Nayak committed Jan 10, 2017 at 14:19 UTC 6eac70fa6343a31b5b310a465a442adb6731a26b
2 files changed +27 -4
ref-filter.c
+25 -4
@@ -16,6 +16,27 @@
16 #include "trailer.h"
17 #include "wt-status.h"
18
19 +static struct ref_msg {
20 + const char *gone;
21 + const char *ahead;
22 + const char *behind;
23 + const char *ahead_behind;
24 +} msgs = {
25 + /* Untranslated plumbing messages: */
26 + "gone",
27 + "ahead %d",
28 + "behind %d",
29 + "ahead %d, behind %d"
30 +};
31 +
32 +void setup_ref_filter_porcelain_msg(void)
33 +{
34 + msgs.gone = _("gone");
35 + msgs.ahead = _("ahead %d");
36 + msgs.behind = _("behind %d");
37 + msgs.ahead_behind = _("ahead %d, behind %d");
38 +}
39 +
40 typedef enum { FIELD_STR, FIELD_ULONG, FIELD_TIME } cmp_type;
41 typedef enum { COMPARE_EQUAL, COMPARE_UNEQUAL, COMPARE_NONE } cmp_status;
42
@@ -1181,15 +1202,15 @@ static void fill_remote_ref_details(struct used_atom *atom, const char *refname,
1202 else if (atom->u.remote_ref.option == RR_TRACK) {
1203 if (stat_tracking_info(branch, &num_ours,
1204 &num_theirs, NULL)) {
1184 - *s = xstrdup("gone");
1205 + *s = xstrdup(msgs.gone);
1206 } else if (!num_ours && !num_theirs)
1207 *s = "";
1208 else if (!num_ours)
1188 - *s = xstrfmt("behind %d", num_theirs);
1209 + *s = xstrfmt(msgs.behind, num_theirs);
1210 else if (!num_theirs)
1190 - *s = xstrfmt("ahead %d", num_ours);
1211 + *s = xstrfmt(msgs.ahead, num_ours);
1212 else
1192 - *s = xstrfmt("ahead %d, behind %d",
1213 + *s = xstrfmt(msgs.ahead_behind,
1214 num_ours, num_theirs);
1215 if (!atom->u.remote_ref.nobracket && *s[0]) {
1216 const char *to_free = *s;
ref-filter.h
+2
@@ -113,5 +113,7 @@ struct ref_sorting *ref_default_sorting(void);
113 int parse_opt_merge_filter(const struct option *opt, const char *arg, int unset);
114 /* Get the current HEAD's description */
115 char *get_head_description(void);
116 +/* Set up translated strings in the output. */
117 +void setup_ref_filter_porcelain_msg(void);
118
119 #endif /* REF_FILTER_H */