Re: [PATCH] use strbuf_addstr() for adding constant strings to a strbuf, part 2
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Sep 15, 2016, 21:39 UTC
- Message-ID
- <xmqqwpiclu65.fsf@gitster.mtv.corp.google.com>
- In-Reply-To
- <67756074-836f-2238-37c3-0d186325bd00@web.de>
René Scharfe <l.s.r@web.de> writes:
Show 31 quoted lines
> Am 15.09.2016 um 22:01 schrieb Junio C Hamano:
>> René Scharfe <l.s.r@web.de> writes:
>>
>>> Take this for example:
>>>
>>> - strbuf_addf(&o->obuf, _("(bad commit)\n"));
>>> + strbuf_addstr(&o->obuf, _("(bad commit)\n"));
>>>
>>> If there's a language that uses percent signs instead of parens or as
>>> regular letters, then they need to be escaped in the translated string
>>> before, but not after the patch. As I wrote: silly.
>>
>> Ahh, OK, so "This use of addf only has format part and nothing else,
>> hence the format part can be taken as-is" which is the Coccinelle rule
>> used to produce this patch is incomplete and always needs manual
>> inspection, in case the format part wanted to give a literal % in
>> the output. E.g. it is a bug to convert this
>>
>> strbuf_addf(&buf, _("this is 100%% wrong!"));
>>
>> to
>>
>> strbuf_addstr(&buf, _("this is 100%% wrong!"));
>
> Right. Such strings seem to be quite rare in practice, though.
>
>> Thanks for clarification. Perhaps the strbuf.cocci rule file can
>> have some comment to warn the person who builds *.patch file to look
>> for % in E2, or something?
>
> Something like this?Yup, with something like that I would understdood where that puzzling question came from.
Thanks.
Show 15 quoted lines
> > --- > contrib/coccinelle/strbuf.cocci | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/contrib/coccinelle/strbuf.cocci b/contrib/coccinelle/strbuf.cocci > index 7932d48..3f535ca 100644 > --- a/contrib/coccinelle/strbuf.cocci > +++ b/contrib/coccinelle/strbuf.cocci > @@ -1,3 +1,5 @@ > +// Careful, this is not fully equivalent: "%" is no longer treated > +// specially. Check for "%%", "%m" etc. in the format string (E2). > @@ > expression E1, E2; > @@