Patchwork D2581: sshpeer: don't read(0)

login
register
mail settings
Submitter phabricator
Date March 3, 2018, 2:52 p.m.
Message ID <differential-rev-PHID-DREV-7xqhumgpgz2u7a2kman4-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/28779/
State Superseded
Headers show

Comments

phabricator - March 3, 2018, 2:52 p.m.
indygreg created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  read(0) is essentially a no-op. Let's avoid the function call, overhead,
  and extra test output by not performing it.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D2581

AFFECTED FILES
  mercurial/sshpeer.py
  tests/test-ssh-proto-unbundle.t

CHANGE DETAILS




To: indygreg, #hg-reviewers
Cc: mercurial-devel

Patch

diff --git a/tests/test-ssh-proto-unbundle.t b/tests/test-ssh-proto-unbundle.t
--- a/tests/test-ssh-proto-unbundle.t
+++ b/tests/test-ssh-proto-unbundle.t
@@ -88,7 +88,6 @@ 
   i> flush() -> None
   o> readline() -> 2:
   o>     0\n
-  o> read(0) -> 0: 
   o> readline() -> 2:
   o>     1\n
   o> read(1) -> 1: 0
@@ -139,7 +138,6 @@ 
   i> flush() -> None
   o> readline() -> 2:
   o>     0\n
-  o> read(0) -> 0: 
   o> readline() -> 2:
   o>     1\n
   o> read(1) -> 1: 0
@@ -257,7 +255,6 @@ 
   i> flush() -> None
   o> readline() -> 2:
   o>     0\n
-  o> read(0) -> 0: 
   o> readline() -> 2:
   o>     1\n
   o> read(1) -> 1: 0
@@ -314,7 +311,6 @@ 
   i> flush() -> None
   o> readline() -> 2:
   o>     0\n
-  o> read(0) -> 0: 
   o> readline() -> 2:
   o>     1\n
   o> read(1) -> 1: 0
@@ -385,7 +381,6 @@ 
   i> flush() -> None
   o> readline() -> 2:
   o>     0\n
-  o> read(0) -> 0: 
   o> readline() -> 2:
   o>     1\n
   o> read(1) -> 1: 0
@@ -443,7 +438,6 @@ 
   i> flush() -> None
   o> readline() -> 2:
   o>     0\n
-  o> read(0) -> 0: 
   o> readline() -> 2:
   o>     1\n
   o> read(1) -> 1: 0
@@ -515,7 +509,6 @@ 
   i> flush() -> None
   o> readline() -> 2:
   o>     0\n
-  o> read(0) -> 0: 
   o> readline() -> 2:
   o>     1\n
   o> read(1) -> 1: 0
@@ -572,7 +565,6 @@ 
   i> flush() -> None
   o> readline() -> 2:
   o>     0\n
-  o> read(0) -> 0: 
   o> readline() -> 2:
   o>     1\n
   o> read(1) -> 1: 0
@@ -643,7 +635,6 @@ 
   i> flush() -> None
   o> readline() -> 2:
   o>     0\n
-  o> read(0) -> 0: 
   o> readline() -> 2:
   o>     1\n
   o> read(1) -> 1: 0
@@ -701,7 +692,6 @@ 
   i> flush() -> None
   o> readline() -> 2:
   o>     0\n
-  o> read(0) -> 0: 
   o> readline() -> 2:
   o>     1\n
   o> read(1) -> 1: 0
@@ -773,7 +763,6 @@ 
   i> flush() -> None
   o> readline() -> 2:
   o>     0\n
-  o> read(0) -> 0: 
   o> readline() -> 2:
   o>     1\n
   o> read(1) -> 1: 0
@@ -833,7 +822,6 @@ 
   i> flush() -> None
   o> readline() -> 2:
   o>     0\n
-  o> read(0) -> 0: 
   o> readline() -> 2:
   o>     1\n
   o> read(1) -> 1: 0
@@ -907,7 +895,6 @@ 
   i> flush() -> None
   o> readline() -> 2:
   o>     0\n
-  o> read(0) -> 0: 
   o> readline() -> 2:
   o>     1\n
   o> read(1) -> 1: 0
@@ -964,7 +951,6 @@ 
   i> flush() -> None
   o> readline() -> 2:
   o>     0\n
-  o> read(0) -> 0: 
   o> readline() -> 2:
   o>     1\n
   o> read(1) -> 1: 0
@@ -1035,7 +1021,6 @@ 
   i> flush() -> None
   o> readline() -> 2:
   o>     0\n
-  o> read(0) -> 0: 
   o> readline() -> 2:
   o>     1\n
   o> read(1) -> 1: 0
@@ -1095,7 +1080,6 @@ 
   i> flush() -> None
   o> readline() -> 2:
   o>     0\n
-  o> read(0) -> 0: 
   o> readline() -> 2:
   o>     1\n
   o> read(1) -> 1: 0
@@ -1169,7 +1153,6 @@ 
   i> flush() -> None
   o> readline() -> 2:
   o>     0\n
-  o> read(0) -> 0: 
   o> readline() -> 2:
   o>     1\n
   o> read(1) -> 1: 0
@@ -1229,7 +1212,6 @@ 
   i> flush() -> None
   o> readline() -> 2:
   o>     0\n
-  o> read(0) -> 0: 
   o> readline() -> 2:
   o>     1\n
   o> read(1) -> 1: 0
@@ -1309,7 +1291,6 @@ 
   i> flush() -> None
   o> readline() -> 2:
   o>     0\n
-  o> read(0) -> 0: 
   o> readline() -> 2:
   o>     1\n
   o> read(1) -> 1: 0
@@ -1367,7 +1348,6 @@ 
   i> flush() -> None
   o> readline() -> 2:
   o>     0\n
-  o> read(0) -> 0: 
   o> readline() -> 2:
   o>     1\n
   o> read(1) -> 1: 0
@@ -1440,7 +1420,6 @@ 
   i> flush() -> None
   o> readline() -> 2:
   o>     0\n
-  o> read(0) -> 0: 
   o> readline() -> 2:
   o>     1\n
   o> read(1) -> 1: 0
@@ -1498,7 +1477,6 @@ 
   i> flush() -> None
   o> readline() -> 2:
   o>     0\n
-  o> read(0) -> 0: 
   o> readline() -> 2:
   o>     1\n
   o> read(1) -> 1: 0
@@ -1573,7 +1551,6 @@ 
   i> flush() -> None
   o> readline() -> 2:
   o>     0\n
-  o> read(0) -> 0: 
   o> readline() -> 2:
   o>     1\n
   o> read(1) -> 1: 0
@@ -1633,7 +1610,6 @@ 
   i> flush() -> None
   o> readline() -> 2:
   o>     0\n
-  o> read(0) -> 0: 
   o> readline() -> 2:
   o>     1\n
   o> read(1) -> 1: 0
@@ -1716,7 +1692,6 @@ 
   i> flush() -> None
   o> readline() -> 2:
   o>     0\n
-  o> read(0) -> 0: 
   o> readline() -> 2:
   o>     1\n
   o> read(1) -> 1: 0
@@ -1780,7 +1755,6 @@ 
   i> flush() -> None
   o> readline() -> 2:
   o>     0\n
-  o> read(0) -> 0: 
   o> readline() -> 2:
   o>     1\n
   o> read(1) -> 1: 0
@@ -1858,7 +1832,6 @@ 
   i> flush() -> None
   o> readline() -> 2:
   o>     0\n
-  o> read(0) -> 0: 
   o> readline() -> 2:
   o>     1\n
   o> read(1) -> 1: 1
@@ -1911,7 +1884,6 @@ 
   i> flush() -> None
   o> readline() -> 2:
   o>     0\n
-  o> read(0) -> 0: 
   o> readline() -> 2:
   o>     1\n
   o> read(1) -> 1: 1
@@ -1990,7 +1962,6 @@ 
   i> flush() -> None
   o> readline() -> 2:
   o>     0\n
-  o> read(0) -> 0: 
   o> readline() -> 2:
   o>     1\n
   o> read(1) -> 1: 1
@@ -2047,7 +2018,6 @@ 
   i> flush() -> None
   o> readline() -> 2:
   o>     0\n
-  o> read(0) -> 0: 
   o> readline() -> 2:
   o>     1\n
   o> read(1) -> 1: 1
diff --git a/mercurial/sshpeer.py b/mercurial/sshpeer.py
--- a/mercurial/sshpeer.py
+++ b/mercurial/sshpeer.py
@@ -523,7 +523,11 @@ 
             self._abort(error.ResponseError(_("unexpected response:"), l))
 
     def _readframed(self):
-        return self._pipei.read(self._getamount())
+        size = self._getamount()
+        if not size:
+            return b''
+
+        return self._pipei.read(size)
 
     def _writeframed(self, data, flush=False):
         self._pipeo.write("%d\n" % len(data))