Patchwork [3,of,4] changeset_printer: replace _meaningful_parentrevs() by changeset_templater's

login
register
mail settings
Submitter Yuya Nishihara
Date March 27, 2015, 3:24 p.m.
Message ID <9e42a6eebfdf5b33502b.1427469887@mimosa>
Download mbox | patch
Permalink /patch/8310/
State Accepted
Headers show

Comments

Yuya Nishihara - March 27, 2015, 3:24 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1426321431 -32400
#      Sat Mar 14 17:23:51 2015 +0900
# Node ID 9e42a6eebfdf5b33502be8ac4291c4bc1f9f2eca
# Parent  9b27dcb00ec22038fefb57ced51e851f8542e416
changeset_printer: replace _meaningful_parentrevs() by changeset_templater's

Because changeset_printer needs pctx object anyway, there would be no benefit
to avoid creation of pctx in _meaningful_parentrevs().

Patch

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -1118,9 +1118,6 @@  class changeset_printer(object):
         else:
             hexfunc = short
 
-        parents = [self.repo[p]
-                   for p in self._meaningful_parentrevs(log, rev)]
-
         # i18n: column positioning for "hg log"
         self.ui.write(_("changeset:   %d:%s\n") % (rev, hexfunc(changenode)),
                       label='log.changeset changeset.%s' % ctx.phasestr())
@@ -1148,7 +1145,7 @@  class changeset_printer(object):
             # i18n: column positioning for "hg log"
             self.ui.write(_("phase:       %s\n") % _(ctx.phasestr()),
                           label='log.phase')
-        for pctx in parents:
+        for pctx in self._meaningful_parentrevs(ctx):
             label = 'log.parent changeset.%s' % pctx.phasestr()
             # i18n: column positioning for "hg log"
             self.ui.write(_("parent:      %d:%s\n")
@@ -1232,19 +1229,20 @@  class changeset_printer(object):
                                match=matchfn, stat=False)
             self.ui.write("\n")
 
-    def _meaningful_parentrevs(self, log, rev):
+    def _meaningful_parentrevs(self, ctx):
         """Return list of meaningful (or all if debug) parentrevs for rev.
 
         For merges (two non-nullrev revisions) both parents are meaningful.
         Otherwise the first parent revision is considered meaningful if it
         is not the preceding revision.
         """
-        parents = log.parentrevs(rev)
-        if not self.ui.debugflag and parents[1] == nullrev:
-            if parents[0] >= rev - 1:
-                parents = []
-            else:
-                parents = [parents[0]]
+        parents = ctx.parents()
+        if len(parents) > 1:
+            return parents
+        if self.ui.debugflag:
+            return [parents[0], self.repo['null']]
+        if parents[0].rev() >= ctx.rev() - 1:
+            return []
         return parents
 
 class jsonchangeset(changeset_printer):
@@ -1358,18 +1356,6 @@  class changeset_templater(changeset_prin
 
         self.cache = {}
 
-    def _meaningful_parentrevs(self, ctx):
-        """Return list of meaningful (or all if debug) parentrevs for rev.
-        """
-        parents = ctx.parents()
-        if len(parents) > 1:
-            return parents
-        if self.ui.debugflag:
-            return [parents[0], self.repo['null']]
-        if parents[0].rev() >= ctx.rev() - 1:
-            return []
-        return parents
-
     def _show(self, ctx, copies, matchfn, props):
         '''show a single changeset or file revision'''