Skip to content

Commit 6eac70f

Browse files
KarthikNayakgitster
authored andcommitted
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 <[email protected]> Mentored-by: Christian Couder <[email protected]> Mentored-by: Matthieu Moy <[email protected]> Signed-off-by: Karthik Nayak <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1a34728 commit 6eac70f

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

ref-filter.c

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,27 @@
1616
#include "trailer.h"
1717
#include "wt-status.h"
1818

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+
1940
typedef enum { FIELD_STR, FIELD_ULONG, FIELD_TIME } cmp_type;
2041
typedef enum { COMPARE_EQUAL, COMPARE_UNEQUAL, COMPARE_NONE } cmp_status;
2142

@@ -1181,15 +1202,15 @@ static void fill_remote_ref_details(struct used_atom *atom, const char *refname,
11811202
else if (atom->u.remote_ref.option == RR_TRACK) {
11821203
if (stat_tracking_info(branch, &num_ours,
11831204
&num_theirs, NULL)) {
1184-
*s = xstrdup("gone");
1205+
*s = xstrdup(msgs.gone);
11851206
} else if (!num_ours && !num_theirs)
11861207
*s = "";
11871208
else if (!num_ours)
1188-
*s = xstrfmt("behind %d", num_theirs);
1209+
*s = xstrfmt(msgs.behind, num_theirs);
11891210
else if (!num_theirs)
1190-
*s = xstrfmt("ahead %d", num_ours);
1211+
*s = xstrfmt(msgs.ahead, num_ours);
11911212
else
1192-
*s = xstrfmt("ahead %d, behind %d",
1213+
*s = xstrfmt(msgs.ahead_behind,
11931214
num_ours, num_theirs);
11941215
if (!atom->u.remote_ref.nobracket && *s[0]) {
11951216
const char *to_free = *s;

ref-filter.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,5 +113,7 @@ struct ref_sorting *ref_default_sorting(void);
113113
int parse_opt_merge_filter(const struct option *opt, const char *arg, int unset);
114114
/* Get the current HEAD's description */
115115
char *get_head_description(void);
116+
/* Set up translated strings in the output. */
117+
void setup_ref_filter_porcelain_msg(void);
116118

117119
#endif /* REF_FILTER_H */

0 commit comments

Comments
 (0)