Patchwork [1,of,5] log: make opt2revset table a module constant

login
register
mail settings
Submitter Yuya Nishihara
Date Jan. 11, 2018, 1:58 p.m.
Message ID <da12c978eafe1b414122.1515679120@mimosa>
Download mbox | patch
Permalink /patch/26686/
State Accepted
Headers show

Comments

Yuya Nishihara - Jan. 11, 2018, 1:58 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1514879917 -32400
#      Tue Jan 02 16:58:37 2018 +0900
# Node ID da12c978eafe1b414122213c75ce149a5e8d8b5b
# Parent  4b68ca118d8d316cff1fbfe260e8fdb0dae3e26a
log: make opt2revset table a module constant

Just makes it clear that the table isn't updated in _makelogrevset().
Gregory Szorc - Jan. 14, 2018, 9:20 p.m.
On Thu, Jan 11, 2018 at 5:58 AM, Yuya Nishihara <yuya@tcha.org> wrote:

> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1514879917 -32400
> #      Tue Jan 02 16:58:37 2018 +0900
> # Node ID da12c978eafe1b414122213c75ce149a5e8d8b5b
> # Parent  4b68ca118d8d316cff1fbfe260e8fdb0dae3e26a
> log: make opt2revset table a module constant
>

Queued this series. Nice cleanup for the revspecs.


>
> Just makes it clear that the table isn't updated in _makelogrevset().
>
> diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
> --- a/mercurial/cmdutil.py
> +++ b/mercurial/cmdutil.py
> @@ -2338,6 +2338,24 @@ def _makenofollowlogfilematcher(repo, pa
>      '''hook for extensions to override the filematcher for non-follow
> cases'''
>      return None
>
> +_opt2logrevset = {
> +    'no_merges':        ('not merge()', None),
> +    'only_merges':      ('merge()', None),
> +    '_ancestors':       ('ancestors(%(val)s)', None),
> +    '_fancestors':      ('_firstancestors(%(val)s)', None),
> +    '_descendants':     ('descendants(%(val)s)', None),
> +    '_fdescendants':    ('_firstdescendants(%(val)s)', None),
> +    '_matchfiles':      ('_matchfiles(%(val)s)', None),
> +    'date':             ('date(%(val)r)', None),
> +    'branch':           ('branch(%(val)r)', ' or '),
> +    '_patslog':         ('filelog(%(val)r)', ' or '),
> +    '_patsfollow':      ('follow(%(val)r)', ' or '),
> +    '_patsfollowfirst': ('_followfirst(%(val)r)', ' or '),
> +    'keyword':          ('keyword(%(val)r)', ' or '),
> +    'prune':            ('not (%(val)r or ancestors(%(val)r))', ' and '),
> +    'user':             ('user(%(val)r)', ' or '),
> +}
> +
>  def _makelogrevset(repo, pats, opts, revs):
>      """Return (expr, filematcher) where expr is a revset string built
>      from log options and file patterns or None. If --stat or --patch
> @@ -2345,24 +2363,6 @@ def _makelogrevset(repo, pats, opts, rev
>      taking a revision number and returning a match objects filtering
>      the files to be detailed when displaying the revision.
>      """
> -    opt2revset = {
> -        'no_merges':        ('not merge()', None),
> -        'only_merges':      ('merge()', None),
> -        '_ancestors':       ('ancestors(%(val)s)', None),
> -        '_fancestors':      ('_firstancestors(%(val)s)', None),
> -        '_descendants':     ('descendants(%(val)s)', None),
> -        '_fdescendants':    ('_firstdescendants(%(val)s)', None),
> -        '_matchfiles':      ('_matchfiles(%(val)s)', None),
> -        'date':             ('date(%(val)r)', None),
> -        'branch':           ('branch(%(val)r)', ' or '),
> -        '_patslog':         ('filelog(%(val)r)', ' or '),
> -        '_patsfollow':      ('follow(%(val)r)', ' or '),
> -        '_patsfollowfirst': ('_followfirst(%(val)r)', ' or '),
> -        'keyword':          ('keyword(%(val)r)', ' or '),
> -        'prune':            ('not (%(val)r or ancestors(%(val)r))', ' and
> '),
> -        'user':             ('user(%(val)r)', ' or '),
> -        }
> -
>      opts = dict(opts)
>      # follow or not follow?
>      follow = opts.get('follow') or opts.get('follow_first')
> @@ -2471,9 +2471,9 @@ def _makelogrevset(repo, pats, opts, rev
>      for op, val in sorted(opts.iteritems()):
>          if not val:
>              continue
> -        if op not in opt2revset:
> +        if op not in _opt2logrevset:
>              continue
> -        revop, andor = opt2revset[op]
> +        revop, andor = _opt2logrevset[op]
>          if '%(val)' not in revop:
>              expr.append(revop)
>          else:
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
>

Patch

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -2338,6 +2338,24 @@  def _makenofollowlogfilematcher(repo, pa
     '''hook for extensions to override the filematcher for non-follow cases'''
     return None
 
+_opt2logrevset = {
+    'no_merges':        ('not merge()', None),
+    'only_merges':      ('merge()', None),
+    '_ancestors':       ('ancestors(%(val)s)', None),
+    '_fancestors':      ('_firstancestors(%(val)s)', None),
+    '_descendants':     ('descendants(%(val)s)', None),
+    '_fdescendants':    ('_firstdescendants(%(val)s)', None),
+    '_matchfiles':      ('_matchfiles(%(val)s)', None),
+    'date':             ('date(%(val)r)', None),
+    'branch':           ('branch(%(val)r)', ' or '),
+    '_patslog':         ('filelog(%(val)r)', ' or '),
+    '_patsfollow':      ('follow(%(val)r)', ' or '),
+    '_patsfollowfirst': ('_followfirst(%(val)r)', ' or '),
+    'keyword':          ('keyword(%(val)r)', ' or '),
+    'prune':            ('not (%(val)r or ancestors(%(val)r))', ' and '),
+    'user':             ('user(%(val)r)', ' or '),
+}
+
 def _makelogrevset(repo, pats, opts, revs):
     """Return (expr, filematcher) where expr is a revset string built
     from log options and file patterns or None. If --stat or --patch
@@ -2345,24 +2363,6 @@  def _makelogrevset(repo, pats, opts, rev
     taking a revision number and returning a match objects filtering
     the files to be detailed when displaying the revision.
     """
-    opt2revset = {
-        'no_merges':        ('not merge()', None),
-        'only_merges':      ('merge()', None),
-        '_ancestors':       ('ancestors(%(val)s)', None),
-        '_fancestors':      ('_firstancestors(%(val)s)', None),
-        '_descendants':     ('descendants(%(val)s)', None),
-        '_fdescendants':    ('_firstdescendants(%(val)s)', None),
-        '_matchfiles':      ('_matchfiles(%(val)s)', None),
-        'date':             ('date(%(val)r)', None),
-        'branch':           ('branch(%(val)r)', ' or '),
-        '_patslog':         ('filelog(%(val)r)', ' or '),
-        '_patsfollow':      ('follow(%(val)r)', ' or '),
-        '_patsfollowfirst': ('_followfirst(%(val)r)', ' or '),
-        'keyword':          ('keyword(%(val)r)', ' or '),
-        'prune':            ('not (%(val)r or ancestors(%(val)r))', ' and '),
-        'user':             ('user(%(val)r)', ' or '),
-        }
-
     opts = dict(opts)
     # follow or not follow?
     follow = opts.get('follow') or opts.get('follow_first')
@@ -2471,9 +2471,9 @@  def _makelogrevset(repo, pats, opts, rev
     for op, val in sorted(opts.iteritems()):
         if not val:
             continue
-        if op not in opt2revset:
+        if op not in _opt2logrevset:
             continue
-        revop, andor = opt2revset[op]
+        revop, andor = _opt2logrevset[op]
         if '%(val)' not in revop:
             expr.append(revop)
         else: