Pierre-Yves David avatar Pierre-Yves David committed 5eecfda

obsolete: enable rebase --keep again

We still never strip anything. But using --keep on the command line dos not lay
marker.

Comments (0)

Files changed (3)

docs/obs-implementation.rst

 * Use secret phase to remove from discovery obsolete and unstable changeset (to
   be improved soon)
 
-* alter rebase to use obsolete marker instead of stripping. (XXX break --keep for now)
+* alter rebase to use obsolete marker instead of stripping.
 
 * Have an experimental mq-like extension to rewrite history (more on that later)
 

hgext/obsolete.py

     return newrev
 
 def cmdrebase(orig, ui, repo, *args, **kwargs):
-    if kwargs.get('keep', False):
-        raise util.Abort(_('rebase --keep option is unsupported with obsolete '
-                           'extension'), hint=_("see 'hg help obsolete'"))
+
+    reallykeep = kwargs.get('keep', False)
     kwargs = dict(kwargs)
     kwargs['keep'] = True
 
     repo._rebasetarget = None
     try:
         res = orig(ui, repo, *args, **kwargs)
-        # Filter nullmerge or unrebased entries
-        repo._rebasestate = dict(p for p in repo._rebasestate.iteritems()
-                                 if p[1] >= 0)
-        if not res and not kwargs.get('abort') and repo._rebasestate:
-            # Rebased revisions are assumed to be descendants of
-            # targetrev. If a source revision is mapped to targetrev
-            # or to another rebased revision, it must have been
-            # removed.
-            targetrev = repo[repo._rebasetarget].rev()
-            newrevs = set([targetrev])
-            replacements = {}
-            for rev, newrev in sorted(repo._rebasestate.items()):
-                oldnode = repo[rev].node()
-                if newrev not in newrevs:
-                    newnode = repo[newrev].node()
-                    newrevs.add(newrev)
+        if not reallykeep:
+            # Filter nullmerge or unrebased entries
+            repo._rebasestate = dict(p for p in repo._rebasestate.iteritems()
+                                     if p[1] >= 0)
+            if not res and not kwargs.get('abort') and repo._rebasestate:
+                # Rebased revisions are assumed to be descendants of
+                # targetrev. If a source revision is mapped to targetrev
+                # or to another rebased revision, it must have been
+                # removed.
+                targetrev = repo[repo._rebasetarget].rev()
+                newrevs = set([targetrev])
+                replacements = {}
+                for rev, newrev in sorted(repo._rebasestate.items()):
+                    oldnode = repo[rev].node()
+                    if newrev not in newrevs:
+                        newnode = repo[newrev].node()
+                        newrevs.add(newrev)
+                    else:
+                        newnode = nullid
+                    replacements[oldnode] = newnode
+
+                if kwargs.get('collapse'):
+                    newnodes = set(n for n in replacements.values() if n != nullid)
+                    if newnodes:
+                        # Collapsing into more than one revision?
+                        assert len(newnodes) == 1, newnodes
+                        newnode = newnodes.pop()
+                    else:
+                        newnode = nullid
+                    repo.addcollapsedobsolete(replacements, newnode)
                 else:
-                    newnode = nullid
-                replacements[oldnode] = newnode
-
-            if kwargs.get('collapse'):
-                newnodes = set(n for n in replacements.values() if n != nullid)
-                if newnodes:
-                    # Collapsing into more than one revision?
-                    assert len(newnodes) == 1, newnodes
-                    newnode = newnodes.pop()
-                else:
-                    newnode = nullid
-                repo.addcollapsedobsolete(replacements, newnode)
-            else:
-                for oldnode, newnode in replacements.iteritems():
-                    repo.addobsolete(newnode, oldnode)
+                    for oldnode, newnode in replacements.iteritems():
+                        repo.addobsolete(newnode, oldnode)
         return res
     finally:
         delattr(repo, '_rebasestate')

tests/test-obsolete-rebase.t

   created new head
   $ echo e > e
   $ hg ci -Am adde e
-  $ hg rebase -d 1 -r . --detach --keep  
-  abort: rebase --keep option is unsupported with obsolete extension
-  (see 'hg help obsolete')
-  [255]
-  $ hg rebase -d 1 -r . --detach
+  $ hg rebase -d 1 -r 3 --detach --keep  
+  $ glog
+  @  4:9c5494949763@default(draft) adde
+  |
+  | o  3:98e4a024635e@default(draft) adde
+  | |
+  | o  2:102a90ea7b4a@default(draft) addb
+  | |
+  o |  1:540395c44225@default(draft) changea
+  |/
+  o  0:07f494440405@default(draft) adda
+  
+  $ glog --hidden
+  @  4:9c5494949763@default(draft) adde
+  |
+  | o  3:98e4a024635e@default(draft) adde
+  | |
+  | o  2:102a90ea7b4a@default(draft) addb
+  | |
+  o |  1:540395c44225@default(draft) changea
+  |/
+  o  0:07f494440405@default(draft) adda
+  
+  $ hg debugsuccessors
+  $ hg --config extensions.hgext.mq= strip tip
+  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  saved backup bundle to $TESTTMP/repo/.hg/strip-backup/9c5494949763-backup.hg
+  $ hg rebase -d 1 -r 3 --detach
+  $ glog
+  @  4:9c5494949763@default(draft) adde
+  |
+  | o  2:102a90ea7b4a@default(draft) addb
+  | |
+  o |  1:540395c44225@default(draft) changea
+  |/
+  o  0:07f494440405@default(draft) adda
+  
   $ glog --hidden
   @  4:9c5494949763@default(draft) adde
   |
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.