diff --git a/hgext/rebase.py b/hgext/rebase.py --- a/hgext/rebase.py +++ b/hgext/rebase.py @@ -4,15 +4,14 @@ # # This software may be used and distributed according to the terms of the # GNU General Public License version 2 or any later version. - -'''command to move sets of revisions to a different ancestor +"""command to move sets of revisions to a different ancestor This extension lets you rebase changesets in an existing Mercurial repository. For more information: https://mercurial-scm.org/wiki/RebaseExtension -''' +""" from __future__ import absolute_import @@ -20,10 +19,7 @@ import os from mercurial.i18n import _ -from mercurial.node import ( - nullrev, - short, -) +from mercurial.node import nullrev, short from mercurial.pycompat import open from mercurial import ( bookmarks, @@ -95,7 +91,8 @@ def _destrebase(repo, sourceset, destspace=None): """small wrapper around destmerge to pass the right extra args - Please wrap destutil.destmerge instead.""" + Please wrap destutil.destmerge instead. + """ return destutil.destmerge( repo, action=b'rebase', @@ -138,7 +135,7 @@ dests = destutil.orphanpossibledestination(repo, src) if len(dests) > 1: raise error.Abort( - _(b"ambiguous automatic rebase: %r could end up on any of %r") + _(b'ambiguous automatic rebase: %r could end up on any of %r') % (src, dests) ) # We have zero or one destination, so we can just return here. @@ -228,7 +225,7 @@ location=b'plain', ) else: - with self.repo.vfs(b"rebasestate", b"w") as f: + with self.repo.vfs(b'rebasestate', b'w') as f: self._writestatus(f) def _writestatus(self, f): @@ -248,9 +245,9 @@ if v >= 0: newrev = repo[v].hex() else: - newrev = b"%d" % v + newrev = b'%d' % v destnode = repo[destmap[d]].hex() - f.write(b"%s:%s:%s\n" % (oldrev, newrev, destnode)) + f.write(b'%s:%s:%s\n' % (oldrev, newrev, destnode)) repo.ui.debug(b'rebase status stored\n') def restorestatus(self): @@ -288,7 +285,7 @@ destmap = {} if True: - f = repo.vfs(b"rebasestate") + f = repo.vfs(b'rebasestate') for i, l in enumerate(f.read().splitlines()): if i == 0: data[b'originalwd'] = repo[l].rev() @@ -445,13 +442,13 @@ from mercurial.context import overlayworkingctx self.wctx = overlayworkingctx(self.repo) - self.repo.ui.debug(b"rebasing in-memory\n") + self.repo.ui.debug(b'rebasing in-memory\n') else: self.wctx = self.repo[None] - self.repo.ui.debug(b"rebasing on disk\n") + self.repo.ui.debug(b'rebasing on disk\n') self.repo.ui.log( - b"rebase", - b"using in-memory rebase: %r\n", + b'rebase', + b'using in-memory rebase: %r\n', self.inmemory, rebase_imm_used=self.inmemory, ) @@ -492,11 +489,11 @@ cands = [k for k, v in pycompat.iteritems(self.state) if v == revtodo] p = repo.ui.makeprogress( - _(b"rebasing"), unit=_(b'changesets'), total=len(cands) + _(b'rebasing'), unit=_(b'changesets'), total=len(cands) ) def progress(ctx): - p.increment(item=(b"%d:%s" % (ctx.rev(), ctx))) + p.increment(item=(b'%d:%s' % (ctx.rev(), ctx))) allowdivergence = self.ui.configbool( b'experimental', b'evolution.allowdivergence' @@ -515,10 +512,11 @@ ui.note(_(b'rebase merging completed\n')) def _concludenode(self, rev, p1, editor, commitmsg=None): - '''Commit the wd changes with parents p1 and p2. + """Commit the wd changes with parents p1 and p2. Reuse commit info from rev but also store useful information in extra. - Return node of committed revision.''' + Return node of committed revision. + """ repo = self.repo ctx = repo[rev] if commitmsg is None: @@ -722,7 +720,7 @@ # original directory is a parent of rebase set root or ignored newwd = self.originalwd if newwd not in [c.rev() for c in repo[None].parents()]: - ui.note(_(b"update back to initial working directory parent\n")) + ui.note(_(b'update back to initial working directory parent\n')) hg.updaterepo(repo, newwd, overwrite=False) collapsedas = None @@ -743,11 +741,11 @@ clearstatus(repo) clearcollapsemsg(repo) - ui.note(_(b"rebase completed\n")) + ui.note(_(b'rebase completed\n')) util.unlinkpath(repo.sjoin(b'undo'), ignoremissing=True) if self.skipped: skippedlen = len(self.skipped) - ui.note(_(b"%d revisions have been skipped\n") % skippedlen) + ui.note(_(b'%d revisions have been skipped\n') % skippedlen) fm.end() if ( @@ -758,7 +756,7 @@ bookmarks.activate(repo, self.activebookmark) def _abort(self, backup=True, suppwarns=False, dryrun=False, confirm=False): - '''Restore the repository to its original state.''' + """Restore the repository to its original state.""" repo = self.repo try: @@ -787,7 +785,7 @@ if descendants - set(rebased): repo.ui.warn( _( - b"warning: new changesets detected on " + b'warning: new changesets detected on ' b"destination branch, can't strip\n" ) ) @@ -1050,13 +1048,13 @@ with repo.wlock(), repo.lock(): rbsrt.restorestatus() if rbsrt.collapsef: - raise error.Abort(_(b"cannot stop in --collapse session")) + raise error.Abort(_(b'cannot stop in --collapse session')) allowunstable = obsolete.isenabled(repo, obsolete.allowunstableopt) if not (rbsrt.keepf or allowunstable): raise error.Abort( _( - b"cannot remove original changesets with" - b" unrebased descendants" + b'cannot remove original changesets with' + b' unrebased descendants' ), hint=_( b'either enable obsmarkers to allow unstable ' @@ -1170,11 +1168,11 @@ if extensions.find(b'histedit'): enablehistedit = b'' except KeyError: - enablehistedit = b" --config extensions.histedit=" - help = b"hg%s help -e histedit" % enablehistedit + enablehistedit = b' --config extensions.histedit=' + help = b'hg%s help -e histedit' % enablehistedit msg = ( _( - b"interactive history editing is supported by the " + b'interactive history editing is supported by the ' b"'histedit' extension (see \"%s\")" ) % help @@ -1350,8 +1348,8 @@ raise error.Abort(_(b'cannot rebase the working copy')) rebasingwcp = repo[b'.'].rev() in rebaseset ui.log( - b"rebase", - b"rebasing working copy parent: %r\n", + b'rebase', + b'rebasing working copy parent: %r\n', rebasingwcp, rebase_rebasing_wcp=rebasingwcp, ) @@ -1403,6 +1401,7 @@ def externalparent(repo, state, destancestors): """Return the revision that should be used as the second parent + when the revisions in state is collapsed on top of destancestors. Abort if there is more than one parent. """ @@ -1423,13 +1422,15 @@ b'unable to collapse on top of %d, there is more ' b'than one external parent: %s' ) - % (max(destancestors), b', '.join(b"%d" % p for p in sorted(parents))) + % (max(destancestors), b', '.join(b'%d' % p for p in sorted(parents))) ) def commitmemorynode(repo, wctx, editor, extra, user, date, commitmsg): - '''Commit the memory changes with parents p1 and p2. - Return node of committed revision.''' + """Commit the memory changes with parents p1 and p2. + + Return node of committed revision. + """ # Replicates the empty check in ``repo.commit``. if wctx.isempty() and not repo.ui.configbool(b'ui', b'allowemptycommit'): return None @@ -1454,8 +1455,10 @@ def commitnode(repo, editor, extra, user, date, commitmsg): - '''Commit the wd changes with parents p1 and p2. - Return node of committed revision.''' + """Commit the wd changes with parents p1 and p2. + + Return node of committed revision. + """ dsguard = util.nullcontextmanager() if not repo.ui.configbool(b'rebase', b'singletransaction'): dsguard = dirstateguard.dirstateguard(repo, b'rebase') @@ -1478,18 +1481,18 @@ wctx.setbase(p1ctx) else: if repo[b'.'].rev() != p1: - repo.ui.debug(b" update to %d:%s\n" % (p1, p1ctx)) + repo.ui.debug(b' update to %d:%s\n' % (p1, p1ctx)) mergemod.clean_update(p1ctx) else: - repo.ui.debug(b" already in destination\n") + repo.ui.debug(b' already in destination\n') # This is, alas, necessary to invalidate workingctx's manifest cache, # as well as other data we litter on it in other places. wctx = repo[None] repo.dirstate.write(repo.currenttransaction()) ctx = repo[rev] - repo.ui.debug(b" merge against %d:%s\n" % (rev, ctx)) + repo.ui.debug(b' merge against %d:%s\n' % (rev, ctx)) if base is not None: - repo.ui.debug(b" detach base %d:%s\n" % (base, repo[base])) + repo.ui.debug(b' detach base %d:%s\n' % (base, repo[base])) # See explanation in merge.graft() mergeancestor = repo.changelog.isancestor(p1ctx.node(), ctx.node()) @@ -1606,12 +1609,12 @@ if divergencebasecandidates and not divergenceok: divhashes = (bytes(repo[r]) for r in divergencebasecandidates) - msg = _(b"this rebase will cause divergences from: %s") + msg = _(b'this rebase will cause divergences from: %s') h = _( - b"to force the rebase please set " - b"experimental.evolution.allowdivergence=True" + b'to force the rebase please set ' + b'experimental.evolution.allowdivergence=True' ) - raise error.Abort(msg % (b",".join(divhashes),), hint=h) + raise error.Abort(msg % (b','.join(divhashes),), hint=h) def successorrevs(unfi, rev): @@ -1805,7 +1808,7 @@ # "rebasenode" updates to new p1, use the corresponding merge base. base = bases[0] - repo.ui.debug(b" future parents are %d and %d\n" % tuple(newps)) + repo.ui.debug(b' future parents are %d and %d\n' % tuple(newps)) return newps[0], newps[1], base @@ -1854,7 +1857,7 @@ (), patchname=name, git=isgit, - rev=[b"%d" % state[rev]], + rev=[b'%d' % state[rev]], ) else: # Rebased and skipped @@ -1876,20 +1879,20 @@ def storecollapsemsg(repo, collapsemsg): """Store the collapse message to allow recovery""" collapsemsg = collapsemsg or b'' - f = repo.vfs(b"last-message.txt", b"w") - f.write(b"%s\n" % collapsemsg) + f = repo.vfs(b'last-message.txt', b'w') + f.write(b'%s\n' % collapsemsg) f.close() def clearcollapsemsg(repo): """Remove collapse message file""" - repo.vfs.unlinkpath(b"last-message.txt", ignoremissing=True) + repo.vfs.unlinkpath(b'last-message.txt', ignoremissing=True) def restorecollapsemsg(repo, isabort): """Restore previously stored collapse message""" try: - f = repo.vfs(b"last-message.txt") + f = repo.vfs(b'last-message.txt') collapsemsg = f.readline().strip() f.close() except IOError as err: @@ -1909,7 +1912,7 @@ tr = repo.currenttransaction() if tr: tr.removefilegenerator(b'rebasestate') - repo.vfs.unlinkpath(b"rebasestate", ignoremissing=True) + repo.vfs.unlinkpath(b'rebasestate', ignoremissing=True) def sortsource(destmap): @@ -1939,11 +1942,11 @@ def buildstate(repo, destmap, collapse): - '''Define which revisions are going to be rebased and where + """Define which revisions are going to be rebased and where repo: repo destmap: {srcrev: destrev} - ''' + """ rebaseset = destmap.keys() originalwd = repo[b'.'].rev() @@ -2058,7 +2061,7 @@ for oldns, newn in pycompat.iteritems(replacements): for oldn in oldns: changes[hf(oldn)] = fl([hf(n) for n in newn], name=b'node') - nodechanges = fd(changes, key=b"oldnode", value=b"newnodes") + nodechanges = fd(changes, key=b'oldnode', value=b'newnodes') fm.data(nodechanges=nodechanges) if keepf: replacements = {} @@ -2239,9 +2242,9 @@ # Replace pull with a decorator to provide --rebase option entry = extensions.wrapcommand(commands.table, b'pull', pullrebase) entry[1].append( - (b'', b'rebase', None, _(b"rebase working directory to branch head")) + (b'', b'rebase', None, _(b'rebase working directory to branch head')) ) - entry[1].append((b't', b'tool', b'', _(b"specify merge tool for rebase"))) + entry[1].append((b't', b'tool', b'', _(b'specify merge tool for rebase'))) cmdutil.summaryhooks.add(b'rebase', summaryhook) statemod.addunfinished( b'rebase', diff --git a/mercurial/error.py b/mercurial/error.py --- a/mercurial/error.py +++ b/mercurial/error.py @@ -4,7 +4,6 @@ # # This software may be used and distributed according to the terms of the # GNU General Public License version 2 or any later version. - """Mercurial exceptions. This allows us to catch exceptions at higher levels without forcing @@ -123,13 +122,15 @@ class HookLoadError(Abort): """raised when loading a hook fails, aborting an operation - Exists to allow more specialized catching.""" + Exists to allow more specialized catching. + """ class HookAbort(Abort): """raised when a validation hook fails, aborting an operation - Exists to allow more specialized catching.""" + Exists to allow more specialized catching. + """ class ConfigError(Abort): @@ -183,7 +184,7 @@ def __init__(self, function, symbols): from .i18n import _ - ParseError.__init__(self, _(b"unknown identifier: %s") % function) + ParseError.__init__(self, _(b'unknown identifier: %s') % function) self.function = function self.symbols = symbols @@ -234,8 +235,7 @@ class UnknownVersion(Abort): - """generic exception for aborting from an encounter with an unknown version - """ + """generic exception for aborting from an encounter with an unknown version""" def __init__(self, msg, hint=None, version=None): self.version = version @@ -342,7 +342,7 @@ if val is None: entries.append(val) else: - entries.append(b"%s=%r" % (par, pycompat.maybebytestr(val))) + entries.append(b'%s=%r' % (par, pycompat.maybebytestr(val))) if entries: msg = b'%s - %s' % (msg, b', '.join(entries)) ValueError.__init__(self, msg) diff --git a/mercurial/shelve.py b/mercurial/shelve.py --- a/mercurial/shelve.py +++ b/mercurial/shelve.py @@ -53,10 +53,7 @@ util, vfs as vfsmod, ) -from .utils import ( - dateutil, - stringutil, -) +from .utils import dateutil, stringutil backupdir = b'shelve-backup' shelvedir = b'shelved' diff --git a/mercurial/state.py b/mercurial/state.py --- a/mercurial/state.py +++ b/mercurial/state.py @@ -4,10 +4,7 @@ # # This software may be used and distributed according to the terms of the # GNU General Public License version 2 or any later version. - -""" -This file contains class to wrap the state for commands and other -related logic. +"""This file contains class to wrap the state for commands and other related logic. All the data related to the command state is stored as dictionary in the object. The class has methods using which the data can be stored to disk in a file under @@ -21,18 +18,11 @@ from .i18n import _ -from . import ( - error, - pycompat, - util, -) +from . import error, pycompat, util from .utils import cborutil if pycompat.TYPE_CHECKING: - from typing import ( - Any, - Dict, - ) + from typing import Any, Dict for t in (Any, Dict): assert t @@ -40,6 +30,7 @@ class cmdstate(object): """a wrapper class to store the state of commands like `rebase`, `graft`, + `histedit`, `shelve` etc. Extensions can also use this to write state files. All the data for the state is stored in the form of key-value pairs in a @@ -54,6 +45,7 @@ def __init__(self, repo, fname): """ repo is the repo object + fname is the file name in which data should be stored in .hg directory """ self._repo = repo @@ -71,7 +63,7 @@ """ if not isinstance(version, int): raise error.ProgrammingError( - b"version of state file should be an integer" + b'version of state file should be an integer' ) with self._repo.vfs(self.fname, b'wb', atomictemp=True) as fp: @@ -81,13 +73,15 @@ def _read(self): """reads the state file and returns a dictionary which contain - data in the same format as it was before storing""" + + data in the same format as it was before storing + """ with self._repo.vfs(self.fname, b'rb') as fp: try: int(fp.readline()) except ValueError: raise error.CorruptedState( - b"unknown version of state file found" + b'unknown version of state file found' ) return cborutil.decodeall(fp.read())[0] @@ -103,6 +97,7 @@ class _statecheck(object): """a utility class that deals with multistep operations like graft, + histedit, bisect, update etc and check whether such commands are in an unfinished conditition or not and return appropriate message and hint. @@ -140,6 +135,7 @@ def statusmsg(self): """returns the hint message corresponding to the command for + hg status --verbose """ if not self._statushint: @@ -156,6 +152,7 @@ def hint(self): """returns the hint message corresponding to an interrupted + operation """ if not self._cmdhint: @@ -177,6 +174,7 @@ def isunfinished(self, repo): """determines whether a multi-step operation is in progress + or not """ if self._opname == b'merge': @@ -197,13 +195,14 @@ reportonly=False, continueflag=False, stopflag=False, - cmdmsg=b"", - cmdhint=b"", - statushint=b"", + cmdmsg=b'', + cmdhint=b'', + statushint=b'', abortfunc=None, continuefunc=None, ): """this registers a new command or operation to unfinishedstates + opname is the name the command or operation fname is the file name in which data should be stored in .hg directory. It is None for merge command. @@ -256,7 +255,7 @@ clearable=True, cmdmsg=_(b'last update was interrupted'), cmdhint=_(b"use 'hg update' to get a consistent checkout"), - statushint=_(b"To continue: hg update ."), + statushint=_(b'To continue: hg update .'), ) addunfinished( b'bisect',