cmdutil.changeset_printer: pass context into showpatch()
authorGregory Szorc <gregory.szorc@gmail.com>
Sat, 14 Nov 2015 17:44:01 -0800
changeset 27065 93bcc73df8d5
parent 27064 a29db426c5ba
child 27066 6f1f8e88f036
cmdutil.changeset_printer: pass context into showpatch() Before, we passed the node then subsequently performed a lookup on repo.changelog. We already has the context available, so just pass it in. This does result in a small performance win. But I doubt it will show up anywhere because diff[stat] calculation will dwarf the time spent to create a changectx. Still, we should be creating fewer changectx out of principle.
mercurial/cmdutil.py
--- a/mercurial/cmdutil.py	Sat Nov 21 19:21:01 2015 -0800
+++ b/mercurial/cmdutil.py	Sat Nov 14 17:44:01 2015 -0800
@@ -1301,16 +1301,17 @@
                               label='log.summary')
         self.ui.write("\n")
 
-        self.showpatch(changenode, matchfn)
-
-    def showpatch(self, node, matchfn):
+        self.showpatch(ctx, matchfn)
+
+    def showpatch(self, ctx, matchfn):
         if not matchfn:
             matchfn = self.matchfn
         if matchfn:
             stat = self.diffopts.get('stat')
             diff = self.diffopts.get('patch')
             diffopts = patch.diffallopts(self.ui, self.diffopts)
-            prev = self.repo.changelog.parents(node)[0]
+            node = ctx.node()
+            prev = ctx.p1()
             if stat:
                 diffordiffstat(self.ui, self.repo, diffopts, prev, node,
                                match=matchfn, stat=True)
@@ -1492,7 +1493,7 @@
             # write changeset metadata, then patch if requested
             key = self._parts['changeset']
             self.ui.write(templater.stringify(self.t(key, **props)))
-            self.showpatch(ctx.node(), matchfn)
+            self.showpatch(ctx, matchfn)
 
             if self._parts['footer']:
                 if not self.footer: