# HG changeset patch # User Martin von Zweigbergk # Date 2019-06-19 17:19:32 # Node ID a68350a7fc5506d55de7ada478e143dc219e0d7b # Parent 88ba0ff94605b5b2c22afe1f5fc647e729068f3b log: pass getcopies() function instead of getrenamed() to displayer (API) This reduces the duplication between the two displayer functions (and between them and scmutil.getcopiesfn()). It's still more code than two patches ago, but there's less duplication. Differential Revision: https://phab.mercurial-scm.org/D6546 diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -3887,12 +3887,12 @@ def log(ui, repo, *pats, **opts): # then filter the result by logcmdutil._makerevset() and --limit revs, differ = logcmdutil.getlinerangerevs(repo, revs, opts) - getrenamed = None + getcopies = None if opts.get('copies'): endrev = None if revs: endrev = revs.max() + 1 - getrenamed = scmutil.getrenamedfn(repo, endrev=endrev) + getcopies = scmutil.getcopiesfn(repo, endrev=endrev) ui.pager('log') displayer = logcmdutil.changesetdisplayer(ui, repo, opts, differ, @@ -3901,7 +3901,7 @@ def log(ui, repo, *pats, **opts): displayfn = logcmdutil.displaygraphrevs else: displayfn = logcmdutil.displayrevs - displayfn(ui, repo, revs, displayer, getrenamed) + displayfn(ui, repo, revs, displayer, getcopies) @command('manifest', [('r', 'rev', '', _('revision to display'), _('REV')), diff --git a/mercurial/logcmdutil.py b/mercurial/logcmdutil.py --- a/mercurial/logcmdutil.py +++ b/mercurial/logcmdutil.py @@ -862,7 +862,7 @@ def _graphnodeformatter(ui, displayer): return templ.renderdefault(props) return formatnode -def displaygraph(ui, repo, dag, displayer, edgefn, getrenamed=None, props=None): +def displaygraph(ui, repo, dag, displayer, edgefn, getcopies=None, props=None): props = props or {} formatnode = _graphnodeformatter(ui, displayer) state = graphmod.asciistate() @@ -890,13 +890,7 @@ def displaygraph(ui, repo, dag, displaye for rev, type, ctx, parents in dag: char = formatnode(repo, ctx) - copies = None - if getrenamed: - copies = [] - for fn in ctx.files(): - rename = getrenamed(fn, ctx.rev()) - if rename: - copies.append((fn, rename)) + copies = getcopies(ctx) if getcopies else None edges = edgefn(type, char, state, rev, parents) firstedge = next(edges) width = firstedge[2] @@ -915,16 +909,10 @@ def displaygraphrevs(ui, repo, revs, dis revdag = graphmod.dagwalker(repo, revs) displaygraph(ui, repo, revdag, displayer, graphmod.asciiedges, getrenamed) -def displayrevs(ui, repo, revs, displayer, getrenamed): +def displayrevs(ui, repo, revs, displayer, getcopies): for rev in revs: ctx = repo[rev] - copies = None - if getrenamed is not None: - copies = [] - for fn in ctx.files(): - rename = getrenamed(fn, rev) - if rename: - copies.append((fn, rename)) + copies = getcopies(ctx) if getcopies else None displayer.show(ctx, copies=copies) displayer.flush(ctx) displayer.close()