rewind: automatically rewind entire stack
We now rewind the full stack, avoiding creating orphans. A `--exact` flag is
added to force rewinding only the explicitly specified changesets.
--- a/hgext3rd/evolve/rewind.py Sun Jun 17 02:22:28 2018 +0200
+++ b/hgext3rd/evolve/rewind.py Sun Jun 17 02:32:29 2018 +0200
@@ -28,6 +28,7 @@
'^rewind',
[('', 'to', [], _("rewind to these revision")),
('', 'as-divergence', None, _("preserve current latest successors")),
+ ('', 'exact', None, _("only rewind explicitly selected revisions")),
],
_(''))
def rewind(ui, repo, **opts):
@@ -36,6 +37,11 @@
This command can be used to restore stacks of changesets to an obsolete
state, creating identical identical copies.
+ When we rewind to an obsolete version, we also rewind to all its obsolete
+ ancestors. To only rewind to the explicitly selection changesets use the
+ `--exact` flag. Using the `--exact` flag can restore some changesets as
+ orphan.
+
The latest successors the obsolete changesets will be superseed by these
new copies. This behavior can be disabled using `--as-divergence`, the
current latest successors won't be affected and content-divergence will
@@ -53,12 +59,16 @@
if not opts.get('to'):
raise error.Abort('no revision to rewind to')
- rewinded = scmutil.revrange(repo, opts.get('to'))
-
successorsmap = collections.defaultdict(set)
rewindmap = {}
sscache = {}
with repo.wlock(), repo.lock():
+
+ rewinded = scmutil.revrange(repo, opts.get('to'))
+
+ if not opts['exact']:
+ rewinded = repo.revs('obsolete() and ::%ld', rewinded)
+
if not opts['as_divergence']:
for rev in rewinded:
ctx = unfi[rev]
--- a/tests/test-rewind.t Sun Jun 17 02:22:28 2018 +0200
+++ b/tests/test-rewind.t Sun Jun 17 02:32:29 2018 +0200
@@ -701,7 +701,7 @@
Actual rewind
`````````````
- $ hg rewind --hidden --to 'min(desc(c_B0))'
+ $ hg rewind --hidden --to 'min(desc(c_B0))' --exact
1 new orphan changesets
rewinded to 1 changesets
(1 changesets obsoleted)
@@ -797,3 +797,57 @@
rewritten(meta, date) as 96622b0702dd using rewind by test (Thu Jan 01 00:00:03 1970 +0000)
rewritten(parent) as a65fceb2324a using evolve by test (Thu Jan 01 00:00:03 1970 +0000)
+Automaticlaly rewinding the full stack
+--------------------------------------
+
+ $ hg rewind --hidden --to 'max(precursors(.))'
+ rewinded to 2 changesets
+ (2 changesets obsoleted)
+ working directory is now at 70892f498f29
+ $ hg debugobsolete
+ 579f120ba91885449adc92eedf48ef3569742cee d952d1794ff657f5c2a82225d2e6307ed930b32f 0 (Thu Jan 01 00:00:03 1970 +0000) {'ef1': '9', 'operation': 'amend', 'user': 'test'}
+ 7e594302a05d3769b27be88fc3cdfd39d7498498 a65fceb2324ae1eb1231610193d24a5fa02c7c0e 0 (Thu Jan 01 00:00:03 1970 +0000) {'ef1': '4', 'operation': 'evolve', 'user': 'test'}
+ 7e594302a05d3769b27be88fc3cdfd39d7498498 96622b0702dd86e3a702b0235b420da41f072efe 4 (Thu Jan 01 00:00:03 1970 +0000) {'ef1': '34', 'operation': 'rewind', 'user': 'test'}
+ a65fceb2324ae1eb1231610193d24a5fa02c7c0e 96622b0702dd86e3a702b0235b420da41f072efe 0 (Thu Jan 01 00:00:03 1970 +0000) {'ef1': '38', 'operation': 'rewind', 'user': 'test'}
+ a65fceb2324ae1eb1231610193d24a5fa02c7c0e 7b1440274cc3b3f8bfcffc891172a7d2d7e9140c 4 (Thu Jan 01 00:00:04 1970 +0000) {'ef1': '34', 'operation': 'rewind', 'user': 'test'}
+ 96622b0702dd86e3a702b0235b420da41f072efe 7b1440274cc3b3f8bfcffc891172a7d2d7e9140c 0 (Thu Jan 01 00:00:04 1970 +0000) {'ef1': '38', 'operation': 'rewind', 'user': 'test'}
+ 579f120ba91885449adc92eedf48ef3569742cee c0d232501dd8e52b8ca8a266f25db89f5120c17f 4 (Thu Jan 01 00:00:05 1970 +0000) {'ef1': '34', 'operation': 'rewind', 'user': 'test'}
+ 96622b0702dd86e3a702b0235b420da41f072efe 70892f498f2993d626848bb312ff856168d0b9c4 4 (Thu Jan 01 00:00:05 1970 +0000) {'ef1': '38', 'operation': 'rewind', 'user': 'test'}
+ 7b1440274cc3b3f8bfcffc891172a7d2d7e9140c 70892f498f2993d626848bb312ff856168d0b9c4 0 (Thu Jan 01 00:00:05 1970 +0000) {'ef1': '38', 'operation': 'rewind', 'user': 'test'}
+ d952d1794ff657f5c2a82225d2e6307ed930b32f c0d232501dd8e52b8ca8a266f25db89f5120c17f 0 (Thu Jan 01 00:00:05 1970 +0000) {'ef1': '43', 'operation': 'rewind', 'user': 'test'}
+ $ hg obslog
+ @ 70892f498f29 (8) c_B0
+ |\
+ x | 7b1440274cc3 (6) c_B0
+ |\| rewritten(meta, date, parent) as 70892f498f29 using rewind by test (Thu Jan 01 00:00:05 1970 +0000)
+ | |
+ | x 96622b0702dd (5) c_B0
+ |/| rewritten(meta, date, parent) as 70892f498f29 using rewind by test (Thu Jan 01 00:00:05 1970 +0000)
+ | | rewritten(meta, date, parent) as 7b1440274cc3 using rewind by test (Thu Jan 01 00:00:04 1970 +0000)
+ | |
+ x | a65fceb2324a (4) c_B0
+ |/ rewritten(meta, date) as 7b1440274cc3 using rewind by test (Thu Jan 01 00:00:04 1970 +0000)
+ | rewritten(meta, date, parent) as 96622b0702dd using rewind by test (Thu Jan 01 00:00:03 1970 +0000)
+ |
+ x 7e594302a05d (2) c_B0
+ rewritten(meta, date) as 96622b0702dd using rewind by test (Thu Jan 01 00:00:03 1970 +0000)
+ rewritten(parent) as a65fceb2324a using evolve by test (Thu Jan 01 00:00:03 1970 +0000)
+
+ $ hg log -G
+ @ changeset: 8:70892f498f29
+ | tag: tip
+ | user: test
+ | date: Thu Jan 01 00:00:05 1970 +0000
+ | summary: c_B0
+ |
+ o changeset: 7:c0d232501dd8
+ | parent: 0:eba9c2249fe7
+ | user: test
+ | date: Thu Jan 01 00:00:05 1970 +0000
+ | summary: c_A0
+ |
+ o changeset: 0:eba9c2249fe7
+ user: test
+ date: Thu Jan 01 00:00:00 1970 +0000
+ summary: c_ROOT
+