comparison hgext/rebase.py @ 38515:19076e2d62e7

rebase: refactor logic to read rebasestate in a separate function This will help us in plugging the use of state.cmdstate() to read rebasestate. Differential Revision: https://phab.mercurial-scm.org/D3873
author Pulkit Goyal <7895pulkit@gmail.com>
date Sun, 01 Jul 2018 00:31:57 +0530
parents 39db5a01cd53
children 7c853edcf4ed
comparison
equal deleted inserted replaced
38514:cc3543c87de5 38515:19076e2d62e7
223 f.write("%s:%s:%s\n" % (oldrev, newrev, destnode)) 223 f.write("%s:%s:%s\n" % (oldrev, newrev, destnode))
224 repo.ui.debug('rebase status stored\n') 224 repo.ui.debug('rebase status stored\n')
225 225
226 def restorestatus(self): 226 def restorestatus(self):
227 """Restore a previously stored status""" 227 """Restore a previously stored status"""
228 data = self._read()
229 self.repo.ui.debug('rebase status resumed\n')
230
231 self.originalwd = data['originalwd']
232 self.destmap = data['destmap']
233 self.state = data['state']
234 self.skipped = data['skipped']
235 self.collapsef = data['collapse']
236 self.keepf = data['keep']
237 self.keepbranchesf = data['keepbranches']
238 self.external = data['external']
239 self.activebookmark = data['activebookmark']
240
241 def _read(self):
228 self.prepared = True 242 self.prepared = True
229 repo = self.repo 243 repo = self.repo
230 assert repo.filtername is None 244 assert repo.filtername is None
231 keepbranches = None 245 data = {'keepbranches': None, 'collapse': None, 'activebookmark': None,
246 'external': nullrev, 'keep': None, 'originalwd': None}
232 legacydest = None 247 legacydest = None
233 collapse = False
234 external = nullrev
235 activebookmark = None
236 state = {} 248 state = {}
237 destmap = {} 249 destmap = {}
238 250
239 try: 251 try:
240 f = repo.vfs("rebasestate") 252 f = repo.vfs("rebasestate")
241 for i, l in enumerate(f.read().splitlines()): 253 for i, l in enumerate(f.read().splitlines()):
242 if i == 0: 254 if i == 0:
243 originalwd = repo[l].rev() 255 data['originalwd'] = repo[l].rev()
244 elif i == 1: 256 elif i == 1:
245 # this line should be empty in newer version. but legacy 257 # this line should be empty in newer version. but legacy
246 # clients may still use it 258 # clients may still use it
247 if l: 259 if l:
248 legacydest = repo[l].rev() 260 legacydest = repo[l].rev()
249 elif i == 2: 261 elif i == 2:
250 external = repo[l].rev() 262 data['external'] = repo[l].rev()
251 elif i == 3: 263 elif i == 3:
252 collapse = bool(int(l)) 264 data['collapse'] = bool(int(l))
253 elif i == 4: 265 elif i == 4:
254 keep = bool(int(l)) 266 data['keep'] = bool(int(l))
255 elif i == 5: 267 elif i == 5:
256 keepbranches = bool(int(l)) 268 data['keepbranches'] = bool(int(l))
257 elif i == 6 and not (len(l) == 81 and ':' in l): 269 elif i == 6 and not (len(l) == 81 and ':' in l):
258 # line 6 is a recent addition, so for backwards 270 # line 6 is a recent addition, so for backwards
259 # compatibility check that the line doesn't look like the 271 # compatibility check that the line doesn't look like the
260 # oldrev:newrev lines 272 # oldrev:newrev lines
261 activebookmark = l 273 data['activebookmark'] = l
262 else: 274 else:
263 args = l.split(':') 275 args = l.split(':')
264 oldrev = repo[args[0]].rev() 276 oldrev = repo[args[0]].rev()
265 newrev = args[1] 277 newrev = args[1]
266 if newrev in legacystates: 278 if newrev in legacystates:
279 except IOError as err: 291 except IOError as err:
280 if err.errno != errno.ENOENT: 292 if err.errno != errno.ENOENT:
281 raise 293 raise
282 cmdutil.wrongtooltocontinue(repo, _('rebase')) 294 cmdutil.wrongtooltocontinue(repo, _('rebase'))
283 295
284 if keepbranches is None: 296 if data['keepbranches'] is None:
285 raise error.Abort(_('.hg/rebasestate is incomplete')) 297 raise error.Abort(_('.hg/rebasestate is incomplete'))
286 298
299 data['destmap'] = destmap
300 data['state'] = state
287 skipped = set() 301 skipped = set()
288 # recompute the set of skipped revs 302 # recompute the set of skipped revs
289 if not collapse: 303 if not data['collapse']:
290 seen = set(destmap.values()) 304 seen = set(destmap.values())
291 for old, new in sorted(state.items()): 305 for old, new in sorted(state.items()):
292 if new != revtodo and new in seen: 306 if new != revtodo and new in seen:
293 skipped.add(old) 307 skipped.add(old)
294 seen.add(new) 308 seen.add(new)
309 data['skipped'] = skipped
295 repo.ui.debug('computed skipped revs: %s\n' % 310 repo.ui.debug('computed skipped revs: %s\n' %
296 (' '.join('%d' % r for r in sorted(skipped)) or '')) 311 (' '.join('%d' % r for r in sorted(skipped)) or ''))
297 repo.ui.debug('rebase status resumed\n') 312
298 313 return data
299 self.originalwd = originalwd
300 self.destmap = destmap
301 self.state = state
302 self.skipped = skipped
303 self.collapsef = collapse
304 self.keepf = keep
305 self.keepbranchesf = keepbranches
306 self.external = external
307 self.activebookmark = activebookmark
308 314
309 def _handleskippingobsolete(self, obsoleterevs, destmap): 315 def _handleskippingobsolete(self, obsoleterevs, destmap):
310 """Compute structures necessary for skipping obsolete revisions 316 """Compute structures necessary for skipping obsolete revisions
311 317
312 obsoleterevs: iterable of all obsolete revisions in rebaseset 318 obsoleterevs: iterable of all obsolete revisions in rebaseset