comparison hgext/rebase.py @ 35319:228916ca12b5

rebase: add concludememorynode(), and call it when rebasing in-memory Differential Revision: https://phab.mercurial-scm.org/D1248
author Phil Cohen <phillco@fb.com>
date Thu, 07 Dec 2017 22:35:43 -0800
parents 2bac2d836ce0
children d901a88891fe
comparison
equal deleted inserted replaced
35318:2bac2d836ce0 35319:228916ca12b5
493 ui.setconfig('ui', 'forcemerge', '', 'rebase') 493 ui.setconfig('ui', 'forcemerge', '', 'rebase')
494 if not self.collapsef: 494 if not self.collapsef:
495 merging = p2 != nullrev 495 merging = p2 != nullrev
496 editform = cmdutil.mergeeditform(merging, 'rebase') 496 editform = cmdutil.mergeeditform(merging, 'rebase')
497 editor = cmdutil.getcommiteditor(editform=editform, **opts) 497 editor = cmdutil.getcommiteditor(editform=editform, **opts)
498 newnode = concludenode(repo, rev, p1, p2, 498 if self.wctx.isinmemory():
499 extrafn=_makeextrafn(self.extrafns), 499 newnode = concludememorynode(repo, rev, p1, p2,
500 editor=editor, 500 wctx=self.wctx,
501 keepbranches=self.keepbranchesf, 501 extrafn=_makeextrafn(self.extrafns),
502 date=self.date) 502 editor=editor,
503 keepbranches=self.keepbranchesf,
504 date=self.date)
505 mergemod.mergestate.clean(repo)
506 else:
507 newnode = concludenode(repo, rev, p1, p2,
508 extrafn=_makeextrafn(self.extrafns),
509 editor=editor,
510 keepbranches=self.keepbranchesf,
511 date=self.date)
512
503 if newnode is None: 513 if newnode is None:
504 # If it ended up being a no-op commit, then the normal 514 # If it ended up being a no-op commit, then the normal
505 # merge state clean-up path doesn't happen, so do it 515 # merge state clean-up path doesn't happen, so do it
506 # here. Fix issue5494 516 # here. Fix issue5494
507 mergemod.mergestate.clean(repo) 517 mergemod.mergestate.clean(repo)
550 revtoreuse = max(self.state) 560 revtoreuse = max(self.state)
551 561
552 dsguard = None 562 dsguard = None
553 if ui.configbool('rebase', 'singletransaction'): 563 if ui.configbool('rebase', 'singletransaction'):
554 dsguard = dirstateguard.dirstateguard(repo, 'rebase') 564 dsguard = dirstateguard.dirstateguard(repo, 'rebase')
555 with util.acceptintervention(dsguard): 565 if self.inmemory:
556 newnode = concludenode(repo, revtoreuse, p1, self.external, 566 newnode = concludememorynode(repo, revtoreuse, p1,
557 commitmsg=commitmsg, 567 self.external,
558 extrafn=_makeextrafn(self.extrafns), 568 commitmsg=commitmsg,
559 editor=editor, 569 extrafn=_makeextrafn(self.extrafns),
560 keepbranches=self.keepbranchesf, 570 editor=editor,
561 date=self.date) 571 keepbranches=self.keepbranchesf,
572 date=self.date, wctx=self.wctx)
573 else:
574 with util.acceptintervention(dsguard):
575 newnode = concludenode(repo, revtoreuse, p1, self.external,
576 commitmsg=commitmsg,
577 extrafn=_makeextrafn(self.extrafns),
578 editor=editor,
579 keepbranches=self.keepbranchesf,
580 date=self.date)
562 if newnode is not None: 581 if newnode is not None:
563 newrev = repo[newnode].rev() 582 newrev = repo[newnode].rev()
564 for oldrev in self.state.iterkeys(): 583 for oldrev in self.state.iterkeys():
565 self.state[oldrev] = newrev 584 self.state[oldrev] = newrev
566 585
961 return parents.pop() 980 return parents.pop()
962 raise error.Abort(_('unable to collapse on top of %s, there is more ' 981 raise error.Abort(_('unable to collapse on top of %s, there is more '
963 'than one external parent: %s') % 982 'than one external parent: %s') %
964 (max(destancestors), 983 (max(destancestors),
965 ', '.join(str(p) for p in sorted(parents)))) 984 ', '.join(str(p) for p in sorted(parents))))
985
986 def concludememorynode(repo, rev, p1, p2, wctx=None,
987 commitmsg=None, editor=None, extrafn=None,
988 keepbranches=False, date=None):
989 '''Commit the wd changes with parents p1 and p2. Reuse commit info from rev
990 but also store useful information in extra.
991 Return node of committed revision.'''
992 ctx = repo[rev]
993 if commitmsg is None:
994 commitmsg = ctx.description()
995 keepbranch = keepbranches and repo[p1].branch() != ctx.branch()
996 extra = {'rebase_source': ctx.hex()}
997 if extrafn:
998 extrafn(ctx, extra)
999
1000 destphase = max(ctx.phase(), phases.draft)
1001 overrides = {('phases', 'new-commit'): destphase}
1002 with repo.ui.configoverride(overrides, 'rebase'):
1003 if keepbranch:
1004 repo.ui.setconfig('ui', 'allowemptycommit', True)
1005 # Replicates the empty check in ``repo.commit``.
1006 if wctx.isempty() and not repo.ui.configbool('ui', 'allowemptycommit'):
1007 return None
1008
1009 if date is None:
1010 date = ctx.date()
1011
1012 # By convention, ``extra['branch']`` (set by extrafn) clobbers
1013 # ``branch`` (used when passing ``--keepbranches``).
1014 branch = repo[p1].branch()
1015 if 'branch' in extra:
1016 branch = extra['branch']
1017
1018 memctx = wctx.tomemctx(commitmsg, parents=(p1, p2), date=date,
1019 extra=extra, user=ctx.user(), branch=branch, editor=editor)
1020 commitres = repo.commitctx(memctx)
1021 wctx.clean() # Might be reused
1022 return commitres
966 1023
967 def concludenode(repo, rev, p1, p2, commitmsg=None, editor=None, extrafn=None, 1024 def concludenode(repo, rev, p1, p2, commitmsg=None, editor=None, extrafn=None,
968 keepbranches=False, date=None): 1025 keepbranches=False, date=None):
969 '''Commit the wd changes with parents p1 and p2. Reuse commit info from rev 1026 '''Commit the wd changes with parents p1 and p2. Reuse commit info from rev
970 but also store useful information in extra. 1027 but also store useful information in extra.