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 <[email protected]> wrote:
> On 10/31/16, Artur Shepilko <[email protected]> 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
> [email protected]
> _______________________________________________
> fossil-users mailing list
> [email protected]
> http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users
_______________________________________________
fossil-users mailing list
[email protected]
http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users

Reply via email to