comparison mercurial/cmdutil.py @ 35642:e64baf32782a

log: make opt2revset table a module constant Just makes it clear that the table isn't updated in _makelogrevset().
author Yuya Nishihara <yuya@tcha.org>
date Tue, 02 Jan 2018 16:58:37 +0900
parents b14c8bcfbad9
children 668c5a527eff
comparison
equal deleted inserted replaced
35641:c41bb85c09ff 35642:e64baf32782a
2336 2336
2337 def _makenofollowlogfilematcher(repo, pats, opts): 2337 def _makenofollowlogfilematcher(repo, pats, opts):
2338 '''hook for extensions to override the filematcher for non-follow cases''' 2338 '''hook for extensions to override the filematcher for non-follow cases'''
2339 return None 2339 return None
2340 2340
2341 _opt2logrevset = {
2342 'no_merges': ('not merge()', None),
2343 'only_merges': ('merge()', None),
2344 '_ancestors': ('ancestors(%(val)s)', None),
2345 '_fancestors': ('_firstancestors(%(val)s)', None),
2346 '_descendants': ('descendants(%(val)s)', None),
2347 '_fdescendants': ('_firstdescendants(%(val)s)', None),
2348 '_matchfiles': ('_matchfiles(%(val)s)', None),
2349 'date': ('date(%(val)r)', None),
2350 'branch': ('branch(%(val)r)', ' or '),
2351 '_patslog': ('filelog(%(val)r)', ' or '),
2352 '_patsfollow': ('follow(%(val)r)', ' or '),
2353 '_patsfollowfirst': ('_followfirst(%(val)r)', ' or '),
2354 'keyword': ('keyword(%(val)r)', ' or '),
2355 'prune': ('not (%(val)r or ancestors(%(val)r))', ' and '),
2356 'user': ('user(%(val)r)', ' or '),
2357 }
2358
2341 def _makelogrevset(repo, pats, opts, revs): 2359 def _makelogrevset(repo, pats, opts, revs):
2342 """Return (expr, filematcher) where expr is a revset string built 2360 """Return (expr, filematcher) where expr is a revset string built
2343 from log options and file patterns or None. If --stat or --patch 2361 from log options and file patterns or None. If --stat or --patch
2344 are not passed filematcher is None. Otherwise it is a callable 2362 are not passed filematcher is None. Otherwise it is a callable
2345 taking a revision number and returning a match objects filtering 2363 taking a revision number and returning a match objects filtering
2346 the files to be detailed when displaying the revision. 2364 the files to be detailed when displaying the revision.
2347 """ 2365 """
2348 opt2revset = {
2349 'no_merges': ('not merge()', None),
2350 'only_merges': ('merge()', None),
2351 '_ancestors': ('ancestors(%(val)s)', None),
2352 '_fancestors': ('_firstancestors(%(val)s)', None),
2353 '_descendants': ('descendants(%(val)s)', None),
2354 '_fdescendants': ('_firstdescendants(%(val)s)', None),
2355 '_matchfiles': ('_matchfiles(%(val)s)', None),
2356 'date': ('date(%(val)r)', None),
2357 'branch': ('branch(%(val)r)', ' or '),
2358 '_patslog': ('filelog(%(val)r)', ' or '),
2359 '_patsfollow': ('follow(%(val)r)', ' or '),
2360 '_patsfollowfirst': ('_followfirst(%(val)r)', ' or '),
2361 'keyword': ('keyword(%(val)r)', ' or '),
2362 'prune': ('not (%(val)r or ancestors(%(val)r))', ' and '),
2363 'user': ('user(%(val)r)', ' or '),
2364 }
2365
2366 opts = dict(opts) 2366 opts = dict(opts)
2367 # follow or not follow? 2367 # follow or not follow?
2368 follow = opts.get('follow') or opts.get('follow_first') 2368 follow = opts.get('follow') or opts.get('follow_first')
2369 if opts.get('follow_first'): 2369 if opts.get('follow_first'):
2370 followfirst = 1 2370 followfirst = 1
2469 2469
2470 expr = [] 2470 expr = []
2471 for op, val in sorted(opts.iteritems()): 2471 for op, val in sorted(opts.iteritems()):
2472 if not val: 2472 if not val:
2473 continue 2473 continue
2474 if op not in opt2revset: 2474 if op not in _opt2logrevset:
2475 continue 2475 continue
2476 revop, andor = opt2revset[op] 2476 revop, andor = _opt2logrevset[op]
2477 if '%(val)' not in revop: 2477 if '%(val)' not in revop:
2478 expr.append(revop) 2478 expr.append(revop)
2479 else: 2479 else:
2480 if not isinstance(val, list): 2480 if not isinstance(val, list):
2481 e = revop % {'val': val} 2481 e = revop % {'val': val}