* [PATCH v2] CodingGuidelines: use octal escapes, not hex
@ 2023-06-14 0:15 Jonathan Tan
2023-06-14 0:28 ` Junio C Hamano
2023-06-14 21:31 ` [PATCH v3] " Jonathan Tan
0 siblings, 2 replies; 4+ messages in thread
From: Jonathan Tan @ 2023-06-14 0:15 UTC (permalink / raw)
To: git; +Cc: Jonathan Tan, sunshine, gitster
Extend the shell-scripting section of CodingGuidelines to suggest octal
escape sequences (e.g. "\302\242") over hexadecimal (e.g. "\xc2\xa2")
since the latter can be a source of portability problems.
Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
---
I've used Eric's suggestion for the commit message and limited the scope
of the documentation change to printf.
Version 1 was here:
https://lore.kernel.org/git/20230613172927.19019-1-jonathantanmy@google.com/
---
Documentation/CodingGuidelines | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/Documentation/CodingGuidelines b/Documentation/CodingGuidelines
index 003393ed16..30ac7d2d3f 100644
--- a/Documentation/CodingGuidelines
+++ b/Documentation/CodingGuidelines
@@ -188,6 +188,10 @@ For shell scripts specifically (not exhaustive):
hopefully nobody starts using "local" before they are reimplemented
in C ;-)
+ - Use octal escape sequences (e.g. "\302\242"), not hexadecimal (e.g.
+ "\xc2\xa2"), since the latter is not portable across commands like
+ "printf".
+
For C programs:
--
2.41.0.162.gfafddb0af9-goog
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2] CodingGuidelines: use octal escapes, not hex
2023-06-14 0:15 [PATCH v2] CodingGuidelines: use octal escapes, not hex Jonathan Tan
@ 2023-06-14 0:28 ` Junio C Hamano
2023-06-14 21:31 ` [PATCH v3] " Jonathan Tan
1 sibling, 0 replies; 4+ messages in thread
From: Junio C Hamano @ 2023-06-14 0:28 UTC (permalink / raw)
To: Jonathan Tan; +Cc: git, sunshine
Jonathan Tan <jonathantanmy@google.com> writes:
> Extend the shell-scripting section of CodingGuidelines to suggest octal
> escape sequences (e.g. "\302\242") over hexadecimal (e.g. "\xc2\xa2")
> since the latter can be a source of portability problems.
>
> Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
> ---
> I've used Eric's suggestion for the commit message and limited the scope
> of the documentation change to printf.
>
> Version 1 was here:
> https://lore.kernel.org/git/20230613172927.19019-1-jonathantanmy@google.com/
> ---
> Documentation/CodingGuidelines | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/Documentation/CodingGuidelines b/Documentation/CodingGuidelines
> index 003393ed16..30ac7d2d3f 100644
> --- a/Documentation/CodingGuidelines
> +++ b/Documentation/CodingGuidelines
> @@ -188,6 +188,10 @@ For shell scripts specifically (not exhaustive):
> hopefully nobody starts using "local" before they are reimplemented
> in C ;-)
>
> + - Use octal escape sequences (e.g. "\302\242"), not hexadecimal (e.g.
> + "\xc2\xa2"), since the latter is not portable across commands like
> + "printf".
I'd say
- Use octal ... not hex..., in printf format string.
not "commands LIKE".
Thanks.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v3] CodingGuidelines: use octal escapes, not hex
2023-06-14 0:15 [PATCH v2] CodingGuidelines: use octal escapes, not hex Jonathan Tan
2023-06-14 0:28 ` Junio C Hamano
@ 2023-06-14 21:31 ` Jonathan Tan
2023-06-14 21:54 ` Junio C Hamano
1 sibling, 1 reply; 4+ messages in thread
From: Jonathan Tan @ 2023-06-14 21:31 UTC (permalink / raw)
To: git; +Cc: Jonathan Tan, gitster
Extend the shell-scripting section of CodingGuidelines to suggest octal
escape sequences (e.g. "\302\242") over hexadecimal (e.g. "\xc2\xa2")
since the latter can be a source of portability problems.
Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
---
Changes in v3: Used Junio's suggestion [1].
[1] https://lore.kernel.org/git/xmqqy1km28g9.fsf@gitster.g/
---
Range-diff against v2:
1: c775a0db22 ! 1: 0b7d3ed8f5 CodingGuidelines: use octal escapes, not hex
@@ Commit message
Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
---
- I've used Eric's suggestion for the commit message and limited the scope
- of the documentation change to printf.
+ Changes in v3: Used Junio's suggestion [1].
- Version 1 was here:
- https://lore.kernel.org/git/20230613172927.19019-1-jonathantanmy@google.com/
+ [1] https://lore.kernel.org/git/xmqqy1km28g9.fsf@gitster.g/
## Documentation/CodingGuidelines ##
@@ Documentation/CodingGuidelines: For shell scripts specifically (not exhaustive):
@@ Documentation/CodingGuidelines: For shell scripts specifically (not exhaustive):
in C ;-)
+ - Use octal escape sequences (e.g. "\302\242"), not hexadecimal (e.g.
-+ "\xc2\xa2"), since the latter is not portable across commands like
-+ "printf".
++ "\xc2\xa2") in printf format strings, since hexadecimal escape
++ sequences are not portable.
+
For C programs:
Documentation/CodingGuidelines | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/Documentation/CodingGuidelines b/Documentation/CodingGuidelines
index 003393ed16..39ef53c237 100644
--- a/Documentation/CodingGuidelines
+++ b/Documentation/CodingGuidelines
@@ -188,6 +188,10 @@ For shell scripts specifically (not exhaustive):
hopefully nobody starts using "local" before they are reimplemented
in C ;-)
+ - Use octal escape sequences (e.g. "\302\242"), not hexadecimal (e.g.
+ "\xc2\xa2") in printf format strings, since hexadecimal escape
+ sequences are not portable.
+
For C programs:
--
2.41.0.162.gfafddb0af9-goog
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v3] CodingGuidelines: use octal escapes, not hex
2023-06-14 21:31 ` [PATCH v3] " Jonathan Tan
@ 2023-06-14 21:54 ` Junio C Hamano
0 siblings, 0 replies; 4+ messages in thread
From: Junio C Hamano @ 2023-06-14 21:54 UTC (permalink / raw)
To: Jonathan Tan; +Cc: git
Jonathan Tan <jonathantanmy@google.com> writes:
> Extend the shell-scripting section of CodingGuidelines to suggest octal
> escape sequences (e.g. "\302\242") over hexadecimal (e.g. "\xc2\xa2")
> since the latter can be a source of portability problems.
Sounds good. On a typical GNU system, /usr/bin/printf as well as
printf built into bash groks "\x<hex>" escapes in its format string,
but we cannot depend on it because POSIX does not require support
for "\x<hex>", and printf built into dash indeed does not. It is a
good idea to stress that this is specifically about the format
string (in other words, nothing magical happens when using octal or
hex escapes in say "printf '%s\n' '\302\242'").
> + - Use octal escape sequences (e.g. "\302\242"), not hexadecimal (e.g.
> + "\xc2\xa2") in printf format strings, since hexadecimal escape
> + sequences are not portable.
Will queue. Thanks.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-06-14 21:54 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-14 0:15 [PATCH v2] CodingGuidelines: use octal escapes, not hex Jonathan Tan
2023-06-14 0:28 ` Junio C Hamano
2023-06-14 21:31 ` [PATCH v3] " Jonathan Tan
2023-06-14 21:54 ` Junio C Hamano
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).