global: mass rewrite to use modern octal syntax
authorGregory Szorc <gregory.szorc@gmail.com>
Tue, 23 Jun 2015 22:30:33 -0700
changeset 26083 e930367479020f3111969852d2082e3342fa32bd
parent 26082 dcc56e10c23b8d91b27e43b172706f6ec2837879
child 26084 d60678a567a9be275a7bb90c4031f41d92157050
push id16
push usergszorc@mozilla.com
push dateSat, 08 Aug 2015 03:14:19 +0000
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.
hgext/convert/darcs.py
hgext/convert/gnuarch.py
hgext/largefiles/overrides.py
mercurial/archival.py
mercurial/commands.py
mercurial/dirstate.py
mercurial/patch.py
mercurial/posix.py
mercurial/scmutil.py
mercurial/store.py
mercurial/subrepo.py
mercurial/transaction.py
mercurial/windows.py
tests/hghave.py
--- a/hgext/convert/darcs.py
+++ b/hgext/convert/darcs.py
@@ -196,13 +196,13 @@ class darcs_source(converter_source, com
         path = os.path.join(self.tmppath, name)
         try:
             data = util.readfile(path)
             mode = os.lstat(path).st_mode
         except IOError, 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
--- a/hgext/convert/gnuarch.py
+++ b/hgext/convert/gnuarch.py
@@ -210,17 +210,17 @@ class gnuarch_source(converter_source, c
         if stat.S_ISLNK(mode):
             data = os.readlink(os.path.join(self.tmppath, name))
             if mode:
                 mode = 'l'
             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']
         for exc in exclude:
             if name.find(exc) != -1:
                 return True
         return False
--- a/hgext/largefiles/overrides.py
+++ b/hgext/largefiles/overrides.py
@@ -903,17 +903,17 @@ def overridearchive(orig, repo, dest, no
         data = getdata()
         if decode:
             data = repo.wwritedata(name, data)
         archiver.addfile(prefix + name, mode, islink, data)
 
     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)
         getdata = ctx[f].data
         if lfutil.isstandin(f):
             if node is not None:
                 path = lfutil.findfile(repo, getdata().strip())
@@ -932,17 +932,17 @@ def overridearchive(orig, repo, dest, no
                 try:
                     fd = open(path, 'rb')
                     return fd.read()
                 finally:
                     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)
             submatch = match_.narrowmatcher(subpath, matchfn)
             sub.archive(archiver, prefix, submatch)
 
     archiver.done()
@@ -986,17 +986,17 @@ def hgsubrepoarchive(orig, repo, archive
                     fd = open(os.path.join(prefix, path), 'rb')
                     return fd.read()
                 finally:
                     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)
 
     for subpath in sorted(ctx.substate):
         sub = ctx.workingsub(subpath)
         submatch = match_.narrowmatcher(subpath, match)
         sub.archive(archiver, prefix + repo._path + '/', submatch)
 
 # If a largefile is modified, the change is not reflected in its
 # standin until a commit. cmdutil.bailifchanged() raises an exception
--- a/mercurial/archival.py
+++ b/mercurial/archival.py
@@ -152,17 +152,17 @@ class tarit(object):
             self.z = taropen(name='', mode='w|', fileobj=dest)
 
     def addfile(self, name, mode, islink, data):
         i = tarfile.TarInfo(name)
         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:
             i.mode = mode
             data = cStringIO.StringIO(data)
         self.z.addfile(i, data)
 
@@ -215,17 +215,17 @@ class zipit(object):
     def addfile(self, name, mode, islink, data):
         i = zipfile.ZipInfo(name, self.date_time)
         i.compress_type = self.z.compression
         # unzip will not honor unix file modes unless file creator is
         # 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,
         # if TZ is not configured as GMT
         i.extra += struct.pack('<hhBl',
                                0x5455,     # block type: "extended-timestamp"
                                1 + 4,      # size of this block
@@ -297,29 +297,29 @@ def archive(repo, dest, node, kind, deco
         raise util.Abort(_("unknown archive type '%s'") % kind)
 
     ctx = repo[node]
     archiver = archivers[kind](dest, mtime or ctx.date()[0])
 
     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:
         files = ctx.manifest().keys()
     total = len(files)
     if total:
         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)
 
     if subrepos:
         for subpath in sorted(ctx.substate):
             sub = ctx.workingsub(subpath)
             submatch = matchmod.narrowmatcher(subpath, matchfn)
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -2996,20 +2996,20 @@ def debugstate(ui, repo, nodates=None, d
     for file_, ent in sorted(repo.dirstate._map.iteritems(), key=keyfunc):
         if ent[3] == -1:
             timestr = 'unset               '
         elif nodates:
             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))
 
 @command('debugsub',
     [('r', 'rev', '',
      _('revision to check'), _('REV'))],
     _('[-r REV] [REV]'))
--- a/mercurial/dirstate.py
+++ b/mercurial/dirstate.py
@@ -589,19 +589,19 @@ class dirstate(object):
             changedfiles = allfiles
         oldmap = self._map
         self.clear()
         for f in allfiles:
             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):
         if not self._dirty:
             return
 
         # enough 'delaywrite' prevents 'pack_dirstate' from dropping
@@ -958,17 +958,17 @@ class dirstate(object):
             time = t[3]
 
             if not st and state in "nma":
                 dadd(fn)
             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:
                     ladd(fn)
                 elif mtime == lastnormaltime:
                     # fn may have just been marked as normal and it may have
                     # changed in the same second without changing its size.
--- a/mercurial/patch.py
+++ b/mercurial/patch.py
@@ -283,18 +283,18 @@ class patchmeta(object):
     def __init__(self, path):
         self.path = path
         self.oldpath = None
         self.mode = None
         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)
         other.oldpath = self.oldpath
         other.mode = self.mode
         other.op = self.op
         other.binary = self.binary
@@ -425,17 +425,17 @@ class fsbackend(abstractbackend):
         return os.path.join(self.opener.base, f)
 
     def getfile(self, fname):
         if self.opener.islink(fname):
             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, e:
             if e.errno != errno.ENOENT:
                 raise
         try:
             return (self.opener.read(fname), (False, isexec))
         except IOError, e:
             if e.errno != errno.ENOENT:
                 raise
--- a/mercurial/posix.py
+++ b/mercurial/posix.py
@@ -66,17 +66,17 @@ def parsepatchoutput(output_line):
 
 def sshargs(sshcmd, host, user, port):
     '''Build argument list for ssh'''
     args = user and ("%s@%s" % (user, host)) or host
     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:
         if not stat.S_ISLNK(s):
             # switch file to link
             fp = open(f)
             data = fp.read()
@@ -93,40 +93,40 @@ def setflags(f, l, x):
         return
     if stat.S_ISLNK(s):
         # switch link to file
         data = os.readlink(f)
         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, 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):
     """
     Check whether the given path is on a filesystem with UNIX-like exec flags
 
     Requires a directory (like /foo/.hg)
     """
@@ -135,20 +135,20 @@ def checkexec(path):
     # a FS remount. Frequently we can detect it if files are created
     # with exec bit on.
 
     try:
         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
         return False
     return not (new_file_has_exec or exec_flags_cannot_flip)
 
 def checklink(path):
@@ -588,17 +588,17 @@ class unixdomainserver(socket.socket):
             okayifmissing(os.rmdir, os.path.dirname(self.realpath))
 
 def statislink(st):
     '''check whether a stat result is a symlink'''
     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
 
     This is a generic helper that will check for any activity
     (read, write.  exception) and return the list of touched files.
 
     In unsupported cases, it will raise a NotImplementedError"""
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -445,17 +445,17 @@ class vfs(abstractvfs):
 
     @util.propertycache
     def _chmod(self):
         return util.checkexec(self.base)
 
     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.
 
         Newly created directories are marked as "not to be indexed by
         the content indexing service", if ``notindexed`` is specified
         for "write" mode access.
--- a/mercurial/store.py
+++ b/mercurial/store.py
@@ -269,17 +269,17 @@ def _pathencode(path):
 def _plainhybridencode(f):
     return _hybridencode(f, False)
 
 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
 
 _data = ('data 00manifest.d 00manifest.i 00changelog.d 00changelog.i'
          ' phaseroots obsstore')
 
--- a/mercurial/subrepo.py
+++ b/mercurial/subrepo.py
@@ -535,17 +535,17 @@ class abstractsubrepo(object):
         else:
             files = self.files()
         total = len(files)
         relpath = subrelpath(self)
         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,
                              unit=_('files'), total=total)
         self.ui.progress(_('archiving (%s)') % relpath, None)
         return total
 
--- a/mercurial/transaction.py
+++ b/mercurial/transaction.py
@@ -125,18 +125,18 @@ class transaction(object):
         # (cache is currently unused)
         self._backupentries = []
         self._backupmap = {}
         self._backupjournal = "%s.backupfiles" % self.journal
         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
         self._pendingcallback = {}
         # True is any pending data have been written ever
         self._anypending = False
         # holds callback to call when writing the transaction
--- a/mercurial/windows.py
+++ b/mercurial/windows.py
@@ -20,17 +20,17 @@ samedevice = win32.samedevice
 samefile = win32.samefile
 setsignalhandler = win32.setsignalhandler
 spawndetached = win32.spawndetached
 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:
         fp = osutil.posixfile(name, mode, buffering) # may raise WindowsError
 
         # The position when opening in append mode is implementation defined, so
         # make it consistent with other platforms, which position at EOF.
--- a/tests/hghave.py
+++ b/tests/hghave.py
@@ -83,20 +83,20 @@ def has_eol_in_paths():
 
 @check("execbit", "executable bit")
 def has_executablebit():
     try:
         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
         return False
     return not (new_file_has_exec or exec_flags_cannot_flip)
 
 @check("icasefs", "case insensitive file system")
@@ -241,23 +241,23 @@ def has_tla():
 def has_gpg():
     return matchoutput('gpg --version 2>&1', r'GnuPG')
 
 @check("unix-permissions", "unix-style permissions")
 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)
 
 @check("unix-socket", "AF_UNIX socket family")
 def has_unix_socket():
     return getattr(socket, 'AF_UNIX', None) is not None