git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 02/11] Support GIT_TEST_GETTEXT_POISON=rot13

From
Junio C Hamano <gitster@pobox.com>
Date
Jan 12, 2021, 19:37 UTC
Message-ID
<xmqqmtxe3q0u.fsf@gitster.c.googlers.com>
In-Reply-To
<ab7832fc7ac783bc8f8c10014fc9747128fc37bc.1610441263.git.gitgitgadget@gmail.com>

"Johannes Schindelin via GitGitGadget" <gitgitgadget@gmail.com> writes:

Show 8 quoted lines
> +const char *gettext_maybe_rot13(const char *msgid)
> +{
> +...
> +	while (*msgid) {
> +		const char *p = strchrnul(msgid, '%'), *spec;
> +
> +		while (*p && p[1] == '%')
> +			p = strchrnul(p + 2, '%');

We are at '%', and while the next is '%' (i.e. a literal '%' is asked), we skip these two bytes and then we go back to the equivalent of the initialization of 'p'. Effects? We leave the loop when we are at the end of the string, or at '%' that is not followed by a '%'.

It would have been easier to understand what is going on in the loop if there weren't duplicated strchrnul() call, perhaps

	const char *p = msgid;
	while (*(p = strchrnul(p, '%')) == '%' && p[1] == '%')
        	p += 2;

That reads "find '%' and if the next char is also '%', skip these two and redo the loop", which would be equivalent. And it would be much easier to follow the logic.

> +		if (p != msgid) {

And if 'p' is different (actually we know p is the same as, or always ahead of, msgid, so "if (msgid < p)" would be easier to follow for readers) ...

> +			strbuf_addstr(buf, "<rot13>");
> +			while (p != msgid)
Ditto.
> +				strbuf_addch(buf, do_rot13(*(msgid++)));
> +			strbuf_addstr(buf, "</rot13>");

... we add a section of obfuscated output enclosed with an xml looking marker.

> +		}
> +
> +		if (!*p)
> +			break;
And if we are at the end, we are done.
> +		spec = strpbrk(p + 1, "diouxXeEfFgGaAcsCSpnm%");
> +		if (!spec)
> +			BUG("Unrecognized format string: %s", p);

It is a bit surprising that things like "%.*d" and "%.7f" do not appear in our translatable strings (or perhaps this is one of the places why the series is marked RFH and is not complete?).

Show 6 quoted lines
> +		strbuf_add(buf, p, spec + 1 - p);
> +		msgid = spec + 1;
> +	}
> +
> +	return buf->buf;
> +}
Anyway, thanks for a fun reading.
Previous: Johannes Schindelin via GitGitGadgetNext: Johannes Schindelin via GitGitGadget
Message 4 of 31 in “[RFH] Introduce support for GETTEXT_POISON=rot13”
  1. 00/11 [RFH] Introduce support for GETTEXT_POISON=rot13Johannes Schindelin via GitGitGadget, Jan 12, 2021
  2. 03/11 parse-options: add forgotten translationsJohannes Schindelin via GitGitGadget, Jan 12, 2021
  3. 02/11 Support GIT_TEST_GETTEXT_POISON=rot13Johannes Schindelin via GitGitGadget, Jan 12, 2021
  4. Junio C HamanoJan 12, 2021
  5. 01/11 tests: remove unnecessary GIT_TEST_GETTEXT_POISON=false constructsJohannes Schindelin via GitGitGadget, Jan 12, 2021
  6. SZEDER GáborJan 12, 2021
  7. 06/11 t0041: stop using `test_i18ngrep` on untranslated outputJohannes Schindelin via GitGitGadget, Jan 12, 2021
  8. 05/11 t0006: use `test_i18ncmp` only for C localesJohannes Schindelin via GitGitGadget, Jan 12, 2021
  9. 07/11 t0027: mark a function as requiring the C localeJohannes Schindelin via GitGitGadget, Jan 12, 2021
  10. 08/11 t6301: do not expect the output of `for-each-ref` to be translatedJohannes Schindelin via GitGitGadget, Jan 12, 2021
  11. 10/11 GETTEXT_POISON=rot13: perform actual checks in `test_i18ngrep`Johannes Schindelin via GitGitGadget, Jan 12, 2021
  12. 09/11 GETTEXT_POISON=rot13: do compare the output in `test_i18ncmp`Johannes Schindelin via GitGitGadget, Jan 12, 2021
  13. Junio C HamanoJan 12, 2021
  14. Johannes SchindelinJan 15, 2021
  15. Junio C HamanoJan 15, 2021
  16. Johannes SchindelinJan 18, 2021
  17. 11/11 test-tool i18n: do not complain about empty messagesJohannes Schindelin via GitGitGadget, Jan 12, 2021
  18. 04/11 sha1dc: mark forgotten message for translationJohannes Schindelin via GitGitGadget, Jan 12, 2021
  19. Jeff KingJan 12, 2021
  20. Junio C HamanoJan 12, 2021
  21. Johannes SchindelinJan 15, 2021
  22. Jeff KingJan 15, 2021
  23. Johannes SchindelinJan 18, 2021
  24. Junio C HamanoJan 18, 2021
  25. Johannes SchindelinJan 19, 2021
  26. Jeff KingJan 12, 2021
  27. Junio C HamanoJan 12, 2021
  28. Jeff KingJan 13, 2021
  29. Junio C HamanoJan 16, 2021
  30. Ævar Arnfjörð BjarmasonJan 12, 2021
  31. Johannes SchindelinJan 15, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.