# HG changeset patch # User Pierre-Yves David # Date 1500780743 -7200 # Node ID 610581a2fb74b3dbb9e4089f7b0e0f6157f48b75 # Parent 7450e360c88c29e9f43119671618b958b502ff40 commands: move split to the 'evocommands' module diff -r 7450e360c88c -r 610581a2fb74 hgext3rd/evolve/__init__.py --- a/hgext3rd/evolve/__init__.py Sun Jul 23 05:16:24 2017 +0200 +++ b/hgext3rd/evolve/__init__.py Sun Jul 23 05:32:23 2017 +0200 @@ -270,7 +270,7 @@ scmutil, ) -from mercurial.commands import commitopts, commitopts2, mergetoolopts +from mercurial.commands import mergetoolopts from mercurial.i18n import _ from mercurial.node import nullid @@ -2384,96 +2384,6 @@ finally: lockmod.release(tr, lock, wlock) -def presplitupdate(repo, ui, prev, ctx): - """prepare the working directory for a split (for topic hooking) - """ - hg.update(repo, prev) - commands.revert(ui, repo, rev=ctx.rev(), all=True) - -@eh.command( - '^split', - [('r', 'rev', [], _("revision to split")), - ] + commitopts + commitopts2, - _('hg split [OPTION]... [-r] REV')) -def cmdsplit(ui, repo, *revs, **opts): - """split a changeset into smaller changesets - - By default, split the current revision by prompting for all its hunks to be - redistributed into new changesets. - - Use --rev to split a given changeset instead. - """ - tr = wlock = lock = None - newcommits = [] - - revarg = (list(revs) + opts.get('rev')) or ['.'] - if len(revarg) != 1: - msg = _("more than one revset is given") - hnt = _("use either `hg split ` or `hg split --rev `, not both") - raise error.Abort(msg, hint=hnt) - - rev = scmutil.revsingle(repo, revarg[0]) - try: - wlock = repo.wlock() - lock = repo.lock() - cmdutil.bailifchanged(repo) - tr = repo.transaction('split') - ctx = repo[rev] - r = ctx.rev() - disallowunstable = not obsolete.isenabled(repo, - obsolete.allowunstableopt) - if disallowunstable: - # XXX We should check head revs - if repo.revs("(%d::) - %d", rev, rev): - raise error.Abort(_("cannot split commit: %s not a head") % ctx) - - if len(ctx.parents()) > 1: - raise error.Abort(_("cannot split merge commits")) - prev = ctx.p1() - bmupdate = _bookmarksupdater(repo, ctx.node(), tr) - bookactive = repo._activebookmark - if bookactive is not None: - repo.ui.status(_("(leaving bookmark %s)\n") % repo._activebookmark) - bookmarksmod.deactivate(repo) - - # Prepare the working directory - presplitupdate(repo, ui, prev, ctx) - - def haschanges(): - modified, added, removed, deleted = repo.status()[:4] - return modified or added or removed or deleted - msg = ("HG: This is the original pre-split commit message. " - "Edit it as appropriate.\n\n") - msg += ctx.description() - opts['message'] = msg - opts['edit'] = True - opts['user'] = ctx.user() - while haschanges(): - pats = () - cmdutil.dorecord(ui, repo, commands.commit, 'commit', False, - cmdutil.recordfilter, *pats, **opts) - # TODO: Does no seem like the best way to do this - # We should make dorecord return the newly created commit - newcommits.append(repo['.']) - if haschanges(): - if ui.prompt('Done splitting? [yN]', default='n') == 'y': - commands.commit(ui, repo, **opts) - newcommits.append(repo['.']) - break - else: - ui.status(_("no more change to split\n")) - - if newcommits: - tip = repo[newcommits[-1]] - bmupdate(tip.node()) - if bookactive is not None: - bookmarksmod.activate(repo, bookactive) - obsolete.createmarkers(repo, [(repo[r], newcommits)]) - tr.close() - finally: - lockmod.release(tr, lock, wlock) - - @eh.wrapcommand('strip', extension='strip', opts=[ ('', 'bundle', None, _("delete the commit entirely and move it to a " "backup bundle")), diff -r 7450e360c88c -r 610581a2fb74 hgext3rd/evolve/evocommands.py --- a/hgext3rd/evolve/evocommands.py Sun Jul 23 05:16:24 2017 +0200 +++ b/hgext3rd/evolve/evocommands.py Sun Jul 23 05:32:23 2017 +0200 @@ -14,6 +14,7 @@ from __future__ import absolute_import from mercurial import ( + bookmarks as bookmarksmod, cmdutil, commands, context, @@ -543,3 +544,86 @@ hg.update(repo, newp1) finally: lockmod.release(lock, wlock) + +@eh.command( + '^split', + [('r', 'rev', [], _("revision to split")), + ] + commitopts + commitopts2, + _('hg split [OPTION]... [-r] REV')) +def cmdsplit(ui, repo, *revs, **opts): + """split a changeset into smaller changesets + + By default, split the current revision by prompting for all its hunks to be + redistributed into new changesets. + + Use --rev to split a given changeset instead. + """ + tr = wlock = lock = None + newcommits = [] + + revarg = (list(revs) + opts.get('rev')) or ['.'] + if len(revarg) != 1: + msg = _("more than one revset is given") + hnt = _("use either `hg split ` or `hg split --rev `, not both") + raise error.Abort(msg, hint=hnt) + + rev = scmutil.revsingle(repo, revarg[0]) + try: + wlock = repo.wlock() + lock = repo.lock() + cmdutil.bailifchanged(repo) + tr = repo.transaction('split') + ctx = repo[rev] + r = ctx.rev() + disallowunstable = not obsolete.isenabled(repo, + obsolete.allowunstableopt) + if disallowunstable: + # XXX We should check head revs + if repo.revs("(%d::) - %d", rev, rev): + raise error.Abort(_("cannot split commit: %s not a head") % ctx) + + if len(ctx.parents()) > 1: + raise error.Abort(_("cannot split merge commits")) + prev = ctx.p1() + bmupdate = rewriteutil.bookmarksupdater(repo, ctx.node(), tr) + bookactive = repo._activebookmark + if bookactive is not None: + repo.ui.status(_("(leaving bookmark %s)\n") % repo._activebookmark) + bookmarksmod.deactivate(repo) + + # Prepare the working directory + rewriteutil.presplitupdate(repo, ui, prev, ctx) + + def haschanges(): + modified, added, removed, deleted = repo.status()[:4] + return modified or added or removed or deleted + msg = ("HG: This is the original pre-split commit message. " + "Edit it as appropriate.\n\n") + msg += ctx.description() + opts['message'] = msg + opts['edit'] = True + opts['user'] = ctx.user() + while haschanges(): + pats = () + cmdutil.dorecord(ui, repo, commands.commit, 'commit', False, + cmdutil.recordfilter, *pats, **opts) + # TODO: Does no seem like the best way to do this + # We should make dorecord return the newly created commit + newcommits.append(repo['.']) + if haschanges(): + if ui.prompt('Done splitting? [yN]', default='n') == 'y': + commands.commit(ui, repo, **opts) + newcommits.append(repo['.']) + break + else: + ui.status(_("no more change to split\n")) + + if newcommits: + tip = repo[newcommits[-1]] + bmupdate(tip.node()) + if bookactive is not None: + bookmarksmod.activate(repo, bookactive) + obsolete.createmarkers(repo, [(repo[r], newcommits)]) + tr.close() + finally: + lockmod.release(tr, lock, wlock) diff -r 7450e360c88c -r 610581a2fb74 hgext3rd/evolve/rewriteutil.py --- a/hgext3rd/evolve/rewriteutil.py Sun Jul 23 05:16:24 2017 +0200 +++ b/hgext3rd/evolve/rewriteutil.py Sun Jul 23 05:32:23 2017 +0200 @@ -13,9 +13,11 @@ from mercurial import ( cmdutil, + commands, context, copies, error, + hg, lock as lockmod, obsolete, phases, @@ -69,6 +71,12 @@ raise error.Abort(msg, hint=hint) return root, head +def presplitupdate(repo, ui, prev, ctx): + """prepare the working directory for a split (for topic hooking) + """ + hg.update(repo, prev) + commands.revert(ui, repo, rev=ctx.rev(), all=True) + def rewrite(repo, old, updates, head, newbases, commitopts): """Return (nodeid, created) where nodeid is the identifier of the changeset generated by the rewrite process, and created is True if diff -r 7450e360c88c -r 610581a2fb74 hgext3rd/topic/__init__.py --- a/hgext3rd/topic/__init__.py Sun Jul 23 05:16:24 2017 +0200 +++ b/hgext3rd/topic/__init__.py Sun Jul 23 05:32:23 2017 +0200 @@ -206,7 +206,8 @@ try: evolve = extensions.find('evolve') - extensions.wrapfunction(evolve, "presplitupdate", presplitupdatetopic) + extensions.wrapfunction(evolve.rewriteutil, "presplitupdate", + presplitupdatetopic) except (KeyError, AttributeError): pass