Thread (6 messages) 6 messages, 3 authors, 2016-06-15

Re: [PATCH 2/3] ref-filter: allow porcelain to translate messages in the output

flat view

From: Karthik Nayak <hidden>
Date: 2016-06-15 23:06:49

On Sun, Oct 11, 2015 at 9:46 PM, Matthieu Moy [off-list ref] wrote:
This patch shows the way, but is obviously incomplete as it works only
for "nobracket" version. Actually, I think the code should first build
the unbracketed output string and then do something like

if (!nobracket) {
        const char *to_free = v->s;
        v->s = xstrfmt("[%s]", v->s);
        free(to_free);
}
Makes sense.
quoted hunk ↗ jump to hunk
so we don't have to worry about brackets anywhere else in the code.

Signed-off-by: Matthieu Moy <redacted>
---
 ref-filter.c | 28 ++++++++++++++++++++++++----
 ref-filter.h |  3 +++
 2 files changed, 27 insertions(+), 4 deletions(-)
diff --git a/ref-filter.c b/ref-filter.c
index 7932c21..c2ee8c9 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -15,6 +15,26 @@
 #include "version.h"
 #include "wt-status.h"

+static struct ref_msg {
+       const char *gone;
+       const char *ahead;
+       const char *behind;
+       const char *ahead_behind;
+} msgs = {
+       "gone",
+       "ahead %d",
+       "behind %d",
+       "ahead %d, behind %d"
+};
+
+void setup_ref_filter_porcelain_msg(void)
+{
+       msgs.gone = _("gone");
+       msgs.ahead = _("ahead %d");
+       msgs.behind = _("behind %d");
+       msgs.ahead_behind = _("ahead %d, behind %d");
+}
+
 typedef enum { FIELD_STR, FIELD_ULONG, FIELD_TIME } cmp_type;

 static struct {
@@ -1124,7 +1144,7 @@ static void populate_value(struct ref_array_item *ref)
                                if (stat_tracking_info(branch, &num_ours,
                                                       &num_theirs, NULL)) {
                                        if (nobracket)
-                                               v->s = "gone";
+                                               v->s = msgs.gone;
                                        else
                                                v->s = "[gone]";
                                        continue;
@@ -1134,17 +1154,17 @@ static void populate_value(struct ref_array_item *ref)
                                        v->s = "";
                                else if (!num_ours) {
                                        if (nobracket)
-                                               v->s = xstrfmt("behind %d", num_theirs);
+                                               v->s = xstrfmt(msgs.behind, num_theirs);
                                        else
                                                v->s = xstrfmt("[behind %d]", num_theirs);
                                } else if (!num_theirs) {
                                        if (nobracket)
-                                               v->s = xstrfmt("ahead %d", num_ours);
+                                               v->s = xstrfmt(msgs.ahead, num_ours);
                                        else
                                                v->s = xstrfmt("[ahead %d]", num_ours);
                                } else {
                                        if (nobracket)
-                                               v->s = xstrfmt("ahead %d, behind %d",
+                                               v->s = xstrfmt(msgs.ahead_behind,
                                                               num_ours, num_theirs);
                                        else
                                                v->s = xstrfmt("[ahead %d, behind %d]",
diff --git a/ref-filter.h b/ref-filter.h
index 0014b92..2cce02c 100644
--- a/ref-filter.h
+++ b/ref-filter.h
@@ -112,4 +112,7 @@ int parse_opt_merge_filter(const struct option *opt, const char *arg, int unset)
 /*  Get the current HEAD's description */
 char *get_head_description(void);

+/*  Set up translated strings in the output. */
+void setup_ref_filter_porcelain_msg(void);
+
 #endif /*  REF_FILTER_H  */
--
2.6.0.rc2.24.gb06d8e9.dirty
I'm squashing this and the other two patches into my series. Thanks :)

-- 
Regards,
Karthik Nayak
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help