From patchwork Tue Jul 18 15:09:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: D134: rebase: add config to move rebase into a single transaction From: phabricator X-Patchwork-Id: 22492 Message-Id: To: mercurial-devel@mercurial-scm.org Date: Tue, 18 Jul 2017 15:09:27 +0000 durham created this revision. Herald added a subscriber: mercurial-devel. Herald added a reviewer: hg-reviewers. REVISION SUMMARY This was previously landed as https://phab.mercurial-scm.org/rHGcf8ad0e6c0e4555809c8e7232c8819ecf152bf1b but backed out in https://phab.mercurial-scm.org/rHGa5abaa81fad665602821b939ca4101d48f4d0ef7 because it broke hook mid rebase and caused conflict resolution data loss in the event of unexpected exceptions. This new version adds the behavior back but behind a config flag, since the performance improvement is notable in large repositories. The next patch adds a test covering this config. The old commit message was: 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. (grafted from cca36c7f35261b0e31beb226bf361067ef0e06ab) (grafted from dc497d8705b71503e32e07bd33925c1e42cf9c9a) REPOSITORY rHG Mercurial REVISION DETAIL https://phab.mercurial-scm.org/D134 AFFECTED FILES hgext/rebase.py mercurial/util.py CHANGE DETAILS EMAIL PREFERENCES https://phab.mercurial-scm.org/settings/panel/emailpreferences/ To: durham, #hg-reviewers Cc: mercurial-devel diff --git a/mercurial/util.py b/mercurial/util.py --- a/mercurial/util.py +++ b/mercurial/util.py @@ -602,6 +602,20 @@ finally: tr.release() +class nullcontextmanager(object): + """A no-op context manager. + """ + def __enter__(self): + return self + def __exit__(self, exc_type, exc_val, exc_tb): + pass + def close(self): + pass + def release(self): + pass + def abort(self): + pass + class _lrucachenode(object): """A node in a doubly linked list. diff --git a/hgext/rebase.py b/hgext/rebase.py --- a/hgext/rebase.py +++ b/hgext/rebase.py @@ -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 @@ -394,7 +394,7 @@ self.state, self.destancestors, 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') @@ -641,6 +641,15 @@ [commands] rebase.requiredest = True + By default, rebase will close the transaction after each commit. For + performance purposes, you can configure rebase to use a single transaction + across the entire rebase. WARNING: This setting introduces a significant + risk of losing the work you've done in a rebase if the rebase aborts + unexpectedly:: + + [rebase] + singletransaction = True + Return Values: Returns 0 on success, 1 if nothing to rebase or there are @@ -700,7 +709,14 @@ if retcode is not None: return retcode - rbsrt._performrebase() + singletr = ui.configbool('rebase', 'singletransaction') + if singletr: + tr = repo.transaction('rebase') + else: + tr = util.nullcontextmanager() + with util.acceptintervention(tr): + rbsrt._performrebase(tr if singletr else None) + rbsrt._finishrebase() def _definesets(ui, repo, destf=None, srcf=None, basef=None, revf=None,