[PATCH 1 of 5 modernize-streamclone] bundle2: implement unbundlepart.readline()

Gregory Szorc gregory.szorc at gmail.com
Sun Oct 4 20:11:27 UTC 2015


# HG changeset patch
# User Gregory Szorc <gregory.szorc at gmail.com>
# Date 1443823506 25200
#      Fri Oct 02 15:05:06 2015 -0700
# Node ID 28a2967528155aac6fbabf642061aa3ba1360be0
# Parent  22f27f7f4ef3933ee604be645ae79f84ca2f5b99
bundle2: implement unbundlepart.readline()

This is used by the stream clone consuming code. readline() is also part
of the standard file object API, so someone else is likely going to want
this sooner or later.

diff --git a/mercurial/bundle2.py b/mercurial/bundle2.py
--- a/mercurial/bundle2.py
+++ b/mercurial/bundle2.py
@@ -1130,8 +1130,21 @@ class unbundlepart(unpackermixin):
                               % self._pos)
             self.consumed = True
         return data
 
+    def readline(self):
+        chars = []
+        while True:
+            c = self.read(1)
+            # EOF.
+            if not len(c):
+                break
+            chars.append(c)
+            if c == '\n':
+                break
+
+        return ''.join(chars)
+
     def tell(self):
         return self._pos
 
     def seek(self, offset, whence=0):


More information about the Mercurial-devel mailing list