Re: [fossil-users] fossil diff: extra empty lines in non-console output on Windows

2016-11-05 Thread Artur Shepilko
Ok, the fix is in:
https://fossil-scm.org/index.html/info/476fe9e932f01133


On Mon, Oct 31, 2016 at 12:42 PM, Artur Shepilko  wrote:
> Ok, just dropped the CLA in the mail.
> Sure USPS has an important role in the Fossil project, it probably has
> its own username in the repo too :
>
> Below is the patch I applied to clear the described issue (not sure if
> the list accepts attachments); as I mentioned earlier, it's
> Windows-specific and is very much similar to how it has been patched
> for "fossil cat" issue:
>
> patch-Base:http://fossil-scm.org/index.html/info/d13fc6a6b79e71bd
> ---
> Index: src/printf.c
> ==
> --- src/printf.c
> +++ src/printf.c
> @@ -875,24 +875,33 @@
>  /*
>  ** Write to standard output or standard error.
>  **
>  ** On windows, transform the output into the current terminal encoding
>  ** if the output is going to the screen.  If output is redirected into
> -** a file, no translation occurs.  No translation ever occurs on unix.
> +** a file, no translation occurs. Switch output mode to binary to
> +** properly process line-endings, make sure to switch the mode back to
> +** text when done.
> +** No translation ever occurs on unix.
>  */
>  void fossil_puts(const char *z, int toStdErr){
> +  FILE* out = (toStdErr ? stderr : stdout);
>int n = (int)strlen(z);
>if( n==0 ) return;
> +  assert( toStdErr==0 || toStdErr==1 );
>if( toStdErr==0 ) stdoutAtBOL = (z[n-1]=='\n');
>  #if defined(_WIN32)
>if( fossil_utf8_to_console(z, n, toStdErr) >= 0 ){
>  return;
>}
> +  fflush(out);
> +  _setmode(_fileno(out), _O_BINARY);
>  #endif
> -  assert( toStdErr==0 || toStdErr==1 );
> -  fwrite(z, 1, n, toStdErr ? stderr : stdout);
> -  fflush(toStdErr ? stderr : stdout);
> +  fwrite(z, 1, n, out);
> +#if defined(_WIN32)
> +  fflush(out);
> +  _setmode(_fileno(out), _O_TEXT);
> +#endif
>  }
>
>  /*
>  ** Force the standard output cursor to move to the beginning
>  ** of a line, if it is not there already.
>
> Index: src/utf8.c
> ==
> --- src/utf8.c
> +++ src/utf8.c
> @@ -317,10 +317,11 @@
>wchar_t *zUnicode; /* Unicode version of zUtf8 */
>DWORD dummy;
>Blob blob;
>
>static int istty[2] = { -1, -1 };
> +  assert( toStdErr==0 || toStdErr==1 );
>if( istty[toStdErr]==-1 ){
>  istty[toStdErr] = _isatty(toStdErr + 1) != 0;
>}
>if( !istty[toStdErr] ){
>  /* stdout/stderr is not a console. */
>
>
> ---
>
> NOTE: Only src/print.c contributes to the issue, src/utf8.c patch only
> has an additional assert to keep it consistent with the expected
> values of toStdErr, which I guess is not really required.
>
> I did some limited testing of this on both Windows and Linux boxes
> mostly to confirm that the issue is cleared. Hope this could be fully
> tested and included in the 1.37 release.
>
> And, yes, the issue was spotted from the qtcreator-plugin-fossil, just
> now its Windows version got somewhat more attention.
>
> Thanks.
>
> On Mon, Oct 31, 2016 at 5:24 AM, Richard Hipp  wrote:
>> On 10/31/16, Artur Shepilko  wrote:
>>>  I would've
>>> gladly fixed it myself, but have not mailed yet the Contributor Agreement..
>>> (I have signed it though :)
>>>
>>
>> Please do mail in your CLA.  And maybe also post a patch to this mailing 
>> list.
>>
>> --
>> D. Richard Hipp
>> d...@sqlite.org
>> ___
>> fossil-users mailing list
>> fossil-users@lists.fossil-scm.org
>> http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users
___
fossil-users mailing list
fossil-users@lists.fossil-scm.org
http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users


Re: [fossil-users] fossil diff: extra empty lines in non-console output on Windows

2016-10-31 Thread Artur Shepilko
Ok, just dropped the CLA in the mail.
Sure USPS has an important role in the Fossil project, it probably has
its own username in the repo too :

Below is the patch I applied to clear the described issue (not sure if
the list accepts attachments); as I mentioned earlier, it's
Windows-specific and is very much similar to how it has been patched
for "fossil cat" issue:

patch-Base:http://fossil-scm.org/index.html/info/d13fc6a6b79e71bd
---
Index: src/printf.c
==
--- src/printf.c
+++ src/printf.c
@@ -875,24 +875,33 @@
 /*
 ** Write to standard output or standard error.
 **
 ** On windows, transform the output into the current terminal encoding
 ** if the output is going to the screen.  If output is redirected into
-** a file, no translation occurs.  No translation ever occurs on unix.
+** a file, no translation occurs. Switch output mode to binary to
+** properly process line-endings, make sure to switch the mode back to
+** text when done.
+** No translation ever occurs on unix.
 */
 void fossil_puts(const char *z, int toStdErr){
+  FILE* out = (toStdErr ? stderr : stdout);
   int n = (int)strlen(z);
   if( n==0 ) return;
+  assert( toStdErr==0 || toStdErr==1 );
   if( toStdErr==0 ) stdoutAtBOL = (z[n-1]=='\n');
 #if defined(_WIN32)
   if( fossil_utf8_to_console(z, n, toStdErr) >= 0 ){
 return;
   }
+  fflush(out);
+  _setmode(_fileno(out), _O_BINARY);
 #endif
-  assert( toStdErr==0 || toStdErr==1 );
-  fwrite(z, 1, n, toStdErr ? stderr : stdout);
-  fflush(toStdErr ? stderr : stdout);
+  fwrite(z, 1, n, out);
+#if defined(_WIN32)
+  fflush(out);
+  _setmode(_fileno(out), _O_TEXT);
+#endif
 }

 /*
 ** Force the standard output cursor to move to the beginning
 ** of a line, if it is not there already.

Index: src/utf8.c
==
--- src/utf8.c
+++ src/utf8.c
@@ -317,10 +317,11 @@
   wchar_t *zUnicode; /* Unicode version of zUtf8 */
   DWORD dummy;
   Blob blob;

   static int istty[2] = { -1, -1 };
+  assert( toStdErr==0 || toStdErr==1 );
   if( istty[toStdErr]==-1 ){
 istty[toStdErr] = _isatty(toStdErr + 1) != 0;
   }
   if( !istty[toStdErr] ){
 /* stdout/stderr is not a console. */


---

NOTE: Only src/print.c contributes to the issue, src/utf8.c patch only
has an additional assert to keep it consistent with the expected
values of toStdErr, which I guess is not really required.

I did some limited testing of this on both Windows and Linux boxes
mostly to confirm that the issue is cleared. Hope this could be fully
tested and included in the 1.37 release.

And, yes, the issue was spotted from the qtcreator-plugin-fossil, just
now its Windows version got somewhat more attention.

Thanks.

On Mon, Oct 31, 2016 at 5:24 AM, Richard Hipp  wrote:
> On 10/31/16, Artur Shepilko  wrote:
>>  I would've
>> gladly fixed it myself, but have not mailed yet the Contributor Agreement..
>> (I have signed it though :)
>>
>
> Please do mail in your CLA.  And maybe also post a patch to this mailing list.
>
> --
> D. Richard Hipp
> d...@sqlite.org
> ___
> fossil-users mailing list
> fossil-users@lists.fossil-scm.org
> http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users
___
fossil-users mailing list
fossil-users@lists.fossil-scm.org
http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users


Re: [fossil-users] fossil diff: extra empty lines in non-console output on Windows

2016-10-31 Thread Richard Hipp
On 10/31/16, Adam Jensen  wrote:
>
> Would a GPG signed statement suffice? (It doesn't apply to me; I'm just
> generally curious). How attached to paper and scribbling is the legal
> system?

I am attached to dead-tree documents.  With prior approval, an email
scan can be used instead of sending the original paper via post.
-- 
D. Richard Hipp
d...@sqlite.org
___
fossil-users mailing list
fossil-users@lists.fossil-scm.org
http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users


Re: [fossil-users] fossil diff: extra empty lines in non-console output on Windows

2016-10-31 Thread Adam Jensen
On 10/31/2016 06:24 AM, Richard Hipp wrote:
> On 10/31/16, Artur Shepilko  wrote:
>>  I would've
>> gladly fixed it myself, but have not mailed yet the Contributor Agreement..
>> (I have signed it though :)
>>
> 
> Please do mail in your CLA.  And maybe also post a patch to this mailing list.
> 

Would a GPG signed statement suffice? (It doesn't apply to me; I'm just
generally curious). How attached to paper and scribbling is the legal
system?

___
fossil-users mailing list
fossil-users@lists.fossil-scm.org
http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users


Re: [fossil-users] fossil diff: extra empty lines in non-console output on Windows

2016-10-31 Thread Richard Hipp
On 10/31/16, Artur Shepilko  wrote:
>  I would've
> gladly fixed it myself, but have not mailed yet the Contributor Agreement..
> (I have signed it though :)
>

Please do mail in your CLA.  And maybe also post a patch to this mailing list.

-- 
D. Richard Hipp
d...@sqlite.org
___
fossil-users mailing list
fossil-users@lists.fossil-scm.org
http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users


[fossil-users] fossil diff: extra empty lines in non-console output on Windows

2016-10-30 Thread Artur Shepilko
This issue seems to be similar to what has been found with 'fossil cat',
and subsequently fixed:
http://www.fossil-scm.org/index.html/info/f2fc37c063af9fae

In brief, when the source-code contains CR/LF line-endings, 'fossil diff'
in non-console output (when run non-interactively) on Windows shows extra
empty line for each line of the actual source-code output. Meanwhile all
looks ok when it's executed from the command-line (cmd.exe).

Digging through the fossil guts, it seems to lead to
"printf.c:fossil_puts()"
In this case the output gets generated by fwrite.
printf.c:892
http://fossil-scm.org/index.html/artifact/2de9ca8ea140e35da05eafeb6a447a2fd4069438?txt=1=0

This issue seems to clear by applying the fix similar to how it was done
for the 'fossil cat' case above. Which is switching stdout/stderr mode to
binary prior to fwrite, then restoring it back to text-mode.

Hope this would speed up the fix so it could make it into 1.37. I would've
gladly fixed it myself, but have not mailed yet the Contributor Agreement..
(I have signed it though :)
___
fossil-users mailing list
fossil-users@lists.fossil-scm.org
http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users