Mercurial > hg
comparison hgext/rebase.py @ 29359:d2168849539d
rebase: move local variable 'target' to the RR class
author | Kostia Balytskyi <ikostia@fb.com> |
---|---|
date | Mon, 13 Jun 2016 22:38:54 +0100 |
parents | 6e83f5bbed8d |
children | 4cbe62ab5c97 |
comparison
equal
deleted
inserted
replaced
29358:6e83f5bbed8d | 29359:d2168849539d |
---|---|
127 # Mapping between the old revision id and either what is the new rebased | 127 # Mapping between the old revision id and either what is the new rebased |
128 # revision or what needs to be done with the old revision. The state | 128 # revision or what needs to be done with the old revision. The state |
129 # dict will be what contains most of the rebase progress state. | 129 # dict will be what contains most of the rebase progress state. |
130 self.state = {} | 130 self.state = {} |
131 self.activebookmark = None | 131 self.activebookmark = None |
132 self.target = None | |
132 | 133 |
133 @command('rebase', | 134 @command('rebase', |
134 [('s', 'source', '', | 135 [('s', 'source', '', |
135 _('rebase the specified changeset and descendants'), _('REV')), | 136 _('rebase the specified changeset and descendants'), _('REV')), |
136 ('b', 'base', '', | 137 ('b', 'base', '', |
239 Returns 0 on success, 1 if nothing to rebase or there are | 240 Returns 0 on success, 1 if nothing to rebase or there are |
240 unresolved conflicts. | 241 unresolved conflicts. |
241 | 242 |
242 """ | 243 """ |
243 rbsrt = rebaseruntime() | 244 rbsrt = rebaseruntime() |
244 target = None | |
245 skipped = set() | 245 skipped = set() |
246 targetancestors = set() | 246 targetancestors = set() |
247 | 247 |
248 | 248 |
249 lock = wlock = None | 249 lock = wlock = None |
300 _('abort and continue do not allow specifying revisions')) | 300 _('abort and continue do not allow specifying revisions')) |
301 if abortf and opts.get('tool', False): | 301 if abortf and opts.get('tool', False): |
302 ui.warn(_('tool option will be ignored\n')) | 302 ui.warn(_('tool option will be ignored\n')) |
303 | 303 |
304 try: | 304 try: |
305 (rbsrt.originalwd, target, rbsrt.state, skipped, | 305 (rbsrt.originalwd, rbsrt.target, rbsrt.state, skipped, |
306 collapsef, keepf, keepbranchesf, rbsrt.external, | 306 collapsef, keepf, keepbranchesf, rbsrt.external, |
307 rbsrt.activebookmark) = restorestatus(repo) | 307 rbsrt.activebookmark) = restorestatus(repo) |
308 collapsemsg = restorecollapsemsg(repo) | 308 collapsemsg = restorecollapsemsg(repo) |
309 except error.RepoLookupError: | 309 except error.RepoLookupError: |
310 if abortf: | 310 if abortf: |
316 else: | 316 else: |
317 msg = _('cannot continue inconsistent rebase') | 317 msg = _('cannot continue inconsistent rebase') |
318 hint = _('use "hg rebase --abort" to clear broken state') | 318 hint = _('use "hg rebase --abort" to clear broken state') |
319 raise error.Abort(msg, hint=hint) | 319 raise error.Abort(msg, hint=hint) |
320 if abortf: | 320 if abortf: |
321 return abort(repo, rbsrt.originalwd, target, rbsrt.state, | 321 return abort(repo, rbsrt.originalwd, rbsrt.target, |
322 rbsrt.state, | |
322 activebookmark=rbsrt.activebookmark) | 323 activebookmark=rbsrt.activebookmark) |
323 | 324 |
324 obsoletenotrebased = {} | 325 obsoletenotrebased = {} |
325 if ui.configbool('experimental', 'rebaseskipobsolete', | 326 if ui.configbool('experimental', 'rebaseskipobsolete', |
326 default=True): | 327 default=True): |
327 rebaseobsrevs = set([r for r, st in rbsrt.state.items() | 328 rebaseobsrevs = set([r for r, st in rbsrt.state.items() |
328 if st == revprecursor]) | 329 if st == revprecursor]) |
329 rebasesetrevs = set(rbsrt.state.keys()) | 330 rebasesetrevs = set(rbsrt.state.keys()) |
330 obsoletenotrebased = _computeobsoletenotrebased(repo, | 331 obsoletenotrebased = _computeobsoletenotrebased(repo, |
331 rebaseobsrevs, target) | 332 rebaseobsrevs, rbsrt.target) |
332 rebaseobsskipped = set(obsoletenotrebased) | 333 rebaseobsskipped = set(obsoletenotrebased) |
333 _checkobsrebase(repo, ui, rebaseobsrevs, rebasesetrevs, | 334 _checkobsrebase(repo, ui, rebaseobsrevs, rebasesetrevs, |
334 rebaseobsskipped) | 335 rebaseobsskipped) |
335 else: | 336 else: |
336 dest, rebaseset = _definesets(ui, repo, destf, srcf, basef, revf, | 337 dest, rebaseset = _definesets(ui, repo, destf, srcf, basef, revf, |
372 if not keepf and not repo[root].mutable(): | 373 if not keepf and not repo[root].mutable(): |
373 raise error.Abort(_("can't rebase public changeset %s") | 374 raise error.Abort(_("can't rebase public changeset %s") |
374 % repo[root], | 375 % repo[root], |
375 hint=_('see "hg help phases" for details')) | 376 hint=_('see "hg help phases" for details')) |
376 | 377 |
377 (rbsrt.originalwd, target, rbsrt.state) = result | 378 (rbsrt.originalwd, rbsrt.target, rbsrt.state) = result |
378 if collapsef: | 379 if collapsef: |
379 targetancestors = repo.changelog.ancestors([target], | 380 targetancestors = repo.changelog.ancestors([rbsrt.target], |
380 inclusive=True) | 381 inclusive=True) |
381 rbsrt.external = externalparent(repo, rbsrt.state, | 382 rbsrt.external = externalparent(repo, rbsrt.state, |
382 targetancestors) | 383 targetancestors) |
383 | 384 |
384 if dest.closesbranch() and not keepbranchesf: | 385 if dest.closesbranch() and not keepbranchesf: |
397 raise error.Abort(_('cannot collapse multiple named ' | 398 raise error.Abort(_('cannot collapse multiple named ' |
398 'branches')) | 399 'branches')) |
399 | 400 |
400 # Rebase | 401 # Rebase |
401 if not targetancestors: | 402 if not targetancestors: |
402 targetancestors = repo.changelog.ancestors([target], inclusive=True) | 403 targetancestors = repo.changelog.ancestors([rbsrt.target], |
404 inclusive=True) | |
403 | 405 |
404 # Keep track of the current bookmarks in order to reset them later | 406 # Keep track of the current bookmarks in order to reset them later |
405 currentbookmarks = repo._bookmarks.copy() | 407 currentbookmarks = repo._bookmarks.copy() |
406 rbsrt.activebookmark = rbsrt.activebookmark or repo._activebookmark | 408 rbsrt.activebookmark = rbsrt.activebookmark or repo._activebookmark |
407 if rbsrt.activebookmark: | 409 if rbsrt.activebookmark: |
422 pos += 1 | 424 pos += 1 |
423 if rbsrt.state[rev] == revtodo: | 425 if rbsrt.state[rev] == revtodo: |
424 ui.status(_('rebasing %s\n') % desc) | 426 ui.status(_('rebasing %s\n') % desc) |
425 ui.progress(_("rebasing"), pos, ("%d:%s" % (rev, ctx)), | 427 ui.progress(_("rebasing"), pos, ("%d:%s" % (rev, ctx)), |
426 _('changesets'), total) | 428 _('changesets'), total) |
427 p1, p2, base = defineparents(repo, rev, target, rbsrt.state, | 429 p1, p2, base = defineparents(repo, rev, rbsrt.target, |
430 rbsrt.state, | |
428 targetancestors, | 431 targetancestors, |
429 obsoletenotrebased) | 432 obsoletenotrebased) |
430 storestatus(repo, rbsrt.originalwd, target, rbsrt.state, | 433 storestatus(repo, rbsrt.originalwd, rbsrt.target, |
431 collapsef, keepf, keepbranchesf, | 434 rbsrt.state, collapsef, keepf, keepbranchesf, |
432 rbsrt.external, rbsrt.activebookmark) | 435 rbsrt.external, rbsrt.activebookmark) |
433 storecollapsemsg(repo, collapsemsg) | 436 storecollapsemsg(repo, collapsemsg) |
434 if len(repo[None].parents()) == 2: | 437 if len(repo[None].parents()) == 2: |
435 repo.ui.debug('resuming interrupted rebase\n') | 438 repo.ui.debug('resuming interrupted rebase\n') |
436 else: | 439 else: |
437 try: | 440 try: |
438 ui.setconfig('ui', 'forcemerge', opts.get('tool', ''), | 441 ui.setconfig('ui', 'forcemerge', opts.get('tool', ''), |
439 'rebase') | 442 'rebase') |
440 stats = rebasenode(repo, rev, p1, base, rbsrt.state, | 443 stats = rebasenode(repo, rev, p1, base, rbsrt.state, |
441 collapsef, target) | 444 collapsef, rbsrt.target) |
442 if stats and stats[3] > 0: | 445 if stats and stats[3] > 0: |
443 raise error.InterventionRequired( | 446 raise error.InterventionRequired( |
444 _('unresolved conflicts (see hg ' | 447 _('unresolved conflicts (see hg ' |
445 'resolve, then hg rebase --continue)')) | 448 'resolve, then hg rebase --continue)')) |
446 finally: | 449 finally: |
489 | 492 |
490 ui.progress(_('rebasing'), None) | 493 ui.progress(_('rebasing'), None) |
491 ui.note(_('rebase merging completed\n')) | 494 ui.note(_('rebase merging completed\n')) |
492 | 495 |
493 if collapsef and not keepopen: | 496 if collapsef and not keepopen: |
494 p1, p2, _base = defineparents(repo, min(rbsrt.state), target, | 497 p1, p2, _base = defineparents(repo, min(rbsrt.state), |
495 rbsrt.state, targetancestors, | 498 rbsrt.target, rbsrt.state, |
496 obsoletenotrebased) | 499 targetancestors, obsoletenotrebased) |
497 editopt = opts.get('edit') | 500 editopt = opts.get('edit') |
498 editform = 'rebase.collapse' | 501 editform = 'rebase.collapse' |
499 if collapsemsg: | 502 if collapsemsg: |
500 commitmsg = collapsemsg | 503 commitmsg = collapsemsg |
501 else: | 504 else: |
510 commitmsg=commitmsg, | 513 commitmsg=commitmsg, |
511 extrafn=extrafn, editor=editor, | 514 extrafn=extrafn, editor=editor, |
512 keepbranches=keepbranchesf, | 515 keepbranches=keepbranchesf, |
513 date=date) | 516 date=date) |
514 if newnode is None: | 517 if newnode is None: |
515 newrev = target | 518 newrev = rbsrt.target |
516 else: | 519 else: |
517 newrev = repo[newnode].rev() | 520 newrev = repo[newnode].rev() |
518 for oldrev in rbsrt.state.iterkeys(): | 521 for oldrev in rbsrt.state.iterkeys(): |
519 if rbsrt.state[oldrev] > nullmerge: | 522 if rbsrt.state[oldrev] > nullmerge: |
520 rbsrt.state[oldrev] = newrev | 523 rbsrt.state[oldrev] = newrev |
528 for k, v in rbsrt.state.iteritems(): | 531 for k, v in rbsrt.state.iteritems(): |
529 if v > nullmerge: | 532 if v > nullmerge: |
530 nstate[repo[k].node()] = repo[v].node() | 533 nstate[repo[k].node()] = repo[v].node() |
531 # XXX this is the same as dest.node() for the non-continue path -- | 534 # XXX this is the same as dest.node() for the non-continue path -- |
532 # this should probably be cleaned up | 535 # this should probably be cleaned up |
533 targetnode = repo[target].node() | 536 targetnode = repo[rbsrt.target].node() |
534 | 537 |
535 # restore original working directory | 538 # restore original working directory |
536 # (we do this before stripping) | 539 # (we do this before stripping) |
537 newwd = rbsrt.state.get(rbsrt.originalwd, rbsrt.originalwd) | 540 newwd = rbsrt.state.get(rbsrt.originalwd, rbsrt.originalwd) |
538 if newwd < 0: | 541 if newwd < 0: |