Mercurial > evolve
changeset 5694:bfdd8866f0b7
evolve: make the `displayer` we pass around just a function
We only depend on its `.show(ctx)` function, so it's enough to pass
around that function instead. That will make it easier to replace the
function by another one in a later patch.
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Thu, 29 Oct 2020 15:11:20 -0700 |
parents | 3083e1936a1a |
children | 8c7de8f8bb42 |
files | hgext3rd/evolve/__init__.py hgext3rd/evolve/cmdrewrite.py hgext3rd/evolve/evolvecmd.py |
diffstat | 3 files changed, 39 insertions(+), 38 deletions(-) [+] |
line wrap: on
line diff
--- a/hgext3rd/evolve/__init__.py Thu Oct 29 14:14:00 2020 -0700 +++ b/hgext3rd/evolve/__init__.py Thu Oct 29 15:11:20 2020 -0700 @@ -829,7 +829,7 @@ def _getcurrenttopic(repo): return getattr(repo, 'currenttopic', b'') -def _prevupdate(repo, displayer, target, bookmark, dryrun, mergeopt): +def _prevupdate(repo, display, target, bookmark, dryrun, mergeopt): if dryrun: repo.ui.write(_(b'hg update %s;\n') % target) if bookmark is not None: @@ -863,9 +863,9 @@ lockmod.release(tr, lock) if not repo.ui.quiet: - displayer.show(target) + display(target) -def _findprevtarget(repo, displayer, movebookmark=False, topic=True): +def _findprevtarget(repo, display, movebookmark=False, topic=True): target = bookmark = None wkctx = repo[None] p1 = wkctx.p1() @@ -895,7 +895,7 @@ choosedrev = utility.revselectionprompt(repo.ui, repo, prevs, header) if choosedrev is None: for p in parents: - displayer.show(p) + display(p) repo.ui.warn(_(b'multiple parents, explicitly update to one\n')) else: target = repo[choosedrev] @@ -940,10 +940,10 @@ if topic and hastopic: template = utility.stacktemplate - displayer = logcmdutil.changesetdisplayer(ui, repo, - {b'template': template}) + display = logcmdutil.changesetdisplayer(ui, repo, + {b'template': template}).show - target, bookmark = _findprevtarget(repo, displayer, + target, bookmark = _findprevtarget(repo, display, opts.get('move_bookmark'), topic) if target is not None: configoverride = util.nullcontextmanager() @@ -952,7 +952,7 @@ (b'_internal', b'keep-topic'): b'yes' }, source=b'topic-extension') with configoverride: - _prevupdate(repo, displayer, target, bookmark, dryrunopt, + _prevupdate(repo, display, target, bookmark, dryrunopt, mergeopt) return 0 else: @@ -999,8 +999,8 @@ children = [ctx for ctx in children if ctx not in filtered] template = utility.stacktemplate opts['stacktemplate'] = True - displayer = logcmdutil.changesetdisplayer(ui, repo, - {b'template': template}) + display = logcmdutil.changesetdisplayer(ui, repo, + {b'template': template}).show # check if we need to evolve while updating to the next child revision needevolve = False @@ -1036,7 +1036,7 @@ if len(children) == 1: c = children[0] - return _updatetonext(ui, repo, c, displayer, opts) + return _updatetonext(ui, repo, c, display, opts) elif children: cheader = _(b"ambiguous next changeset, choose one to update:") crevs = [c.rev() for c in children] @@ -1044,11 +1044,11 @@ if choosedrev is None: ui.warn(_(b"ambiguous next changeset:\n")) for c in children: - displayer.show(c) + display(c) ui.warn(_(b"explicitly update to one of them\n")) return 1 else: - return _updatetonext(ui, repo, repo[choosedrev], displayer, opts) + return _updatetonext(ui, repo, repo[choosedrev], display, opts) else: if not opts['evolve'] or not aspchildren: if filtered: @@ -1069,7 +1069,7 @@ if choosedrev is None: ui.warn(_(b"ambiguous next (unstable) changeset:\n")) for c in aspchildren: - displayer.show(repo[c]) + display(repo[c]) ui.warn(_(b"(run 'hg evolve --rev REV' on one of them)\n")) return 1 else: @@ -1100,7 +1100,7 @@ % ui.label(bytes(repo[b'.']), b'evolve.node')) return 0 -def _updatetonext(ui, repo, child, displayer, opts): +def _updatetonext(ui, repo, child, display, opts): """ logic for `hg next` command to update to children and move bookmarks if required """ bm = repo._activebookmark @@ -1137,7 +1137,7 @@ finally: lockmod.release(tr, lock) if not ui.quiet: - displayer.show(child) + display(child) return 0 @eh.wrapcommand(b'commit')
--- a/hgext3rd/evolve/cmdrewrite.py Thu Oct 29 14:14:00 2020 -0700 +++ b/hgext3rd/evolve/cmdrewrite.py Thu Oct 29 15:11:20 2020 -0700 @@ -1334,9 +1334,10 @@ with ui.configoverride(overrides, b'touch'): rewriteutil.precheck(repo, revs, b'touch') tmpl = utility.shorttemplate - displayer = logcmdutil.changesetdisplayer(ui, repo, {b'template': tmpl}) + display = logcmdutil.changesetdisplayer(ui, repo, + {b'template': tmpl}).show with repo.wlock(), repo.lock(), repo.transaction(b'touch'): - touchnodes(ui, repo, revs, displayer, **opts) + touchnodes(ui, repo, revs, display, **opts) def touchnodes(ui, repo, revs, displayer, **opts): duplicate = opts['duplicate'] @@ -1355,7 +1356,7 @@ if not (duplicate or allowdivergence): if precheck_contentdiv(repo, ctx): - displayer.show(ctx) + displayer(ctx) index = ui.promptchoice( _(b"reviving this changeset will create divergence" b" unless you make a duplicate.\n(a)llow divergence or"
--- a/hgext3rd/evolve/evolvecmd.py Thu Oct 29 14:14:00 2020 -0700 +++ b/hgext3rd/evolve/evolvecmd.py Thu Oct 29 15:11:20 2020 -0700 @@ -70,23 +70,23 @@ template = shorttemplate if stacktmplt: template = stacktemplate - displayer = logcmdutil.changesetdisplayer(ui, repo, - {b'template': template}) + display = logcmdutil.changesetdisplayer(ui, repo, + {b'template': template}).show if b'orphan' == category: - result = _solveorphan(ui, repo, ctx, evolvestate, displayer, + result = _solveorphan(ui, repo, ctx, evolvestate, display, dryrun, confirm, progresscb) elif b'phasedivergent' == category: result = _solvephasedivergence(ui, repo, ctx, evolvestate, - displayer, dryrun, confirm, + display, dryrun, confirm, progresscb) elif b'contentdivergent' == category: - result = _solvedivergent(ui, repo, ctx, evolvestate, displayer, + result = _solvedivergent(ui, repo, ctx, evolvestate, display, dryrun, confirm, progresscb) else: assert False, b"unknown trouble category: %s" % (category) return result -def _solveorphan(ui, repo, orig, evolvestate, displayer, dryrun=False, +def _solveorphan(ui, repo, orig, evolvestate, display, dryrun=False, confirm=False, progresscb=None): """ Tries to stabilize the changeset orig which is orphan. @@ -144,13 +144,13 @@ target = repo[newer] if not ui.quiet or confirm: repo.ui.write(_(b'move:'), label=b'evolve.operation') - displayer.show(orig) + display(orig) # lastsolved: keep track of successor of last troubled cset we evolved # to confirm that if atop msg should be suppressed to remove redundancy lastsolved = evolvestate.get(b'lastsolved') if lastsolved is None or target != repo[lastsolved]: repo.ui.write(_(b'atop:')) - displayer.show(target) + display(target) if confirm and ui.prompt(b'perform evolve? [Ny]', b'n') != b'y': raise error.Abort(_(b'evolve aborted by user')) todo = b'hg rebase -r %s -d %s\n' % (orig, target) @@ -168,7 +168,7 @@ keepbranch, b'orphan') return (True, newid) -def _solvephasedivergence(ui, repo, bumped, evolvestate, displayer, +def _solvephasedivergence(ui, repo, bumped, evolvestate, display, dryrun=False, confirm=False, progresscb=None): """Stabilize a phase divergent changeset @@ -195,9 +195,9 @@ if not ui.quiet or confirm: repo.ui.write(_(b'recreate:'), label=b'evolve.operation') - displayer.show(bumped) + display(bumped) repo.ui.write(_(b'atop:')) - displayer.show(prec) + display(prec) if confirm and ui.prompt(_(b'perform evolve? [Ny]'), b'n') != b'y': raise error.Abort(_(b'evolve aborted by user')) if dryrun: @@ -420,7 +420,7 @@ with state.saver(evolvestate, {b'current': orig.node()}), configoverride: return _relocate(repo, orig, dest, evolvestate, keepbranch=True) -def _solvedivergent(ui, repo, divergent, evolvestate, displayer, dryrun=False, +def _solvedivergent(ui, repo, divergent, evolvestate, display, dryrun=False, confirm=False, progresscb=None): """tries to solve content-divergence of a changeset @@ -486,11 +486,11 @@ if not ui.quiet or confirm: ui.write(_(b'merge:'), label=b'evolve.operation') - displayer.show(divergent) + display(divergent) ui.write(_(b'with: ')) - displayer.show(other) + display(other) ui.write(_(b'base: ')) - displayer.show(base) + display(base) if confirm and ui.prompt(_(b'perform evolve? [Ny]'), b'n') != b'y': raise error.Abort(_(b'evolve aborted by user')) if dryrun: @@ -1711,8 +1711,8 @@ oldid = repo[b'.'].node() startctx = repo[b'.'] dryrunopt = opts.get('dry_run', False) - displayer = logcmdutil.changesetdisplayer(ui, repo, - {b'template': shorttemplate}) + display = logcmdutil.changesetdisplayer(ui, repo, + {b'template': shorttemplate}).show try: ctx = repo[utility._singlesuccessor(repo, repo[b'.'])] except utility.MultipleSuccessorsError as exc: @@ -1720,12 +1720,12 @@ b' successors:\n')) for ln in exc.successorssets: for n in ln: - displayer.show(repo[n]) + display(repo[n]) return 2 ui.status(_(b'update:')) if not ui.quiet: - displayer.show(ctx) + display(ctx) if dryrunopt: return 0