comparison mercurial/logcmdutil.py @ 41610:d683aca738cd

diffordiffstat: avoid looking up contexts twice I'm not worried about performance; this is just simpler. Differential Revision: https://phab.mercurial-scm.org/D5890
author Martin von Zweigbergk <martinvonz@google.com>
date Wed, 06 Feb 2019 22:32:50 -0800
parents 6a63ba61e71f
children 035cae1d197f
comparison
equal deleted inserted replaced
41609:286eeed14893 41610:d683aca738cd
56 56
57 def diffordiffstat(ui, repo, diffopts, node1, node2, match, 57 def diffordiffstat(ui, repo, diffopts, node1, node2, match,
58 changes=None, stat=False, fp=None, graphwidth=0, 58 changes=None, stat=False, fp=None, graphwidth=0,
59 prefix='', root='', listsubrepos=False, hunksfilterfn=None): 59 prefix='', root='', listsubrepos=False, hunksfilterfn=None):
60 '''show diff or diffstat.''' 60 '''show diff or diffstat.'''
61 ctx1 = repo[node1]
62 ctx2 = repo[node2]
61 if root: 63 if root:
62 relroot = pathutil.canonpath(repo.root, repo.getcwd(), root) 64 relroot = pathutil.canonpath(repo.root, repo.getcwd(), root)
63 else: 65 else:
64 relroot = '' 66 relroot = ''
65 if relroot != '': 67 if relroot != '':
76 diffopts = diffopts.copy(context=0, noprefix=False) 78 diffopts = diffopts.copy(context=0, noprefix=False)
77 width = 80 79 width = 80
78 if not ui.plain(): 80 if not ui.plain():
79 width = ui.termwidth() - graphwidth 81 width = ui.termwidth() - graphwidth
80 82
81 chunks = repo[node2].diff(repo[node1], match, changes, opts=diffopts, 83 chunks = ctx2.diff(ctx1, match, changes, opts=diffopts, prefix=prefix,
82 prefix=prefix, relroot=relroot, 84 relroot=relroot, hunksfilterfn=hunksfilterfn)
83 hunksfilterfn=hunksfilterfn)
84 85
85 if fp is not None or ui.canwritewithoutlabels(): 86 if fp is not None or ui.canwritewithoutlabels():
86 out = fp or ui 87 out = fp or ui
87 if stat: 88 if stat:
88 chunks = [patch.diffstat(util.iterlines(chunks), width=width)] 89 chunks = [patch.diffstat(util.iterlines(chunks), width=width)]
103 else: 104 else:
104 for chunk, label in chunks: 105 for chunk, label in chunks:
105 ui.write(chunk, label=label) 106 ui.write(chunk, label=label)
106 107
107 if listsubrepos: 108 if listsubrepos:
108 ctx1 = repo[node1]
109 ctx2 = repo[node2]
110 for subpath, sub in scmutil.itersubrepos(ctx1, ctx2): 109 for subpath, sub in scmutil.itersubrepos(ctx1, ctx2):
111 tempnode2 = node2 110 tempnode2 = node2
112 try: 111 try:
113 if node2 is not None: 112 if node2 is not None:
114 tempnode2 = ctx2.substate[subpath][1] 113 tempnode2 = ctx2.substate[subpath][1]