Patchwork D2158: py3: use raw string for open() mode

login
register
mail settings
Submitter phabricator
Date Feb. 12, 2018, 2:36 a.m.
Message ID <differential-rev-PHID-DREV-eykxbpp3tvqy7ew4p76g-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/27623/
State New
Headers show

Comments

phabricator - Feb. 12, 2018, 2:36 a.m.
indygreg created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  hgext/largefiles/lfutil.py

CHANGE DETAILS




To: indygreg, #hg-reviewers
Cc: mercurial-devel
phabricator - Feb. 12, 2018, 7:33 a.m.
pulkit added a comment.


  Looks like a better approach will be to revert this change: https://www.mercurial-scm.org/repo/hg/rev/7c54917b31f6. I did that in favor of pycompat.open() and now I think it's better to revert that change.

REPOSITORY
  rHG Mercurial

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

To: indygreg, #hg-reviewers
Cc: pulkit, mercurial-devel
phabricator - Feb. 12, 2018, 10:41 a.m.
yuja added a comment.


  I wanna leave it with no prefix as possible. I think we'll have to bulk-replace
  `''`s to `b''`s at some point so we can leverage static analysis tools, where
  `r''` will be unneeded.

REPOSITORY
  rHG Mercurial

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

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

Patch

diff --git a/hgext/largefiles/lfutil.py b/hgext/largefiles/lfutil.py
--- a/hgext/largefiles/lfutil.py
+++ b/hgext/largefiles/lfutil.py
@@ -57,7 +57,7 @@ 
         util.oslink(src, dest)
     except OSError:
         # if hardlinks fail, fallback on atomic copy
-        with open(src, 'rb') as srcf, util.atomictempfile(dest) as dstf:
+        with open(src, r'rb') as srcf, util.atomictempfile(dest) as dstf:
             for chunk in util.filechunkiter(srcf):
                 dstf.write(chunk)
         os.chmod(dest, os.stat(src).st_mode)
@@ -236,7 +236,7 @@ 
     wvfs.makedirs(wvfs.dirname(wvfs.join(filename)))
     # The write may fail before the file is fully written, but we
     # don't use atomic writes in the working copy.
-    with open(path, 'rb') as srcfd, wvfs(filename, 'wb') as destfd:
+    with open(path, r'rb') as srcfd, wvfs(filename, 'wb') as destfd:
         gothash = copyandhash(
             util.filechunkiter(srcfd), destfd)
     if gothash != hash:
@@ -271,7 +271,7 @@ 
         link(usercachepath(repo.ui, hash), storepath(repo, hash))
     else:
         util.makedirs(os.path.dirname(storepath(repo, hash)))
-        with open(file, 'rb') as srcf:
+        with open(file, r'rb') as srcf:
             with util.atomictempfile(storepath(repo, hash),
                                      createmode=repo.store.createmode) as dstf:
                 for chunk in util.filechunkiter(srcf):
@@ -376,7 +376,7 @@ 
 def hashfile(file):
     if not os.path.exists(file):
         return ''
-    with open(file, 'rb') as fd:
+    with open(file, r'rb') as fd:
         return hexsha1(fd)
 
 def getexecutable(filename):