comparison mercurial/cmdutil.py @ 35645:b6b7855c79aa

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.
author Yuya Nishihara <yuya@tcha.org>
date Tue, 02 Jan 2018 17:37:01 +0900
parents 7a0a90d63a8c
children 91f0979f16c0
comparison
equal deleted inserted replaced
35644:7a0a90d63a8c 35645:b6b7855c79aa
2340 return None 2340 return None
2341 2341
2342 _opt2logrevset = { 2342 _opt2logrevset = {
2343 'no_merges': ('not merge()', None), 2343 'no_merges': ('not merge()', None),
2344 'only_merges': ('merge()', None), 2344 'only_merges': ('merge()', None),
2345 '_ancestors': ('ancestors(%(val)s)', None), 2345 '_ancestors': ('ancestors(%r)', None),
2346 '_fancestors': ('_firstancestors(%(val)s)', None), 2346 '_fancestors': ('_firstancestors(%r)', None),
2347 '_descendants': ('descendants(%(val)s)', None), 2347 '_descendants': ('descendants(%r)', None),
2348 '_fdescendants': ('_firstdescendants(%(val)s)', None), 2348 '_fdescendants': ('_firstdescendants(%r)', None),
2349 '_matchfiles': ('_matchfiles(%(val)s)', None), 2349 '_matchfiles': (None, '_matchfiles(%ps)'),
2350 'date': ('date(%(val)r)', None), 2350 'date': ('date(%s)', None),
2351 'branch': ('branch(%(val)r)', '%lr'), 2351 'branch': ('branch(%s)', '%lr'),
2352 '_patslog': ('filelog(%(val)r)', '%lr'), 2352 '_patslog': ('filelog(%s)', '%lr'),
2353 '_patsfollow': ('follow(%(val)r)', '%lr'), 2353 '_patsfollow': ('follow(%s)', '%lr'),
2354 '_patsfollowfirst': ('_followfirst(%(val)r)', '%lr'), 2354 '_patsfollowfirst': ('_followfirst(%s)', '%lr'),
2355 'keyword': ('keyword(%(val)r)', '%lr'), 2355 'keyword': ('keyword(%s)', '%lr'),
2356 'prune': ('ancestors(%(val)r)', 'not %lr'), 2356 'prune': ('ancestors(%s)', 'not %lr'),
2357 'user': ('user(%(val)r)', '%lr'), 2357 'user': ('user(%s)', '%lr'),
2358 } 2358 }
2359 2359
2360 def _makelogrevset(repo, pats, opts, revs): 2360 def _makelogrevset(repo, pats, opts, revs):
2361 """Return (expr, filematcher) where expr is a revset string built 2361 """Return (expr, filematcher) where expr is a revset string built
2362 from log options and file patterns or None. If --stat or --patch 2362 from log options and file patterns or None. If --stat or --patch
2435 matchargs.append('p:' + p) 2435 matchargs.append('p:' + p)
2436 for p in opts.get('include', []): 2436 for p in opts.get('include', []):
2437 matchargs.append('i:' + p) 2437 matchargs.append('i:' + p)
2438 for p in opts.get('exclude', []): 2438 for p in opts.get('exclude', []):
2439 matchargs.append('x:' + p) 2439 matchargs.append('x:' + p)
2440 matchargs = ','.join(('%r' % p) for p in matchargs)
2441 opts['_matchfiles'] = matchargs 2440 opts['_matchfiles'] = matchargs
2442 if follow: 2441 if follow:
2443 opts[fnopats[0][followfirst]] = '.' 2442 opts[fnopats[0][followfirst]] = '.'
2444 else: 2443 else:
2445 if follow: 2444 if follow:
2473 if not val: 2472 if not val:
2474 continue 2473 continue
2475 if op not in _opt2logrevset: 2474 if op not in _opt2logrevset:
2476 continue 2475 continue
2477 revop, listop = _opt2logrevset[op] 2476 revop, listop = _opt2logrevset[op]
2478 if '%(val)' not in revop: 2477 if revop and '%' not in revop:
2479 expr.append(revop) 2478 expr.append(revop)
2479 elif not listop:
2480 expr.append(revsetlang.formatspec(revop, val))
2480 else: 2481 else:
2481 if not listop: 2482 if revop:
2482 e = revop % {'val': val} 2483 val = [revsetlang.formatspec(revop, v) for v in val]
2483 else: 2484 expr.append(revsetlang.formatspec(listop, val))
2484 e = [revop % {'val': v} for v in val]
2485 e = revsetlang.formatspec(listop, e)
2486 expr.append(e)
2487 2485
2488 if expr: 2486 if expr:
2489 expr = '(' + ' and '.join(expr) + ')' 2487 expr = '(' + ' and '.join(expr) + ')'
2490 else: 2488 else:
2491 expr = None 2489 expr = None