changeset 35396:dd11df900f7f

rebase: replace --inmemory flag with rebase.experimental.inmemory config Differential Revision: https://phab.mercurial-scm.org/D1666
author Phil Cohen <phillco@fb.com>
date Mon, 11 Dec 2017 22:16:13 -0800
parents c0c6df81c9bb
children b963750b125f
files hgext/rebase.py mercurial/configitems.py tests/test-rebase-inmemory.t
diffstat 3 files changed, 32 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/rebase.py	Mon Dec 11 09:37:11 2017 -0500
+++ b/hgext/rebase.py	Mon Dec 11 22:16:13 2017 -0800
@@ -136,7 +136,7 @@
 
 class rebaseruntime(object):
     """This class is a container for rebase runtime state"""
-    def __init__(self, repo, ui, opts=None):
+    def __init__(self, repo, ui, inmemory=False, opts=None):
         if opts is None:
             opts = {}
 
@@ -179,7 +179,7 @@
         self.keepopen = opts.get('keepopen', False)
         self.obsoletenotrebased = {}
         self.obsoletewithoutsuccessorindestination = set()
-        self.inmemory = opts.get('inmemory', False)
+        self.inmemory = inmemory
 
     @property
     def repo(self):
@@ -645,7 +645,6 @@
     ('i', 'interactive', False, _('(DEPRECATED)')),
     ('t', 'tool', '', _('specify merge tool')),
     ('c', 'continue', False, _('continue an interrupted rebase')),
-    ('',  'inmemory', False, _('run rebase in-memory (EXPERIMENTAL)')),
     ('a', 'abort', False, _('abort an interrupted rebase'))] +
     cmdutil.formatteropts,
     _('[-s REV | -b REV] [-d REV] [OPTION]'))
@@ -757,35 +756,40 @@
       [rebase]
       singletransaction = True
 
+    By default, rebase writes to the working copy, but you can configure it to
+    run in-memory for for better performance, and to allow it to run if the
+    working copy is dirty::
+
+      [rebase]
+      experimental.inmemory = True
+
     Return Values:
 
     Returns 0 on success, 1 if nothing to rebase or there are
     unresolved conflicts.
 
     """
+    inmemory = ui.configbool('rebase', 'experimental.inmemory')
     if opts.get('continue') or opts.get('abort'):
         # in-memory rebase is not compatible with resuming rebases.
-        opts['inmemory'] = False
+        inmemory = False
 
-    if opts.get('inmemory', False):
+    if inmemory:
         try:
             # in-memory merge doesn't support conflicts, so if we hit any, abort
             # and re-run as an on-disk merge.
-            return _origrebase(ui, repo, **opts)
+            return _origrebase(ui, repo, inmemory=inmemory, **opts)
         except error.InMemoryMergeConflictsError:
             ui.warn(_('hit merge conflicts; re-running rebase without in-memory'
                       ' merge\n'))
             _origrebase(ui, repo, **{'abort': True})
-            opts['inmemory'] = False
-            return _origrebase(ui, repo, **opts)
+            return _origrebase(ui, repo, inmemory=False, **opts)
     else:
         return _origrebase(ui, repo, **opts)
 
-def _origrebase(ui, repo, **opts):
+def _origrebase(ui, repo, inmemory=False, **opts):
     opts = pycompat.byteskwargs(opts)
-    if 'inmemory' not in opts:
-        opts['inmemory'] = False
-    rbsrt = rebaseruntime(repo, ui, opts)
+    rbsrt = rebaseruntime(repo, ui, inmemory, opts)
 
     with repo.wlock(), repo.lock():
         # Validate input and define rebasing points
@@ -832,10 +836,8 @@
             if retcode is not None:
                 return retcode
         else:
-            destmap = _definedestmap(ui, repo, destf, srcf, basef, revf,
-                                     destspace=destspace,
-                                     opts=opts)
-            rbsrt.inmemory = opts['inmemory']
+            destmap = _definedestmap(ui, repo, rbsrt, destf, srcf, basef, revf,
+                                     destspace=destspace)
             retcode = rbsrt._preparenewrebase(destmap)
             if retcode is not None:
                 return retcode
@@ -854,8 +856,8 @@
 
         rbsrt._finishrebase()
 
-def _definedestmap(ui, repo, destf=None, srcf=None, basef=None, revf=None,
-                   destspace=None, opts=None):
+def _definedestmap(ui, repo, rbsrt, destf=None, srcf=None, basef=None,
+                   revf=None, destspace=None):
     """use revisions argument to define destmap {srcrev: destrev}"""
     if revf is None:
         revf = []
@@ -869,7 +871,7 @@
     if revf and srcf:
         raise error.Abort(_('cannot specify both a revision and a source'))
 
-    if not opts['inmemory']:
+    if not rbsrt.inmemory:
         cmdutil.checkunfinished(repo)
         cmdutil.bailifchanged(repo)
 
@@ -955,8 +957,8 @@
     # stacks that include the WCP. However, I'm not yet sure where the cutoff
     # is.
     rebasingwcp = repo['.'].rev() in rebaseset
-    if opts['inmemory'] and rebasingwcp:
-        opts['inmemory'] = False
+    if rbsrt.inmemory and rebasingwcp:
+        rbsrt.inmemory = False
         # Check these since we did not before.
         cmdutil.checkunfinished(repo)
         cmdutil.bailifchanged(repo)
--- a/mercurial/configitems.py	Mon Dec 11 09:37:11 2017 -0500
+++ b/mercurial/configitems.py	Mon Dec 11 22:16:13 2017 -0800
@@ -1269,3 +1269,6 @@
 coreconfigitem('rebase', 'singletransaction',
     default=False,
 )
+coreconfigitem('rebase', 'experimental.inmemory',
+    default=False,
+)
--- a/tests/test-rebase-inmemory.t	Mon Dec 11 09:37:11 2017 -0500
+++ b/tests/test-rebase-inmemory.t	Mon Dec 11 22:16:13 2017 -0800
@@ -4,6 +4,8 @@
   > amend=
   > rebase=
   > debugdrawdag=$TESTDIR/drawdag.py
+  > [rebase]
+  > experimental.inmemory=1
   > [diff]
   > git=1
   > [alias]
@@ -35,7 +37,7 @@
   c (no-eol)
   $ hg cat -r 2 b
   b (no-eol)
-  $ hg rebase --inmemory --debug -r b -d c | grep rebasing
+  $ hg rebase --debug -r b -d c | grep rebasing
   rebasing in-memory
   rebasing 2:db0e82a16a62 "b" (b)
   $ hg tglog
@@ -94,7 +96,7 @@
   b (no-eol)
   $ hg cat -r 3 e
   somefile (no-eol)
-  $ hg rebase --inmemory --debug -s b -d a | grep rebasing
+  $ hg rebase --debug -s b -d a | grep rebasing
   rebasing in-memory
   rebasing 2:db0e82a16a62 "b" (b)
   $ hg tglog
@@ -110,7 +112,7 @@
   c (no-eol)
   $ hg cat -r 3 b
   b (no-eol)
-  $ hg rebase --inmemory --debug -s 1 -d 3 | grep rebasing
+  $ hg rebase --debug -s 1 -d 3 | grep rebasing
   rebasing in-memory
   rebasing 1:02952614a83d "d" (d)
   rebasing 2:f56b71190a8f "c"
@@ -142,7 +144,7 @@
 we requested in-memory.
   $ hg up -C 3
   0 files updated, 0 files merged, 0 files removed, 0 files unresolved
-  $ hg rebase -r 3 -d 0 --inmemory --debug | grep rebasing
+  $ hg rebase -r 3 -d 0 --debug | grep rebasing
   rebasing on disk
   rebasing 3:753feb6fd12a "c" (tip)
   $ hg tglog