Patchwork httpconnection: make sure to clear progress of httpsendfile at EOF

login
register
mail settings
Submitter Yuya Nishihara
Date March 18, 2017, 7:45 a.m.
Message ID <6d6c4d50c59b87e01936.1489823148@mimosa>
Download mbox | patch
Permalink /patch/19431/
State Accepted
Headers show

Comments

Yuya Nishihara - March 18, 2017, 7:45 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1489820534 -32400
#      Sat Mar 18 16:02:14 2017 +0900
# Node ID 6d6c4d50c59b87e01936095f34720e79b812d05b
# Parent  da7d19324b1e3d2ce0636bf73e76bf8f3d68ed27
httpconnection: make sure to clear progress of httpsendfile at EOF

read() should never raise EOFError. If it did, UnboundLocalError would occur
due to unassigned 'ret' variable.

This issue was originally reported to TortoiseHg:
https://bitbucket.org/tortoisehg/thg/issues/4707/
Augie Fackler - March 19, 2017, 6:18 a.m.
On Sat, Mar 18, 2017 at 04:45:48PM +0900, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1489820534 -32400
> #      Sat Mar 18 16:02:14 2017 +0900
> # Node ID 6d6c4d50c59b87e01936095f34720e79b812d05b
> # Parent  da7d19324b1e3d2ce0636bf73e76bf8f3d68ed27
> httpconnection: make sure to clear progress of httpsendfile at EOF

Queued, thanks

>
> read() should never raise EOFError. If it did, UnboundLocalError would occur
> due to unassigned 'ret' variable.
>
> This issue was originally reported to TortoiseHg:
> https://bitbucket.org/tortoisehg/thg/issues/4707/
>
> diff --git a/mercurial/httpconnection.py b/mercurial/httpconnection.py
> --- a/mercurial/httpconnection.py
> +++ b/mercurial/httpconnection.py
> @@ -44,10 +44,10 @@ class httpsendfile(object):
>          self._total = self.length // 1024 * 2
>
>      def read(self, *args, **kwargs):
> -        try:
> -            ret = self._data.read(*args, **kwargs)
> -        except EOFError:
> +        ret = self._data.read(*args, **kwargs)
> +        if not ret:
>              self.ui.progress(_('sending'), None)
> +            return ret
>          self._pos += len(ret)
>          # We pass double the max for total because we currently have
>          # to send the bundle twice in the case of a server that
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Patch

diff --git a/mercurial/httpconnection.py b/mercurial/httpconnection.py
--- a/mercurial/httpconnection.py
+++ b/mercurial/httpconnection.py
@@ -44,10 +44,10 @@  class httpsendfile(object):
         self._total = self.length // 1024 * 2
 
     def read(self, *args, **kwargs):
-        try:
-            ret = self._data.read(*args, **kwargs)
-        except EOFError:
+        ret = self._data.read(*args, **kwargs)
+        if not ret:
             self.ui.progress(_('sending'), None)
+            return ret
         self._pos += len(ret)
         # We pass double the max for total because we currently have
         # to send the bundle twice in the case of a server that