Read about our upcoming Code of Conduct on this issue

Commit f05bb157 authored by Augie Fackler's avatar Augie Fackler
Browse files

cleanup: remove pointless r-prefixes on double-quoted strings

This is only double-quoted strings. I'll do single-quoted strings as a
second step. These had existed because our source transformer didn't
turn r"" into b"", so we had tagged some strings as r-strings to get
"native" strings on both Pythons. Now that the transformer is gone, we
can dispense with this nonsense.

Methodology:

I ran

    hg locate 'set:added() or modified() or clean()' | egrep '.*\.py$'  | xargs egrep --color=never -n  -- \[\^a-z\]r\"\[\^\"\\\\\]\*\"\[\^\"\]

in an emacs grep-mode buffer, and then used a keyboard macro to
iterate over the results and remove the r prefix as needed.

# skip-blame removing unneeded r prefixes left over from Python 3 migration.

Differential Revision: https://phab.mercurial-scm.org/D7305
parent c093cc6e6c99
......@@ -281,10 +281,10 @@ for i in [0, 1]:
for tp in testpats[i]:
p = tp[0]
m = tp[1]
if p.startswith(r'^'):
p = r"^ [$>] (%s)" % p[1:]
if p.startswith('^'):
p = "^ [$>] (%s)" % p[1:]
else:
p = r"^ [$>] .*(%s)" % p
p = "^ [$>] .*(%s)" % p
utestpats[i].append((p, m) + tp[2:])
# don't transform the following rules:
......
......@@ -1658,7 +1658,7 @@ def perfstartup(ui, repo, **opts):
)
else:
os.environ[r'HGRCPATH'] = r' '
os.system(r"%s version -q > NUL" % sys.argv[0])
os.system("%s version -q > NUL" % sys.argv[0])
timer(d)
fm.end()
......
......@@ -22,7 +22,7 @@ except ImportError:
# available. Relax C module requirements.
os.environ[r'HGMODULEPOLICY'] = r'allow'
# import from the live mercurial repo
sys.path.insert(0, r"..")
sys.path.insert(0, "..")
from mercurial import demandimport
demandimport.enable()
......
......@@ -70,9 +70,9 @@ class _demandmod(object):
head = name
after = []
object.__setattr__(
self, r"_data", (head, globals, locals, after, level, set())
self, "_data", (head, globals, locals, after, level, set())
)
object.__setattr__(self, r"_module", None)
object.__setattr__(self, "_module", None)
def _extend(self, name):
"""add to the list of submodules to load"""
......@@ -143,7 +143,7 @@ class _demandmod(object):
if modref and getattr(modref, head, None) is self:
setattr(modref, head, mod)
object.__setattr__(self, r"_module", mod)
object.__setattr__(self, "_module", mod)
def __repr__(self):
if self._module:
......
......@@ -493,7 +493,7 @@ class commandline(object):
# POSIX requires at least 4096 bytes for ARG_MAX
argmax = 4096
try:
argmax = os.sysconf(r"SC_ARG_MAX")
argmax = os.sysconf("SC_ARG_MAX")
except (AttributeError, ValueError):
pass
......
......@@ -54,10 +54,8 @@ class logentry(object):
self.__dict__.update(entries)
def __repr__(self):
items = (
r"%s=%r" % (k, self.__dict__[k]) for k in sorted(self.__dict__)
)
return r"%s(%s)" % (type(self).__name__, r", ".join(items))
items = ("%s=%r" % (k, self.__dict__[k]) for k in sorted(self.__dict__))
return "%s(%s)" % (type(self).__name__, ", ".join(items))
class logerror(Exception):
......
......@@ -90,7 +90,7 @@ def parseoptions(ui, cmdoptions, args):
args = fancyopts.fancyopts(list(args), cmdoptions, opts, True)
break
except getopt.GetoptError as ex:
if r"requires argument" in ex.msg:
if "requires argument" in ex.msg:
raise
if (r'--' + ex.opt) in ex.msg:
flag = b'--' + pycompat.bytestr(ex.opt)
......
......@@ -249,7 +249,7 @@ def _batchresponseobjects(req, objects, action, store):
if not exists:
rsp[r'error'] = {
r'code': 404,
r'message': r"The object does not exist",
r'message': "The object does not exist",
}
yield rsp
continue
......@@ -257,7 +257,7 @@ def _batchresponseobjects(req, objects, action, store):
elif not verifies:
rsp[r'error'] = {
r'code': 422, # XXX: is this the right code?
r'message': r"The object is corrupt",
r'message': "The object is corrupt",
}
yield rsp
continue
......@@ -287,7 +287,7 @@ def _batchresponseobjects(req, objects, action, store):
b'%s%s/.hg/lfs/objects/%s' % (req.baseurl, req.apppath, oid)
),
# datetime.isoformat() doesn't include the 'Z' suffix
r"expires_at": expiresat.strftime(r'%Y-%m-%dT%H:%M:%SZ'),
"expires_at": expiresat.strftime(r'%Y-%m-%dT%H:%M:%SZ'),
r'header': _buildheader(),
}
}
......
......@@ -33,8 +33,8 @@ def reposetup(repo):
# TODO: don't blindly add include/exclude wireproto
# arguments to unbundle.
include, exclude = repo.narrowpats
kwargs[r"includepats"] = b','.join(include)
kwargs[r"excludepats"] = b','.join(exclude)
kwargs["includepats"] = b','.join(include)
kwargs["excludepats"] = b','.join(exclude)
return orig(cmd, *args, **kwargs)
extensions.wrapfunction(peer, b'_calltwowaystream', wrapped)
......
......@@ -72,7 +72,7 @@ def record(ui, repo, *pats, **opts):
_(b'running non-interactively, use %s instead') % b'commit'
)
opts[r"interactive"] = True
opts["interactive"] = True
overrides = {(b'experimental', b'crecord'): False}
with ui.configoverride(overrides, b'record'):
return commands.commit(ui, repo, *pats, **opts)
......
......@@ -260,9 +260,9 @@ def parsesizeflags(raw):
# v0, str(int(size)) is the header
size = int(header)
except ValueError:
raise RuntimeError(r"unexpected remotefilelog header: illegal format")
raise RuntimeError("unexpected remotefilelog header: illegal format")
if size is None:
raise RuntimeError(r"unexpected remotefilelog header: no size found")
raise RuntimeError("unexpected remotefilelog header: no size found")
return index + 1, size, flags
......
......@@ -95,7 +95,7 @@ def publish(name, desc, path, port):
hostname = socket.gethostname().split(r'.')[0]
host = hostname + r".local"
name = r"%s-%s" % (hostname, name)
name = "%s-%s" % (hostname, name)
# advertise to browsers
svc = Zeroconf.ServiceInfo(
......@@ -180,10 +180,10 @@ def getzcpaths():
server.close()
for value in l.found.values():
name = value.name[: value.name.index(b'.')]
url = r"http://%s:%s%s" % (
url = "http://%s:%s%s" % (
socket.inet_ntoa(value.address),
value.port,
value.properties.get(r"path", r"/"),
value.properties.get("path", "/"),
)
yield b"zc-" + name, pycompat.bytestr(url)
......
......@@ -85,7 +85,7 @@ def writechunks(ui, chunks, filename, vfs=None):
fh = open(filename, b"wb", 131072)
else:
fd, filename = pycompat.mkstemp(prefix=b"hg-bundle-", suffix=b".hg")
fh = os.fdopen(fd, r"wb")
fh = os.fdopen(fd, "wb")
cleanup = filename
for c in chunks:
fh.write(c)
......
......@@ -71,7 +71,7 @@ class basectx(object):
__str__ = encoding.strmethod(__bytes__)
def __repr__(self):
return r"<%s %s>" % (type(self).__name__, str(self))
return "<%s %s>" % (type(self).__name__, str(self))
def __eq__(self, other):
try:
......@@ -789,7 +789,7 @@ class basefilectx(object):
__str__ = encoding.strmethod(__bytes__)
def __repr__(self):
return r"<%s %s>" % (type(self).__name__, str(self))
return "<%s %s>" % (type(self).__name__, str(self))
def __hash__(self):
try:
......
......@@ -651,7 +651,7 @@ def debugdata(ui, repo, file_, rev=None, **opts):
)
def debugdate(ui, date, range=None, **opts):
"""parse and display a date"""
if opts[r"extended"]:
if opts["extended"]:
d = dateutil.parsedate(date, util.extendeddateformats)
else:
d = dateutil.parsedate(date)
......@@ -877,7 +877,7 @@ def debugstate(ui, repo, **opts):
timestr = b'set '
else:
timestr = time.strftime(
r"%Y-%m-%d %H:%M:%S ", time.localtime(ent[3])
"%Y-%m-%d %H:%M:%S ", time.localtime(ent[3])
)
timestr = encoding.strtolocal(timestr)
if ent[1] & 0o20000:
......
......@@ -368,7 +368,7 @@ class dirstate(object):
rereads the dirstate. Use localrepo.invalidatedirstate() if you want to
check whether the dirstate has changed before rereading it.'''
for a in (r"_map", r"_branch", r"_ignore"):
for a in ("_map", "_branch", "_ignore"):
if a in self.__dict__:
delattr(self, a)
self._lastnormaltime = 0
......@@ -1399,9 +1399,9 @@ class dirstatemap(object):
def addfile(self, f, oldstate, state, mode, size, mtime):
"""Add a tracked file to the dirstate."""
if oldstate in b"?r" and r"_dirs" in self.__dict__:
if oldstate in b"?r" and "_dirs" in self.__dict__:
self._dirs.addpath(f)
if oldstate == b"?" and r"_alldirs" in self.__dict__:
if oldstate == b"?" and "_alldirs" in self.__dict__:
self._alldirs.addpath(f)
self._map[f] = dirstatetuple(state, mode, size, mtime)
if state != b'n' or mtime == -1:
......@@ -1417,11 +1417,11 @@ class dirstatemap(object):
the file's previous state. In the future, we should refactor this
to be more explicit about what that state is.
"""
if oldstate not in b"?r" and r"_dirs" in self.__dict__:
if oldstate not in b"?r" and "_dirs" in self.__dict__:
self._dirs.delpath(f)
if oldstate == b"?" and r"_alldirs" in self.__dict__:
if oldstate == b"?" and "_alldirs" in self.__dict__:
self._alldirs.addpath(f)
if r"filefoldmap" in self.__dict__:
if "filefoldmap" in self.__dict__:
normed = util.normcase(f)
self.filefoldmap.pop(normed, None)
self._map[f] = dirstatetuple(b'r', 0, size, 0)
......@@ -1434,11 +1434,11 @@ class dirstatemap(object):
"""
exists = self._map.pop(f, None) is not None
if exists:
if oldstate != b"r" and r"_dirs" in self.__dict__:
if oldstate != b"r" and "_dirs" in self.__dict__:
self._dirs.delpath(f)
if r"_alldirs" in self.__dict__:
if "_alldirs" in self.__dict__:
self._alldirs.delpath(f)
if r"filefoldmap" in self.__dict__:
if "filefoldmap" in self.__dict__:
normed = util.normcase(f)
self.filefoldmap.pop(normed, None)
self.nonnormalset.discard(f)
......
......@@ -182,7 +182,7 @@ def tolocal(s):
if encoding == b'UTF-8':
# fast path
return s
r = u.encode(_sysstr(encoding), r"replace")
r = u.encode(_sysstr(encoding), "replace")
if u == r.decode(_sysstr(encoding)):
# r is a safe, non-lossy encoding of s
return safelocalstr(r)
......@@ -191,7 +191,7 @@ def tolocal(s):
# we should only get here if we're looking at an ancient changeset
try:
u = s.decode(_sysstr(fallbackencoding))
r = u.encode(_sysstr(encoding), r"replace")
r = u.encode(_sysstr(encoding), "replace")
if u == r.decode(_sysstr(encoding)):
# r is a safe, non-lossy encoding of s
return safelocalstr(r)
......@@ -199,7 +199,7 @@ def tolocal(s):
except UnicodeDecodeError:
u = s.decode("utf-8", "replace") # last ditch
# can't round-trip
return u.encode(_sysstr(encoding), r"replace")
return u.encode(_sysstr(encoding), "replace")
except LookupError as k:
raise error.Abort(k, hint=b"please check your locale settings")
......
......@@ -591,9 +591,7 @@ def wrapfilecache(cls, propname, wrapper):
break
if currcls is object:
raise AttributeError(
r"type '%s' has no property '%s'" % (cls, propname)
)
raise AttributeError("type '%s' has no property '%s'" % (cls, propname))
class wrappedfunction(object):
......
......@@ -934,10 +934,10 @@ def _maketempfiles(repo, fco, fca, localpath, uselocalpath):
name = os.path.join(tmproot, pre)
if ext:
name += ext
f = open(name, r"wb")
f = open(name, "wb")
else:
fd, name = pycompat.mkstemp(prefix=pre + b'.', suffix=ext)
f = os.fdopen(fd, r"wb")
f = os.fdopen(fd, "wb")
return f, name
def tempfromcontext(prefix, ctx):
......
......@@ -62,7 +62,7 @@ class _error_logger(object):
def writelines(self, seq):
for msg in seq:
self.handler.log_error(r"HG error: %s", encoding.strfromlocal(msg))
self.handler.log_error("HG error: %s", encoding.strfromlocal(msg))
class _httprequesthandler(httpservermod.basehttprequesthandler):
......@@ -128,20 +128,20 @@ class _httprequesthandler(httpservermod.basehttprequesthandler):
isinstance(e, (OSError, socket.error))
and e.errno == errno.ECONNRESET
):
tb = r"".join(traceback.format_exception(*sys.exc_info()))
tb = "".join(traceback.format_exception(*sys.exc_info()))
# We need a native-string newline to poke in the log
# message, because we won't get a newline when using an
# r-string. This is the easy way out.
newline = chr(10)
self.log_error(
r"Exception happened during processing "
r"request '%s':%s%s",
"request '%s':%s%s",
self.path,
newline,
tb,
)
self._start_response(r"500 Internal Server Error", [])
self._start_response("500 Internal Server Error", [])
self._write(b"Internal Server Error")
self._done()
......@@ -335,8 +335,8 @@ class _httprequesthandlerssl(_httprequesthandler):
def setup(self):
self.connection = self.request
self.rfile = self.request.makefile(r"rb", self.rbufsize)
self.wfile = self.request.makefile(r"wb", self.wbufsize)
self.rfile = self.request.makefile("rb", self.rbufsize)
self.wfile = self.request.makefile("wb", self.wbufsize)
try:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment