Patchwork D6556: cleanup: use named constants for second arg to .seek()

login
register
mail settings
Submitter phabricator
Date June 20, 2019, 6:36 p.m.
Message ID <differential-rev-PHID-DREV-6wlonmfnhbmrbxnzpcqx-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/40627/
State Superseded
Headers show

Comments

phabricator - June 20, 2019, 6:36 p.m.
durin42 created this revision.
Herald added a reviewer: indygreg.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  hgext/fastannotate/revmap.py
  mercurial/revlog.py
  mercurial/tags.py

CHANGE DETAILS




To: durin42, indygreg, #hg-reviewers
Cc: mercurial-devel
Yuya Nishihara - July 10, 2019, 12:09 a.m.
> @@ -16,6 +16,7 @@
>  import collections
>  import contextlib
>  import errno
> +import io
>  import os
>  import struct
>  import zlib
> @@ -2306,7 +2307,7 @@
>  
>          try:
>              with self._datafp() as f:
> -                f.seek(0, 2)
> +                f.seek(0, io.SEEK_END)

Nit: can be `os.SEEK_END` since we don't use the (new) io module on Python 2.
phabricator - July 10, 2019, 12:10 a.m.
yuja added a comment.


  > @@ -16,6 +16,7 @@
  >  import collections
  >  import contextlib
  >  import errno
  > +import io
  >  import os
  >  import struct
  >  import zlib
  > @@ -2306,7 +2307,7 @@
  >
  >   try:
  >       with self._datafp() as f:
  >
  > - f.seek(0, 2)
  >
  > +                f.seek(0, io.SEEK_END)
  
  Nit: can be `os.SEEK_END` since we don't use the (new) io module on Python 2.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D6556/new/

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

To: durin42, indygreg, #hg-reviewers, pulkit
Cc: yuja, mercurial-devel

Patch

diff --git a/mercurial/tags.py b/mercurial/tags.py
--- a/mercurial/tags.py
+++ b/mercurial/tags.py
@@ -563,7 +563,7 @@ 
             " branch name\n") % name)
 
     def writetags(fp, names, munge, prevtags):
-        fp.seek(0, 2)
+        fp.seek(0, io.SEEK_END)
         if prevtags and not prevtags.endswith('\n'):
             fp.write('\n')
         for name in names:
diff --git a/mercurial/revlog.py b/mercurial/revlog.py
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -16,6 +16,7 @@ 
 import collections
 import contextlib
 import errno
+import io
 import os
 import struct
 import zlib
@@ -2306,7 +2307,7 @@ 
 
         try:
             with self._datafp() as f:
-                f.seek(0, 2)
+                f.seek(0, io.SEEK_END)
                 actual = f.tell()
             dd = actual - expected
         except IOError as inst:
@@ -2316,7 +2317,7 @@ 
 
         try:
             f = self.opener(self.indexfile)
-            f.seek(0, 2)
+            f.seek(0, io.SEEK_END)
             actual = f.tell()
             f.close()
             s = self._io.size
diff --git a/hgext/fastannotate/revmap.py b/hgext/fastannotate/revmap.py
--- a/hgext/fastannotate/revmap.py
+++ b/hgext/fastannotate/revmap.py
@@ -8,6 +8,7 @@ 
 from __future__ import absolute_import
 
 import bisect
+import io
 import os
 import struct
 
@@ -246,7 +247,7 @@ 
     hsh = None
     try:
         with open(path, 'rb') as f:
-            f.seek(-_hshlen, 2)
+            f.seek(-_hshlen, io.SEEK_END)
             if f.tell() > len(revmap.HEADER):
                 hsh = f.read(_hshlen)
     except IOError: