comparison hgext/rebase.py @ 45548:25e365d5aa8f

rebase: add dryrun property to rebaseruntime I want to be able to check the property in `rebaseruntime._rebasenode()`. Passing the value via the runtime is a convenient way. Differential Revision: https://phab.mercurial-scm.org/D9074
author Martin von Zweigbergk <martinvonz@google.com>
date Fri, 18 Sep 2020 15:40:26 -0700
parents 2dcf595f6985
children e9468f14379a
comparison
equal deleted inserted replaced
45547:2dcf595f6985 45548:25e365d5aa8f
164 164
165 165
166 class rebaseruntime(object): 166 class rebaseruntime(object):
167 """This class is a container for rebase runtime state""" 167 """This class is a container for rebase runtime state"""
168 168
169 def __init__(self, repo, ui, inmemory=False, opts=None): 169 def __init__(self, repo, ui, inmemory=False, dryrun=False, opts=None):
170 if opts is None: 170 if opts is None:
171 opts = {} 171 opts = {}
172 172
173 # prepared: whether we have rebasestate prepared or not. Currently it 173 # prepared: whether we have rebasestate prepared or not. Currently it
174 # decides whether "self.repo" is unfiltered or not. 174 # decides whether "self.repo" is unfiltered or not.
210 repo.ui, b'rebase' 210 repo.ui, b'rebase'
211 ) 211 )
212 self.obsoletenotrebased = {} 212 self.obsoletenotrebased = {}
213 self.obsoletewithoutsuccessorindestination = set() 213 self.obsoletewithoutsuccessorindestination = set()
214 self.inmemory = inmemory 214 self.inmemory = inmemory
215 self.dryrun = dryrun
215 self.stateobj = statemod.cmdstate(repo, b'rebasestate') 216 self.stateobj = statemod.cmdstate(repo, b'rebasestate')
216 217
217 @property 218 @property
218 def repo(self): 219 def repo(self):
219 if self.prepared: 220 if self.prepared:
1086 else: 1087 else:
1087 return _dorebase(ui, repo, action, opts) 1088 return _dorebase(ui, repo, action, opts)
1088 1089
1089 1090
1090 def _dryrunrebase(ui, repo, action, opts): 1091 def _dryrunrebase(ui, repo, action, opts):
1091 rbsrt = rebaseruntime(repo, ui, inmemory=True, opts=opts) 1092 rbsrt = rebaseruntime(repo, ui, inmemory=True, dryrun=True, opts=opts)
1092 confirm = opts.get(b'confirm') 1093 confirm = opts.get(b'confirm')
1093 if confirm: 1094 if confirm:
1094 ui.status(_(b'starting in-memory rebase\n')) 1095 ui.status(_(b'starting in-memory rebase\n'))
1095 else: 1096 else:
1096 ui.status( 1097 ui.status(
1100 needsabort = True 1101 needsabort = True
1101 try: 1102 try:
1102 overrides = {(b'rebase', b'singletransaction'): True} 1103 overrides = {(b'rebase', b'singletransaction'): True}
1103 with ui.configoverride(overrides, b'rebase'): 1104 with ui.configoverride(overrides, b'rebase'):
1104 _origrebase( 1105 _origrebase(
1105 ui, repo, action, opts, rbsrt, leaveunfinished=True, 1106 ui, repo, action, opts, rbsrt,
1106 ) 1107 )
1107 except error.InMemoryMergeConflictsError: 1108 except error.InMemoryMergeConflictsError:
1108 ui.status(_(b'hit a merge conflict\n')) 1109 ui.status(_(b'hit a merge conflict\n'))
1109 return 1 1110 return 1
1110 except error.Abort: 1111 except error.Abort:
1142 dryrun=opts.get(b'dry_run'), 1143 dryrun=opts.get(b'dry_run'),
1143 ) 1144 )
1144 1145
1145 1146
1146 def _dorebase(ui, repo, action, opts, inmemory=False): 1147 def _dorebase(ui, repo, action, opts, inmemory=False):
1147 rbsrt = rebaseruntime(repo, ui, inmemory, opts) 1148 rbsrt = rebaseruntime(repo, ui, inmemory, opts=opts)
1148 return _origrebase(ui, repo, action, opts, rbsrt) 1149 return _origrebase(ui, repo, action, opts, rbsrt)
1149 1150
1150 1151
1151 def _origrebase(ui, repo, action, opts, rbsrt, leaveunfinished=False): 1152 def _origrebase(ui, repo, action, opts, rbsrt):
1152 assert action != b'stop' 1153 assert action != b'stop'
1153 with repo.wlock(), repo.lock(): 1154 with repo.wlock(), repo.lock():
1154 if opts.get(b'interactive'): 1155 if opts.get(b'interactive'):
1155 try: 1156 try:
1156 if extensions.find(b'histedit'): 1157 if extensions.find(b'histedit'):
1220 dsguard = None 1221 dsguard = None
1221 if singletr and not rbsrt.inmemory: 1222 if singletr and not rbsrt.inmemory:
1222 dsguard = dirstateguard.dirstateguard(repo, b'rebase') 1223 dsguard = dirstateguard.dirstateguard(repo, b'rebase')
1223 with util.acceptintervention(dsguard): 1224 with util.acceptintervention(dsguard):
1224 rbsrt._performrebase(tr) 1225 rbsrt._performrebase(tr)
1225 if not leaveunfinished: 1226 if not rbsrt.dryrun:
1226 rbsrt._finishrebase() 1227 rbsrt._finishrebase()
1227 1228
1228 1229
1229 def _definedestmap(ui, repo, inmemory, destf, srcf, basef, revf, destspace): 1230 def _definedestmap(ui, repo, inmemory, destf, srcf, basef, revf, destspace):
1230 """use revisions argument to define destmap {srcrev: destrev}""" 1231 """use revisions argument to define destmap {srcrev: destrev}"""