Patchwork [1,of,6] log: merge getlogrevs() and getgraphlogrevs()

login
register
mail settings
Submitter Yuya Nishihara
Date Jan. 4, 2018, 8:36 a.m.
Message ID <340e4b15e4e6d6d020d2.1515055002@mimosa>
Download mbox | patch
Permalink /patch/26530/
State Accepted
Headers show

Comments

Yuya Nishihara - Jan. 4, 2018, 8:36 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1515030701 -32400
#      Thu Jan 04 10:51:41 2018 +0900
# Node ID 340e4b15e4e6d6d020d2c7d8f8683c7c11598925
# Parent  e01549a7bf0a6a7adbbb317a5d4bfde36c205b4d
log: merge getlogrevs() and getgraphlogrevs()

cmdutil.graphlog() is updated to receive (revs, filematcher) as arguments
to make sure that opts['graph'] is set when getlogrevs() is invoked.

Patch

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -2506,7 +2506,7 @@  def _logrevs(repo, opts):
         revs.reverse()
     return revs
 
-def getgraphlogrevs(repo, pats, opts):
+def getlogrevs(repo, pats, opts):
     """Return (revs, expr, filematcher) where revs is an iterable of
     revision numbers, expr is a revset string built from log options
     and file patterns or None, and used to filter 'revs'. If --stat or
@@ -2519,7 +2519,7 @@  def getgraphlogrevs(repo, pats, opts):
     if not revs:
         return smartset.baseset(), None, None
     expr, filematcher = _makelogrevset(repo, pats, opts, revs)
-    if opts.get('rev'):
+    if opts.get('graph') and opts.get('rev'):
         # User-specified revs might be unsorted, but don't sort before
         # _makelogrevset because it might depend on the order of revs
         if not (revs.isdescending() or revs.istopo()):
@@ -2537,32 +2537,6 @@  def getgraphlogrevs(repo, pats, opts):
 
     return revs, expr, filematcher
 
-def getlogrevs(repo, pats, opts):
-    """Return (revs, expr, filematcher) where revs is an iterable of
-    revision numbers, expr is a revset string built from log options
-    and file patterns or None, and used to filter 'revs'. If --stat or
-    --patch are not passed filematcher is None. Otherwise it is a
-    callable taking a revision number and returning a match objects
-    filtering the files to be detailed when displaying the revision.
-    """
-    limit = loglimit(opts)
-    revs = _logrevs(repo, opts)
-    if not revs:
-        return smartset.baseset([]), None, None
-    expr, filematcher = _makelogrevset(repo, pats, opts, revs)
-    if expr:
-        matcher = revset.match(repo.ui, expr)
-        revs = matcher(repo, revs)
-    if limit is not None:
-        limitedrevs = []
-        for idx, r in enumerate(revs):
-            if limit <= idx:
-                break
-            limitedrevs.append(r)
-        revs = smartset.baseset(limitedrevs)
-
-    return revs, expr, filematcher
-
 def _parselinerangelogopt(repo, opts):
     """Parse --line-range log option and return a list of tuples (filename,
     (fromline, toline)).
@@ -2719,9 +2693,8 @@  def displaygraph(ui, repo, dag, displaye
             lines = []
     displayer.close()
 
-def graphlog(ui, repo, pats, opts):
+def graphlog(ui, repo, revs, filematcher, opts):
     # Parameters are identical to log command ones
-    revs, expr, filematcher = getgraphlogrevs(repo, pats, opts)
     revdag = graphmod.dagwalker(repo, revs)
 
     getrenamed = None
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -3400,14 +3400,14 @@  def log(ui, repo, *pats, **opts):
         opts['rev'] = [revsetlang.formatspec('reverse(::%lr)', opts.get('rev'))]
         del opts['follow']
 
+    repo = scmutil.unhidehashlikerevs(repo, opts.get('rev'), 'nowarn')
+    revs, expr, filematcher = cmdutil.getlogrevs(repo, pats, opts)
+    hunksfilter = None
+
     if opts.get('graph'):
         if linerange:
             raise error.Abort(_('graph not supported with line range patterns'))
-        return cmdutil.graphlog(ui, repo, pats, opts)
-
-    repo = scmutil.unhidehashlikerevs(repo, opts.get('rev'), 'nowarn')
-    revs, expr, filematcher = cmdutil.getlogrevs(repo, pats, opts)
-    hunksfilter = None
+        return cmdutil.graphlog(ui, repo, revs, filematcher, opts)
 
     if linerange:
         revs, lrfilematcher, hunksfilter = cmdutil.getloglinerangerevs(
diff --git a/tests/test-glog.t b/tests/test-glog.t
--- a/tests/test-glog.t
+++ b/tests/test-glog.t
@@ -93,7 +93,7 @@  o  (0) root
   > def uisetup(ui):
   >     def printrevset(orig, ui, repo, *pats, **opts):
   >         if opts.get('print_revset'):
-  >             expr = cmdutil.getgraphlogrevs(repo, pats, opts)[1]
+  >             expr = cmdutil.getlogrevs(repo, pats, opts)[1]
   >             if expr:
   >                 tree = revsetlang.parse(expr)
   >             else: