D7684: histedit: use rewriteutil.precheck() instead of reimplementing it

martinvonz (Martin von Zweigbergk) phabricator at mercurial-scm.org
Tue Dec 17 19:36:53 UTC 2019


martinvonz created this revision.
Herald added a reviewer: durin42.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  We have had this nice utility since 490df753894d <https://phab.mercurial-scm.org/rHG490df753894d65f76cc638ad918712a6b24aeeb0> (rewriteutil: add a
  precheck function to check if revs can be rewritten, 2017-11-24). We
  got two callers soon thereafter, in 98f97eb20597 <https://phab.mercurial-scm.org/rHG98f97eb2059767ce1d659cd9c929ca69b21b7450> (rewriteutil: use
  precheck() in uncommit and amend commands, 2017-11-28). It's about
  time we use it in other places.
  
  rewriteutil.precheck() looks unfortunate for i18n (it seems to rely on
  an English verb for the action making sense in other languages), but
  hopefully not bad enough that we should avoid using it.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  hgext/histedit.py
  tests/test-histedit-obsolete.t

CHANGE DETAILS

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 changeset: cb9a9f314b8b
+  abort: cannot edit public changesets
   (see 'hg help phases' for details)
   [255]
 
diff --git a/hgext/histedit.py b/hgext/histedit.py
--- a/hgext/histedit.py
+++ b/hgext/histedit.py
@@ -230,6 +230,7 @@
     pycompat,
     registrar,
     repair,
+    rewriteutil,
     scmutil,
     state as statemod,
     util,
@@ -2306,23 +2307,9 @@
     When keep is false, the specified set can't have children."""
     revs = repo.revs(b'%n::%n', old, new)
     if revs and not keep:
-        if not obsolete.isenabled(
-            repo, obsolete.allowunstableopt
-        ) and repo.revs(b'(%ld::) - (%ld)', revs, revs):
-            raise error.Abort(
-                _(
-                    b'can only histedit a changeset together '
-                    b'with all its descendants'
-                )
-            )
+        rewriteutil.precheck(repo, revs, b'edit')
         if repo.revs(b'(%ld) and merge()', revs):
             raise error.Abort(_(b'cannot edit history that contains merges'))
-        root = repo[revs.first()]  # list is already sorted by repo.revs()
-        if not root.mutable():
-            raise error.Abort(
-                _(b'cannot edit public changeset: %s') % root,
-                hint=_(b"see 'hg help phases' for details"),
-            )
     return pycompat.maplist(repo.changelog.node, revs)
 
 



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


More information about the Mercurial-devel mailing list