comparison mercurial/rewriteutil.py @ 35243:490df753894d

rewriteutil: add a precheck function to check if revs can be rewritten The precheck function is intended to be used before we start rewritting changesets. Differential Revision: https://phab.mercurial-scm.org/D1503
author Pulkit Goyal <7895pulkit@gmail.com>
date Fri, 24 Nov 2017 03:44:50 +0530
parents 27d5c2d2db2b
children 8c6329fa6038
comparison
equal deleted inserted replaced
35242:27d5c2d2db2b 35243:490df753894d
5 # This software may be used and distributed according to the terms of the 5 # This software may be used and distributed according to the terms of the
6 # GNU General Public License version 2 or any later version. 6 # GNU General Public License version 2 or any later version.
7 7
8 from __future__ import absolute_import 8 from __future__ import absolute_import
9 9
10 from .i18n import _
11
10 from . import ( 12 from . import (
13 error,
14 node,
11 obsolete, 15 obsolete,
12 revset, 16 revset,
13 ) 17 )
18
19 def precheck(repo, revs, action='rewrite'):
20 """check if revs can be rewritten
21 action is used to control the error message.
22
23 Make sure this function is called after taking the lock.
24 """
25 if node.nullrev in revs:
26 msg = _("cannot %s null changeset") % (action)
27 hint = _("no changeset checked out")
28 raise error.Abort(msg, hint=hint)
29
30 publicrevs = repo.revs('%ld and public()', revs)
31 if len(repo[None].parents()) > 1:
32 raise error.Abort(_("cannot %s while merging") % action)
33
34 if publicrevs:
35 msg = _("cannot %s public changesets") % (action)
36 hint = _("see 'hg help phases' for details")
37 raise error.Abort(msg, hint=hint)
38
39 newunstable = disallowednewunstable(repo, revs)
40 if newunstable:
41 raise error.Abort(_("cannot %s changeset with children") % action)
14 42
15 def disallowednewunstable(repo, revs): 43 def disallowednewunstable(repo, revs):
16 """Checks whether editing the revs will create new unstable changesets and 44 """Checks whether editing the revs will create new unstable changesets and
17 are we allowed to create them. 45 are we allowed to create them.
18 46