rebase: move actual rebase into a single transaction
authorDurham Goode <durham@fb.com>
Tue, 07 Mar 2017 16:27:32 -0800
changeset 31226 cf8ad0e6c0e4
parent 31225 749b057b01f3
child 31227 ac47df82bdba
rebase: move actual rebase into a single transaction Previously, rebasing would open several transaction over the course of rebasing several commits. Opening a transaction can have notable overhead (like copying the dirstate) which can add up when rebasing many commits. This patch adds a single large transaction around the actual commit rebase operation, with a catch for intervention which serializes the current state if we need to drop back to the terminal for user intervention. Amazingly, almost all the tests seem to pass. On large repos with large working copies, this can speed up rebasing 7 commits by 25%. I'd expect the percentage to be a bit larger for rebasing even more commits. There are minor test changes because we're rolling back the entire transaction during unexpected exceptions instead of just stopping mid-rebase, so there's no more backup bundle. It also leave an unknown file in the working copy, since our clean up 'hg update' doesn't delete unknown files.
hgext/rebase.py
tests/test-rebase-abort.t
tests/test-rebase-conflicts.t
--- a/hgext/rebase.py	Tue Mar 07 16:30:31 2017 -0800
+++ b/hgext/rebase.py	Tue Mar 07 16:27:32 2017 -0800
@@ -343,7 +343,7 @@
         if dest.closesbranch() and not self.keepbranchesf:
             self.ui.status(_('reopening closed branch head %s\n') % dest)
 
-    def _performrebase(self):
+    def _performrebase(self, tr):
         repo, ui, opts = self.repo, self.ui, self.opts
         if self.keepbranchesf:
             # insert _savebranch at the start of extrafns so if
@@ -393,7 +393,7 @@
                                              self.state,
                                              self.targetancestors,
                                              self.obsoletenotrebased)
-                self.storestatus()
+                self.storestatus(tr=tr)
                 storecollapsemsg(repo, self.collapsemsg)
                 if len(repo[None].parents()) == 2:
                     repo.ui.debug('resuming interrupted rebase\n')
@@ -711,7 +711,12 @@
             if retcode is not None:
                 return retcode
 
-        rbsrt._performrebase()
+        with repo.transaction('rebase') as tr:
+            try:
+                rbsrt._performrebase(tr)
+            except error.InterventionRequired:
+                tr.close()
+                raise
         rbsrt._finishrebase()
     finally:
         release(lock, wlock)
--- a/tests/test-rebase-abort.t	Tue Mar 07 16:30:31 2017 -0800
+++ b/tests/test-rebase-abort.t	Tue Mar 07 16:27:32 2017 -0800
@@ -374,10 +374,11 @@
   $ hg --config extensions.n=$TESTDIR/failfilemerge.py rebase -s 3 -d tip
   rebasing 3:3a71550954f1 "b"
   rebasing 4:e80b69427d80 "c"
+  transaction abort!
+  rollback completed
   abort: ^C
   [255]
   $ hg rebase --abort
-  saved backup bundle to $TESTTMP/interrupted/.hg/strip-backup/3d8812cf300d-93041a90-backup.hg (glob)
   rebase aborted
   $ hg log -G --template "{rev} {desc} {bookmarks}"
   o  6 no-a
@@ -398,7 +399,7 @@
   parent: 0:df4f53cec30a 
    base
   branch: default
-  commit: (clean)
+  commit: 1 unknown (clean)
   update: 6 new changesets (update)
   phases: 7 draft
 
--- a/tests/test-rebase-conflicts.t	Tue Mar 07 16:30:31 2017 -0800
+++ b/tests/test-rebase-conflicts.t	Tue Mar 07 16:27:32 2017 -0800
@@ -225,7 +225,6 @@
   ignoring null merge rebase of 8
   rebasing 9:e31216eec445 "more changes to f1"
    future parents are 2 and -1
-  rebase status stored
    update to 2:4bc80088dc6b
   resolving manifests
    branchmerge: False, force: True, partial: False
@@ -251,7 +250,6 @@
   rebased as 19c888675e13
   rebasing 10:2f2496ddf49d "merge" (tip)
    future parents are 11 and 7
-  rebase status stored
    already in target
    merge against 10:2f2496ddf49d
      detach base 9:e31216eec445
@@ -269,6 +267,7 @@
   committing changelog
   rebased as 2a7f09cac94c
   rebase merging completed
+  rebase status stored
   update back to initial working directory parent
   resolving manifests
    branchmerge: False, force: False, partial: False