Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/logcmdutil.py @ 42519:a68350a7fc55
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
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Wed, 19 Jun 2019 10:19:32 -0700 |
parents | c929f612afac |
children | 2372284d9457 |
comparison
equal
deleted
inserted
replaced
42518:88ba0ff94605 | 42519:a68350a7fc55 |
---|---|
860 def formatnode(repo, ctx): | 860 def formatnode(repo, ctx): |
861 props = {'ctx': ctx, 'repo': repo} | 861 props = {'ctx': ctx, 'repo': repo} |
862 return templ.renderdefault(props) | 862 return templ.renderdefault(props) |
863 return formatnode | 863 return formatnode |
864 | 864 |
865 def displaygraph(ui, repo, dag, displayer, edgefn, getrenamed=None, props=None): | 865 def displaygraph(ui, repo, dag, displayer, edgefn, getcopies=None, props=None): |
866 props = props or {} | 866 props = props or {} |
867 formatnode = _graphnodeformatter(ui, displayer) | 867 formatnode = _graphnodeformatter(ui, displayer) |
868 state = graphmod.asciistate() | 868 state = graphmod.asciistate() |
869 styles = state['styles'] | 869 styles = state['styles'] |
870 | 870 |
888 # experimental config: experimental.graphshorten | 888 # experimental config: experimental.graphshorten |
889 state['graphshorten'] = ui.configbool('experimental', 'graphshorten') | 889 state['graphshorten'] = ui.configbool('experimental', 'graphshorten') |
890 | 890 |
891 for rev, type, ctx, parents in dag: | 891 for rev, type, ctx, parents in dag: |
892 char = formatnode(repo, ctx) | 892 char = formatnode(repo, ctx) |
893 copies = None | 893 copies = getcopies(ctx) if getcopies else None |
894 if getrenamed: | |
895 copies = [] | |
896 for fn in ctx.files(): | |
897 rename = getrenamed(fn, ctx.rev()) | |
898 if rename: | |
899 copies.append((fn, rename)) | |
900 edges = edgefn(type, char, state, rev, parents) | 894 edges = edgefn(type, char, state, rev, parents) |
901 firstedge = next(edges) | 895 firstedge = next(edges) |
902 width = firstedge[2] | 896 width = firstedge[2] |
903 displayer.show(ctx, copies=copies, | 897 displayer.show(ctx, copies=copies, |
904 graphwidth=width, **pycompat.strkwargs(props)) | 898 graphwidth=width, **pycompat.strkwargs(props)) |
913 | 907 |
914 def displaygraphrevs(ui, repo, revs, displayer, getrenamed): | 908 def displaygraphrevs(ui, repo, revs, displayer, getrenamed): |
915 revdag = graphmod.dagwalker(repo, revs) | 909 revdag = graphmod.dagwalker(repo, revs) |
916 displaygraph(ui, repo, revdag, displayer, graphmod.asciiedges, getrenamed) | 910 displaygraph(ui, repo, revdag, displayer, graphmod.asciiedges, getrenamed) |
917 | 911 |
918 def displayrevs(ui, repo, revs, displayer, getrenamed): | 912 def displayrevs(ui, repo, revs, displayer, getcopies): |
919 for rev in revs: | 913 for rev in revs: |
920 ctx = repo[rev] | 914 ctx = repo[rev] |
921 copies = None | 915 copies = getcopies(ctx) if getcopies else None |
922 if getrenamed is not None: | |
923 copies = [] | |
924 for fn in ctx.files(): | |
925 rename = getrenamed(fn, rev) | |
926 if rename: | |
927 copies.append((fn, rename)) | |
928 displayer.show(ctx, copies=copies) | 916 displayer.show(ctx, copies=copies) |
929 displayer.flush(ctx) | 917 displayer.flush(ctx) |
930 displayer.close() | 918 displayer.close() |
931 | 919 |
932 def checkunsupportedgraphflags(pats, opts): | 920 def checkunsupportedgraphflags(pats, opts): |