changeset 2780:58e4b51ee902

prefetc: point at the offending changeset when aborting We do our best to display comptact but usable information.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Mon, 24 Jul 2017 03:04:20 +0200
parents f51efb2bb8c9
children 78b0c6053139
files hgext3rd/evolve/rewriteutil.py tests/test-fold.t tests/test-metaedit.t
diffstat 3 files changed, 30 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/hgext3rd/evolve/rewriteutil.py	Mon Jul 24 02:06:14 2017 +0200
+++ b/hgext3rd/evolve/rewriteutil.py	Mon Jul 24 03:04:20 2017 +0200
@@ -19,10 +19,12 @@
     error,
     hg,
     lock as lockmod,
+    node,
     obsolete,
     phases,
     repair,
     revset,
+    util,
 )
 
 from mercurial.i18n import _
@@ -31,13 +33,37 @@
     compat,
 )
 
+def _formatrevs(repo, revs, maxrevs=4):
+    """return a string summarising revision in a descent size
+
+    If there is few enough revision, we list them otherwise we display a
+    summary in the form:
+
+        1ea73414a91b and 5 others
+    """
+    tonode = repo.changelog.node
+    numrevs = len(revs)
+    if numrevs < maxrevs:
+        shorts = [node.short(tonode(r)) for r in revs]
+        summary = ', '.join(shorts)
+    else:
+        if util.safehasattr(revs, 'first'):
+            first = revs.first()
+        else:
+            first = revs[0]
+        summary = _('%s and %d others')
+        summary %= (node.short(tonode(first)), numrevs - 1)
+    return summary
+
 def precheck(repo, revs, action='rewrite'):
     """check if <revs> can be rewritten
 
     <action> can be used to control the commit message.
     """
-    if repo.revs('%ld and public()', revs):
-        msg = _("cannot %s public changesets") % action
+    publicrevs = repo.revs('%ld and public()', revs)
+    if publicrevs:
+        summary = _formatrevs(repo, publicrevs)
+        msg = _("cannot %s public changesets: %s") % (action, summary)
         hint = _("see 'hg help phases' for details")
         raise error.Abort(msg, hint=hint)
 
--- a/tests/test-fold.t	Mon Jul 24 02:06:14 2017 +0200
+++ b/tests/test-fold.t	Mon Jul 24 03:04:20 2017 +0200
@@ -73,7 +73,7 @@
   [255]
   $ hg phase --public 0
   $ hg fold --from -r 0
-  abort: cannot fold public changesets
+  abort: cannot fold public changesets: 1ea73414a91b
   (see 'hg help phases' for details)
   [255]
 
--- a/tests/test-metaedit.t	Mon Jul 24 02:06:14 2017 +0200
+++ b/tests/test-metaedit.t	Mon Jul 24 03:04:20 2017 +0200
@@ -103,7 +103,7 @@
   abort: revisions must be specified with --fold
   [255]
   $ hg metaedit -r 0 --fold
-  abort: cannot fold public changesets
+  abort: cannot fold public changesets: ea207398892e
   (see 'hg help phases' for details)
   [255]
   $ hg metaedit 'desc(C) + desc(F)' --fold