Mercurial > hg
comparison mercurial/cmdutil.py @ 35644:7a0a90d63a8c
log: use revsetlang.formatspec() to concatenate list expression
This rewrites 'not ancestors(x) and not ...' as 'not (ancestors(x) or ...)'
so we can use '%lr'. 'isinstance(val, list)' is replaced with 'listop' to
make sure 'listop' is applied.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Tue, 02 Jan 2018 17:13:18 +0900 |
parents | 668c5a527eff |
children | b6b7855c79aa |
comparison
equal
deleted
inserted
replaced
35643:668c5a527eff | 35644:7a0a90d63a8c |
---|---|
39 pathutil, | 39 pathutil, |
40 pycompat, | 40 pycompat, |
41 registrar, | 41 registrar, |
42 revlog, | 42 revlog, |
43 revset, | 43 revset, |
44 revsetlang, | |
44 scmutil, | 45 scmutil, |
45 smartset, | 46 smartset, |
46 templatekw, | 47 templatekw, |
47 templater, | 48 templater, |
48 util, | 49 util, |
2345 '_fancestors': ('_firstancestors(%(val)s)', None), | 2346 '_fancestors': ('_firstancestors(%(val)s)', None), |
2346 '_descendants': ('descendants(%(val)s)', None), | 2347 '_descendants': ('descendants(%(val)s)', None), |
2347 '_fdescendants': ('_firstdescendants(%(val)s)', None), | 2348 '_fdescendants': ('_firstdescendants(%(val)s)', None), |
2348 '_matchfiles': ('_matchfiles(%(val)s)', None), | 2349 '_matchfiles': ('_matchfiles(%(val)s)', None), |
2349 'date': ('date(%(val)r)', None), | 2350 'date': ('date(%(val)r)', None), |
2350 'branch': ('branch(%(val)r)', ' or '), | 2351 'branch': ('branch(%(val)r)', '%lr'), |
2351 '_patslog': ('filelog(%(val)r)', ' or '), | 2352 '_patslog': ('filelog(%(val)r)', '%lr'), |
2352 '_patsfollow': ('follow(%(val)r)', ' or '), | 2353 '_patsfollow': ('follow(%(val)r)', '%lr'), |
2353 '_patsfollowfirst': ('_followfirst(%(val)r)', ' or '), | 2354 '_patsfollowfirst': ('_followfirst(%(val)r)', '%lr'), |
2354 'keyword': ('keyword(%(val)r)', ' or '), | 2355 'keyword': ('keyword(%(val)r)', '%lr'), |
2355 'prune': ('not ancestors(%(val)r)', ' and '), | 2356 'prune': ('ancestors(%(val)r)', 'not %lr'), |
2356 'user': ('user(%(val)r)', ' or '), | 2357 'user': ('user(%(val)r)', '%lr'), |
2357 } | 2358 } |
2358 | 2359 |
2359 def _makelogrevset(repo, pats, opts, revs): | 2360 def _makelogrevset(repo, pats, opts, revs): |
2360 """Return (expr, filematcher) where expr is a revset string built | 2361 """Return (expr, filematcher) where expr is a revset string built |
2361 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 |
2471 for op, val in sorted(opts.iteritems()): | 2472 for op, val in sorted(opts.iteritems()): |
2472 if not val: | 2473 if not val: |
2473 continue | 2474 continue |
2474 if op not in _opt2logrevset: | 2475 if op not in _opt2logrevset: |
2475 continue | 2476 continue |
2476 revop, andor = _opt2logrevset[op] | 2477 revop, listop = _opt2logrevset[op] |
2477 if '%(val)' not in revop: | 2478 if '%(val)' not in revop: |
2478 expr.append(revop) | 2479 expr.append(revop) |
2479 else: | 2480 else: |
2480 if not isinstance(val, list): | 2481 if not listop: |
2481 e = revop % {'val': val} | 2482 e = revop % {'val': val} |
2482 else: | 2483 else: |
2483 e = '(' + andor.join((revop % {'val': v}) for v in val) + ')' | 2484 e = [revop % {'val': v} for v in val] |
2485 e = revsetlang.formatspec(listop, e) | |
2484 expr.append(e) | 2486 expr.append(e) |
2485 | 2487 |
2486 if expr: | 2488 if expr: |
2487 expr = '(' + ' and '.join(expr) + ')' | 2489 expr = '(' + ' and '.join(expr) + ')' |
2488 else: | 2490 else: |