log: merge getlogrevs() and getgraphlogrevs()
authorYuya Nishihara <yuya@tcha.org>
Thu, 04 Jan 2018 10:51:41 +0900
changeset 35543 a7f7eff4ec08
parent 35542 beb667c9880f
child 35544 8494944940e5
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.
mercurial/cmdutil.py
mercurial/commands.py
tests/test-glog.t
--- a/mercurial/cmdutil.py	Sat Dec 30 17:55:23 2017 +0900
+++ b/mercurial/cmdutil.py	Thu Jan 04 10:51:41 2018 +0900
@@ -2506,7 +2506,7 @@
         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 @@
     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 @@
 
     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 @@
             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
--- a/mercurial/commands.py	Sat Dec 30 17:55:23 2017 +0900
+++ b/mercurial/commands.py	Thu Jan 04 10:51:41 2018 +0900
@@ -3409,14 +3409,14 @@
         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(
--- a/tests/test-glog.t	Sat Dec 30 17:55:23 2017 +0900
+++ b/tests/test-glog.t	Thu Jan 04 10:51:41 2018 +0900
@@ -93,7 +93,7 @@
   > 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: