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

login
register
mail settings
Submitter timeless@mozdev.org
Date Feb. 12, 2016, 8:54 p.m.
Message ID <f66f87ca38782cb9ff66.1455310449@waste.org>
Download mbox | patch
Permalink /patch/13149/
State Accepted
Delegated to: Pierre-Yves David
Headers show

Comments

timeless@mozdev.org - Feb. 12, 2016, 8:54 p.m.
# HG changeset patch
# User timeless <timeless@mozdev.org>
# Date 1454557448 0
#      Thu Feb 04 03:44:08 2016 +0000
# Node ID f66f87ca38782cb9ff6619309f5aa1687be0b5df
# 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. 14, 2016, 4:33 p.m.
On 02/12/2016 08:54 PM, timeless wrote:
> # HG changeset patch
> # User timeless <timeless@mozdev.org>
> # Date 1454557448 0
> #      Thu Feb 04 03:44:08 2016 +0000
> # Node ID f66f87ca38782cb9ff6619309f5aa1687be0b5df
> # Parent  a036e1ae1fbe88ab99cb861ebfc2e4da7a3912ca
> cmdutil: provide a way to report how to continue

Ive made significant code update to this first patch and pushed the 
result to the clowncopter.

Thanks a lot, this is a good usability improvement. Would you consider 
doing the same for --abort?
timeless - Feb. 15, 2016, 5:32 a.m.
Pierre-Yves David wrote:
> Thanks a lot, this is a good usability improvement.
> Would you consider doing the same for --abort?

Yes, although, probably not right away. I need to review the landscape
and figure out which things are worth focusing on.
otoh, since doing that wouldn't be blocked on it, I might do this
sooner rather than later.

Patch

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -3347,13 +3347,53 @@ 
      _('hg graft --continue')),
     ]
 
-def checkafterresolved(repo):
-    contmsg = _("continue: %s\n")
+def howtocontinue(repo):
+    '''Check for an unfinished operation and return the command to finish
+    it.
+
+    afterresolvedstates tupples define a .hg/{file} and the corresponding
+    command needed to finish it.
+
+    Returns the continue command, and the default notification function:
+        repo.ui.warn for states listed in afterresolvedstates,
+        repo.ui.note otherwise.
+    '''
+    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):
+    '''Inform the user about the next action after completing hg resolve
+
+    If there's a matching afterresolvedstates, howtocontinue will yield
+    repo.ui.warn as the reporter.
+
+    Otherwise, it will yield repo.ui.note.
+    '''
+    msg, reporter = howtocontinue(repo)
+    if msg is not None and reporter is not None:
+        reporter("%s\n" % msg)
+
+def wrongtooltocontinue(repo, task):
+    '''Raise an abort suggesting how to properly continue if there is an
+    active task.
+
+    Uses howtocontinue() to find the active task.
+
+    If there's no task (repo.ui.note for 'hg commit'), it does not offer
+    a hint.
+    '''
+    after = howtocontinue(repo)
+    hint = None
+    if after and after[1] == repo.ui.warn:
+        hint = after[0]
+    raise error.Abort(_('no %s in progress') % task, hint=hint)
 
 class dirstateguard(object):
     '''Restore dirstate at unexpected failure.