changeset 3871:2e32a1ef0c60

rewing: add the ability to rewind "from" revisions
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Sun, 17 Jun 2018 03:10:19 +0200
parents e0bf44befd6e
children bbc3cfdfe42b
files hgext3rd/evolve/rewind.py tests/test-rewind.t
diffstat 2 files changed, 95 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/hgext3rd/evolve/rewind.py	Sun Jun 17 03:29:34 2018 +0200
+++ b/hgext3rd/evolve/rewind.py	Sun Jun 17 03:10:19 2018 +0200
@@ -29,6 +29,7 @@
     [('', 'to', [], _("rewind to these revision")),
      ('', 'as-divergence', None, _("preserve current latest successors")),
      ('', 'exact', None, _("only rewind explicitly selected revisions")),
+     ('', 'from', [], _("rewind these revisions to their predecessors")),
     ],
     _(''))
 def rewind(ui, repo, **opts):
@@ -37,6 +38,11 @@
     This command can be used to restore stacks of changesets to an obsolete
     state, creating identical identical copies.
 
+    There are two mains way to select the rewind target. Rewinding "from"
+    changesets will restore the direct precursors of theses changesets (and
+    obsolete the changeset you rewind from). Rewinding "to" will restore the
+    changeset you have selected (and obsolete their latest successors).
+
     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
@@ -53,6 +59,14 @@
               problematic. The fold result is marked obsolete and the part not
               rewinded too are "lost".  Please use --as-divergence when you
               need to perform such operation.
+
+      * :hg:`rewind` might affect changeset outside the current stack. Without --exact, we
+              also restore ancestors of the rewind target, obsoleting their
+              latest successors (unless --as-divergent is provided). In some
+              case, these latest successors will be on branches unrelated to
+              the changeset you rewind from.
+              (We plan to automatically detect this cases in the future)
+
     """
     unfi = repo.unfiltered()
 
@@ -104,15 +118,21 @@
 def _select_rewinded(repo, opts):
     """select the revision we shoudl rewind to
     """
-    if not opts.get('to'):
+    unfi = repo.unfiltered()
+    rewinded = set()
+    if opts.get('to'):
+        rewinded.update(scmutil.revrange(repo, opts.get('to')))
+    if opts.get('from'):
+        succs = scmutil.revrange(repo, opts.get('from'))
+        rewinded.update(unfi.revs('precursors(%ld)', succs))
+
+    if not rewinded:
         raise error.Abort('no revision to rewind to')
 
-    rewinded = scmutil.revrange(repo, opts.get('to'))
+    if not opts['exact']:
+        rewinded = unfi.revs('obsolete() and ::%ld', rewinded)
 
-    if not opts['exact']:
-        rewinded = repo.revs('obsolete() and ::%ld', rewinded)
-
-    return rewinded
+    return sorted(rewinded)
 
 def _revive_revision(unfi, rev, rewindmap):
     """rewind a single revision rev.
--- a/tests/test-rewind.t	Sun Jun 17 03:29:34 2018 +0200
+++ b/tests/test-rewind.t	Sun Jun 17 03:10:19 2018 +0200
@@ -748,11 +748,11 @@
      summary:     c_ROOT
   
 
-cleanup
-```````
+Testing --from (and cleanup)
+```````````````````````````
 
   $ echo 'default-date = 4 0' >> $HGRCPATH
-  $ hg rewind --hidden --to 'precursors(.)'
+  $ hg rewind --from '.'
   rewinded to 1 changesets
   (1 changesets obsoleted)
   working directory is now at 7b1440274cc3
@@ -797,8 +797,8 @@
        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
---------------------------------------
+Automatically rewinding the full stack (with --to)
+--------------------------------------------------
 
   $ hg rewind --hidden --to 'precursors(.)'
   rewinded to 2 changesets
@@ -851,3 +851,67 @@
      date:        Thu Jan 01 00:00:00 1970 +0000
      summary:     c_ROOT
   
+
+Automatically rewinding the full stack (with --from)
+----------------------------------------------------
+
+  $ echo 'default-date = 6 0' >> $HGRCPATH
+  $ hg rewind --hidden --from '.'
+  rewinded to 2 changesets
+  (2 changesets obsoleted)
+  working directory is now at 141aedbbde8f
+  $ 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'}
+  d952d1794ff657f5c2a82225d2e6307ed930b32f 7b4aed5e99d2734da6cc25f0095876c5cb6e8084 4 (Thu Jan 01 00:00:06 1970 +0000) {'ef1': '34', 'operation': 'rewind', 'user': 'test'}
+  7b1440274cc3b3f8bfcffc891172a7d2d7e9140c 141aedbbde8f407fc8a8a7355221733b0fc01ca5 4 (Thu Jan 01 00:00:06 1970 +0000) {'ef1': '38', 'operation': 'rewind', 'user': 'test'}
+  70892f498f2993d626848bb312ff856168d0b9c4 141aedbbde8f407fc8a8a7355221733b0fc01ca5 0 (Thu Jan 01 00:00:06 1970 +0000) {'ef1': '38', 'operation': 'rewind', 'user': 'test'}
+  c0d232501dd8e52b8ca8a266f25db89f5120c17f 7b4aed5e99d2734da6cc25f0095876c5cb6e8084 0 (Thu Jan 01 00:00:06 1970 +0000) {'ef1': '43', 'operation': 'rewind', 'user': 'test'}
+  $ hg obslog
+  @    141aedbbde8f (10) c_B0
+  |\
+  x |  70892f498f29 (8) c_B0
+  |\|    rewritten(meta, date, parent) as 141aedbbde8f using rewind by test (Thu Jan 01 00:00:06 1970 +0000)
+  | |
+  | x  7b1440274cc3 (6) c_B0
+  |/|    rewritten(meta, date, parent) as 141aedbbde8f using rewind by test (Thu Jan 01 00:00:06 1970 +0000)
+  | |    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:   10:141aedbbde8f
+  |  tag:         tip
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:06 1970 +0000
+  |  summary:     c_B0
+  |
+  o  changeset:   9:7b4aed5e99d2
+  |  parent:      0:eba9c2249fe7
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:06 1970 +0000
+  |  summary:     c_A1
+  |
+  o  changeset:   0:eba9c2249fe7
+     user:        test
+     date:        Thu Jan 01 00:00:00 1970 +0000
+     summary:     c_ROOT
+