Show More
@@ -1,55 +1,72 b'' | |||||
1 | # rewriteutil.py - utility functions for rewriting changesets |
|
1 | # rewriteutil.py - utility functions for rewriting changesets | |
2 | # |
|
2 | # | |
3 | # Copyright 2017 Octobus <contact@octobus.net> |
|
3 | # Copyright 2017 Octobus <contact@octobus.net> | |
4 | # |
|
4 | # | |
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 _ |
|
10 | from .i18n import _ | |
11 |
|
11 | |||
12 | from . import ( |
|
12 | from . import ( | |
13 | error, |
|
13 | error, | |
14 | node, |
|
14 | node, | |
15 | obsolete, |
|
15 | obsolete, | |
16 | revset, |
|
16 | revset, | |
17 | ) |
|
17 | ) | |
18 |
|
18 | |||
19 |
|
19 | |||
20 | def precheck(repo, revs, action=b'rewrite'): |
|
20 | def precheck(repo, revs, action=b'rewrite'): | |
21 | """check if revs can be rewritten |
|
21 | """check if revs can be rewritten | |
22 | action is used to control the error message. |
|
22 | action is used to control the error message. | |
23 |
|
23 | |||
24 | Make sure this function is called after taking the lock. |
|
24 | Make sure this function is called after taking the lock. | |
25 | """ |
|
25 | """ | |
26 | if node.nullrev in revs: |
|
26 | if node.nullrev in revs: | |
27 | msg = _(b"cannot %s null changeset") % action |
|
27 | msg = _(b"cannot %s null changeset") % action | |
28 | hint = _(b"no changeset checked out") |
|
28 | hint = _(b"no changeset checked out") | |
29 | raise error.Abort(msg, hint=hint) |
|
29 | raise error.Abort(msg, hint=hint) | |
30 |
|
30 | |||
31 | if len(repo[None].parents()) > 1: |
|
31 | if len(repo[None].parents()) > 1: | |
32 | raise error.Abort(_(b"cannot %s while merging") % action) |
|
32 | raise error.Abort(_(b"cannot %s while merging") % action) | |
33 |
|
33 | |||
34 | publicrevs = repo.revs(b'%ld and public()', revs) |
|
34 | publicrevs = repo.revs(b'%ld and public()', revs) | |
35 | if publicrevs: |
|
35 | if publicrevs: | |
36 | msg = _(b"cannot %s public changesets") % action |
|
36 | msg = _(b"cannot %s public changesets") % action | |
37 | hint = _(b"see 'hg help phases' for details") |
|
37 | hint = _(b"see 'hg help phases' for details") | |
38 | raise error.Abort(msg, hint=hint) |
|
38 | raise error.Abort(msg, hint=hint) | |
39 |
|
39 | |||
40 | newunstable = disallowednewunstable(repo, revs) |
|
40 | newunstable = disallowednewunstable(repo, revs) | |
41 | if newunstable: |
|
41 | if newunstable: | |
42 | raise error.Abort(_(b"cannot %s changeset with children") % action) |
|
42 | raise error.Abort(_(b"cannot %s changeset with children") % action) | |
43 |
|
43 | |||
44 |
|
44 | |||
45 | def disallowednewunstable(repo, revs): |
|
45 | def disallowednewunstable(repo, revs): | |
46 | """Checks whether editing the revs will create new unstable changesets and |
|
46 | """Checks whether editing the revs will create new unstable changesets and | |
47 | are we allowed to create them. |
|
47 | are we allowed to create them. | |
48 |
|
48 | |||
49 | To allow new unstable changesets, set the config: |
|
49 | To allow new unstable changesets, set the config: | |
50 | `experimental.evolution.allowunstable=True` |
|
50 | `experimental.evolution.allowunstable=True` | |
51 | """ |
|
51 | """ | |
52 | allowunstable = obsolete.isenabled(repo, obsolete.allowunstableopt) |
|
52 | allowunstable = obsolete.isenabled(repo, obsolete.allowunstableopt) | |
53 | if allowunstable: |
|
53 | if allowunstable: | |
54 | return revset.baseset() |
|
54 | return revset.baseset() | |
55 | return repo.revs(b"(%ld::) - %ld", revs, revs) |
|
55 | return repo.revs(b"(%ld::) - %ld", revs, revs) | |
|
56 | ||||
|
57 | ||||
|
58 | def skip_empty_successor(ui, command): | |||
|
59 | empty_successor = ui.config(b'rewrite', b'empty-successor') | |||
|
60 | if empty_successor == b'skip': | |||
|
61 | return True | |||
|
62 | elif empty_successor == b'keep': | |||
|
63 | return False | |||
|
64 | else: | |||
|
65 | raise error.ConfigError( | |||
|
66 | _( | |||
|
67 | b"%s doesn't know how to handle config " | |||
|
68 | b"rewrite.empty-successor=%s (only 'skip' and 'keep' are " | |||
|
69 | b"supported)" | |||
|
70 | ) | |||
|
71 | % (command, empty_successor) | |||
|
72 | ) |
General Comments 0
You need to be logged in to leave comments.
Login now