Mercurial > hg
comparison hgext/rebase.py @ 37033:5f99142f59cc
rebase: extract common _concludenode()
_rebasenode() and _finishrebase() had a lot of code in common. This
commit extracts some of that. This means we will also have a single
caller of concludenode() and concludememorynode(), which gives us a
place to put code that is common between those two functions (which is
quite a bit).
Differential Revision: https://phab.mercurial-scm.org/D2914
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Wed, 21 Mar 2018 11:03:31 -0700 |
parents | 98663bed146e |
children | fbc82a08bdcb |
comparison
equal
deleted
inserted
replaced
37032:98663bed146e | 37033:5f99142f59cc |
---|---|
445 ) | 445 ) |
446 for rev in sortedrevs: | 446 for rev in sortedrevs: |
447 self._rebasenode(tr, rev, allowdivergence, progress) | 447 self._rebasenode(tr, rev, allowdivergence, progress) |
448 ui.progress(_('rebasing'), None) | 448 ui.progress(_('rebasing'), None) |
449 ui.note(_('rebase merging completed\n')) | 449 ui.note(_('rebase merging completed\n')) |
450 | |
451 def _concludenode(self, rev, p1, p2, editor, commitmsg=None): | |
452 '''Commit the wd changes with parents p1 and p2. | |
453 | |
454 Reuse commit info from rev but also store useful information in extra. | |
455 Return node of committed revision.''' | |
456 repo = self.repo | |
457 if self.inmemory: | |
458 newnode = concludememorynode(repo, rev, p1, p2, | |
459 wctx=self.wctx, | |
460 extrafn=_makeextrafn(self.extrafns), | |
461 commitmsg=commitmsg, | |
462 editor=editor, | |
463 keepbranches=self.keepbranchesf, | |
464 date=self.date) | |
465 mergemod.mergestate.clean(repo) | |
466 else: | |
467 newnode = concludenode(repo, rev, p1, p2, | |
468 extrafn=_makeextrafn(self.extrafns), | |
469 commitmsg=commitmsg, | |
470 editor=editor, | |
471 keepbranches=self.keepbranchesf, | |
472 date=self.date) | |
473 | |
474 if newnode is None: | |
475 # If it ended up being a no-op commit, then the normal | |
476 # merge state clean-up path doesn't happen, so do it | |
477 # here. Fix issue5494 | |
478 mergemod.mergestate.clean(repo) | |
479 return newnode | |
450 | 480 |
451 def _rebasenode(self, tr, rev, allowdivergence, progressfn): | 481 def _rebasenode(self, tr, rev, allowdivergence, progressfn): |
452 repo, ui, opts = self.repo, self.ui, self.opts | 482 repo, ui, opts = self.repo, self.ui, self.opts |
453 dest = self.destmap[rev] | 483 dest = self.destmap[rev] |
454 ctx = repo[rev] | 484 ctx = repo[rev] |
501 if not self.collapsef: | 531 if not self.collapsef: |
502 merging = p2 != nullrev | 532 merging = p2 != nullrev |
503 editform = cmdutil.mergeeditform(merging, 'rebase') | 533 editform = cmdutil.mergeeditform(merging, 'rebase') |
504 editor = cmdutil.getcommiteditor(editform=editform, | 534 editor = cmdutil.getcommiteditor(editform=editform, |
505 **pycompat.strkwargs(opts)) | 535 **pycompat.strkwargs(opts)) |
506 if self.inmemory: | 536 newnode = self._concludenode(rev, p1, p2, editor) |
507 newnode = concludememorynode(repo, rev, p1, p2, | |
508 wctx=self.wctx, | |
509 extrafn=_makeextrafn(self.extrafns), | |
510 editor=editor, | |
511 keepbranches=self.keepbranchesf, | |
512 date=self.date) | |
513 mergemod.mergestate.clean(repo) | |
514 else: | |
515 newnode = concludenode(repo, rev, p1, p2, | |
516 extrafn=_makeextrafn(self.extrafns), | |
517 editor=editor, | |
518 keepbranches=self.keepbranchesf, | |
519 date=self.date) | |
520 | |
521 if newnode is None: | |
522 # If it ended up being a no-op commit, then the normal | |
523 # merge state clean-up path doesn't happen, so do it | |
524 # here. Fix issue5494 | |
525 mergemod.mergestate.clean(repo) | |
526 else: | 537 else: |
527 # Skip commit if we are collapsing | 538 # Skip commit if we are collapsing |
528 if self.inmemory: | 539 if self.inmemory: |
529 self.wctx.setbase(repo[p1]) | 540 self.wctx.setbase(repo[p1]) |
530 else: | 541 else: |
570 commitmsg += '\n* %s' % repo[rebased].description() | 581 commitmsg += '\n* %s' % repo[rebased].description() |
571 editopt = True | 582 editopt = True |
572 editor = cmdutil.getcommiteditor(edit=editopt, editform=editform) | 583 editor = cmdutil.getcommiteditor(edit=editopt, editform=editform) |
573 revtoreuse = max(self.state) | 584 revtoreuse = max(self.state) |
574 | 585 |
575 if self.inmemory: | 586 newnode = self._concludenode(revtoreuse, p1, self.external, |
576 newnode = concludememorynode(repo, revtoreuse, p1, | 587 editor, commitmsg=commitmsg) |
577 self.external, | 588 |
578 commitmsg=commitmsg, | |
579 extrafn=_makeextrafn(self.extrafns), | |
580 editor=editor, | |
581 keepbranches=self.keepbranchesf, | |
582 date=self.date, wctx=self.wctx) | |
583 else: | |
584 newnode = concludenode(repo, revtoreuse, p1, self.external, | |
585 commitmsg=commitmsg, | |
586 extrafn=_makeextrafn(self.extrafns), | |
587 editor=editor, | |
588 keepbranches=self.keepbranchesf, | |
589 date=self.date) | |
590 | |
591 if newnode is None: | |
592 # If it ended up being a no-op commit, then the normal | |
593 # merge state clean-up path doesn't happen, so do it | |
594 # here. Fix issue5494 | |
595 mergemod.mergestate.clean(repo) | |
596 if newnode is not None: | 589 if newnode is not None: |
597 newrev = repo[newnode].rev() | 590 newrev = repo[newnode].rev() |
598 for oldrev in self.state: | 591 for oldrev in self.state: |
599 self.state[oldrev] = newrev | 592 self.state[oldrev] = newrev |
600 | 593 |