diff hgext/rebase.py @ 33332:3b7cb3d17137

rebase: use scmutil.cleanupnodes (issue5606) (BC) This patch migrates rebase to use scmutil.cleanupnodes API. It simplifies the code and makes rebase code reusable inside a transaction. This is a BC because the backup file is no longer strip-backup/*-backup.hg, but strip-backup/*-rebase.hg. The latter looks more reasonable since the directory name is "strip-backup" so there is no need to repeat "backup". I think the backup file name change is probably fine as a BC, since we have changed it before (aa4a1672583e) and didn't get complains. The end result of this series will be a much more consistent and unified backup names: command | old backup file suffix | new backup file suffix ------------------------------------------------------------------- amend | amend-backup.hg | amend.hg histedit | backup.hg (could be 2 files) | histedit.hg (single file) rebase | backup.hg | rebase.hg strip | backup.hg | backup.hg (note: backup files are under .hg/strip-backup) It also fixes issue5606 as a side effect because the new "delayedstrip" code path will carefully examine nodes (safestriproots) to make sure orphaned changesets won't get stripped by accident. Some warning messages are changed to the new "warning: orphaned descendants detected, not stripping HASHES", which provides more information about exactly what changesets are left behind. Another minor behavior change is when there is an obsoleted changeset with a successor in the destination branch, bookmarks pointing to that obsoleted changeset will not be moved. I have commented in test-rebase-obsolete.t explaining why that is more desirable.
author Jun Wu <quark@fb.com>
date Fri, 07 Jul 2017 18:51:46 -0700
parents 5d29c55414b3
children 8bfd10e4c55a
line wrap: on
line diff
--- a/hgext/rebase.py	Mon Jun 26 13:13:51 2017 -0700
+++ b/hgext/rebase.py	Fri Jul 07 18:51:46 2017 -0700
@@ -139,7 +139,6 @@
         # dict will be what contains most of the rebase progress state.
         self.state = {}
         self.activebookmark = None
-        self.currentbookmarks = None
         self.dest = None
         self.skipped = set()
         self.destancestors = set()
@@ -364,8 +363,7 @@
             self.destancestors = repo.changelog.ancestors([self.dest],
                                                           inclusive=True)
 
-        # Keep track of the current bookmarks in order to reset them later
-        self.currentbookmarks = repo._bookmarks.copy()
+        # Keep track of the active bookmarks in order to reset them later
         self.activebookmark = self.activebookmark or repo._activebookmark
         if self.activebookmark:
             bookmarks.deactivate(repo)
@@ -498,19 +496,6 @@
         if 'qtip' in repo.tags():
             updatemq(repo, self.state, self.skipped, **opts)
 
-        if self.currentbookmarks:
-            # Nodeids are needed to reset bookmarks
-            nstate = {}
-            for k, v in self.state.iteritems():
-                if v > nullmerge and v != k:
-                    nstate[repo[k].node()] = repo[v].node()
-                elif v == revprecursor:
-                    succ = self.obsoletenotrebased[k]
-                    nstate[repo[k].node()] = repo[succ].node()
-            # XXX this is the same as dest.node() for the non-continue path --
-            # this should probably be cleaned up
-            destnode = repo[self.dest].node()
-
         # restore original working directory
         # (we do this before stripping)
         newwd = self.state.get(self.originalwd, self.originalwd)
@@ -523,14 +508,6 @@
             ui.note(_("update back to initial working directory parent\n"))
             hg.updaterepo(repo, newwd, False)
 
-        if self.currentbookmarks:
-            with repo.transaction('bookmark') as tr:
-                updatebookmarks(repo, destnode, nstate,
-                                self.currentbookmarks, tr)
-                if self.activebookmark not in repo._bookmarks:
-                    # active bookmark was divergent one and has been deleted
-                    self.activebookmark = None
-
         if not self.keepf:
             collapsedas = None
             if self.collapsef:
@@ -546,7 +523,7 @@
             skippedlen = len(self.skipped)
             ui.note(_("%d revisions have been skipped\n") % skippedlen)
 
-        if (self.activebookmark and
+        if (self.activebookmark and self.activebookmark in repo._bookmarks and
             repo['.'].node() == repo._bookmarks[self.activebookmark]):
                 bookmarks.activate(repo, self.activebookmark)
 
@@ -1089,16 +1066,6 @@
         mq.seriesdirty = True
         mq.savedirty()
 
-def updatebookmarks(repo, destnode, nstate, originalbookmarks, tr):
-    'Move bookmarks to their correct changesets, and delete divergent ones'
-    marks = repo._bookmarks
-    for k, v in originalbookmarks.iteritems():
-        if v in nstate:
-            # update the bookmarks for revs that have moved
-            marks[k] = nstate[v]
-            bookmarks.deletedivergent(repo, [destnode], k)
-    marks.recordchange(tr)
-
 def storecollapsemsg(repo, collapsemsg):
     'Store the collapse message to allow recovery'
     collapsemsg = collapsemsg or ''
@@ -1325,34 +1292,19 @@
 
     If `collapsedas` is not None, the rebase was a collapse whose result if the
     `collapsedas` node."""
-    if obsolete.isenabled(repo, obsolete.createmarkersopt):
-        markers = []
+    tonode = repo.changelog.node
+    mapping = {}
+    if True:
         for rev, newrev in sorted(state.items()):
             if newrev >= 0 and newrev != rev:
                 if rev in skipped:
                     succs = ()
                 elif collapsedas is not None:
-                    succs = (repo[collapsedas],)
+                    succs = (collapsedas,)
                 else:
-                    succs = (repo[newrev],)
-                markers.append((repo[rev], succs))
-        if markers:
-            obsolete.createmarkers(repo, markers, operation='rebase')
-    else:
-        rebased = [rev for rev in state
-                   if state[rev] > nullmerge and state[rev] != rev]
-        if rebased:
-            stripped = []
-            for root in repo.set('roots(%ld)', rebased):
-                if set(repo.changelog.descendants([root.rev()])) - set(state):
-                    ui.warn(_("warning: new changesets detected "
-                              "on source branch, not stripping\n"))
-                else:
-                    stripped.append(root.node())
-            if stripped:
-                # backup the old csets by default
-                repair.strip(ui, repo, stripped, "all")
-
+                    succs = (tonode(newrev),)
+                mapping[tonode(rev)] = succs
+        scmutil.cleanupnodes(repo, mapping, 'rebase')
 
 def pullrebase(orig, ui, repo, *args, **opts):
     'Call rebase after pull if the latter has been invoked with --rebase'