Patchwork [4,of,5] log: use revsetlang.formatspec() thoroughly

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

Comments

Yuya Nishihara - Jan. 11, 2018, 1:58 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1514882221 -32400
#      Tue Jan 02 17:37:01 2018 +0900
# Node ID 438dde28f8693b822898903325d2567c5e618c4b
# Parent  bab0b8954f8430710ddacf1db852a4420121f677
log: use revsetlang.formatspec() thoroughly

This patch replaces %(val)s and %(val)r with %r (expression) and %s (string)
respectively. _matchfiles() is the exception as it takes a list of string
parameters.

"--prune REV" could take a revset expression if it were "ancestors(%(val)s)",
but this patch doesn't change the existing behavior.

Patch

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -2342,19 +2342,19 @@  def _makenofollowlogfilematcher(repo, pa
 _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)', '%lr'),
-    '_patslog':         ('filelog(%(val)r)', '%lr'),
-    '_patsfollow':      ('follow(%(val)r)', '%lr'),
-    '_patsfollowfirst': ('_followfirst(%(val)r)', '%lr'),
-    'keyword':          ('keyword(%(val)r)', '%lr'),
-    'prune':            ('ancestors(%(val)r)', 'not %lr'),
-    'user':             ('user(%(val)r)', '%lr'),
+    '_ancestors':       ('ancestors(%r)', None),
+    '_fancestors':      ('_firstancestors(%r)', None),
+    '_descendants':     ('descendants(%r)', None),
+    '_fdescendants':    ('_firstdescendants(%r)', None),
+    '_matchfiles':      (None, '_matchfiles(%ps)'),
+    'date':             ('date(%s)', None),
+    'branch':           ('branch(%s)', '%lr'),
+    '_patslog':         ('filelog(%s)', '%lr'),
+    '_patsfollow':      ('follow(%s)', '%lr'),
+    '_patsfollowfirst': ('_followfirst(%s)', '%lr'),
+    'keyword':          ('keyword(%s)', '%lr'),
+    'prune':            ('ancestors(%s)', 'not %lr'),
+    'user':             ('user(%s)', '%lr'),
 }
 
 def _makelogrevset(repo, pats, opts, revs):
@@ -2437,7 +2437,6 @@  def _makelogrevset(repo, pats, opts, rev
             matchargs.append('i:' + p)
         for p in opts.get('exclude', []):
             matchargs.append('x:' + p)
-        matchargs = ','.join(('%r' % p) for p in matchargs)
         opts['_matchfiles'] = matchargs
         if follow:
             opts[fnopats[0][followfirst]] = '.'
@@ -2475,15 +2474,14 @@  def _makelogrevset(repo, pats, opts, rev
         if op not in _opt2logrevset:
             continue
         revop, listop = _opt2logrevset[op]
-        if '%(val)' not in revop:
+        if revop and '%' not in revop:
             expr.append(revop)
+        elif not listop:
+            expr.append(revsetlang.formatspec(revop, val))
         else:
-            if not listop:
-                e = revop % {'val': val}
-            else:
-                e = [revop % {'val': v} for v in val]
-                e = revsetlang.formatspec(listop, e)
-            expr.append(e)
+            if revop:
+                val = [revsetlang.formatspec(revop, v) for v in val]
+            expr.append(revsetlang.formatspec(listop, val))
 
     if expr:
         expr = '(' + ' and '.join(expr) + ')'