Patchwork [1,of,5,v2] cmdutil: provide a way to report how to continue

login
register
mail settings
Submitter timeless@mozdev.org
Date Feb. 7, 2016, 7:57 a.m.
Message ID <4a488f74e91b0347b208.1454831856@waste.org>
Download mbox | patch
Permalink /patch/13028/
State Superseded
Commit ed4d06f180b8453a4455d9cef23e1fc023acdc05
Headers show

Comments

timeless@mozdev.org - Feb. 7, 2016, 7:57 a.m.
# HG changeset patch
# User timeless <timeless@mozdev.org>
# Date 1454557448 0
#      Thu Feb 04 03:44:08 2016 +0000
# Node ID 4a488f74e91b0347b208e0edb62f4b4d111474ba
# Parent  a036e1ae1fbe88ab99cb861ebfc2e4da7a3912ca
cmdutil: provide a way to report how to continue

checkafterresolved allows Mercurial to suggest what command to
use next. If users try to continue the wrong command, there
wasn't a good way for the command to suggest what to do next.

Split checcmdutil into howtocontinue and checkafterresolved.
Introduce wrongtooltocontinue which handles raising an Abort with
the hint from howtocontinue.
Pierre-Yves David - Feb. 12, 2016, 11:31 a.m.
On 02/07/2016 07:57 AM, timeless wrote:
> # HG changeset patch
> # User timeless <timeless@mozdev.org>
> # Date 1454557448 0
> #      Thu Feb 04 03:44:08 2016 +0000
> # Node ID 4a488f74e91b0347b208e0edb62f4b4d111474ba
> # Parent  a036e1ae1fbe88ab99cb861ebfc2e4da7a3912ca
> cmdutil: provide a way to report how to continue
>
> checkafterresolved allows Mercurial to suggest what command to
> use next. If users try to continue the wrong command, there
> wasn't a good way for the command to suggest what to do next.
>
> Split checcmdutil into howtocontinue and checkafterresolved.
> Introduce wrongtooltocontinue which handles raising an Abort with
> the hint from howtocontinue.

I really really like the feature introduced in this series. I've a 
couple of small feedback that made not take it right away.

> diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
> --- a/mercurial/cmdutil.py
> +++ b/mercurial/cmdutil.py
> @@ -3347,13 +3347,28 @@
>        _('hg graft --continue')),
>       ]
>
> -def checkafterresolved(repo):
> -    contmsg = _("continue: %s\n")
> +def howtocontinue(repo):

Can I get you to add docstrings formally describing the goal and 
contract of theses new functions? This will help people to add support 
the right way when new command arrive.

Patch

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -3347,13 +3347,28 @@ 
      _('hg graft --continue')),
     ]
 
-def checkafterresolved(repo):
-    contmsg = _("continue: %s\n")
+def howtocontinue(repo):
+    contmsg = _("continue: %s")
     for f, msg in afterresolvedstates:
         if repo.vfs.exists(f):
-            repo.ui.warn(contmsg % msg)
-            return
-    repo.ui.note(contmsg % _("hg commit"))
+            return contmsg % msg, repo.ui.warn
+    workingctx = repo[None]
+    if (any(repo.status())
+     or any(workingctx.sub(s).dirty() for s in workingctx.substate)):
+        return contmsg % _("hg commit"), repo.ui.note
+    return None, None
+
+def checkafterresolved(repo):
+    msg, reporter = howtocontinue(repo)
+    if msg is not None and reporter is not None:
+        reporter("%s\n" % msg)
+
+def wrongtooltocontinue(repo, msg):
+    after = howtocontinue(repo)
+    hint = None
+    if after:
+        hint = after[0]
+    raise error.Abort(msg, hint=hint)
 
 class dirstateguard(object):
     '''Restore dirstate at unexpected failure.