comparison hgext/rebase.py @ 37040:b8d305bd12ca

rebase: move config override out of conclude[memory]node() Differential Revision: https://phab.mercurial-scm.org/D2921
author Martin von Zweigbergk <martinvonz@google.com>
date Tue, 20 Mar 2018 21:58:32 -0700
parents 7616073a4cf1
children 0b1230a5a958
comparison
equal deleted inserted replaced
37039:7616073a4cf1 37040:b8d305bd12ca
452 keepbranch = self.keepbranchesf and repo[p1].branch() != ctx.branch() 452 keepbranch = self.keepbranchesf and repo[p1].branch() != ctx.branch()
453 destphase = max(ctx.phase(), phases.draft) 453 destphase = max(ctx.phase(), phases.draft)
454 overrides = {('phases', 'new-commit'): destphase} 454 overrides = {('phases', 'new-commit'): destphase}
455 if keepbranch: 455 if keepbranch:
456 overrides[('ui', 'allowemptycommit')] = True 456 overrides[('ui', 'allowemptycommit')] = True
457 if self.inmemory: 457 with repo.ui.configoverride(overrides, 'rebase'):
458 newnode = concludememorynode(repo, ctx, p1, p2, 458 if self.inmemory:
459 wctx=self.wctx, 459 newnode = concludememorynode(repo, ctx, p1, p2,
460 extra=extra, 460 wctx=self.wctx,
461 commitmsg=commitmsg, 461 extra=extra,
462 editor=editor, 462 commitmsg=commitmsg,
463 overrides=overrides, 463 editor=editor,
464 date=self.date) 464 date=self.date)
465 mergemod.mergestate.clean(repo) 465 mergemod.mergestate.clean(repo)
466 else: 466 else:
467 newnode = concludenode(repo, ctx, p1, p2, 467 newnode = concludenode(repo, ctx, p1, p2,
468 extra=extra, 468 extra=extra,
469 commitmsg=commitmsg, 469 commitmsg=commitmsg,
470 editor=editor, 470 editor=editor,
471 overrides=overrides, 471 date=self.date)
472 date=self.date) 472
473 473 if newnode is None:
474 if newnode is None: 474 # If it ended up being a no-op commit, then the normal
475 # If it ended up being a no-op commit, then the normal 475 # merge state clean-up path doesn't happen, so do it
476 # merge state clean-up path doesn't happen, so do it 476 # here. Fix issue5494
477 # here. Fix issue5494 477 mergemod.mergestate.clean(repo)
478 mergemod.mergestate.clean(repo) 478 return newnode
479 return newnode
480 479
481 def _rebasenode(self, tr, rev, allowdivergence, progressfn): 480 def _rebasenode(self, tr, rev, allowdivergence, progressfn):
482 repo, ui, opts = self.repo, self.ui, self.opts 481 repo, ui, opts = self.repo, self.ui, self.opts
483 dest = self.destmap[rev] 482 dest = self.destmap[rev]
484 ctx = repo[rev] 483 ctx = repo[rev]
1026 raise error.Abort(_('unable to collapse on top of %d, there is more ' 1025 raise error.Abort(_('unable to collapse on top of %d, there is more '
1027 'than one external parent: %s') % 1026 'than one external parent: %s') %
1028 (max(destancestors), 1027 (max(destancestors),
1029 ', '.join("%d" % p for p in sorted(parents)))) 1028 ', '.join("%d" % p for p in sorted(parents))))
1030 1029
1031 def concludememorynode(repo, ctx, p1, p2, wctx, editor, extra, overrides, date, 1030 def concludememorynode(repo, ctx, p1, p2, wctx, editor, extra, date, commitmsg):
1032 commitmsg):
1033 '''Commit the memory changes with parents p1 and p2. Reuse commit info from 1031 '''Commit the memory changes with parents p1 and p2. Reuse commit info from
1034 ctx. 1032 ctx.
1035 Return node of committed revision.''' 1033 Return node of committed revision.'''
1036 with repo.ui.configoverride(overrides, 'rebase'): 1034 # Replicates the empty check in ``repo.commit``.
1037 # Replicates the empty check in ``repo.commit``. 1035 if wctx.isempty() and not repo.ui.configbool('ui', 'allowemptycommit'):
1038 if wctx.isempty() and not repo.ui.configbool('ui', 'allowemptycommit'): 1036 return None
1039 return None 1037
1040 1038 if date is None:
1041 if date is None: 1039 date = ctx.date()
1042 date = ctx.date() 1040
1043 1041 # By convention, ``extra['branch']`` (set by extrafn) clobbers
1044 # By convention, ``extra['branch']`` (set by extrafn) clobbers 1042 # ``branch`` (used when passing ``--keepbranches``).
1045 # ``branch`` (used when passing ``--keepbranches``). 1043 branch = repo[p1].branch()
1046 branch = repo[p1].branch() 1044 if 'branch' in extra:
1047 if 'branch' in extra: 1045 branch = extra['branch']
1048 branch = extra['branch'] 1046
1049 1047 memctx = wctx.tomemctx(commitmsg, parents=(p1, p2), date=date,
1050 memctx = wctx.tomemctx(commitmsg, parents=(p1, p2), date=date, 1048 extra=extra, user=ctx.user(), branch=branch, editor=editor)
1051 extra=extra, user=ctx.user(), branch=branch, editor=editor) 1049 commitres = repo.commitctx(memctx)
1052 commitres = repo.commitctx(memctx) 1050 wctx.clean() # Might be reused
1053 wctx.clean() # Might be reused 1051 return commitres
1054 return commitres 1052
1055 1053 def concludenode(repo, ctx, p1, p2, editor, extra, date, commitmsg):
1056 def concludenode(repo, ctx, p1, p2, editor, extra, overrides, date,
1057 commitmsg):
1058 '''Commit the wd changes with parents p1 and p2. Reuse commit info from ctx. 1054 '''Commit the wd changes with parents p1 and p2. Reuse commit info from ctx.
1059 Return node of committed revision.''' 1055 Return node of committed revision.'''
1060 dsguard = util.nullcontextmanager() 1056 dsguard = util.nullcontextmanager()
1061 if not repo.ui.configbool('rebase', 'singletransaction'): 1057 if not repo.ui.configbool('rebase', 'singletransaction'):
1062 dsguard = dirstateguard.dirstateguard(repo, 'rebase') 1058 dsguard = dirstateguard.dirstateguard(repo, 'rebase')
1063 with dsguard: 1059 with dsguard:
1064 repo.setparents(repo[p1].node(), repo[p2].node()) 1060 repo.setparents(repo[p1].node(), repo[p2].node())
1065 1061
1066 with repo.ui.configoverride(overrides, 'rebase'): 1062 # Commit might fail if unresolved files exist
1067 # Commit might fail if unresolved files exist 1063 if date is None:
1068 if date is None: 1064 date = ctx.date()
1069 date = ctx.date() 1065 newnode = repo.commit(text=commitmsg, user=ctx.user(),
1070 newnode = repo.commit(text=commitmsg, user=ctx.user(), 1066 date=date, extra=extra, editor=editor)
1071 date=date, extra=extra, editor=editor)
1072 1067
1073 repo.dirstate.setbranch(repo[newnode].branch()) 1068 repo.dirstate.setbranch(repo[newnode].branch())
1074 return newnode 1069 return newnode
1075 1070
1076 def rebasenode(repo, rev, p1, base, collapse, dest, wctx): 1071 def rebasenode(repo, rev, p1, base, collapse, dest, wctx):