Mercurial > hg
diff hgext/convert/common.py @ 43076:2372284d9457
formatting: blacken the codebase
This is using my patch to black
(https://github.com/psf/black/pull/826) so we don't un-wrap collection
literals.
Done with:
hg files 'set:**.py - mercurial/thirdparty/** - "contrib/python-zstandard/**"' | xargs black -S
# skip-blame mass-reformatting only
# no-check-commit reformats foo_bar functions
Differential Revision: https://phab.mercurial-scm.org/D6971
author | Augie Fackler <augie@google.com> |
---|---|
date | Sun, 06 Oct 2019 09:45:02 -0400 |
parents | d98ec36be808 |
children | 687b865b95ad |
line wrap: on
line diff
--- a/hgext/convert/common.py Sat Oct 05 10:29:34 2019 -0400 +++ b/hgext/convert/common.py Sun Oct 06 09:45:02 2019 -0400 @@ -22,20 +22,19 @@ pycompat, util, ) -from mercurial.utils import ( - procutil, -) +from mercurial.utils import procutil pickle = util.pickle propertycache = util.propertycache + def _encodeornone(d): if d is None: return return d.encode('latin1') + class _shlexpy3proxy(object): - def __init__(self, l): self._l = l @@ -53,6 +52,7 @@ def lineno(self): return self._l.lineno + def shlexer(data=None, filepath=None, wordchars=None, whitespace=None): if data is None: if pycompat.ispy3: @@ -62,7 +62,8 @@ else: if filepath is not None: raise error.ProgrammingError( - 'shlexer only accepts data or filepath, not both') + 'shlexer only accepts data or filepath, not both' + ) if pycompat.ispy3: data = data.decode('latin1') l = shlex.shlex(data, infile=filepath, posix=True) @@ -81,6 +82,7 @@ return _shlexpy3proxy(l) return l + def encodeargs(args): def encodearg(s): lines = base64.encodestring(s) @@ -90,13 +92,16 @@ s = pickle.dumps(args) return encodearg(s) + def decodeargs(s): s = base64.decodestring(s) return pickle.loads(s) + class MissingTool(Exception): pass + def checktool(exe, name=None, abort=True): name = name or exe if not procutil.findexe(exe): @@ -106,27 +111,43 @@ exc = MissingTool raise exc(_('cannot find required "%s" tool') % name) + class NoRepo(Exception): pass + SKIPREV = 'SKIP' + class commit(object): - def __init__(self, author, date, desc, parents, branch=None, rev=None, - extra=None, sortkey=None, saverev=True, phase=phases.draft, - optparents=None, ctx=None): + def __init__( + self, + author, + date, + desc, + parents, + branch=None, + rev=None, + extra=None, + sortkey=None, + saverev=True, + phase=phases.draft, + optparents=None, + ctx=None, + ): self.author = author or 'unknown' self.date = date or '0 0' self.desc = desc - self.parents = parents # will be converted and used as parents - self.optparents = optparents or [] # will be used if already converted + self.parents = parents # will be converted and used as parents + self.optparents = optparents or [] # will be used if already converted self.branch = branch self.rev = rev self.extra = extra or {} self.sortkey = sortkey self.saverev = saverev self.phase = phase - self.ctx = ctx # for hg to hg conversions + self.ctx = ctx # for hg to hg conversions + class converter_source(object): """Conversion source interface""" @@ -146,8 +167,10 @@ such format for their revision numbering """ if not re.match(br'[0-9a-fA-F]{40,40}$', revstr): - raise error.Abort(_('%s entry %s is not a valid revision' - ' identifier') % (mapname, revstr)) + raise error.Abort( + _('%s entry %s is not a valid revision' ' identifier') + % (mapname, revstr) + ) def before(self): pass @@ -223,8 +246,9 @@ try: return s.decode("latin-1").encode("utf-8") except UnicodeError: - return s.decode(pycompat.sysstr(encoding), - "replace").encode("utf-8") + return s.decode(pycompat.sysstr(encoding), "replace").encode( + "utf-8" + ) def getchangedfiles(self, rev, i): """Return the files changed by rev compared to parent[i]. @@ -275,6 +299,7 @@ """ return True + class converter_sink(object): """Conversion sink (target) interface""" @@ -301,8 +326,9 @@ mapping equivalent authors identifiers for each system.""" return None - def putcommit(self, files, copies, parents, commit, source, revmap, full, - cleanp2): + def putcommit( + self, files, copies, parents, commit, source, revmap, full, cleanp2 + ): """Create a revision with all changed files listed in 'files' and having listed parents. 'commit' is a commit object containing at a minimum the author, date, and message for this @@ -369,6 +395,7 @@ special cases.""" raise NotImplementedError + class commandline(object): def __init__(self, ui, command): self.ui = ui @@ -403,11 +430,15 @@ def _run(self, cmd, *args, **kwargs): def popen(cmdline): - p = subprocess.Popen(procutil.tonativestr(cmdline), - shell=True, bufsize=-1, - close_fds=procutil.closefds, - stdout=subprocess.PIPE) + p = subprocess.Popen( + procutil.tonativestr(cmdline), + shell=True, + bufsize=-1, + close_fds=procutil.closefds, + stdout=subprocess.PIPE, + ) return p + return self._dorun(popen, cmd, *args, **kwargs) def _run2(self, cmd, *args, **kwargs): @@ -416,7 +447,7 @@ def _run3(self, cmd, *args, **kwargs): return self._dorun(procutil.popen3, cmd, *args, **kwargs) - def _dorun(self, openfunc, cmd, *args, **kwargs): + def _dorun(self, openfunc, cmd, *args, **kwargs): cmdline = self._cmdline(cmd, *args, **kwargs) self.ui.debug('running: %s\n' % (cmdline,)) self.prerun() @@ -495,6 +526,7 @@ for l in self._limit_arglist(arglist, cmd, *args, **kwargs): self.run0(cmd, *(list(args) + l), **kwargs) + class mapfile(dict): def __init__(self, ui, path): super(mapfile, self).__init__() @@ -523,7 +555,8 @@ except ValueError: raise error.Abort( _('syntax error in %s(%d): key/value pair expected') - % (self.path, i + 1)) + % (self.path, i + 1) + ) if key not in self: self.order.append(key) super(mapfile, self).__setitem__(key, value) @@ -535,8 +568,9 @@ self.fp = open(self.path, 'ab') except IOError as err: raise error.Abort( - _('could not open map file %r: %s') % - (self.path, encoding.strtolocal(err.strerror))) + _('could not open map file %r: %s') + % (self.path, encoding.strtolocal(err.strerror)) + ) self.fp.write(util.tonativeeol('%s %s\n' % (key, value))) self.fp.flush() super(mapfile, self).__setitem__(key, value) @@ -546,9 +580,11 @@ self.fp.close() self.fp = None + def makedatetimestamp(t): """Like dateutil.makedate() but for time t instead of current time""" - delta = (datetime.datetime.utcfromtimestamp(t) - - datetime.datetime.fromtimestamp(t)) + delta = datetime.datetime.utcfromtimestamp( + t + ) - datetime.datetime.fromtimestamp(t) tz = delta.days * 86400 + delta.seconds return t, tz