[PATCH 1 of 2] global: mass rewrite to use modern octal syntax

Gregory Szorc gregory.szorc at gmail.com
Wed Jun 24 00:41:03 CDT 2015


# HG changeset patch
# User Gregory Szorc <gregory.szorc at gmail.com>
# Date 1435123833 25200
#      Tue Jun 23 22:30:33 2015 -0700
# Node ID 7f0d2282983cf202b8a1d7667ff15a6e16ce1307
# Parent  e81b2ef5ba3e3d3f1bce3da29515976a52645ac6
global: mass rewrite to use modern octal syntax

Python 2.6 introduced a new octal syntax: "0oXXX", replacing "0XXX". The
old syntax is not recognized in Python 3 and will result in a parse
error.

Mass rewrite all instances of the old octal syntax to the new syntax.

This patch was generated by `2to3 -f numliterals -w -n .` and the diff
was selectively recorded to exclude changes to "<N>l" syntax conversion,
which will be handled separately.

diff --git a/hgext/convert/darcs.py b/hgext/convert/darcs.py
--- a/hgext/convert/darcs.py
+++ b/hgext/convert/darcs.py
@@ -200,9 +200,9 @@ class darcs_source(converter_source, com
         except IOError as inst:
             if inst.errno == errno.ENOENT:
                 return None, None
             raise
-        mode = (mode & 0111) and 'x' or ''
+        mode = (mode & 0o111) and 'x' or ''
         return data, mode
 
     def gettags(self):
         return self.tags
diff --git a/hgext/convert/gnuarch.py b/hgext/convert/gnuarch.py
--- a/hgext/convert/gnuarch.py
+++ b/hgext/convert/gnuarch.py
@@ -214,9 +214,9 @@ class gnuarch_source(converter_source, c
             else:
                 mode = ''
         else:
             data = open(os.path.join(self.tmppath, name), 'rb').read()
-            mode = (mode & 0111) and 'x' or ''
+            mode = (mode & 0o111) and 'x' or ''
         return data, mode
 
     def _exclude(self, name):
         exclude = ['{arch}', '.arch-ids', '.arch-inventory']
diff --git a/hgext/largefiles/overrides.py b/hgext/largefiles/overrides.py
--- a/hgext/largefiles/overrides.py
+++ b/hgext/largefiles/overrides.py
@@ -907,9 +907,9 @@ def overridearchive(orig, repo, dest, no
 
     archiver = archival.archivers[kind](dest, mtime or ctx.date()[0])
 
     if repo.ui.configbool("ui", "archivemeta", True):
-        write('.hg_archival.txt', 0644, False,
+        write('.hg_archival.txt', 0o644, False,
               lambda: archival.buildmetadata(ctx))
 
     for f in ctx:
         ff = ctx.flags(f)
@@ -936,9 +936,9 @@ def overridearchive(orig, repo, dest, no
                     if fd:
                         fd.close()
 
             getdata = getdatafn
-        write(f, 'x' in ff and 0755 or 0644, 'l' in ff, getdata)
+        write(f, 'x' in ff and 0o755 or 0o644, 'l' in ff, getdata)
 
     if subrepos:
         for subpath in sorted(ctx.substate):
             sub = ctx.workingsub(subpath)
@@ -990,9 +990,9 @@ def hgsubrepoarchive(orig, repo, archive
                         fd.close()
 
             getdata = getdatafn
 
-        write(f, 'x' in ff and 0755 or 0644, 'l' in ff, getdata)
+        write(f, 'x' in ff and 0o755 or 0o644, 'l' in ff, getdata)
 
     for subpath in sorted(ctx.substate):
         sub = ctx.workingsub(subpath)
         submatch = match_.narrowmatcher(subpath, match)
diff --git a/mercurial/archival.py b/mercurial/archival.py
--- a/mercurial/archival.py
+++ b/mercurial/archival.py
@@ -156,9 +156,9 @@ class tarit(object):
         i.mtime = self.mtime
         i.size = len(data)
         if islink:
             i.type = tarfile.SYMTYPE
-            i.mode = 0777
+            i.mode = 0o777
             i.linkname = data
             data = None
             i.size = 0
         else:
@@ -219,9 +219,9 @@ class zipit(object):
         # set to unix (id 3).
         i.create_system = 3
         ftype = _UNX_IFREG
         if islink:
-            mode = 0777
+            mode = 0o777
             ftype = _UNX_IFLNK
         i.external_attr = (mode | ftype) << 16L
         # add "extended-timestamp" extra block, because zip archives
         # without this will be extracted with unexpected timestamp,
@@ -301,9 +301,9 @@ def archive(repo, dest, node, kind, deco
 
     if repo.ui.configbool("ui", "archivemeta", True):
         name = '.hg_archival.txt'
         if not matchfn or matchfn(name):
-            write(name, 0644, False, lambda: buildmetadata(ctx))
+            write(name, 0o644, False, lambda: buildmetadata(ctx))
 
     if matchfn:
         files = [f for f in ctx.manifest().keys() if matchfn(f)]
     else:
@@ -313,9 +313,9 @@ def archive(repo, dest, node, kind, deco
         files.sort()
         repo.ui.progress(_('archiving'), 0, unit=_('files'), total=total)
         for i, f in enumerate(files):
             ff = ctx.flags(f)
-            write(f, 'x' in ff and 0755 or 0644, 'l' in ff, ctx[f].data)
+            write(f, 'x' in ff and 0o755 or 0o644, 'l' in ff, ctx[f].data)
             repo.ui.progress(_('archiving'), i + 1, item=f,
                              unit=_('files'), total=total)
         repo.ui.progress(_('archiving'), None)
 
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -2995,12 +2995,12 @@ def debugstate(ui, repo, nodates=None, d
             timestr = 'set                 '
         else:
             timestr = time.strftime("%Y-%m-%d %H:%M:%S ",
                                     time.localtime(ent[3]))
-        if ent[1] & 020000:
+        if ent[1] & 0o20000:
             mode = 'lnk'
         else:
-            mode = '%3o' % (ent[1] & 0777 & ~util.umask)
+            mode = '%3o' % (ent[1] & 0o777 & ~util.umask)
         ui.write("%c %s %10d %s%s\n" % (ent[0], mode, ent[2], timestr, file_))
     for f in repo.dirstate.copies():
         ui.write(_("copy: %s -> %s\n") % (repo.dirstate.copied(f), f))
 
diff --git a/mercurial/dirstate.py b/mercurial/dirstate.py
--- a/mercurial/dirstate.py
+++ b/mercurial/dirstate.py
@@ -593,11 +593,11 @@ class dirstate(object):
             if f not in changedfiles:
                 self._map[f] = oldmap[f]
             else:
                 if 'x' in allfiles.flags(f):
-                    self._map[f] = dirstatetuple('n', 0777, -1, 0)
+                    self._map[f] = dirstatetuple('n', 0o777, -1, 0)
                 else:
-                    self._map[f] = dirstatetuple('n', 0666, -1, 0)
+                    self._map[f] = dirstatetuple('n', 0o666, -1, 0)
         self._pl = (parent, nullid)
         self._dirty = True
 
     def write(self):
@@ -962,9 +962,9 @@ class dirstate(object):
             elif state == 'n':
                 mtime = int(st.st_mtime)
                 if (size >= 0 and
                     ((size != st.st_size and size != st.st_size & _rangemask)
-                     or ((mode ^ st.st_mode) & 0100 and checkexec))
+                     or ((mode ^ st.st_mode) & 0o100 and checkexec))
                     or size == -2 # other parent
                     or fn in copymap):
                     madd(fn)
                 elif time != mtime and time != mtime & _rangemask:
diff --git a/mercurial/patch.py b/mercurial/patch.py
--- a/mercurial/patch.py
+++ b/mercurial/patch.py
@@ -291,10 +291,10 @@ class patchmeta(object):
         self.op = 'MODIFY'
         self.binary = False
 
     def setmode(self, mode):
-        islink = mode & 020000
-        isexec = mode & 0100
+        islink = mode & 0o20000
+        isexec = mode & 0o100
         self.mode = (islink, isexec)
 
     def copy(self):
         other = patchmeta(self.path)
@@ -433,9 +433,9 @@ class fsbackend(abstractbackend):
             return (self.opener.readlink(fname), (True, False))
 
         isexec = False
         try:
-            isexec = self.opener.lstat(fname).st_mode & 0100 != 0
+            isexec = self.opener.lstat(fname).st_mode & 0o100 != 0
         except OSError as e:
             if e.errno != errno.ENOENT:
                 raise
         try:
diff --git a/mercurial/posix.py b/mercurial/posix.py
--- a/mercurial/posix.py
+++ b/mercurial/posix.py
@@ -70,9 +70,9 @@ def sshargs(sshcmd, host, user, port):
     return port and ("%s -p %s" % (args, port)) or args
 
 def isexec(f):
     """check whether a file is executable"""
-    return (os.lstat(f).st_mode & 0100 != 0)
+    return (os.lstat(f).st_mode & 0o100 != 0)
 
 def setflags(f, l, x):
     s = os.lstat(f).st_mode
     if l:
@@ -97,32 +97,32 @@ def setflags(f, l, x):
         os.unlink(f)
         fp = open(f, "w")
         fp.write(data)
         fp.close()
-        s = 0666 & ~umask # avoid restatting for chmod
+        s = 0o666 & ~umask # avoid restatting for chmod
 
-    sx = s & 0100
+    sx = s & 0o100
     if x and not sx:
         # Turn on +x for every +r bit when making a file executable
         # and obey umask.
-        os.chmod(f, s | (s & 0444) >> 2 & ~umask)
+        os.chmod(f, s | (s & 0o444) >> 2 & ~umask)
     elif not x and sx:
         # Turn off all +x bits
-        os.chmod(f, s & 0666)
+        os.chmod(f, s & 0o666)
 
 def copymode(src, dst, mode=None):
     '''Copy the file mode from the file at path src to dst.
     If src doesn't exist, we're using mode instead. If mode is None, we're
     using umask.'''
     try:
-        st_mode = os.lstat(src).st_mode & 0777
+        st_mode = os.lstat(src).st_mode & 0o777
     except OSError as inst:
         if inst.errno != errno.ENOENT:
             raise
         st_mode = mode
         if st_mode is None:
             st_mode = ~umask
-        st_mode &= 0666
+        st_mode &= 0o666
     os.chmod(dst, st_mode)
 
 def checkexec(path):
     """
@@ -139,12 +139,12 @@ def checkexec(path):
         EXECFLAGS = stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH
         fh, fn = tempfile.mkstemp(dir=path, prefix='hg-checkexec-')
         try:
             os.close(fh)
-            m = os.stat(fn).st_mode & 0777
+            m = os.stat(fn).st_mode & 0o777
             new_file_has_exec = m & EXECFLAGS
             os.chmod(fn, m ^ EXECFLAGS)
-            exec_flags_cannot_flip = ((os.stat(fn).st_mode & 0777) == m)
+            exec_flags_cannot_flip = ((os.stat(fn).st_mode & 0o777) == m)
         finally:
             os.unlink(fn)
     except (IOError, OSError):
         # we don't care, the user probably won't be able to commit anyway
@@ -592,9 +592,9 @@ def statislink(st):
     return st and stat.S_ISLNK(st.st_mode)
 
 def statisexec(st):
     '''check whether a stat result is an executable file'''
-    return st and (st.st_mode & 0100 != 0)
+    return st and (st.st_mode & 0o100 != 0)
 
 def poll(fds):
     """block until something happens on any file descriptor
 
diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -449,9 +449,9 @@ class vfs(abstractvfs):
 
     def _fixfilemode(self, name):
         if self.createmode is None or not self._chmod:
             return
-        os.chmod(name, self.createmode & 0666)
+        os.chmod(name, self.createmode & 0o666)
 
     def __call__(self, path, mode="r", text=False, atomictemp=False,
                  notindexed=False):
         '''Open ``path`` file, which is relative to vfs root.
diff --git a/mercurial/store.py b/mercurial/store.py
--- a/mercurial/store.py
+++ b/mercurial/store.py
@@ -273,9 +273,9 @@ def _calcmode(vfs):
     try:
         # files in .hg/ will be created using this mode
         mode = vfs.stat().st_mode
             # avoid some useless chmods
-        if (0777 & ~util.umask) == (0777 & mode):
+        if (0o777 & ~util.umask) == (0o777 & mode):
             mode = None
     except OSError:
         mode = None
     return mode
diff --git a/mercurial/subrepo.py b/mercurial/subrepo.py
--- a/mercurial/subrepo.py
+++ b/mercurial/subrepo.py
@@ -539,9 +539,9 @@ class abstractsubrepo(object):
         self.ui.progress(_('archiving (%s)') % relpath, 0,
                          unit=_('files'), total=total)
         for i, name in enumerate(files):
             flags = self.fileflags(name)
-            mode = 'x' in flags and 0755 or 0644
+            mode = 'x' in flags and 0o755 or 0o644
             symlink = 'l' in flags
             archiver.addfile(prefix + self._path + '/' + name,
                              mode, symlink, self.filedata(name))
             self.ui.progress(_('archiving (%s)') % relpath, i + 1,
diff --git a/mercurial/transaction.py b/mercurial/transaction.py
--- a/mercurial/transaction.py
+++ b/mercurial/transaction.py
@@ -129,10 +129,10 @@ class transaction(object):
         self._backupsfile = opener.open(self._backupjournal, 'w')
         self._backupsfile.write('%d\n' % version)
 
         if createmode is not None:
-            opener.chmod(self.journal, createmode & 0666)
-            opener.chmod(self._backupjournal, createmode & 0666)
+            opener.chmod(self.journal, createmode & 0o666)
+            opener.chmod(self._backupjournal, createmode & 0o666)
 
         # hold file generations to be performed on commit
         self._filegenerators = {}
         # hold callback to write pending data for hooks
diff --git a/mercurial/windows.py b/mercurial/windows.py
--- a/mercurial/windows.py
+++ b/mercurial/windows.py
@@ -24,9 +24,9 @@ split = os.path.split
 termwidth = win32.termwidth
 testpid = win32.testpid
 unlink = win32.unlink
 
-umask = 0022
+umask = 0o022
 
 def posixfile(name, mode='r', buffering=-1):
     '''Open a file with even more POSIX-like semantics'''
     try:
diff --git a/tests/hghave.py b/tests/hghave.py
--- a/tests/hghave.py
+++ b/tests/hghave.py
@@ -87,12 +87,12 @@ def has_executablebit():
         EXECFLAGS = stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH
         fh, fn = tempfile.mkstemp(dir='.', prefix=tempprefix)
         try:
             os.close(fh)
-            m = os.stat(fn).st_mode & 0777
+            m = os.stat(fn).st_mode & 0o777
             new_file_has_exec = m & EXECFLAGS
             os.chmod(fn, m ^ EXECFLAGS)
-            exec_flags_cannot_flip = ((os.stat(fn).st_mode & 0777) == m)
+            exec_flags_cannot_flip = ((os.stat(fn).st_mode & 0o777) == m)
         finally:
             os.unlink(fn)
     except (IOError, OSError):
         # we don't care, the user probably won't be able to commit anyway
@@ -245,15 +245,15 @@ def has_gpg():
 def has_unix_permissions():
     d = tempfile.mkdtemp(dir='.', prefix=tempprefix)
     try:
         fname = os.path.join(d, 'foo')
-        for umask in (077, 007, 022):
+        for umask in (0o77, 0o07, 0o22):
             os.umask(umask)
             f = open(fname, 'w')
             f.close()
             mode = os.stat(fname).st_mode
             os.unlink(fname)
-            if mode & 0777 != ~umask & 0666:
+            if mode & 0o777 != ~umask & 0o666:
                 return False
         return True
     finally:
         os.rmdir(d)


More information about the Mercurial-devel mailing list