changeset 35069:241d9caca11e

bundle2: use os.SEEK_* constants Constants make code easier to read than magic numbers. I also threw in an explicit argument in a caller to further increase code comprehension. Differential Revision: https://phab.mercurial-scm.org/D1370
author Gregory Szorc <gregory.szorc@gmail.com>
date Sat, 11 Nov 2017 16:48:40 -0800
parents b0262b25ab48
children 32d079f37207
files mercurial/bundle2.py
diffstat 1 files changed, 11 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/bundle2.py	Mon Oct 30 20:35:30 2017 -0700
+++ b/mercurial/bundle2.py	Sat Nov 11 16:48:40 2017 -0800
@@ -148,6 +148,7 @@
 from __future__ import absolute_import, division
 
 import errno
+import os
 import re
 import string
 import struct
@@ -362,7 +363,7 @@
                 self.count = count
                 self.current = p
                 yield p
-                p.seek(0, 2)
+                p.seek(0, os.SEEK_END)
                 self.current = None
         self.iterator = func()
         return self.iterator
@@ -384,11 +385,11 @@
             try:
                 if self.current:
                     # consume the part content to not corrupt the stream.
-                    self.current.seek(0, 2)
+                    self.current.seek(0, os.SEEK_END)
 
                 for part in self.iterator:
                     # consume the bundle content
-                    part.seek(0, 2)
+                    part.seek(0, os.SEEK_END)
             except Exception:
                 seekerror = True
 
@@ -858,8 +859,8 @@
             # Seek to the end of the part to force it's consumption so the next
             # part can be read. But then seek back to the beginning so the
             # code consuming this generator has a part that starts at 0.
-            part.seek(0, 2)
-            part.seek(0)
+            part.seek(0, os.SEEK_END)
+            part.seek(0, os.SEEK_SET)
             headerblock = self._readpartheader()
         indebug(self.ui, 'end of bundle2 stream')
 
@@ -1164,7 +1165,7 @@
             raise
         finally:
             if not hardabort:
-                part.seek(0, 2)
+                part.seek(0, os.SEEK_END)
         self.ui.debug('bundle2-input-stream-interrupt:'
                       ' closing out of band context\n')
 
@@ -1330,12 +1331,12 @@
     def tell(self):
         return self._pos
 
-    def seek(self, offset, whence=0):
-        if whence == 0:
+    def seek(self, offset, whence=os.SEEK_SET):
+        if whence == os.SEEK_SET:
             newpos = offset
-        elif whence == 1:
+        elif whence == os.SEEK_CUR:
             newpos = self._pos + offset
-        elif whence == 2:
+        elif whence == os.SEEK_END:
             if not self.consumed:
                 self.read()
             newpos = self._chunkindex[-1][0] - offset