amend: extract into a 'evolve.evocommands' module
We are about to play around with a UI mixing amend and uncommit, we take
advantage of this to split the __init__.py module a bit more.
--- a/hgext3rd/evolve/__init__.py Wed Jul 12 16:09:08 2017 +0200
+++ b/hgext3rd/evolve/__init__.py Tue Jul 11 10:38:01 2017 +0200
@@ -270,7 +270,7 @@
scmutil,
)
-from mercurial.commands import walkopts, commitopts, commitopts2, mergetoolopts
+from mercurial.commands import commitopts, commitopts2, mergetoolopts
from mercurial.i18n import _
from mercurial.node import nullid
@@ -278,6 +278,7 @@
checkheads,
compat,
debugcmd,
+ evocommands,
exthelper,
metadata,
obscache,
@@ -313,7 +314,9 @@
_unpack = struct.unpack
aliases, entry = cmdutil.findcmd('commit', commands.table)
-interactiveopt = [['i', 'interactive', None, _('use interactive mode')]]
+commitopts3 = evocommands.commitopts3
+interactiveopt = evocommands.commitopts3
+
# This extension contains the following code
#
# - Extension Helper code
@@ -330,6 +333,7 @@
eh.merge(obshistory.eh)
eh.merge(templatekw.eh)
eh.merge(compat.eh)
+eh.merge(evocommands.eh)
uisetup = eh.final_uisetup
extsetup = eh.final_extsetup
reposetup = eh.final_reposetup
@@ -400,25 +404,6 @@
### experimental behavior ###
#####################################################################
-commitopts3 = [
- ('D', 'current-date', None,
- _('record the current date as commit date')),
- ('U', 'current-user', None,
- _('record the current user as committer')),
-]
-
-def _resolveoptions(ui, opts):
- """modify commit options dict to handle related options
-
- For now, all it does is figure out the commit date: respect -D unless
- -d was supplied.
- """
- # N.B. this is extremely similar to setupheaderopts() in mq.py
- if not opts.get('date') and opts.get('current_date'):
- opts['date'] = '%d %d' % util.makedate()
- if not opts.get('user') and opts.get('current_user'):
- opts['user'] = ui.username()
-
getrevs = obsolete.getrevs
#####################################################################
@@ -1978,7 +1963,7 @@
with repo.dirstate.parentchange():
repo.dirstate.setparents(divergent.node(), node.nullid)
oldlen = len(repo)
- amend(ui, repo, message='', logfile='')
+ evocommands.amend(ui, repo, message='', logfile='')
if oldlen == len(repo):
new = divergent
# no changes
@@ -2421,45 +2406,6 @@
finally:
lockmod.release(tr, lock, wlock)
-@eh.command(
- 'amend|refresh',
- [('A', 'addremove', None,
- _('mark new/missing files as added/removed before committing')),
- ('e', 'edit', False, _('invoke editor on commit messages')),
- ('', 'close-branch', None,
- _('mark a branch as closed, hiding it from the branch list')),
- ('s', 'secret', None, _('use the secret phase for committing')),
- ] + walkopts + commitopts + commitopts2 + commitopts3 + interactiveopt,
- _('[OPTION]... [FILE]...'))
-def amend(ui, repo, *pats, **opts):
- """combine a changeset with updates and replace it with a new one
-
- Commits a new changeset incorporating both the changes to the given files
- and all the changes from the current parent changeset into the repository.
-
- See :hg:`commit` for details about committing changes.
-
- If you don't specify -m, the parent's message will be reused.
-
- Behind the scenes, Mercurial first commits the update as a regular child
- of the current parent. Then it creates a new commit on the parent's parents
- with the updated contents. Then it changes the working copy parent to this
- new combined changeset. Finally, the old changeset and its update are hidden
- from :hg:`log` (unless you use --hidden with log).
-
- Returns 0 on success, 1 if nothing changed.
- """
- opts = opts.copy()
- edit = opts.pop('edit', False)
- log = opts.get('logfile')
- opts['amend'] = True
- if not (edit or opts['message'] or log):
- opts['message'] = repo['.'].description()
- _resolveoptions(ui, opts)
- _alias, commitcmd = cmdutil.findcmd('commit', commands.table)
- return commitcmd[0](ui, repo, *pats, **opts)
-
-
def _touchedbetween(repo, source, dest, match=None):
touched = set()
for files in repo.status(source, dest, match=match)[:3]:
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/hgext3rd/evolve/evocommands.py Tue Jul 11 10:38:01 2017 +0200
@@ -0,0 +1,94 @@
+# Module dedicated to host new commands added by the evolve extensions
+#
+# Copyright 2017 Octobus <contact@octobus.net>
+#
+# This software may be used and distributed according to the terms of the
+# GNU General Public License version 2 or any later version.
+
+# Status: Stabilization of the API in progress
+#
+# The final set of command should go into core.
+#
+# Some command still live in evolve/__init__.py
+
+from __future__ import absolute_import
+
+from mercurial import (
+ cmdutil,
+ commands,
+ util,
+)
+
+from mercurial.i18n import _
+
+from . import (
+ exthelper,
+)
+
+eh = exthelper.exthelper()
+
+walkopts = commands.walkopts
+commitopts = commands.commitopts
+commitopts2 = commands.commitopts2
+mergetoolopts = commands.mergetoolopts
+
+# option added by evolve
+
+def _resolveoptions(ui, opts):
+ """modify commit options dict to handle related options
+
+ For now, all it does is figure out the commit date: respect -D unless
+ -d was supplied.
+ """
+ # N.B. this is extremely similar to setupheaderopts() in mq.py
+ if not opts.get('date') and opts.get('current_date'):
+ opts['date'] = '%d %d' % util.makedate()
+ if not opts.get('user') and opts.get('current_user'):
+ opts['user'] = ui.username()
+
+commitopts3 = [
+ ('D', 'current-date', None,
+ _('record the current date as commit date')),
+ ('U', 'current-user', None,
+ _('record the current user as committer')),
+]
+
+interactiveopt = [['i', 'interactive', None, _('use interactive mode')]]
+
+@eh.command(
+ 'amend|refresh',
+ [('A', 'addremove', None,
+ _('mark new/missing files as added/removed before committing')),
+ ('e', 'edit', False, _('invoke editor on commit messages')),
+ ('', 'close-branch', None,
+ _('mark a branch as closed, hiding it from the branch list')),
+ ('s', 'secret', None, _('use the secret phase for committing')),
+ ] + walkopts + commitopts + commitopts2 + commitopts3 + interactiveopt,
+ _('[OPTION]... [FILE]...'))
+def amend(ui, repo, *pats, **opts):
+ """combine a changeset with updates and replace it with a new one
+
+ Commits a new changeset incorporating both the changes to the given files
+ and all the changes from the current parent changeset into the repository.
+
+ See :hg:`commit` for details about committing changes.
+
+ If you don't specify -m, the parent's message will be reused.
+
+ Behind the scenes, Mercurial first commits the update as a regular child
+ of the current parent. Then it creates a new commit on the parent's parents
+ with the updated contents. Then it changes the working copy parent to this
+ new combined changeset. Finally, the old changeset and its update are hidden
+ from :hg:`log` (unless you use --hidden with log).
+
+ Returns 0 on success, 1 if nothing changed.
+ """
+ opts = opts.copy()
+ edit = opts.pop('edit', False)
+ log = opts.get('logfile')
+ opts['amend'] = True
+ if not (edit or opts['message'] or log):
+ opts['message'] = repo['.'].description()
+ _resolveoptions(ui, opts)
+ _alias, commitcmd = cmdutil.findcmd('commit', commands.table)
+ return commitcmd[0](ui, repo, *pats, **opts)