Patchwork [2,of,5] changeset_printer: move _meaningful_parentrevs() to scmutil

login
register
mail settings
Submitter Yuya Nishihara
Date Oct. 1, 2015, 1:38 p.m.
Message ID <e2a3cb8dcc7fe5f62f78.1443706686@mimosa>
Download mbox | patch
Permalink /patch/10714/
State Accepted
Headers show

Comments

Yuya Nishihara - Oct. 1, 2015, 1:38 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1443238149 -32400
#      Sat Sep 26 12:29:09 2015 +0900
# Node ID e2a3cb8dcc7fe5f62f78b06153d9b16441c4557a
# Parent  c310d3303e03b338ed5ad8c9a8254d19effc8915
changeset_printer: move _meaningful_parentrevs() to scmutil

It will be used by templatekw.

Patch

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -1195,7 +1195,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 self._meaningful_parentrevs(ctx):
+        for pctx in scmutil.meaningfulparents(self.repo, ctx):
             label = 'log.parent changeset.%s' % pctx.phasestr()
             # i18n: column positioning for "hg log"
             self.ui.write(_("parent:      %d:%s\n")
@@ -1279,22 +1279,6 @@  class changeset_printer(object):
                                match=matchfn, stat=False)
             self.ui.write("\n")
 
-    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 = ctx.parents()
-        if len(parents) > 1:
-            return parents
-        if self.ui.debugflag:
-            return [parents[0], self.repo['null']]
-        if parents[0].rev() >= scmutil.intrev(ctx.rev()) - 1:
-            return []
-        return parents
-
 class jsonchangeset(changeset_printer):
     '''format changeset information.'''
 
@@ -1456,7 +1440,7 @@  class changeset_templater(changeset_prin
             parents = [[('rev', p.rev()),
                         ('node', p.hex()),
                         ('phase', p.phasestr())]
-                       for p in self._meaningful_parentrevs(ctx)]
+                       for p in scmutil.meaningfulparents(self.repo, ctx)]
             return showlist('parent', parents, **args)
 
         props = props.copy()
diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -734,6 +734,22 @@  def revrange(repo, revs):
     m = revset.matchany(repo.ui, allspecs, repo)
     return m(repo)
 
+def meaningfulparents(repo, 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 = ctx.parents()
+    if len(parents) > 1:
+        return parents
+    if repo.ui.debugflag:
+        return [parents[0], repo['null']]
+    if parents[0].rev() >= intrev(ctx.rev()) - 1:
+        return []
+    return parents
+
 def expandpats(pats):
     '''Expand bare globs when running on windows.
     On posix we assume it already has already been done by sh.'''