Patchwork [4,of,5] cmdutil.changeset_printer: pass context into showpatch()

login
register
mail settings
Submitter Gregory Szorc
Date Nov. 22, 2015, 4:14 a.m.
Message ID <7f3a388e86fc1a4ecfb5.1448165669@ubuntu-main>
Download mbox | patch
Permalink /patch/11574/
State Accepted
Headers show

Comments

Gregory Szorc - Nov. 22, 2015, 4:14 a.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1447551841 28800
#      Sat Nov 14 17:44:01 2015 -0800
# Node ID 7f3a388e86fc1a4ecfb5052ebf8496e78bb486e4
# Parent  2ec388664377f3e729a60d718092d625efd4f50b
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.

Patch

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -1296,26 +1296,27 @@  class changeset_printer(object):
                 self.ui.write("\n\n")
             else:
                 # i18n: column positioning for "hg log"
                 self.ui.write(_("summary:     %s\n") %
                               description.splitlines()[0],
                               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)
             if diff:
                 if stat:
                     self.ui.write("\n")
                 diffordiffstat(self.ui, self.repo, diffopts, prev, node,
                                match=matchfn, stat=False)
@@ -1487,17 +1488,17 @@  class changeset_templater(changeset_prin
                 else:
                     if self.lastheader != h:
                         self.lastheader = h
                         self.ui.write(h)
 
             # 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:
                     self.footer = templater.stringify(
                         self.t(self._parts['footer'], **props))
         except KeyError as inst:
             msg = _("%s: no key named '%s'")
             raise error.Abort(msg % (self.t.mapfile, inst.args[0]))