comparison hgext/rebase.py @ 37038:7db86856f27f

rebase: pass in "keepbranch" to conclude[memory]node() Both functions calculated the same "keepbranch" value from the "keepbranches" we passed in, so let's make the caller do it instead. Differential Revision: https://phab.mercurial-scm.org/D2919
author Martin von Zweigbergk <martinvonz@google.com>
date Tue, 20 Mar 2018 21:49:09 -0700
parents bd0086bd3af4
children 7616073a4cf1
comparison
equal deleted inserted replaced
37037:bd0086bd3af4 37038:7db86856f27f
447 if commitmsg is None: 447 if commitmsg is None:
448 commitmsg = ctx.description() 448 commitmsg = ctx.description()
449 extra = {'rebase_source': ctx.hex()} 449 extra = {'rebase_source': ctx.hex()}
450 for c in self.extrafns: 450 for c in self.extrafns:
451 c(ctx, extra) 451 c(ctx, extra)
452 keepbranch = self.keepbranchesf and repo[p1].branch() != ctx.branch()
452 if self.inmemory: 453 if self.inmemory:
453 newnode = concludememorynode(repo, ctx, p1, p2, 454 newnode = concludememorynode(repo, ctx, p1, p2,
454 wctx=self.wctx, 455 wctx=self.wctx,
455 extra=extra, 456 extra=extra,
456 commitmsg=commitmsg, 457 commitmsg=commitmsg,
457 editor=editor, 458 editor=editor,
458 keepbranches=self.keepbranchesf, 459 keepbranch=keepbranch,
459 date=self.date) 460 date=self.date)
460 mergemod.mergestate.clean(repo) 461 mergemod.mergestate.clean(repo)
461 else: 462 else:
462 newnode = concludenode(repo, ctx, p1, p2, 463 newnode = concludenode(repo, ctx, p1, p2,
463 extra=extra, 464 extra=extra,
464 commitmsg=commitmsg, 465 commitmsg=commitmsg,
465 editor=editor, 466 editor=editor,
466 keepbranches=self.keepbranchesf, 467 keepbranch=keepbranch,
467 date=self.date) 468 date=self.date)
468 469
469 if newnode is None: 470 if newnode is None:
470 # If it ended up being a no-op commit, then the normal 471 # If it ended up being a no-op commit, then the normal
471 # merge state clean-up path doesn't happen, so do it 472 # merge state clean-up path doesn't happen, so do it
1021 raise error.Abort(_('unable to collapse on top of %d, there is more ' 1022 raise error.Abort(_('unable to collapse on top of %d, there is more '
1022 'than one external parent: %s') % 1023 'than one external parent: %s') %
1023 (max(destancestors), 1024 (max(destancestors),
1024 ', '.join("%d" % p for p in sorted(parents)))) 1025 ', '.join("%d" % p for p in sorted(parents))))
1025 1026
1026 def concludememorynode(repo, ctx, p1, p2, wctx, editor, extra, keepbranches, 1027 def concludememorynode(repo, ctx, p1, p2, wctx, editor, extra, keepbranch,
1027 date, commitmsg): 1028 date, commitmsg):
1028 '''Commit the memory changes with parents p1 and p2. Reuse commit info from 1029 '''Commit the memory changes with parents p1 and p2. Reuse commit info from
1029 ctx. 1030 ctx.
1030 Return node of committed revision.''' 1031 Return node of committed revision.'''
1031 keepbranch = keepbranches and repo[p1].branch() != ctx.branch()
1032
1033 destphase = max(ctx.phase(), phases.draft) 1032 destphase = max(ctx.phase(), phases.draft)
1034 overrides = {('phases', 'new-commit'): destphase} 1033 overrides = {('phases', 'new-commit'): destphase}
1035 if keepbranch: 1034 if keepbranch:
1036 overrides[('ui', 'allowemptycommit')] = True 1035 overrides[('ui', 'allowemptycommit')] = True
1037 with repo.ui.configoverride(overrides, 'rebase'): 1036 with repo.ui.configoverride(overrides, 'rebase'):
1052 extra=extra, user=ctx.user(), branch=branch, editor=editor) 1051 extra=extra, user=ctx.user(), branch=branch, editor=editor)
1053 commitres = repo.commitctx(memctx) 1052 commitres = repo.commitctx(memctx)
1054 wctx.clean() # Might be reused 1053 wctx.clean() # Might be reused
1055 return commitres 1054 return commitres
1056 1055
1057 def concludenode(repo, ctx, p1, p2, editor, extra, keepbranches, date, 1056 def concludenode(repo, ctx, p1, p2, editor, extra, keepbranch, date,
1058 commitmsg): 1057 commitmsg):
1059 '''Commit the wd changes with parents p1 and p2. Reuse commit info from ctx. 1058 '''Commit the wd changes with parents p1 and p2. Reuse commit info from ctx.
1060 Return node of committed revision.''' 1059 Return node of committed revision.'''
1061 dsguard = util.nullcontextmanager() 1060 dsguard = util.nullcontextmanager()
1062 if not repo.ui.configbool('rebase', 'singletransaction'): 1061 if not repo.ui.configbool('rebase', 'singletransaction'):
1063 dsguard = dirstateguard.dirstateguard(repo, 'rebase') 1062 dsguard = dirstateguard.dirstateguard(repo, 'rebase')
1064 with dsguard: 1063 with dsguard:
1065 repo.setparents(repo[p1].node(), repo[p2].node()) 1064 repo.setparents(repo[p1].node(), repo[p2].node())
1066 keepbranch = keepbranches and repo[p1].branch() != ctx.branch()
1067 1065
1068 destphase = max(ctx.phase(), phases.draft) 1066 destphase = max(ctx.phase(), phases.draft)
1069 overrides = {('phases', 'new-commit'): destphase} 1067 overrides = {('phases', 'new-commit'): destphase}
1070 if keepbranch: 1068 if keepbranch:
1071 overrides[('ui', 'allowemptycommit')] = True 1069 overrides[('ui', 'allowemptycommit')] = True