# HG changeset patch # User Durham Goode # Date 2015-04-04 09:12:24 # Node ID 8f6494eb16eb7173b98a9f060b120750ce894c9a # Parent 3133e246c912290b98f8716adfd87b086f42ce30 histedit: move finishfold into fold class Let's move the finishfold function into the fold class so we can modify it from the roll class more easily. diff --git a/hgext/histedit.py b/hgext/histedit.py --- a/hgext/histedit.py +++ b/hgext/histedit.py @@ -546,53 +546,53 @@ class fold(histeditaction): if isinstance(self, rollup): foldopts['rollup'] = True - return finishfold(repo.ui, repo, parentctx, rulectx, ctx.node(), - foldopts, middlecommits) + return self.finishfold(repo.ui, repo, parentctx, rulectx, ctx.node(), + foldopts, middlecommits) + + def finishfold(self, ui, repo, ctx, oldctx, newnode, opts, internalchanges): + parent = ctx.parents()[0].node() + hg.update(repo, parent) + ### prepare new commit data + commitopts = opts.copy() + commitopts['user'] = ctx.user() + # commit message + if opts.get('rollup'): + newmessage = ctx.description() + else: + newmessage = '\n***\n'.join( + [ctx.description()] + + [repo[r].description() for r in internalchanges] + + [oldctx.description()]) + '\n' + commitopts['message'] = newmessage + # date + commitopts['date'] = max(ctx.date(), oldctx.date()) + extra = ctx.extra().copy() + # histedit_source + # note: ctx is likely a temporary commit but that the best we can do + # here. This is sufficient to solve issue3681 anyway. + extra['histedit_source'] = '%s,%s' % (ctx.hex(), oldctx.hex()) + commitopts['extra'] = extra + phasebackup = repo.ui.backupconfig('phases', 'new-commit') + try: + phasemin = max(ctx.phase(), oldctx.phase()) + repo.ui.setconfig('phases', 'new-commit', phasemin, 'histedit') + n = collapse(repo, ctx, repo[newnode], commitopts) + finally: + repo.ui.restoreconfig(phasebackup) + if n is None: + return ctx, [] + hg.update(repo, n) + replacements = [(oldctx.node(), (newnode,)), + (ctx.node(), (n,)), + (newnode, (n,)), + ] + for ich in internalchanges: + replacements.append((ich, (n,))) + return repo[n], replacements class rollup(fold): pass -def finishfold(ui, repo, ctx, oldctx, newnode, opts, internalchanges): - parent = ctx.parents()[0].node() - hg.update(repo, parent) - ### prepare new commit data - commitopts = opts.copy() - commitopts['user'] = ctx.user() - # commit message - if opts.get('rollup'): - newmessage = ctx.description() - else: - newmessage = '\n***\n'.join( - [ctx.description()] + - [repo[r].description() for r in internalchanges] + - [oldctx.description()]) + '\n' - commitopts['message'] = newmessage - # date - commitopts['date'] = max(ctx.date(), oldctx.date()) - extra = ctx.extra().copy() - # histedit_source - # note: ctx is likely a temporary commit but that the best we can do here - # This is sufficient to solve issue3681 anyway - extra['histedit_source'] = '%s,%s' % (ctx.hex(), oldctx.hex()) - commitopts['extra'] = extra - phasebackup = repo.ui.backupconfig('phases', 'new-commit') - try: - phasemin = max(ctx.phase(), oldctx.phase()) - repo.ui.setconfig('phases', 'new-commit', phasemin, 'histedit') - n = collapse(repo, ctx, repo[newnode], commitopts) - finally: - repo.ui.restoreconfig(phasebackup) - if n is None: - return ctx, [] - hg.update(repo, n) - replacements = [(oldctx.node(), (newnode,)), - (ctx.node(), (n,)), - (newnode, (n,)), - ] - for ich in internalchanges: - replacements.append((ich, (n,))) - return repo[n], replacements - class drop(histeditaction): def run(self): parentctx = self.repo[self.state.parentctxnode]