Patchwork D10670: rewriteutil: give examples of public changesets that can't be rewritten

login
register
mail settings
Submitter phabricator
Date May 4, 2021, 5:59 p.m.
Message ID <differential-rev-PHID-DREV-f3enkgaj5h43zmbdvj2l-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/48990/
State Superseded
Headers show

Comments

phabricator - May 4, 2021, 5:59 p.m.
martinvonz created this revision.
Herald added a reviewer: durin42.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  This patch copies the feature from the evolve extension.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D10670

AFFECTED FILES
  mercurial/rewriteutil.py
  tests/test-amend.t
  tests/test-branch-change.t
  tests/test-commit-amend.t
  tests/test-fix.t
  tests/test-histedit-obsolete.t
  tests/test-rebase-scenario-global.t
  tests/test-split.t
  tests/test-unamend.t

CHANGE DETAILS




To: martinvonz, durin42, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/tests/test-unamend.t b/tests/test-unamend.t
--- a/tests/test-unamend.t
+++ b/tests/test-unamend.t
@@ -298,7 +298,7 @@ 
   $ hg phase -r . -p
   1 new phase-divergent changesets
   $ hg unamend
-  abort: cannot unamend public changesets
+  abort: cannot unamend public changesets: 03ddd6fc5af1
   (see 'hg help phases' for details)
   [10]
 
diff --git a/tests/test-split.t b/tests/test-split.t
--- a/tests/test-split.t
+++ b/tests/test-split.t
@@ -77,7 +77,7 @@ 
 
   $ hg phase --public -r 'all()'
   $ hg split .
-  abort: cannot split public changesets
+  abort: cannot split public changesets: 1df0d5c5a3ab
   (see 'hg help phases' for details)
   [10]
 
diff --git a/tests/test-rebase-scenario-global.t b/tests/test-rebase-scenario-global.t
--- a/tests/test-rebase-scenario-global.t
+++ b/tests/test-rebase-scenario-global.t
@@ -328,11 +328,11 @@ 
   nothing to rebase
   [1]
   $ hg rebase -d 5 -b 6
-  abort: cannot rebase public changesets
+  abort: cannot rebase public changesets: e1c4361dd923
   (see 'hg help phases' for details)
   [10]
   $ hg rebase -d 5 -r '1 + (6::)'
-  abort: cannot rebase public changesets
+  abort: cannot rebase public changesets: e1c4361dd923
   (see 'hg help phases' for details)
   [10]
 
diff --git a/tests/test-histedit-obsolete.t b/tests/test-histedit-obsolete.t
--- a/tests/test-histedit-obsolete.t
+++ b/tests/test-histedit-obsolete.t
@@ -307,7 +307,7 @@ 
   o  0:cb9a9f314b8b (public) a
   
   $ hg histedit -r '.~2'
-  abort: cannot edit public changesets
+  abort: cannot edit public changesets: cb9a9f314b8b, 40db8afa467b
   (see 'hg help phases' for details)
   [10]
 
diff --git a/tests/test-fix.t b/tests/test-fix.t
--- a/tests/test-fix.t
+++ b/tests/test-fix.t
@@ -264,11 +264,11 @@ 
   $ hg commit -Aqm "hello"
   $ hg phase -r 0 --public
   $ hg fix -r 0
-  abort: cannot fix public changesets
+  abort: cannot fix public changesets: 6470986d2e7b
   (see 'hg help phases' for details)
   [10]
   $ hg fix -r 0 --working-dir
-  abort: cannot fix public changesets
+  abort: cannot fix public changesets: 6470986d2e7b
   (see 'hg help phases' for details)
   [10]
   $ hg cat -r tip hello.whole
diff --git a/tests/test-commit-amend.t b/tests/test-commit-amend.t
--- a/tests/test-commit-amend.t
+++ b/tests/test-commit-amend.t
@@ -10,7 +10,7 @@ 
 
   $ hg phase -r . -p
   $ hg ci --amend
-  abort: cannot amend public changesets
+  abort: cannot amend public changesets: ad120869acf0
   (see 'hg help phases' for details)
   [10]
   $ hg phase -r . -f -d
diff --git a/tests/test-branch-change.t b/tests/test-branch-change.t
--- a/tests/test-branch-change.t
+++ b/tests/test-branch-change.t
@@ -369,7 +369,7 @@ 
 
   $ hg phase -r . -p
   $ hg branch -r . def
-  abort: cannot change branch of public changesets
+  abort: cannot change branch of public changesets: d1c2addda4a2
   (see 'hg help phases' for details)
   [10]
 
diff --git a/tests/test-amend.t b/tests/test-amend.t
--- a/tests/test-amend.t
+++ b/tests/test-amend.t
@@ -250,7 +250,7 @@ 
   $ hg phase -r A --public
   $ hg update -C -q A
   $ hg amend -m AMEND
-  abort: cannot amend public changesets
+  abort: cannot amend public changesets: 426bada5c675
   (see 'hg help phases' for details)
   [10]
 
diff --git a/mercurial/rewriteutil.py b/mercurial/rewriteutil.py
--- a/mercurial/rewriteutil.py
+++ b/mercurial/rewriteutil.py
@@ -17,6 +17,7 @@ 
 
 from . import (
     error,
+    node,
     obsolete,
     obsutil,
     revset,
@@ -28,6 +29,26 @@ 
 NODE_RE = re.compile(br'\b[0-9a-f]{6,64}\b')
 
 
+def _formatrevs(repo, revs, maxrevs=4):
+    """returns a string summarizing revisions in a decent size
+
+    If there are few enough revisions, we list them all. Otherwise we display a
+    summary of 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 = b', '.join(shorts)
+    else:
+        first = revs.first()
+        summary = _(b'%s and %d others')
+        summary %= (node.short(tonode(first)), numrevs - 1)
+    return summary
+
+
 def precheck(repo, revs, action=b'rewrite'):
     """check if revs can be rewritten
     action is used to control the error message.
@@ -50,7 +71,8 @@ 
 
     publicrevs = repo.revs(b'%ld and public()', revs)
     if publicrevs:
-        msg = _(b"cannot %s public changesets") % action
+        summary = _formatrevs(repo, publicrevs)
+        msg = _(b"cannot %s public changesets: %s") % (action, summary)
         hint = _(b"see 'hg help phases' for details")
         raise error.InputError(msg, hint=hint)