author | Pierre-Yves David <pierre-yves.david@octobus.net> |
Tue, 27 Nov 2018 04:07:33 +0100 | |
branch | mercurial-4.6 |
changeset 4273 | 1f333a7bc33b |
parent 4191 | 5c734be63c3e |
child 4194 | cae466b70bf1 |
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 ( |
3873
b81fd1487e04
rewing: prevent rewind in case of uncommitted changes
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3872
diff
changeset
|
7 |
cmdutil, |
3858
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
8 |
error, |
3863
c31be22d1d90
rewind: update the working copy if it gets obsoleted
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3862
diff
changeset
|
9 |
hg, |
3858
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
10 |
obsolete, |
3861
bbe635dfd75c
rewind: obsolete latest successors unless instructed otherwise
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3859
diff
changeset
|
11 |
obsutil, |
3858
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
12 |
scmutil, |
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 |
|
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
15 |
from mercurial.i18n import _ |
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
16 |
|
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
17 |
from . import ( |
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
18 |
exthelper, |
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
19 |
rewriteutil, |
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
20 |
compat, |
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 |
|
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
23 |
eh = exthelper.exthelper() |
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
24 |
|
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
25 |
# 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
|
26 |
identicalflag = 4 |
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
27 |
|
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
28 |
@eh.command( |
4191
5c734be63c3e
evolve: adapt for changed @command decorator
Martin von Zweigbergk <martinvonz@google.com>
parents:
4158
diff
changeset
|
29 |
'rewind|undo', |
4091
2c60ad0d54a9
rewind: fix help text (mostly grammar, but also s/precursor/predecessor)
Martin von Zweigbergk <martinvonz@google.com>
parents:
3873
diff
changeset
|
30 |
[('', 'to', [], _("rewind to these revisions")), |
3861
bbe635dfd75c
rewind: obsolete latest successors unless instructed otherwise
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3859
diff
changeset
|
31 |
('', '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
|
32 |
('', '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
|
33 |
('', '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
|
34 |
], |
4191
5c734be63c3e
evolve: adapt for changed @command decorator
Martin von Zweigbergk <martinvonz@google.com>
parents:
4158
diff
changeset
|
35 |
_(''), |
5c734be63c3e
evolve: adapt for changed @command decorator
Martin von Zweigbergk <martinvonz@google.com>
parents:
4158
diff
changeset
|
36 |
helpbasic=True) |
3858
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
37 |
def rewind(ui, repo, **opts): |
4091
2c60ad0d54a9
rewind: fix help text (mostly grammar, but also s/precursor/predecessor)
Martin von Zweigbergk <martinvonz@google.com>
parents:
3873
diff
changeset
|
38 |
"""rewind a stack of changesets to a previous state |
3861
bbe635dfd75c
rewind: obsolete latest successors unless instructed otherwise
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3859
diff
changeset
|
39 |
|
bbe635dfd75c
rewind: obsolete latest successors unless instructed otherwise
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3859
diff
changeset
|
40 |
This command can be used to restore stacks of changesets to an obsolete |
4091
2c60ad0d54a9
rewind: fix help text (mostly grammar, but also s/precursor/predecessor)
Martin von Zweigbergk <martinvonz@google.com>
parents:
3873
diff
changeset
|
41 |
state, creating identical copies. |
3861
bbe635dfd75c
rewind: obsolete latest successors unless instructed otherwise
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3859
diff
changeset
|
42 |
|
4091
2c60ad0d54a9
rewind: fix help text (mostly grammar, but also s/precursor/predecessor)
Martin von Zweigbergk <martinvonz@google.com>
parents:
3873
diff
changeset
|
43 |
There are two main ways to select the rewind target. Rewinding "from" |
2c60ad0d54a9
rewind: fix help text (mostly grammar, but also s/precursor/predecessor)
Martin von Zweigbergk <martinvonz@google.com>
parents:
3873
diff
changeset
|
44 |
changesets will restore the direct predecessors of these changesets (and |
3871
2e32a1ef0c60
rewing: add the ability to rewind "from" revisions
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3869
diff
changeset
|
45 |
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
|
46 |
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
|
47 |
|
3872
bbc3cfdfe42b
rewind: default to rewinding the current stack
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3871
diff
changeset
|
48 |
By default, we rewind from the working copy parents, restoring its |
4091
2c60ad0d54a9
rewind: fix help text (mostly grammar, but also s/precursor/predecessor)
Martin von Zweigbergk <martinvonz@google.com>
parents:
3873
diff
changeset
|
49 |
predecessor. |
3872
bbc3cfdfe42b
rewind: default to rewinding the current stack
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3871
diff
changeset
|
50 |
|
3868
1742254d1190
rewind: automatically rewind entire stack
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3866
diff
changeset
|
51 |
When we rewind to an obsolete version, we also rewind to all its obsolete |
4091
2c60ad0d54a9
rewind: fix help text (mostly grammar, but also s/precursor/predecessor)
Martin von Zweigbergk <martinvonz@google.com>
parents:
3873
diff
changeset
|
52 |
ancestors. To only rewind to the explicitly selected changesets use the |
3868
1742254d1190
rewind: automatically rewind entire stack
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3866
diff
changeset
|
53 |
`--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
|
54 |
orphan. |
1742254d1190
rewind: automatically rewind entire stack
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3866
diff
changeset
|
55 |
|
4091
2c60ad0d54a9
rewind: fix help text (mostly grammar, but also s/precursor/predecessor)
Martin von Zweigbergk <martinvonz@google.com>
parents:
3873
diff
changeset
|
56 |
The latest successors of the obsolete changesets will be superseded by |
2c60ad0d54a9
rewind: fix help text (mostly grammar, but also s/precursor/predecessor)
Martin von Zweigbergk <martinvonz@google.com>
parents:
3873
diff
changeset
|
57 |
these new copies. This behavior can be disabled using `--as-divergence`, |
2c60ad0d54a9
rewind: fix help text (mostly grammar, but also s/precursor/predecessor)
Martin von Zweigbergk <martinvonz@google.com>
parents:
3873
diff
changeset
|
58 |
the current latest successors won't be affected and content-divergence will |
2c60ad0d54a9
rewind: fix help text (mostly grammar, but also s/precursor/predecessor)
Martin von Zweigbergk <martinvonz@google.com>
parents:
3873
diff
changeset
|
59 |
appear 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
|
60 |
|
4091
2c60ad0d54a9
rewind: fix help text (mostly grammar, but also s/precursor/predecessor)
Martin von Zweigbergk <martinvonz@google.com>
parents:
3873
diff
changeset
|
61 |
Current rough edges: |
3865
b945f2dae587
rewind: add a test for rewinding a fold
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3863
diff
changeset
|
62 |
|
b945f2dae587
rewind: add a test for rewinding a fold
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3863
diff
changeset
|
63 |
* 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
|
64 |
problematic. The fold result is marked obsolete and the part not |
4091
2c60ad0d54a9
rewind: fix help text (mostly grammar, but also s/precursor/predecessor)
Martin von Zweigbergk <martinvonz@google.com>
parents:
3873
diff
changeset
|
65 |
rewinded to are "lost". Please use --as-divergence when you |
3865
b945f2dae587
rewind: add a test for rewinding a fold
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3863
diff
changeset
|
66 |
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
|
67 |
|
4091
2c60ad0d54a9
rewind: fix help text (mostly grammar, but also s/precursor/predecessor)
Martin von Zweigbergk <martinvonz@google.com>
parents:
3873
diff
changeset
|
68 |
* :hg:`rewind` might affect changesets outside the current stack. Without |
2c60ad0d54a9
rewind: fix help text (mostly grammar, but also s/precursor/predecessor)
Martin von Zweigbergk <martinvonz@google.com>
parents:
3873
diff
changeset
|
69 |
--exact, we also restore ancestors of the rewind target, |
2c60ad0d54a9
rewind: fix help text (mostly grammar, but also s/precursor/predecessor)
Martin von Zweigbergk <martinvonz@google.com>
parents:
3873
diff
changeset
|
70 |
obsoleting their latest successors (unless --as-divergent is |
2c60ad0d54a9
rewind: fix help text (mostly grammar, but also s/precursor/predecessor)
Martin von Zweigbergk <martinvonz@google.com>
parents:
3873
diff
changeset
|
71 |
provided). In some case, these latest successors will be on |
2c60ad0d54a9
rewind: fix help text (mostly grammar, but also s/precursor/predecessor)
Martin von Zweigbergk <martinvonz@google.com>
parents:
3873
diff
changeset
|
72 |
branches unrelated to the changeset you rewind from. |
2c60ad0d54a9
rewind: fix help text (mostly grammar, but also s/precursor/predecessor)
Martin von Zweigbergk <martinvonz@google.com>
parents:
3873
diff
changeset
|
73 |
(We plan to automatically detect this case in the future) |
3871
2e32a1ef0c60
rewing: add the ability to rewind "from" revisions
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3869
diff
changeset
|
74 |
|
3858
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
75 |
""" |
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
76 |
unfi = repo.unfiltered() |
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
77 |
|
3861
bbe635dfd75c
rewind: obsolete latest successors unless instructed otherwise
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3859
diff
changeset
|
78 |
successorsmap = collections.defaultdict(set) |
bbe635dfd75c
rewind: obsolete latest successors unless instructed otherwise
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3859
diff
changeset
|
79 |
rewindmap = {} |
bbe635dfd75c
rewind: obsolete latest successors unless instructed otherwise
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3859
diff
changeset
|
80 |
sscache = {} |
3858
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
81 |
with repo.wlock(), repo.lock(): |
3873
b81fd1487e04
rewing: prevent rewind in case of uncommitted changes
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3872
diff
changeset
|
82 |
# stay on the safe side: prevent local case in case we need to upgrade |
b81fd1487e04
rewing: prevent rewind in case of uncommitted changes
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3872
diff
changeset
|
83 |
cmdutil.bailifchanged(repo) |
3868
1742254d1190
rewind: automatically rewind entire stack
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3866
diff
changeset
|
84 |
|
3869
bbfbaf46f7b0
rewind: move revision selection into its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3868
diff
changeset
|
85 |
rewinded = _select_rewinded(repo, opts) |
3868
1742254d1190
rewind: automatically rewind entire stack
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3866
diff
changeset
|
86 |
|
3861
bbe635dfd75c
rewind: obsolete latest successors unless instructed otherwise
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3859
diff
changeset
|
87 |
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
|
88 |
for rev in rewinded: |
bbe635dfd75c
rewind: obsolete latest successors unless instructed otherwise
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3859
diff
changeset
|
89 |
ctx = unfi[rev] |
bbe635dfd75c
rewind: obsolete latest successors unless instructed otherwise
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3859
diff
changeset
|
90 |
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
|
91 |
if 1 < len(ssets): |
bbe635dfd75c
rewind: obsolete latest successors unless instructed otherwise
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3859
diff
changeset
|
92 |
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
|
93 |
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
|
94 |
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
|
95 |
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
|
96 |
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
|
97 |
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
|
98 |
|
3858
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
99 |
# 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
|
100 |
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
|
101 |
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
|
102 |
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
|
103 |
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
|
104 |
|
bbe635dfd75c
rewind: obsolete latest successors unless instructed otherwise
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3859
diff
changeset
|
105 |
relationships = [] |
bbe635dfd75c
rewind: obsolete latest successors unless instructed otherwise
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3859
diff
changeset
|
106 |
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
|
107 |
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
|
108 |
update_target = None |
3861
bbe635dfd75c
rewind: obsolete latest successors unless instructed otherwise
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3859
diff
changeset
|
109 |
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
|
110 |
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
|
111 |
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
|
112 |
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
|
113 |
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
|
114 |
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
|
115 |
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
|
116 |
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
|
117 |
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
|
118 |
|
3859
6e3d844b56f2
rewind: add a message about the rewinded changesets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3858
diff
changeset
|
119 |
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
|
120 |
if relationships: |
8d3eed113b77
rewind: add a message about obsolete changeset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3861
diff
changeset
|
121 |
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
|
122 |
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
|
123 |
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
|
124 |
|
3869
bbfbaf46f7b0
rewind: move revision selection into its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3868
diff
changeset
|
125 |
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
|
126 |
"""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
|
127 |
""" |
3871
2e32a1ef0c60
rewing: add the ability to rewind "from" revisions
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3869
diff
changeset
|
128 |
unfi = repo.unfiltered() |
2e32a1ef0c60
rewing: add the ability to rewind "from" revisions
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3869
diff
changeset
|
129 |
rewinded = set() |
3872
bbc3cfdfe42b
rewind: default to rewinding the current stack
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3871
diff
changeset
|
130 |
revsto = opts.get('to') |
bbc3cfdfe42b
rewind: default to rewinding the current stack
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3871
diff
changeset
|
131 |
revsfrom = opts.get('from') |
bbc3cfdfe42b
rewind: default to rewinding the current stack
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3871
diff
changeset
|
132 |
if not (revsto or revsfrom): |
bbc3cfdfe42b
rewind: default to rewinding the current stack
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3871
diff
changeset
|
133 |
revsfrom.append('.') |
bbc3cfdfe42b
rewind: default to rewinding the current stack
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3871
diff
changeset
|
134 |
if revsto: |
bbc3cfdfe42b
rewind: default to rewinding the current stack
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3871
diff
changeset
|
135 |
rewinded.update(scmutil.revrange(repo, revsto)) |
bbc3cfdfe42b
rewind: default to rewinding the current stack
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3871
diff
changeset
|
136 |
if revsfrom: |
bbc3cfdfe42b
rewind: default to rewinding the current stack
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3871
diff
changeset
|
137 |
succs = scmutil.revrange(repo, revsfrom) |
3871
2e32a1ef0c60
rewing: add the ability to rewind "from" revisions
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3869
diff
changeset
|
138 |
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
|
139 |
|
2e32a1ef0c60
rewing: add the ability to rewind "from" revisions
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3869
diff
changeset
|
140 |
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
|
141 |
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
|
142 |
|
3871
2e32a1ef0c60
rewing: add the ability to rewind "from" revisions
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3869
diff
changeset
|
143 |
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
|
144 |
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
|
145 |
|
3871
2e32a1ef0c60
rewing: add the ability to rewind "from" revisions
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3869
diff
changeset
|
146 |
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
|
147 |
|
3866
de42d00d6ee2
rewind: use rewinded parent when creating multiple changesets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
3865
diff
changeset
|
148 |
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
|
149 |
"""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
|
150 |
""" |
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
151 |
ctx = unfi[rev] |
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
152 |
extra = ctx.extra().copy() |
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
153 |
# 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
|
154 |
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
|
155 |
if not user: |
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
156 |
user = unfi.ui.username() |
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
157 |
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
|
158 |
if date is None: |
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
159 |
date = compat.makedate() |
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
160 |
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
|
161 |
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
|
162 |
|
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
163 |
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
|
164 |
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
|
165 |
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
|
166 |
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
|
167 |
|
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
168 |
extradict = {'extra': extra} |
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
169 |
|
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
170 |
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
|
171 |
[p1, p2], |
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
172 |
commitopts=extradict) |
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
173 |
|
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
174 |
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
|
175 |
flag=identicalflag, operation='rewind') |
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
176 |
|
bb4f5ad63877
rewind: add a proto version of the command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
177 |
return new |