Message ID | 20181105192059.20303-16-pclouds@gmail.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | Mark more strings for translation | expand |
Nguyễn Thái Ngọc Duy <pclouds@gmail.com> writes: > static const char *describe_object(struct object *obj) > { > - static struct strbuf buf = STRBUF_INIT; > - char *name = name_objects ? > - lookup_decoration(fsck_walk_options.object_names, obj) : NULL; > + static struct strbuf bufs[4] = { > + STRBUF_INIT, STRBUF_INIT, STRBUF_INIT, STRBUF_INIT > + }; If you need to repeat _INIT anyway, perhaps you want to actively omit the 4 from above, no? If you typed 6 by mistake instead, you'd be in trouble when using the last two elements. > static int objerror(struct object *obj, const char *err) > { > errors_found |= ERROR_OBJECT; > - objreport(obj, "error", err); > + fprintf_ln(stderr, "error in %s %s: %s", > + printable_type(obj), describe_object(obj), err); > return -1; > } Makes sense. > static int fsck_error_func(struct fsck_options *o, > struct object *obj, int type, const char *message) > { > - objreport(obj, (type == FSCK_WARN) ? "warning" : "error", message); > - return (type == FSCK_WARN) ? 0 : 1; > + if (type == FSCK_WARN) { > + fprintf_ln(stderr, "warning in %s %s: %s", > + printable_type(obj), describe_object(obj), message); > + return 0; > + } > + > + fprintf_ln(stderr, "error in %s %s: %s", > + printable_type(obj), describe_object(obj), message); > + return 1; Make it look more symmetrical like the original, perhaps by if (type == FSCK_WARN) { ... return 0; } else { /* FSCK_ERROR */ ... return 1; } Actually, wouldn't it be clearer to see what is going on, if we did it like this instead? const char *fmt = (type == FSCK_WARN) ? N_("warning in %s %s: %s") : N_("error in %s %s: %s"); fprintf_ln(stderr, _(fmt), printable_type(obj), describe_object(obj), message); return (type == FSCK_WARN) ? 0 : 1; It would show that in either case we show these three things in the message. I dunno.
On Tue, Nov 6, 2018 at 4:41 AM Junio C Hamano <gitster@pobox.com> wrote: > > static int fsck_error_func(struct fsck_options *o, > > struct object *obj, int type, const char *message) > > { > > - objreport(obj, (type == FSCK_WARN) ? "warning" : "error", message); > > - return (type == FSCK_WARN) ? 0 : 1; > > + if (type == FSCK_WARN) { > > + fprintf_ln(stderr, "warning in %s %s: %s", > > + printable_type(obj), describe_object(obj), message); > > + return 0; > > + } > > + > > + fprintf_ln(stderr, "error in %s %s: %s", > > + printable_type(obj), describe_object(obj), message); > > + return 1; > > Make it look more symmetrical like the original, perhaps by > > if (type == FSCK_WARN) { > ... > return 0; > } else { /* FSCK_ERROR */ > ... > return 1; > } > > Actually, wouldn't it be clearer to see what is going on, if we did > it like this instead? > > const char *fmt = (type == FSCK_WARN) > ? N_("warning in %s %s: %s") > : N_("error in %s %s: %s"); > fprintf_ln(stderr, _(fmt), > printable_type(obj), describe_object(obj), message); > return (type == FSCK_WARN) ? 0 : 1; > > It would show that in either case we show these three things in the > message. I dunno. Specifying "type == FSCK_WARN" twice triggers me (what if we add a third fsck type?) so I just turn this to a switch/case block instead (and get to know the third fsck type FSCK_IGNORE).
diff --git a/builtin/fsck.c b/builtin/fsck.c index 06eb421720..504f47d7a4 100644 --- a/builtin/fsck.c +++ b/builtin/fsck.c @@ -52,16 +52,24 @@ static int name_objects; static const char *describe_object(struct object *obj) { - static struct strbuf buf = STRBUF_INIT; - char *name = name_objects ? - lookup_decoration(fsck_walk_options.object_names, obj) : NULL; + static struct strbuf bufs[4] = { + STRBUF_INIT, STRBUF_INIT, STRBUF_INIT, STRBUF_INIT + }; + static int b = 0; + struct strbuf *buf; + char *name = NULL; - strbuf_reset(&buf); - strbuf_addstr(&buf, oid_to_hex(&obj->oid)); + if (name_objects) + name = lookup_decoration(fsck_walk_options.object_names, obj); + + buf = bufs + b; + b = (b + 1) % ARRAY_SIZE(bufs); + strbuf_reset(buf); + strbuf_addstr(buf, oid_to_hex(&obj->oid)); if (name) - strbuf_addf(&buf, " (%s)", name); + strbuf_addf(buf, " (%s)", name); - return buf.buf; + return buf->buf; } static const char *printable_type(struct object *obj) @@ -105,25 +113,26 @@ static int fsck_config(const char *var, const char *value, void *cb) return git_default_config(var, value, cb); } -static void objreport(struct object *obj, const char *msg_type, - const char *err) -{ - fprintf(stderr, "%s in %s %s: %s\n", - msg_type, printable_type(obj), describe_object(obj), err); -} - static int objerror(struct object *obj, const char *err) { errors_found |= ERROR_OBJECT; - objreport(obj, "error", err); + fprintf_ln(stderr, "error in %s %s: %s", + printable_type(obj), describe_object(obj), err); return -1; } static int fsck_error_func(struct fsck_options *o, struct object *obj, int type, const char *message) { - objreport(obj, (type == FSCK_WARN) ? "warning" : "error", message); - return (type == FSCK_WARN) ? 0 : 1; + if (type == FSCK_WARN) { + fprintf_ln(stderr, "warning in %s %s: %s", + printable_type(obj), describe_object(obj), message); + return 0; + } + + fprintf_ln(stderr, "error in %s %s: %s", + printable_type(obj), describe_object(obj), message); + return 1; } static struct object_array pending; @@ -165,10 +174,12 @@ static int mark_object(struct object *obj, int type, void *data, struct fsck_opt if (!(obj->flags & HAS_OBJ)) { if (parent && !has_object_file(&obj->oid)) { - printf("broken link from %7s %s\n", - printable_type(parent), describe_object(parent)); - printf(" to %7s %s\n", - printable_type(obj), describe_object(obj)); + printf_ln("broken link from %7s %s\n" + " to %7s %s", + printable_type(parent), + describe_object(parent), + printable_type(obj), + describe_object(obj)); errors_found |= ERROR_REACHABLE; } return 1; @@ -371,10 +382,11 @@ static int fsck_obj(struct object *obj, void *buffer, unsigned long size) struct tag *tag = (struct tag *) obj; if (show_tags && tag->tagged) { - printf("tagged %s %s", printable_type(tag->tagged), - describe_object(tag->tagged)); - printf(" (%s) in %s\n", tag->tag, - describe_object(&tag->object)); + printf_ln("tagged %s %s (%s) in %s", + printable_type(tag->tagged), + describe_object(tag->tagged), + tag->tag, + describe_object(&tag->object)); } }
These messages will be marked for translation later. Reduce word legos and give translators almost full phrases. describe_object() is updated so that it can be called from printf() twice. While at there, remove \n from the strings to reduce a bit of work from translators. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> --- builtin/fsck.c | 62 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 37 insertions(+), 25 deletions(-)