# [PATCH v1] msvc: fix non-standard escape sequence in source

5 messages from 2018-07-24 to 2018-07-25. Participants: git@jeffhostetler.com, Eric Sunshine, Junio C Hamano, Beat Bolli, Jeff Hostetler.
Thread: https://gitlist.dev/t/48946

## git@jeffhostetler.com, 2018-07-24 14:42

Subject: [PATCH v1] msvc: fix non-standard escape sequence in source
Message-ID: <20180724144249.2857-1-git@jeffhostetler.com>
URL: https://gitlist.dev/e/20180724144249.2857-1-git%40jeffhostetler.com

```
From: Jeff Hostetler <jeffhost@microsoft.com>

Replace non-standard "\e" escape sequence with "\x1B".

In commit 7a17918c34f4e83982456ffe22d880c3cda5384f a trace message with
several "\e" escape sequences was added.  This causes a compiler warning
under MSVC.

According to [1], the "\e" sequence is an extension supported by GCC,
clang, and tcc.

[1] https://en.wikipedia.org/wiki/Escape_sequences_in_C

Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com>
---
 convert.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/convert.c b/convert.c
index 56cfe31..52092be 100644
--- a/convert.c
+++ b/convert.c
@@ -335,7 +335,7 @@ static void trace_encoding(const char *context, const char *path,
 	strbuf_addf(&trace, "%s (%s, considered %s):\n", context, path, encoding);
 	for (i = 0; i < len && buf; ++i) {
 		strbuf_addf(
-			&trace,"| \e[2m%2i:\e[0m %2x \e[2m%c\e[0m%c",
+			&trace,"| \x1B[2m%2i:\x1B[0m %2x \x1B[2m%c\x1B[0m%c",
 			i,
 			(unsigned char) buf[i],
 			(buf[i] > 32 && buf[i] < 127 ? buf[i] : ' '),
-- 
2.9.3


```

## Eric Sunshine, 2018-07-24 17:33

Subject: Re: [PATCH v1] msvc: fix non-standard escape sequence in source
Message-ID: <CAPig+cSzJQS9PnHgEbyUpOAQGQgWJuwZDP7nsgBMECzy2C3wkQ@mail.gmail.com>
URL: https://gitlist.dev/e/CAPig%2BcSzJQS9PnHgEbyUpOAQGQgWJuwZDP7nsgBMECzy2C3wkQ%40mail.gmail.com
In-Reply-To: <20180724144249.2857-1-git@jeffhostetler.com>

```
On Tue, Jul 24, 2018 at 10:43 AM <git@jeffhostetler.com> wrote:
> Replace non-standard "\e" escape sequence with "\x1B".
>
> In commit 7a17918c34f4e83982456ffe22d880c3cda5384f a trace message with
> several "\e" escape sequences was added.  This causes a compiler warning
> under MSVC.

Wrong commit. That code was actually introduced by 541d059cd9
(convert: add tracing for 'working-tree-encoding' attribute,
2018-04-15).

> diff --git a/convert.c b/convert.c
> @@ -335,7 +335,7 @@ static void trace_encoding(const char *context, const char *path,
>         strbuf_addf(&trace, "%s (%s, considered %s):\n", context, path, encoding);
>         for (i = 0; i < len && buf; ++i) {
>                 strbuf_addf(
> -                       &trace,"| \e[2m%2i:\e[0m %2x \e[2m%c\e[0m%c",
> +                       &trace,"| \x1B[2m%2i:\x1B[0m %2x \x1B[2m%c\x1B[0m%c",

In this codebase, ESC is always spelled as octal \033 rather than hex \x1b.

```

## Junio C Hamano, 2018-07-24 18:03

Subject: Re: [PATCH v1] msvc: fix non-standard escape sequence in source
Message-ID: <xmqq6014zf33.fsf@gitster-ct.c.googlers.com>
URL: https://gitlist.dev/e/xmqq6014zf33.fsf%40gitster-ct.c.googlers.com
In-Reply-To: <20180724144249.2857-1-git@jeffhostetler.com>

```
git@jeffhostetler.com writes:

> From: Jeff Hostetler <jeffhost@microsoft.com>
>
> Replace non-standard "\e" escape sequence with "\x1B".
>
> In commit 7a17918c34f4e83982456ffe22d880c3cda5384f a trace message with
> several "\e" escape sequences was added.  This causes a compiler warning
> under MSVC.
>
> According to [1], the "\e" sequence is an extension supported by GCC,
> clang, and tcc.

Good spotting.  Please spell it \x1b (or \033 if you are a
traditionalist), as it seems nobody in the existing code uses
uppercase, according to

    $ git grep -e '\\x[A-F][0-9A-F]' -e '\\x[0-9A-F][A-F]' \*.c

and "\033"  is already used in many places

    $ git grep -e '\\0[0-7][0-7]' \*.c



> [1] https://en.wikipedia.org/wiki/Escape_sequences_in_C
>
> Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com>
> ---
>  convert.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/convert.c b/convert.c
> index 56cfe31..52092be 100644
> --- a/convert.c
> +++ b/convert.c
> @@ -335,7 +335,7 @@ static void trace_encoding(const char *context, const char *path,
>  	strbuf_addf(&trace, "%s (%s, considered %s):\n", context, path, encoding);
>  	for (i = 0; i < len && buf; ++i) {
>  		strbuf_addf(
> -			&trace,"| \e[2m%2i:\e[0m %2x \e[2m%c\e[0m%c",
> +			&trace,"| \x1B[2m%2i:\x1B[0m %2x \x1B[2m%c\x1B[0m%c",
>  			i,
>  			(unsigned char) buf[i],
>  			(buf[i] > 32 && buf[i] < 127 ? buf[i] : ' '),

```

## Beat Bolli, 2018-07-24 18:13

Subject: Re: [PATCH v1] msvc: fix non-standard escape sequence in source
Message-ID: <e443fe24-e072-d11c-a6b0-53e7de8a7f5c@drbeat.li>
URL: https://gitlist.dev/e/e443fe24-e072-d11c-a6b0-53e7de8a7f5c%40drbeat.li
In-Reply-To: <20180724144249.2857-1-git@jeffhostetler.com>

```
Hi Jeff

On 24.07.18 16:42, git@jeffhostetler.com wrote:
> From: Jeff Hostetler <jeffhost@microsoft.com>
> 
> Replace non-standard "\e" escape sequence with "\x1B".

This was already fixed in <20180708144342.11922-4-dev+git@drbeat.li>.

Cheers,
Beat


> 
> In commit 7a17918c34f4e83982456ffe22d880c3cda5384f a trace message with
> several "\e" escape sequences was added.  This causes a compiler warning
> under MSVC.
> 
> According to [1], the "\e" sequence is an extension supported by GCC,
> clang, and tcc.
> 
> [1] https://en.wikipedia.org/wiki/Escape_sequences_in_C
> 
> Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com>
> ---
>  convert.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/convert.c b/convert.c
> index 56cfe31..52092be 100644
> --- a/convert.c
> +++ b/convert.c
> @@ -335,7 +335,7 @@ static void trace_encoding(const char *context, const char *path,
>  	strbuf_addf(&trace, "%s (%s, considered %s):\n", context, path, encoding);
>  	for (i = 0; i < len && buf; ++i) {
>  		strbuf_addf(
> -			&trace,"| \e[2m%2i:\e[0m %2x \e[2m%c\e[0m%c",
> +			&trace,"| \x1B[2m%2i:\x1B[0m %2x \x1B[2m%c\x1B[0m%c",
>  			i,
>  			(unsigned char) buf[i],
>  			(buf[i] > 32 && buf[i] < 127 ? buf[i] : ' '),
> 



```

## Jeff Hostetler, 2018-07-25 12:30

Subject: Re: [PATCH v1] msvc: fix non-standard escape sequence in source
Message-ID: <9559a485-1977-d7e8-1bfb-ab2b65b60c02@jeffhostetler.com>
URL: https://gitlist.dev/e/9559a485-1977-d7e8-1bfb-ab2b65b60c02%40jeffhostetler.com
In-Reply-To: <e443fe24-e072-d11c-a6b0-53e7de8a7f5c@drbeat.li>

```


On 7/24/2018 2:13 PM, Beat Bolli wrote:
> Hi Jeff
> 
> On 24.07.18 16:42, git@jeffhostetler.com wrote:
>> From: Jeff Hostetler <jeffhost@microsoft.com>
>>
>> Replace non-standard "\e" escape sequence with "\x1B".
> 
> This was already fixed in <20180708144342.11922-4-dev+git@drbeat.li>.
> 
> Cheers,
> Beat
> 

Thanks for the pointer.  I see that commit is in 'next'.
I was only looking in 'master'.

Thanks,
Jeff


```
