{"thread":{"id":"61851","subject":"[PATCH] doc: fix hex code escapes in git-ls-files","startedAt":"2024-07-26T15:42:17Z","lastAt":"2024-07-26T17:52:20Z","messageCount":3,"participants":["Jayson Rhynas","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"499451","messageId":"CACStHN-Gs2Sxej+md6zWr3V1dFo+pp=B4yEPm9=uPambDR2NaQ@mail.gmail.com","threadId":"61851","inReplyTo":null,"subject":"[PATCH] doc: fix hex code escapes in git-ls-files","fromName":"Jayson Rhynas","fromEmail":"jayrhynas@gmail.com","sentAt":"2024-07-26T15:41:40Z","receivedAt":"2024-07-26T15:42:17Z","isPatch":true,"sender":{"key":"jayrhynas@gmail.com","avatar":null},"body":"The --format option on the git-ls-files man page states that `%xx`\ninterpolates to the character with hex code `xx`. This mirrors the\ndocumentation and behavior of `git for-each-ref --format=...`. However,\nin reality it requires the character with code `XX` to be specified as\n`%xXX`, mirroring the behaviour of  `git log --format`.\n\nSigned-off-by: Jayson Rhynas <jayrhynas@gmail.com>\n---\n Documentation/git-ls-files.txt | 6 +++---\n 1 file changed, 3 insertions(+), 3 deletions(-)\n\ndiff --git a/Documentation/git-ls-files.txt b/Documentation/git-ls-files.txt\nindex d08c7da8f4..58c529afbe 100644\n--- a/Documentation/git-ls-files.txt\n+++ b/Documentation/git-ls-files.txt\n@@ -219,9 +219,9 @@ followed by the  (\"attr/<eolattr>\").\n\n --format=<format>::\n  A string that interpolates `%(fieldname)` from the result being shown.\n- It also interpolates `%%` to `%`, and `%xx` where `xx` are hex digits\n- interpolates to character with hex code `xx`; for example `%00`\n- interpolates to `\\0` (NUL), `%09` to `\\t` (TAB) and %0a to `\\n` (LF).\n+ It also interpolates `%%` to `%`, and `%xXX` where `XX` are hex digits\n+ interpolates to character with hex code `XX`; for example `%x00`\n+ interpolates to `\\0` (NUL), `%x09` to `\\t` (TAB) and %x0a to `\\n` (LF).\n  --format cannot be combined with `-s`, `-o`, `-k`, `-t`, `--resolve-undo`\n  and `--eol`.\n \\--::\n\nbase-commit: c2b3f2b3cdbf5ad9feb978dd367d77561a1271f7\n-- \n2.44.0\n"},{"id":"499457","messageId":"xmqqh6ccvz2v.fsf@gitster.g","threadId":"61851","inReplyTo":"CACStHN-Gs2Sxej+md6zWr3V1dFo+pp=B4yEPm9=uPambDR2NaQ@mail.gmail.com","subject":"Re: [PATCH] doc: fix hex code escapes in git-ls-files","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2024-07-26T17:32:24Z","receivedAt":"2024-07-26T17:32:27Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jayson Rhynas <jayrhynas@gmail.com> writes:\n\n> The --format option on the git-ls-files man page states that `%xx`\n> interpolates to the character with hex code `xx`. This mirrors the\n> documentation and behavior of `git for-each-ref --format=...`. However,\n> in reality it requires the character with code `XX` to be specified as\n> `%xXX`, mirroring the behaviour of  `git log --format`.\n\nGiven that no placeholder strings ls-files uses begin with two\ncharacters that are valid hexadecimal, it is tempting to say that we\nprobably can teach strbuf_expand_literal() to grok %XX the same way\nas %xXX for 256 cases where XX is hexadecimal, and do away with this\ndocumentation update, and it would make things consistent.\n\nDoing such a change is also almost trivial (see below).\n\nBut \"git log --format\" shares the code, and over there, %cd is a\nplaceholder that is committer datestamp, not a byte with value 205,\nso that would not quite work.\n\n> Signed-off-by: Jayson Rhynas <jayrhynas@gmail.com>\n> ---\n>  Documentation/git-ls-files.txt | 6 +++---\n>  1 file changed, 3 insertions(+), 3 deletions(-)\n>\n> diff --git a/Documentation/git-ls-files.txt b/Documentation/git-ls-files.txt\n> index d08c7da8f4..58c529afbe 100644\n> --- a/Documentation/git-ls-files.txt\n> +++ b/Documentation/git-ls-files.txt\n> @@ -219,9 +219,9 @@ followed by the  (\"attr/<eolattr>\").\n>\n>  --format=<format>::\n>   A string that interpolates `%(fieldname)` from the result being shown.\n> - It also interpolates `%%` to `%`, and `%xx` where `xx` are hex digits\n> - interpolates to character with hex code `xx`; for example `%00`\n> - interpolates to `\\0` (NUL), `%09` to `\\t` (TAB) and %0a to `\\n` (LF).\n> + It also interpolates `%%` to `%`, and `%xXX` where `XX` are hex digits\n> + interpolates to character with hex code `XX`; for example `%x00`\n> + interpolates to `\\0` (NUL), `%x09` to `\\t` (TAB) and %x0a to `\\n` (LF).\n>   --format cannot be combined with `-s`, `-o`, `-k`, `-t`, `--resolve-undo`\n>   and `--eol`.\n\nThe change looks good.\n\nThanks.\n\n\n\n[DONOTUSE-BROKEN] Allow %XX as a synonym for %xXX\n\n strbuf.c | 8 ++++----\n 1 file changed, 4 insertions(+), 4 deletions(-)\n\ndiff --git i/strbuf.c w/strbuf.c\nindex 3d2189a7f6..3594e10d09 100644\n--- i/strbuf.c\n+++ w/strbuf.c\n@@ -443,13 +443,13 @@ size_t strbuf_expand_literal(struct strbuf *sb, const char *placeholder)\n \tcase 'n':\t\t/* newline */\n \t\tstrbuf_addch(sb, '\\n');\n \t\treturn 1;\n-\tcase 'x':\n-\t\t/* %x00 == NUL, %x0a == LF, etc. */\n-\t\tch = hex2chr(placeholder + 1);\n+\tdefault:\n+\t\t/* %x00 == NUL, %x0a == LF, etc., with 'x' being optional */\n+\t\tch = hex2chr(placeholder + (placeholder[0] == 'x'));\n \t\tif (ch < 0)\n \t\t\treturn 0;\n \t\tstrbuf_addch(sb, ch);\n-\t\treturn 3;\n+\t\treturn 2 + (placeholder[0] == 'x');\n \t}\n \treturn 0;\n }\n"},{"id":"499459","messageId":"xmqq1q3gvy5s.fsf@gitster.g","threadId":"61851","inReplyTo":"xmqqh6ccvz2v.fsf@gitster.g","subject":"Re: [PATCH] doc: fix hex code escapes in git-ls-files","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2024-07-26T17:52:15Z","receivedAt":"2024-07-26T17:52:20Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n>>  --format=<format>::\n>>   A string that interpolates `%(fieldname)` from the result being shown.\n>> - It also interpolates `%%` to `%`, and `%xx` where `xx` are hex digits\n>> - interpolates to character with hex code `xx`; for example `%00`\n>> - interpolates to `\\0` (NUL), `%09` to `\\t` (TAB) and %0a to `\\n` (LF).\n>> + It also interpolates `%%` to `%`, and `%xXX` where `XX` are hex digits\n>> + interpolates to character with hex code `XX`; for example `%x00`\n>> + interpolates to `\\0` (NUL), `%x09` to `\\t` (TAB) and %x0a to `\\n` (LF).\n>>   --format cannot be combined with `-s`, `-o`, `-k`, `-t`, `--resolve-undo`\n>>   and `--eol`.\n>\n> The change looks good.\n\nI do not know what your MUA did to it, but this won't apply as a\npatch.\n"}]}