Mercurial > hg
diff hgext/convert/hg.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 | b4093d1d3b18 |
children | 687b865b95ad |
line wrap: on
line diff
--- a/hgext/convert/hg.py Sat Oct 05 10:29:34 2019 -0400 +++ b/hgext/convert/hg.py Sun Oct 06 09:45:02 2019 -0400 @@ -37,14 +37,17 @@ util, ) from mercurial.utils import dateutil + stringio = util.stringio from . import common + mapfile = common.mapfile NoRepo = common.NoRepo sha1re = re.compile(br'\b[0-9a-f]{12,40}\b') + class mercurial_sink(common.converter_sink): def __init__(self, ui, repotype, path): common.converter_sink.__init__(self, ui, repotype, path) @@ -56,8 +59,9 @@ try: self.repo = hg.repository(self.ui, path) if not self.repo.local(): - raise NoRepo(_('%s is not a local Mercurial repository') - % path) + raise NoRepo( + _('%s is not a local Mercurial repository') % path + ) except error.RepoError as err: ui.traceback() raise NoRepo(err.args[0]) @@ -66,13 +70,15 @@ ui.status(_('initializing destination %s repository\n') % path) self.repo = hg.repository(self.ui, path, create=True) if not self.repo.local(): - raise NoRepo(_('%s is not a local Mercurial repository') - % path) + raise NoRepo( + _('%s is not a local Mercurial repository') % path + ) self.created.append(path) except error.RepoError: ui.traceback() - raise NoRepo(_("could not create hg repository %s as sink") - % path) + raise NoRepo( + _("could not create hg repository %s as sink") % path + ) self.lock = None self.wlock = None self.filemapmode = False @@ -100,7 +106,7 @@ if not self.clonebranches: return - setbranch = (branch != self.lastbranch) + setbranch = branch != self.lastbranch self.lastbranch = branch if not branch: branch = 'default' @@ -130,8 +136,9 @@ pbranchpath = os.path.join(self.path, pbranch) prepo = hg.peer(self.ui, {}, pbranchpath) self.ui.note(_('pulling from %s into %s\n') % (pbranch, branch)) - exchange.pull(self.repo, prepo, - [prepo.lookup(h) for h in heads]) + exchange.pull( + self.repo, prepo, [prepo.lookup(h) for h in heads] + ) self.before() def _rewritetags(self, source, revmap, data): @@ -166,8 +173,9 @@ if revid != nodemod.nullhex: revmap = self.subrevmaps.get(subpath) if revmap is None: - revmap = mapfile(self.ui, - self.repo.wjoin(subpath, '.hg/shamap')) + revmap = mapfile( + self.ui, self.repo.wjoin(subpath, '.hg/shamap') + ) self.subrevmaps[subpath] = revmap # It is reasonable that one or more of the subrepos don't @@ -184,8 +192,10 @@ newid = revmap.get(revid) if not newid: if len(revmap) > 0: - self.ui.warn(_("%s is missing from %s/.hg/shamap\n") % - (revid, subpath)) + self.ui.warn( + _("%s is missing from %s/.hg/shamap\n") + % (revid, subpath) + ) else: revid = newid @@ -204,8 +214,15 @@ anc = [p1ctx.ancestor(p2ctx)] # Calculate what files are coming from p2 actions, diverge, rename = mergemod.calculateupdates( - self.repo, p1ctx, p2ctx, anc, branchmerge=True, - force=True, acceptremote=False, followcopies=False) + self.repo, + p1ctx, + p2ctx, + anc, + branchmerge=True, + force=True, + acceptremote=False, + followcopies=False, + ) for file, (action, info, msg) in actions.iteritems(): if source.targetfilebelongstosource(file): @@ -216,10 +233,14 @@ # If the file requires actual merging, abort. We don't have enough # context to resolve merges correctly. if action in ['m', 'dm', 'cd', 'dc']: - raise error.Abort(_("unable to convert merge commit " - "since target parents do not merge cleanly (file " - "%s, parents %s and %s)") % (file, p1ctx, - p2ctx)) + raise error.Abort( + _( + "unable to convert merge commit " + "since target parents do not merge cleanly (file " + "%s, parents %s and %s)" + ) + % (file, p1ctx, p2ctx) + ) elif action == 'k': # 'keep' means nothing changed from p1 continue @@ -227,8 +248,9 @@ # Any other change means we want to take the p2 version yield file - def putcommit(self, files, copies, parents, commit, source, revmap, full, - cleanp2): + def putcommit( + self, files, copies, parents, commit, source, revmap, full, cleanp2 + ): files = dict(files) def getfilectx(repo, memctx, f): @@ -251,8 +273,15 @@ data = self._rewritetags(source, revmap, data) if f == '.hgsubstate': data = self._rewritesubstate(source, data) - return context.memfilectx(self.repo, memctx, f, data, 'l' in mode, - 'x' in mode, copies.get(f)) + return context.memfilectx( + self.repo, + memctx, + f, + data, + 'l' in mode, + 'x' in mode, + copies.get(f), + ) pl = [] for p in parents: @@ -277,7 +306,7 @@ oldrev = source.lookuprev(sha1) newrev = revmap.get(oldrev) if newrev is not None: - text = text.replace(sha1, newrev[:len(sha1)]) + text = text.replace(sha1, newrev[: len(sha1)]) extra = commit.extra.copy() @@ -285,8 +314,12 @@ if sourcename: extra['convert_source'] = sourcename - for label in ('source', 'transplant_source', 'rebase_source', - 'intermediate-source'): + for label in ( + 'source', + 'transplant_source', + 'rebase_source', + 'intermediate-source', + ): node = extra.get(label) if node is None: @@ -326,13 +359,25 @@ p2files.add(file) fileset.add(file) - ctx = context.memctx(self.repo, (p1, p2), text, fileset, - getfilectx, commit.author, commit.date, extra) + ctx = context.memctx( + self.repo, + (p1, p2), + text, + fileset, + getfilectx, + commit.author, + commit.date, + extra, + ) # We won't know if the conversion changes the node until after the # commit, so copy the source's phase for now. - self.repo.ui.setconfig('phases', 'new-commit', - phases.phasenames[commit.phase], 'convert') + self.repo.ui.setconfig( + 'phases', + 'new-commit', + phases.phasenames[commit.phase], + 'convert', + ) with self.repo.transaction("convert") as tr: if self.repo.ui.config('convert', 'hg.preserve-hash'): @@ -347,8 +392,9 @@ if commit.rev != node: ctx = self.repo[node] if ctx.phase() < phases.draft: - phases.registernew(self.repo, tr, phases.draft, - [ctx.node()]) + phases.registernew( + self.repo, tr, phases.draft, [ctx.node()] + ) text = "(octopus merge fixup)\n" p2 = node @@ -372,7 +418,8 @@ for h in heads: if '.hgtags' in self.repo[h]: oldlines.update( - set(self.repo[h]['.hgtags'].data().splitlines(True))) + set(self.repo[h]['.hgtags'].data().splitlines(True)) + ) oldlines = sorted(list(oldlines)) newlines = sorted([("%s %s\n" % (tags[tag], tag)) for tag in tags]) @@ -398,15 +445,23 @@ return None, None data = "".join(newlines) + def getfilectx(repo, memctx, f): return context.memfilectx(repo, memctx, f, data, False, False, None) self.ui.status(_("updating tags\n")) date = "%d 0" % int(time.mktime(time.gmtime())) extra = {'branch': self.tagsbranch} - ctx = context.memctx(self.repo, (tagparent, None), "update tags", - [".hgtags"], getfilectx, "convert-repo", date, - extra) + ctx = context.memctx( + self.repo, + (tagparent, None), + "update tags", + [".hgtags"], + getfilectx, + "convert-repo", + date, + extra, + ) node = self.repo.commitctx(ctx) return nodemod.hex(node), nodemod.hex(tagparent) @@ -423,8 +478,10 @@ tr = self.repo.transaction('bookmark') self.ui.status(_("updating bookmarks\n")) destmarks = self.repo._bookmarks - changes = [(bookmark, nodemod.bin(updatedbookmark[bookmark])) - for bookmark in updatedbookmark] + changes = [ + (bookmark, nodemod.bin(updatedbookmark[bookmark])) + for bookmark in updatedbookmark + ] destmarks.applychanges(self.repo, tr, changes) tr.close() finally: @@ -436,11 +493,17 @@ def hascommitforsplicemap(self, rev): if rev not in self.repo and self.clonebranches: - raise error.Abort(_('revision %s not found in destination ' - 'repository (lookups with clonebranches=true ' - 'are not implemented)') % rev) + raise error.Abort( + _( + 'revision %s not found in destination ' + 'repository (lookups with clonebranches=true ' + 'are not implemented)' + ) + % rev + ) return rev in self.repo + class mercurial_source(common.converter_source): def __init__(self, ui, repotype, path, revs=None): common.converter_source.__init__(self, ui, repotype, path, revs) @@ -468,8 +531,9 @@ try: startnode = self.repo.lookup(startnode) except error.RepoError: - raise error.Abort(_('%s is not a valid start revision') - % startnode) + raise error.Abort( + _('%s is not a valid start revision') % startnode + ) startrev = self.repo.changelog.rev(startnode) children = {startnode: 1} for r in self.repo.changelog.descendants([startrev]): @@ -483,8 +547,9 @@ self._heads = self.repo.heads() else: if revs or startnode is not None: - raise error.Abort(_('hg.revs cannot be combined with ' - 'hg.startrev or --rev')) + raise error.Abort( + _('hg.revs cannot be combined with ' 'hg.startrev or --rev') + ) nodes = set() parents = set() for r in scmutil.revrange(self.repo, [hgrevs]): @@ -580,29 +645,38 @@ optparents = [p.hex() for p in ctx.parents() if p and p not in _parents] crev = rev - return common.commit(author=ctx.user(), - date=dateutil.datestr(ctx.date(), - '%Y-%m-%d %H:%M:%S %1%2'), - desc=ctx.description(), - rev=crev, - parents=parents, - optparents=optparents, - branch=ctx.branch(), - extra=ctx.extra(), - sortkey=ctx.rev(), - saverev=self.saverev, - phase=ctx.phase(), - ctx=ctx) + return common.commit( + author=ctx.user(), + date=dateutil.datestr(ctx.date(), '%Y-%m-%d %H:%M:%S %1%2'), + desc=ctx.description(), + rev=crev, + parents=parents, + optparents=optparents, + branch=ctx.branch(), + extra=ctx.extra(), + sortkey=ctx.rev(), + saverev=self.saverev, + phase=ctx.phase(), + ctx=ctx, + ) def numcommits(self): return len(self.repo) def gettags(self): # This will get written to .hgtags, filter non global tags out. - tags = [t for t in self.repo.tagslist() - if self.repo.tagtype(t[0]) == 'global'] - return dict([(name, nodemod.hex(node)) for name, node in tags - if self.keep(node)]) + tags = [ + t + for t in self.repo.tagslist() + if self.repo.tagtype(t[0]) == 'global' + ] + return dict( + [ + (name, nodemod.hex(node)) + for name, node in tags + if self.keep(node) + ] + ) def getchangedfiles(self, rev, i): ctx = self._changectx(rev)