{"thread":{"id":"33866","subject":"Re: [PATCH] git-remote-hg: set stdout to binary mode on win32","startedAt":"2013-05-19T05:33:46Z","lastAt":"2013-05-19T11:23:56Z","messageCount":3,"participants":["Felipe Contreras","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"217838","messageId":"CAMP44s3H5e3ffoA04pdJx-pfKMGiRBTmjAn6NceP+s6_TYo1GA@mail.gmail.com","threadId":"33866","inReplyTo":"CAFGOX=V0A=2kMpxtNvsjgEtMt=zsm_-zX_DJo0qkV9y1_C4Haw@mail.gmail.com","subject":"Re: [PATCH] git-remote-hg: set stdout to binary mode on win32","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2013-05-19T05:33:46Z","receivedAt":"2013-05-19T05:33:46Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"Hi,\n\nSorry Amit, I assumed this patch made it to the list, but I just\nrealized it didn't; it doesn't allow HTML, and mails and silently\ndropped (I hate that).\n\nSo I'm sending it so the list can see it:\n\nIt seems OK for me, but I would like to try it, and so far I haven't\nmanaged to access Mercurial libraries at all from python scripts in\nWindows. What steps did you follow?\n\nOn Mon, Jan 28, 2013 at 4:13 PM, Amit Bakshi <ambakshi@gmail.com> wrote:\n> git clone hangs on windows (msysgit/cygwin), and\n> file.write would return errno 22 inside of mercurial's\n> windows.winstdout wrapper class. This patch sets\n> stdout's mode to binary, fixing both issues.\n> ---\n>  contrib/remote-helpers/git-remote-hg | 21 +++++++++++++++++++++\n>  1 file changed, 21 insertions(+)\n>\n> diff --git a/contrib/remote-helpers/git-remote-hg\n> b/contrib/remote-helpers/git-remote-hg\n> index 328c2dc..95f4c1f 100755\n> --- a/contrib/remote-helpers/git-remote-hg\n> +++ b/contrib/remote-helpers/git-remote-hg\n> @@ -62,6 +62,24 @@ def get_config(config):\n>      output, _ = process.communicate()\n>      return output\n>\n> +#\n> +# On Windows (msysgit/cygwin) have to set stdout to binary\n> +# mode (_O_BINARY is 32768). Otherwise clone hangs, and pushing\n> +# to remote fails when doing a write to mercurial's wrapper\n> +# windows.winstdout wrapper class.\n> +#\n> +def set_binmode(fd):\n> +    try:\n> +        if sys.platform == \"win32\":\n> +            import msvcrt\n> +            msvcrt.setmode(fd, os.O_BINARY)\n> +        elif sys.platform  == 'cygwin':\n> +            import ctypes\n> +            msvcrt = ctypes.CDLL('msvcrt.dll')\n> +            msvcrt._setmode(fd, 32768) # On Cygwin os.O_BINARY is different\n> +    except OSError:\n> +        pass\n> +\n>  class Marks:\n>\n>      def __init__(self, path):\n> @@ -764,6 +782,9 @@ def main(args):\n>      else:\n>          is_tmp = False\n>\n> +    if sys.platform in ['win32','cygwin']:\n> +        set_binmode(sys.stdout.fileno())\n> +\n>      gitdir = os.environ['GIT_DIR']\n>      dirname = os.path.join(gitdir, 'hg', alias)\n>      branches = {}\n> --\n> 1.8.1\n\n-- \nFelipe Contreras\n"},{"id":"217849","messageId":"7v8v3bz9yd.fsf@alter.siamese.dyndns.org","threadId":"33866","inReplyTo":"CAMP44s3H5e3ffoA04pdJx-pfKMGiRBTmjAn6NceP+s6_TYo1GA@mail.gmail.com","subject":"Re: [PATCH] git-remote-hg: set stdout to binary mode on win32","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-05-19T07:48:42Z","receivedAt":"2013-05-19T07:48:42Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Felipe Contreras <felipe.contreras@gmail.com> writes:\n\n> Sorry Amit, I assumed this patch made it to the list, but I just\n> realized it didn't; it doesn't allow HTML, and mails and silently\n> dropped (I hate that).\n>\n> So I'm sending it so the list can see it:\n>\n> It seems OK for me, but I would like to try it, and so far I haven't\n> managed to access Mercurial libraries at all from python scripts in\n> Windows. What steps did you follow?\n\nThanks for keeping an eye on this part of the system.  It seems that\nhaving an extra -rc cycle turned out to be not so bad an idea.\n\n\n\n> On Mon, Jan 28, 2013 at 4:13 PM, Amit Bakshi <ambakshi@gmail.com> wrote:\n>> git clone hangs on windows (msysgit/cygwin), and\n>> file.write would return errno 22 inside of mercurial's\n>> windows.winstdout wrapper class. This patch sets\n>> stdout's mode to binary, fixing both issues.\n>> ---\n>>  contrib/remote-helpers/git-remote-hg | 21 +++++++++++++++++++++\n>>  1 file changed, 21 insertions(+)\n>>\n>> diff --git a/contrib/remote-helpers/git-remote-hg\n>> b/contrib/remote-helpers/git-remote-hg\n>> index 328c2dc..95f4c1f 100755\n>> --- a/contrib/remote-helpers/git-remote-hg\n>> +++ b/contrib/remote-helpers/git-remote-hg\n>> @@ -62,6 +62,24 @@ def get_config(config):\n>>      output, _ = process.communicate()\n>>      return output\n>>\n>> +#\n>> +# On Windows (msysgit/cygwin) have to set stdout to binary\n>> +# mode (_O_BINARY is 32768). Otherwise clone hangs, and pushing\n>> +# to remote fails when doing a write to mercurial's wrapper\n>> +# windows.winstdout wrapper class.\n>> +#\n>> +def set_binmode(fd):\n>> +    try:\n>> +        if sys.platform == \"win32\":\n>> +            import msvcrt\n>> +            msvcrt.setmode(fd, os.O_BINARY)\n>> +        elif sys.platform  == 'cygwin':\n>> +            import ctypes\n>> +            msvcrt = ctypes.CDLL('msvcrt.dll')\n>> +            msvcrt._setmode(fd, 32768) # On Cygwin os.O_BINARY is different\n>> +    except OSError:\n>> +        pass\n>> +\n>>  class Marks:\n>>\n>>      def __init__(self, path):\n>> @@ -764,6 +782,9 @@ def main(args):\n>>      else:\n>>          is_tmp = False\n>>\n>> +    if sys.platform in ['win32','cygwin']:\n>> +        set_binmode(sys.stdout.fileno())\n>> +\n>>      gitdir = os.environ['GIT_DIR']\n>>      dirname = os.path.join(gitdir, 'hg', alias)\n>>      branches = {}\n>> --\n>> 1.8.1\n"},{"id":"217874","messageId":"CAMP44s2h6O9_H=e9r_pSqdyU5O_NAFD94S8kZNC_eN_CJz-g7g@mail.gmail.com","threadId":"33866","inReplyTo":"CAFGOX=V0A=2kMpxtNvsjgEtMt=zsm_-zX_DJo0qkV9y1_C4Haw@mail.gmail.com","subject":"Re: [PATCH] git-remote-hg: set stdout to binary mode on win32","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2013-05-19T11:23:56Z","receivedAt":"2013-05-19T11:23:56Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"On Mon, Jan 28, 2013 at 4:13 PM, Amit Bakshi <ambakshi@gmail.com> wrote:\n> git clone hangs on windows (msysgit/cygwin), and\n> file.write would return errno 22 inside of mercurial's\n> windows.winstdout wrapper class. This patch sets\n> stdout's mode to binary, fixing both issues.\n> ---\n>  contrib/remote-helpers/git-remote-hg | 21 +++++++++++++++++++++\n>  1 file changed, 21 insertions(+)\n>\n> diff --git a/contrib/remote-helpers/git-remote-hg\n> b/contrib/remote-helpers/git-remote-hg\n> index 328c2dc..95f4c1f 100755\n> --- a/contrib/remote-helpers/git-remote-hg\n> +++ b/contrib/remote-helpers/git-remote-hg\n> @@ -62,6 +62,24 @@ def get_config(config):\n>      output, _ = process.communicate()\n>      return output\n>\n> +#\n> +# On Windows (msysgit/cygwin) have to set stdout to binary\n> +# mode (_O_BINARY is 32768). Otherwise clone hangs, and pushing\n> +# to remote fails when doing a write to mercurial's wrapper\n> +# windows.winstdout wrapper class.\n> +#\n> +def set_binmode(fd):\n> +    try:\n> +        if sys.platform == \"win32\":\n> +            import msvcrt\n> +            msvcrt.setmode(fd, os.O_BINARY)\n> +        elif sys.platform  == 'cygwin':\n> +            import ctypes\n> +            msvcrt = ctypes.CDLL('msvcrt.dll')\n> +            msvcrt._setmode(fd, 32768) # On Cygwin os.O_BINARY is different\n> +    except OSError:\n> +        pass\n\nI tried many things, and it seems it's true that we need to set the\nbinary mode in Windows, but it seemed to work fine cygwin. I saw in\nmany places the workaround for 'win32', but I didn't find the one for\n'cygwin'. Where did you find it? Did you test in cygwin? Is it needed\nthere?\n\nCheers.\n\n-- \nFelipe Contreras\n"}]}