# HG changeset patch # User Gregory Szorc # Date 2015-06-24 05:30:33 # Node ID e930367479020f3111969852d2082e3342fa32bd # Parent dcc56e10c23b8d91b27e43b172706f6ec2837879 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 "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 @@ -201,7 +201,7 @@ class darcs_source(converter_source, com 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): diff --git a/hgext/convert/gnuarch.py b/hgext/convert/gnuarch.py --- a/hgext/convert/gnuarch.py +++ b/hgext/convert/gnuarch.py @@ -215,7 +215,7 @@ class gnuarch_source(converter_source, c 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): diff --git a/hgext/largefiles/overrides.py b/hgext/largefiles/overrides.py --- a/hgext/largefiles/overrides.py +++ b/hgext/largefiles/overrides.py @@ -908,7 +908,7 @@ 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: @@ -937,7 +937,7 @@ def overridearchive(orig, repo, dest, no 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): @@ -991,7 +991,7 @@ def hgsubrepoarchive(orig, repo, archive 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) diff --git a/mercurial/archival.py b/mercurial/archival.py --- a/mercurial/archival.py +++ b/mercurial/archival.py @@ -157,7 +157,7 @@ class tarit(object): i.size = len(data) if islink: i.type = tarfile.SYMTYPE - i.mode = 0777 + i.mode = 0o777 i.linkname = data data = None i.size = 0 @@ -220,7 +220,7 @@ class zipit(object): 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 @@ -302,7 +302,7 @@ 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)] @@ -314,7 +314,7 @@ def archive(repo, dest, node, kind, deco 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 @@ -3001,10 +3001,10 @@ def debugstate(ui, repo, nodates=None, d 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 @@ -594,9 +594,9 @@ class dirstate(object): 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 @@ -963,7 +963,7 @@ class dirstate(object): 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) diff --git a/mercurial/patch.py b/mercurial/patch.py --- a/mercurial/patch.py +++ b/mercurial/patch.py @@ -288,8 +288,8 @@ class patchmeta(object): 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): @@ -430,7 +430,7 @@ class fsbackend(abstractbackend): 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 diff --git a/mercurial/posix.py b/mercurial/posix.py --- a/mercurial/posix.py +++ b/mercurial/posix.py @@ -71,7 +71,7 @@ def sshargs(sshcmd, host, user, port): 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 @@ -98,30 +98,30 @@ def setflags(f, l, x): 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): @@ -140,10 +140,10 @@ def checkexec(path): 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): @@ -593,7 +593,7 @@ def statislink(st): 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 @@ -450,7 +450,7 @@ 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): diff --git a/mercurial/store.py b/mercurial/store.py --- a/mercurial/store.py +++ b/mercurial/store.py @@ -274,7 +274,7 @@ def _calcmode(vfs): # 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 diff --git a/mercurial/subrepo.py b/mercurial/subrepo.py --- a/mercurial/subrepo.py +++ b/mercurial/subrepo.py @@ -540,7 +540,7 @@ class abstractsubrepo(object): 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)) diff --git a/mercurial/transaction.py b/mercurial/transaction.py --- a/mercurial/transaction.py +++ b/mercurial/transaction.py @@ -130,8 +130,8 @@ class transaction(object): 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 = {} diff --git a/mercurial/windows.py b/mercurial/windows.py --- a/mercurial/windows.py +++ b/mercurial/windows.py @@ -25,7 +25,7 @@ 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''' diff --git a/tests/hghave.py b/tests/hghave.py --- a/tests/hghave.py +++ b/tests/hghave.py @@ -88,10 +88,10 @@ def has_executablebit(): 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): @@ -246,13 +246,13 @@ 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: