author | Pierre-Yves David <pierre-yves.david@octobus.net> |
Sun, 17 Jun 2018 03:10:19 +0200 | |
changeset 3871 | 2e32a1ef0c60 |
parent 3869 | bbfbaf46f7b0 |
child 3872 | bbc3cfdfe42b |
permissions | -rw-r--r-- |
3858
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
1 |
from __future__ import absolute_import |
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
2 |
|
3861
bbe635dfd75c
rewind: obsolete latest successors unless instructed otherwise
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3859
diff
changeset
|
3 |
import collections |
3858
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
4 |
import hashlib |
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
5 |
|
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
6 |
from mercurial import ( |
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
7 |
error, |
3863
c31be22d1d90
rewind: update the working copy if it gets obsoleted
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3862
diff
changeset
|
8 |
hg, |
3858
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
9 |
obsolete, |
3861
bbe635dfd75c
rewind: obsolete latest successors unless instructed otherwise
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3859
diff
changeset
|
10 |
obsutil, |
3858
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
11 |
scmutil, |
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
12 |
) |
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
13 |
|
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
14 |
from mercurial.i18n import _ |
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
15 |
|
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
16 |
from . import ( |
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
17 |
exthelper, |
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
18 |
rewriteutil, |
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
19 |
compat, |
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
20 |
) |
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
21 |
|
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
22 |
eh = exthelper.exthelper() |
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
23 |
|
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
24 |
# flag in obsolescence markers to link to identical version |
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
25 |
identicalflag = 4 |
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
26 |
|
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
27 |
@eh.command( |
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
28 |
'^rewind', |
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
29 |
[('', 'to', [], _("rewind to these revision")), |
3861
bbe635dfd75c
rewind: obsolete latest successors unless instructed otherwise
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3859
diff
changeset
|
30 |
('', 'as-divergence', None, _("preserve current latest successors")), |
3868
1742254d1190
rewind: automatically rewind entire stack
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3866
diff
changeset
|
31 |
('', 'exact', None, _("only rewind explicitly selected revisions")), |
3871
2e32a1ef0c60
rewing: add the ability to rewind "from" revisions
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3869
diff
changeset
|
32 |
('', 'from', [], _("rewind these revisions to their predecessors")), |
3858
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
33 |
], |
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
34 |
_('')) |
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
35 |
def rewind(ui, repo, **opts): |
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
36 |
"""rewind stacks of changeset to a previous content |
3861
bbe635dfd75c
rewind: obsolete latest successors unless instructed otherwise
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3859
diff
changeset
|
37 |
|
bbe635dfd75c
rewind: obsolete latest successors unless instructed otherwise
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3859
diff
changeset
|
38 |
This command can be used to restore stacks of changesets to an obsolete |
bbe635dfd75c
rewind: obsolete latest successors unless instructed otherwise
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3859
diff
changeset
|
39 |
state, creating identical identical copies. |
bbe635dfd75c
rewind: obsolete latest successors unless instructed otherwise
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3859
diff
changeset
|
40 |
|
3871
2e32a1ef0c60
rewing: add the ability to rewind "from" revisions
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3869
diff
changeset
|
41 |
There are two mains way to select the rewind target. Rewinding "from" |
2e32a1ef0c60
rewing: add the ability to rewind "from" revisions
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3869
diff
changeset
|
42 |
changesets will restore the direct precursors of theses changesets (and |
2e32a1ef0c60
rewing: add the ability to rewind "from" revisions
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3869
diff
changeset
|
43 |
obsolete the changeset you rewind from). Rewinding "to" will restore the |
2e32a1ef0c60
rewing: add the ability to rewind "from" revisions
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3869
diff
changeset
|
44 |
changeset you have selected (and obsolete their latest successors). |
2e32a1ef0c60
rewing: add the ability to rewind "from" revisions
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3869
diff
changeset
|
45 |
|
3868
1742254d1190
rewind: automatically rewind entire stack
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3866
diff
changeset
|
46 |
When we rewind to an obsolete version, we also rewind to all its obsolete |
1742254d1190
rewind: automatically rewind entire stack
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3866
diff
changeset
|
47 |
ancestors. To only rewind to the explicitly selection changesets use the |
1742254d1190
rewind: automatically rewind entire stack
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3866
diff
changeset
|
48 |
`--exact` flag. Using the `--exact` flag can restore some changesets as |
1742254d1190
rewind: automatically rewind entire stack
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3866
diff
changeset
|
49 |
orphan. |
1742254d1190
rewind: automatically rewind entire stack
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3866
diff
changeset
|
50 |
|
3861
bbe635dfd75c
rewind: obsolete latest successors unless instructed otherwise
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3859
diff
changeset
|
51 |
The latest successors the obsolete changesets will be superseed by these |
bbe635dfd75c
rewind: obsolete latest successors unless instructed otherwise
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3859
diff
changeset
|
52 |
new copies. This behavior can be disabled using `--as-divergence`, the |
bbe635dfd75c
rewind: obsolete latest successors unless instructed otherwise
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3859
diff
changeset
|
53 |
current latest successors won't be affected and content-divergence will |
bbe635dfd75c
rewind: obsolete latest successors unless instructed otherwise
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3859
diff
changeset
|
54 |
appears between them and the restored version of the obsolete changesets. |
3865
b945f2dae587
rewind: add a test for rewinding a fold
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3863
diff
changeset
|
55 |
|
b945f2dae587
rewind: add a test for rewinding a fold
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3863
diff
changeset
|
56 |
Current rought edges: |
b945f2dae587
rewind: add a test for rewinding a fold
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3863
diff
changeset
|
57 |
|
b945f2dae587
rewind: add a test for rewinding a fold
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3863
diff
changeset
|
58 |
* fold: rewinding to only some of the initially folded changesets will be |
b945f2dae587
rewind: add a test for rewinding a fold
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3863
diff
changeset
|
59 |
problematic. The fold result is marked obsolete and the part not |
b945f2dae587
rewind: add a test for rewinding a fold
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3863
diff
changeset
|
60 |
rewinded too are "lost". Please use --as-divergence when you |
b945f2dae587
rewind: add a test for rewinding a fold
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3863
diff
changeset
|
61 |
need to perform such operation. |
3871
2e32a1ef0c60
rewing: add the ability to rewind "from" revisions
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3869
diff
changeset
|
62 |
|
2e32a1ef0c60
rewing: add the ability to rewind "from" revisions
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3869
diff
changeset
|
63 |
* :hg:`rewind` might affect changeset outside the current stack. Without --exact, we |
2e32a1ef0c60
rewing: add the ability to rewind "from" revisions
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3869
diff
changeset
|
64 |
also restore ancestors of the rewind target, obsoleting their |
2e32a1ef0c60
rewing: add the ability to rewind "from" revisions
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3869
diff
changeset
|
65 |
latest successors (unless --as-divergent is provided). In some |
2e32a1ef0c60
rewing: add the ability to rewind "from" revisions
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3869
diff
changeset
|
66 |
case, these latest successors will be on branches unrelated to |
2e32a1ef0c60
rewing: add the ability to rewind "from" revisions
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3869
diff
changeset
|
67 |
the changeset you rewind from. |
2e32a1ef0c60
rewing: add the ability to rewind "from" revisions
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3869
diff
changeset
|
68 |
(We plan to automatically detect this cases in the future) |
2e32a1ef0c60
rewing: add the ability to rewind "from" revisions
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3869
diff
changeset
|
69 |
|
3858
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
70 |
""" |
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
71 |
unfi = repo.unfiltered() |
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
72 |
|
3861
bbe635dfd75c
rewind: obsolete latest successors unless instructed otherwise
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3859
diff
changeset
|
73 |
successorsmap = collections.defaultdict(set) |
bbe635dfd75c
rewind: obsolete latest successors unless instructed otherwise
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3859
diff
changeset
|
74 |
rewindmap = {} |
bbe635dfd75c
rewind: obsolete latest successors unless instructed otherwise
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3859
diff
changeset
|
75 |
sscache = {} |
3858
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
76 |
with repo.wlock(), repo.lock(): |
3868
1742254d1190
rewind: automatically rewind entire stack
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3866
diff
changeset
|
77 |
|
3869
bbfbaf46f7b0
rewind: move revision selection into its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3868
diff
changeset
|
78 |
rewinded = _select_rewinded(repo, opts) |
3868
1742254d1190
rewind: automatically rewind entire stack
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3866
diff
changeset
|
79 |
|
3861
bbe635dfd75c
rewind: obsolete latest successors unless instructed otherwise
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3859
diff
changeset
|
80 |
if not opts['as_divergence']: |
bbe635dfd75c
rewind: obsolete latest successors unless instructed otherwise
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3859
diff
changeset
|
81 |
for rev in rewinded: |
bbe635dfd75c
rewind: obsolete latest successors unless instructed otherwise
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3859
diff
changeset
|
82 |
ctx = unfi[rev] |
bbe635dfd75c
rewind: obsolete latest successors unless instructed otherwise
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3859
diff
changeset
|
83 |
ssets = obsutil.successorssets(repo, ctx.node(), sscache) |
bbe635dfd75c
rewind: obsolete latest successors unless instructed otherwise
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3859
diff
changeset
|
84 |
if 1 < len(ssets): |
bbe635dfd75c
rewind: obsolete latest successors unless instructed otherwise
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3859
diff
changeset
|
85 |
msg = _('rewind confused by divergence on %s') % ctx |
bbe635dfd75c
rewind: obsolete latest successors unless instructed otherwise
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3859
diff
changeset
|
86 |
hint = _('solve divergence first or use "--as-divergence"') |
bbe635dfd75c
rewind: obsolete latest successors unless instructed otherwise
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3859
diff
changeset
|
87 |
raise error.Abort(msg, hint=hint) |
bbe635dfd75c
rewind: obsolete latest successors unless instructed otherwise
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3859
diff
changeset
|
88 |
if ssets and ssets[0]: |
bbe635dfd75c
rewind: obsolete latest successors unless instructed otherwise
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3859
diff
changeset
|
89 |
for succ in ssets[0]: |
bbe635dfd75c
rewind: obsolete latest successors unless instructed otherwise
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3859
diff
changeset
|
90 |
successorsmap[succ].add(ctx.node()) |
bbe635dfd75c
rewind: obsolete latest successors unless instructed otherwise
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3859
diff
changeset
|
91 |
|
3858
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
92 |
# Check that we can rewind these changesets |
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
93 |
with repo.transaction('rewind'): |
3866
de42d00d6ee2
rewind: use rewinded parent when creating multiple changesets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3865
diff
changeset
|
94 |
for rev in sorted(rewinded): |
3861
bbe635dfd75c
rewind: obsolete latest successors unless instructed otherwise
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3859
diff
changeset
|
95 |
ctx = unfi[rev] |
3866
de42d00d6ee2
rewind: use rewinded parent when creating multiple changesets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3865
diff
changeset
|
96 |
rewindmap[ctx.node()] = _revive_revision(unfi, rev, rewindmap) |
3861
bbe635dfd75c
rewind: obsolete latest successors unless instructed otherwise
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3859
diff
changeset
|
97 |
|
bbe635dfd75c
rewind: obsolete latest successors unless instructed otherwise
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3859
diff
changeset
|
98 |
relationships = [] |
bbe635dfd75c
rewind: obsolete latest successors unless instructed otherwise
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3859
diff
changeset
|
99 |
cl = unfi.changelog |
3863
c31be22d1d90
rewind: update the working copy if it gets obsoleted
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3862
diff
changeset
|
100 |
wctxp = repo[None].p1() |
c31be22d1d90
rewind: update the working copy if it gets obsoleted
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3862
diff
changeset
|
101 |
update_target = None |
3861
bbe635dfd75c
rewind: obsolete latest successors unless instructed otherwise
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3859
diff
changeset
|
102 |
for (source, dest) in sorted(successorsmap.items()): |
bbe635dfd75c
rewind: obsolete latest successors unless instructed otherwise
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3859
diff
changeset
|
103 |
newdest = [rewindmap[d] for d in sorted(dest, key=cl.rev)] |
bbe635dfd75c
rewind: obsolete latest successors unless instructed otherwise
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3859
diff
changeset
|
104 |
rel = (unfi[source], tuple(unfi[d] for d in newdest)) |
bbe635dfd75c
rewind: obsolete latest successors unless instructed otherwise
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3859
diff
changeset
|
105 |
relationships.append(rel) |
3863
c31be22d1d90
rewind: update the working copy if it gets obsoleted
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3862
diff
changeset
|
106 |
if wctxp.node() == source: |
c31be22d1d90
rewind: update the working copy if it gets obsoleted
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3862
diff
changeset
|
107 |
update_target = newdest[-1] |
3861
bbe635dfd75c
rewind: obsolete latest successors unless instructed otherwise
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3859
diff
changeset
|
108 |
obsolete.createmarkers(unfi, relationships, operation='rewind') |
3863
c31be22d1d90
rewind: update the working copy if it gets obsoleted
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3862
diff
changeset
|
109 |
if update_target is not None: |
c31be22d1d90
rewind: update the working copy if it gets obsoleted
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3862
diff
changeset
|
110 |
hg.updaterepo(repo, update_target, False) |
c31be22d1d90
rewind: update the working copy if it gets obsoleted
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3862
diff
changeset
|
111 |
|
3859
6e3d844b56f2
rewind: add a message about the rewinded changesets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3858
diff
changeset
|
112 |
repo.ui.status(_('rewinded to %d changesets\n') % len(rewinded)) |
3862
8d3eed113b77
rewind: add a message about obsolete changeset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3861
diff
changeset
|
113 |
if relationships: |
8d3eed113b77
rewind: add a message about obsolete changeset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3861
diff
changeset
|
114 |
repo.ui.status(_('(%d changesets obsoleted)\n') % len(relationships)) |
3863
c31be22d1d90
rewind: update the working copy if it gets obsoleted
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3862
diff
changeset
|
115 |
if update_target is not None: |
c31be22d1d90
rewind: update the working copy if it gets obsoleted
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3862
diff
changeset
|
116 |
ui.status(_('working directory is now at %s\n') % repo['.']) |
3858
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
117 |
|
3869
bbfbaf46f7b0
rewind: move revision selection into its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3868
diff
changeset
|
118 |
def _select_rewinded(repo, opts): |
bbfbaf46f7b0
rewind: move revision selection into its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3868
diff
changeset
|
119 |
"""select the revision we shoudl rewind to |
bbfbaf46f7b0
rewind: move revision selection into its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3868
diff
changeset
|
120 |
""" |
3871
2e32a1ef0c60
rewing: add the ability to rewind "from" revisions
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3869
diff
changeset
|
121 |
unfi = repo.unfiltered() |
2e32a1ef0c60
rewing: add the ability to rewind "from" revisions
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3869
diff
changeset
|
122 |
rewinded = set() |
2e32a1ef0c60
rewing: add the ability to rewind "from" revisions
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3869
diff
changeset
|
123 |
if opts.get('to'): |
2e32a1ef0c60
rewing: add the ability to rewind "from" revisions
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3869
diff
changeset
|
124 |
rewinded.update(scmutil.revrange(repo, opts.get('to'))) |
2e32a1ef0c60
rewing: add the ability to rewind "from" revisions
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3869
diff
changeset
|
125 |
if opts.get('from'): |
2e32a1ef0c60
rewing: add the ability to rewind "from" revisions
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3869
diff
changeset
|
126 |
succs = scmutil.revrange(repo, opts.get('from')) |
2e32a1ef0c60
rewing: add the ability to rewind "from" revisions
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3869
diff
changeset
|
127 |
rewinded.update(unfi.revs('precursors(%ld)', succs)) |
2e32a1ef0c60
rewing: add the ability to rewind "from" revisions
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3869
diff
changeset
|
128 |
|
2e32a1ef0c60
rewing: add the ability to rewind "from" revisions
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3869
diff
changeset
|
129 |
if not rewinded: |
3869
bbfbaf46f7b0
rewind: move revision selection into its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3868
diff
changeset
|
130 |
raise error.Abort('no revision to rewind to') |
bbfbaf46f7b0
rewind: move revision selection into its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3868
diff
changeset
|
131 |
|
3871
2e32a1ef0c60
rewing: add the ability to rewind "from" revisions
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3869
diff
changeset
|
132 |
if not opts['exact']: |
2e32a1ef0c60
rewing: add the ability to rewind "from" revisions
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3869
diff
changeset
|
133 |
rewinded = unfi.revs('obsolete() and ::%ld', rewinded) |
3869
bbfbaf46f7b0
rewind: move revision selection into its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3868
diff
changeset
|
134 |
|
3871
2e32a1ef0c60
rewing: add the ability to rewind "from" revisions
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3869
diff
changeset
|
135 |
return sorted(rewinded) |
3869
bbfbaf46f7b0
rewind: move revision selection into its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3868
diff
changeset
|
136 |
|
3866
de42d00d6ee2
rewind: use rewinded parent when creating multiple changesets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3865
diff
changeset
|
137 |
def _revive_revision(unfi, rev, rewindmap): |
3858
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
138 |
"""rewind a single revision rev. |
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
139 |
""" |
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
140 |
ctx = unfi[rev] |
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
141 |
extra = ctx.extra().copy() |
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
142 |
# rewind hash should be unique over multiple rewind. |
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
143 |
user = unfi.ui.config('devel', 'user.obsmarker') |
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
144 |
if not user: |
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
145 |
user = unfi.ui.username() |
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
146 |
date = unfi.ui.configdate('devel', 'default-date') |
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
147 |
if date is None: |
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
148 |
date = compat.makedate() |
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
149 |
noise = "%s\0%s\0%d\0%d" % (ctx.node(), user, date[0], date[1]) |
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
150 |
extra['__rewind-hash__'] = hashlib.sha256(noise).hexdigest() |
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
151 |
|
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
152 |
p1 = ctx.p1().node() |
3866
de42d00d6ee2
rewind: use rewinded parent when creating multiple changesets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3865
diff
changeset
|
153 |
p1 = rewindmap.get(p1, p1) |
3858
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
154 |
p2 = ctx.p2().node() |
3866
de42d00d6ee2
rewind: use rewinded parent when creating multiple changesets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3865
diff
changeset
|
155 |
p2 = rewindmap.get(p2, p2) |
3858
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
156 |
|
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
157 |
extradict = {'extra': extra} |
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
158 |
|
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
159 |
new, unusedvariable = rewriteutil.rewrite(unfi, ctx, [], ctx, |
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
160 |
[p1, p2], |
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
161 |
commitopts=extradict) |
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
162 |
|
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
163 |
obsolete.createmarkers(unfi, [(ctx, (unfi[new],))], |
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
164 |
flag=identicalflag, operation='rewind') |
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
165 |
|
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
166 |
return new |