comparison hgext/rebase.py @ 37034:fbc82a08bdcb

rebase: pass in ctx, not rev, to conclude[memory]node() They both need it and there's no locking that might make the results different, so let's do it in one place. This also lets us move out more common code in the following patches. Differential Revision: https://phab.mercurial-scm.org/D2915
author Martin von Zweigbergk <martinvonz@google.com>
date Wed, 21 Mar 2018 11:04:13 -0700
parents 5f99142f59cc
children b7f5d03e1e54
comparison
equal deleted inserted replaced
37033:5f99142f59cc 37034:fbc82a08bdcb
452 '''Commit the wd changes with parents p1 and p2. 452 '''Commit the wd changes with parents p1 and p2.
453 453
454 Reuse commit info from rev but also store useful information in extra. 454 Reuse commit info from rev but also store useful information in extra.
455 Return node of committed revision.''' 455 Return node of committed revision.'''
456 repo = self.repo 456 repo = self.repo
457 ctx = repo[rev]
457 if self.inmemory: 458 if self.inmemory:
458 newnode = concludememorynode(repo, rev, p1, p2, 459 newnode = concludememorynode(repo, ctx, p1, p2,
459 wctx=self.wctx, 460 wctx=self.wctx,
460 extrafn=_makeextrafn(self.extrafns), 461 extrafn=_makeextrafn(self.extrafns),
461 commitmsg=commitmsg, 462 commitmsg=commitmsg,
462 editor=editor, 463 editor=editor,
463 keepbranches=self.keepbranchesf, 464 keepbranches=self.keepbranchesf,
464 date=self.date) 465 date=self.date)
465 mergemod.mergestate.clean(repo) 466 mergemod.mergestate.clean(repo)
466 else: 467 else:
467 newnode = concludenode(repo, rev, p1, p2, 468 newnode = concludenode(repo, ctx, p1, p2,
468 extrafn=_makeextrafn(self.extrafns), 469 extrafn=_makeextrafn(self.extrafns),
469 commitmsg=commitmsg, 470 commitmsg=commitmsg,
470 editor=editor, 471 editor=editor,
471 keepbranches=self.keepbranchesf, 472 keepbranches=self.keepbranchesf,
472 date=self.date) 473 date=self.date)
1026 raise error.Abort(_('unable to collapse on top of %d, there is more ' 1027 raise error.Abort(_('unable to collapse on top of %d, there is more '
1027 'than one external parent: %s') % 1028 'than one external parent: %s') %
1028 (max(destancestors), 1029 (max(destancestors),
1029 ', '.join("%d" % p for p in sorted(parents)))) 1030 ', '.join("%d" % p for p in sorted(parents))))
1030 1031
1031 def concludememorynode(repo, rev, p1, p2, wctx, editor, extrafn, keepbranches, 1032 def concludememorynode(repo, ctx, p1, p2, wctx, editor, extrafn, keepbranches,
1032 date, commitmsg=None): 1033 date, commitmsg=None):
1033 '''Commit the memory changes with parents p1 and p2. Reuse commit info from 1034 '''Commit the memory changes with parents p1 and p2. Reuse commit info from
1034 rev but also store useful information in extra. 1035 ctx but also store useful information in extra.
1035 Return node of committed revision.''' 1036 Return node of committed revision.'''
1036 ctx = repo[rev]
1037 if commitmsg is None: 1037 if commitmsg is None:
1038 commitmsg = ctx.description() 1038 commitmsg = ctx.description()
1039 keepbranch = keepbranches and repo[p1].branch() != ctx.branch() 1039 keepbranch = keepbranches and repo[p1].branch() != ctx.branch()
1040 extra = {'rebase_source': ctx.hex()} 1040 extra = {'rebase_source': ctx.hex()}
1041 if extrafn: 1041 if extrafn:
1063 extra=extra, user=ctx.user(), branch=branch, editor=editor) 1063 extra=extra, user=ctx.user(), branch=branch, editor=editor)
1064 commitres = repo.commitctx(memctx) 1064 commitres = repo.commitctx(memctx)
1065 wctx.clean() # Might be reused 1065 wctx.clean() # Might be reused
1066 return commitres 1066 return commitres
1067 1067
1068 def concludenode(repo, rev, p1, p2, editor, extrafn, keepbranches, date, 1068 def concludenode(repo, ctx, p1, p2, editor, extrafn, keepbranches, date,
1069 commitmsg=None): 1069 commitmsg=None):
1070 '''Commit the wd changes with parents p1 and p2. Reuse commit info from rev 1070 '''Commit the wd changes with parents p1 and p2. Reuse commit info from ctx
1071 but also store useful information in extra. 1071 but also store useful information in extra.
1072 Return node of committed revision.''' 1072 Return node of committed revision.'''
1073 dsguard = util.nullcontextmanager() 1073 dsguard = util.nullcontextmanager()
1074 if not repo.ui.configbool('rebase', 'singletransaction'): 1074 if not repo.ui.configbool('rebase', 'singletransaction'):
1075 dsguard = dirstateguard.dirstateguard(repo, 'rebase') 1075 dsguard = dirstateguard.dirstateguard(repo, 'rebase')
1076 with dsguard: 1076 with dsguard:
1077 repo.setparents(repo[p1].node(), repo[p2].node()) 1077 repo.setparents(repo[p1].node(), repo[p2].node())
1078 ctx = repo[rev]
1079 if commitmsg is None: 1078 if commitmsg is None:
1080 commitmsg = ctx.description() 1079 commitmsg = ctx.description()
1081 keepbranch = keepbranches and repo[p1].branch() != ctx.branch() 1080 keepbranch = keepbranches and repo[p1].branch() != ctx.branch()
1082 extra = {'rebase_source': ctx.hex()} 1081 extra = {'rebase_source': ctx.hex()}
1083 if extrafn: 1082 if extrafn: