# HG changeset patch # User Martin von Zweigbergk # Date 1576608831 28800 # Node ID bde97bee321f656ebee8ff2c2fe0590fe1cbdeca # Parent 9fb9f3a5cad70d51547a06b2699f93a1e9f3add9 histedit: use rewriteutil.precheck() instead of reimplementing it We have had this nice utility since 490df753894d (rewriteutil: add a precheck function to check if revs can be rewritten, 2017-11-24). We got two callers soon thereafter, in 98f97eb20597 (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. Differential Revision: https://phab.mercurial-scm.org/D7684 diff -r 9fb9f3a5cad7 -r bde97bee321f hgext/histedit.py --- a/hgext/histedit.py Thu Dec 12 23:25:16 2019 -0800 +++ b/hgext/histedit.py Tue Dec 17 10:53:51 2019 -0800 @@ -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) diff -r 9fb9f3a5cad7 -r bde97bee321f tests/test-histedit-obsolete.t --- a/tests/test-histedit-obsolete.t Thu Dec 12 23:25:16 2019 -0800 +++ b/tests/test-histedit-obsolete.t Tue Dec 17 10:53:51 2019 -0800 @@ -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]