2010-06-01 20:18:57 +04:00
|
|
|
# revset.py - revision set queries for mercurial
|
|
|
|
#
|
|
|
|
# Copyright 2010 Matt Mackall <mpm@selenic.com>
|
|
|
|
#
|
|
|
|
# This software may be used and distributed according to the terms of the
|
|
|
|
# GNU General Public License version 2 or any later version.
|
|
|
|
|
2015-08-09 04:36:58 +03:00
|
|
|
from __future__ import absolute_import
|
|
|
|
|
2014-02-07 22:32:02 +04:00
|
|
|
import heapq
|
2015-08-09 04:36:58 +03:00
|
|
|
import re
|
2016-10-07 15:32:40 +03:00
|
|
|
import string
|
2015-08-09 04:36:58 +03:00
|
|
|
|
|
|
|
from .i18n import _
|
|
|
|
from . import (
|
2015-10-15 03:35:44 +03:00
|
|
|
destutil,
|
2015-08-09 04:36:58 +03:00
|
|
|
encoding,
|
|
|
|
error,
|
|
|
|
hbisect,
|
|
|
|
match as matchmod,
|
|
|
|
node,
|
|
|
|
obsolete as obsmod,
|
|
|
|
parser,
|
|
|
|
pathutil,
|
|
|
|
phases,
|
2016-10-07 15:32:40 +03:00
|
|
|
pycompat,
|
2015-12-29 17:58:30 +03:00
|
|
|
registrar,
|
2015-08-09 04:36:58 +03:00
|
|
|
repoview,
|
|
|
|
util,
|
|
|
|
)
|
2010-06-01 20:18:57 +04:00
|
|
|
|
2012-04-11 13:25:34 +04:00
|
|
|
def _revancestors(repo, revs, followfirst):
|
|
|
|
"""Like revlog.ancestors(), but supports followfirst."""
|
2015-03-14 00:00:06 +03:00
|
|
|
if followfirst:
|
|
|
|
cut = 1
|
|
|
|
else:
|
|
|
|
cut = None
|
2012-04-11 13:25:34 +04:00
|
|
|
cl = repo.changelog
|
2014-02-07 22:32:02 +04:00
|
|
|
|
|
|
|
def iterate():
|
2014-10-07 12:48:34 +04:00
|
|
|
revs.sort(reverse=True)
|
2014-03-27 03:21:30 +04:00
|
|
|
irevs = iter(revs)
|
2015-05-06 21:29:09 +03:00
|
|
|
h = []
|
2015-05-18 03:54:58 +03:00
|
|
|
|
|
|
|
inputrev = next(irevs, None)
|
|
|
|
if inputrev is not None:
|
2014-03-27 03:21:30 +04:00
|
|
|
heapq.heappush(h, -inputrev)
|
2014-02-08 01:44:57 +04:00
|
|
|
|
2015-01-25 14:20:27 +03:00
|
|
|
seen = set()
|
2014-02-07 22:32:02 +04:00
|
|
|
while h:
|
|
|
|
current = -heapq.heappop(h)
|
2014-03-27 02:55:50 +04:00
|
|
|
if current == inputrev:
|
2015-05-18 03:54:58 +03:00
|
|
|
inputrev = next(irevs, None)
|
|
|
|
if inputrev is not None:
|
2014-03-27 02:55:50 +04:00
|
|
|
heapq.heappush(h, -inputrev)
|
2014-02-07 22:32:02 +04:00
|
|
|
if current not in seen:
|
|
|
|
seen.add(current)
|
|
|
|
yield current
|
|
|
|
for parent in cl.parentrevs(current)[:cut]:
|
|
|
|
if parent != node.nullrev:
|
|
|
|
heapq.heappush(h, -parent)
|
|
|
|
|
2014-10-04 07:12:02 +04:00
|
|
|
return generatorset(iterate(), iterasc=False)
|
2012-04-11 13:25:34 +04:00
|
|
|
|
|
|
|
def _revdescendants(repo, revs, followfirst):
|
|
|
|
"""Like revlog.descendants() but supports followfirst."""
|
2015-03-14 00:00:06 +03:00
|
|
|
if followfirst:
|
|
|
|
cut = 1
|
|
|
|
else:
|
|
|
|
cut = None
|
2014-02-11 00:26:45 +04:00
|
|
|
|
|
|
|
def iterate():
|
|
|
|
cl = repo.changelog
|
2015-06-12 00:26:44 +03:00
|
|
|
# XXX this should be 'parentset.min()' assuming 'parentset' is a
|
|
|
|
# smartset (and if it is not, it should.)
|
2014-02-11 00:26:45 +04:00
|
|
|
first = min(revs)
|
|
|
|
nullrev = node.nullrev
|
|
|
|
if first == nullrev:
|
|
|
|
# Are there nodes with a null first parent and a non-null
|
|
|
|
# second one? Maybe. Do we care? Probably not.
|
|
|
|
for i in cl:
|
2012-04-11 13:25:34 +04:00
|
|
|
yield i
|
2014-02-11 00:26:45 +04:00
|
|
|
else:
|
|
|
|
seen = set(revs)
|
|
|
|
for i in cl.revs(first + 1):
|
|
|
|
for x in cl.parentrevs(i)[:cut]:
|
|
|
|
if x != nullrev and x in seen:
|
|
|
|
seen.add(i)
|
|
|
|
yield i
|
|
|
|
break
|
|
|
|
|
2014-10-04 07:12:02 +04:00
|
|
|
return generatorset(iterate(), iterasc=True)
|
2012-04-11 13:25:34 +04:00
|
|
|
|
2015-08-28 05:15:31 +03:00
|
|
|
def _reachablerootspure(repo, minroot, roots, heads, includepath):
|
2015-06-20 06:18:54 +03:00
|
|
|
"""return (heads(::<roots> and ::<heads>))
|
|
|
|
|
|
|
|
If includepath is True, return (<roots>::<heads>)."""
|
2012-06-02 02:50:22 +04:00
|
|
|
if not roots:
|
2015-08-28 05:14:24 +03:00
|
|
|
return []
|
2012-06-02 02:50:22 +04:00
|
|
|
parentrevs = repo.changelog.parentrevs
|
2015-08-14 09:43:29 +03:00
|
|
|
roots = set(roots)
|
2014-09-17 09:55:49 +04:00
|
|
|
visit = list(heads)
|
2012-06-02 02:50:22 +04:00
|
|
|
reachable = set()
|
|
|
|
seen = {}
|
2015-06-11 21:42:46 +03:00
|
|
|
# prefetch all the things! (because python is slow)
|
|
|
|
reached = reachable.add
|
|
|
|
dovisit = visit.append
|
|
|
|
nextvisit = visit.pop
|
2012-06-02 02:50:22 +04:00
|
|
|
# open-code the post-order traversal due to the tiny size of
|
|
|
|
# sys.getrecursionlimit()
|
|
|
|
while visit:
|
2015-06-11 21:42:46 +03:00
|
|
|
rev = nextvisit()
|
2012-06-02 02:50:22 +04:00
|
|
|
if rev in roots:
|
2015-06-11 21:42:46 +03:00
|
|
|
reached(rev)
|
2015-06-20 06:18:54 +03:00
|
|
|
if not includepath:
|
|
|
|
continue
|
2012-06-02 02:50:22 +04:00
|
|
|
parents = parentrevs(rev)
|
|
|
|
seen[rev] = parents
|
|
|
|
for parent in parents:
|
|
|
|
if parent >= minroot and parent not in seen:
|
2015-06-11 21:42:46 +03:00
|
|
|
dovisit(parent)
|
2012-06-02 02:50:22 +04:00
|
|
|
if not reachable:
|
2014-10-06 21:41:43 +04:00
|
|
|
return baseset()
|
2015-06-20 06:18:54 +03:00
|
|
|
if not includepath:
|
|
|
|
return reachable
|
2012-06-02 02:50:22 +04:00
|
|
|
for rev in sorted(seen):
|
|
|
|
for parent in seen[rev]:
|
|
|
|
if parent in reachable:
|
2015-06-11 21:42:46 +03:00
|
|
|
reached(rev)
|
2015-08-25 01:40:42 +03:00
|
|
|
return reachable
|
2012-06-02 02:50:22 +04:00
|
|
|
|
2015-08-07 08:11:20 +03:00
|
|
|
def reachableroots(repo, roots, heads, includepath=False):
|
|
|
|
"""return (heads(::<roots> and ::<heads>))
|
|
|
|
|
|
|
|
If includepath is True, return (<roots>::<heads>)."""
|
|
|
|
if not roots:
|
|
|
|
return baseset()
|
2015-08-22 02:12:24 +03:00
|
|
|
minroot = roots.min()
|
2015-08-14 09:43:29 +03:00
|
|
|
roots = list(roots)
|
2015-08-07 08:11:20 +03:00
|
|
|
heads = list(heads)
|
|
|
|
try:
|
2015-08-28 05:14:24 +03:00
|
|
|
revs = repo.changelog.reachableroots(minroot, heads, roots, includepath)
|
2015-08-07 08:11:20 +03:00
|
|
|
except AttributeError:
|
2015-08-28 05:15:31 +03:00
|
|
|
revs = _reachablerootspure(repo, minroot, roots, heads, includepath)
|
2015-08-28 05:14:24 +03:00
|
|
|
revs = baseset(revs)
|
|
|
|
revs.sort()
|
|
|
|
return revs
|
2015-08-07 08:11:20 +03:00
|
|
|
|
2010-06-01 20:18:57 +04:00
|
|
|
elements = {
|
parser: separate actions for primary expression and prefix operator
This will allow us to define both a primary expression, ":", and a prefix
operator, ":y". The ambiguity will be resolved by the next patch.
Prefix actions in elements table are adjusted as follows:
original prefix primary prefix
----------------- -------- -----------------
("group", 1, ")") -> n/a ("group", 1, ")")
("negate", 19) -> n/a ("negate", 19)
("symbol",) -> "symbol" n/a
2015-07-05 06:02:13 +03:00
|
|
|
# token-type: binding-strength, primary, prefix, infix, suffix
|
|
|
|
"(": (21, None, ("group", 1, ")"), ("func", 1, ")"), None),
|
|
|
|
"##": (20, None, None, ("_concat", 20), None),
|
|
|
|
"~": (18, None, None, ("ancestor", 18), None),
|
2015-07-05 15:11:19 +03:00
|
|
|
"^": (18, None, None, ("parent", 18), "parentpost"),
|
parser: separate actions for primary expression and prefix operator
This will allow us to define both a primary expression, ":", and a prefix
operator, ":y". The ambiguity will be resolved by the next patch.
Prefix actions in elements table are adjusted as follows:
original prefix primary prefix
----------------- -------- -----------------
("group", 1, ")") -> n/a ("group", 1, ")")
("negate", 19) -> n/a ("negate", 19)
("symbol",) -> "symbol" n/a
2015-07-05 06:02:13 +03:00
|
|
|
"-": (5, None, ("negate", 19), ("minus", 5), None),
|
2015-07-05 15:11:19 +03:00
|
|
|
"::": (17, None, ("dagrangepre", 17), ("dagrange", 17), "dagrangepost"),
|
|
|
|
"..": (17, None, ("dagrangepre", 17), ("dagrange", 17), "dagrangepost"),
|
|
|
|
":": (15, "rangeall", ("rangepre", 15), ("range", 15), "rangepost"),
|
parser: separate actions for primary expression and prefix operator
This will allow us to define both a primary expression, ":", and a prefix
operator, ":y". The ambiguity will be resolved by the next patch.
Prefix actions in elements table are adjusted as follows:
original prefix primary prefix
----------------- -------- -----------------
("group", 1, ")") -> n/a ("group", 1, ")")
("negate", 19) -> n/a ("negate", 19)
("symbol",) -> "symbol" n/a
2015-07-05 06:02:13 +03:00
|
|
|
"not": (10, None, ("not", 10), None, None),
|
|
|
|
"!": (10, None, ("not", 10), None, None),
|
|
|
|
"and": (5, None, None, ("and", 5), None),
|
|
|
|
"&": (5, None, None, ("and", 5), None),
|
2015-07-05 15:11:19 +03:00
|
|
|
"%": (5, None, None, ("only", 5), "onlypost"),
|
parser: separate actions for primary expression and prefix operator
This will allow us to define both a primary expression, ":", and a prefix
operator, ":y". The ambiguity will be resolved by the next patch.
Prefix actions in elements table are adjusted as follows:
original prefix primary prefix
----------------- -------- -----------------
("group", 1, ")") -> n/a ("group", 1, ")")
("negate", 19) -> n/a ("negate", 19)
("symbol",) -> "symbol" n/a
2015-07-05 06:02:13 +03:00
|
|
|
"or": (4, None, None, ("or", 4), None),
|
|
|
|
"|": (4, None, None, ("or", 4), None),
|
|
|
|
"+": (4, None, None, ("or", 4), None),
|
|
|
|
"=": (3, None, None, ("keyvalue", 3), None),
|
|
|
|
",": (2, None, None, ("list", 2), None),
|
|
|
|
")": (0, None, None, None, None),
|
|
|
|
"symbol": (0, "symbol", None, None, None),
|
|
|
|
"string": (0, "string", None, None, None),
|
|
|
|
"end": (0, None, None, None, None),
|
2010-06-01 20:18:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
keywords = set(['and', 'or', 'not'])
|
|
|
|
|
2015-01-10 17:18:11 +03:00
|
|
|
# default set of valid characters for the initial letter of symbols
|
2016-10-07 15:32:40 +03:00
|
|
|
_syminitletters = set(
|
|
|
|
string.ascii_letters +
|
|
|
|
string.digits + pycompat.sysstr('._@')) | set(map(chr, xrange(128, 256)))
|
2015-01-10 17:18:11 +03:00
|
|
|
|
|
|
|
# default set of valid characters for non-initial letters of symbols
|
2016-10-07 15:32:40 +03:00
|
|
|
_symletters = _syminitletters | set(pycompat.sysstr('-/'))
|
2015-01-10 17:18:11 +03:00
|
|
|
|
|
|
|
def tokenize(program, lookup=None, syminitletters=None, symletters=None):
|
2012-10-31 03:48:44 +04:00
|
|
|
'''
|
|
|
|
Parse a revset statement into a stream of tokens
|
|
|
|
|
2015-01-10 17:18:11 +03:00
|
|
|
``syminitletters`` is the set of valid characters for the initial
|
|
|
|
letter of symbols.
|
|
|
|
|
|
|
|
By default, character ``c`` is recognized as valid for initial
|
|
|
|
letter of symbols, if ``c.isalnum() or c in '._@' or ord(c) > 127``.
|
|
|
|
|
|
|
|
``symletters`` is the set of valid characters for non-initial
|
|
|
|
letters of symbols.
|
|
|
|
|
|
|
|
By default, character ``c`` is recognized as valid for non-initial
|
|
|
|
letters of symbols, if ``c.isalnum() or c in '-._/@' or ord(c) > 127``.
|
|
|
|
|
2012-10-31 03:48:44 +04:00
|
|
|
Check that @ is a valid unquoted token character (issue3686):
|
|
|
|
>>> list(tokenize("@::"))
|
|
|
|
[('symbol', '@', 0), ('::', None, 1), ('end', None, 3)]
|
|
|
|
|
|
|
|
'''
|
2015-01-10 17:18:11 +03:00
|
|
|
if syminitletters is None:
|
|
|
|
syminitletters = _syminitletters
|
|
|
|
if symletters is None:
|
|
|
|
symletters = _symletters
|
2012-10-31 03:48:44 +04:00
|
|
|
|
2015-07-18 17:30:17 +03:00
|
|
|
if program and lookup:
|
|
|
|
# attempt to parse old-style ranges first to deal with
|
|
|
|
# things like old-tag which contain query metacharacters
|
|
|
|
parts = program.split(':', 1)
|
|
|
|
if all(lookup(sym) for sym in parts if sym):
|
|
|
|
if parts[0]:
|
|
|
|
yield ('symbol', parts[0], 0)
|
|
|
|
if len(parts) > 1:
|
|
|
|
s = len(parts[0])
|
|
|
|
yield (':', None, s)
|
|
|
|
if parts[1]:
|
|
|
|
yield ('symbol', parts[1], s + 1)
|
|
|
|
yield ('end', None, len(program))
|
|
|
|
return
|
|
|
|
|
2010-06-01 20:18:57 +04:00
|
|
|
pos, l = 0, len(program)
|
|
|
|
while pos < l:
|
|
|
|
c = program[pos]
|
|
|
|
if c.isspace(): # skip inter-token whitespace
|
|
|
|
pass
|
2010-06-02 23:07:46 +04:00
|
|
|
elif c == ':' and program[pos:pos + 2] == '::': # look ahead carefully
|
2010-06-05 05:57:52 +04:00
|
|
|
yield ('::', None, pos)
|
2010-06-02 23:07:46 +04:00
|
|
|
pos += 1 # skip ahead
|
2010-06-01 20:18:57 +04:00
|
|
|
elif c == '.' and program[pos:pos + 2] == '..': # look ahead carefully
|
2010-06-05 05:57:52 +04:00
|
|
|
yield ('..', None, pos)
|
2010-06-01 20:18:57 +04:00
|
|
|
pos += 1 # skip ahead
|
revset: introduce new operator "##" to concatenate strings/symbols at runtime
Before this patch, there is no way to concatenate strings at runtime.
For example, to search for the issue ID "1234" in descriptions against
all of "issue 1234", "issue:1234", issue1234" and "bug(1234)"
patterns, the revset below should be written fully from scratch for
each issue ID.
grep(r"\bissue[ :]?1234\b|\bbug\(1234\)")
This patch introduces new infix operator "##" to concatenate
strings/symbols at runtime. Operator symbol "##" comes from the same
one of C pre-processor. This concatenation allows parametrizing a part
of strings in revset queries.
In the case of example above, the definition of the revset alias using
operator "##" below can search issue ID "1234" in complicated patterns
by "issue(1234)" simply:
issue($1) = grep(r"\bissue[ :]?" ## $1 ## r"\b|\bbug\(" ## $1 ## r"\)")
"##" operator does:
- concatenate not only strings but also symbols into the string
Exact distinction between strings and symbols seems not to be
convenience, because it is tiresome for users (and
"revset.getstring" treats both similarly)
For example of revset alias "issue()", "issue(1234)" is easier
than "issue('1234')".
- have higher priority than any other prefix, infix and postfix
operators (like as "##" of C pre-processor)
This patch (re-)assigns the priority 20 to "##", and 21 to "(",
because priority 19 is already assigned to "-" as prefix "negate".
2015-01-06 17:46:18 +03:00
|
|
|
elif c == '#' and program[pos:pos + 2] == '##': # look ahead carefully
|
|
|
|
yield ('##', None, pos)
|
|
|
|
pos += 1 # skip ahead
|
2015-06-27 11:05:28 +03:00
|
|
|
elif c in "():=,-|&+!~^%": # handle simple operators
|
2010-06-05 05:57:52 +04:00
|
|
|
yield (c, None, pos)
|
2010-09-25 00:36:53 +04:00
|
|
|
elif (c in '"\'' or c == 'r' and
|
|
|
|
program[pos:pos + 2] in ("r'", 'r"')): # handle quoted strings
|
|
|
|
if c == 'r':
|
|
|
|
pos += 1
|
|
|
|
c = program[pos]
|
|
|
|
decode = lambda x: x
|
|
|
|
else:
|
2015-09-10 17:29:55 +03:00
|
|
|
decode = parser.unescapestr
|
2010-06-01 20:18:57 +04:00
|
|
|
pos += 1
|
|
|
|
s = pos
|
|
|
|
while pos < l: # find closing quote
|
|
|
|
d = program[pos]
|
|
|
|
if d == '\\': # skip over escaped characters
|
|
|
|
pos += 2
|
|
|
|
continue
|
|
|
|
if d == c:
|
2010-09-25 00:36:53 +04:00
|
|
|
yield ('string', decode(program[s:pos]), s)
|
2010-06-01 20:18:57 +04:00
|
|
|
break
|
|
|
|
pos += 1
|
|
|
|
else:
|
2010-06-18 23:31:19 +04:00
|
|
|
raise error.ParseError(_("unterminated string"), s)
|
2012-05-12 17:54:54 +04:00
|
|
|
# gather up a symbol/keyword
|
2015-01-10 17:18:11 +03:00
|
|
|
elif c in syminitletters:
|
2010-06-01 20:18:57 +04:00
|
|
|
s = pos
|
|
|
|
pos += 1
|
|
|
|
while pos < l: # find end of symbol
|
|
|
|
d = program[pos]
|
2015-01-10 17:18:11 +03:00
|
|
|
if d not in symletters:
|
2010-06-01 20:18:57 +04:00
|
|
|
break
|
|
|
|
if d == '.' and program[pos - 1] == '.': # special case for ..
|
|
|
|
pos -= 1
|
|
|
|
break
|
|
|
|
pos += 1
|
|
|
|
sym = program[s:pos]
|
|
|
|
if sym in keywords: # operator keywords
|
2010-06-05 05:57:52 +04:00
|
|
|
yield (sym, None, s)
|
2014-03-19 02:54:42 +04:00
|
|
|
elif '-' in sym:
|
|
|
|
# some jerk gave us foo-bar-baz, try to check if it's a symbol
|
|
|
|
if lookup and lookup(sym):
|
|
|
|
# looks like a real symbol
|
|
|
|
yield ('symbol', sym, s)
|
|
|
|
else:
|
|
|
|
# looks like an expression
|
|
|
|
parts = sym.split('-')
|
|
|
|
for p in parts[:-1]:
|
|
|
|
if p: # possible consecutive -
|
|
|
|
yield ('symbol', p, s)
|
|
|
|
s += len(p)
|
|
|
|
yield ('-', None, pos)
|
|
|
|
s += 1
|
|
|
|
if parts[-1]: # possible trailing -
|
|
|
|
yield ('symbol', parts[-1], s)
|
2010-06-01 20:18:57 +04:00
|
|
|
else:
|
2010-06-05 05:57:52 +04:00
|
|
|
yield ('symbol', sym, s)
|
2010-06-01 20:18:57 +04:00
|
|
|
pos -= 1
|
|
|
|
else:
|
2015-04-14 06:53:05 +03:00
|
|
|
raise error.ParseError(_("syntax error in revset '%s'") %
|
|
|
|
program, pos)
|
2010-06-01 20:18:57 +04:00
|
|
|
pos += 1
|
2010-06-05 05:57:52 +04:00
|
|
|
yield ('end', None, pos)
|
2010-06-01 20:18:57 +04:00
|
|
|
|
|
|
|
# helpers
|
|
|
|
|
2016-06-27 14:44:14 +03:00
|
|
|
def getsymbol(x):
|
|
|
|
if x and x[0] == 'symbol':
|
|
|
|
return x[1]
|
|
|
|
raise error.ParseError(_('not a symbol'))
|
|
|
|
|
2010-06-01 20:18:57 +04:00
|
|
|
def getstring(x, err):
|
2010-09-24 21:46:54 +04:00
|
|
|
if x and (x[0] == 'string' or x[0] == 'symbol'):
|
2010-06-01 20:18:57 +04:00
|
|
|
return x[1]
|
2010-06-05 05:57:52 +04:00
|
|
|
raise error.ParseError(err)
|
2010-06-01 20:18:57 +04:00
|
|
|
|
|
|
|
def getlist(x):
|
|
|
|
if not x:
|
|
|
|
return []
|
|
|
|
if x[0] == 'list':
|
2016-02-02 17:49:49 +03:00
|
|
|
return list(x[1:])
|
2010-06-01 20:18:57 +04:00
|
|
|
return [x]
|
|
|
|
|
2010-06-12 00:30:12 +04:00
|
|
|
def getargs(x, min, max, err):
|
2010-06-01 20:18:57 +04:00
|
|
|
l = getlist(x)
|
2012-02-23 21:05:20 +04:00
|
|
|
if len(l) < min or (max >= 0 and len(l) > max):
|
2010-06-05 05:57:52 +04:00
|
|
|
raise error.ParseError(err)
|
2010-06-01 20:18:57 +04:00
|
|
|
return l
|
|
|
|
|
2015-07-02 15:39:31 +03:00
|
|
|
def getargsdict(x, funcname, keys):
|
2015-06-27 11:25:01 +03:00
|
|
|
return parser.buildargsdict(getlist(x), funcname, keys.split(),
|
|
|
|
keyvaluenode='keyvalue', keynode='symbol')
|
|
|
|
|
2010-06-01 20:18:57 +04:00
|
|
|
def getset(repo, subset, x):
|
|
|
|
if not x:
|
2010-06-18 23:31:19 +04:00
|
|
|
raise error.ParseError(_("missing argument"))
|
2014-02-19 03:54:46 +04:00
|
|
|
s = methods[x[0]](repo, subset, *x[1:])
|
2014-10-11 01:22:23 +04:00
|
|
|
if util.safehasattr(s, 'isascending'):
|
2014-02-19 03:54:46 +04:00
|
|
|
return s
|
2016-05-08 11:43:41 +03:00
|
|
|
# else case should not happen, because all non-func are internal,
|
|
|
|
# ignoring for now.
|
|
|
|
if x[0] == 'func' and x[1][0] == 'symbol' and x[1][1] in symbols:
|
2016-05-11 10:34:59 +03:00
|
|
|
repo.ui.deprecwarn('revset "%s" uses list instead of smartset'
|
2016-05-11 10:31:47 +03:00
|
|
|
% x[1][1],
|
|
|
|
'3.9')
|
2014-02-19 03:54:46 +04:00
|
|
|
return baseset(s)
|
2010-06-01 20:18:57 +04:00
|
|
|
|
2012-06-06 04:35:34 +04:00
|
|
|
def _getrevsource(repo, r):
|
|
|
|
extra = repo[r].extra()
|
|
|
|
for label in ('source', 'transplant_source', 'rebase_source'):
|
|
|
|
if label in extra:
|
|
|
|
try:
|
|
|
|
return repo[extra[label]].rev()
|
|
|
|
except error.RepoLookupError:
|
|
|
|
pass
|
|
|
|
return None
|
|
|
|
|
2010-06-01 20:18:57 +04:00
|
|
|
# operator methods
|
|
|
|
|
|
|
|
def stringset(repo, subset, x):
|
|
|
|
x = repo[x].rev()
|
2015-05-24 04:29:33 +03:00
|
|
|
if (x in subset
|
|
|
|
or x == node.nullrev and isinstance(subset, fullreposet)):
|
2014-01-21 23:39:26 +04:00
|
|
|
return baseset([x])
|
2014-10-06 21:41:43 +04:00
|
|
|
return baseset()
|
2010-06-01 20:18:57 +04:00
|
|
|
|
2016-08-07 11:46:12 +03:00
|
|
|
def rangeset(repo, subset, x, y, order):
|
2014-10-17 10:10:44 +04:00
|
|
|
m = getset(repo, fullreposet(repo), x)
|
|
|
|
n = getset(repo, fullreposet(repo), y)
|
2010-06-28 20:07:27 +04:00
|
|
|
|
|
|
|
if not m or not n:
|
2014-10-06 21:41:43 +04:00
|
|
|
return baseset()
|
2016-10-01 14:11:48 +03:00
|
|
|
return _makerangeset(repo, subset, m.first(), n.last(), order)
|
2010-06-28 20:07:27 +04:00
|
|
|
|
2016-10-01 14:20:11 +03:00
|
|
|
def rangepre(repo, subset, y, order):
|
|
|
|
# ':y' can't be rewritten to '0:y' since '0' may be hidden
|
|
|
|
n = getset(repo, fullreposet(repo), y)
|
|
|
|
if not n:
|
|
|
|
return baseset()
|
|
|
|
return _makerangeset(repo, subset, 0, n.last(), order)
|
|
|
|
|
2016-10-01 14:11:48 +03:00
|
|
|
def _makerangeset(repo, subset, m, n, order):
|
2015-06-28 10:08:07 +03:00
|
|
|
if m == n:
|
|
|
|
r = baseset([m])
|
|
|
|
elif n == node.wdirrev:
|
|
|
|
r = spanset(repo, m, len(repo)) + baseset([n])
|
|
|
|
elif m == node.wdirrev:
|
|
|
|
r = baseset([m]) + spanset(repo, len(repo) - 1, n - 1)
|
|
|
|
elif m < n:
|
2014-02-03 22:15:15 +04:00
|
|
|
r = spanset(repo, m, n + 1)
|
2010-06-28 20:07:27 +04:00
|
|
|
else:
|
2014-02-03 22:15:15 +04:00
|
|
|
r = spanset(repo, m, n - 1)
|
2016-05-03 06:52:50 +03:00
|
|
|
|
|
|
|
if order == defineorder:
|
|
|
|
return r & subset
|
|
|
|
else:
|
|
|
|
# carrying the sorting over when possible would be more efficient
|
|
|
|
return subset & r
|
2010-06-01 20:18:57 +04:00
|
|
|
|
2016-08-07 11:46:12 +03:00
|
|
|
def dagrange(repo, subset, x, y, order):
|
2015-01-08 17:46:54 +03:00
|
|
|
r = fullreposet(repo)
|
2015-06-20 06:18:54 +03:00
|
|
|
xs = reachableroots(repo, getset(repo, r, x), getset(repo, r, y),
|
|
|
|
includepath=True)
|
2016-05-03 06:36:44 +03:00
|
|
|
return subset & xs
|
2012-06-02 02:50:22 +04:00
|
|
|
|
2016-08-07 11:46:12 +03:00
|
|
|
def andset(repo, subset, x, y, order):
|
2010-06-01 20:18:57 +04:00
|
|
|
return getset(repo, getset(repo, subset, x), y)
|
|
|
|
|
2016-08-07 11:46:12 +03:00
|
|
|
def differenceset(repo, subset, x, y, order):
|
2016-02-24 21:41:15 +03:00
|
|
|
return getset(repo, subset, x) - getset(repo, subset, y)
|
|
|
|
|
2016-08-07 11:04:05 +03:00
|
|
|
def _orsetlist(repo, subset, xs):
|
2015-07-05 06:50:09 +03:00
|
|
|
assert xs
|
|
|
|
if len(xs) == 1:
|
|
|
|
return getset(repo, subset, xs[0])
|
|
|
|
p = len(xs) // 2
|
2016-08-07 11:04:05 +03:00
|
|
|
a = _orsetlist(repo, subset, xs[:p])
|
|
|
|
b = _orsetlist(repo, subset, xs[p:])
|
2015-07-05 06:50:09 +03:00
|
|
|
return a + b
|
2010-06-01 20:18:57 +04:00
|
|
|
|
2016-08-07 11:46:12 +03:00
|
|
|
def orset(repo, subset, x, order):
|
2016-06-26 12:17:12 +03:00
|
|
|
xs = getlist(x)
|
|
|
|
if order == followorder:
|
|
|
|
# slow path to take the subset order
|
|
|
|
return subset & _orsetlist(repo, fullreposet(repo), xs)
|
|
|
|
else:
|
|
|
|
return _orsetlist(repo, subset, xs)
|
2016-08-07 11:04:05 +03:00
|
|
|
|
2016-08-07 11:46:12 +03:00
|
|
|
def notset(repo, subset, x, order):
|
2014-01-24 02:20:58 +04:00
|
|
|
return subset - getset(repo, subset, x)
|
2010-06-01 20:18:57 +04:00
|
|
|
|
2016-02-02 17:49:49 +03:00
|
|
|
def listset(repo, subset, *xs):
|
2015-12-23 20:54:03 +03:00
|
|
|
raise error.ParseError(_("can't use a list in this context"),
|
|
|
|
hint=_('see hg help "revsets.x or y"'))
|
2010-06-01 20:18:57 +04:00
|
|
|
|
2015-06-27 11:05:28 +03:00
|
|
|
def keyvaluepair(repo, subset, k, v):
|
|
|
|
raise error.ParseError(_("can't use a key-value pair in this context"))
|
|
|
|
|
2016-08-07 11:46:12 +03:00
|
|
|
def func(repo, subset, a, b, order):
|
2016-06-27 14:44:14 +03:00
|
|
|
f = getsymbol(a)
|
|
|
|
if f in symbols:
|
2016-08-07 11:58:50 +03:00
|
|
|
fn = symbols[f]
|
|
|
|
if getattr(fn, '_takeorder', False):
|
|
|
|
return fn(repo, subset, b, order)
|
|
|
|
return fn(repo, subset, b)
|
2015-06-20 17:59:56 +03:00
|
|
|
|
|
|
|
keep = lambda fn: getattr(fn, '__doc__', None) is not None
|
|
|
|
|
|
|
|
syms = [s for (s, fn) in symbols.items() if keep(fn)]
|
2016-06-27 14:44:14 +03:00
|
|
|
raise error.UnknownIdentifier(f, syms)
|
2010-06-01 20:18:57 +04:00
|
|
|
|
|
|
|
# functions
|
|
|
|
|
2015-12-29 17:58:30 +03:00
|
|
|
# symbols are callables like:
|
|
|
|
# fn(repo, subset, x)
|
|
|
|
# with:
|
|
|
|
# repo - current repository instance
|
|
|
|
# subset - of revisions to be examined
|
|
|
|
# x - argument in tree form
|
|
|
|
symbols = {}
|
|
|
|
|
2015-12-29 17:58:30 +03:00
|
|
|
# symbols which can't be used for a DoS attack for any given input
|
|
|
|
# (e.g. those which accept regexes as plain strings shouldn't be included)
|
|
|
|
# functions that just return a lot of changesets (like all) don't count here
|
|
|
|
safesymbols = set()
|
|
|
|
|
2016-03-08 17:04:53 +03:00
|
|
|
predicate = registrar.revsetpredicate()
|
2015-12-29 17:58:30 +03:00
|
|
|
|
2015-12-29 17:58:30 +03:00
|
|
|
@predicate('_destupdate')
|
2015-10-15 03:35:44 +03:00
|
|
|
def _destupdate(repo, subset, x):
|
|
|
|
# experimental revset for update destination
|
|
|
|
args = getargsdict(x, 'limit', 'clean check')
|
|
|
|
return subset & baseset([destutil.destupdate(repo, **args)[0]])
|
|
|
|
|
2015-12-29 17:58:30 +03:00
|
|
|
@predicate('_destmerge')
|
2015-10-15 03:47:28 +03:00
|
|
|
def _destmerge(repo, subset, x):
|
|
|
|
# experimental revset for merge destination
|
2016-02-08 21:32:29 +03:00
|
|
|
sourceset = None
|
|
|
|
if x is not None:
|
|
|
|
sourceset = getset(repo, fullreposet(repo), x)
|
|
|
|
return subset & baseset([destutil.destmerge(repo, sourceset=sourceset)])
|
2015-09-18 00:03:15 +03:00
|
|
|
|
2015-12-29 17:58:30 +03:00
|
|
|
@predicate('adds(pattern)', safe=True)
|
2011-04-08 18:47:58 +04:00
|
|
|
def adds(repo, subset, x):
|
2015-12-29 17:58:30 +03:00
|
|
|
"""Changesets that add a file matching pattern.
|
2014-01-17 18:55:11 +04:00
|
|
|
|
|
|
|
The pattern without explicit kind like ``glob:`` is expected to be
|
|
|
|
relative to the current directory and match against a file or a
|
|
|
|
directory.
|
2010-10-23 21:21:51 +04:00
|
|
|
"""
|
2011-04-08 18:47:58 +04:00
|
|
|
# i18n: "adds" is a keyword
|
|
|
|
pat = getstring(x, _("adds requires a pattern"))
|
|
|
|
return checkstatus(repo, subset, pat, 1)
|
2010-06-01 20:18:57 +04:00
|
|
|
|
2015-12-29 17:58:30 +03:00
|
|
|
@predicate('ancestor(*changeset)', safe=True)
|
2011-04-08 18:47:58 +04:00
|
|
|
def ancestor(repo, subset, x):
|
2015-12-29 17:58:30 +03:00
|
|
|
"""A greatest common ancestor of the changesets.
|
2013-01-29 00:19:21 +04:00
|
|
|
|
|
|
|
Accepts 0 or more changesets.
|
|
|
|
Will return empty list when passed no args.
|
|
|
|
Greatest common ancestor of a single changeset is that changeset.
|
2010-10-23 21:21:51 +04:00
|
|
|
"""
|
2011-04-08 18:47:58 +04:00
|
|
|
# i18n: "ancestor" is a keyword
|
2013-01-29 00:19:21 +04:00
|
|
|
l = getlist(x)
|
2015-01-08 17:46:54 +03:00
|
|
|
rl = fullreposet(repo)
|
2013-01-29 00:19:21 +04:00
|
|
|
anc = None
|
|
|
|
|
|
|
|
# (getset(repo, rl, i) for i in l) generates a list of lists
|
|
|
|
for revs in (getset(repo, rl, i) for i in l):
|
|
|
|
for r in revs:
|
|
|
|
if anc is None:
|
2014-04-08 01:17:51 +04:00
|
|
|
anc = repo[r]
|
2013-01-29 00:19:21 +04:00
|
|
|
else:
|
2014-04-08 01:17:51 +04:00
|
|
|
anc = anc.ancestor(repo[r])
|
2013-01-29 00:19:21 +04:00
|
|
|
|
2014-04-08 01:17:51 +04:00
|
|
|
if anc is not None and anc.rev() in subset:
|
|
|
|
return baseset([anc.rev()])
|
2014-10-06 21:41:43 +04:00
|
|
|
return baseset()
|
2010-06-01 20:18:57 +04:00
|
|
|
|
2012-04-11 13:25:34 +04:00
|
|
|
def _ancestors(repo, subset, x, followfirst=False):
|
2015-01-08 17:46:54 +03:00
|
|
|
heads = getset(repo, fullreposet(repo), x)
|
2014-10-15 06:08:06 +04:00
|
|
|
if not heads:
|
2014-10-06 21:41:43 +04:00
|
|
|
return baseset()
|
2014-10-15 06:08:06 +04:00
|
|
|
s = _revancestors(repo, heads, followfirst)
|
2014-10-01 00:03:54 +04:00
|
|
|
return subset & s
|
2010-06-01 20:18:57 +04:00
|
|
|
|
2015-12-29 17:58:30 +03:00
|
|
|
@predicate('ancestors(set)', safe=True)
|
2012-04-11 13:25:34 +04:00
|
|
|
def ancestors(repo, subset, x):
|
2015-12-29 17:58:30 +03:00
|
|
|
"""Changesets that are ancestors of a changeset in set.
|
2012-04-11 13:25:34 +04:00
|
|
|
"""
|
|
|
|
return _ancestors(repo, subset, x)
|
|
|
|
|
2015-12-29 17:58:30 +03:00
|
|
|
@predicate('_firstancestors', safe=True)
|
2012-04-11 13:25:34 +04:00
|
|
|
def _firstancestors(repo, subset, x):
|
|
|
|
# ``_firstancestors(set)``
|
|
|
|
# Like ``ancestors(set)`` but follows only the first parents.
|
|
|
|
return _ancestors(repo, subset, x, followfirst=True)
|
|
|
|
|
2016-08-07 11:46:12 +03:00
|
|
|
def ancestorspec(repo, subset, x, n, order):
|
2011-04-30 19:43:04 +04:00
|
|
|
"""``set~n``
|
2012-05-12 17:54:54 +04:00
|
|
|
Changesets that are the Nth ancestor (first parents only) of a changeset
|
|
|
|
in set.
|
2011-04-30 19:43:04 +04:00
|
|
|
"""
|
|
|
|
try:
|
|
|
|
n = int(n[1])
|
2011-07-12 21:35:03 +04:00
|
|
|
except (TypeError, ValueError):
|
2011-04-30 19:43:04 +04:00
|
|
|
raise error.ParseError(_("~ expects a number"))
|
|
|
|
ps = set()
|
|
|
|
cl = repo.changelog
|
2014-10-17 10:11:25 +04:00
|
|
|
for r in getset(repo, fullreposet(repo), x):
|
2011-04-30 19:43:04 +04:00
|
|
|
for i in range(n):
|
|
|
|
r = cl.parentrevs(r)[0]
|
|
|
|
ps.add(r)
|
2014-09-17 21:57:47 +04:00
|
|
|
return subset & ps
|
2011-04-30 19:43:04 +04:00
|
|
|
|
2015-12-29 17:58:30 +03:00
|
|
|
@predicate('author(string)', safe=True)
|
2011-04-08 18:47:58 +04:00
|
|
|
def author(repo, subset, x):
|
2015-12-29 17:58:30 +03:00
|
|
|
"""Alias for ``user(string)``.
|
2010-10-23 21:21:51 +04:00
|
|
|
"""
|
2011-04-08 18:47:58 +04:00
|
|
|
# i18n: "author" is a keyword
|
2011-12-25 15:35:16 +04:00
|
|
|
n = encoding.lower(getstring(x, _("author requires a string")))
|
2012-05-31 02:13:58 +04:00
|
|
|
kind, pattern, matcher = _substringmatcher(n)
|
2016-02-13 14:05:57 +03:00
|
|
|
return subset.filter(lambda x: matcher(encoding.lower(repo[x].user())),
|
|
|
|
condrepr=('<user %r>', n))
|
2010-07-30 05:07:46 +04:00
|
|
|
|
2015-12-29 17:58:30 +03:00
|
|
|
@predicate('bisect(string)', safe=True)
|
2011-09-19 00:54:11 +04:00
|
|
|
def bisect(repo, subset, x):
|
2015-12-29 17:58:30 +03:00
|
|
|
"""Changesets marked in the specified bisect status:
|
2011-09-24 03:32:50 +04:00
|
|
|
|
|
|
|
- ``good``, ``bad``, ``skip``: csets explicitly marked as good/bad/skip
|
2012-08-16 00:38:42 +04:00
|
|
|
- ``goods``, ``bads`` : csets topologically good/bad
|
2011-09-24 03:32:50 +04:00
|
|
|
- ``range`` : csets taking part in the bisection
|
|
|
|
- ``pruned`` : csets that are goods, bads or skipped
|
|
|
|
- ``untested`` : csets whose fate is yet unknown
|
|
|
|
- ``ignored`` : csets ignored due to DAG topology
|
2012-05-09 02:29:09 +04:00
|
|
|
- ``current`` : the cset currently being bisected
|
2010-10-23 21:21:51 +04:00
|
|
|
"""
|
2012-07-26 08:58:43 +04:00
|
|
|
# i18n: "bisect" is a keyword
|
2011-09-17 02:20:45 +04:00
|
|
|
status = getstring(x, _("bisect requires a string")).lower()
|
2012-04-19 08:27:35 +04:00
|
|
|
state = set(hbisect.get(repo, status))
|
2014-09-17 21:57:57 +04:00
|
|
|
return subset & state
|
2010-06-01 20:18:57 +04:00
|
|
|
|
2011-09-19 00:54:11 +04:00
|
|
|
# Backward-compatibility
|
|
|
|
# - no help entry so that we do not advertise it any more
|
2015-12-29 17:58:30 +03:00
|
|
|
@predicate('bisected', safe=True)
|
2011-09-19 00:54:11 +04:00
|
|
|
def bisected(repo, subset, x):
|
|
|
|
return bisect(repo, subset, x)
|
|
|
|
|
2015-12-29 17:58:30 +03:00
|
|
|
@predicate('bookmark([name])', safe=True)
|
2011-04-08 18:47:58 +04:00
|
|
|
def bookmark(repo, subset, x):
|
2015-12-29 17:58:30 +03:00
|
|
|
"""The named bookmark or all bookmarks.
|
2012-05-31 02:13:33 +04:00
|
|
|
|
|
|
|
If `name` starts with `re:`, the remainder of the name is treated as
|
|
|
|
a regular expression. To match a bookmark that actually starts with `re:`,
|
|
|
|
use the prefix `literal:`.
|
2010-10-23 21:21:51 +04:00
|
|
|
"""
|
2011-04-08 18:47:58 +04:00
|
|
|
# i18n: "bookmark" is a keyword
|
|
|
|
args = getargs(x, 0, 1, _('bookmark takes one or no arguments'))
|
|
|
|
if args:
|
|
|
|
bm = getstring(args[0],
|
|
|
|
# i18n: "bookmark" is a keyword
|
|
|
|
_('the argument to bookmark must be a string'))
|
2015-08-23 05:52:18 +03:00
|
|
|
kind, pattern, matcher = util.stringmatcher(bm)
|
2014-09-17 21:58:25 +04:00
|
|
|
bms = set()
|
2012-05-31 02:13:33 +04:00
|
|
|
if kind == 'literal':
|
2014-08-12 07:45:08 +04:00
|
|
|
bmrev = repo._bookmarks.get(pattern, None)
|
2012-05-31 02:13:33 +04:00
|
|
|
if not bmrev:
|
revset: raise RepoLookupError to make present() predicate continue the query
Before this patch, "bookmark()", "named()" and "tag()" predicates
raise "Abort", when the specified pattern doesn't match against
existing ones.
This prevents "present()" predicate from continuing the query, because
it only catches "RepoLookupError".
This patch raises "RepoLookupError" instead of "Abort", to make
"present()" predicate continue the query, even if "bookmark()",
"named()" or "tag()" in the sub-query of it are aborted.
This patch doesn't contain raising "RepoLookupError" for "re:" pattern
in "tag()", because "tag()" treats it differently from others. Actions
of each predicates at failure of pattern matching can be summarized as
below:
predicate "literal:" "re:"
---------- ----------- ------------
bookmark abort abort
named abort abort
tag abort continue (*1)
branch abort continue (*2)
---------- ----------- ------------
"tag()" may have to abort in the (*1) case for similarity, but this
change may break backward compatibility of existing revset queries. It
seems to have to be changed on "default" branch (with "BC" ?).
On the other hand, (*2) seems to be reasonable, even though it breaks
similarity, because "branch()" in this case doesn't check exact
existence of branches, but does pick up revisions of which branch
matches against the pattern.
This patch also adds tests for "branch()" to clarify behavior around
"present()" of similar predicates, even though this patch doesn't
change "branch()".
2015-01-30 19:00:50 +03:00
|
|
|
raise error.RepoLookupError(_("bookmark '%s' does not exist")
|
2015-10-07 17:04:31 +03:00
|
|
|
% pattern)
|
2014-09-17 21:58:25 +04:00
|
|
|
bms.add(repo[bmrev].rev())
|
2012-05-31 02:13:33 +04:00
|
|
|
else:
|
|
|
|
matchrevs = set()
|
2013-01-28 00:24:37 +04:00
|
|
|
for name, bmrev in repo._bookmarks.iteritems():
|
2012-05-31 02:13:33 +04:00
|
|
|
if matcher(name):
|
|
|
|
matchrevs.add(bmrev)
|
|
|
|
if not matchrevs:
|
revset: raise RepoLookupError to make present() predicate continue the query
Before this patch, "bookmark()", "named()" and "tag()" predicates
raise "Abort", when the specified pattern doesn't match against
existing ones.
This prevents "present()" predicate from continuing the query, because
it only catches "RepoLookupError".
This patch raises "RepoLookupError" instead of "Abort", to make
"present()" predicate continue the query, even if "bookmark()",
"named()" or "tag()" in the sub-query of it are aborted.
This patch doesn't contain raising "RepoLookupError" for "re:" pattern
in "tag()", because "tag()" treats it differently from others. Actions
of each predicates at failure of pattern matching can be summarized as
below:
predicate "literal:" "re:"
---------- ----------- ------------
bookmark abort abort
named abort abort
tag abort continue (*1)
branch abort continue (*2)
---------- ----------- ------------
"tag()" may have to abort in the (*1) case for similarity, but this
change may break backward compatibility of existing revset queries. It
seems to have to be changed on "default" branch (with "BC" ?).
On the other hand, (*2) seems to be reasonable, even though it breaks
similarity, because "branch()" in this case doesn't check exact
existence of branches, but does pick up revisions of which branch
matches against the pattern.
This patch also adds tests for "branch()" to clarify behavior around
"present()" of similar predicates, even though this patch doesn't
change "branch()".
2015-01-30 19:00:50 +03:00
|
|
|
raise error.RepoLookupError(_("no bookmarks exist"
|
|
|
|
" that match '%s'") % pattern)
|
2012-05-31 02:13:33 +04:00
|
|
|
for bmrev in matchrevs:
|
2014-09-17 21:58:25 +04:00
|
|
|
bms.add(repo[bmrev].rev())
|
|
|
|
else:
|
|
|
|
bms = set([repo[r].rev()
|
|
|
|
for r in repo._bookmarks.values()])
|
2014-09-18 06:56:59 +04:00
|
|
|
bms -= set([node.nullrev])
|
2014-09-18 06:57:09 +04:00
|
|
|
return subset & bms
|
2010-06-01 20:18:57 +04:00
|
|
|
|
2015-12-29 17:58:30 +03:00
|
|
|
@predicate('branch(string or set)', safe=True)
|
2010-06-01 20:18:57 +04:00
|
|
|
def branch(repo, subset, x):
|
2015-12-29 17:58:30 +03:00
|
|
|
"""
|
# User Dan Villiom Podlaski Christiansen <danchr@gmail.com>
# Date 1289564504 -3600
# Node ID b75264c15cc888cf38c3c7b8f619801e3c2589c7
# Parent 89b2e5d940f669e590096c6be70eee61c9172fff
revsets: overload the branch() revset to also take a branch name.
This should only change semantics in the specific case of a tag/branch
conflict where the tag wasn't done on the branch with the same
name. Previously, branch(whatever) would resolve to the branch of the
tag in that case, whereas now it will resolve to the branch of the
name. The previous behaviour, while documented, seemed very
counter-intuitive to me.
An alternate approach would be to introduce a new revset such as
branchname() or namedbranch(). While this would retain backwards
compatibility, the distinction between it and branch() would not be
readily apparent to users. The most intuitive behaviour would be to
have branch(x) require 'x' to be a branch name, and something like
branchof(x) or samebranch(x) do what branch(x) currently
does. Unfortunately, our backwards compatibility guarantees prevent us
from doing that.
Please note that while 'hg tag' guards against shadowing a branch, 'hg
branch' does not. Besides, even if it did, that wouldn't solve the
issue of conversions with such tags and branches...
2011-03-24 03:28:16 +03:00
|
|
|
All changesets belonging to the given branch or the branches of the given
|
|
|
|
changesets.
|
2012-05-31 02:13:33 +04:00
|
|
|
|
|
|
|
If `string` starts with `re:`, the remainder of the name is treated as
|
|
|
|
a regular expression. To match a branch that actually starts with `re:`,
|
|
|
|
use the prefix `literal:`.
|
2010-10-23 21:21:51 +04:00
|
|
|
"""
|
2015-02-11 06:57:51 +03:00
|
|
|
getbi = repo.revbranchcache().branchinfo
|
2015-01-08 02:01:03 +03:00
|
|
|
|
# User Dan Villiom Podlaski Christiansen <danchr@gmail.com>
# Date 1289564504 -3600
# Node ID b75264c15cc888cf38c3c7b8f619801e3c2589c7
# Parent 89b2e5d940f669e590096c6be70eee61c9172fff
revsets: overload the branch() revset to also take a branch name.
This should only change semantics in the specific case of a tag/branch
conflict where the tag wasn't done on the branch with the same
name. Previously, branch(whatever) would resolve to the branch of the
tag in that case, whereas now it will resolve to the branch of the
name. The previous behaviour, while documented, seemed very
counter-intuitive to me.
An alternate approach would be to introduce a new revset such as
branchname() or namedbranch(). While this would retain backwards
compatibility, the distinction between it and branch() would not be
readily apparent to users. The most intuitive behaviour would be to
have branch(x) require 'x' to be a branch name, and something like
branchof(x) or samebranch(x) do what branch(x) currently
does. Unfortunately, our backwards compatibility guarantees prevent us
from doing that.
Please note that while 'hg tag' guards against shadowing a branch, 'hg
branch' does not. Besides, even if it did, that wouldn't solve the
issue of conversions with such tags and branches...
2011-03-24 03:28:16 +03:00
|
|
|
try:
|
|
|
|
b = getstring(x, '')
|
|
|
|
except error.ParseError:
|
|
|
|
# not a string, but another revspec, e.g. tip()
|
|
|
|
pass
|
2012-05-31 02:13:33 +04:00
|
|
|
else:
|
2015-08-23 05:52:18 +03:00
|
|
|
kind, pattern, matcher = util.stringmatcher(b)
|
2012-05-31 02:13:33 +04:00
|
|
|
if kind == 'literal':
|
|
|
|
# note: falls through to the revspec case if no branch with
|
2015-10-07 17:00:29 +03:00
|
|
|
# this name exists and pattern kind is not specified explicitly
|
2012-05-31 02:13:33 +04:00
|
|
|
if pattern in repo.branchmap():
|
2016-02-13 14:05:57 +03:00
|
|
|
return subset.filter(lambda r: matcher(getbi(r)[0]),
|
|
|
|
condrepr=('<branch %r>', b))
|
2015-10-07 17:00:29 +03:00
|
|
|
if b.startswith('literal:'):
|
|
|
|
raise error.RepoLookupError(_("branch '%s' does not exist")
|
|
|
|
% pattern)
|
2012-05-31 02:13:33 +04:00
|
|
|
else:
|
2016-02-13 14:05:57 +03:00
|
|
|
return subset.filter(lambda r: matcher(getbi(r)[0]),
|
|
|
|
condrepr=('<branch %r>', b))
|
# User Dan Villiom Podlaski Christiansen <danchr@gmail.com>
# Date 1289564504 -3600
# Node ID b75264c15cc888cf38c3c7b8f619801e3c2589c7
# Parent 89b2e5d940f669e590096c6be70eee61c9172fff
revsets: overload the branch() revset to also take a branch name.
This should only change semantics in the specific case of a tag/branch
conflict where the tag wasn't done on the branch with the same
name. Previously, branch(whatever) would resolve to the branch of the
tag in that case, whereas now it will resolve to the branch of the
name. The previous behaviour, while documented, seemed very
counter-intuitive to me.
An alternate approach would be to introduce a new revset such as
branchname() or namedbranch(). While this would retain backwards
compatibility, the distinction between it and branch() would not be
readily apparent to users. The most intuitive behaviour would be to
have branch(x) require 'x' to be a branch name, and something like
branchof(x) or samebranch(x) do what branch(x) currently
does. Unfortunately, our backwards compatibility guarantees prevent us
from doing that.
Please note that while 'hg tag' guards against shadowing a branch, 'hg
branch' does not. Besides, even if it did, that wouldn't solve the
issue of conversions with such tags and branches...
2011-03-24 03:28:16 +03:00
|
|
|
|
2015-01-08 17:46:54 +03:00
|
|
|
s = getset(repo, fullreposet(repo), x)
|
2010-06-01 20:18:57 +04:00
|
|
|
b = set()
|
|
|
|
for r in s:
|
2015-02-11 06:57:51 +03:00
|
|
|
b.add(getbi(r)[0])
|
2014-10-08 13:47:00 +04:00
|
|
|
c = s.__contains__
|
2016-02-13 14:05:57 +03:00
|
|
|
return subset.filter(lambda r: c(r) or getbi(r)[0] in b,
|
|
|
|
condrepr=lambda: '<branch %r>' % sorted(b))
|
2010-06-01 20:18:57 +04:00
|
|
|
|
2015-12-29 17:58:30 +03:00
|
|
|
@predicate('bumped()', safe=True)
|
2012-10-19 02:39:06 +04:00
|
|
|
def bumped(repo, subset, x):
|
2015-12-29 17:58:30 +03:00
|
|
|
"""Mutable changesets marked as successors of public changesets.
|
2012-10-19 02:39:06 +04:00
|
|
|
|
|
|
|
Only non-public and non-obsolete changesets can be `bumped`.
|
|
|
|
"""
|
|
|
|
# i18n: "bumped" is a keyword
|
|
|
|
getargs(x, 0, 0, _("bumped takes no arguments"))
|
|
|
|
bumped = obsmod.getrevs(repo, 'bumped')
|
2014-01-25 04:57:44 +04:00
|
|
|
return subset & bumped
|
2012-10-19 02:39:06 +04:00
|
|
|
|
2015-12-29 17:58:30 +03:00
|
|
|
@predicate('bundle()', safe=True)
|
2012-11-01 03:23:23 +04:00
|
|
|
def bundle(repo, subset, x):
|
2015-12-29 17:58:30 +03:00
|
|
|
"""Changesets in the bundle.
|
2012-11-01 03:23:23 +04:00
|
|
|
|
|
|
|
Bundle must be specified by the -R option."""
|
|
|
|
|
|
|
|
try:
|
2013-01-16 23:41:34 +04:00
|
|
|
bundlerevs = repo.changelog.bundlerevs
|
2012-11-01 03:23:23 +04:00
|
|
|
except AttributeError:
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort(_("no bundle provided - specify with -R"))
|
2014-01-25 04:57:44 +04:00
|
|
|
return subset & bundlerevs
|
2012-11-01 03:23:23 +04:00
|
|
|
|
2011-04-08 18:47:58 +04:00
|
|
|
def checkstatus(repo, subset, pat, field):
|
2012-04-26 16:24:46 +04:00
|
|
|
hasset = matchmod.patkind(pat) == 'set'
|
2014-01-31 22:47:51 +04:00
|
|
|
|
2014-10-31 20:41:36 +03:00
|
|
|
mcache = [None]
|
2014-01-31 22:47:51 +04:00
|
|
|
def matches(x):
|
|
|
|
c = repo[x]
|
2014-10-31 20:41:36 +03:00
|
|
|
if not mcache[0] or hasset:
|
|
|
|
mcache[0] = matchmod.match(repo.root, repo.getcwd(), [pat], ctx=c)
|
|
|
|
m = mcache[0]
|
|
|
|
fname = None
|
|
|
|
if not m.anypats() and len(m.files()) == 1:
|
|
|
|
fname = m.files()[0]
|
2012-04-26 16:24:46 +04:00
|
|
|
if fname is not None:
|
|
|
|
if fname not in c.files():
|
2014-01-31 22:47:51 +04:00
|
|
|
return False
|
2011-04-08 18:47:58 +04:00
|
|
|
else:
|
|
|
|
for f in c.files():
|
|
|
|
if m(f):
|
|
|
|
break
|
|
|
|
else:
|
2014-01-31 22:47:51 +04:00
|
|
|
return False
|
2011-04-08 18:47:58 +04:00
|
|
|
files = repo.status(c.p1().node(), c.node())[field]
|
2012-04-26 16:24:46 +04:00
|
|
|
if fname is not None:
|
|
|
|
if fname in files:
|
2014-01-31 22:47:51 +04:00
|
|
|
return True
|
2011-04-08 18:47:58 +04:00
|
|
|
else:
|
|
|
|
for f in files:
|
|
|
|
if m(f):
|
2014-01-31 22:47:51 +04:00
|
|
|
return True
|
|
|
|
|
2016-02-13 14:05:57 +03:00
|
|
|
return subset.filter(matches, condrepr=('<status[%r] %r>', field, pat))
|
2011-04-08 18:47:58 +04:00
|
|
|
|
2016-06-23 22:39:05 +03:00
|
|
|
def _children(repo, subset, parentset):
|
2012-12-07 22:37:43 +04:00
|
|
|
if not parentset:
|
2015-06-12 00:27:52 +03:00
|
|
|
return baseset()
|
|
|
|
cs = set()
|
2012-01-16 11:21:30 +04:00
|
|
|
pr = repo.changelog.parentrevs
|
2015-06-12 05:02:24 +03:00
|
|
|
minrev = parentset.min()
|
2016-06-23 22:39:05 +03:00
|
|
|
for r in subset:
|
2014-03-13 23:34:32 +04:00
|
|
|
if r <= minrev:
|
|
|
|
continue
|
|
|
|
for p in pr(r):
|
2012-04-08 13:14:56 +04:00
|
|
|
if p in parentset:
|
2014-03-13 23:34:32 +04:00
|
|
|
cs.add(r)
|
|
|
|
return baseset(cs)
|
2012-01-16 11:21:30 +04:00
|
|
|
|
2015-12-29 17:58:30 +03:00
|
|
|
@predicate('children(set)', safe=True)
|
2011-04-08 18:47:58 +04:00
|
|
|
def children(repo, subset, x):
|
2015-12-29 17:58:30 +03:00
|
|
|
"""Child changesets of changesets in set.
|
2010-10-23 21:21:51 +04:00
|
|
|
"""
|
2014-10-17 10:14:17 +04:00
|
|
|
s = getset(repo, fullreposet(repo), x)
|
2012-01-16 11:21:30 +04:00
|
|
|
cs = _children(repo, subset, s)
|
2014-01-25 04:57:44 +04:00
|
|
|
return subset & cs
|
2010-07-22 17:17:38 +04:00
|
|
|
|
2015-12-29 17:58:30 +03:00
|
|
|
@predicate('closed()', safe=True)
|
2011-04-08 18:47:58 +04:00
|
|
|
def closed(repo, subset, x):
|
2015-12-29 17:58:30 +03:00
|
|
|
"""Changeset is closed.
|
2011-04-08 18:47:58 +04:00
|
|
|
"""
|
|
|
|
# i18n: "closed" is a keyword
|
|
|
|
getargs(x, 0, 0, _("closed takes no arguments"))
|
2016-02-13 14:05:57 +03:00
|
|
|
return subset.filter(lambda r: repo[r].closesbranch(),
|
|
|
|
condrepr='<branch closed>')
|
2010-06-01 20:18:57 +04:00
|
|
|
|
2015-12-29 17:58:30 +03:00
|
|
|
@predicate('contains(pattern)')
|
2011-04-08 18:47:58 +04:00
|
|
|
def contains(repo, subset, x):
|
2015-12-29 17:58:30 +03:00
|
|
|
"""The revision's manifest contains a file matching pattern (but might not
|
2014-04-29 02:09:23 +04:00
|
|
|
modify it). See :hg:`help patterns` for information about file patterns.
|
2014-01-17 18:55:11 +04:00
|
|
|
|
|
|
|
The pattern without explicit kind like ``glob:`` is expected to be
|
|
|
|
relative to the current directory and match against a file exactly
|
|
|
|
for efficiency.
|
2010-10-23 21:21:51 +04:00
|
|
|
"""
|
2011-04-08 18:47:58 +04:00
|
|
|
# i18n: "contains" is a keyword
|
|
|
|
pat = getstring(x, _("contains requires a pattern"))
|
2014-02-05 03:07:03 +04:00
|
|
|
|
|
|
|
def matches(x):
|
|
|
|
if not matchmod.patkind(pat):
|
|
|
|
pats = pathutil.canonpath(repo.root, repo.getcwd(), pat)
|
|
|
|
if pats in repo[x]:
|
|
|
|
return True
|
|
|
|
else:
|
|
|
|
c = repo[x]
|
|
|
|
m = matchmod.match(repo.root, repo.getcwd(), [pat], ctx=c)
|
2012-01-21 09:05:04 +04:00
|
|
|
for f in c.manifest():
|
2011-04-08 18:47:58 +04:00
|
|
|
if m(f):
|
2014-02-05 03:07:03 +04:00
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
2016-02-13 14:05:57 +03:00
|
|
|
return subset.filter(matches, condrepr=('<contains %r>', pat))
|
2011-04-08 18:47:58 +04:00
|
|
|
|
2015-12-29 17:58:30 +03:00
|
|
|
@predicate('converted([id])', safe=True)
|
2012-05-13 09:12:26 +04:00
|
|
|
def converted(repo, subset, x):
|
2015-12-29 17:58:30 +03:00
|
|
|
"""Changesets converted from the given identifier in the old repository if
|
2012-05-13 09:12:26 +04:00
|
|
|
present, or all converted changesets if no identifier is specified.
|
|
|
|
"""
|
|
|
|
|
|
|
|
# There is exactly no chance of resolving the revision, so do a simple
|
|
|
|
# string compare and hope for the best
|
|
|
|
|
|
|
|
rev = None
|
2012-07-26 08:58:43 +04:00
|
|
|
# i18n: "converted" is a keyword
|
2012-05-13 09:12:26 +04:00
|
|
|
l = getargs(x, 0, 1, _('converted takes one or no arguments'))
|
|
|
|
if l:
|
2012-07-26 08:58:43 +04:00
|
|
|
# i18n: "converted" is a keyword
|
2012-05-13 09:12:26 +04:00
|
|
|
rev = getstring(l[0], _('converted requires a revision'))
|
|
|
|
|
|
|
|
def _matchvalue(r):
|
|
|
|
source = repo[r].extra().get('convert_revision', None)
|
|
|
|
return source is not None and (rev is None or source.startswith(rev))
|
|
|
|
|
2016-02-13 14:05:57 +03:00
|
|
|
return subset.filter(lambda r: _matchvalue(r),
|
|
|
|
condrepr=('<converted %r>', rev))
|
2012-05-13 09:12:26 +04:00
|
|
|
|
2015-12-29 17:58:30 +03:00
|
|
|
@predicate('date(interval)', safe=True)
|
2011-04-08 18:47:58 +04:00
|
|
|
def date(repo, subset, x):
|
2015-12-29 17:58:30 +03:00
|
|
|
"""Changesets within the interval, see :hg:`help dates`.
|
2011-04-08 18:47:58 +04:00
|
|
|
"""
|
|
|
|
# i18n: "date" is a keyword
|
|
|
|
ds = getstring(x, _("date requires a string"))
|
|
|
|
dm = util.matchdate(ds)
|
2016-02-13 14:05:57 +03:00
|
|
|
return subset.filter(lambda x: dm(repo[x].date()[0]),
|
|
|
|
condrepr=('<date %r>', ds))
|
2010-06-01 20:18:57 +04:00
|
|
|
|
2015-12-29 17:58:30 +03:00
|
|
|
@predicate('desc(string)', safe=True)
|
2011-06-17 00:47:34 +04:00
|
|
|
def desc(repo, subset, x):
|
2015-12-29 17:58:30 +03:00
|
|
|
"""Search commit message for string. The match is case-insensitive.
|
2011-06-17 00:47:34 +04:00
|
|
|
"""
|
|
|
|
# i18n: "desc" is a keyword
|
2011-12-25 15:35:16 +04:00
|
|
|
ds = encoding.lower(getstring(x, _("desc requires a string")))
|
2014-01-31 03:39:56 +04:00
|
|
|
|
|
|
|
def matches(x):
|
|
|
|
c = repo[x]
|
|
|
|
return ds in encoding.lower(c.description())
|
|
|
|
|
2016-02-13 14:05:57 +03:00
|
|
|
return subset.filter(matches, condrepr=('<desc %r>', ds))
|
2011-06-17 00:47:34 +04:00
|
|
|
|
2012-04-11 13:25:34 +04:00
|
|
|
def _descendants(repo, subset, x, followfirst=False):
|
2015-01-08 17:46:54 +03:00
|
|
|
roots = getset(repo, fullreposet(repo), x)
|
2014-10-15 06:08:06 +04:00
|
|
|
if not roots:
|
2014-10-06 21:41:43 +04:00
|
|
|
return baseset()
|
2014-10-15 06:08:06 +04:00
|
|
|
s = _revdescendants(repo, roots, followfirst)
|
2014-03-26 01:10:01 +04:00
|
|
|
|
|
|
|
# Both sets need to be ascending in order to lazily return the union
|
|
|
|
# in the correct order.
|
2014-10-15 06:08:06 +04:00
|
|
|
base = subset & roots
|
2014-10-09 20:12:54 +04:00
|
|
|
desc = subset & s
|
|
|
|
result = base + desc
|
|
|
|
if subset.isascending():
|
|
|
|
result.sort()
|
|
|
|
elif subset.isdescending():
|
|
|
|
result.sort(reverse=True)
|
|
|
|
else:
|
|
|
|
result = subset & result
|
2014-10-07 12:36:53 +04:00
|
|
|
return result
|
2010-06-01 20:18:57 +04:00
|
|
|
|
2015-12-29 17:58:30 +03:00
|
|
|
@predicate('descendants(set)', safe=True)
|
2012-04-11 13:25:34 +04:00
|
|
|
def descendants(repo, subset, x):
|
2015-12-29 17:58:30 +03:00
|
|
|
"""Changesets which are descendants of changesets in set.
|
2012-04-11 13:25:34 +04:00
|
|
|
"""
|
|
|
|
return _descendants(repo, subset, x)
|
|
|
|
|
2015-12-29 17:58:30 +03:00
|
|
|
@predicate('_firstdescendants', safe=True)
|
2012-04-11 13:25:34 +04:00
|
|
|
def _firstdescendants(repo, subset, x):
|
|
|
|
# ``_firstdescendants(set)``
|
|
|
|
# Like ``descendants(set)`` but follows only the first parents.
|
|
|
|
return _descendants(repo, subset, x, followfirst=True)
|
|
|
|
|
2015-12-29 17:58:30 +03:00
|
|
|
@predicate('destination([set])', safe=True)
|
revset: add destination() predicate
This predicate is used to find csets that were created because of a graft,
transplant or rebase --keep. An optional revset can be supplied, in which case
the result will be limited to those copies which specified one of the revs as
the source for the command.
hg log -r destination() # csets copied from anywhere
hg log -r destination(branch(default)) # all csets copied from default
hg log -r origin(x) or destination(origin(x)) # all instances of x
This predicate will follow a cset through different types of copies. Given a
repo with a cset 'S' that is grafted to create G(S), which itself is
transplanted to become T(G(S)):
o-S
/
o-o-G(S)
\
o-T(G(S))
hg log -r destination( S ) # { G(S), T(G(S)) }
hg log -r destination( G(S) ) # { T(G(S)) }
The implementation differences between the three different copy commands (see
the origin() predicate) are not intentionally exposed, however if the
transplant was a graft instead:
hg log -r destination( G(S) ) # {}
because the 'extra' field in G(G(S)) is S, not G(S). The implementation cannot
correct this by following sources before G(S) and then select the csets that
reference those sources because the cset provided to the predicate would also
end up selected. If there were more than two copies, sources of the argument
would also get selected.
Note that the convert extension does not currently update the 'extra' map in its
destination csets, and therefore copies made prior to the convert will be
missing from the resulting set.
Instead of the loop over 'subset', the following almost works, but does not
select a transplant of a transplant. That is, 'destination(S)' will only
select T(S).
dests = set([r for r in subset if _getrevsource(repo, r) in args])
2012-07-07 08:47:55 +04:00
|
|
|
def destination(repo, subset, x):
|
2015-12-29 17:58:30 +03:00
|
|
|
"""Changesets that were created by a graft, transplant or rebase operation,
|
revset: add destination() predicate
This predicate is used to find csets that were created because of a graft,
transplant or rebase --keep. An optional revset can be supplied, in which case
the result will be limited to those copies which specified one of the revs as
the source for the command.
hg log -r destination() # csets copied from anywhere
hg log -r destination(branch(default)) # all csets copied from default
hg log -r origin(x) or destination(origin(x)) # all instances of x
This predicate will follow a cset through different types of copies. Given a
repo with a cset 'S' that is grafted to create G(S), which itself is
transplanted to become T(G(S)):
o-S
/
o-o-G(S)
\
o-T(G(S))
hg log -r destination( S ) # { G(S), T(G(S)) }
hg log -r destination( G(S) ) # { T(G(S)) }
The implementation differences between the three different copy commands (see
the origin() predicate) are not intentionally exposed, however if the
transplant was a graft instead:
hg log -r destination( G(S) ) # {}
because the 'extra' field in G(G(S)) is S, not G(S). The implementation cannot
correct this by following sources before G(S) and then select the csets that
reference those sources because the cset provided to the predicate would also
end up selected. If there were more than two copies, sources of the argument
would also get selected.
Note that the convert extension does not currently update the 'extra' map in its
destination csets, and therefore copies made prior to the convert will be
missing from the resulting set.
Instead of the loop over 'subset', the following almost works, but does not
select a transplant of a transplant. That is, 'destination(S)' will only
select T(S).
dests = set([r for r in subset if _getrevsource(repo, r) in args])
2012-07-07 08:47:55 +04:00
|
|
|
with the given revisions specified as the source. Omitting the optional set
|
|
|
|
is the same as passing all().
|
|
|
|
"""
|
|
|
|
if x is not None:
|
2015-01-08 17:46:54 +03:00
|
|
|
sources = getset(repo, fullreposet(repo), x)
|
revset: add destination() predicate
This predicate is used to find csets that were created because of a graft,
transplant or rebase --keep. An optional revset can be supplied, in which case
the result will be limited to those copies which specified one of the revs as
the source for the command.
hg log -r destination() # csets copied from anywhere
hg log -r destination(branch(default)) # all csets copied from default
hg log -r origin(x) or destination(origin(x)) # all instances of x
This predicate will follow a cset through different types of copies. Given a
repo with a cset 'S' that is grafted to create G(S), which itself is
transplanted to become T(G(S)):
o-S
/
o-o-G(S)
\
o-T(G(S))
hg log -r destination( S ) # { G(S), T(G(S)) }
hg log -r destination( G(S) ) # { T(G(S)) }
The implementation differences between the three different copy commands (see
the origin() predicate) are not intentionally exposed, however if the
transplant was a graft instead:
hg log -r destination( G(S) ) # {}
because the 'extra' field in G(G(S)) is S, not G(S). The implementation cannot
correct this by following sources before G(S) and then select the csets that
reference those sources because the cset provided to the predicate would also
end up selected. If there were more than two copies, sources of the argument
would also get selected.
Note that the convert extension does not currently update the 'extra' map in its
destination csets, and therefore copies made prior to the convert will be
missing from the resulting set.
Instead of the loop over 'subset', the following almost works, but does not
select a transplant of a transplant. That is, 'destination(S)' will only
select T(S).
dests = set([r for r in subset if _getrevsource(repo, r) in args])
2012-07-07 08:47:55 +04:00
|
|
|
else:
|
2015-01-10 10:41:36 +03:00
|
|
|
sources = fullreposet(repo)
|
revset: add destination() predicate
This predicate is used to find csets that were created because of a graft,
transplant or rebase --keep. An optional revset can be supplied, in which case
the result will be limited to those copies which specified one of the revs as
the source for the command.
hg log -r destination() # csets copied from anywhere
hg log -r destination(branch(default)) # all csets copied from default
hg log -r origin(x) or destination(origin(x)) # all instances of x
This predicate will follow a cset through different types of copies. Given a
repo with a cset 'S' that is grafted to create G(S), which itself is
transplanted to become T(G(S)):
o-S
/
o-o-G(S)
\
o-T(G(S))
hg log -r destination( S ) # { G(S), T(G(S)) }
hg log -r destination( G(S) ) # { T(G(S)) }
The implementation differences between the three different copy commands (see
the origin() predicate) are not intentionally exposed, however if the
transplant was a graft instead:
hg log -r destination( G(S) ) # {}
because the 'extra' field in G(G(S)) is S, not G(S). The implementation cannot
correct this by following sources before G(S) and then select the csets that
reference those sources because the cset provided to the predicate would also
end up selected. If there were more than two copies, sources of the argument
would also get selected.
Note that the convert extension does not currently update the 'extra' map in its
destination csets, and therefore copies made prior to the convert will be
missing from the resulting set.
Instead of the loop over 'subset', the following almost works, but does not
select a transplant of a transplant. That is, 'destination(S)' will only
select T(S).
dests = set([r for r in subset if _getrevsource(repo, r) in args])
2012-07-07 08:47:55 +04:00
|
|
|
|
|
|
|
dests = set()
|
|
|
|
|
|
|
|
# subset contains all of the possible destinations that can be returned, so
|
2014-10-15 06:08:06 +04:00
|
|
|
# iterate over them and see if their source(s) were provided in the arg set.
|
|
|
|
# Even if the immediate src of r is not in the arg set, src's source (or
|
revset: add destination() predicate
This predicate is used to find csets that were created because of a graft,
transplant or rebase --keep. An optional revset can be supplied, in which case
the result will be limited to those copies which specified one of the revs as
the source for the command.
hg log -r destination() # csets copied from anywhere
hg log -r destination(branch(default)) # all csets copied from default
hg log -r origin(x) or destination(origin(x)) # all instances of x
This predicate will follow a cset through different types of copies. Given a
repo with a cset 'S' that is grafted to create G(S), which itself is
transplanted to become T(G(S)):
o-S
/
o-o-G(S)
\
o-T(G(S))
hg log -r destination( S ) # { G(S), T(G(S)) }
hg log -r destination( G(S) ) # { T(G(S)) }
The implementation differences between the three different copy commands (see
the origin() predicate) are not intentionally exposed, however if the
transplant was a graft instead:
hg log -r destination( G(S) ) # {}
because the 'extra' field in G(G(S)) is S, not G(S). The implementation cannot
correct this by following sources before G(S) and then select the csets that
reference those sources because the cset provided to the predicate would also
end up selected. If there were more than two copies, sources of the argument
would also get selected.
Note that the convert extension does not currently update the 'extra' map in its
destination csets, and therefore copies made prior to the convert will be
missing from the resulting set.
Instead of the loop over 'subset', the following almost works, but does not
select a transplant of a transplant. That is, 'destination(S)' will only
select T(S).
dests = set([r for r in subset if _getrevsource(repo, r) in args])
2012-07-07 08:47:55 +04:00
|
|
|
# further back) may be. Scanning back further than the immediate src allows
|
|
|
|
# transitive transplants and rebases to yield the same results as transitive
|
|
|
|
# grafts.
|
|
|
|
for r in subset:
|
|
|
|
src = _getrevsource(repo, r)
|
|
|
|
lineage = None
|
|
|
|
|
|
|
|
while src is not None:
|
|
|
|
if lineage is None:
|
|
|
|
lineage = list()
|
|
|
|
|
|
|
|
lineage.append(r)
|
|
|
|
|
|
|
|
# The visited lineage is a match if the current source is in the arg
|
|
|
|
# set. Since every candidate dest is visited by way of iterating
|
2012-08-16 00:38:42 +04:00
|
|
|
# subset, any dests further back in the lineage will be tested by a
|
revset: add destination() predicate
This predicate is used to find csets that were created because of a graft,
transplant or rebase --keep. An optional revset can be supplied, in which case
the result will be limited to those copies which specified one of the revs as
the source for the command.
hg log -r destination() # csets copied from anywhere
hg log -r destination(branch(default)) # all csets copied from default
hg log -r origin(x) or destination(origin(x)) # all instances of x
This predicate will follow a cset through different types of copies. Given a
repo with a cset 'S' that is grafted to create G(S), which itself is
transplanted to become T(G(S)):
o-S
/
o-o-G(S)
\
o-T(G(S))
hg log -r destination( S ) # { G(S), T(G(S)) }
hg log -r destination( G(S) ) # { T(G(S)) }
The implementation differences between the three different copy commands (see
the origin() predicate) are not intentionally exposed, however if the
transplant was a graft instead:
hg log -r destination( G(S) ) # {}
because the 'extra' field in G(G(S)) is S, not G(S). The implementation cannot
correct this by following sources before G(S) and then select the csets that
reference those sources because the cset provided to the predicate would also
end up selected. If there were more than two copies, sources of the argument
would also get selected.
Note that the convert extension does not currently update the 'extra' map in its
destination csets, and therefore copies made prior to the convert will be
missing from the resulting set.
Instead of the loop over 'subset', the following almost works, but does not
select a transplant of a transplant. That is, 'destination(S)' will only
select T(S).
dests = set([r for r in subset if _getrevsource(repo, r) in args])
2012-07-07 08:47:55 +04:00
|
|
|
# different iteration over subset. Likewise, if the src was already
|
|
|
|
# selected, the current lineage can be selected without going back
|
|
|
|
# further.
|
2014-10-15 06:08:06 +04:00
|
|
|
if src in sources or src in dests:
|
revset: add destination() predicate
This predicate is used to find csets that were created because of a graft,
transplant or rebase --keep. An optional revset can be supplied, in which case
the result will be limited to those copies which specified one of the revs as
the source for the command.
hg log -r destination() # csets copied from anywhere
hg log -r destination(branch(default)) # all csets copied from default
hg log -r origin(x) or destination(origin(x)) # all instances of x
This predicate will follow a cset through different types of copies. Given a
repo with a cset 'S' that is grafted to create G(S), which itself is
transplanted to become T(G(S)):
o-S
/
o-o-G(S)
\
o-T(G(S))
hg log -r destination( S ) # { G(S), T(G(S)) }
hg log -r destination( G(S) ) # { T(G(S)) }
The implementation differences between the three different copy commands (see
the origin() predicate) are not intentionally exposed, however if the
transplant was a graft instead:
hg log -r destination( G(S) ) # {}
because the 'extra' field in G(G(S)) is S, not G(S). The implementation cannot
correct this by following sources before G(S) and then select the csets that
reference those sources because the cset provided to the predicate would also
end up selected. If there were more than two copies, sources of the argument
would also get selected.
Note that the convert extension does not currently update the 'extra' map in its
destination csets, and therefore copies made prior to the convert will be
missing from the resulting set.
Instead of the loop over 'subset', the following almost works, but does not
select a transplant of a transplant. That is, 'destination(S)' will only
select T(S).
dests = set([r for r in subset if _getrevsource(repo, r) in args])
2012-07-07 08:47:55 +04:00
|
|
|
dests.update(lineage)
|
|
|
|
break
|
|
|
|
|
|
|
|
r = src
|
|
|
|
src = _getrevsource(repo, r)
|
|
|
|
|
2016-02-13 14:05:57 +03:00
|
|
|
return subset.filter(dests.__contains__,
|
|
|
|
condrepr=lambda: '<destination %r>' % sorted(dests))
|
revset: add destination() predicate
This predicate is used to find csets that were created because of a graft,
transplant or rebase --keep. An optional revset can be supplied, in which case
the result will be limited to those copies which specified one of the revs as
the source for the command.
hg log -r destination() # csets copied from anywhere
hg log -r destination(branch(default)) # all csets copied from default
hg log -r origin(x) or destination(origin(x)) # all instances of x
This predicate will follow a cset through different types of copies. Given a
repo with a cset 'S' that is grafted to create G(S), which itself is
transplanted to become T(G(S)):
o-S
/
o-o-G(S)
\
o-T(G(S))
hg log -r destination( S ) # { G(S), T(G(S)) }
hg log -r destination( G(S) ) # { T(G(S)) }
The implementation differences between the three different copy commands (see
the origin() predicate) are not intentionally exposed, however if the
transplant was a graft instead:
hg log -r destination( G(S) ) # {}
because the 'extra' field in G(G(S)) is S, not G(S). The implementation cannot
correct this by following sources before G(S) and then select the csets that
reference those sources because the cset provided to the predicate would also
end up selected. If there were more than two copies, sources of the argument
would also get selected.
Note that the convert extension does not currently update the 'extra' map in its
destination csets, and therefore copies made prior to the convert will be
missing from the resulting set.
Instead of the loop over 'subset', the following almost works, but does not
select a transplant of a transplant. That is, 'destination(S)' will only
select T(S).
dests = set([r for r in subset if _getrevsource(repo, r) in args])
2012-07-07 08:47:55 +04:00
|
|
|
|
2015-12-29 17:58:30 +03:00
|
|
|
@predicate('divergent()', safe=True)
|
2012-12-12 06:12:55 +04:00
|
|
|
def divergent(repo, subset, x):
|
2015-12-29 17:58:30 +03:00
|
|
|
"""
|
2012-12-12 06:12:55 +04:00
|
|
|
Final successors of changesets with an alternative set of final successors.
|
|
|
|
"""
|
|
|
|
# i18n: "divergent" is a keyword
|
|
|
|
getargs(x, 0, 0, _("divergent takes no arguments"))
|
|
|
|
divergent = obsmod.getrevs(repo, 'divergent')
|
2014-09-17 21:58:39 +04:00
|
|
|
return subset & divergent
|
2012-12-12 06:12:55 +04:00
|
|
|
|
2015-12-29 17:58:30 +03:00
|
|
|
@predicate('extinct()', safe=True)
|
2012-07-06 21:34:09 +04:00
|
|
|
def extinct(repo, subset, x):
|
2015-12-29 17:58:30 +03:00
|
|
|
"""Obsolete changesets with obsolete descendants only.
|
2012-07-30 17:48:04 +04:00
|
|
|
"""
|
2012-07-26 08:58:43 +04:00
|
|
|
# i18n: "extinct" is a keyword
|
2012-07-26 08:58:43 +04:00
|
|
|
getargs(x, 0, 0, _("extinct takes no arguments"))
|
2012-10-19 02:28:13 +04:00
|
|
|
extincts = obsmod.getrevs(repo, 'extinct')
|
2014-01-25 04:57:44 +04:00
|
|
|
return subset & extincts
|
2012-07-06 21:34:09 +04:00
|
|
|
|
2015-12-29 17:58:30 +03:00
|
|
|
@predicate('extra(label, [value])', safe=True)
|
2012-05-12 12:20:57 +04:00
|
|
|
def extra(repo, subset, x):
|
2015-12-29 17:58:30 +03:00
|
|
|
"""Changesets with the given label in the extra metadata, with the given
|
2012-05-31 02:14:04 +04:00
|
|
|
optional value.
|
|
|
|
|
|
|
|
If `value` starts with `re:`, the remainder of the value is treated as
|
|
|
|
a regular expression. To match a value that actually starts with `re:`,
|
|
|
|
use the prefix `literal:`.
|
|
|
|
"""
|
2015-07-02 15:39:31 +03:00
|
|
|
args = getargsdict(x, 'extra', 'label value')
|
2015-06-28 16:57:33 +03:00
|
|
|
if 'label' not in args:
|
|
|
|
# i18n: "extra" is a keyword
|
|
|
|
raise error.ParseError(_('extra takes at least 1 argument'))
|
2012-07-26 08:58:43 +04:00
|
|
|
# i18n: "extra" is a keyword
|
2015-06-28 16:57:33 +03:00
|
|
|
label = getstring(args['label'], _('first argument to extra must be '
|
|
|
|
'a string'))
|
2012-05-12 12:20:57 +04:00
|
|
|
value = None
|
|
|
|
|
2015-06-28 16:57:33 +03:00
|
|
|
if 'value' in args:
|
2012-07-26 08:58:43 +04:00
|
|
|
# i18n: "extra" is a keyword
|
2015-06-28 16:57:33 +03:00
|
|
|
value = getstring(args['value'], _('second argument to extra must be '
|
|
|
|
'a string'))
|
2015-08-23 05:52:18 +03:00
|
|
|
kind, value, matcher = util.stringmatcher(value)
|
2012-05-12 12:20:57 +04:00
|
|
|
|
|
|
|
def _matchvalue(r):
|
|
|
|
extra = repo[r].extra()
|
2012-05-31 02:14:04 +04:00
|
|
|
return label in extra and (value is None or matcher(extra[label]))
|
2012-05-12 12:20:57 +04:00
|
|
|
|
2016-02-13 14:05:57 +03:00
|
|
|
return subset.filter(lambda r: _matchvalue(r),
|
|
|
|
condrepr=('<extra[%r] %r>', label, value))
|
2012-05-12 12:20:57 +04:00
|
|
|
|
2015-12-29 17:58:30 +03:00
|
|
|
@predicate('filelog(pattern)', safe=True)
|
2011-05-17 02:02:35 +04:00
|
|
|
def filelog(repo, subset, x):
|
2015-12-29 17:58:30 +03:00
|
|
|
"""Changesets connected to the specified filelog.
|
2012-07-25 11:15:28 +04:00
|
|
|
|
2014-04-29 02:09:23 +04:00
|
|
|
For performance reasons, visits only revisions mentioned in the file-level
|
|
|
|
filelog, rather than filtering through all changesets (much faster, but
|
|
|
|
doesn't include deletes or duplicate changes). For a slower, more accurate
|
|
|
|
result, use ``file()``.
|
2014-01-17 18:55:11 +04:00
|
|
|
|
|
|
|
The pattern without explicit kind like ``glob:`` is expected to be
|
|
|
|
relative to the current directory and match against a file exactly
|
|
|
|
for efficiency.
|
2014-12-30 04:23:16 +03:00
|
|
|
|
|
|
|
If some linkrev points to revisions filtered by the current repoview, we'll
|
|
|
|
work around it to return a non-filtered value.
|
2011-05-17 02:02:35 +04:00
|
|
|
"""
|
|
|
|
|
2012-07-26 08:58:43 +04:00
|
|
|
# i18n: "filelog" is a keyword
|
2011-05-17 02:02:35 +04:00
|
|
|
pat = getstring(x, _("filelog requires a pattern"))
|
|
|
|
s = set()
|
2014-12-30 04:23:16 +03:00
|
|
|
cl = repo.changelog
|
2011-05-17 02:02:35 +04:00
|
|
|
|
2012-01-21 09:05:04 +04:00
|
|
|
if not matchmod.patkind(pat):
|
2014-01-17 18:55:03 +04:00
|
|
|
f = pathutil.canonpath(repo.root, repo.getcwd(), pat)
|
2014-12-30 04:23:16 +03:00
|
|
|
files = [f]
|
2011-05-17 02:02:35 +04:00
|
|
|
else:
|
2014-01-17 18:55:03 +04:00
|
|
|
m = matchmod.match(repo.root, repo.getcwd(), [pat], ctx=repo[None])
|
2014-12-30 04:23:16 +03:00
|
|
|
files = (f for f in repo[None] if m(f))
|
|
|
|
|
|
|
|
for f in files:
|
|
|
|
fl = repo.file(f)
|
2016-01-22 21:08:20 +03:00
|
|
|
known = {}
|
|
|
|
scanpos = 0
|
2014-12-30 04:23:16 +03:00
|
|
|
for fr in list(fl):
|
2016-01-22 21:08:20 +03:00
|
|
|
fn = fl.node(fr)
|
|
|
|
if fn in known:
|
|
|
|
s.add(known[fn])
|
2015-01-12 20:49:25 +03:00
|
|
|
continue
|
2014-12-30 04:23:16 +03:00
|
|
|
|
2016-01-22 21:08:20 +03:00
|
|
|
lr = fl.linkrev(fr)
|
|
|
|
if lr in cl:
|
|
|
|
s.add(lr)
|
|
|
|
elif scanpos is not None:
|
|
|
|
# lowest matching changeset is filtered, scan further
|
|
|
|
# ahead in changelog
|
|
|
|
start = max(lr, scanpos) + 1
|
|
|
|
scanpos = None
|
|
|
|
for r in cl.revs(start):
|
|
|
|
# minimize parsing of non-matching entries
|
|
|
|
if f in cl.revision(r) and f in cl.readfiles(r):
|
|
|
|
try:
|
|
|
|
# try to use manifest delta fastpath
|
|
|
|
n = repo[r].filenode(f)
|
|
|
|
if n not in known:
|
|
|
|
if n == fn:
|
|
|
|
s.add(r)
|
|
|
|
scanpos = r
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
known[n] = r
|
|
|
|
except error.ManifestLookupError:
|
|
|
|
# deletion in changelog
|
|
|
|
continue
|
2011-05-17 02:02:35 +04:00
|
|
|
|
2014-09-17 21:58:50 +04:00
|
|
|
return subset & s
|
2011-05-17 02:02:35 +04:00
|
|
|
|
2015-12-29 17:58:30 +03:00
|
|
|
@predicate('first(set, [n])', safe=True)
|
2011-09-17 21:34:47 +04:00
|
|
|
def first(repo, subset, x):
|
2015-12-29 17:58:30 +03:00
|
|
|
"""An alias for limit().
|
2011-09-17 21:34:47 +04:00
|
|
|
"""
|
|
|
|
return limit(repo, subset, x)
|
|
|
|
|
2012-02-26 20:10:57 +04:00
|
|
|
def _follow(repo, subset, x, name, followfirst=False):
|
2016-08-18 18:25:10 +03:00
|
|
|
l = getargs(x, 0, 2, _("%s takes no arguments or a pattern "
|
|
|
|
"and an optional revset") % name)
|
2012-01-21 09:52:31 +04:00
|
|
|
c = repo['.']
|
2011-05-17 02:02:35 +04:00
|
|
|
if l:
|
2015-08-20 18:19:32 +03:00
|
|
|
x = getstring(l[0], _("%s expected a pattern") % name)
|
2016-08-18 18:25:10 +03:00
|
|
|
rev = None
|
|
|
|
if len(l) >= 2:
|
2016-10-10 23:30:09 +03:00
|
|
|
revs = getset(repo, fullreposet(repo), l[1])
|
|
|
|
if len(revs) != 1:
|
2016-08-18 18:25:10 +03:00
|
|
|
raise error.RepoLookupError(
|
2016-10-10 23:30:09 +03:00
|
|
|
_("%s expected one starting revision") % name)
|
|
|
|
rev = revs.last()
|
2016-08-18 18:25:10 +03:00
|
|
|
c = repo[rev]
|
2015-08-20 18:19:32 +03:00
|
|
|
matcher = matchmod.match(repo.root, repo.getcwd(), [x],
|
2016-08-18 18:25:10 +03:00
|
|
|
ctx=repo[rev], default='path')
|
2015-08-20 18:19:32 +03:00
|
|
|
|
2016-02-06 00:30:25 +03:00
|
|
|
files = c.manifest().walk(matcher)
|
|
|
|
|
2015-08-20 18:19:32 +03:00
|
|
|
s = set()
|
2016-02-06 00:30:25 +03:00
|
|
|
for fname in files:
|
|
|
|
fctx = c[fname]
|
|
|
|
s = s.union(set(c.rev() for c in fctx.ancestors(followfirst)))
|
|
|
|
# include the revision responsible for the most recent version
|
|
|
|
s.add(fctx.introrev())
|
2011-05-17 02:02:35 +04:00
|
|
|
else:
|
2014-02-07 22:32:02 +04:00
|
|
|
s = _revancestors(repo, baseset([c.rev()]), followfirst)
|
2012-02-26 01:11:36 +04:00
|
|
|
|
2014-09-17 21:59:16 +04:00
|
|
|
return subset & s
|
2012-02-26 01:11:36 +04:00
|
|
|
|
2016-08-18 18:25:10 +03:00
|
|
|
@predicate('follow([pattern[, startrev]])', safe=True)
|
2012-02-26 20:10:57 +04:00
|
|
|
def follow(repo, subset, x):
|
2015-12-29 17:58:30 +03:00
|
|
|
"""
|
2015-03-17 14:50:19 +03:00
|
|
|
An alias for ``::.`` (ancestors of the working directory's first parent).
|
2015-08-20 18:19:32 +03:00
|
|
|
If pattern is specified, the histories of files matching given
|
2016-08-18 18:25:10 +03:00
|
|
|
pattern in the revision given by startrev are followed, including copies.
|
2012-02-26 20:10:57 +04:00
|
|
|
"""
|
|
|
|
return _follow(repo, subset, x, 'follow')
|
|
|
|
|
2015-12-29 17:58:30 +03:00
|
|
|
@predicate('_followfirst', safe=True)
|
2012-02-26 20:10:57 +04:00
|
|
|
def _followfirst(repo, subset, x):
|
2016-08-18 18:25:10 +03:00
|
|
|
# ``followfirst([pattern[, startrev]])``
|
|
|
|
# Like ``follow([pattern[, startrev]])`` but follows only the first parent
|
|
|
|
# of every revisions or files revisions.
|
2012-02-26 20:10:57 +04:00
|
|
|
return _follow(repo, subset, x, '_followfirst', followfirst=True)
|
|
|
|
|
2015-12-29 17:58:30 +03:00
|
|
|
@predicate('all()', safe=True)
|
2011-04-08 18:47:58 +04:00
|
|
|
def getall(repo, subset, x):
|
2015-12-29 17:58:30 +03:00
|
|
|
"""All changesets, the same as ``0:tip``.
|
2010-10-23 21:21:51 +04:00
|
|
|
"""
|
2011-04-08 18:47:58 +04:00
|
|
|
# i18n: "all" is a keyword
|
|
|
|
getargs(x, 0, 0, _("all takes no arguments"))
|
2015-01-10 08:49:50 +03:00
|
|
|
return subset & spanset(repo) # drop "null" if any
|
2010-06-01 20:18:57 +04:00
|
|
|
|
2015-12-29 17:58:30 +03:00
|
|
|
@predicate('grep(regex)')
|
2010-06-01 20:18:57 +04:00
|
|
|
def grep(repo, subset, x):
|
2015-12-29 17:58:30 +03:00
|
|
|
"""Like ``keyword(string)`` but accepts a regex. Use ``grep(r'...')``
|
2011-05-18 11:28:11 +04:00
|
|
|
to ensure special escape characters are handled correctly. Unlike
|
|
|
|
``keyword(string)``, the match is case-sensitive.
|
2010-10-23 21:21:51 +04:00
|
|
|
"""
|
2010-09-17 19:21:02 +04:00
|
|
|
try:
|
2010-10-23 16:59:19 +04:00
|
|
|
# i18n: "grep" is a keyword
|
2010-10-16 20:50:53 +04:00
|
|
|
gr = re.compile(getstring(x, _("grep requires a string")))
|
2015-06-24 08:20:08 +03:00
|
|
|
except re.error as e:
|
2010-09-17 19:21:02 +04:00
|
|
|
raise error.ParseError(_('invalid match pattern: %s') % e)
|
2014-01-31 04:03:18 +04:00
|
|
|
|
|
|
|
def matches(x):
|
|
|
|
c = repo[x]
|
2010-06-01 20:18:57 +04:00
|
|
|
for e in c.files() + [c.user(), c.description()]:
|
|
|
|
if gr.search(e):
|
2014-01-31 04:03:18 +04:00
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
2016-02-13 14:05:57 +03:00
|
|
|
return subset.filter(matches, condrepr=('<grep %r>', gr.pattern))
|
2010-06-01 20:18:57 +04:00
|
|
|
|
2015-12-29 17:58:30 +03:00
|
|
|
@predicate('_matchfiles', safe=True)
|
2012-02-23 21:05:20 +04:00
|
|
|
def _matchfiles(repo, subset, x):
|
|
|
|
# _matchfiles takes a revset list of prefixed arguments:
|
|
|
|
#
|
|
|
|
# [p:foo, i:bar, x:baz]
|
|
|
|
#
|
|
|
|
# builds a match object from them and filters subset. Allowed
|
|
|
|
# prefixes are 'p:' for regular patterns, 'i:' for include
|
2012-02-26 20:10:51 +04:00
|
|
|
# patterns and 'x:' for exclude patterns. Use 'r:' prefix to pass
|
|
|
|
# a revision identifier, or the empty string to reference the
|
|
|
|
# working directory, from which the match object is
|
2012-04-11 13:32:00 +04:00
|
|
|
# initialized. Use 'd:' to set the default matching mode, default
|
|
|
|
# to 'glob'. At most one 'r:' and 'd:' argument can be passed.
|
2012-02-23 21:05:20 +04:00
|
|
|
|
2015-05-05 04:47:35 +03:00
|
|
|
l = getargs(x, 1, -1, "_matchfiles requires at least one argument")
|
2012-02-23 21:05:20 +04:00
|
|
|
pats, inc, exc = [], [], []
|
2012-04-11 13:32:00 +04:00
|
|
|
rev, default = None, None
|
2012-02-23 21:05:20 +04:00
|
|
|
for arg in l:
|
2015-05-05 04:47:35 +03:00
|
|
|
s = getstring(arg, "_matchfiles requires string arguments")
|
2012-02-23 21:05:20 +04:00
|
|
|
prefix, value = s[:2], s[2:]
|
|
|
|
if prefix == 'p:':
|
|
|
|
pats.append(value)
|
|
|
|
elif prefix == 'i:':
|
|
|
|
inc.append(value)
|
|
|
|
elif prefix == 'x:':
|
|
|
|
exc.append(value)
|
2012-02-26 20:10:51 +04:00
|
|
|
elif prefix == 'r:':
|
|
|
|
if rev is not None:
|
2015-05-05 04:47:35 +03:00
|
|
|
raise error.ParseError('_matchfiles expected at most one '
|
|
|
|
'revision')
|
log: evaluate filesets on working copy, not its parent
When running "hg log 'set:added()'", we create two matchers: one used
for producing the revset and one used for finding files to match. In
185b6b930e8c (graphlog: evaluate FILE/-I/-X filesets on the working
dir, 2012-02-26), we started passing a revision argument along from
what's currently in cmdutil._makelogrevset() to
revset._matchfiles(). When the revision was an empty string, it
referred to the working copy. This was subtly done with "repo[rev or
None]". Then, in 5ff5c5c9e69f (revset: avoid recalculating filesets,
2014-10-22), that conversion from empty string to None was lost. Note
that repo[''] is equivalent to repo['.'], not repo[None].
The consequence of this, to the user, is that when running "hg log
'set:added()'", the file matcher matches files added in the working
copy, while the revset matcher matches revisions that touch files
added in the parent of the working copy. As a result, only revisions
that touch any files added in the parent of the working copy will be
considered, but they will only be included if they also touch files
added in the working copy.
Fix the bug by converting '' to None again, but make it a little more
explicit this time (plus, we now have tests for it).
2015-01-22 02:23:13 +03:00
|
|
|
if value != '': # empty means working directory; leave rev as None
|
|
|
|
rev = value
|
2012-04-11 13:32:00 +04:00
|
|
|
elif prefix == 'd:':
|
|
|
|
if default is not None:
|
2015-05-05 04:47:35 +03:00
|
|
|
raise error.ParseError('_matchfiles expected at most one '
|
|
|
|
'default mode')
|
2012-04-11 13:32:00 +04:00
|
|
|
default = value
|
2012-02-23 21:05:20 +04:00
|
|
|
else:
|
2015-05-05 04:47:35 +03:00
|
|
|
raise error.ParseError('invalid _matchfiles prefix: %s' % prefix)
|
2012-04-11 13:32:00 +04:00
|
|
|
if not default:
|
|
|
|
default = 'glob'
|
2014-02-04 20:51:07 +04:00
|
|
|
|
2014-10-23 00:47:27 +04:00
|
|
|
m = matchmod.match(repo.root, repo.getcwd(), pats, include=inc,
|
|
|
|
exclude=exc, ctx=repo[rev], default=default)
|
|
|
|
|
2015-11-19 10:23:03 +03:00
|
|
|
# This directly read the changelog data as creating changectx for all
|
|
|
|
# revisions is quite expensive.
|
2015-12-18 23:54:45 +03:00
|
|
|
getfiles = repo.changelog.readfiles
|
2015-11-19 10:23:03 +03:00
|
|
|
wdirrev = node.wdirrev
|
2014-02-04 20:51:07 +04:00
|
|
|
def matches(x):
|
2015-11-19 10:23:03 +03:00
|
|
|
if x == wdirrev:
|
|
|
|
files = repo[x].files()
|
|
|
|
else:
|
2015-12-18 23:54:45 +03:00
|
|
|
files = getfiles(x)
|
2015-11-19 10:23:03 +03:00
|
|
|
for f in files:
|
2010-06-01 20:18:57 +04:00
|
|
|
if m(f):
|
2014-02-04 20:51:07 +04:00
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
2016-02-13 14:05:57 +03:00
|
|
|
return subset.filter(matches,
|
|
|
|
condrepr=('<matchfiles patterns=%r, include=%r '
|
|
|
|
'exclude=%r, default=%r, rev=%r>',
|
|
|
|
pats, inc, exc, default, rev))
|
2010-06-01 20:18:57 +04:00
|
|
|
|
2015-12-29 17:58:30 +03:00
|
|
|
@predicate('file(pattern)', safe=True)
|
2012-02-23 21:05:20 +04:00
|
|
|
def hasfile(repo, subset, x):
|
2015-12-29 17:58:30 +03:00
|
|
|
"""Changesets affecting files matched by pattern.
|
2012-07-25 11:15:28 +04:00
|
|
|
|
2012-07-26 06:41:26 +04:00
|
|
|
For a faster but less accurate result, consider using ``filelog()``
|
|
|
|
instead.
|
2014-01-17 18:55:11 +04:00
|
|
|
|
|
|
|
This predicate uses ``glob:`` as the default kind of pattern.
|
2012-02-23 21:05:20 +04:00
|
|
|
"""
|
|
|
|
# i18n: "file" is a keyword
|
|
|
|
pat = getstring(x, _("file requires a pattern"))
|
|
|
|
return _matchfiles(repo, subset, ('string', 'p:' + pat))
|
|
|
|
|
2015-12-29 17:58:30 +03:00
|
|
|
@predicate('head()', safe=True)
|
2011-04-08 18:47:58 +04:00
|
|
|
def head(repo, subset, x):
|
2015-12-29 17:58:30 +03:00
|
|
|
"""Changeset is a named branch head.
|
2010-10-23 21:21:51 +04:00
|
|
|
"""
|
2011-04-08 18:47:58 +04:00
|
|
|
# i18n: "head" is a keyword
|
|
|
|
getargs(x, 0, 0, _("head takes no arguments"))
|
|
|
|
hs = set()
|
2015-06-17 05:47:46 +03:00
|
|
|
cl = repo.changelog
|
2016-06-23 23:08:10 +03:00
|
|
|
for ls in repo.branchmap().itervalues():
|
2015-06-17 05:47:46 +03:00
|
|
|
hs.update(cl.rev(h) for h in ls)
|
2016-06-23 22:37:09 +03:00
|
|
|
return subset & baseset(hs)
|
2010-06-01 20:18:57 +04:00
|
|
|
|
2015-12-29 17:58:30 +03:00
|
|
|
@predicate('heads(set)', safe=True)
|
2011-04-08 18:47:58 +04:00
|
|
|
def heads(repo, subset, x):
|
2015-12-29 17:58:30 +03:00
|
|
|
"""Members of set with no children in set.
|
2011-04-08 18:47:58 +04:00
|
|
|
"""
|
2014-01-24 02:20:58 +04:00
|
|
|
s = getset(repo, subset, x)
|
|
|
|
ps = parents(repo, subset, x)
|
|
|
|
return s - ps
|
2011-04-08 18:47:58 +04:00
|
|
|
|
2015-12-29 17:58:30 +03:00
|
|
|
@predicate('hidden()', safe=True)
|
2012-08-04 22:20:48 +04:00
|
|
|
def hidden(repo, subset, x):
|
2015-12-29 17:58:30 +03:00
|
|
|
"""Hidden changesets.
|
2012-08-04 22:20:48 +04:00
|
|
|
"""
|
|
|
|
# i18n: "hidden" is a keyword
|
|
|
|
getargs(x, 0, 0, _("hidden takes no arguments"))
|
2013-01-13 11:39:16 +04:00
|
|
|
hiddenrevs = repoview.filterrevs(repo, 'visible')
|
2014-01-25 04:57:44 +04:00
|
|
|
return subset & hiddenrevs
|
2012-08-04 22:20:48 +04:00
|
|
|
|
2015-12-29 17:58:30 +03:00
|
|
|
@predicate('keyword(string)', safe=True)
|
2011-04-08 18:47:58 +04:00
|
|
|
def keyword(repo, subset, x):
|
2015-12-29 17:58:30 +03:00
|
|
|
"""Search commit message, user name, and names of changed files for
|
2011-05-18 11:56:27 +04:00
|
|
|
string. The match is case-insensitive.
|
2011-04-08 18:47:58 +04:00
|
|
|
"""
|
|
|
|
# i18n: "keyword" is a keyword
|
2011-12-25 15:35:16 +04:00
|
|
|
kw = encoding.lower(getstring(x, _("keyword requires a string")))
|
2014-01-29 21:04:03 +04:00
|
|
|
|
|
|
|
def matches(r):
|
2010-06-01 20:18:57 +04:00
|
|
|
c = repo[r]
|
2015-06-12 01:36:03 +03:00
|
|
|
return any(kw in encoding.lower(t)
|
|
|
|
for t in c.files() + [c.user(), c.description()])
|
2014-01-29 21:04:03 +04:00
|
|
|
|
2016-02-13 14:05:57 +03:00
|
|
|
return subset.filter(matches, condrepr=('<keyword %r>', kw))
|
2011-04-08 18:47:58 +04:00
|
|
|
|
2015-12-29 17:58:30 +03:00
|
|
|
@predicate('limit(set[, n[, offset]])', safe=True)
|
2011-04-08 18:47:58 +04:00
|
|
|
def limit(repo, subset, x):
|
2015-12-29 17:58:30 +03:00
|
|
|
"""First n members of set, defaulting to 1, starting from offset.
|
2011-04-08 18:47:58 +04:00
|
|
|
"""
|
2015-03-23 18:28:28 +03:00
|
|
|
args = getargsdict(x, 'limit', 'set n offset')
|
2015-10-12 11:19:22 +03:00
|
|
|
if 'set' not in args:
|
|
|
|
# i18n: "limit" is a keyword
|
2015-03-23 18:28:28 +03:00
|
|
|
raise error.ParseError(_("limit requires one to three arguments"))
|
2011-04-08 18:47:58 +04:00
|
|
|
try:
|
2015-03-23 18:28:28 +03:00
|
|
|
lim, ofs = 1, 0
|
2015-10-12 11:19:22 +03:00
|
|
|
if 'n' in args:
|
2011-09-17 07:57:47 +04:00
|
|
|
# i18n: "limit" is a keyword
|
2015-10-12 11:19:22 +03:00
|
|
|
lim = int(getstring(args['n'], _("limit requires a number")))
|
2015-03-23 18:28:28 +03:00
|
|
|
if 'offset' in args:
|
|
|
|
# i18n: "limit" is a keyword
|
|
|
|
ofs = int(getstring(args['offset'], _("limit requires a number")))
|
|
|
|
if ofs < 0:
|
|
|
|
raise error.ParseError(_("negative offset"))
|
2011-07-12 21:35:03 +04:00
|
|
|
except (TypeError, ValueError):
|
2011-04-08 18:47:58 +04:00
|
|
|
# i18n: "limit" is a keyword
|
|
|
|
raise error.ParseError(_("limit expects a number"))
|
2015-10-12 11:19:22 +03:00
|
|
|
os = getset(repo, fullreposet(repo), args['set'])
|
2014-10-06 21:57:01 +04:00
|
|
|
result = []
|
2014-01-29 04:19:30 +04:00
|
|
|
it = iter(os)
|
2015-03-23 18:28:28 +03:00
|
|
|
for x in xrange(ofs):
|
|
|
|
y = next(it, None)
|
|
|
|
if y is None:
|
|
|
|
break
|
2014-01-29 04:19:30 +04:00
|
|
|
for x in xrange(lim):
|
2015-05-18 03:58:39 +03:00
|
|
|
y = next(it, None)
|
|
|
|
if y is None:
|
2014-01-29 04:19:30 +04:00
|
|
|
break
|
2015-10-12 11:14:47 +03:00
|
|
|
elif y in subset:
|
2015-05-18 03:58:39 +03:00
|
|
|
result.append(y)
|
2016-02-16 15:43:51 +03:00
|
|
|
return baseset(result, datarepr=('<limit n=%d, offset=%d, %r, %r>',
|
|
|
|
lim, ofs, subset, os))
|
2011-04-08 18:47:58 +04:00
|
|
|
|
2015-12-29 17:58:30 +03:00
|
|
|
@predicate('last(set, [n])', safe=True)
|
2011-04-30 19:56:43 +04:00
|
|
|
def last(repo, subset, x):
|
2015-12-29 17:58:30 +03:00
|
|
|
"""Last n members of set, defaulting to 1.
|
2011-04-30 19:56:43 +04:00
|
|
|
"""
|
|
|
|
# i18n: "last" is a keyword
|
2011-09-17 07:57:47 +04:00
|
|
|
l = getargs(x, 1, 2, _("last requires one or two arguments"))
|
2011-04-30 19:56:43 +04:00
|
|
|
try:
|
2011-09-17 07:57:47 +04:00
|
|
|
lim = 1
|
|
|
|
if len(l) == 2:
|
|
|
|
# i18n: "last" is a keyword
|
|
|
|
lim = int(getstring(l[1], _("last requires a number")))
|
2011-07-12 21:35:03 +04:00
|
|
|
except (TypeError, ValueError):
|
2011-04-30 19:56:43 +04:00
|
|
|
# i18n: "last" is a keyword
|
|
|
|
raise error.ParseError(_("last expects a number"))
|
2015-01-08 17:46:54 +03:00
|
|
|
os = getset(repo, fullreposet(repo), l[0])
|
2014-02-20 00:56:41 +04:00
|
|
|
os.reverse()
|
2014-10-08 11:55:09 +04:00
|
|
|
result = []
|
2014-02-20 00:56:41 +04:00
|
|
|
it = iter(os)
|
|
|
|
for x in xrange(lim):
|
2015-05-18 04:00:38 +03:00
|
|
|
y = next(it, None)
|
|
|
|
if y is None:
|
2014-02-20 00:56:41 +04:00
|
|
|
break
|
2015-10-12 11:14:47 +03:00
|
|
|
elif y in subset:
|
2015-05-18 04:00:38 +03:00
|
|
|
result.append(y)
|
2016-02-16 15:43:51 +03:00
|
|
|
return baseset(result, datarepr=('<last n=%d, %r, %r>', lim, subset, os))
|
2011-04-30 19:56:43 +04:00
|
|
|
|
2015-12-29 17:58:30 +03:00
|
|
|
@predicate('max(set)', safe=True)
|
2011-04-08 18:47:58 +04:00
|
|
|
def maxrev(repo, subset, x):
|
2015-12-29 17:58:30 +03:00
|
|
|
"""Changeset with highest revision number in set.
|
2011-04-08 18:47:58 +04:00
|
|
|
"""
|
2015-01-08 17:46:54 +03:00
|
|
|
os = getset(repo, fullreposet(repo), x)
|
2015-09-21 05:27:53 +03:00
|
|
|
try:
|
2014-02-18 23:35:03 +04:00
|
|
|
m = os.max()
|
2011-04-08 18:47:58 +04:00
|
|
|
if m in subset:
|
2016-02-16 15:44:13 +03:00
|
|
|
return baseset([m], datarepr=('<max %r, %r>', subset, os))
|
2015-09-21 05:27:53 +03:00
|
|
|
except ValueError:
|
|
|
|
# os.max() throws a ValueError when the collection is empty.
|
|
|
|
# Same as python's max().
|
|
|
|
pass
|
2016-02-16 15:44:13 +03:00
|
|
|
return baseset(datarepr=('<max %r, %r>', subset, os))
|
2011-04-08 18:47:58 +04:00
|
|
|
|
2015-12-29 17:58:30 +03:00
|
|
|
@predicate('merge()', safe=True)
|
2011-04-08 18:47:58 +04:00
|
|
|
def merge(repo, subset, x):
|
2015-12-29 17:58:30 +03:00
|
|
|
"""Changeset is a merge changeset.
|
2011-04-08 18:47:58 +04:00
|
|
|
"""
|
|
|
|
# i18n: "merge" is a keyword
|
|
|
|
getargs(x, 0, 0, _("merge takes no arguments"))
|
|
|
|
cl = repo.changelog
|
2016-02-13 14:05:57 +03:00
|
|
|
return subset.filter(lambda r: cl.parentrevs(r)[1] != -1,
|
|
|
|
condrepr='<merge>')
|
2011-04-08 18:47:58 +04:00
|
|
|
|
2015-12-29 17:58:30 +03:00
|
|
|
@predicate('branchpoint()', safe=True)
|
2012-08-13 23:50:45 +04:00
|
|
|
def branchpoint(repo, subset, x):
|
2015-12-29 17:58:30 +03:00
|
|
|
"""Changesets with more than one child.
|
2012-08-13 23:50:45 +04:00
|
|
|
"""
|
|
|
|
# i18n: "branchpoint" is a keyword
|
|
|
|
getargs(x, 0, 0, _("branchpoint takes no arguments"))
|
|
|
|
cl = repo.changelog
|
|
|
|
if not subset:
|
2014-10-06 21:41:43 +04:00
|
|
|
return baseset()
|
2015-06-12 00:26:44 +03:00
|
|
|
# XXX this should be 'parentset.min()' assuming 'parentset' is a smartset
|
|
|
|
# (and if it is not, it should.)
|
2012-08-13 23:50:45 +04:00
|
|
|
baserev = min(subset)
|
|
|
|
parentscount = [0]*(len(repo) - baserev)
|
2012-10-15 19:42:40 +04:00
|
|
|
for r in cl.revs(start=baserev + 1):
|
2012-08-13 23:50:45 +04:00
|
|
|
for p in cl.parentrevs(r):
|
|
|
|
if p >= baserev:
|
|
|
|
parentscount[p - baserev] += 1
|
2016-02-13 14:05:57 +03:00
|
|
|
return subset.filter(lambda r: parentscount[r - baserev] > 1,
|
|
|
|
condrepr='<branchpoint>')
|
2012-08-13 23:50:45 +04:00
|
|
|
|
2015-12-29 17:58:30 +03:00
|
|
|
@predicate('min(set)', safe=True)
|
2011-04-08 18:47:58 +04:00
|
|
|
def minrev(repo, subset, x):
|
2015-12-29 17:58:30 +03:00
|
|
|
"""Changeset with lowest revision number in set.
|
2011-04-08 18:47:58 +04:00
|
|
|
"""
|
2015-01-08 17:46:54 +03:00
|
|
|
os = getset(repo, fullreposet(repo), x)
|
2015-09-21 05:27:53 +03:00
|
|
|
try:
|
2014-02-18 23:35:03 +04:00
|
|
|
m = os.min()
|
2011-04-08 18:47:58 +04:00
|
|
|
if m in subset:
|
2016-02-16 15:44:13 +03:00
|
|
|
return baseset([m], datarepr=('<min %r, %r>', subset, os))
|
2015-09-21 05:27:53 +03:00
|
|
|
except ValueError:
|
|
|
|
# os.min() throws a ValueError when the collection is empty.
|
|
|
|
# Same as python's min().
|
|
|
|
pass
|
2016-02-16 15:44:13 +03:00
|
|
|
return baseset(datarepr=('<min %r, %r>', subset, os))
|
2010-06-01 20:18:57 +04:00
|
|
|
|
2015-12-29 17:58:30 +03:00
|
|
|
@predicate('modifies(pattern)', safe=True)
|
2010-06-01 20:18:57 +04:00
|
|
|
def modifies(repo, subset, x):
|
2015-12-29 17:58:30 +03:00
|
|
|
"""Changesets modifying files matched by pattern.
|
2014-01-17 18:55:11 +04:00
|
|
|
|
|
|
|
The pattern without explicit kind like ``glob:`` is expected to be
|
|
|
|
relative to the current directory and match against a file or a
|
|
|
|
directory.
|
2010-10-23 21:21:51 +04:00
|
|
|
"""
|
2010-10-23 16:59:19 +04:00
|
|
|
# i18n: "modifies" is a keyword
|
2010-10-16 20:50:53 +04:00
|
|
|
pat = getstring(x, _("modifies requires a pattern"))
|
2010-06-01 20:18:57 +04:00
|
|
|
return checkstatus(repo, subset, pat, 0)
|
|
|
|
|
2015-12-29 17:58:30 +03:00
|
|
|
@predicate('named(namespace)')
|
2015-01-14 02:07:08 +03:00
|
|
|
def named(repo, subset, x):
|
2015-12-29 17:58:30 +03:00
|
|
|
"""The changesets in a given namespace.
|
2015-01-14 02:07:08 +03:00
|
|
|
|
|
|
|
If `namespace` starts with `re:`, the remainder of the string is treated as
|
|
|
|
a regular expression. To match a namespace that actually starts with `re:`,
|
|
|
|
use the prefix `literal:`.
|
|
|
|
"""
|
|
|
|
# i18n: "named" is a keyword
|
|
|
|
args = getargs(x, 1, 1, _('named requires a namespace argument'))
|
|
|
|
|
|
|
|
ns = getstring(args[0],
|
|
|
|
# i18n: "named" is a keyword
|
|
|
|
_('the argument to named must be a string'))
|
2015-08-23 05:52:18 +03:00
|
|
|
kind, pattern, matcher = util.stringmatcher(ns)
|
2015-01-14 02:07:08 +03:00
|
|
|
namespaces = set()
|
|
|
|
if kind == 'literal':
|
|
|
|
if pattern not in repo.names:
|
revset: raise RepoLookupError to make present() predicate continue the query
Before this patch, "bookmark()", "named()" and "tag()" predicates
raise "Abort", when the specified pattern doesn't match against
existing ones.
This prevents "present()" predicate from continuing the query, because
it only catches "RepoLookupError".
This patch raises "RepoLookupError" instead of "Abort", to make
"present()" predicate continue the query, even if "bookmark()",
"named()" or "tag()" in the sub-query of it are aborted.
This patch doesn't contain raising "RepoLookupError" for "re:" pattern
in "tag()", because "tag()" treats it differently from others. Actions
of each predicates at failure of pattern matching can be summarized as
below:
predicate "literal:" "re:"
---------- ----------- ------------
bookmark abort abort
named abort abort
tag abort continue (*1)
branch abort continue (*2)
---------- ----------- ------------
"tag()" may have to abort in the (*1) case for similarity, but this
change may break backward compatibility of existing revset queries. It
seems to have to be changed on "default" branch (with "BC" ?).
On the other hand, (*2) seems to be reasonable, even though it breaks
similarity, because "branch()" in this case doesn't check exact
existence of branches, but does pick up revisions of which branch
matches against the pattern.
This patch also adds tests for "branch()" to clarify behavior around
"present()" of similar predicates, even though this patch doesn't
change "branch()".
2015-01-30 19:00:50 +03:00
|
|
|
raise error.RepoLookupError(_("namespace '%s' does not exist")
|
|
|
|
% ns)
|
2015-01-14 02:07:08 +03:00
|
|
|
namespaces.add(repo.names[pattern])
|
|
|
|
else:
|
|
|
|
for name, ns in repo.names.iteritems():
|
|
|
|
if matcher(name):
|
|
|
|
namespaces.add(ns)
|
|
|
|
if not namespaces:
|
revset: raise RepoLookupError to make present() predicate continue the query
Before this patch, "bookmark()", "named()" and "tag()" predicates
raise "Abort", when the specified pattern doesn't match against
existing ones.
This prevents "present()" predicate from continuing the query, because
it only catches "RepoLookupError".
This patch raises "RepoLookupError" instead of "Abort", to make
"present()" predicate continue the query, even if "bookmark()",
"named()" or "tag()" in the sub-query of it are aborted.
This patch doesn't contain raising "RepoLookupError" for "re:" pattern
in "tag()", because "tag()" treats it differently from others. Actions
of each predicates at failure of pattern matching can be summarized as
below:
predicate "literal:" "re:"
---------- ----------- ------------
bookmark abort abort
named abort abort
tag abort continue (*1)
branch abort continue (*2)
---------- ----------- ------------
"tag()" may have to abort in the (*1) case for similarity, but this
change may break backward compatibility of existing revset queries. It
seems to have to be changed on "default" branch (with "BC" ?).
On the other hand, (*2) seems to be reasonable, even though it breaks
similarity, because "branch()" in this case doesn't check exact
existence of branches, but does pick up revisions of which branch
matches against the pattern.
This patch also adds tests for "branch()" to clarify behavior around
"present()" of similar predicates, even though this patch doesn't
change "branch()".
2015-01-30 19:00:50 +03:00
|
|
|
raise error.RepoLookupError(_("no namespace exists"
|
|
|
|
" that match '%s'") % pattern)
|
2015-01-14 02:07:08 +03:00
|
|
|
|
|
|
|
names = set()
|
|
|
|
for ns in namespaces:
|
|
|
|
for name in ns.listnames(repo):
|
revset: mask specific names for named() predicate
Before this patch, revset predicate "tag()" and "named('tags')" differ
from each other, because the former doesn't include "tip" but the
latter does.
For equivalence, "named('tags')" shouldn't include the revision
corresponded to "tip". But just removing "tip" from the "tags"
namespace causes breaking backward compatibility, even though "tip"
itself is planned to be eliminated, as mentioned below.
http://selenic.com/pipermail/mercurial-devel/2015-February/066157.html
To mask specific names ("tip" in this case) for "named()" predicate,
this patch introduces "deprecated" into "namespaces", and makes
"named()" predicate examine whether each names are masked by the
namespace, to which they belong.
"named()" will really work correctly after 3.3.1 (see a3c326a7f57a for
detail), and fixing this on STABLE before 3.3.1 can prevent initial
users of "named()" from expecting "named('tags')" to include "tip".
It is reason why this patch is posted for STABLE, even though problem
itself isn't so serious.
This may have to be flagged as "(BC)", if applied on DEFAULT.
2015-02-05 08:45:49 +03:00
|
|
|
if name not in ns.deprecated:
|
|
|
|
names.update(repo[n].rev() for n in ns.nodes(repo, name))
|
2015-01-14 02:07:08 +03:00
|
|
|
|
|
|
|
names -= set([node.nullrev])
|
|
|
|
return subset & names
|
|
|
|
|
2015-12-29 17:58:30 +03:00
|
|
|
@predicate('id(string)', safe=True)
|
2012-04-14 00:32:49 +04:00
|
|
|
def node_(repo, subset, x):
|
2015-12-29 17:58:30 +03:00
|
|
|
"""Revision non-ambiguously specified by the given hex string prefix.
|
2010-10-23 21:21:51 +04:00
|
|
|
"""
|
2011-04-08 18:47:58 +04:00
|
|
|
# i18n: "id" is a keyword
|
|
|
|
l = getargs(x, 1, 1, _("id requires one argument"))
|
|
|
|
# i18n: "id" is a keyword
|
|
|
|
n = getstring(l[0], _("id requires a string"))
|
|
|
|
if len(n) == 40:
|
2015-04-20 10:52:20 +03:00
|
|
|
try:
|
|
|
|
rn = repo.changelog.rev(node.bin(n))
|
|
|
|
except (LookupError, TypeError):
|
|
|
|
rn = None
|
2011-04-08 18:47:58 +04:00
|
|
|
else:
|
2012-05-15 03:25:13 +04:00
|
|
|
rn = None
|
|
|
|
pm = repo.changelog._partialmatch(n)
|
|
|
|
if pm is not None:
|
|
|
|
rn = repo.changelog.rev(pm)
|
|
|
|
|
2014-10-11 12:39:20 +04:00
|
|
|
if rn is None:
|
|
|
|
return baseset()
|
|
|
|
result = baseset([rn])
|
|
|
|
return result & subset
|
2010-06-01 20:18:57 +04:00
|
|
|
|
2015-12-29 17:58:30 +03:00
|
|
|
@predicate('obsolete()', safe=True)
|
2012-07-06 21:29:10 +04:00
|
|
|
def obsolete(repo, subset, x):
|
2015-12-29 17:58:30 +03:00
|
|
|
"""Mutable changeset with a newer version."""
|
2012-07-26 08:58:43 +04:00
|
|
|
# i18n: "obsolete" is a keyword
|
2012-07-06 21:29:10 +04:00
|
|
|
getargs(x, 0, 0, _("obsolete takes no arguments"))
|
2012-10-19 02:28:13 +04:00
|
|
|
obsoletes = obsmod.getrevs(repo, 'obsolete')
|
2014-01-25 04:57:44 +04:00
|
|
|
return subset & obsoletes
|
2012-07-06 21:29:10 +04:00
|
|
|
|
2015-12-29 17:58:30 +03:00
|
|
|
@predicate('only(set, [set])', safe=True)
|
2014-12-03 16:52:54 +03:00
|
|
|
def only(repo, subset, x):
|
2015-12-29 17:58:30 +03:00
|
|
|
"""Changesets that are ancestors of the first set that are not ancestors
|
2014-12-03 16:52:54 +03:00
|
|
|
of any other head in the repo. If a second set is specified, the result
|
|
|
|
is ancestors of the first set that are not ancestors of the second set
|
|
|
|
(i.e. ::<set1> - ::<set2>).
|
|
|
|
"""
|
|
|
|
cl = repo.changelog
|
|
|
|
# i18n: "only" is a keyword
|
|
|
|
args = getargs(x, 1, 2, _('only takes one or two arguments'))
|
2015-01-08 17:46:54 +03:00
|
|
|
include = getset(repo, fullreposet(repo), args[0])
|
2014-12-03 16:52:54 +03:00
|
|
|
if len(args) == 1:
|
|
|
|
if not include:
|
|
|
|
return baseset()
|
|
|
|
|
|
|
|
descendants = set(_revdescendants(repo, include, False))
|
|
|
|
exclude = [rev for rev in cl.headrevs()
|
|
|
|
if not rev in descendants and not rev in include]
|
|
|
|
else:
|
2015-01-08 17:46:54 +03:00
|
|
|
exclude = getset(repo, fullreposet(repo), args[1])
|
2014-12-03 16:52:54 +03:00
|
|
|
|
|
|
|
results = set(cl.findmissingrevs(common=exclude, heads=include))
|
2015-06-12 01:45:02 +03:00
|
|
|
# XXX we should turn this into a baseset instead of a set, smartset may do
|
|
|
|
# some optimisations from the fact this is a baseset.
|
2014-12-03 16:52:54 +03:00
|
|
|
return subset & results
|
|
|
|
|
2015-12-29 17:58:30 +03:00
|
|
|
@predicate('origin([set])', safe=True)
|
2012-07-07 08:47:30 +04:00
|
|
|
def origin(repo, subset, x):
|
2015-12-29 17:58:30 +03:00
|
|
|
"""
|
2012-07-07 08:47:30 +04:00
|
|
|
Changesets that were specified as a source for the grafts, transplants or
|
|
|
|
rebases that created the given revisions. Omitting the optional set is the
|
|
|
|
same as passing all(). If a changeset created by these operations is itself
|
|
|
|
specified as a source for one of these operations, only the source changeset
|
|
|
|
for the first operation is selected.
|
|
|
|
"""
|
|
|
|
if x is not None:
|
2015-01-08 17:46:54 +03:00
|
|
|
dests = getset(repo, fullreposet(repo), x)
|
2012-07-07 08:47:30 +04:00
|
|
|
else:
|
2015-01-10 10:41:36 +03:00
|
|
|
dests = fullreposet(repo)
|
2012-07-07 08:47:30 +04:00
|
|
|
|
|
|
|
def _firstsrc(rev):
|
|
|
|
src = _getrevsource(repo, rev)
|
|
|
|
if src is None:
|
|
|
|
return None
|
|
|
|
|
|
|
|
while True:
|
|
|
|
prev = _getrevsource(repo, src)
|
|
|
|
|
|
|
|
if prev is None:
|
|
|
|
return src
|
|
|
|
src = prev
|
|
|
|
|
2014-10-15 06:08:06 +04:00
|
|
|
o = set([_firstsrc(r) for r in dests])
|
2014-09-17 21:59:30 +04:00
|
|
|
o -= set([None])
|
2015-06-12 01:45:02 +03:00
|
|
|
# XXX we should turn this into a baseset instead of a set, smartset may do
|
|
|
|
# some optimisations from the fact this is a baseset.
|
2014-09-18 06:52:34 +04:00
|
|
|
return subset & o
|
2012-07-07 08:47:30 +04:00
|
|
|
|
2015-12-29 17:58:30 +03:00
|
|
|
@predicate('outgoing([path])', safe=True)
|
2011-04-08 18:47:58 +04:00
|
|
|
def outgoing(repo, subset, x):
|
2015-12-29 17:58:30 +03:00
|
|
|
"""Changesets not found in the specified destination repository, or the
|
2011-04-08 18:47:58 +04:00
|
|
|
default push location.
|
2010-10-23 21:21:51 +04:00
|
|
|
"""
|
2015-04-14 19:54:16 +03:00
|
|
|
# Avoid cycles.
|
2015-08-09 04:36:58 +03:00
|
|
|
from . import (
|
|
|
|
discovery,
|
|
|
|
hg,
|
|
|
|
)
|
2011-04-08 18:47:58 +04:00
|
|
|
# i18n: "outgoing" is a keyword
|
2011-06-22 03:55:00 +04:00
|
|
|
l = getargs(x, 0, 1, _("outgoing takes one or no arguments"))
|
2011-04-08 18:47:58 +04:00
|
|
|
# i18n: "outgoing" is a keyword
|
|
|
|
dest = l and getstring(l[0], _("outgoing requires a repository path")) or ''
|
|
|
|
dest = repo.ui.expandpath(dest or 'default-push', dest or 'default')
|
|
|
|
dest, branches = hg.parseurl(dest)
|
|
|
|
revs, checkout = hg.addbranchrevs(repo, repo, branches, [])
|
|
|
|
if revs:
|
|
|
|
revs = [repo.lookup(rev) for rev in revs]
|
2011-06-10 20:43:38 +04:00
|
|
|
other = hg.peer(repo, {}, dest)
|
2011-04-08 18:47:58 +04:00
|
|
|
repo.ui.pushbuffer()
|
2012-01-09 06:47:16 +04:00
|
|
|
outgoing = discovery.findcommonoutgoing(repo, other, onlyheads=revs)
|
2011-04-08 18:47:58 +04:00
|
|
|
repo.ui.popbuffer()
|
|
|
|
cl = repo.changelog
|
2012-01-09 06:47:16 +04:00
|
|
|
o = set([cl.rev(r) for r in outgoing.missing])
|
2014-09-17 21:59:40 +04:00
|
|
|
return subset & o
|
2010-06-01 20:18:57 +04:00
|
|
|
|
2015-12-29 17:58:30 +03:00
|
|
|
@predicate('p1([set])', safe=True)
|
2011-04-08 18:47:58 +04:00
|
|
|
def p1(repo, subset, x):
|
2015-12-29 17:58:30 +03:00
|
|
|
"""First parent of changesets in set, or the working directory.
|
2010-10-23 21:21:51 +04:00
|
|
|
"""
|
2011-04-08 18:47:58 +04:00
|
|
|
if x is None:
|
|
|
|
p = repo[x].p1().rev()
|
2014-09-17 21:59:52 +04:00
|
|
|
if p >= 0:
|
|
|
|
return subset & baseset([p])
|
2014-10-06 21:41:43 +04:00
|
|
|
return baseset()
|
2011-04-08 18:47:58 +04:00
|
|
|
|
|
|
|
ps = set()
|
2010-06-01 20:18:57 +04:00
|
|
|
cl = repo.changelog
|
2015-01-08 17:46:54 +03:00
|
|
|
for r in getset(repo, fullreposet(repo), x):
|
2011-04-08 18:47:58 +04:00
|
|
|
ps.add(cl.parentrevs(r)[0])
|
2014-09-17 15:40:30 +04:00
|
|
|
ps -= set([node.nullrev])
|
2015-06-12 01:45:02 +03:00
|
|
|
# XXX we should turn this into a baseset instead of a set, smartset may do
|
|
|
|
# some optimisations from the fact this is a baseset.
|
2014-01-25 04:57:44 +04:00
|
|
|
return subset & ps
|
2010-06-01 20:18:57 +04:00
|
|
|
|
2015-12-29 17:58:30 +03:00
|
|
|
@predicate('p2([set])', safe=True)
|
2011-04-08 18:47:58 +04:00
|
|
|
def p2(repo, subset, x):
|
2015-12-29 17:58:30 +03:00
|
|
|
"""Second parent of changesets in set, or the working directory.
|
2010-10-23 21:21:51 +04:00
|
|
|
"""
|
2011-04-08 18:47:58 +04:00
|
|
|
if x is None:
|
|
|
|
ps = repo[x].parents()
|
|
|
|
try:
|
|
|
|
p = ps[1].rev()
|
2014-09-17 22:00:03 +04:00
|
|
|
if p >= 0:
|
|
|
|
return subset & baseset([p])
|
2014-10-06 21:41:43 +04:00
|
|
|
return baseset()
|
2011-04-08 18:47:58 +04:00
|
|
|
except IndexError:
|
2014-10-06 21:41:43 +04:00
|
|
|
return baseset()
|
2010-06-01 20:18:57 +04:00
|
|
|
|
2011-04-08 18:47:58 +04:00
|
|
|
ps = set()
|
|
|
|
cl = repo.changelog
|
2015-01-08 17:46:54 +03:00
|
|
|
for r in getset(repo, fullreposet(repo), x):
|
2011-04-08 18:47:58 +04:00
|
|
|
ps.add(cl.parentrevs(r)[1])
|
2014-09-17 15:40:30 +04:00
|
|
|
ps -= set([node.nullrev])
|
2015-06-12 01:45:02 +03:00
|
|
|
# XXX we should turn this into a baseset instead of a set, smartset may do
|
|
|
|
# some optimisations from the fact this is a baseset.
|
2014-01-25 04:57:44 +04:00
|
|
|
return subset & ps
|
2010-06-01 20:18:57 +04:00
|
|
|
|
2016-08-07 11:46:12 +03:00
|
|
|
def parentpost(repo, subset, x, order):
|
2016-08-07 11:48:52 +03:00
|
|
|
return p1(repo, subset, x)
|
|
|
|
|
2015-12-29 17:58:30 +03:00
|
|
|
@predicate('parents([set])', safe=True)
|
2011-04-08 18:47:58 +04:00
|
|
|
def parents(repo, subset, x):
|
2015-12-29 17:58:30 +03:00
|
|
|
"""
|
2011-04-08 18:47:58 +04:00
|
|
|
The set of all parents for all changesets in set, or the working directory.
|
2010-10-23 21:21:51 +04:00
|
|
|
"""
|
2011-04-08 18:47:58 +04:00
|
|
|
if x is None:
|
2014-09-18 06:44:03 +04:00
|
|
|
ps = set(p.rev() for p in repo[x].parents())
|
|
|
|
else:
|
|
|
|
ps = set()
|
|
|
|
cl = repo.changelog
|
2015-07-03 09:46:18 +03:00
|
|
|
up = ps.update
|
|
|
|
parentrevs = cl.parentrevs
|
2015-01-08 17:46:54 +03:00
|
|
|
for r in getset(repo, fullreposet(repo), x):
|
2015-03-16 10:17:06 +03:00
|
|
|
if r == node.wdirrev:
|
2015-07-03 09:46:18 +03:00
|
|
|
up(p.rev() for p in repo[r].parents())
|
2015-06-29 17:34:56 +03:00
|
|
|
else:
|
2015-07-03 09:46:18 +03:00
|
|
|
up(parentrevs(r))
|
2014-09-18 06:49:26 +04:00
|
|
|
ps -= set([node.nullrev])
|
2014-09-17 15:55:55 +04:00
|
|
|
return subset & ps
|
2010-06-01 20:18:57 +04:00
|
|
|
|
2015-06-18 05:19:57 +03:00
|
|
|
def _phase(repo, subset, target):
|
|
|
|
"""helper to select all rev in phase <target>"""
|
2015-06-11 05:18:51 +03:00
|
|
|
repo._phasecache.loadphaserevs(repo) # ensure phase's sets are loaded
|
|
|
|
if repo._phasecache._phasesets:
|
|
|
|
s = repo._phasecache._phasesets[target] - repo.changelog.filteredrevs
|
|
|
|
s = baseset(s)
|
|
|
|
s.sort() # set are non ordered, so we enforce ascending
|
|
|
|
return subset & s
|
|
|
|
else:
|
|
|
|
phase = repo._phasecache.phase
|
|
|
|
condition = lambda r: phase(repo, r) == target
|
2016-02-13 14:05:57 +03:00
|
|
|
return subset.filter(condition, condrepr=('<phase %r>', target),
|
|
|
|
cache=False)
|
2015-06-18 05:19:57 +03:00
|
|
|
|
2015-12-29 17:58:30 +03:00
|
|
|
@predicate('draft()', safe=True)
|
2015-06-18 05:19:57 +03:00
|
|
|
def draft(repo, subset, x):
|
2015-12-29 17:58:30 +03:00
|
|
|
"""Changeset in draft phase."""
|
2015-06-18 05:19:57 +03:00
|
|
|
# i18n: "draft" is a keyword
|
|
|
|
getargs(x, 0, 0, _("draft takes no arguments"))
|
|
|
|
target = phases.draft
|
|
|
|
return _phase(repo, subset, target)
|
|
|
|
|
2015-12-29 17:58:30 +03:00
|
|
|
@predicate('secret()', safe=True)
|
2015-06-18 05:19:57 +03:00
|
|
|
def secret(repo, subset, x):
|
2015-12-29 17:58:30 +03:00
|
|
|
"""Changeset in secret phase."""
|
2015-06-18 05:19:57 +03:00
|
|
|
# i18n: "secret" is a keyword
|
|
|
|
getargs(x, 0, 0, _("secret takes no arguments"))
|
|
|
|
target = phases.secret
|
|
|
|
return _phase(repo, subset, target)
|
|
|
|
|
2016-08-07 11:46:12 +03:00
|
|
|
def parentspec(repo, subset, x, n, order):
|
2011-04-30 19:43:04 +04:00
|
|
|
"""``set^0``
|
|
|
|
The set.
|
|
|
|
``set^1`` (or ``set^``), ``set^2``
|
|
|
|
First or second parent, respectively, of all changesets in set.
|
|
|
|
"""
|
|
|
|
try:
|
|
|
|
n = int(n[1])
|
2011-04-30 20:25:45 +04:00
|
|
|
if n not in (0, 1, 2):
|
2011-04-30 19:43:04 +04:00
|
|
|
raise ValueError
|
2011-07-12 21:35:03 +04:00
|
|
|
except (TypeError, ValueError):
|
2011-04-30 19:43:04 +04:00
|
|
|
raise error.ParseError(_("^ expects a number 0, 1, or 2"))
|
|
|
|
ps = set()
|
|
|
|
cl = repo.changelog
|
2014-10-17 10:15:06 +04:00
|
|
|
for r in getset(repo, fullreposet(repo), x):
|
2011-04-30 19:43:04 +04:00
|
|
|
if n == 0:
|
|
|
|
ps.add(r)
|
|
|
|
elif n == 1:
|
|
|
|
ps.add(cl.parentrevs(r)[0])
|
|
|
|
elif n == 2:
|
|
|
|
parents = cl.parentrevs(r)
|
2016-10-14 17:33:00 +03:00
|
|
|
if parents[1] != node.nullrev:
|
2011-04-30 19:43:04 +04:00
|
|
|
ps.add(parents[1])
|
2014-01-25 04:57:44 +04:00
|
|
|
return subset & ps
|
2011-04-30 19:43:04 +04:00
|
|
|
|
2015-12-29 17:58:30 +03:00
|
|
|
@predicate('present(set)', safe=True)
|
2010-08-13 20:11:41 +04:00
|
|
|
def present(repo, subset, x):
|
2015-12-29 17:58:30 +03:00
|
|
|
"""An empty set, if any revision in set isn't found; otherwise,
|
2010-10-23 21:21:51 +04:00
|
|
|
all revisions in set.
|
2012-05-16 12:02:30 +04:00
|
|
|
|
|
|
|
If any of specified revisions is not present in the local repository,
|
|
|
|
the query is normally aborted. But this predicate allows the query
|
|
|
|
to continue even in such cases.
|
2010-10-23 21:21:51 +04:00
|
|
|
"""
|
2010-08-13 20:11:41 +04:00
|
|
|
try:
|
|
|
|
return getset(repo, subset, x)
|
|
|
|
except error.RepoLookupError:
|
2014-10-06 21:41:43 +04:00
|
|
|
return baseset()
|
2010-08-13 20:11:41 +04:00
|
|
|
|
2015-05-19 17:26:25 +03:00
|
|
|
# for internal use
|
2015-12-29 17:58:30 +03:00
|
|
|
@predicate('_notpublic', safe=True)
|
2015-04-25 00:30:30 +03:00
|
|
|
def _notpublic(repo, subset, x):
|
2015-05-19 17:29:20 +03:00
|
|
|
getargs(x, 0, 0, "_notpublic takes no arguments")
|
2015-06-16 02:16:02 +03:00
|
|
|
repo._phasecache.loadphaserevs(repo) # ensure phase's sets are loaded
|
2015-04-25 00:30:30 +03:00
|
|
|
if repo._phasecache._phasesets:
|
|
|
|
s = set()
|
|
|
|
for u in repo._phasecache._phasesets[1:]:
|
|
|
|
s.update(u)
|
2015-06-11 05:58:27 +03:00
|
|
|
s = baseset(s - repo.changelog.filteredrevs)
|
|
|
|
s.sort()
|
2015-04-25 00:30:30 +03:00
|
|
|
return subset & s
|
|
|
|
else:
|
|
|
|
phase = repo._phasecache.phase
|
|
|
|
target = phases.public
|
|
|
|
condition = lambda r: phase(repo, r) != target
|
2016-02-13 14:05:57 +03:00
|
|
|
return subset.filter(condition, condrepr=('<phase %r>', target),
|
|
|
|
cache=False)
|
2015-04-25 00:30:30 +03:00
|
|
|
|
2015-12-29 17:58:30 +03:00
|
|
|
@predicate('public()', safe=True)
|
2012-01-06 13:04:20 +04:00
|
|
|
def public(repo, subset, x):
|
2015-12-29 17:58:30 +03:00
|
|
|
"""Changeset in public phase."""
|
2012-07-26 08:58:43 +04:00
|
|
|
# i18n: "public" is a keyword
|
2012-01-06 13:04:20 +04:00
|
|
|
getargs(x, 0, 0, _("public takes no arguments"))
|
2014-10-17 04:46:58 +04:00
|
|
|
phase = repo._phasecache.phase
|
|
|
|
target = phases.public
|
|
|
|
condition = lambda r: phase(repo, r) == target
|
2016-02-13 14:05:57 +03:00
|
|
|
return subset.filter(condition, condrepr=('<phase %r>', target),
|
|
|
|
cache=False)
|
2012-01-06 13:04:20 +04:00
|
|
|
|
2015-12-29 17:58:30 +03:00
|
|
|
@predicate('remote([id [,path]])', safe=True)
|
2012-01-20 00:31:05 +04:00
|
|
|
def remote(repo, subset, x):
|
2015-12-29 17:58:30 +03:00
|
|
|
"""Local revision that corresponds to the given identifier in a
|
2012-01-20 00:31:05 +04:00
|
|
|
remote repository, if present. Here, the '.' identifier is a
|
|
|
|
synonym for the current local branch.
|
|
|
|
"""
|
|
|
|
|
2015-08-09 04:36:58 +03:00
|
|
|
from . import hg # avoid start-up nasties
|
2012-01-20 00:31:05 +04:00
|
|
|
# i18n: "remote" is a keyword
|
2015-11-30 22:30:16 +03:00
|
|
|
l = getargs(x, 0, 2, _("remote takes zero, one, or two arguments"))
|
2012-01-20 00:31:05 +04:00
|
|
|
|
|
|
|
q = '.'
|
|
|
|
if len(l) > 0:
|
|
|
|
# i18n: "remote" is a keyword
|
|
|
|
q = getstring(l[0], _("remote requires a string id"))
|
|
|
|
if q == '.':
|
|
|
|
q = repo['.'].branch()
|
|
|
|
|
|
|
|
dest = ''
|
|
|
|
if len(l) > 1:
|
|
|
|
# i18n: "remote" is a keyword
|
|
|
|
dest = getstring(l[1], _("remote requires a repository path"))
|
|
|
|
dest = repo.ui.expandpath(dest or 'default')
|
|
|
|
dest, branches = hg.parseurl(dest)
|
|
|
|
revs, checkout = hg.addbranchrevs(repo, repo, branches, [])
|
|
|
|
if revs:
|
|
|
|
revs = [repo.lookup(rev) for rev in revs]
|
|
|
|
other = hg.peer(repo, {}, dest)
|
|
|
|
n = other.lookup(q)
|
|
|
|
if n in repo:
|
|
|
|
r = repo[n].rev()
|
2012-01-27 17:29:58 +04:00
|
|
|
if r in subset:
|
2014-01-21 23:39:26 +04:00
|
|
|
return baseset([r])
|
2014-10-06 21:41:43 +04:00
|
|
|
return baseset()
|
2012-01-20 00:31:05 +04:00
|
|
|
|
2015-12-29 17:58:30 +03:00
|
|
|
@predicate('removes(pattern)', safe=True)
|
2011-04-08 18:47:58 +04:00
|
|
|
def removes(repo, subset, x):
|
2015-12-29 17:58:30 +03:00
|
|
|
"""Changesets which remove files matching pattern.
|
2014-01-17 18:55:11 +04:00
|
|
|
|
|
|
|
The pattern without explicit kind like ``glob:`` is expected to be
|
|
|
|
relative to the current directory and match against a file or a
|
|
|
|
directory.
|
2011-04-08 18:47:58 +04:00
|
|
|
"""
|
|
|
|
# i18n: "removes" is a keyword
|
|
|
|
pat = getstring(x, _("removes requires a pattern"))
|
|
|
|
return checkstatus(repo, subset, pat, 2)
|
|
|
|
|
2015-12-29 17:58:30 +03:00
|
|
|
@predicate('rev(number)', safe=True)
|
2011-04-08 18:47:58 +04:00
|
|
|
def rev(repo, subset, x):
|
2015-12-29 17:58:30 +03:00
|
|
|
"""Revision with the given numeric identifier.
|
2011-04-08 18:47:58 +04:00
|
|
|
"""
|
|
|
|
# i18n: "rev" is a keyword
|
|
|
|
l = getargs(x, 1, 1, _("rev requires one argument"))
|
|
|
|
try:
|
|
|
|
# i18n: "rev" is a keyword
|
|
|
|
l = int(getstring(l[0], _("rev requires a number")))
|
2011-07-12 21:35:03 +04:00
|
|
|
except (TypeError, ValueError):
|
2011-04-08 18:47:58 +04:00
|
|
|
# i18n: "rev" is a keyword
|
|
|
|
raise error.ParseError(_("rev expects a number"))
|
2015-02-04 15:37:06 +03:00
|
|
|
if l not in repo.changelog and l != node.nullrev:
|
2014-10-19 11:48:33 +04:00
|
|
|
return baseset()
|
2014-09-17 22:00:09 +04:00
|
|
|
return subset & baseset([l])
|
2011-04-08 18:47:58 +04:00
|
|
|
|
2015-12-29 17:58:30 +03:00
|
|
|
@predicate('matching(revision [, field])', safe=True)
|
revset: add "matching" keyword
This keyword can be used to find revisions that "match" one or more fields of a
given set of revisions.
A revision matches another if all the selected fields (description, author,
branch, date, files, phase, parents, substate, user, summary and/or metadata)
match the corresponding values of those fields on the source revision.
By default this keyword looks for revisions that whose metadata match
(description, author and date) making it ideal to look for duplicate revisions.
matching takes 2 arguments (the second being optional):
1.- rev: a revset represeting a _single_ revision (e.g. tip, ., p1(.), etc)
2.- [field(s) to match]: an optional string containing the field or fields
(separated by spaces) to match.
Valid fields are most regular context fields and some special fields:
* regular fields:
- description, author, branch, date, files, phase, parents,
substate, user.
Note that author and user are synonyms.
* special fields: summary, metadata.
- summary: matches the first line of the description.
- metatadata: It is equivalent to matching 'description user date'
(i.e. it matches the main metadata fields).
Examples:
1.- Look for revisions with the same metadata (author, description and date)
as the 11th revision:
hg log -r "matching(11)"
2.- Look for revisions with the same description as the 11th revision:
hg log -r "matching(11, description)"
3.- Look for revisions with the same 'summary' (i.e. same first line on their
description) as the 11th revision:
hg log -r "matching(11, summary)"
4.- Look for revisions with the same author as the current revision:
hg log -r "matching(., author)"
You could use 'user' rather than 'author' to get the same result.
5.- Look for revisions with the same description _AND_ author as the tip of the
repository:
hg log -r "matching(tip, 'author description')"
6.- Look for revisions touching the same files as the parent of the tip of the
repository
hg log -r "matching(p1(tip), files)"
7.- Look for revisions whose subrepos are on the same state as the tip of the
repository or its parent
hg log -r "matching(p1(tip):tip, substate)"
8.- Look for revisions whose author and subrepo states both match those of any
of the revisions on the stable branch:
hg log -r "matching(branch(stable), 'author substate')"
2012-04-01 16:12:14 +04:00
|
|
|
def matching(repo, subset, x):
|
2015-12-29 17:58:30 +03:00
|
|
|
"""Changesets in which a given set of fields match the set of fields in the
|
revset: add "matching" keyword
This keyword can be used to find revisions that "match" one or more fields of a
given set of revisions.
A revision matches another if all the selected fields (description, author,
branch, date, files, phase, parents, substate, user, summary and/or metadata)
match the corresponding values of those fields on the source revision.
By default this keyword looks for revisions that whose metadata match
(description, author and date) making it ideal to look for duplicate revisions.
matching takes 2 arguments (the second being optional):
1.- rev: a revset represeting a _single_ revision (e.g. tip, ., p1(.), etc)
2.- [field(s) to match]: an optional string containing the field or fields
(separated by spaces) to match.
Valid fields are most regular context fields and some special fields:
* regular fields:
- description, author, branch, date, files, phase, parents,
substate, user.
Note that author and user are synonyms.
* special fields: summary, metadata.
- summary: matches the first line of the description.
- metatadata: It is equivalent to matching 'description user date'
(i.e. it matches the main metadata fields).
Examples:
1.- Look for revisions with the same metadata (author, description and date)
as the 11th revision:
hg log -r "matching(11)"
2.- Look for revisions with the same description as the 11th revision:
hg log -r "matching(11, description)"
3.- Look for revisions with the same 'summary' (i.e. same first line on their
description) as the 11th revision:
hg log -r "matching(11, summary)"
4.- Look for revisions with the same author as the current revision:
hg log -r "matching(., author)"
You could use 'user' rather than 'author' to get the same result.
5.- Look for revisions with the same description _AND_ author as the tip of the
repository:
hg log -r "matching(tip, 'author description')"
6.- Look for revisions touching the same files as the parent of the tip of the
repository
hg log -r "matching(p1(tip), files)"
7.- Look for revisions whose subrepos are on the same state as the tip of the
repository or its parent
hg log -r "matching(p1(tip):tip, substate)"
8.- Look for revisions whose author and subrepo states both match those of any
of the revisions on the stable branch:
hg log -r "matching(branch(stable), 'author substate')"
2012-04-01 16:12:14 +04:00
|
|
|
selected revision or set.
|
2012-04-26 16:32:48 +04:00
|
|
|
|
revset: add "matching" keyword
This keyword can be used to find revisions that "match" one or more fields of a
given set of revisions.
A revision matches another if all the selected fields (description, author,
branch, date, files, phase, parents, substate, user, summary and/or metadata)
match the corresponding values of those fields on the source revision.
By default this keyword looks for revisions that whose metadata match
(description, author and date) making it ideal to look for duplicate revisions.
matching takes 2 arguments (the second being optional):
1.- rev: a revset represeting a _single_ revision (e.g. tip, ., p1(.), etc)
2.- [field(s) to match]: an optional string containing the field or fields
(separated by spaces) to match.
Valid fields are most regular context fields and some special fields:
* regular fields:
- description, author, branch, date, files, phase, parents,
substate, user.
Note that author and user are synonyms.
* special fields: summary, metadata.
- summary: matches the first line of the description.
- metatadata: It is equivalent to matching 'description user date'
(i.e. it matches the main metadata fields).
Examples:
1.- Look for revisions with the same metadata (author, description and date)
as the 11th revision:
hg log -r "matching(11)"
2.- Look for revisions with the same description as the 11th revision:
hg log -r "matching(11, description)"
3.- Look for revisions with the same 'summary' (i.e. same first line on their
description) as the 11th revision:
hg log -r "matching(11, summary)"
4.- Look for revisions with the same author as the current revision:
hg log -r "matching(., author)"
You could use 'user' rather than 'author' to get the same result.
5.- Look for revisions with the same description _AND_ author as the tip of the
repository:
hg log -r "matching(tip, 'author description')"
6.- Look for revisions touching the same files as the parent of the tip of the
repository
hg log -r "matching(p1(tip), files)"
7.- Look for revisions whose subrepos are on the same state as the tip of the
repository or its parent
hg log -r "matching(p1(tip):tip, substate)"
8.- Look for revisions whose author and subrepo states both match those of any
of the revisions on the stable branch:
hg log -r "matching(branch(stable), 'author substate')"
2012-04-01 16:12:14 +04:00
|
|
|
To match more than one field pass the list of fields to match separated
|
2012-04-26 16:32:48 +04:00
|
|
|
by spaces (e.g. ``author description``).
|
|
|
|
|
|
|
|
Valid fields are most regular revision fields and some special fields.
|
|
|
|
|
|
|
|
Regular revision fields are ``description``, ``author``, ``branch``,
|
2012-06-14 01:32:58 +04:00
|
|
|
``date``, ``files``, ``phase``, ``parents``, ``substate``, ``user``
|
|
|
|
and ``diff``.
|
|
|
|
Note that ``author`` and ``user`` are synonyms. ``diff`` refers to the
|
|
|
|
contents of the revision. Two revisions matching their ``diff`` will
|
|
|
|
also match their ``files``.
|
2012-04-26 16:32:48 +04:00
|
|
|
|
|
|
|
Special fields are ``summary`` and ``metadata``:
|
|
|
|
``summary`` matches the first line of the description.
|
2012-05-10 22:17:05 +04:00
|
|
|
``metadata`` is equivalent to matching ``description user date``
|
2012-04-26 16:32:48 +04:00
|
|
|
(i.e. it matches the main metadata fields).
|
|
|
|
|
|
|
|
``metadata`` is the default field which is used when no fields are
|
|
|
|
specified. You can match more than one field at a time.
|
revset: add "matching" keyword
This keyword can be used to find revisions that "match" one or more fields of a
given set of revisions.
A revision matches another if all the selected fields (description, author,
branch, date, files, phase, parents, substate, user, summary and/or metadata)
match the corresponding values of those fields on the source revision.
By default this keyword looks for revisions that whose metadata match
(description, author and date) making it ideal to look for duplicate revisions.
matching takes 2 arguments (the second being optional):
1.- rev: a revset represeting a _single_ revision (e.g. tip, ., p1(.), etc)
2.- [field(s) to match]: an optional string containing the field or fields
(separated by spaces) to match.
Valid fields are most regular context fields and some special fields:
* regular fields:
- description, author, branch, date, files, phase, parents,
substate, user.
Note that author and user are synonyms.
* special fields: summary, metadata.
- summary: matches the first line of the description.
- metatadata: It is equivalent to matching 'description user date'
(i.e. it matches the main metadata fields).
Examples:
1.- Look for revisions with the same metadata (author, description and date)
as the 11th revision:
hg log -r "matching(11)"
2.- Look for revisions with the same description as the 11th revision:
hg log -r "matching(11, description)"
3.- Look for revisions with the same 'summary' (i.e. same first line on their
description) as the 11th revision:
hg log -r "matching(11, summary)"
4.- Look for revisions with the same author as the current revision:
hg log -r "matching(., author)"
You could use 'user' rather than 'author' to get the same result.
5.- Look for revisions with the same description _AND_ author as the tip of the
repository:
hg log -r "matching(tip, 'author description')"
6.- Look for revisions touching the same files as the parent of the tip of the
repository
hg log -r "matching(p1(tip), files)"
7.- Look for revisions whose subrepos are on the same state as the tip of the
repository or its parent
hg log -r "matching(p1(tip):tip, substate)"
8.- Look for revisions whose author and subrepo states both match those of any
of the revisions on the stable branch:
hg log -r "matching(branch(stable), 'author substate')"
2012-04-01 16:12:14 +04:00
|
|
|
"""
|
2012-07-26 08:58:43 +04:00
|
|
|
# i18n: "matching" is a keyword
|
revset: add "matching" keyword
This keyword can be used to find revisions that "match" one or more fields of a
given set of revisions.
A revision matches another if all the selected fields (description, author,
branch, date, files, phase, parents, substate, user, summary and/or metadata)
match the corresponding values of those fields on the source revision.
By default this keyword looks for revisions that whose metadata match
(description, author and date) making it ideal to look for duplicate revisions.
matching takes 2 arguments (the second being optional):
1.- rev: a revset represeting a _single_ revision (e.g. tip, ., p1(.), etc)
2.- [field(s) to match]: an optional string containing the field or fields
(separated by spaces) to match.
Valid fields are most regular context fields and some special fields:
* regular fields:
- description, author, branch, date, files, phase, parents,
substate, user.
Note that author and user are synonyms.
* special fields: summary, metadata.
- summary: matches the first line of the description.
- metatadata: It is equivalent to matching 'description user date'
(i.e. it matches the main metadata fields).
Examples:
1.- Look for revisions with the same metadata (author, description and date)
as the 11th revision:
hg log -r "matching(11)"
2.- Look for revisions with the same description as the 11th revision:
hg log -r "matching(11, description)"
3.- Look for revisions with the same 'summary' (i.e. same first line on their
description) as the 11th revision:
hg log -r "matching(11, summary)"
4.- Look for revisions with the same author as the current revision:
hg log -r "matching(., author)"
You could use 'user' rather than 'author' to get the same result.
5.- Look for revisions with the same description _AND_ author as the tip of the
repository:
hg log -r "matching(tip, 'author description')"
6.- Look for revisions touching the same files as the parent of the tip of the
repository
hg log -r "matching(p1(tip), files)"
7.- Look for revisions whose subrepos are on the same state as the tip of the
repository or its parent
hg log -r "matching(p1(tip):tip, substate)"
8.- Look for revisions whose author and subrepo states both match those of any
of the revisions on the stable branch:
hg log -r "matching(branch(stable), 'author substate')"
2012-04-01 16:12:14 +04:00
|
|
|
l = getargs(x, 1, 2, _("matching takes 1 or 2 arguments"))
|
|
|
|
|
2014-10-17 10:15:35 +04:00
|
|
|
revs = getset(repo, fullreposet(repo), l[0])
|
revset: add "matching" keyword
This keyword can be used to find revisions that "match" one or more fields of a
given set of revisions.
A revision matches another if all the selected fields (description, author,
branch, date, files, phase, parents, substate, user, summary and/or metadata)
match the corresponding values of those fields on the source revision.
By default this keyword looks for revisions that whose metadata match
(description, author and date) making it ideal to look for duplicate revisions.
matching takes 2 arguments (the second being optional):
1.- rev: a revset represeting a _single_ revision (e.g. tip, ., p1(.), etc)
2.- [field(s) to match]: an optional string containing the field or fields
(separated by spaces) to match.
Valid fields are most regular context fields and some special fields:
* regular fields:
- description, author, branch, date, files, phase, parents,
substate, user.
Note that author and user are synonyms.
* special fields: summary, metadata.
- summary: matches the first line of the description.
- metatadata: It is equivalent to matching 'description user date'
(i.e. it matches the main metadata fields).
Examples:
1.- Look for revisions with the same metadata (author, description and date)
as the 11th revision:
hg log -r "matching(11)"
2.- Look for revisions with the same description as the 11th revision:
hg log -r "matching(11, description)"
3.- Look for revisions with the same 'summary' (i.e. same first line on their
description) as the 11th revision:
hg log -r "matching(11, summary)"
4.- Look for revisions with the same author as the current revision:
hg log -r "matching(., author)"
You could use 'user' rather than 'author' to get the same result.
5.- Look for revisions with the same description _AND_ author as the tip of the
repository:
hg log -r "matching(tip, 'author description')"
6.- Look for revisions touching the same files as the parent of the tip of the
repository
hg log -r "matching(p1(tip), files)"
7.- Look for revisions whose subrepos are on the same state as the tip of the
repository or its parent
hg log -r "matching(p1(tip):tip, substate)"
8.- Look for revisions whose author and subrepo states both match those of any
of the revisions on the stable branch:
hg log -r "matching(branch(stable), 'author substate')"
2012-04-01 16:12:14 +04:00
|
|
|
|
|
|
|
fieldlist = ['metadata']
|
|
|
|
if len(l) > 1:
|
|
|
|
fieldlist = getstring(l[1],
|
2012-07-26 08:58:43 +04:00
|
|
|
# i18n: "matching" is a keyword
|
revset: add "matching" keyword
This keyword can be used to find revisions that "match" one or more fields of a
given set of revisions.
A revision matches another if all the selected fields (description, author,
branch, date, files, phase, parents, substate, user, summary and/or metadata)
match the corresponding values of those fields on the source revision.
By default this keyword looks for revisions that whose metadata match
(description, author and date) making it ideal to look for duplicate revisions.
matching takes 2 arguments (the second being optional):
1.- rev: a revset represeting a _single_ revision (e.g. tip, ., p1(.), etc)
2.- [field(s) to match]: an optional string containing the field or fields
(separated by spaces) to match.
Valid fields are most regular context fields and some special fields:
* regular fields:
- description, author, branch, date, files, phase, parents,
substate, user.
Note that author and user are synonyms.
* special fields: summary, metadata.
- summary: matches the first line of the description.
- metatadata: It is equivalent to matching 'description user date'
(i.e. it matches the main metadata fields).
Examples:
1.- Look for revisions with the same metadata (author, description and date)
as the 11th revision:
hg log -r "matching(11)"
2.- Look for revisions with the same description as the 11th revision:
hg log -r "matching(11, description)"
3.- Look for revisions with the same 'summary' (i.e. same first line on their
description) as the 11th revision:
hg log -r "matching(11, summary)"
4.- Look for revisions with the same author as the current revision:
hg log -r "matching(., author)"
You could use 'user' rather than 'author' to get the same result.
5.- Look for revisions with the same description _AND_ author as the tip of the
repository:
hg log -r "matching(tip, 'author description')"
6.- Look for revisions touching the same files as the parent of the tip of the
repository
hg log -r "matching(p1(tip), files)"
7.- Look for revisions whose subrepos are on the same state as the tip of the
repository or its parent
hg log -r "matching(p1(tip):tip, substate)"
8.- Look for revisions whose author and subrepo states both match those of any
of the revisions on the stable branch:
hg log -r "matching(branch(stable), 'author substate')"
2012-04-01 16:12:14 +04:00
|
|
|
_("matching requires a string "
|
|
|
|
"as its second argument")).split()
|
|
|
|
|
2012-06-14 01:32:58 +04:00
|
|
|
# Make sure that there are no repeated fields,
|
|
|
|
# expand the 'special' 'metadata' field type
|
|
|
|
# and check the 'files' whenever we check the 'diff'
|
revset: add "matching" keyword
This keyword can be used to find revisions that "match" one or more fields of a
given set of revisions.
A revision matches another if all the selected fields (description, author,
branch, date, files, phase, parents, substate, user, summary and/or metadata)
match the corresponding values of those fields on the source revision.
By default this keyword looks for revisions that whose metadata match
(description, author and date) making it ideal to look for duplicate revisions.
matching takes 2 arguments (the second being optional):
1.- rev: a revset represeting a _single_ revision (e.g. tip, ., p1(.), etc)
2.- [field(s) to match]: an optional string containing the field or fields
(separated by spaces) to match.
Valid fields are most regular context fields and some special fields:
* regular fields:
- description, author, branch, date, files, phase, parents,
substate, user.
Note that author and user are synonyms.
* special fields: summary, metadata.
- summary: matches the first line of the description.
- metatadata: It is equivalent to matching 'description user date'
(i.e. it matches the main metadata fields).
Examples:
1.- Look for revisions with the same metadata (author, description and date)
as the 11th revision:
hg log -r "matching(11)"
2.- Look for revisions with the same description as the 11th revision:
hg log -r "matching(11, description)"
3.- Look for revisions with the same 'summary' (i.e. same first line on their
description) as the 11th revision:
hg log -r "matching(11, summary)"
4.- Look for revisions with the same author as the current revision:
hg log -r "matching(., author)"
You could use 'user' rather than 'author' to get the same result.
5.- Look for revisions with the same description _AND_ author as the tip of the
repository:
hg log -r "matching(tip, 'author description')"
6.- Look for revisions touching the same files as the parent of the tip of the
repository
hg log -r "matching(p1(tip), files)"
7.- Look for revisions whose subrepos are on the same state as the tip of the
repository or its parent
hg log -r "matching(p1(tip):tip, substate)"
8.- Look for revisions whose author and subrepo states both match those of any
of the revisions on the stable branch:
hg log -r "matching(branch(stable), 'author substate')"
2012-04-01 16:12:14 +04:00
|
|
|
fields = []
|
|
|
|
for field in fieldlist:
|
|
|
|
if field == 'metadata':
|
|
|
|
fields += ['user', 'description', 'date']
|
2012-06-14 01:32:58 +04:00
|
|
|
elif field == 'diff':
|
|
|
|
# a revision matching the diff must also match the files
|
|
|
|
# since matching the diff is very costly, make sure to
|
|
|
|
# also match the files first
|
|
|
|
fields += ['files', 'diff']
|
revset: add "matching" keyword
This keyword can be used to find revisions that "match" one or more fields of a
given set of revisions.
A revision matches another if all the selected fields (description, author,
branch, date, files, phase, parents, substate, user, summary and/or metadata)
match the corresponding values of those fields on the source revision.
By default this keyword looks for revisions that whose metadata match
(description, author and date) making it ideal to look for duplicate revisions.
matching takes 2 arguments (the second being optional):
1.- rev: a revset represeting a _single_ revision (e.g. tip, ., p1(.), etc)
2.- [field(s) to match]: an optional string containing the field or fields
(separated by spaces) to match.
Valid fields are most regular context fields and some special fields:
* regular fields:
- description, author, branch, date, files, phase, parents,
substate, user.
Note that author and user are synonyms.
* special fields: summary, metadata.
- summary: matches the first line of the description.
- metatadata: It is equivalent to matching 'description user date'
(i.e. it matches the main metadata fields).
Examples:
1.- Look for revisions with the same metadata (author, description and date)
as the 11th revision:
hg log -r "matching(11)"
2.- Look for revisions with the same description as the 11th revision:
hg log -r "matching(11, description)"
3.- Look for revisions with the same 'summary' (i.e. same first line on their
description) as the 11th revision:
hg log -r "matching(11, summary)"
4.- Look for revisions with the same author as the current revision:
hg log -r "matching(., author)"
You could use 'user' rather than 'author' to get the same result.
5.- Look for revisions with the same description _AND_ author as the tip of the
repository:
hg log -r "matching(tip, 'author description')"
6.- Look for revisions touching the same files as the parent of the tip of the
repository
hg log -r "matching(p1(tip), files)"
7.- Look for revisions whose subrepos are on the same state as the tip of the
repository or its parent
hg log -r "matching(p1(tip):tip, substate)"
8.- Look for revisions whose author and subrepo states both match those of any
of the revisions on the stable branch:
hg log -r "matching(branch(stable), 'author substate')"
2012-04-01 16:12:14 +04:00
|
|
|
else:
|
|
|
|
if field == 'author':
|
|
|
|
field = 'user'
|
|
|
|
fields.append(field)
|
|
|
|
fields = set(fields)
|
2012-04-13 15:35:45 +04:00
|
|
|
if 'summary' in fields and 'description' in fields:
|
|
|
|
# If a revision matches its description it also matches its summary
|
|
|
|
fields.discard('summary')
|
revset: add "matching" keyword
This keyword can be used to find revisions that "match" one or more fields of a
given set of revisions.
A revision matches another if all the selected fields (description, author,
branch, date, files, phase, parents, substate, user, summary and/or metadata)
match the corresponding values of those fields on the source revision.
By default this keyword looks for revisions that whose metadata match
(description, author and date) making it ideal to look for duplicate revisions.
matching takes 2 arguments (the second being optional):
1.- rev: a revset represeting a _single_ revision (e.g. tip, ., p1(.), etc)
2.- [field(s) to match]: an optional string containing the field or fields
(separated by spaces) to match.
Valid fields are most regular context fields and some special fields:
* regular fields:
- description, author, branch, date, files, phase, parents,
substate, user.
Note that author and user are synonyms.
* special fields: summary, metadata.
- summary: matches the first line of the description.
- metatadata: It is equivalent to matching 'description user date'
(i.e. it matches the main metadata fields).
Examples:
1.- Look for revisions with the same metadata (author, description and date)
as the 11th revision:
hg log -r "matching(11)"
2.- Look for revisions with the same description as the 11th revision:
hg log -r "matching(11, description)"
3.- Look for revisions with the same 'summary' (i.e. same first line on their
description) as the 11th revision:
hg log -r "matching(11, summary)"
4.- Look for revisions with the same author as the current revision:
hg log -r "matching(., author)"
You could use 'user' rather than 'author' to get the same result.
5.- Look for revisions with the same description _AND_ author as the tip of the
repository:
hg log -r "matching(tip, 'author description')"
6.- Look for revisions touching the same files as the parent of the tip of the
repository
hg log -r "matching(p1(tip), files)"
7.- Look for revisions whose subrepos are on the same state as the tip of the
repository or its parent
hg log -r "matching(p1(tip):tip, substate)"
8.- Look for revisions whose author and subrepo states both match those of any
of the revisions on the stable branch:
hg log -r "matching(branch(stable), 'author substate')"
2012-04-01 16:12:14 +04:00
|
|
|
|
|
|
|
# We may want to match more than one field
|
revset: speedup matching() by first matching fields that take less time to
match
This patch sorts the fields that are passed to the matching function so that it
always starts by matching those fields that take less time to match.
Not all fields take the same amount of time to match. I've done several
measurements running the following command:
hg --time log -r "matching(1, field)"
on the mercurial repository, and where 'field' was each one of the fields
accepted by match. In order to avoid the print overhead (which could be
different for different fields, given the different number of matches) I used a
modified version of the matching() function which always returns no matches.
These tests showed that different fields take wildly different amounts of time
to match. Particulary the substate field takes up to 25 seconds to match on my
machine, compared to the 0.3 seconds that takes to match the phase field or the
2 seconds (approx) that takes to match most fields. With this patch, matching
both the phase and the substate of a revision takes the same amount of time as
matching the phase.
The field match order introduced by this patch is as follows:
phase, parents, user, date, branch, summary, files, description, substate
An extra nice thing about this patch is that it makes the match time stable.
2012-04-14 03:41:03 +04:00
|
|
|
# Not all fields take the same amount of time to be matched
|
|
|
|
# Sort the selected fields in order of increasing matching cost
|
2012-04-17 12:33:47 +04:00
|
|
|
fieldorder = ['phase', 'parents', 'user', 'date', 'branch', 'summary',
|
2012-06-14 01:32:58 +04:00
|
|
|
'files', 'description', 'substate', 'diff']
|
revset: speedup matching() by first matching fields that take less time to
match
This patch sorts the fields that are passed to the matching function so that it
always starts by matching those fields that take less time to match.
Not all fields take the same amount of time to match. I've done several
measurements running the following command:
hg --time log -r "matching(1, field)"
on the mercurial repository, and where 'field' was each one of the fields
accepted by match. In order to avoid the print overhead (which could be
different for different fields, given the different number of matches) I used a
modified version of the matching() function which always returns no matches.
These tests showed that different fields take wildly different amounts of time
to match. Particulary the substate field takes up to 25 seconds to match on my
machine, compared to the 0.3 seconds that takes to match the phase field or the
2 seconds (approx) that takes to match most fields. With this patch, matching
both the phase and the substate of a revision takes the same amount of time as
matching the phase.
The field match order introduced by this patch is as follows:
phase, parents, user, date, branch, summary, files, description, substate
An extra nice thing about this patch is that it makes the match time stable.
2012-04-14 03:41:03 +04:00
|
|
|
def fieldkeyfunc(f):
|
|
|
|
try:
|
|
|
|
return fieldorder.index(f)
|
|
|
|
except ValueError:
|
|
|
|
# assume an unknown field is very costly
|
|
|
|
return len(fieldorder)
|
|
|
|
fields = list(fields)
|
|
|
|
fields.sort(key=fieldkeyfunc)
|
|
|
|
|
revset: add "matching" keyword
This keyword can be used to find revisions that "match" one or more fields of a
given set of revisions.
A revision matches another if all the selected fields (description, author,
branch, date, files, phase, parents, substate, user, summary and/or metadata)
match the corresponding values of those fields on the source revision.
By default this keyword looks for revisions that whose metadata match
(description, author and date) making it ideal to look for duplicate revisions.
matching takes 2 arguments (the second being optional):
1.- rev: a revset represeting a _single_ revision (e.g. tip, ., p1(.), etc)
2.- [field(s) to match]: an optional string containing the field or fields
(separated by spaces) to match.
Valid fields are most regular context fields and some special fields:
* regular fields:
- description, author, branch, date, files, phase, parents,
substate, user.
Note that author and user are synonyms.
* special fields: summary, metadata.
- summary: matches the first line of the description.
- metatadata: It is equivalent to matching 'description user date'
(i.e. it matches the main metadata fields).
Examples:
1.- Look for revisions with the same metadata (author, description and date)
as the 11th revision:
hg log -r "matching(11)"
2.- Look for revisions with the same description as the 11th revision:
hg log -r "matching(11, description)"
3.- Look for revisions with the same 'summary' (i.e. same first line on their
description) as the 11th revision:
hg log -r "matching(11, summary)"
4.- Look for revisions with the same author as the current revision:
hg log -r "matching(., author)"
You could use 'user' rather than 'author' to get the same result.
5.- Look for revisions with the same description _AND_ author as the tip of the
repository:
hg log -r "matching(tip, 'author description')"
6.- Look for revisions touching the same files as the parent of the tip of the
repository
hg log -r "matching(p1(tip), files)"
7.- Look for revisions whose subrepos are on the same state as the tip of the
repository or its parent
hg log -r "matching(p1(tip):tip, substate)"
8.- Look for revisions whose author and subrepo states both match those of any
of the revisions on the stable branch:
hg log -r "matching(branch(stable), 'author substate')"
2012-04-01 16:12:14 +04:00
|
|
|
# Each field will be matched with its own "getfield" function
|
|
|
|
# which will be added to the getfieldfuncs array of functions
|
|
|
|
getfieldfuncs = []
|
|
|
|
_funcs = {
|
|
|
|
'user': lambda r: repo[r].user(),
|
|
|
|
'branch': lambda r: repo[r].branch(),
|
|
|
|
'date': lambda r: repo[r].date(),
|
|
|
|
'description': lambda r: repo[r].description(),
|
|
|
|
'files': lambda r: repo[r].files(),
|
|
|
|
'parents': lambda r: repo[r].parents(),
|
|
|
|
'phase': lambda r: repo[r].phase(),
|
|
|
|
'substate': lambda r: repo[r].substate,
|
|
|
|
'summary': lambda r: repo[r].description().splitlines()[0],
|
2012-06-14 01:32:58 +04:00
|
|
|
'diff': lambda r: list(repo[r].diff(git=True),)
|
revset: add "matching" keyword
This keyword can be used to find revisions that "match" one or more fields of a
given set of revisions.
A revision matches another if all the selected fields (description, author,
branch, date, files, phase, parents, substate, user, summary and/or metadata)
match the corresponding values of those fields on the source revision.
By default this keyword looks for revisions that whose metadata match
(description, author and date) making it ideal to look for duplicate revisions.
matching takes 2 arguments (the second being optional):
1.- rev: a revset represeting a _single_ revision (e.g. tip, ., p1(.), etc)
2.- [field(s) to match]: an optional string containing the field or fields
(separated by spaces) to match.
Valid fields are most regular context fields and some special fields:
* regular fields:
- description, author, branch, date, files, phase, parents,
substate, user.
Note that author and user are synonyms.
* special fields: summary, metadata.
- summary: matches the first line of the description.
- metatadata: It is equivalent to matching 'description user date'
(i.e. it matches the main metadata fields).
Examples:
1.- Look for revisions with the same metadata (author, description and date)
as the 11th revision:
hg log -r "matching(11)"
2.- Look for revisions with the same description as the 11th revision:
hg log -r "matching(11, description)"
3.- Look for revisions with the same 'summary' (i.e. same first line on their
description) as the 11th revision:
hg log -r "matching(11, summary)"
4.- Look for revisions with the same author as the current revision:
hg log -r "matching(., author)"
You could use 'user' rather than 'author' to get the same result.
5.- Look for revisions with the same description _AND_ author as the tip of the
repository:
hg log -r "matching(tip, 'author description')"
6.- Look for revisions touching the same files as the parent of the tip of the
repository
hg log -r "matching(p1(tip), files)"
7.- Look for revisions whose subrepos are on the same state as the tip of the
repository or its parent
hg log -r "matching(p1(tip):tip, substate)"
8.- Look for revisions whose author and subrepo states both match those of any
of the revisions on the stable branch:
hg log -r "matching(branch(stable), 'author substate')"
2012-04-01 16:12:14 +04:00
|
|
|
}
|
|
|
|
for info in fields:
|
|
|
|
getfield = _funcs.get(info, None)
|
|
|
|
if getfield is None:
|
|
|
|
raise error.ParseError(
|
2012-07-26 08:58:43 +04:00
|
|
|
# i18n: "matching" is a keyword
|
revset: add "matching" keyword
This keyword can be used to find revisions that "match" one or more fields of a
given set of revisions.
A revision matches another if all the selected fields (description, author,
branch, date, files, phase, parents, substate, user, summary and/or metadata)
match the corresponding values of those fields on the source revision.
By default this keyword looks for revisions that whose metadata match
(description, author and date) making it ideal to look for duplicate revisions.
matching takes 2 arguments (the second being optional):
1.- rev: a revset represeting a _single_ revision (e.g. tip, ., p1(.), etc)
2.- [field(s) to match]: an optional string containing the field or fields
(separated by spaces) to match.
Valid fields are most regular context fields and some special fields:
* regular fields:
- description, author, branch, date, files, phase, parents,
substate, user.
Note that author and user are synonyms.
* special fields: summary, metadata.
- summary: matches the first line of the description.
- metatadata: It is equivalent to matching 'description user date'
(i.e. it matches the main metadata fields).
Examples:
1.- Look for revisions with the same metadata (author, description and date)
as the 11th revision:
hg log -r "matching(11)"
2.- Look for revisions with the same description as the 11th revision:
hg log -r "matching(11, description)"
3.- Look for revisions with the same 'summary' (i.e. same first line on their
description) as the 11th revision:
hg log -r "matching(11, summary)"
4.- Look for revisions with the same author as the current revision:
hg log -r "matching(., author)"
You could use 'user' rather than 'author' to get the same result.
5.- Look for revisions with the same description _AND_ author as the tip of the
repository:
hg log -r "matching(tip, 'author description')"
6.- Look for revisions touching the same files as the parent of the tip of the
repository
hg log -r "matching(p1(tip), files)"
7.- Look for revisions whose subrepos are on the same state as the tip of the
repository or its parent
hg log -r "matching(p1(tip):tip, substate)"
8.- Look for revisions whose author and subrepo states both match those of any
of the revisions on the stable branch:
hg log -r "matching(branch(stable), 'author substate')"
2012-04-01 16:12:14 +04:00
|
|
|
_("unexpected field name passed to matching: %s") % info)
|
|
|
|
getfieldfuncs.append(getfield)
|
|
|
|
# convert the getfield array of functions into a "getinfo" function
|
|
|
|
# which returns an array of field values (or a single value if there
|
|
|
|
# is only one field to match)
|
2012-04-13 15:46:49 +04:00
|
|
|
getinfo = lambda r: [f(r) for f in getfieldfuncs]
|
revset: add "matching" keyword
This keyword can be used to find revisions that "match" one or more fields of a
given set of revisions.
A revision matches another if all the selected fields (description, author,
branch, date, files, phase, parents, substate, user, summary and/or metadata)
match the corresponding values of those fields on the source revision.
By default this keyword looks for revisions that whose metadata match
(description, author and date) making it ideal to look for duplicate revisions.
matching takes 2 arguments (the second being optional):
1.- rev: a revset represeting a _single_ revision (e.g. tip, ., p1(.), etc)
2.- [field(s) to match]: an optional string containing the field or fields
(separated by spaces) to match.
Valid fields are most regular context fields and some special fields:
* regular fields:
- description, author, branch, date, files, phase, parents,
substate, user.
Note that author and user are synonyms.
* special fields: summary, metadata.
- summary: matches the first line of the description.
- metatadata: It is equivalent to matching 'description user date'
(i.e. it matches the main metadata fields).
Examples:
1.- Look for revisions with the same metadata (author, description and date)
as the 11th revision:
hg log -r "matching(11)"
2.- Look for revisions with the same description as the 11th revision:
hg log -r "matching(11, description)"
3.- Look for revisions with the same 'summary' (i.e. same first line on their
description) as the 11th revision:
hg log -r "matching(11, summary)"
4.- Look for revisions with the same author as the current revision:
hg log -r "matching(., author)"
You could use 'user' rather than 'author' to get the same result.
5.- Look for revisions with the same description _AND_ author as the tip of the
repository:
hg log -r "matching(tip, 'author description')"
6.- Look for revisions touching the same files as the parent of the tip of the
repository
hg log -r "matching(p1(tip), files)"
7.- Look for revisions whose subrepos are on the same state as the tip of the
repository or its parent
hg log -r "matching(p1(tip):tip, substate)"
8.- Look for revisions whose author and subrepo states both match those of any
of the revisions on the stable branch:
hg log -r "matching(branch(stable), 'author substate')"
2012-04-01 16:12:14 +04:00
|
|
|
|
2014-02-04 21:14:45 +04:00
|
|
|
def matches(x):
|
|
|
|
for rev in revs:
|
|
|
|
target = getinfo(rev)
|
2012-04-13 15:46:49 +04:00
|
|
|
match = True
|
|
|
|
for n, f in enumerate(getfieldfuncs):
|
2014-02-04 21:14:45 +04:00
|
|
|
if target[n] != f(x):
|
2012-04-13 15:46:49 +04:00
|
|
|
match = False
|
|
|
|
if match:
|
2014-02-04 21:14:45 +04:00
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
2016-02-13 14:05:57 +03:00
|
|
|
return subset.filter(matches, condrepr=('<matching%r %r>', fields, revs))
|
revset: add "matching" keyword
This keyword can be used to find revisions that "match" one or more fields of a
given set of revisions.
A revision matches another if all the selected fields (description, author,
branch, date, files, phase, parents, substate, user, summary and/or metadata)
match the corresponding values of those fields on the source revision.
By default this keyword looks for revisions that whose metadata match
(description, author and date) making it ideal to look for duplicate revisions.
matching takes 2 arguments (the second being optional):
1.- rev: a revset represeting a _single_ revision (e.g. tip, ., p1(.), etc)
2.- [field(s) to match]: an optional string containing the field or fields
(separated by spaces) to match.
Valid fields are most regular context fields and some special fields:
* regular fields:
- description, author, branch, date, files, phase, parents,
substate, user.
Note that author and user are synonyms.
* special fields: summary, metadata.
- summary: matches the first line of the description.
- metatadata: It is equivalent to matching 'description user date'
(i.e. it matches the main metadata fields).
Examples:
1.- Look for revisions with the same metadata (author, description and date)
as the 11th revision:
hg log -r "matching(11)"
2.- Look for revisions with the same description as the 11th revision:
hg log -r "matching(11, description)"
3.- Look for revisions with the same 'summary' (i.e. same first line on their
description) as the 11th revision:
hg log -r "matching(11, summary)"
4.- Look for revisions with the same author as the current revision:
hg log -r "matching(., author)"
You could use 'user' rather than 'author' to get the same result.
5.- Look for revisions with the same description _AND_ author as the tip of the
repository:
hg log -r "matching(tip, 'author description')"
6.- Look for revisions touching the same files as the parent of the tip of the
repository
hg log -r "matching(p1(tip), files)"
7.- Look for revisions whose subrepos are on the same state as the tip of the
repository or its parent
hg log -r "matching(p1(tip):tip, substate)"
8.- Look for revisions whose author and subrepo states both match those of any
of the revisions on the stable branch:
hg log -r "matching(branch(stable), 'author substate')"
2012-04-01 16:12:14 +04:00
|
|
|
|
2016-05-03 07:36:12 +03:00
|
|
|
@predicate('reverse(set)', safe=True, takeorder=True)
|
|
|
|
def reverse(repo, subset, x, order):
|
2015-12-29 17:58:30 +03:00
|
|
|
"""Reverse order of set.
|
2011-04-08 18:47:58 +04:00
|
|
|
"""
|
|
|
|
l = getset(repo, subset, x)
|
2016-05-03 07:36:12 +03:00
|
|
|
if order == defineorder:
|
|
|
|
l.reverse()
|
2011-04-08 18:47:58 +04:00
|
|
|
return l
|
|
|
|
|
2015-12-29 17:58:30 +03:00
|
|
|
@predicate('roots(set)', safe=True)
|
2011-04-08 18:47:58 +04:00
|
|
|
def roots(repo, subset, x):
|
2015-12-29 17:58:30 +03:00
|
|
|
"""Changesets in set with no parent changeset in set.
|
2011-04-08 18:47:58 +04:00
|
|
|
"""
|
2015-01-08 17:46:54 +03:00
|
|
|
s = getset(repo, fullreposet(repo), x)
|
2015-06-22 20:19:12 +03:00
|
|
|
parents = repo.changelog.parentrevs
|
|
|
|
def filter(r):
|
|
|
|
for p in parents(r):
|
|
|
|
if 0 <= p and p in s:
|
|
|
|
return False
|
|
|
|
return True
|
2016-02-13 14:05:57 +03:00
|
|
|
return subset & s.filter(filter, condrepr='<roots>')
|
2011-04-08 18:47:58 +04:00
|
|
|
|
2016-05-14 13:52:00 +03:00
|
|
|
_sortkeyfuncs = {
|
|
|
|
'rev': lambda c: c.rev(),
|
|
|
|
'branch': lambda c: c.branch(),
|
|
|
|
'desc': lambda c: c.description(),
|
|
|
|
'user': lambda c: c.user(),
|
|
|
|
'author': lambda c: c.user(),
|
|
|
|
'date': lambda c: c.date()[0],
|
|
|
|
}
|
|
|
|
|
2016-06-11 04:17:49 +03:00
|
|
|
def _getsortargs(x):
|
|
|
|
"""Parse sort options into (set, [(key, reverse)], opts)"""
|
2016-06-13 20:20:00 +03:00
|
|
|
args = getargsdict(x, 'sort', 'set keys topo.firstbranch')
|
2016-05-24 00:09:50 +03:00
|
|
|
if 'set' not in args:
|
|
|
|
# i18n: "sort" is a keyword
|
|
|
|
raise error.ParseError(_('sort requires one or two arguments'))
|
2010-06-01 20:18:57 +04:00
|
|
|
keys = "rev"
|
2016-05-24 00:09:50 +03:00
|
|
|
if 'keys' in args:
|
2012-07-26 08:58:43 +04:00
|
|
|
# i18n: "sort" is a keyword
|
2016-05-24 00:09:50 +03:00
|
|
|
keys = getstring(args['keys'], _("sort spec must be a string"))
|
2010-06-01 20:18:57 +04:00
|
|
|
|
2016-06-11 04:15:40 +03:00
|
|
|
keyflags = []
|
|
|
|
for k in keys.split():
|
|
|
|
fk = k
|
|
|
|
reverse = (k[0] == '-')
|
|
|
|
if reverse:
|
|
|
|
k = k[1:]
|
|
|
|
if k not in _sortkeyfuncs and k != 'topo':
|
|
|
|
raise error.ParseError(_("unknown sort key %r") % fk)
|
|
|
|
keyflags.append((k, reverse))
|
|
|
|
|
|
|
|
if len(keyflags) > 1 and any(k == 'topo' for k, reverse in keyflags):
|
2016-06-13 20:20:00 +03:00
|
|
|
# i18n: "topo" is a keyword
|
2016-08-01 00:08:26 +03:00
|
|
|
raise error.ParseError(_('topo sort order cannot be combined '
|
|
|
|
'with other sort keys'))
|
2016-06-13 20:20:00 +03:00
|
|
|
|
2016-06-15 15:26:45 +03:00
|
|
|
opts = {}
|
2016-06-13 20:20:00 +03:00
|
|
|
if 'topo.firstbranch' in args:
|
2016-06-11 04:15:40 +03:00
|
|
|
if any(k == 'topo' for k, reverse in keyflags):
|
2016-06-15 15:26:45 +03:00
|
|
|
opts['topo.firstbranch'] = args['topo.firstbranch']
|
2016-06-13 20:20:00 +03:00
|
|
|
else:
|
|
|
|
# i18n: "topo" and "topo.firstbranch" are keywords
|
2016-08-01 00:08:26 +03:00
|
|
|
raise error.ParseError(_('topo.firstbranch can only be used '
|
|
|
|
'when using the topo sort key'))
|
2016-06-13 20:20:00 +03:00
|
|
|
|
2016-06-11 04:17:49 +03:00
|
|
|
return args['set'], keyflags, opts
|
|
|
|
|
2016-05-03 07:36:12 +03:00
|
|
|
@predicate('sort(set[, [-]key... [, ...]])', safe=True, takeorder=True)
|
|
|
|
def sort(repo, subset, x, order):
|
2016-06-11 04:17:49 +03:00
|
|
|
"""Sort set by keys. The default sort order is ascending, specify a key
|
|
|
|
as ``-key`` to sort in descending order.
|
|
|
|
|
|
|
|
The keys can be:
|
|
|
|
|
|
|
|
- ``rev`` for the revision number,
|
|
|
|
- ``branch`` for the branch name,
|
|
|
|
- ``desc`` for the commit message (description),
|
|
|
|
- ``user`` for user name (``author`` can be used as an alias),
|
|
|
|
- ``date`` for the commit date
|
|
|
|
- ``topo`` for a reverse topographical sort
|
|
|
|
|
|
|
|
The ``topo`` sort order cannot be combined with other sort keys. This sort
|
|
|
|
takes one optional argument, ``topo.firstbranch``, which takes a revset that
|
|
|
|
specifies what topographical branches to prioritize in the sort.
|
|
|
|
|
|
|
|
"""
|
|
|
|
s, keyflags, opts = _getsortargs(x)
|
2016-06-15 15:26:45 +03:00
|
|
|
revs = getset(repo, subset, s)
|
|
|
|
|
2016-05-03 07:36:12 +03:00
|
|
|
if not keyflags or order != defineorder:
|
2014-03-14 04:15:21 +04:00
|
|
|
return revs
|
2016-06-11 04:15:40 +03:00
|
|
|
if len(keyflags) == 1 and keyflags[0][0] == "rev":
|
|
|
|
revs.sort(reverse=keyflags[0][1])
|
2014-03-14 04:15:21 +04:00
|
|
|
return revs
|
2016-06-11 04:15:40 +03:00
|
|
|
elif keyflags[0][0] == "topo":
|
2016-06-15 15:26:45 +03:00
|
|
|
firstbranch = ()
|
|
|
|
if 'topo.firstbranch' in opts:
|
|
|
|
firstbranch = getset(repo, subset, opts['topo.firstbranch'])
|
2016-06-13 20:20:00 +03:00
|
|
|
revs = baseset(_toposort(revs, repo.changelog.parentrevs, firstbranch),
|
|
|
|
istopo=True)
|
2016-06-11 04:15:40 +03:00
|
|
|
if keyflags[0][1]:
|
2016-06-13 20:20:00 +03:00
|
|
|
revs.reverse()
|
|
|
|
return revs
|
|
|
|
|
revset: make sort() do dumb multi-pass sorting for multiple keys (issue5218)
Our invert() function was too clever to not take length into account. I could
fix the problem by appending '\xff' as a terminator (opposite to '\0'), but
it turned out to be slower than simple multi-pass sorting.
New implementation is pretty straightforward, which just calls sort() from the
last key. We can do that since Python sort() is guaranteed to be stable. It
doesn't sound nice to call sort() multiple times, but actually it is faster.
That's probably because we have fewer Python codes in hot loop, and can avoid
heavy string and list manipulation.
revset #0: sort(0:10000, 'branch')
0) 0.412753
1) 0.393254
revset #1: sort(0:10000, '-branch')
0) 0.455377
1) 0.389191 85%
revset #2: sort(0:10000, 'date')
0) 0.408082
1) 0.376332 92%
revset #3: sort(0:10000, '-date')
0) 0.406910
1) 0.380498 93%
revset #4: sort(0:10000, 'desc branch user date rev')
0) 0.542996
1) 0.486397 89%
revset #5: sort(0:10000, '-desc -branch -user -date -rev')
0) 0.965032
1) 0.518426 53%
2016-04-23 10:09:30 +03:00
|
|
|
# sort() is guaranteed to be stable
|
|
|
|
ctxs = [repo[r] for r in revs]
|
2016-06-11 04:15:40 +03:00
|
|
|
for k, reverse in reversed(keyflags):
|
|
|
|
ctxs.sort(key=_sortkeyfuncs[k], reverse=reverse)
|
revset: make sort() do dumb multi-pass sorting for multiple keys (issue5218)
Our invert() function was too clever to not take length into account. I could
fix the problem by appending '\xff' as a terminator (opposite to '\0'), but
it turned out to be slower than simple multi-pass sorting.
New implementation is pretty straightforward, which just calls sort() from the
last key. We can do that since Python sort() is guaranteed to be stable. It
doesn't sound nice to call sort() multiple times, but actually it is faster.
That's probably because we have fewer Python codes in hot loop, and can avoid
heavy string and list manipulation.
revset #0: sort(0:10000, 'branch')
0) 0.412753
1) 0.393254
revset #1: sort(0:10000, '-branch')
0) 0.455377
1) 0.389191 85%
revset #2: sort(0:10000, 'date')
0) 0.408082
1) 0.376332 92%
revset #3: sort(0:10000, '-date')
0) 0.406910
1) 0.380498 93%
revset #4: sort(0:10000, 'desc branch user date rev')
0) 0.542996
1) 0.486397 89%
revset #5: sort(0:10000, '-desc -branch -user -date -rev')
0) 0.965032
1) 0.518426 53%
2016-04-23 10:09:30 +03:00
|
|
|
return baseset([c.rev() for c in ctxs])
|
2010-06-01 20:18:57 +04:00
|
|
|
|
2016-06-13 20:20:00 +03:00
|
|
|
def _toposort(revs, parentsfunc, firstbranch=()):
|
2016-06-13 20:20:00 +03:00
|
|
|
"""Yield revisions from heads to roots one (topo) branch at a time.
|
|
|
|
|
|
|
|
This function aims to be used by a graph generator that wishes to minimize
|
|
|
|
the number of parallel branches and their interleaving.
|
|
|
|
|
|
|
|
Example iteration order (numbers show the "true" order in a changelog):
|
|
|
|
|
|
|
|
o 4
|
|
|
|
|
|
|
|
|
o 1
|
|
|
|
|
|
|
|
|
| o 3
|
|
|
|
| |
|
|
|
|
| o 2
|
|
|
|
|/
|
|
|
|
o 0
|
|
|
|
|
|
|
|
Note that the ancestors of merges are understood by the current
|
|
|
|
algorithm to be on the same branch. This means no reordering will
|
|
|
|
occur behind a merge.
|
|
|
|
"""
|
|
|
|
|
|
|
|
### Quick summary of the algorithm
|
|
|
|
#
|
|
|
|
# This function is based around a "retention" principle. We keep revisions
|
|
|
|
# in memory until we are ready to emit a whole branch that immediately
|
|
|
|
# "merges" into an existing one. This reduces the number of parallel
|
|
|
|
# branches with interleaved revisions.
|
|
|
|
#
|
|
|
|
# During iteration revs are split into two groups:
|
|
|
|
# A) revision already emitted
|
|
|
|
# B) revision in "retention". They are stored as different subgroups.
|
|
|
|
#
|
|
|
|
# for each REV, we do the following logic:
|
|
|
|
#
|
|
|
|
# 1) if REV is a parent of (A), we will emit it. If there is a
|
|
|
|
# retention group ((B) above) that is blocked on REV being
|
|
|
|
# available, we emit all the revisions out of that retention
|
|
|
|
# group first.
|
|
|
|
#
|
|
|
|
# 2) else, we'll search for a subgroup in (B) awaiting for REV to be
|
|
|
|
# available, if such subgroup exist, we add REV to it and the subgroup is
|
|
|
|
# now awaiting for REV.parents() to be available.
|
|
|
|
#
|
|
|
|
# 3) finally if no such group existed in (B), we create a new subgroup.
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# To bootstrap the algorithm, we emit the tipmost revision (which
|
|
|
|
# puts it in group (A) from above).
|
|
|
|
|
|
|
|
revs.sort(reverse=True)
|
|
|
|
|
|
|
|
# Set of parents of revision that have been emitted. They can be considered
|
|
|
|
# unblocked as the graph generator is already aware of them so there is no
|
|
|
|
# need to delay the revisions that reference them.
|
|
|
|
#
|
|
|
|
# If someone wants to prioritize a branch over the others, pre-filling this
|
|
|
|
# set will force all other branches to wait until this branch is ready to be
|
|
|
|
# emitted.
|
|
|
|
unblocked = set(firstbranch)
|
|
|
|
|
|
|
|
# list of groups waiting to be displayed, each group is defined by:
|
|
|
|
#
|
|
|
|
# (revs: lists of revs waiting to be displayed,
|
|
|
|
# blocked: set of that cannot be displayed before those in 'revs')
|
|
|
|
#
|
|
|
|
# The second value ('blocked') correspond to parents of any revision in the
|
|
|
|
# group ('revs') that is not itself contained in the group. The main idea
|
|
|
|
# of this algorithm is to delay as much as possible the emission of any
|
|
|
|
# revision. This means waiting for the moment we are about to display
|
|
|
|
# these parents to display the revs in a group.
|
|
|
|
#
|
|
|
|
# This first implementation is smart until it encounters a merge: it will
|
|
|
|
# emit revs as soon as any parent is about to be emitted and can grow an
|
|
|
|
# arbitrary number of revs in 'blocked'. In practice this mean we properly
|
|
|
|
# retains new branches but gives up on any special ordering for ancestors
|
|
|
|
# of merges. The implementation can be improved to handle this better.
|
|
|
|
#
|
|
|
|
# The first subgroup is special. It corresponds to all the revision that
|
|
|
|
# were already emitted. The 'revs' lists is expected to be empty and the
|
|
|
|
# 'blocked' set contains the parents revisions of already emitted revision.
|
|
|
|
#
|
|
|
|
# You could pre-seed the <parents> set of groups[0] to a specific
|
|
|
|
# changesets to select what the first emitted branch should be.
|
|
|
|
groups = [([], unblocked)]
|
|
|
|
pendingheap = []
|
|
|
|
pendingset = set()
|
|
|
|
|
|
|
|
heapq.heapify(pendingheap)
|
|
|
|
heappop = heapq.heappop
|
|
|
|
heappush = heapq.heappush
|
|
|
|
for currentrev in revs:
|
|
|
|
# Heap works with smallest element, we want highest so we invert
|
|
|
|
if currentrev not in pendingset:
|
|
|
|
heappush(pendingheap, -currentrev)
|
|
|
|
pendingset.add(currentrev)
|
|
|
|
# iterates on pending rev until after the current rev have been
|
|
|
|
# processed.
|
|
|
|
rev = None
|
|
|
|
while rev != currentrev:
|
|
|
|
rev = -heappop(pendingheap)
|
|
|
|
pendingset.remove(rev)
|
|
|
|
|
|
|
|
# Seek for a subgroup blocked, waiting for the current revision.
|
|
|
|
matching = [i for i, g in enumerate(groups) if rev in g[1]]
|
|
|
|
|
|
|
|
if matching:
|
|
|
|
# The main idea is to gather together all sets that are blocked
|
|
|
|
# on the same revision.
|
|
|
|
#
|
|
|
|
# Groups are merged when a common blocking ancestor is
|
|
|
|
# observed. For example, given two groups:
|
|
|
|
#
|
|
|
|
# revs [5, 4] waiting for 1
|
|
|
|
# revs [3, 2] waiting for 1
|
|
|
|
#
|
|
|
|
# These two groups will be merged when we process
|
|
|
|
# 1. In theory, we could have merged the groups when
|
|
|
|
# we added 2 to the group it is now in (we could have
|
|
|
|
# noticed the groups were both blocked on 1 then), but
|
|
|
|
# the way it works now makes the algorithm simpler.
|
|
|
|
#
|
|
|
|
# We also always keep the oldest subgroup first. We can
|
|
|
|
# probably improve the behavior by having the longest set
|
|
|
|
# first. That way, graph algorithms could minimise the length
|
|
|
|
# of parallel lines their drawing. This is currently not done.
|
|
|
|
targetidx = matching.pop(0)
|
|
|
|
trevs, tparents = groups[targetidx]
|
|
|
|
for i in matching:
|
|
|
|
gr = groups[i]
|
|
|
|
trevs.extend(gr[0])
|
|
|
|
tparents |= gr[1]
|
|
|
|
# delete all merged subgroups (except the one we kept)
|
|
|
|
# (starting from the last subgroup for performance and
|
|
|
|
# sanity reasons)
|
|
|
|
for i in reversed(matching):
|
|
|
|
del groups[i]
|
|
|
|
else:
|
|
|
|
# This is a new head. We create a new subgroup for it.
|
|
|
|
targetidx = len(groups)
|
|
|
|
groups.append(([], set([rev])))
|
|
|
|
|
|
|
|
gr = groups[targetidx]
|
|
|
|
|
|
|
|
# We now add the current nodes to this subgroups. This is done
|
|
|
|
# after the subgroup merging because all elements from a subgroup
|
|
|
|
# that relied on this rev must precede it.
|
|
|
|
#
|
|
|
|
# we also update the <parents> set to include the parents of the
|
|
|
|
# new nodes.
|
|
|
|
if rev == currentrev: # only display stuff in rev
|
|
|
|
gr[0].append(rev)
|
|
|
|
gr[1].remove(rev)
|
|
|
|
parents = [p for p in parentsfunc(rev) if p > node.nullrev]
|
|
|
|
gr[1].update(parents)
|
|
|
|
for p in parents:
|
|
|
|
if p not in pendingset:
|
|
|
|
pendingset.add(p)
|
|
|
|
heappush(pendingheap, -p)
|
|
|
|
|
|
|
|
# Look for a subgroup to display
|
|
|
|
#
|
|
|
|
# When unblocked is empty (if clause), we were not waiting for any
|
|
|
|
# revisions during the first iteration (if no priority was given) or
|
|
|
|
# if we emitted a whole disconnected set of the graph (reached a
|
|
|
|
# root). In that case we arbitrarily take the oldest known
|
|
|
|
# subgroup. The heuristic could probably be better.
|
|
|
|
#
|
|
|
|
# Otherwise (elif clause) if the subgroup is blocked on
|
|
|
|
# a revision we just emitted, we can safely emit it as
|
|
|
|
# well.
|
|
|
|
if not unblocked:
|
|
|
|
if len(groups) > 1: # display other subset
|
|
|
|
targetidx = 1
|
|
|
|
gr = groups[1]
|
|
|
|
elif not gr[1] & unblocked:
|
|
|
|
gr = None
|
|
|
|
|
|
|
|
if gr is not None:
|
|
|
|
# update the set of awaited revisions with the one from the
|
|
|
|
# subgroup
|
|
|
|
unblocked |= gr[1]
|
|
|
|
# output all revisions in the subgroup
|
|
|
|
for r in gr[0]:
|
|
|
|
yield r
|
|
|
|
# delete the subgroup that you just output
|
|
|
|
# unless it is groups[0] in which case you just empty it.
|
|
|
|
if targetidx:
|
|
|
|
del groups[targetidx]
|
|
|
|
else:
|
|
|
|
gr[0][:] = []
|
|
|
|
# Check if we have some subgroup waiting for revisions we are not going to
|
|
|
|
# iterate over
|
|
|
|
for g in groups:
|
|
|
|
for r in g[0]:
|
|
|
|
yield r
|
|
|
|
|
2015-12-29 17:58:30 +03:00
|
|
|
@predicate('subrepo([pattern])')
|
revset: add the 'subrepo' symbol
This returns the csets where matching subrepos have changed with respect to the
containing repo's first parent. The second parent shouldn't matter, because it
is either syncing up to the first parent (i.e. it hasn't changed from the
current branch's POV), or the merge changed it with respect to the first parent
(which already adds it to the set).
There's already a 'subrepo' fileset, but it is prefixed with 'set:', so there
should be no ambiguity (in code anyway). The only test I see for it is to
revert subrepos named by a glob pattern (in test-subrepo.t, line 58). Since it
doesn't return a tracked file, neither 'log "set:subrepo()"' nor
'files "set:subrepo()"' print anything. Therefore, it seems useful to have a
revset that will return something for log (and can be added to a revsetalias to
be chained with 'file' revsets.)
It might be nice to be able to filter for added, modified and removed
separately, but add/remove should be rare. It might also be nice to be able to
do a 'contains' check, in addition to this mutated check. Maybe it is possible
to get those with the existing 'adds', 'contains', 'modifies' and 'removes' by
teaching them to chase explicit paths into subrepos.
I'm not sure if this should be added to the 'modifies adds removes' line in
revset.optimize() (since it is doing an AMR check on .hgsubstate), or if it is
OK to put into 'safesymbols' (things like 'file' are on the list, and that takes
a regex, among other patterns).
2015-03-25 21:56:54 +03:00
|
|
|
def subrepo(repo, subset, x):
|
2015-12-29 17:58:30 +03:00
|
|
|
"""Changesets that add, modify or remove the given subrepo. If no subrepo
|
revset: add the 'subrepo' symbol
This returns the csets where matching subrepos have changed with respect to the
containing repo's first parent. The second parent shouldn't matter, because it
is either syncing up to the first parent (i.e. it hasn't changed from the
current branch's POV), or the merge changed it with respect to the first parent
(which already adds it to the set).
There's already a 'subrepo' fileset, but it is prefixed with 'set:', so there
should be no ambiguity (in code anyway). The only test I see for it is to
revert subrepos named by a glob pattern (in test-subrepo.t, line 58). Since it
doesn't return a tracked file, neither 'log "set:subrepo()"' nor
'files "set:subrepo()"' print anything. Therefore, it seems useful to have a
revset that will return something for log (and can be added to a revsetalias to
be chained with 'file' revsets.)
It might be nice to be able to filter for added, modified and removed
separately, but add/remove should be rare. It might also be nice to be able to
do a 'contains' check, in addition to this mutated check. Maybe it is possible
to get those with the existing 'adds', 'contains', 'modifies' and 'removes' by
teaching them to chase explicit paths into subrepos.
I'm not sure if this should be added to the 'modifies adds removes' line in
revset.optimize() (since it is doing an AMR check on .hgsubstate), or if it is
OK to put into 'safesymbols' (things like 'file' are on the list, and that takes
a regex, among other patterns).
2015-03-25 21:56:54 +03:00
|
|
|
pattern is named, any subrepo changes are returned.
|
|
|
|
"""
|
|
|
|
# i18n: "subrepo" is a keyword
|
|
|
|
args = getargs(x, 0, 1, _('subrepo takes at most one argument'))
|
2016-02-13 14:13:45 +03:00
|
|
|
pat = None
|
revset: add the 'subrepo' symbol
This returns the csets where matching subrepos have changed with respect to the
containing repo's first parent. The second parent shouldn't matter, because it
is either syncing up to the first parent (i.e. it hasn't changed from the
current branch's POV), or the merge changed it with respect to the first parent
(which already adds it to the set).
There's already a 'subrepo' fileset, but it is prefixed with 'set:', so there
should be no ambiguity (in code anyway). The only test I see for it is to
revert subrepos named by a glob pattern (in test-subrepo.t, line 58). Since it
doesn't return a tracked file, neither 'log "set:subrepo()"' nor
'files "set:subrepo()"' print anything. Therefore, it seems useful to have a
revset that will return something for log (and can be added to a revsetalias to
be chained with 'file' revsets.)
It might be nice to be able to filter for added, modified and removed
separately, but add/remove should be rare. It might also be nice to be able to
do a 'contains' check, in addition to this mutated check. Maybe it is possible
to get those with the existing 'adds', 'contains', 'modifies' and 'removes' by
teaching them to chase explicit paths into subrepos.
I'm not sure if this should be added to the 'modifies adds removes' line in
revset.optimize() (since it is doing an AMR check on .hgsubstate), or if it is
OK to put into 'safesymbols' (things like 'file' are on the list, and that takes
a regex, among other patterns).
2015-03-25 21:56:54 +03:00
|
|
|
if len(args) != 0:
|
|
|
|
pat = getstring(args[0], _("subrepo requires a pattern"))
|
|
|
|
|
|
|
|
m = matchmod.exact(repo.root, repo.root, ['.hgsubstate'])
|
|
|
|
|
|
|
|
def submatches(names):
|
2015-08-23 05:52:18 +03:00
|
|
|
k, p, m = util.stringmatcher(pat)
|
revset: add the 'subrepo' symbol
This returns the csets where matching subrepos have changed with respect to the
containing repo's first parent. The second parent shouldn't matter, because it
is either syncing up to the first parent (i.e. it hasn't changed from the
current branch's POV), or the merge changed it with respect to the first parent
(which already adds it to the set).
There's already a 'subrepo' fileset, but it is prefixed with 'set:', so there
should be no ambiguity (in code anyway). The only test I see for it is to
revert subrepos named by a glob pattern (in test-subrepo.t, line 58). Since it
doesn't return a tracked file, neither 'log "set:subrepo()"' nor
'files "set:subrepo()"' print anything. Therefore, it seems useful to have a
revset that will return something for log (and can be added to a revsetalias to
be chained with 'file' revsets.)
It might be nice to be able to filter for added, modified and removed
separately, but add/remove should be rare. It might also be nice to be able to
do a 'contains' check, in addition to this mutated check. Maybe it is possible
to get those with the existing 'adds', 'contains', 'modifies' and 'removes' by
teaching them to chase explicit paths into subrepos.
I'm not sure if this should be added to the 'modifies adds removes' line in
revset.optimize() (since it is doing an AMR check on .hgsubstate), or if it is
OK to put into 'safesymbols' (things like 'file' are on the list, and that takes
a regex, among other patterns).
2015-03-25 21:56:54 +03:00
|
|
|
for name in names:
|
|
|
|
if m(name):
|
|
|
|
yield name
|
|
|
|
|
|
|
|
def matches(x):
|
|
|
|
c = repo[x]
|
|
|
|
s = repo.status(c.p1().node(), c.node(), match=m)
|
|
|
|
|
2016-02-13 14:13:45 +03:00
|
|
|
if pat is None:
|
revset: add the 'subrepo' symbol
This returns the csets where matching subrepos have changed with respect to the
containing repo's first parent. The second parent shouldn't matter, because it
is either syncing up to the first parent (i.e. it hasn't changed from the
current branch's POV), or the merge changed it with respect to the first parent
(which already adds it to the set).
There's already a 'subrepo' fileset, but it is prefixed with 'set:', so there
should be no ambiguity (in code anyway). The only test I see for it is to
revert subrepos named by a glob pattern (in test-subrepo.t, line 58). Since it
doesn't return a tracked file, neither 'log "set:subrepo()"' nor
'files "set:subrepo()"' print anything. Therefore, it seems useful to have a
revset that will return something for log (and can be added to a revsetalias to
be chained with 'file' revsets.)
It might be nice to be able to filter for added, modified and removed
separately, but add/remove should be rare. It might also be nice to be able to
do a 'contains' check, in addition to this mutated check. Maybe it is possible
to get those with the existing 'adds', 'contains', 'modifies' and 'removes' by
teaching them to chase explicit paths into subrepos.
I'm not sure if this should be added to the 'modifies adds removes' line in
revset.optimize() (since it is doing an AMR check on .hgsubstate), or if it is
OK to put into 'safesymbols' (things like 'file' are on the list, and that takes
a regex, among other patterns).
2015-03-25 21:56:54 +03:00
|
|
|
return s.added or s.modified or s.removed
|
|
|
|
|
|
|
|
if s.added:
|
2015-05-16 21:30:07 +03:00
|
|
|
return any(submatches(c.substate.keys()))
|
revset: add the 'subrepo' symbol
This returns the csets where matching subrepos have changed with respect to the
containing repo's first parent. The second parent shouldn't matter, because it
is either syncing up to the first parent (i.e. it hasn't changed from the
current branch's POV), or the merge changed it with respect to the first parent
(which already adds it to the set).
There's already a 'subrepo' fileset, but it is prefixed with 'set:', so there
should be no ambiguity (in code anyway). The only test I see for it is to
revert subrepos named by a glob pattern (in test-subrepo.t, line 58). Since it
doesn't return a tracked file, neither 'log "set:subrepo()"' nor
'files "set:subrepo()"' print anything. Therefore, it seems useful to have a
revset that will return something for log (and can be added to a revsetalias to
be chained with 'file' revsets.)
It might be nice to be able to filter for added, modified and removed
separately, but add/remove should be rare. It might also be nice to be able to
do a 'contains' check, in addition to this mutated check. Maybe it is possible
to get those with the existing 'adds', 'contains', 'modifies' and 'removes' by
teaching them to chase explicit paths into subrepos.
I'm not sure if this should be added to the 'modifies adds removes' line in
revset.optimize() (since it is doing an AMR check on .hgsubstate), or if it is
OK to put into 'safesymbols' (things like 'file' are on the list, and that takes
a regex, among other patterns).
2015-03-25 21:56:54 +03:00
|
|
|
|
|
|
|
if s.modified:
|
|
|
|
subs = set(c.p1().substate.keys())
|
|
|
|
subs.update(c.substate.keys())
|
|
|
|
|
|
|
|
for path in submatches(subs):
|
|
|
|
if c.p1().substate.get(path) != c.substate.get(path):
|
|
|
|
return True
|
|
|
|
|
|
|
|
if s.removed:
|
2015-05-16 21:30:07 +03:00
|
|
|
return any(submatches(c.p1().substate.keys()))
|
revset: add the 'subrepo' symbol
This returns the csets where matching subrepos have changed with respect to the
containing repo's first parent. The second parent shouldn't matter, because it
is either syncing up to the first parent (i.e. it hasn't changed from the
current branch's POV), or the merge changed it with respect to the first parent
(which already adds it to the set).
There's already a 'subrepo' fileset, but it is prefixed with 'set:', so there
should be no ambiguity (in code anyway). The only test I see for it is to
revert subrepos named by a glob pattern (in test-subrepo.t, line 58). Since it
doesn't return a tracked file, neither 'log "set:subrepo()"' nor
'files "set:subrepo()"' print anything. Therefore, it seems useful to have a
revset that will return something for log (and can be added to a revsetalias to
be chained with 'file' revsets.)
It might be nice to be able to filter for added, modified and removed
separately, but add/remove should be rare. It might also be nice to be able to
do a 'contains' check, in addition to this mutated check. Maybe it is possible
to get those with the existing 'adds', 'contains', 'modifies' and 'removes' by
teaching them to chase explicit paths into subrepos.
I'm not sure if this should be added to the 'modifies adds removes' line in
revset.optimize() (since it is doing an AMR check on .hgsubstate), or if it is
OK to put into 'safesymbols' (things like 'file' are on the list, and that takes
a regex, among other patterns).
2015-03-25 21:56:54 +03:00
|
|
|
|
|
|
|
return False
|
|
|
|
|
2016-02-13 14:05:57 +03:00
|
|
|
return subset.filter(matches, condrepr=('<subrepo %r>', pat))
|
revset: add the 'subrepo' symbol
This returns the csets where matching subrepos have changed with respect to the
containing repo's first parent. The second parent shouldn't matter, because it
is either syncing up to the first parent (i.e. it hasn't changed from the
current branch's POV), or the merge changed it with respect to the first parent
(which already adds it to the set).
There's already a 'subrepo' fileset, but it is prefixed with 'set:', so there
should be no ambiguity (in code anyway). The only test I see for it is to
revert subrepos named by a glob pattern (in test-subrepo.t, line 58). Since it
doesn't return a tracked file, neither 'log "set:subrepo()"' nor
'files "set:subrepo()"' print anything. Therefore, it seems useful to have a
revset that will return something for log (and can be added to a revsetalias to
be chained with 'file' revsets.)
It might be nice to be able to filter for added, modified and removed
separately, but add/remove should be rare. It might also be nice to be able to
do a 'contains' check, in addition to this mutated check. Maybe it is possible
to get those with the existing 'adds', 'contains', 'modifies' and 'removes' by
teaching them to chase explicit paths into subrepos.
I'm not sure if this should be added to the 'modifies adds removes' line in
revset.optimize() (since it is doing an AMR check on .hgsubstate), or if it is
OK to put into 'safesymbols' (things like 'file' are on the list, and that takes
a regex, among other patterns).
2015-03-25 21:56:54 +03:00
|
|
|
|
2012-05-31 02:13:58 +04:00
|
|
|
def _substringmatcher(pattern):
|
2015-08-23 05:52:18 +03:00
|
|
|
kind, pattern, matcher = util.stringmatcher(pattern)
|
2012-05-31 02:13:58 +04:00
|
|
|
if kind == 'literal':
|
|
|
|
matcher = lambda s: pattern in s
|
|
|
|
return kind, pattern, matcher
|
2012-05-31 02:13:33 +04:00
|
|
|
|
2015-12-29 17:58:30 +03:00
|
|
|
@predicate('tag([name])', safe=True)
|
2010-10-10 21:41:36 +04:00
|
|
|
def tag(repo, subset, x):
|
2015-12-29 17:58:30 +03:00
|
|
|
"""The specified tag by name, or all tagged revisions if no name is given.
|
2014-03-25 05:27:40 +04:00
|
|
|
|
|
|
|
If `name` starts with `re:`, the remainder of the name is treated as
|
|
|
|
a regular expression. To match a tag that actually starts with `re:`,
|
|
|
|
use the prefix `literal:`.
|
2010-10-23 21:21:51 +04:00
|
|
|
"""
|
2010-10-23 16:59:19 +04:00
|
|
|
# i18n: "tag" is a keyword
|
2010-10-10 21:41:36 +04:00
|
|
|
args = getargs(x, 0, 1, _("tag takes one or no arguments"))
|
2010-06-04 02:39:40 +04:00
|
|
|
cl = repo.changelog
|
2010-10-10 21:41:36 +04:00
|
|
|
if args:
|
2012-05-31 02:13:33 +04:00
|
|
|
pattern = getstring(args[0],
|
|
|
|
# i18n: "tag" is a keyword
|
|
|
|
_('the argument to tag must be a string'))
|
2015-08-23 05:52:18 +03:00
|
|
|
kind, pattern, matcher = util.stringmatcher(pattern)
|
2012-05-31 02:13:33 +04:00
|
|
|
if kind == 'literal':
|
2012-06-02 00:13:05 +04:00
|
|
|
# avoid resolving all tags
|
|
|
|
tn = repo._tagscache.tags.get(pattern, None)
|
|
|
|
if tn is None:
|
revset: raise RepoLookupError to make present() predicate continue the query
Before this patch, "bookmark()", "named()" and "tag()" predicates
raise "Abort", when the specified pattern doesn't match against
existing ones.
This prevents "present()" predicate from continuing the query, because
it only catches "RepoLookupError".
This patch raises "RepoLookupError" instead of "Abort", to make
"present()" predicate continue the query, even if "bookmark()",
"named()" or "tag()" in the sub-query of it are aborted.
This patch doesn't contain raising "RepoLookupError" for "re:" pattern
in "tag()", because "tag()" treats it differently from others. Actions
of each predicates at failure of pattern matching can be summarized as
below:
predicate "literal:" "re:"
---------- ----------- ------------
bookmark abort abort
named abort abort
tag abort continue (*1)
branch abort continue (*2)
---------- ----------- ------------
"tag()" may have to abort in the (*1) case for similarity, but this
change may break backward compatibility of existing revset queries. It
seems to have to be changed on "default" branch (with "BC" ?).
On the other hand, (*2) seems to be reasonable, even though it breaks
similarity, because "branch()" in this case doesn't check exact
existence of branches, but does pick up revisions of which branch
matches against the pattern.
This patch also adds tests for "branch()" to clarify behavior around
"present()" of similar predicates, even though this patch doesn't
change "branch()".
2015-01-30 19:00:50 +03:00
|
|
|
raise error.RepoLookupError(_("tag '%s' does not exist")
|
|
|
|
% pattern)
|
2012-06-02 00:13:05 +04:00
|
|
|
s = set([repo[tn].rev()])
|
2012-05-31 02:13:33 +04:00
|
|
|
else:
|
|
|
|
s = set([cl.rev(n) for t, n in repo.tagslist() if matcher(t)])
|
2010-10-10 21:41:36 +04:00
|
|
|
else:
|
|
|
|
s = set([cl.rev(n) for t, n in repo.tagslist() if t != 'tip'])
|
2014-01-25 04:57:44 +04:00
|
|
|
return subset & s
|
2010-06-04 02:39:40 +04:00
|
|
|
|
2015-12-29 17:58:30 +03:00
|
|
|
@predicate('tagged', safe=True)
|
2010-10-23 21:21:51 +04:00
|
|
|
def tagged(repo, subset, x):
|
|
|
|
return tag(repo, subset, x)
|
|
|
|
|
2015-12-29 17:58:30 +03:00
|
|
|
@predicate('unstable()', safe=True)
|
2012-07-06 02:18:09 +04:00
|
|
|
def unstable(repo, subset, x):
|
2015-12-29 17:58:30 +03:00
|
|
|
"""Non-obsolete changesets with obsolete ancestors.
|
2012-07-30 17:48:04 +04:00
|
|
|
"""
|
2012-07-26 08:58:43 +04:00
|
|
|
# i18n: "unstable" is a keyword
|
2012-07-26 08:58:43 +04:00
|
|
|
getargs(x, 0, 0, _("unstable takes no arguments"))
|
2012-10-19 02:28:13 +04:00
|
|
|
unstables = obsmod.getrevs(repo, 'unstable')
|
2014-01-25 04:57:44 +04:00
|
|
|
return subset & unstables
|
2012-07-06 02:18:09 +04:00
|
|
|
|
|
|
|
|
2015-12-29 17:58:30 +03:00
|
|
|
@predicate('user(string)', safe=True)
|
2011-04-08 18:47:58 +04:00
|
|
|
def user(repo, subset, x):
|
2015-12-29 17:58:30 +03:00
|
|
|
"""User name contains string. The match is case-insensitive.
|
2012-05-31 02:13:58 +04:00
|
|
|
|
|
|
|
If `string` starts with `re:`, the remainder of the string is treated as
|
|
|
|
a regular expression. To match a user that actually contains `re:`, use
|
|
|
|
the prefix `literal:`.
|
2011-03-12 20:48:30 +03:00
|
|
|
"""
|
2011-04-08 18:47:58 +04:00
|
|
|
return author(repo, subset, x)
|
2011-03-12 20:48:30 +03:00
|
|
|
|
2015-04-12 13:00:31 +03:00
|
|
|
# experimental
|
2015-12-29 17:58:30 +03:00
|
|
|
@predicate('wdir', safe=True)
|
2014-08-16 08:44:16 +04:00
|
|
|
def wdir(repo, subset, x):
|
|
|
|
# i18n: "wdir" is a keyword
|
|
|
|
getargs(x, 0, 0, _("wdir takes no arguments"))
|
2015-03-16 10:17:06 +03:00
|
|
|
if node.wdirrev in subset or isinstance(subset, fullreposet):
|
|
|
|
return baseset([node.wdirrev])
|
2014-08-16 08:44:16 +04:00
|
|
|
return baseset()
|
|
|
|
|
2016-06-26 12:41:28 +03:00
|
|
|
def _orderedlist(repo, subset, x):
|
2012-01-16 11:21:22 +04:00
|
|
|
s = getstring(x, "internal error")
|
|
|
|
if not s:
|
2014-10-06 21:41:43 +04:00
|
|
|
return baseset()
|
2015-05-24 08:49:41 +03:00
|
|
|
# remove duplicates here. it's difficult for caller to deduplicate sets
|
|
|
|
# because different symbols can point to the same rev.
|
2015-05-17 09:16:13 +03:00
|
|
|
cl = repo.changelog
|
2015-05-24 08:49:41 +03:00
|
|
|
ls = []
|
|
|
|
seen = set()
|
|
|
|
for t in s.split('\0'):
|
2015-05-17 09:16:13 +03:00
|
|
|
try:
|
|
|
|
# fast path for integer revision
|
|
|
|
r = int(t)
|
|
|
|
if str(r) != t or r not in cl:
|
|
|
|
raise ValueError
|
2015-09-02 02:46:05 +03:00
|
|
|
revs = [r]
|
2015-05-17 09:16:13 +03:00
|
|
|
except ValueError:
|
2015-09-02 02:46:05 +03:00
|
|
|
revs = stringset(repo, subset, t)
|
|
|
|
|
|
|
|
for r in revs:
|
|
|
|
if r in seen:
|
|
|
|
continue
|
|
|
|
if (r in subset
|
|
|
|
or r == node.nullrev and isinstance(subset, fullreposet)):
|
|
|
|
ls.append(r)
|
|
|
|
seen.add(r)
|
2015-05-24 08:49:41 +03:00
|
|
|
return baseset(ls)
|
2012-01-16 11:21:22 +04:00
|
|
|
|
2014-02-27 00:36:36 +04:00
|
|
|
# for internal use
|
2016-06-26 12:41:28 +03:00
|
|
|
@predicate('_list', safe=True, takeorder=True)
|
|
|
|
def _list(repo, subset, x, order):
|
|
|
|
if order == followorder:
|
|
|
|
# slow path to take the subset order
|
|
|
|
return subset & _orderedlist(repo, fullreposet(repo), x)
|
|
|
|
else:
|
|
|
|
return _orderedlist(repo, subset, x)
|
|
|
|
|
|
|
|
def _orderedintlist(repo, subset, x):
|
2014-02-27 00:36:36 +04:00
|
|
|
s = getstring(x, "internal error")
|
|
|
|
if not s:
|
2014-10-06 21:41:43 +04:00
|
|
|
return baseset()
|
2014-02-27 00:36:36 +04:00
|
|
|
ls = [int(r) for r in s.split('\0')]
|
2014-10-08 13:51:54 +04:00
|
|
|
s = subset
|
2014-02-27 00:36:36 +04:00
|
|
|
return baseset([r for r in ls if r in s])
|
|
|
|
|
2014-02-27 05:15:55 +04:00
|
|
|
# for internal use
|
2016-06-26 12:41:28 +03:00
|
|
|
@predicate('_intlist', safe=True, takeorder=True)
|
|
|
|
def _intlist(repo, subset, x, order):
|
|
|
|
if order == followorder:
|
|
|
|
# slow path to take the subset order
|
|
|
|
return subset & _orderedintlist(repo, fullreposet(repo), x)
|
|
|
|
else:
|
|
|
|
return _orderedintlist(repo, subset, x)
|
|
|
|
|
|
|
|
def _orderedhexlist(repo, subset, x):
|
2014-02-27 05:15:55 +04:00
|
|
|
s = getstring(x, "internal error")
|
|
|
|
if not s:
|
2014-10-06 21:41:43 +04:00
|
|
|
return baseset()
|
2014-02-27 05:15:55 +04:00
|
|
|
cl = repo.changelog
|
|
|
|
ls = [cl.rev(node.bin(r)) for r in s.split('\0')]
|
2014-10-08 13:52:10 +04:00
|
|
|
s = subset
|
2014-02-27 05:15:55 +04:00
|
|
|
return baseset([r for r in ls if r in s])
|
|
|
|
|
2016-06-26 12:41:28 +03:00
|
|
|
# for internal use
|
|
|
|
@predicate('_hexlist', safe=True, takeorder=True)
|
|
|
|
def _hexlist(repo, subset, x, order):
|
|
|
|
if order == followorder:
|
|
|
|
# slow path to take the subset order
|
|
|
|
return subset & _orderedhexlist(repo, fullreposet(repo), x)
|
|
|
|
else:
|
|
|
|
return _orderedhexlist(repo, subset, x)
|
|
|
|
|
2010-06-01 20:18:57 +04:00
|
|
|
methods = {
|
|
|
|
"range": rangeset,
|
2016-10-01 14:20:11 +03:00
|
|
|
"rangepre": rangepre,
|
2012-06-02 02:50:22 +04:00
|
|
|
"dagrange": dagrange,
|
2010-06-01 20:18:57 +04:00
|
|
|
"string": stringset,
|
2015-05-03 19:28:15 +03:00
|
|
|
"symbol": stringset,
|
2010-06-01 20:18:57 +04:00
|
|
|
"and": andset,
|
|
|
|
"or": orset,
|
|
|
|
"not": notset,
|
2016-02-24 21:41:15 +03:00
|
|
|
"difference": differenceset,
|
2010-06-01 20:18:57 +04:00
|
|
|
"list": listset,
|
2015-06-27 11:05:28 +03:00
|
|
|
"keyvalue": keyvaluepair,
|
2010-06-01 20:18:57 +04:00
|
|
|
"func": func,
|
2011-04-30 19:43:04 +04:00
|
|
|
"ancestor": ancestorspec,
|
|
|
|
"parent": parentspec,
|
2016-08-07 11:48:52 +03:00
|
|
|
"parentpost": parentpost,
|
2010-06-01 20:18:57 +04:00
|
|
|
}
|
|
|
|
|
revset: infer ordering flag to teach if operation should define/follow order
New flag 'order' is the hint to determine if a function or operation can
enforce its ordering requirement or take the ordering already defined. It
will be used to fix a couple of ordering bugs, such as:
a) 'x & (y | z)' disregards the order of 'x' (issue5100)
b) 'x & y:z' is listed from 'y' to 'z'
c) 'x & y' can be rewritten as 'y & x' if weight(x) > weight(y)
(a) and (b) are bugs of the revset core. Before this, there was no way to
tell if 'orset()' and 'rangeset()' can enforce its ordering. These bugs
could be addressed by overriding __and__() of the initial set to take the
ordering of the other set:
class fullreposet:
def __and__(self, other):
# allow other to enforce its ordering
return other
but it would expose (c), which is a hidden bug of optimize(). So, in either
ways, optimize() have to know the current ordering requirement. Otherwise,
it couldn't rewrite expressions by weights with no output change, nor tell
how a revset function or operation should order the entries.
'order' is tri-state. It starts with 'define', and shifts to 'follow' by
'x & y'. It changes back to 'define' on function call 'f(x)' or function-like
operation 'x (f) y' because 'f' may have its own ordering requirement for 'x'
and 'y'. The state 'any' will allow us to avoid extra cost that would be
necessary to constrain ordering where it isn't important, 'not x'.
2016-02-16 16:02:16 +03:00
|
|
|
# Constants for ordering requirement, used in _analyze():
|
|
|
|
#
|
|
|
|
# If 'define', any nested functions and operations can change the ordering of
|
|
|
|
# the entries in the set. If 'follow', any nested functions and operations
|
|
|
|
# should take the ordering specified by the first operand to the '&' operator.
|
|
|
|
#
|
|
|
|
# For instance,
|
|
|
|
#
|
|
|
|
# X & (Y | Z)
|
|
|
|
# ^ ^^^^^^^
|
|
|
|
# | follow
|
|
|
|
# define
|
|
|
|
#
|
|
|
|
# will be evaluated as 'or(y(x()), z(x()))', where 'x()' can change the order
|
|
|
|
# of the entries in the set, but 'y()', 'z()' and 'or()' shouldn't.
|
|
|
|
#
|
|
|
|
# 'any' means the order doesn't matter. For instance,
|
|
|
|
#
|
|
|
|
# X & !Y
|
|
|
|
# ^
|
|
|
|
# any
|
|
|
|
#
|
|
|
|
# 'y()' can either enforce its ordering requirement or take the ordering
|
|
|
|
# specified by 'x()' because 'not()' doesn't care the order.
|
|
|
|
#
|
|
|
|
# Transition of ordering requirement:
|
|
|
|
#
|
|
|
|
# 1. starts with 'define'
|
|
|
|
# 2. shifts to 'follow' by 'x & y'
|
|
|
|
# 3. changes back to 'define' on function call 'f(x)' or function-like
|
|
|
|
# operation 'x (f) y' because 'f' may have its own ordering requirement
|
|
|
|
# for 'x' and 'y' (e.g. 'first(x)')
|
|
|
|
#
|
|
|
|
anyorder = 'any' # don't care the order
|
|
|
|
defineorder = 'define' # should define the order
|
|
|
|
followorder = 'follow' # must follow the current order
|
|
|
|
|
|
|
|
# transition table for 'x & y', from the current expression 'x' to 'y'
|
|
|
|
_tofolloworder = {
|
|
|
|
anyorder: anyorder,
|
|
|
|
defineorder: followorder,
|
|
|
|
followorder: followorder,
|
|
|
|
}
|
|
|
|
|
2016-05-02 05:50:48 +03:00
|
|
|
def _matchonly(revs, bases):
|
|
|
|
"""
|
|
|
|
>>> f = lambda *args: _matchonly(*map(parse, args))
|
|
|
|
>>> f('ancestors(A)', 'not ancestors(B)')
|
|
|
|
('list', ('symbol', 'A'), ('symbol', 'B'))
|
|
|
|
"""
|
|
|
|
if (revs is not None
|
2016-05-02 05:27:26 +03:00
|
|
|
and revs[0] == 'func'
|
2016-06-27 14:44:14 +03:00
|
|
|
and getsymbol(revs[1]) == 'ancestors'
|
2016-05-02 05:27:26 +03:00
|
|
|
and bases is not None
|
|
|
|
and bases[0] == 'not'
|
|
|
|
and bases[1][0] == 'func'
|
2016-06-27 14:44:14 +03:00
|
|
|
and getsymbol(bases[1][1]) == 'ancestors'):
|
2016-05-02 05:50:48 +03:00
|
|
|
return ('list', revs[2], bases[1][2])
|
2016-05-02 05:27:26 +03:00
|
|
|
|
2016-08-06 14:21:00 +03:00
|
|
|
def _fixops(x):
|
|
|
|
"""Rewrite raw parsed tree to resolve ambiguous syntax which cannot be
|
|
|
|
handled well by our simple top-down parser"""
|
|
|
|
if not isinstance(x, tuple):
|
|
|
|
return x
|
|
|
|
|
|
|
|
op = x[0]
|
|
|
|
if op == 'parent':
|
|
|
|
# x^:y means (x^) : y, not x ^ (:y)
|
2016-08-06 14:37:48 +03:00
|
|
|
# x^: means (x^) :, not x ^ (:)
|
2016-08-06 14:21:00 +03:00
|
|
|
post = ('parentpost', x[1])
|
|
|
|
if x[2][0] == 'dagrangepre':
|
|
|
|
return _fixops(('dagrange', post, x[2][1]))
|
|
|
|
elif x[2][0] == 'rangepre':
|
|
|
|
return _fixops(('range', post, x[2][1]))
|
2016-08-06 14:37:48 +03:00
|
|
|
elif x[2][0] == 'rangeall':
|
|
|
|
return _fixops(('rangepost', post))
|
2016-08-07 11:04:05 +03:00
|
|
|
elif op == 'or':
|
|
|
|
# make number of arguments deterministic:
|
|
|
|
# x + y + z -> (or x y z) -> (or (list x y z))
|
|
|
|
return (op, _fixops(('list',) + x[1:]))
|
2016-08-06 14:21:00 +03:00
|
|
|
|
|
|
|
return (op,) + tuple(_fixops(y) for y in x[1:])
|
|
|
|
|
revset: infer ordering flag to teach if operation should define/follow order
New flag 'order' is the hint to determine if a function or operation can
enforce its ordering requirement or take the ordering already defined. It
will be used to fix a couple of ordering bugs, such as:
a) 'x & (y | z)' disregards the order of 'x' (issue5100)
b) 'x & y:z' is listed from 'y' to 'z'
c) 'x & y' can be rewritten as 'y & x' if weight(x) > weight(y)
(a) and (b) are bugs of the revset core. Before this, there was no way to
tell if 'orset()' and 'rangeset()' can enforce its ordering. These bugs
could be addressed by overriding __and__() of the initial set to take the
ordering of the other set:
class fullreposet:
def __and__(self, other):
# allow other to enforce its ordering
return other
but it would expose (c), which is a hidden bug of optimize(). So, in either
ways, optimize() have to know the current ordering requirement. Otherwise,
it couldn't rewrite expressions by weights with no output change, nor tell
how a revset function or operation should order the entries.
'order' is tri-state. It starts with 'define', and shifts to 'follow' by
'x & y'. It changes back to 'define' on function call 'f(x)' or function-like
operation 'x (f) y' because 'f' may have its own ordering requirement for 'x'
and 'y'. The state 'any' will allow us to avoid extra cost that would be
necessary to constrain ordering where it isn't important, 'not x'.
2016-02-16 16:02:16 +03:00
|
|
|
def _analyze(x, order):
|
2016-08-07 08:35:03 +03:00
|
|
|
if x is None:
|
|
|
|
return x
|
2010-06-01 20:18:57 +04:00
|
|
|
|
|
|
|
op = x[0]
|
2010-06-04 19:26:55 +04:00
|
|
|
if op == 'minus':
|
revset: infer ordering flag to teach if operation should define/follow order
New flag 'order' is the hint to determine if a function or operation can
enforce its ordering requirement or take the ordering already defined. It
will be used to fix a couple of ordering bugs, such as:
a) 'x & (y | z)' disregards the order of 'x' (issue5100)
b) 'x & y:z' is listed from 'y' to 'z'
c) 'x & y' can be rewritten as 'y & x' if weight(x) > weight(y)
(a) and (b) are bugs of the revset core. Before this, there was no way to
tell if 'orset()' and 'rangeset()' can enforce its ordering. These bugs
could be addressed by overriding __and__() of the initial set to take the
ordering of the other set:
class fullreposet:
def __and__(self, other):
# allow other to enforce its ordering
return other
but it would expose (c), which is a hidden bug of optimize(). So, in either
ways, optimize() have to know the current ordering requirement. Otherwise,
it couldn't rewrite expressions by weights with no output change, nor tell
how a revset function or operation should order the entries.
'order' is tri-state. It starts with 'define', and shifts to 'follow' by
'x & y'. It changes back to 'define' on function call 'f(x)' or function-like
operation 'x (f) y' because 'f' may have its own ordering requirement for 'x'
and 'y'. The state 'any' will allow us to avoid extra cost that would be
necessary to constrain ordering where it isn't important, 'not x'.
2016-02-16 16:02:16 +03:00
|
|
|
return _analyze(('and', x[1], ('not', x[2])), order)
|
2014-11-07 01:55:18 +03:00
|
|
|
elif op == 'only':
|
2016-05-02 06:47:09 +03:00
|
|
|
t = ('func', ('symbol', 'only'), ('list', x[1], x[2]))
|
revset: infer ordering flag to teach if operation should define/follow order
New flag 'order' is the hint to determine if a function or operation can
enforce its ordering requirement or take the ordering already defined. It
will be used to fix a couple of ordering bugs, such as:
a) 'x & (y | z)' disregards the order of 'x' (issue5100)
b) 'x & y:z' is listed from 'y' to 'z'
c) 'x & y' can be rewritten as 'y & x' if weight(x) > weight(y)
(a) and (b) are bugs of the revset core. Before this, there was no way to
tell if 'orset()' and 'rangeset()' can enforce its ordering. These bugs
could be addressed by overriding __and__() of the initial set to take the
ordering of the other set:
class fullreposet:
def __and__(self, other):
# allow other to enforce its ordering
return other
but it would expose (c), which is a hidden bug of optimize(). So, in either
ways, optimize() have to know the current ordering requirement. Otherwise,
it couldn't rewrite expressions by weights with no output change, nor tell
how a revset function or operation should order the entries.
'order' is tri-state. It starts with 'define', and shifts to 'follow' by
'x & y'. It changes back to 'define' on function call 'f(x)' or function-like
operation 'x (f) y' because 'f' may have its own ordering requirement for 'x'
and 'y'. The state 'any' will allow us to avoid extra cost that would be
necessary to constrain ordering where it isn't important, 'not x'.
2016-02-16 16:02:16 +03:00
|
|
|
return _analyze(t, order)
|
2015-05-15 16:32:31 +03:00
|
|
|
elif op == 'onlypost':
|
revset: infer ordering flag to teach if operation should define/follow order
New flag 'order' is the hint to determine if a function or operation can
enforce its ordering requirement or take the ordering already defined. It
will be used to fix a couple of ordering bugs, such as:
a) 'x & (y | z)' disregards the order of 'x' (issue5100)
b) 'x & y:z' is listed from 'y' to 'z'
c) 'x & y' can be rewritten as 'y & x' if weight(x) > weight(y)
(a) and (b) are bugs of the revset core. Before this, there was no way to
tell if 'orset()' and 'rangeset()' can enforce its ordering. These bugs
could be addressed by overriding __and__() of the initial set to take the
ordering of the other set:
class fullreposet:
def __and__(self, other):
# allow other to enforce its ordering
return other
but it would expose (c), which is a hidden bug of optimize(). So, in either
ways, optimize() have to know the current ordering requirement. Otherwise,
it couldn't rewrite expressions by weights with no output change, nor tell
how a revset function or operation should order the entries.
'order' is tri-state. It starts with 'define', and shifts to 'follow' by
'x & y'. It changes back to 'define' on function call 'f(x)' or function-like
operation 'x (f) y' because 'f' may have its own ordering requirement for 'x'
and 'y'. The state 'any' will allow us to avoid extra cost that would be
necessary to constrain ordering where it isn't important, 'not x'.
2016-02-16 16:02:16 +03:00
|
|
|
return _analyze(('func', ('symbol', 'only'), x[1]), order)
|
2010-06-04 02:39:34 +04:00
|
|
|
elif op == 'dagrangepre':
|
revset: infer ordering flag to teach if operation should define/follow order
New flag 'order' is the hint to determine if a function or operation can
enforce its ordering requirement or take the ordering already defined. It
will be used to fix a couple of ordering bugs, such as:
a) 'x & (y | z)' disregards the order of 'x' (issue5100)
b) 'x & y:z' is listed from 'y' to 'z'
c) 'x & y' can be rewritten as 'y & x' if weight(x) > weight(y)
(a) and (b) are bugs of the revset core. Before this, there was no way to
tell if 'orset()' and 'rangeset()' can enforce its ordering. These bugs
could be addressed by overriding __and__() of the initial set to take the
ordering of the other set:
class fullreposet:
def __and__(self, other):
# allow other to enforce its ordering
return other
but it would expose (c), which is a hidden bug of optimize(). So, in either
ways, optimize() have to know the current ordering requirement. Otherwise,
it couldn't rewrite expressions by weights with no output change, nor tell
how a revset function or operation should order the entries.
'order' is tri-state. It starts with 'define', and shifts to 'follow' by
'x & y'. It changes back to 'define' on function call 'f(x)' or function-like
operation 'x (f) y' because 'f' may have its own ordering requirement for 'x'
and 'y'. The state 'any' will allow us to avoid extra cost that would be
necessary to constrain ordering where it isn't important, 'not x'.
2016-02-16 16:02:16 +03:00
|
|
|
return _analyze(('func', ('symbol', 'ancestors'), x[1]), order)
|
2010-06-04 02:39:34 +04:00
|
|
|
elif op == 'dagrangepost':
|
revset: infer ordering flag to teach if operation should define/follow order
New flag 'order' is the hint to determine if a function or operation can
enforce its ordering requirement or take the ordering already defined. It
will be used to fix a couple of ordering bugs, such as:
a) 'x & (y | z)' disregards the order of 'x' (issue5100)
b) 'x & y:z' is listed from 'y' to 'z'
c) 'x & y' can be rewritten as 'y & x' if weight(x) > weight(y)
(a) and (b) are bugs of the revset core. Before this, there was no way to
tell if 'orset()' and 'rangeset()' can enforce its ordering. These bugs
could be addressed by overriding __and__() of the initial set to take the
ordering of the other set:
class fullreposet:
def __and__(self, other):
# allow other to enforce its ordering
return other
but it would expose (c), which is a hidden bug of optimize(). So, in either
ways, optimize() have to know the current ordering requirement. Otherwise,
it couldn't rewrite expressions by weights with no output change, nor tell
how a revset function or operation should order the entries.
'order' is tri-state. It starts with 'define', and shifts to 'follow' by
'x & y'. It changes back to 'define' on function call 'f(x)' or function-like
operation 'x (f) y' because 'f' may have its own ordering requirement for 'x'
and 'y'. The state 'any' will allow us to avoid extra cost that would be
necessary to constrain ordering where it isn't important, 'not x'.
2016-02-16 16:02:16 +03:00
|
|
|
return _analyze(('func', ('symbol', 'descendants'), x[1]), order)
|
2015-07-05 06:15:54 +03:00
|
|
|
elif op == 'rangeall':
|
2016-10-01 14:20:11 +03:00
|
|
|
return _analyze(('rangepre', ('string', 'tip')), order)
|
2010-06-04 02:39:34 +04:00
|
|
|
elif op == 'rangepost':
|
revset: infer ordering flag to teach if operation should define/follow order
New flag 'order' is the hint to determine if a function or operation can
enforce its ordering requirement or take the ordering already defined. It
will be used to fix a couple of ordering bugs, such as:
a) 'x & (y | z)' disregards the order of 'x' (issue5100)
b) 'x & y:z' is listed from 'y' to 'z'
c) 'x & y' can be rewritten as 'y & x' if weight(x) > weight(y)
(a) and (b) are bugs of the revset core. Before this, there was no way to
tell if 'orset()' and 'rangeset()' can enforce its ordering. These bugs
could be addressed by overriding __and__() of the initial set to take the
ordering of the other set:
class fullreposet:
def __and__(self, other):
# allow other to enforce its ordering
return other
but it would expose (c), which is a hidden bug of optimize(). So, in either
ways, optimize() have to know the current ordering requirement. Otherwise,
it couldn't rewrite expressions by weights with no output change, nor tell
how a revset function or operation should order the entries.
'order' is tri-state. It starts with 'define', and shifts to 'follow' by
'x & y'. It changes back to 'define' on function call 'f(x)' or function-like
operation 'x (f) y' because 'f' may have its own ordering requirement for 'x'
and 'y'. The state 'any' will allow us to avoid extra cost that would be
necessary to constrain ordering where it isn't important, 'not x'.
2016-02-16 16:02:16 +03:00
|
|
|
return _analyze(('range', x[1], ('string', 'tip')), order)
|
2010-07-01 02:44:36 +04:00
|
|
|
elif op == 'negate':
|
2016-05-02 06:47:09 +03:00
|
|
|
s = getstring(x[1], _("can't negate that"))
|
revset: infer ordering flag to teach if operation should define/follow order
New flag 'order' is the hint to determine if a function or operation can
enforce its ordering requirement or take the ordering already defined. It
will be used to fix a couple of ordering bugs, such as:
a) 'x & (y | z)' disregards the order of 'x' (issue5100)
b) 'x & y:z' is listed from 'y' to 'z'
c) 'x & y' can be rewritten as 'y & x' if weight(x) > weight(y)
(a) and (b) are bugs of the revset core. Before this, there was no way to
tell if 'orset()' and 'rangeset()' can enforce its ordering. These bugs
could be addressed by overriding __and__() of the initial set to take the
ordering of the other set:
class fullreposet:
def __and__(self, other):
# allow other to enforce its ordering
return other
but it would expose (c), which is a hidden bug of optimize(). So, in either
ways, optimize() have to know the current ordering requirement. Otherwise,
it couldn't rewrite expressions by weights with no output change, nor tell
how a revset function or operation should order the entries.
'order' is tri-state. It starts with 'define', and shifts to 'follow' by
'x & y'. It changes back to 'define' on function call 'f(x)' or function-like
operation 'x (f) y' because 'f' may have its own ordering requirement for 'x'
and 'y'. The state 'any' will allow us to avoid extra cost that would be
necessary to constrain ordering where it isn't important, 'not x'.
2016-02-16 16:02:16 +03:00
|
|
|
return _analyze(('string', '-' + s), order)
|
2016-08-07 10:36:08 +03:00
|
|
|
elif op in ('string', 'symbol'):
|
2016-08-07 08:35:03 +03:00
|
|
|
return x
|
|
|
|
elif op == 'and':
|
revset: infer ordering flag to teach if operation should define/follow order
New flag 'order' is the hint to determine if a function or operation can
enforce its ordering requirement or take the ordering already defined. It
will be used to fix a couple of ordering bugs, such as:
a) 'x & (y | z)' disregards the order of 'x' (issue5100)
b) 'x & y:z' is listed from 'y' to 'z'
c) 'x & y' can be rewritten as 'y & x' if weight(x) > weight(y)
(a) and (b) are bugs of the revset core. Before this, there was no way to
tell if 'orset()' and 'rangeset()' can enforce its ordering. These bugs
could be addressed by overriding __and__() of the initial set to take the
ordering of the other set:
class fullreposet:
def __and__(self, other):
# allow other to enforce its ordering
return other
but it would expose (c), which is a hidden bug of optimize(). So, in either
ways, optimize() have to know the current ordering requirement. Otherwise,
it couldn't rewrite expressions by weights with no output change, nor tell
how a revset function or operation should order the entries.
'order' is tri-state. It starts with 'define', and shifts to 'follow' by
'x & y'. It changes back to 'define' on function call 'f(x)' or function-like
operation 'x (f) y' because 'f' may have its own ordering requirement for 'x'
and 'y'. The state 'any' will allow us to avoid extra cost that would be
necessary to constrain ordering where it isn't important, 'not x'.
2016-02-16 16:02:16 +03:00
|
|
|
ta = _analyze(x[1], order)
|
|
|
|
tb = _analyze(x[2], _tofolloworder[order])
|
2016-08-07 11:46:12 +03:00
|
|
|
return (op, ta, tb, order)
|
2016-08-07 08:35:03 +03:00
|
|
|
elif op == 'or':
|
2016-08-07 11:46:12 +03:00
|
|
|
return (op, _analyze(x[1], order), order)
|
2016-08-07 08:35:03 +03:00
|
|
|
elif op == 'not':
|
2016-08-07 11:46:12 +03:00
|
|
|
return (op, _analyze(x[1], anyorder), order)
|
2016-10-01 14:20:11 +03:00
|
|
|
elif op in ('rangepre', 'parentpost'):
|
2016-08-07 11:46:12 +03:00
|
|
|
return (op, _analyze(x[1], defineorder), order)
|
2016-08-07 08:35:03 +03:00
|
|
|
elif op == 'group':
|
revset: infer ordering flag to teach if operation should define/follow order
New flag 'order' is the hint to determine if a function or operation can
enforce its ordering requirement or take the ordering already defined. It
will be used to fix a couple of ordering bugs, such as:
a) 'x & (y | z)' disregards the order of 'x' (issue5100)
b) 'x & y:z' is listed from 'y' to 'z'
c) 'x & y' can be rewritten as 'y & x' if weight(x) > weight(y)
(a) and (b) are bugs of the revset core. Before this, there was no way to
tell if 'orset()' and 'rangeset()' can enforce its ordering. These bugs
could be addressed by overriding __and__() of the initial set to take the
ordering of the other set:
class fullreposet:
def __and__(self, other):
# allow other to enforce its ordering
return other
but it would expose (c), which is a hidden bug of optimize(). So, in either
ways, optimize() have to know the current ordering requirement. Otherwise,
it couldn't rewrite expressions by weights with no output change, nor tell
how a revset function or operation should order the entries.
'order' is tri-state. It starts with 'define', and shifts to 'follow' by
'x & y'. It changes back to 'define' on function call 'f(x)' or function-like
operation 'x (f) y' because 'f' may have its own ordering requirement for 'x'
and 'y'. The state 'any' will allow us to avoid extra cost that would be
necessary to constrain ordering where it isn't important, 'not x'.
2016-02-16 16:02:16 +03:00
|
|
|
return _analyze(x[1], order)
|
2016-08-07 08:35:03 +03:00
|
|
|
elif op in ('dagrange', 'range', 'parent', 'ancestor'):
|
revset: infer ordering flag to teach if operation should define/follow order
New flag 'order' is the hint to determine if a function or operation can
enforce its ordering requirement or take the ordering already defined. It
will be used to fix a couple of ordering bugs, such as:
a) 'x & (y | z)' disregards the order of 'x' (issue5100)
b) 'x & y:z' is listed from 'y' to 'z'
c) 'x & y' can be rewritten as 'y & x' if weight(x) > weight(y)
(a) and (b) are bugs of the revset core. Before this, there was no way to
tell if 'orset()' and 'rangeset()' can enforce its ordering. These bugs
could be addressed by overriding __and__() of the initial set to take the
ordering of the other set:
class fullreposet:
def __and__(self, other):
# allow other to enforce its ordering
return other
but it would expose (c), which is a hidden bug of optimize(). So, in either
ways, optimize() have to know the current ordering requirement. Otherwise,
it couldn't rewrite expressions by weights with no output change, nor tell
how a revset function or operation should order the entries.
'order' is tri-state. It starts with 'define', and shifts to 'follow' by
'x & y'. It changes back to 'define' on function call 'f(x)' or function-like
operation 'x (f) y' because 'f' may have its own ordering requirement for 'x'
and 'y'. The state 'any' will allow us to avoid extra cost that would be
necessary to constrain ordering where it isn't important, 'not x'.
2016-02-16 16:02:16 +03:00
|
|
|
ta = _analyze(x[1], defineorder)
|
|
|
|
tb = _analyze(x[2], defineorder)
|
2016-08-07 11:46:12 +03:00
|
|
|
return (op, ta, tb, order)
|
2016-08-07 08:35:03 +03:00
|
|
|
elif op == 'list':
|
revset: infer ordering flag to teach if operation should define/follow order
New flag 'order' is the hint to determine if a function or operation can
enforce its ordering requirement or take the ordering already defined. It
will be used to fix a couple of ordering bugs, such as:
a) 'x & (y | z)' disregards the order of 'x' (issue5100)
b) 'x & y:z' is listed from 'y' to 'z'
c) 'x & y' can be rewritten as 'y & x' if weight(x) > weight(y)
(a) and (b) are bugs of the revset core. Before this, there was no way to
tell if 'orset()' and 'rangeset()' can enforce its ordering. These bugs
could be addressed by overriding __and__() of the initial set to take the
ordering of the other set:
class fullreposet:
def __and__(self, other):
# allow other to enforce its ordering
return other
but it would expose (c), which is a hidden bug of optimize(). So, in either
ways, optimize() have to know the current ordering requirement. Otherwise,
it couldn't rewrite expressions by weights with no output change, nor tell
how a revset function or operation should order the entries.
'order' is tri-state. It starts with 'define', and shifts to 'follow' by
'x & y'. It changes back to 'define' on function call 'f(x)' or function-like
operation 'x (f) y' because 'f' may have its own ordering requirement for 'x'
and 'y'. The state 'any' will allow us to avoid extra cost that would be
necessary to constrain ordering where it isn't important, 'not x'.
2016-02-16 16:02:16 +03:00
|
|
|
return (op,) + tuple(_analyze(y, order) for y in x[1:])
|
2016-08-07 08:35:03 +03:00
|
|
|
elif op == 'keyvalue':
|
revset: infer ordering flag to teach if operation should define/follow order
New flag 'order' is the hint to determine if a function or operation can
enforce its ordering requirement or take the ordering already defined. It
will be used to fix a couple of ordering bugs, such as:
a) 'x & (y | z)' disregards the order of 'x' (issue5100)
b) 'x & y:z' is listed from 'y' to 'z'
c) 'x & y' can be rewritten as 'y & x' if weight(x) > weight(y)
(a) and (b) are bugs of the revset core. Before this, there was no way to
tell if 'orset()' and 'rangeset()' can enforce its ordering. These bugs
could be addressed by overriding __and__() of the initial set to take the
ordering of the other set:
class fullreposet:
def __and__(self, other):
# allow other to enforce its ordering
return other
but it would expose (c), which is a hidden bug of optimize(). So, in either
ways, optimize() have to know the current ordering requirement. Otherwise,
it couldn't rewrite expressions by weights with no output change, nor tell
how a revset function or operation should order the entries.
'order' is tri-state. It starts with 'define', and shifts to 'follow' by
'x & y'. It changes back to 'define' on function call 'f(x)' or function-like
operation 'x (f) y' because 'f' may have its own ordering requirement for 'x'
and 'y'. The state 'any' will allow us to avoid extra cost that would be
necessary to constrain ordering where it isn't important, 'not x'.
2016-02-16 16:02:16 +03:00
|
|
|
return (op, x[1], _analyze(x[2], order))
|
2016-08-07 08:35:03 +03:00
|
|
|
elif op == 'func':
|
2016-06-01 14:54:04 +03:00
|
|
|
f = getsymbol(x[1])
|
|
|
|
d = defineorder
|
|
|
|
if f == 'present':
|
|
|
|
# 'present(set)' is known to return the argument set with no
|
|
|
|
# modification, so forward the current order to its argument
|
|
|
|
d = order
|
|
|
|
return (op, x[1], _analyze(x[2], d), order)
|
2016-08-07 08:35:03 +03:00
|
|
|
raise ValueError('invalid operator %r' % op)
|
|
|
|
|
revset: infer ordering flag to teach if operation should define/follow order
New flag 'order' is the hint to determine if a function or operation can
enforce its ordering requirement or take the ordering already defined. It
will be used to fix a couple of ordering bugs, such as:
a) 'x & (y | z)' disregards the order of 'x' (issue5100)
b) 'x & y:z' is listed from 'y' to 'z'
c) 'x & y' can be rewritten as 'y & x' if weight(x) > weight(y)
(a) and (b) are bugs of the revset core. Before this, there was no way to
tell if 'orset()' and 'rangeset()' can enforce its ordering. These bugs
could be addressed by overriding __and__() of the initial set to take the
ordering of the other set:
class fullreposet:
def __and__(self, other):
# allow other to enforce its ordering
return other
but it would expose (c), which is a hidden bug of optimize(). So, in either
ways, optimize() have to know the current ordering requirement. Otherwise,
it couldn't rewrite expressions by weights with no output change, nor tell
how a revset function or operation should order the entries.
'order' is tri-state. It starts with 'define', and shifts to 'follow' by
'x & y'. It changes back to 'define' on function call 'f(x)' or function-like
operation 'x (f) y' because 'f' may have its own ordering requirement for 'x'
and 'y'. The state 'any' will allow us to avoid extra cost that would be
necessary to constrain ordering where it isn't important, 'not x'.
2016-02-16 16:02:16 +03:00
|
|
|
def analyze(x, order=defineorder):
|
2016-08-21 05:29:57 +03:00
|
|
|
"""Transform raw parsed tree to evaluatable tree which can be fed to
|
|
|
|
optimize() or getset()
|
2016-08-07 08:35:03 +03:00
|
|
|
|
2016-08-21 05:29:57 +03:00
|
|
|
All pseudo operations should be mapped to real operations or functions
|
|
|
|
defined in methods or symbols table respectively.
|
revset: infer ordering flag to teach if operation should define/follow order
New flag 'order' is the hint to determine if a function or operation can
enforce its ordering requirement or take the ordering already defined. It
will be used to fix a couple of ordering bugs, such as:
a) 'x & (y | z)' disregards the order of 'x' (issue5100)
b) 'x & y:z' is listed from 'y' to 'z'
c) 'x & y' can be rewritten as 'y & x' if weight(x) > weight(y)
(a) and (b) are bugs of the revset core. Before this, there was no way to
tell if 'orset()' and 'rangeset()' can enforce its ordering. These bugs
could be addressed by overriding __and__() of the initial set to take the
ordering of the other set:
class fullreposet:
def __and__(self, other):
# allow other to enforce its ordering
return other
but it would expose (c), which is a hidden bug of optimize(). So, in either
ways, optimize() have to know the current ordering requirement. Otherwise,
it couldn't rewrite expressions by weights with no output change, nor tell
how a revset function or operation should order the entries.
'order' is tri-state. It starts with 'define', and shifts to 'follow' by
'x & y'. It changes back to 'define' on function call 'f(x)' or function-like
operation 'x (f) y' because 'f' may have its own ordering requirement for 'x'
and 'y'. The state 'any' will allow us to avoid extra cost that would be
necessary to constrain ordering where it isn't important, 'not x'.
2016-02-16 16:02:16 +03:00
|
|
|
|
|
|
|
'order' specifies how the current expression 'x' is ordered (see the
|
|
|
|
constants defined above.)
|
2016-08-07 08:35:03 +03:00
|
|
|
"""
|
revset: infer ordering flag to teach if operation should define/follow order
New flag 'order' is the hint to determine if a function or operation can
enforce its ordering requirement or take the ordering already defined. It
will be used to fix a couple of ordering bugs, such as:
a) 'x & (y | z)' disregards the order of 'x' (issue5100)
b) 'x & y:z' is listed from 'y' to 'z'
c) 'x & y' can be rewritten as 'y & x' if weight(x) > weight(y)
(a) and (b) are bugs of the revset core. Before this, there was no way to
tell if 'orset()' and 'rangeset()' can enforce its ordering. These bugs
could be addressed by overriding __and__() of the initial set to take the
ordering of the other set:
class fullreposet:
def __and__(self, other):
# allow other to enforce its ordering
return other
but it would expose (c), which is a hidden bug of optimize(). So, in either
ways, optimize() have to know the current ordering requirement. Otherwise,
it couldn't rewrite expressions by weights with no output change, nor tell
how a revset function or operation should order the entries.
'order' is tri-state. It starts with 'define', and shifts to 'follow' by
'x & y'. It changes back to 'define' on function call 'f(x)' or function-like
operation 'x (f) y' because 'f' may have its own ordering requirement for 'x'
and 'y'. The state 'any' will allow us to avoid extra cost that would be
necessary to constrain ordering where it isn't important, 'not x'.
2016-02-16 16:02:16 +03:00
|
|
|
return _analyze(x, order)
|
2016-08-21 05:29:57 +03:00
|
|
|
|
|
|
|
def _optimize(x, small):
|
2016-08-07 08:35:03 +03:00
|
|
|
if x is None:
|
|
|
|
return 0, x
|
|
|
|
|
|
|
|
smallbonus = 1
|
|
|
|
if small:
|
|
|
|
smallbonus = .5
|
|
|
|
|
|
|
|
op = x[0]
|
|
|
|
if op in ('string', 'symbol'):
|
2010-06-04 02:39:34 +04:00
|
|
|
return smallbonus, x # single revisions are small
|
2012-06-02 02:50:22 +04:00
|
|
|
elif op == 'and':
|
2016-05-02 06:09:00 +03:00
|
|
|
wa, ta = _optimize(x[1], True)
|
|
|
|
wb, tb = _optimize(x[2], True)
|
2016-08-07 11:46:12 +03:00
|
|
|
order = x[3]
|
2016-05-02 05:27:26 +03:00
|
|
|
w = min(wa, wb)
|
2014-02-14 02:04:47 +04:00
|
|
|
|
|
|
|
# (::x and not ::y)/(not ::y and ::x) have a fast path
|
2016-05-02 05:50:48 +03:00
|
|
|
tm = _matchonly(ta, tb) or _matchonly(tb, ta)
|
|
|
|
if tm:
|
2016-08-07 11:46:12 +03:00
|
|
|
return w, ('func', ('symbol', 'only'), tm, order)
|
2014-02-14 02:04:47 +04:00
|
|
|
|
2016-02-24 21:41:15 +03:00
|
|
|
if tb is not None and tb[0] == 'not':
|
2016-08-07 11:46:12 +03:00
|
|
|
return wa, ('difference', ta, tb[1], order)
|
2016-02-24 21:41:15 +03:00
|
|
|
|
2010-06-04 02:39:34 +04:00
|
|
|
if wa > wb:
|
2016-08-07 11:46:12 +03:00
|
|
|
return w, (op, tb, ta, order)
|
|
|
|
return w, (op, ta, tb, order)
|
2010-06-04 02:39:34 +04:00
|
|
|
elif op == 'or':
|
2015-05-17 09:11:38 +03:00
|
|
|
# fast path for machine-generated expression, that is likely to have
|
|
|
|
# lots of trivial revisions: 'a + b + c()' to '_list(a b) + c()'
|
2016-08-07 11:46:12 +03:00
|
|
|
order = x[2]
|
2015-05-17 09:11:38 +03:00
|
|
|
ws, ts, ss = [], [], []
|
|
|
|
def flushss():
|
|
|
|
if not ss:
|
|
|
|
return
|
|
|
|
if len(ss) == 1:
|
|
|
|
w, t = ss[0]
|
|
|
|
else:
|
|
|
|
s = '\0'.join(t[1] for w, t in ss)
|
2016-08-07 11:46:12 +03:00
|
|
|
y = ('func', ('symbol', '_list'), ('string', s), order)
|
2016-05-02 06:09:00 +03:00
|
|
|
w, t = _optimize(y, False)
|
2015-05-17 09:11:38 +03:00
|
|
|
ws.append(w)
|
|
|
|
ts.append(t)
|
|
|
|
del ss[:]
|
2016-08-07 11:04:05 +03:00
|
|
|
for y in getlist(x[1]):
|
2016-05-02 06:09:00 +03:00
|
|
|
w, t = _optimize(y, False)
|
2015-08-09 10:09:41 +03:00
|
|
|
if t is not None and (t[0] == 'string' or t[0] == 'symbol'):
|
2015-05-17 09:11:38 +03:00
|
|
|
ss.append((w, t))
|
|
|
|
continue
|
|
|
|
flushss()
|
|
|
|
ws.append(w)
|
|
|
|
ts.append(t)
|
|
|
|
flushss()
|
|
|
|
if len(ts) == 1:
|
|
|
|
return ws[0], ts[0] # 'or' operation is fully optimized out
|
2015-04-26 12:27:32 +03:00
|
|
|
# we can't reorder trees by weight because it would change the order.
|
|
|
|
# ("sort(a + b)" == "sort(b + a)", but "a + b" != "b + a")
|
2015-04-26 12:13:48 +03:00
|
|
|
# ts = tuple(t for w, t in sorted(zip(ws, ts), key=lambda wt: wt[0]))
|
2016-08-07 11:46:12 +03:00
|
|
|
return max(ws), (op, ('list',) + tuple(ts), order)
|
2010-06-01 20:18:57 +04:00
|
|
|
elif op == 'not':
|
2015-04-25 00:30:30 +03:00
|
|
|
# Optimize not public() to _notpublic() because we have a fast version
|
2016-08-07 11:46:12 +03:00
|
|
|
if x[1][:3] == ('func', ('symbol', 'public'), None):
|
|
|
|
order = x[1][3]
|
|
|
|
newsym = ('func', ('symbol', '_notpublic'), None, order)
|
2016-05-02 06:09:00 +03:00
|
|
|
o = _optimize(newsym, not small)
|
2015-04-25 00:30:30 +03:00
|
|
|
return o[0], o[1]
|
|
|
|
else:
|
2016-05-02 06:09:00 +03:00
|
|
|
o = _optimize(x[1], not small)
|
2016-08-07 11:46:12 +03:00
|
|
|
order = x[2]
|
|
|
|
return o[0], (op, o[1], order)
|
2016-10-01 14:20:11 +03:00
|
|
|
elif op in ('rangepre', 'parentpost'):
|
2016-05-02 06:09:00 +03:00
|
|
|
o = _optimize(x[1], small)
|
2016-08-07 11:46:12 +03:00
|
|
|
order = x[2]
|
|
|
|
return o[0], (op, o[1], order)
|
2016-08-07 10:36:08 +03:00
|
|
|
elif op in ('dagrange', 'range', 'parent', 'ancestor'):
|
2016-05-02 06:09:00 +03:00
|
|
|
wa, ta = _optimize(x[1], small)
|
|
|
|
wb, tb = _optimize(x[2], small)
|
2016-08-07 11:46:12 +03:00
|
|
|
order = x[3]
|
|
|
|
return wa + wb, (op, ta, tb, order)
|
2016-02-02 17:49:49 +03:00
|
|
|
elif op == 'list':
|
2016-05-02 06:09:00 +03:00
|
|
|
ws, ts = zip(*(_optimize(y, small) for y in x[1:]))
|
2016-02-02 17:49:49 +03:00
|
|
|
return sum(ws), (op,) + ts
|
2016-08-07 08:58:49 +03:00
|
|
|
elif op == 'keyvalue':
|
|
|
|
w, t = _optimize(x[2], small)
|
|
|
|
return w, (op, x[1], t)
|
2010-06-01 20:18:57 +04:00
|
|
|
elif op == 'func':
|
2016-06-27 14:44:14 +03:00
|
|
|
f = getsymbol(x[1])
|
2016-05-02 06:09:00 +03:00
|
|
|
wa, ta = _optimize(x[2], small)
|
2016-08-07 10:36:08 +03:00
|
|
|
if f in ('author', 'branch', 'closed', 'date', 'desc', 'file', 'grep',
|
2016-10-17 20:48:36 +03:00
|
|
|
'keyword', 'outgoing', 'user', 'destination'):
|
2010-06-04 02:39:34 +04:00
|
|
|
w = 10 # slow
|
2016-08-07 10:36:08 +03:00
|
|
|
elif f in ('modifies', 'adds', 'removes'):
|
2010-06-04 02:39:34 +04:00
|
|
|
w = 30 # slower
|
2010-06-01 20:18:57 +04:00
|
|
|
elif f == "contains":
|
2010-06-04 02:39:34 +04:00
|
|
|
w = 100 # very slow
|
2010-06-01 20:18:57 +04:00
|
|
|
elif f == "ancestor":
|
2010-06-04 02:39:34 +04:00
|
|
|
w = 1 * smallbonus
|
2016-08-07 10:36:08 +03:00
|
|
|
elif f in ('reverse', 'limit', 'first', '_intlist'):
|
2010-06-04 02:39:34 +04:00
|
|
|
w = 0
|
2016-08-07 10:36:08 +03:00
|
|
|
elif f == "sort":
|
2010-06-04 02:39:34 +04:00
|
|
|
w = 10 # assume most sorts look at changelog
|
2010-06-01 20:18:57 +04:00
|
|
|
else:
|
2010-06-04 02:39:34 +04:00
|
|
|
w = 1
|
2016-08-07 11:46:12 +03:00
|
|
|
order = x[3]
|
|
|
|
return w + wa, (op, x[1], ta, order)
|
2016-08-07 09:01:42 +03:00
|
|
|
raise ValueError('invalid operator %r' % op)
|
2010-06-01 20:18:57 +04:00
|
|
|
|
2016-05-02 06:09:00 +03:00
|
|
|
def optimize(tree):
|
2016-08-21 05:29:57 +03:00
|
|
|
"""Optimize evaluatable tree
|
|
|
|
|
|
|
|
All pseudo operations should be transformed beforehand.
|
|
|
|
"""
|
2016-05-02 06:09:00 +03:00
|
|
|
_weight, newtree = _optimize(tree, small=True)
|
|
|
|
return newtree
|
|
|
|
|
revset: introduce "_parsealiasdecl" to parse alias declarations strictly
This patch introduces "_parsealiasdecl" to parse alias declarations
strictly. For example, "_parsealiasdecl" can detect problems below,
which current implementation can't.
- un-closed parenthesis causes being treated as "alias symbol"
because all of declarations not in "func(....)" style are
recognized as "alias symbol".
for example, "foo($1, $2" is treated as the alias symbol.
- alias symbol/function names aren't examined whether they are valid
as symbol or not
for example, "foo bar" can be treated as the alias symbol, but of
course such invalid symbol can't be referred in revset.
- just splitting argument list by "," causes overlooking syntax
problems in the declaration
for example, all of invalid declarations below are overlooked:
- foo("bar") => taking one argument named as '"bar"'
- foo("unclosed) => taking one argument named as '"unclosed'
- foo(bar::baz) => taking one argument named as 'bar::baz'
- foo(bar($1)) => taking one argument named as 'bar($1)'
To decrease complication of patch, current implementation for alias
declarations is replaced by "_parsealiasdecl" in the subsequent
patch. This patch just introduces it.
This patch defines "_parsealiasdecl" not as a method of "revsetalias"
class but as a one of "revset" module, because of ease of testing by
doctest.
This patch factors some helper functions for "tree" out, because:
- direct accessing like "if tree[0] == 'func' and len(tree) > 1"
decreases readability
- subsequent patch (and also existing code paths, in the future) can
use them for readability
This patch also factors "_tokenizealias" out, because it can be used
also for parsing alias definitions strictly.
2015-01-10 17:18:11 +03:00
|
|
|
# the set of valid characters for the initial letter of symbols in
|
|
|
|
# alias declarations and definitions
|
2016-10-07 15:32:40 +03:00
|
|
|
_aliassyminitletters = _syminitletters | set(pycompat.sysstr('$'))
|
revset: introduce "_parsealiasdecl" to parse alias declarations strictly
This patch introduces "_parsealiasdecl" to parse alias declarations
strictly. For example, "_parsealiasdecl" can detect problems below,
which current implementation can't.
- un-closed parenthesis causes being treated as "alias symbol"
because all of declarations not in "func(....)" style are
recognized as "alias symbol".
for example, "foo($1, $2" is treated as the alias symbol.
- alias symbol/function names aren't examined whether they are valid
as symbol or not
for example, "foo bar" can be treated as the alias symbol, but of
course such invalid symbol can't be referred in revset.
- just splitting argument list by "," causes overlooking syntax
problems in the declaration
for example, all of invalid declarations below are overlooked:
- foo("bar") => taking one argument named as '"bar"'
- foo("unclosed) => taking one argument named as '"unclosed'
- foo(bar::baz) => taking one argument named as 'bar::baz'
- foo(bar($1)) => taking one argument named as 'bar($1)'
To decrease complication of patch, current implementation for alias
declarations is replaced by "_parsealiasdecl" in the subsequent
patch. This patch just introduces it.
This patch defines "_parsealiasdecl" not as a method of "revsetalias"
class but as a one of "revset" module, because of ease of testing by
doctest.
This patch factors some helper functions for "tree" out, because:
- direct accessing like "if tree[0] == 'func' and len(tree) > 1"
decreases readability
- subsequent patch (and also existing code paths, in the future) can
use them for readability
This patch also factors "_tokenizealias" out, because it can be used
also for parsing alias definitions strictly.
2015-01-10 17:18:11 +03:00
|
|
|
|
2016-04-17 07:03:23 +03:00
|
|
|
def _parsewith(spec, lookup=None, syminitletters=None):
|
|
|
|
"""Generate a parse tree of given spec with given tokenizing options
|
revset: introduce "_parsealiasdecl" to parse alias declarations strictly
This patch introduces "_parsealiasdecl" to parse alias declarations
strictly. For example, "_parsealiasdecl" can detect problems below,
which current implementation can't.
- un-closed parenthesis causes being treated as "alias symbol"
because all of declarations not in "func(....)" style are
recognized as "alias symbol".
for example, "foo($1, $2" is treated as the alias symbol.
- alias symbol/function names aren't examined whether they are valid
as symbol or not
for example, "foo bar" can be treated as the alias symbol, but of
course such invalid symbol can't be referred in revset.
- just splitting argument list by "," causes overlooking syntax
problems in the declaration
for example, all of invalid declarations below are overlooked:
- foo("bar") => taking one argument named as '"bar"'
- foo("unclosed) => taking one argument named as '"unclosed'
- foo(bar::baz) => taking one argument named as 'bar::baz'
- foo(bar($1)) => taking one argument named as 'bar($1)'
To decrease complication of patch, current implementation for alias
declarations is replaced by "_parsealiasdecl" in the subsequent
patch. This patch just introduces it.
This patch defines "_parsealiasdecl" not as a method of "revsetalias"
class but as a one of "revset" module, because of ease of testing by
doctest.
This patch factors some helper functions for "tree" out, because:
- direct accessing like "if tree[0] == 'func' and len(tree) > 1"
decreases readability
- subsequent patch (and also existing code paths, in the future) can
use them for readability
This patch also factors "_tokenizealias" out, because it can be used
also for parsing alias definitions strictly.
2015-01-10 17:18:11 +03:00
|
|
|
|
2016-04-17 07:03:23 +03:00
|
|
|
>>> _parsewith('foo($1)', syminitletters=_aliassyminitletters)
|
2016-02-29 11:54:03 +03:00
|
|
|
('func', ('symbol', 'foo'), ('symbol', '$1'))
|
2016-04-17 07:03:23 +03:00
|
|
|
>>> _parsewith('$1')
|
|
|
|
Traceback (most recent call last):
|
|
|
|
...
|
|
|
|
ParseError: ("syntax error in revset '$1'", 0)
|
|
|
|
>>> _parsewith('foo bar')
|
2016-02-29 11:54:03 +03:00
|
|
|
Traceback (most recent call last):
|
|
|
|
...
|
|
|
|
ParseError: ('invalid token', 4)
|
revset: introduce "_parsealiasdecl" to parse alias declarations strictly
This patch introduces "_parsealiasdecl" to parse alias declarations
strictly. For example, "_parsealiasdecl" can detect problems below,
which current implementation can't.
- un-closed parenthesis causes being treated as "alias symbol"
because all of declarations not in "func(....)" style are
recognized as "alias symbol".
for example, "foo($1, $2" is treated as the alias symbol.
- alias symbol/function names aren't examined whether they are valid
as symbol or not
for example, "foo bar" can be treated as the alias symbol, but of
course such invalid symbol can't be referred in revset.
- just splitting argument list by "," causes overlooking syntax
problems in the declaration
for example, all of invalid declarations below are overlooked:
- foo("bar") => taking one argument named as '"bar"'
- foo("unclosed) => taking one argument named as '"unclosed'
- foo(bar::baz) => taking one argument named as 'bar::baz'
- foo(bar($1)) => taking one argument named as 'bar($1)'
To decrease complication of patch, current implementation for alias
declarations is replaced by "_parsealiasdecl" in the subsequent
patch. This patch just introduces it.
This patch defines "_parsealiasdecl" not as a method of "revsetalias"
class but as a one of "revset" module, because of ease of testing by
doctest.
This patch factors some helper functions for "tree" out, because:
- direct accessing like "if tree[0] == 'func' and len(tree) > 1"
decreases readability
- subsequent patch (and also existing code paths, in the future) can
use them for readability
This patch also factors "_tokenizealias" out, because it can be used
also for parsing alias definitions strictly.
2015-01-10 17:18:11 +03:00
|
|
|
"""
|
2015-06-20 18:49:26 +03:00
|
|
|
p = parser.parser(elements)
|
2016-04-17 07:03:23 +03:00
|
|
|
tree, pos = p.parse(tokenize(spec, lookup=lookup,
|
|
|
|
syminitletters=syminitletters))
|
2016-03-28 18:05:14 +03:00
|
|
|
if pos != len(spec):
|
2015-02-02 17:07:04 +03:00
|
|
|
raise error.ParseError(_('invalid token'), pos)
|
2016-08-06 14:21:00 +03:00
|
|
|
return _fixops(parser.simplifyinfixops(tree, ('list', 'or')))
|
2015-02-02 17:07:04 +03:00
|
|
|
|
parser: add stub class that will host alias parsing and expansion
This class will keep syntax rules that are necessary to parse and expand
aliases. The implementations will be extracted from the revset module. In
order to make the porting easier, this class keeps parsedecl and parsedefn
separately, which will be unified later. Also, getlist and funcnode will
be refactored by future patches for better handling of the template aliases.
The following public functions will be added:
aliasrules.build(decl, defn) -> aliasobj
parse decl and defn into an object that keeps alias name, arguments
and replacement tree.
aliasrules.buildmap(aliasitems) -> aliasdict
helper to build() a dict of alias objects from a list of (decl, defn)
aliasrules.expand(aliasdict, tree) -> tree
expand aliases in tree recursively
Because these functions aren't introduced by this series, there would remain
a few wrapper functions in the revset module. These ugly wrappers should be
eliminated by the next series.
This class is considered an inheritable namespace, which will host only
class/static methods. That's because it won't have no object-scope variables.
I'm not a big fan of using class as a syntax sugar, but I admit it can improve
code readability at some level. So let's give it a try.
2016-04-03 10:55:23 +03:00
|
|
|
class _aliasrules(parser.basealiasrules):
|
|
|
|
"""Parsing and expansion rule set of revset aliases"""
|
|
|
|
_section = _('revset alias')
|
2016-04-17 07:06:44 +03:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def _parse(spec):
|
|
|
|
"""Parse alias declaration/definition ``spec``
|
|
|
|
|
|
|
|
This allows symbol names to use also ``$`` as an initial letter
|
|
|
|
(for backward compatibility), and callers of this function should
|
|
|
|
examine whether ``$`` is used also for unexpected symbols or not.
|
|
|
|
"""
|
|
|
|
return _parsewith(spec, syminitletters=_aliassyminitletters)
|
2016-03-29 11:27:34 +03:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def _trygetfunc(tree):
|
|
|
|
if tree[0] == 'func' and tree[1][0] == 'symbol':
|
|
|
|
return tree[1][1], getlist(tree[2])
|
parser: add stub class that will host alias parsing and expansion
This class will keep syntax rules that are necessary to parse and expand
aliases. The implementations will be extracted from the revset module. In
order to make the porting easier, this class keeps parsedecl and parsedefn
separately, which will be unified later. Also, getlist and funcnode will
be refactored by future patches for better handling of the template aliases.
The following public functions will be added:
aliasrules.build(decl, defn) -> aliasobj
parse decl and defn into an object that keeps alias name, arguments
and replacement tree.
aliasrules.buildmap(aliasitems) -> aliasdict
helper to build() a dict of alias objects from a list of (decl, defn)
aliasrules.expand(aliasdict, tree) -> tree
expand aliases in tree recursively
Because these functions aren't introduced by this series, there would remain
a few wrapper functions in the revset module. These ugly wrappers should be
eliminated by the next series.
This class is considered an inheritable namespace, which will host only
class/static methods. That's because it won't have no object-scope variables.
I'm not a big fan of using class as a syntax sugar, but I admit it can improve
code readability at some level. So let's give it a try.
2016-04-03 10:55:23 +03:00
|
|
|
|
2016-09-08 16:44:10 +03:00
|
|
|
def expandaliases(ui, tree):
|
2016-02-29 13:24:15 +03:00
|
|
|
aliases = _aliasrules.buildmap(ui.configitems('revsetalias'))
|
2016-02-29 16:15:44 +03:00
|
|
|
tree = _aliasrules.expand(aliases, tree)
|
2016-09-08 16:44:10 +03:00
|
|
|
# warn about problematic (but not referred) aliases
|
|
|
|
for name, alias in sorted(aliases.iteritems()):
|
|
|
|
if alias.error and not alias.warned:
|
|
|
|
ui.warn(_('warning: %s\n') % (alias.error))
|
|
|
|
alias.warned = True
|
2015-01-05 05:02:04 +03:00
|
|
|
return tree
|
2011-04-30 20:30:14 +04:00
|
|
|
|
revset: introduce new operator "##" to concatenate strings/symbols at runtime
Before this patch, there is no way to concatenate strings at runtime.
For example, to search for the issue ID "1234" in descriptions against
all of "issue 1234", "issue:1234", issue1234" and "bug(1234)"
patterns, the revset below should be written fully from scratch for
each issue ID.
grep(r"\bissue[ :]?1234\b|\bbug\(1234\)")
This patch introduces new infix operator "##" to concatenate
strings/symbols at runtime. Operator symbol "##" comes from the same
one of C pre-processor. This concatenation allows parametrizing a part
of strings in revset queries.
In the case of example above, the definition of the revset alias using
operator "##" below can search issue ID "1234" in complicated patterns
by "issue(1234)" simply:
issue($1) = grep(r"\bissue[ :]?" ## $1 ## r"\b|\bbug\(" ## $1 ## r"\)")
"##" operator does:
- concatenate not only strings but also symbols into the string
Exact distinction between strings and symbols seems not to be
convenience, because it is tiresome for users (and
"revset.getstring" treats both similarly)
For example of revset alias "issue()", "issue(1234)" is easier
than "issue('1234')".
- have higher priority than any other prefix, infix and postfix
operators (like as "##" of C pre-processor)
This patch (re-)assigns the priority 20 to "##", and 21 to "(",
because priority 19 is already assigned to "-" as prefix "negate".
2015-01-06 17:46:18 +03:00
|
|
|
def foldconcat(tree):
|
|
|
|
"""Fold elements to be concatenated by `##`
|
|
|
|
"""
|
|
|
|
if not isinstance(tree, tuple) or tree[0] in ('string', 'symbol'):
|
|
|
|
return tree
|
|
|
|
if tree[0] == '_concat':
|
|
|
|
pending = [tree]
|
|
|
|
l = []
|
|
|
|
while pending:
|
|
|
|
e = pending.pop()
|
|
|
|
if e[0] == '_concat':
|
|
|
|
pending.extend(reversed(e[1:]))
|
|
|
|
elif e[0] in ('string', 'symbol'):
|
|
|
|
l.append(e[1])
|
|
|
|
else:
|
|
|
|
msg = _("\"##\" can't concatenate \"%s\" element") % (e[0])
|
|
|
|
raise error.ParseError(msg)
|
|
|
|
return ('string', ''.join(l))
|
|
|
|
else:
|
|
|
|
return tuple(foldconcat(t) for t in tree)
|
|
|
|
|
2014-03-19 02:19:44 +04:00
|
|
|
def parse(spec, lookup=None):
|
2016-04-17 07:03:23 +03:00
|
|
|
return _parsewith(spec, lookup=lookup)
|
2010-06-01 20:18:57 +04:00
|
|
|
|
2015-03-25 00:24:55 +03:00
|
|
|
def posttreebuilthook(tree, repo):
|
|
|
|
# hook for extensions to execute code on the optimized tree
|
|
|
|
pass
|
|
|
|
|
2016-05-03 08:18:28 +03:00
|
|
|
def match(ui, spec, repo=None, order=defineorder):
|
|
|
|
"""Create a matcher for a single revision spec
|
2015-08-07 15:31:16 +03:00
|
|
|
|
2016-05-03 08:18:28 +03:00
|
|
|
If order=followorder, a matcher takes the ordering specified by the input
|
|
|
|
set.
|
|
|
|
"""
|
|
|
|
return matchany(ui, [spec], repo=repo, order=order)
|
|
|
|
|
|
|
|
def matchany(ui, specs, repo=None, order=defineorder):
|
2015-08-07 15:39:38 +03:00
|
|
|
"""Create a matcher that will include any revisions matching one of the
|
2016-05-03 08:18:28 +03:00
|
|
|
given specs
|
|
|
|
|
|
|
|
If order=followorder, a matcher takes the ordering specified by the input
|
|
|
|
set.
|
|
|
|
"""
|
2015-08-07 15:39:38 +03:00
|
|
|
if not specs:
|
|
|
|
def mfunc(repo, subset=None):
|
|
|
|
return baseset()
|
|
|
|
return mfunc
|
|
|
|
if not all(specs):
|
|
|
|
raise error.ParseError(_("empty query"))
|
|
|
|
lookup = None
|
|
|
|
if repo:
|
|
|
|
lookup = repo.__contains__
|
|
|
|
if len(specs) == 1:
|
|
|
|
tree = parse(specs[0], lookup)
|
|
|
|
else:
|
2016-08-07 11:04:05 +03:00
|
|
|
tree = ('or', ('list',) + tuple(parse(s, lookup) for s in specs))
|
2015-08-07 15:39:38 +03:00
|
|
|
|
2011-07-21 23:04:57 +04:00
|
|
|
if ui:
|
2016-09-08 16:44:10 +03:00
|
|
|
tree = expandaliases(ui, tree)
|
revset: introduce new operator "##" to concatenate strings/symbols at runtime
Before this patch, there is no way to concatenate strings at runtime.
For example, to search for the issue ID "1234" in descriptions against
all of "issue 1234", "issue:1234", issue1234" and "bug(1234)"
patterns, the revset below should be written fully from scratch for
each issue ID.
grep(r"\bissue[ :]?1234\b|\bbug\(1234\)")
This patch introduces new infix operator "##" to concatenate
strings/symbols at runtime. Operator symbol "##" comes from the same
one of C pre-processor. This concatenation allows parametrizing a part
of strings in revset queries.
In the case of example above, the definition of the revset alias using
operator "##" below can search issue ID "1234" in complicated patterns
by "issue(1234)" simply:
issue($1) = grep(r"\bissue[ :]?" ## $1 ## r"\b|\bbug\(" ## $1 ## r"\)")
"##" operator does:
- concatenate not only strings but also symbols into the string
Exact distinction between strings and symbols seems not to be
convenience, because it is tiresome for users (and
"revset.getstring" treats both similarly)
For example of revset alias "issue()", "issue(1234)" is easier
than "issue('1234')".
- have higher priority than any other prefix, infix and postfix
operators (like as "##" of C pre-processor)
This patch (re-)assigns the priority 20 to "##", and 21 to "(",
because priority 19 is already assigned to "-" as prefix "negate".
2015-01-06 17:46:18 +03:00
|
|
|
tree = foldconcat(tree)
|
2016-05-03 08:18:28 +03:00
|
|
|
tree = analyze(tree, order)
|
2016-05-02 06:09:00 +03:00
|
|
|
tree = optimize(tree)
|
2015-03-25 00:24:55 +03:00
|
|
|
posttreebuilthook(tree, repo)
|
2016-08-21 05:37:00 +03:00
|
|
|
return makematcher(tree)
|
|
|
|
|
|
|
|
def makematcher(tree):
|
|
|
|
"""Create a matcher from an evaluatable tree"""
|
2015-02-02 16:21:07 +03:00
|
|
|
def mfunc(repo, subset=None):
|
|
|
|
if subset is None:
|
2015-01-08 17:46:54 +03:00
|
|
|
subset = fullreposet(repo)
|
2014-10-11 01:27:05 +04:00
|
|
|
if util.safehasattr(subset, 'isascending'):
|
2014-09-30 21:39:21 +04:00
|
|
|
result = getset(repo, subset, tree)
|
|
|
|
else:
|
|
|
|
result = getset(repo, baseset(subset), tree)
|
|
|
|
return result
|
2010-06-01 20:18:57 +04:00
|
|
|
return mfunc
|
2010-10-23 21:21:51 +04:00
|
|
|
|
2011-07-21 23:05:45 +04:00
|
|
|
def formatspec(expr, *args):
|
|
|
|
'''
|
|
|
|
This is a convenience function for using revsets internally, and
|
|
|
|
escapes arguments appropriately. Aliases are intentionally ignored
|
|
|
|
so that intended expression behavior isn't accidentally subverted.
|
|
|
|
|
|
|
|
Supported arguments:
|
|
|
|
|
2011-10-15 19:20:08 +04:00
|
|
|
%r = revset expression, parenthesized
|
2011-07-21 23:05:45 +04:00
|
|
|
%d = int(arg), no quoting
|
|
|
|
%s = string(arg), escaped and single-quoted
|
|
|
|
%b = arg.branch(), escaped and single-quoted
|
|
|
|
%n = hex(arg), single-quoted
|
|
|
|
%% = a literal '%'
|
|
|
|
|
2011-10-15 19:20:08 +04:00
|
|
|
Prefixing the type with 'l' specifies a parenthesized list of that type.
|
2011-09-20 01:28:44 +04:00
|
|
|
|
2011-10-15 21:52:43 +04:00
|
|
|
>>> formatspec('%r:: and %lr', '10 or 11', ("this()", "that()"))
|
|
|
|
'(10 or 11):: and ((this()) or (that()))'
|
2011-07-21 23:05:45 +04:00
|
|
|
>>> formatspec('%d:: and not %d::', 10, 20)
|
|
|
|
'10:: and not 20::'
|
2011-10-21 21:12:21 +04:00
|
|
|
>>> formatspec('%ld or %ld', [], [1])
|
2012-01-16 11:21:22 +04:00
|
|
|
"_list('') or 1"
|
2011-07-21 23:05:45 +04:00
|
|
|
>>> formatspec('keyword(%s)', 'foo\\xe9')
|
|
|
|
"keyword('foo\\\\xe9')"
|
|
|
|
>>> b = lambda: 'default'
|
|
|
|
>>> b.branch = b
|
|
|
|
>>> formatspec('branch(%b)', b)
|
|
|
|
"branch('default')"
|
2011-09-20 01:28:44 +04:00
|
|
|
>>> formatspec('root(%ls)', ['a', 'b', 'c', 'd'])
|
2012-01-16 11:21:22 +04:00
|
|
|
"root(_list('a\\x00b\\x00c\\x00d'))"
|
2011-07-21 23:05:45 +04:00
|
|
|
'''
|
|
|
|
|
|
|
|
def quote(s):
|
|
|
|
return repr(str(s))
|
|
|
|
|
2011-09-20 01:28:44 +04:00
|
|
|
def argtype(c, arg):
|
|
|
|
if c == 'd':
|
|
|
|
return str(int(arg))
|
|
|
|
elif c == 's':
|
|
|
|
return quote(arg)
|
2011-10-15 19:20:08 +04:00
|
|
|
elif c == 'r':
|
|
|
|
parse(arg) # make sure syntax errors are confined
|
|
|
|
return '(%s)' % arg
|
2011-09-20 01:28:44 +04:00
|
|
|
elif c == 'n':
|
2012-04-14 00:32:49 +04:00
|
|
|
return quote(node.hex(arg))
|
2011-09-20 01:28:44 +04:00
|
|
|
elif c == 'b':
|
|
|
|
return quote(arg.branch())
|
|
|
|
|
2011-12-01 08:43:24 +04:00
|
|
|
def listexp(s, t):
|
|
|
|
l = len(s)
|
|
|
|
if l == 0:
|
2012-01-16 11:21:22 +04:00
|
|
|
return "_list('')"
|
|
|
|
elif l == 1:
|
2011-12-01 08:43:24 +04:00
|
|
|
return argtype(t, s[0])
|
2012-01-16 11:21:22 +04:00
|
|
|
elif t == 'd':
|
2014-02-27 00:36:36 +04:00
|
|
|
return "_intlist('%s')" % "\0".join(str(int(a)) for a in s)
|
2012-01-16 11:21:22 +04:00
|
|
|
elif t == 's':
|
|
|
|
return "_list('%s')" % "\0".join(s)
|
|
|
|
elif t == 'n':
|
2014-02-27 05:15:55 +04:00
|
|
|
return "_hexlist('%s')" % "\0".join(node.hex(a) for a in s)
|
2012-01-16 11:21:22 +04:00
|
|
|
elif t == 'b':
|
|
|
|
return "_list('%s')" % "\0".join(a.branch() for a in s)
|
|
|
|
|
2012-01-08 21:15:54 +04:00
|
|
|
m = l // 2
|
2011-12-01 08:43:24 +04:00
|
|
|
return '(%s or %s)' % (listexp(s[:m], t), listexp(s[m:], t))
|
|
|
|
|
2011-07-21 23:05:45 +04:00
|
|
|
ret = ''
|
|
|
|
pos = 0
|
|
|
|
arg = 0
|
|
|
|
while pos < len(expr):
|
|
|
|
c = expr[pos]
|
|
|
|
if c == '%':
|
|
|
|
pos += 1
|
|
|
|
d = expr[pos]
|
|
|
|
if d == '%':
|
|
|
|
ret += d
|
2011-10-15 21:52:43 +04:00
|
|
|
elif d in 'dsnbr':
|
2011-09-20 01:28:44 +04:00
|
|
|
ret += argtype(d, args[arg])
|
2011-07-21 23:05:45 +04:00
|
|
|
arg += 1
|
2011-09-20 01:28:44 +04:00
|
|
|
elif d == 'l':
|
|
|
|
# a list of some type
|
|
|
|
pos += 1
|
|
|
|
d = expr[pos]
|
2011-12-01 11:42:03 +04:00
|
|
|
ret += listexp(list(args[arg]), d)
|
2011-07-21 23:05:45 +04:00
|
|
|
arg += 1
|
|
|
|
else:
|
2016-06-14 12:53:55 +03:00
|
|
|
raise error.Abort(_('unexpected revspec format character %s')
|
|
|
|
% d)
|
2011-07-21 23:05:45 +04:00
|
|
|
else:
|
|
|
|
ret += c
|
|
|
|
pos += 1
|
|
|
|
|
|
|
|
return ret
|
|
|
|
|
debugrevspec: pretty print output
Before:
('func', ('symbol', 'reverse'), ('func', ('symbol', 'sort'), ('list', ('or',
('symbol', '2'), ('symbol', '3')), ('symbol', 'date'))))
After:
(func
('symbol', 'reverse')
(func
('symbol', 'sort')
(list
(or
('symbol', '2')
('symbol', '3'))
('symbol', 'date'))))
v2:
- Rebased on stable to avoid having to merge tests output
2012-02-24 14:02:21 +04:00
|
|
|
def prettyformat(tree):
|
2015-04-26 16:20:03 +03:00
|
|
|
return parser.prettyformat(tree, ('string', 'symbol'))
|
debugrevspec: pretty print output
Before:
('func', ('symbol', 'reverse'), ('func', ('symbol', 'sort'), ('list', ('or',
('symbol', '2'), ('symbol', '3')), ('symbol', 'date'))))
After:
(func
('symbol', 'reverse')
(func
('symbol', 'sort')
(list
(or
('symbol', '2')
('symbol', '3'))
('symbol', 'date'))))
v2:
- Rebased on stable to avoid having to merge tests output
2012-02-24 14:02:21 +04:00
|
|
|
|
2013-08-09 22:52:58 +04:00
|
|
|
def depth(tree):
|
|
|
|
if isinstance(tree, tuple):
|
|
|
|
return max(map(depth, tree)) + 1
|
|
|
|
else:
|
|
|
|
return 0
|
|
|
|
|
2013-08-07 01:21:31 +04:00
|
|
|
def funcsused(tree):
|
|
|
|
if not isinstance(tree, tuple) or tree[0] in ('string', 'symbol'):
|
|
|
|
return set()
|
|
|
|
else:
|
|
|
|
funcs = set()
|
|
|
|
for s in tree[1:]:
|
|
|
|
funcs |= funcsused(s)
|
|
|
|
if tree[0] == 'func':
|
|
|
|
funcs.add(tree[1][1])
|
|
|
|
return funcs
|
|
|
|
|
2016-02-13 13:25:11 +03:00
|
|
|
def _formatsetrepr(r):
|
|
|
|
"""Format an optional printable representation of a set
|
|
|
|
|
|
|
|
======== =================================
|
|
|
|
type(r) example
|
|
|
|
======== =================================
|
|
|
|
tuple ('<not %r>', other)
|
|
|
|
str '<branch closed>'
|
|
|
|
callable lambda: '<branch %r>' % sorted(b)
|
|
|
|
object other
|
|
|
|
======== =================================
|
|
|
|
"""
|
|
|
|
if r is None:
|
|
|
|
return ''
|
|
|
|
elif isinstance(r, tuple):
|
|
|
|
return r[0] % r[1:]
|
|
|
|
elif isinstance(r, str):
|
|
|
|
return r
|
|
|
|
elif callable(r):
|
|
|
|
return r()
|
|
|
|
else:
|
|
|
|
return repr(r)
|
|
|
|
|
2014-10-02 00:14:36 +04:00
|
|
|
class abstractsmartset(object):
|
|
|
|
|
|
|
|
def __nonzero__(self):
|
|
|
|
"""True if the smartset is not empty"""
|
|
|
|
raise NotImplementedError()
|
|
|
|
|
|
|
|
def __contains__(self, rev):
|
|
|
|
"""provide fast membership testing"""
|
|
|
|
raise NotImplementedError()
|
|
|
|
|
|
|
|
def __iter__(self):
|
|
|
|
"""iterate the set in the order it is supposed to be iterated"""
|
|
|
|
raise NotImplementedError()
|
|
|
|
|
2014-10-01 07:26:34 +04:00
|
|
|
# Attributes containing a function to perform a fast iteration in a given
|
|
|
|
# direction. A smartset can have none, one, or both defined.
|
|
|
|
#
|
|
|
|
# Default value is None instead of a function returning None to avoid
|
|
|
|
# initializing an iterator just for testing if a fast method exists.
|
|
|
|
fastasc = None
|
|
|
|
fastdesc = None
|
|
|
|
|
2014-10-02 00:14:36 +04:00
|
|
|
def isascending(self):
|
|
|
|
"""True if the set will iterate in ascending order"""
|
|
|
|
raise NotImplementedError()
|
|
|
|
|
|
|
|
def isdescending(self):
|
|
|
|
"""True if the set will iterate in descending order"""
|
|
|
|
raise NotImplementedError()
|
|
|
|
|
2016-06-14 13:05:36 +03:00
|
|
|
def istopo(self):
|
|
|
|
"""True if the set will iterate in topographical order"""
|
|
|
|
raise NotImplementedError()
|
|
|
|
|
2015-08-28 03:57:33 +03:00
|
|
|
@util.cachefunc
|
2014-10-02 00:14:36 +04:00
|
|
|
def min(self):
|
|
|
|
"""return the minimum element in the set"""
|
2014-10-03 03:59:41 +04:00
|
|
|
if self.fastasc is not None:
|
|
|
|
for r in self.fastasc():
|
|
|
|
return r
|
|
|
|
raise ValueError('arg is an empty sequence')
|
|
|
|
return min(self)
|
2014-10-02 00:14:36 +04:00
|
|
|
|
2015-08-28 03:57:33 +03:00
|
|
|
@util.cachefunc
|
2014-10-02 00:14:36 +04:00
|
|
|
def max(self):
|
|
|
|
"""return the maximum element in the set"""
|
2014-10-03 03:59:41 +04:00
|
|
|
if self.fastdesc is not None:
|
|
|
|
for r in self.fastdesc():
|
|
|
|
return r
|
|
|
|
raise ValueError('arg is an empty sequence')
|
|
|
|
return max(self)
|
2014-10-02 00:14:36 +04:00
|
|
|
|
2014-10-06 22:46:53 +04:00
|
|
|
def first(self):
|
|
|
|
"""return the first element in the set (user iteration perspective)
|
|
|
|
|
|
|
|
Return None if the set is empty"""
|
|
|
|
raise NotImplementedError()
|
|
|
|
|
|
|
|
def last(self):
|
|
|
|
"""return the last element in the set (user iteration perspective)
|
|
|
|
|
|
|
|
Return None if the set is empty"""
|
|
|
|
raise NotImplementedError()
|
|
|
|
|
2014-10-15 15:26:23 +04:00
|
|
|
def __len__(self):
|
|
|
|
"""return the length of the smartsets
|
|
|
|
|
|
|
|
This can be expensive on smartset that could be lazy otherwise."""
|
|
|
|
raise NotImplementedError()
|
|
|
|
|
2014-10-02 00:14:36 +04:00
|
|
|
def reverse(self):
|
|
|
|
"""reverse the expected iteration order"""
|
|
|
|
raise NotImplementedError()
|
|
|
|
|
|
|
|
def sort(self, reverse=True):
|
|
|
|
"""get the set to iterate in an ascending or descending order"""
|
|
|
|
raise NotImplementedError()
|
|
|
|
|
|
|
|
def __and__(self, other):
|
|
|
|
"""Returns a new object with the intersection of the two collections.
|
|
|
|
|
|
|
|
This is part of the mandatory API for smartset."""
|
2015-03-16 11:11:25 +03:00
|
|
|
if isinstance(other, fullreposet):
|
|
|
|
return self
|
2016-02-13 13:25:11 +03:00
|
|
|
return self.filter(other.__contains__, condrepr=other, cache=False)
|
2014-10-02 00:14:36 +04:00
|
|
|
|
|
|
|
def __add__(self, other):
|
|
|
|
"""Returns a new object with the union of the two collections.
|
|
|
|
|
|
|
|
This is part of the mandatory API for smartset."""
|
2014-10-09 15:24:51 +04:00
|
|
|
return addset(self, other)
|
2014-10-02 00:14:36 +04:00
|
|
|
|
|
|
|
def __sub__(self, other):
|
|
|
|
"""Returns a new object with the substraction of the two collections.
|
|
|
|
|
|
|
|
This is part of the mandatory API for smartset."""
|
2014-10-03 04:22:17 +04:00
|
|
|
c = other.__contains__
|
2016-02-13 13:25:11 +03:00
|
|
|
return self.filter(lambda r: not c(r), condrepr=('<not %r>', other),
|
|
|
|
cache=False)
|
2014-10-02 00:14:36 +04:00
|
|
|
|
2016-02-13 13:25:11 +03:00
|
|
|
def filter(self, condition, condrepr=None, cache=True):
|
2014-10-02 00:14:36 +04:00
|
|
|
"""Returns this smartset filtered by condition as a new smartset.
|
|
|
|
|
|
|
|
`condition` is a callable which takes a revision number and returns a
|
2016-02-13 13:25:11 +03:00
|
|
|
boolean. Optional `condrepr` provides a printable representation of
|
|
|
|
the given `condition`.
|
2014-10-02 00:14:36 +04:00
|
|
|
|
|
|
|
This is part of the mandatory API for smartset."""
|
2014-10-10 09:57:52 +04:00
|
|
|
# builtin cannot be cached. but do not needs to
|
|
|
|
if cache and util.safehasattr(condition, 'func_code'):
|
|
|
|
condition = util.cachefunc(condition)
|
2016-02-13 13:25:11 +03:00
|
|
|
return filteredset(self, condition, condrepr)
|
2014-10-02 00:14:36 +04:00
|
|
|
|
2014-10-06 22:03:30 +04:00
|
|
|
class baseset(abstractsmartset):
|
2014-02-06 23:33:36 +04:00
|
|
|
"""Basic data structure that represents a revset and contains the basic
|
|
|
|
operation that it should be able to perform.
|
2014-03-14 20:18:14 +04:00
|
|
|
|
|
|
|
Every method in this class should be implemented by any smartset class.
|
2014-02-06 23:33:36 +04:00
|
|
|
"""
|
2016-06-14 13:05:36 +03:00
|
|
|
def __init__(self, data=(), datarepr=None, istopo=False):
|
2016-02-16 15:32:00 +03:00
|
|
|
"""
|
|
|
|
datarepr: a tuple of (format, obj, ...), a function or an object that
|
|
|
|
provides a printable representation of the given data.
|
|
|
|
"""
|
2016-04-05 03:45:54 +03:00
|
|
|
self._ascending = None
|
2016-06-14 13:05:36 +03:00
|
|
|
self._istopo = istopo
|
2014-10-06 22:03:30 +04:00
|
|
|
if not isinstance(data, list):
|
2015-08-21 03:19:56 +03:00
|
|
|
if isinstance(data, set):
|
|
|
|
self._set = data
|
2016-04-05 03:45:54 +03:00
|
|
|
# set has no order we pick one for stability purpose
|
|
|
|
self._ascending = True
|
2014-10-06 22:03:30 +04:00
|
|
|
data = list(data)
|
|
|
|
self._list = data
|
2016-02-16 15:32:00 +03:00
|
|
|
self._datarepr = datarepr
|
2014-01-22 22:46:02 +04:00
|
|
|
|
2014-10-10 23:30:56 +04:00
|
|
|
@util.propertycache
|
|
|
|
def _set(self):
|
|
|
|
return set(self._list)
|
|
|
|
|
2014-10-03 12:19:23 +04:00
|
|
|
@util.propertycache
|
|
|
|
def _asclist(self):
|
|
|
|
asclist = self._list[:]
|
|
|
|
asclist.sort()
|
|
|
|
return asclist
|
|
|
|
|
2014-10-03 12:26:18 +04:00
|
|
|
def __iter__(self):
|
|
|
|
if self._ascending is None:
|
|
|
|
return iter(self._list)
|
|
|
|
elif self._ascending:
|
|
|
|
return iter(self._asclist)
|
|
|
|
else:
|
|
|
|
return reversed(self._asclist)
|
|
|
|
|
2014-10-03 12:19:23 +04:00
|
|
|
def fastasc(self):
|
|
|
|
return iter(self._asclist)
|
|
|
|
|
|
|
|
def fastdesc(self):
|
|
|
|
return reversed(self._asclist)
|
|
|
|
|
2014-09-17 10:59:29 +04:00
|
|
|
@util.propertycache
|
|
|
|
def __contains__(self):
|
2014-10-10 23:31:22 +04:00
|
|
|
return self._set.__contains__
|
2014-09-17 10:59:29 +04:00
|
|
|
|
2014-10-02 00:03:16 +04:00
|
|
|
def __nonzero__(self):
|
2014-10-06 22:03:30 +04:00
|
|
|
return bool(self._list)
|
|
|
|
|
|
|
|
def sort(self, reverse=False):
|
2014-10-03 12:29:55 +04:00
|
|
|
self._ascending = not bool(reverse)
|
2016-06-14 13:05:36 +03:00
|
|
|
self._istopo = False
|
2014-10-06 22:03:30 +04:00
|
|
|
|
|
|
|
def reverse(self):
|
2014-10-03 12:29:55 +04:00
|
|
|
if self._ascending is None:
|
|
|
|
self._list.reverse()
|
|
|
|
else:
|
|
|
|
self._ascending = not self._ascending
|
2016-06-14 13:05:36 +03:00
|
|
|
self._istopo = False
|
2014-10-06 22:03:30 +04:00
|
|
|
|
|
|
|
def __len__(self):
|
|
|
|
return len(self._list)
|
2014-10-02 00:03:16 +04:00
|
|
|
|
2014-03-12 04:09:23 +04:00
|
|
|
def isascending(self):
|
2014-03-14 20:18:14 +04:00
|
|
|
"""Returns True if the collection is ascending order, False if not.
|
|
|
|
|
|
|
|
This is part of the mandatory API for smartset."""
|
2014-10-09 15:12:20 +04:00
|
|
|
if len(self) <= 1:
|
|
|
|
return True
|
2014-10-03 12:31:05 +04:00
|
|
|
return self._ascending is not None and self._ascending
|
2014-03-12 04:09:23 +04:00
|
|
|
|
|
|
|
def isdescending(self):
|
2014-03-14 20:18:14 +04:00
|
|
|
"""Returns True if the collection is descending order, False if not.
|
|
|
|
|
|
|
|
This is part of the mandatory API for smartset."""
|
2014-10-09 15:12:20 +04:00
|
|
|
if len(self) <= 1:
|
|
|
|
return True
|
2014-10-03 12:31:05 +04:00
|
|
|
return self._ascending is not None and not self._ascending
|
2014-03-12 04:09:23 +04:00
|
|
|
|
2016-06-14 13:05:36 +03:00
|
|
|
def istopo(self):
|
|
|
|
"""Is the collection is in topographical order or not.
|
|
|
|
|
|
|
|
This is part of the mandatory API for smartset."""
|
|
|
|
if len(self) <= 1:
|
|
|
|
return True
|
|
|
|
return self._istopo
|
|
|
|
|
2014-10-07 01:42:00 +04:00
|
|
|
def first(self):
|
|
|
|
if self:
|
2014-10-03 12:29:55 +04:00
|
|
|
if self._ascending is None:
|
|
|
|
return self._list[0]
|
|
|
|
elif self._ascending:
|
|
|
|
return self._asclist[0]
|
|
|
|
else:
|
|
|
|
return self._asclist[-1]
|
2014-10-07 01:42:00 +04:00
|
|
|
return None
|
|
|
|
|
|
|
|
def last(self):
|
|
|
|
if self:
|
2014-10-03 12:29:55 +04:00
|
|
|
if self._ascending is None:
|
|
|
|
return self._list[-1]
|
|
|
|
elif self._ascending:
|
|
|
|
return self._asclist[-1]
|
|
|
|
else:
|
|
|
|
return self._asclist[0]
|
2014-10-07 01:42:00 +04:00
|
|
|
return None
|
|
|
|
|
2015-03-16 12:15:06 +03:00
|
|
|
def __repr__(self):
|
|
|
|
d = {None: '', False: '-', True: '+'}[self._ascending]
|
2016-02-16 15:32:00 +03:00
|
|
|
s = _formatsetrepr(self._datarepr)
|
|
|
|
if not s:
|
2016-04-05 03:45:15 +03:00
|
|
|
l = self._list
|
|
|
|
# if _list has been built from a set, it might have a different
|
|
|
|
# order from one python implementation to another.
|
|
|
|
# We fallback to the sorted version for a stable output.
|
|
|
|
if self._ascending is not None:
|
|
|
|
l = self._asclist
|
|
|
|
s = repr(l)
|
2016-02-16 15:32:00 +03:00
|
|
|
return '<%s%s %s>' % (type(self).__name__, d, s)
|
2015-03-16 12:15:06 +03:00
|
|
|
|
2014-10-03 10:16:23 +04:00
|
|
|
class filteredset(abstractsmartset):
|
2014-02-07 02:19:40 +04:00
|
|
|
"""Duck type for baseset class which iterates lazily over the revisions in
|
|
|
|
the subset and contains a function which tests for membership in the
|
|
|
|
revset
|
|
|
|
"""
|
2016-02-13 13:25:11 +03:00
|
|
|
def __init__(self, subset, condition=lambda x: True, condrepr=None):
|
2014-03-14 21:55:03 +04:00
|
|
|
"""
|
|
|
|
condition: a function that decide whether a revision in the subset
|
|
|
|
belongs to the revset or not.
|
2016-02-13 13:25:11 +03:00
|
|
|
condrepr: a tuple of (format, obj, ...), a function or an object that
|
|
|
|
provides a printable representation of the given condition.
|
2014-03-14 21:55:03 +04:00
|
|
|
"""
|
2014-02-07 02:19:40 +04:00
|
|
|
self._subset = subset
|
|
|
|
self._condition = condition
|
2016-02-13 13:25:11 +03:00
|
|
|
self._condrepr = condrepr
|
2014-02-07 02:19:40 +04:00
|
|
|
|
|
|
|
def __contains__(self, x):
|
2015-09-05 06:56:53 +03:00
|
|
|
return x in self._subset and self._condition(x)
|
2014-02-07 02:19:40 +04:00
|
|
|
|
|
|
|
def __iter__(self):
|
2014-10-03 03:25:37 +04:00
|
|
|
return self._iterfilter(self._subset)
|
|
|
|
|
|
|
|
def _iterfilter(self, it):
|
2014-02-07 02:19:40 +04:00
|
|
|
cond = self._condition
|
2014-10-03 03:25:37 +04:00
|
|
|
for x in it:
|
2014-02-07 02:19:40 +04:00
|
|
|
if cond(x):
|
|
|
|
yield x
|
|
|
|
|
2014-10-01 08:36:57 +04:00
|
|
|
@property
|
|
|
|
def fastasc(self):
|
|
|
|
it = self._subset.fastasc
|
|
|
|
if it is None:
|
|
|
|
return None
|
|
|
|
return lambda: self._iterfilter(it())
|
|
|
|
|
|
|
|
@property
|
|
|
|
def fastdesc(self):
|
|
|
|
it = self._subset.fastdesc
|
|
|
|
if it is None:
|
|
|
|
return None
|
|
|
|
return lambda: self._iterfilter(it())
|
|
|
|
|
2014-02-20 22:15:38 +04:00
|
|
|
def __nonzero__(self):
|
revset: make filteredset.__nonzero__ respect the order of the filteredset
This fix allows __nonzero__ to respect the direction of iteration of the
whole filteredset. Here's the case when it matters. Imagine that we have a
very large repository and we want to execute a command like:
$ hg log --rev '(tip:0) and user(ikostia)' --limit 1
(we want to get the latest commit by me).
Mercurial will evaluate a filteredset lazy data structure, an
instance of the filteredset class, which will know that it has to iterate
in a descending order (isdescending() will return True if called). This
means that when some code iterates over the instance of this filteredset,
the 'and user(ikostia)' condition will be first checked on the latest
revision, then on the second latest and so on, allowing Mercurial to
print matches as it founds them. However, cmdutil.getgraphlogrevs
contains the following code:
revs = _logrevs(repo, opts)
if not revs:
return revset.baseset(), None, None
The "not revs" expression is evaluated by calling filteredset.__nonzero__,
which in its current implementation will try to iterate the filteredset
in ascending order until it finds a revision that matches the 'and user(..'
condition. If the condition is only true on late revisions, a lot of
useless iterations will be done. These iterations could be avoided if
__nonzero__ followed the order of the filteredset, which in my opinion
is a sensible thing to do here.
The problem gets even worse when instead of 'user(ikostia)' some more
expensive check is performed, like grepping the commit diff.
I tested this fix on a very large repo where tip is my commit and my very
first commit comes fairly late in the revision history. Results of timing
of the above command on that very large repo.
-with my fix:
real 0m1.795s
user 0m1.657s
sys 0m0.135s
-without my fix:
real 1m29.245s
user 1m28.223s
sys 0m0.929s
I understand that this is a very specific kind of problem that presents
itself very rarely, only on very big repositories and with expensive
checks and so on. But I don't see any disadvantages to this kind of fix
either.
2016-06-03 00:39:01 +03:00
|
|
|
fast = None
|
|
|
|
candidates = [self.fastasc if self.isascending() else None,
|
|
|
|
self.fastdesc if self.isdescending() else None,
|
|
|
|
self.fastasc,
|
|
|
|
self.fastdesc]
|
|
|
|
for candidate in candidates:
|
|
|
|
if candidate is not None:
|
|
|
|
fast = candidate
|
|
|
|
break
|
|
|
|
|
2015-09-23 10:41:07 +03:00
|
|
|
if fast is not None:
|
2015-09-21 02:53:42 +03:00
|
|
|
it = fast()
|
2015-09-23 10:41:07 +03:00
|
|
|
else:
|
|
|
|
it = self
|
2015-09-21 02:53:42 +03:00
|
|
|
|
|
|
|
for r in it:
|
2014-02-20 22:15:38 +04:00
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
2014-02-07 02:29:37 +04:00
|
|
|
def __len__(self):
|
|
|
|
# Basic implementation to be changed in future patches.
|
2016-04-01 11:09:34 +03:00
|
|
|
# until this gets improved, we use generator expression
|
|
|
|
# here, since list compr is free to call __len__ again
|
|
|
|
# causing infinite recursion
|
|
|
|
l = baseset(r for r in self)
|
2014-02-07 02:29:37 +04:00
|
|
|
return len(l)
|
|
|
|
|
|
|
|
def sort(self, reverse=False):
|
2014-10-07 12:33:05 +04:00
|
|
|
self._subset.sort(reverse=reverse)
|
2014-02-07 02:29:37 +04:00
|
|
|
|
|
|
|
def reverse(self):
|
|
|
|
self._subset.reverse()
|
|
|
|
|
2014-03-12 04:09:23 +04:00
|
|
|
def isascending(self):
|
2014-10-07 12:33:05 +04:00
|
|
|
return self._subset.isascending()
|
2014-03-12 04:09:23 +04:00
|
|
|
|
|
|
|
def isdescending(self):
|
2014-10-07 12:33:05 +04:00
|
|
|
return self._subset.isdescending()
|
2014-03-12 04:09:23 +04:00
|
|
|
|
2016-06-14 13:05:36 +03:00
|
|
|
def istopo(self):
|
|
|
|
return self._subset.istopo()
|
|
|
|
|
2014-10-07 11:18:08 +04:00
|
|
|
def first(self):
|
|
|
|
for x in self:
|
|
|
|
return x
|
|
|
|
return None
|
|
|
|
|
|
|
|
def last(self):
|
|
|
|
it = None
|
2015-06-22 23:48:01 +03:00
|
|
|
if self.isascending():
|
2014-10-07 12:33:05 +04:00
|
|
|
it = self.fastdesc
|
2015-06-22 23:48:01 +03:00
|
|
|
elif self.isdescending():
|
|
|
|
it = self.fastasc
|
|
|
|
if it is not None:
|
|
|
|
for x in it():
|
|
|
|
return x
|
|
|
|
return None #empty case
|
|
|
|
else:
|
|
|
|
x = None
|
|
|
|
for x in self:
|
|
|
|
pass
|
2014-10-07 11:18:08 +04:00
|
|
|
return x
|
|
|
|
|
2015-03-16 12:15:06 +03:00
|
|
|
def __repr__(self):
|
2016-02-13 13:25:11 +03:00
|
|
|
xs = [repr(self._subset)]
|
|
|
|
s = _formatsetrepr(self._condrepr)
|
|
|
|
if s:
|
|
|
|
xs.append(s)
|
|
|
|
return '<%s %s>' % (type(self).__name__, ', '.join(xs))
|
2015-03-16 12:15:06 +03:00
|
|
|
|
2015-05-16 15:42:09 +03:00
|
|
|
def _iterordered(ascending, iter1, iter2):
|
|
|
|
"""produce an ordered iteration from two iterators with the same order
|
|
|
|
|
|
|
|
The ascending is used to indicated the iteration direction.
|
|
|
|
"""
|
|
|
|
choice = max
|
|
|
|
if ascending:
|
|
|
|
choice = min
|
|
|
|
|
|
|
|
val1 = None
|
|
|
|
val2 = None
|
|
|
|
try:
|
|
|
|
# Consume both iterators in an ordered way until one is empty
|
|
|
|
while True:
|
|
|
|
if val1 is None:
|
2016-05-17 00:30:53 +03:00
|
|
|
val1 = next(iter1)
|
2015-05-16 15:42:09 +03:00
|
|
|
if val2 is None:
|
2016-05-17 00:30:53 +03:00
|
|
|
val2 = next(iter2)
|
2016-05-17 00:30:32 +03:00
|
|
|
n = choice(val1, val2)
|
|
|
|
yield n
|
|
|
|
if val1 == n:
|
2015-05-16 15:42:09 +03:00
|
|
|
val1 = None
|
2016-05-17 00:30:32 +03:00
|
|
|
if val2 == n:
|
2015-05-16 15:42:09 +03:00
|
|
|
val2 = None
|
|
|
|
except StopIteration:
|
|
|
|
# Flush any remaining values and consume the other one
|
|
|
|
it = iter2
|
|
|
|
if val1 is not None:
|
|
|
|
yield val1
|
|
|
|
it = iter1
|
|
|
|
elif val2 is not None:
|
|
|
|
# might have been equality and both are empty
|
|
|
|
yield val2
|
|
|
|
for val in it:
|
|
|
|
yield val
|
|
|
|
|
2014-10-04 07:18:48 +04:00
|
|
|
class addset(abstractsmartset):
|
2014-03-13 04:20:26 +04:00
|
|
|
"""Represent the addition of two sets
|
|
|
|
|
|
|
|
Wrapper structure for lazily adding two structures without losing much
|
2014-03-08 01:48:31 +04:00
|
|
|
performance on the __contains__ method
|
2014-03-13 04:20:26 +04:00
|
|
|
|
2014-03-12 03:52:15 +04:00
|
|
|
If the ascending attribute is set, that means the two structures are
|
|
|
|
ordered in either an ascending or descending way. Therefore, we can add
|
2014-04-13 21:01:00 +04:00
|
|
|
them maintaining the order by iterating over both at the same time
|
2015-03-30 13:51:40 +03:00
|
|
|
|
|
|
|
>>> xs = baseset([0, 3, 2])
|
|
|
|
>>> ys = baseset([5, 2, 4])
|
|
|
|
|
|
|
|
>>> rs = addset(xs, ys)
|
|
|
|
>>> bool(rs), 0 in rs, 1 in rs, 5 in rs, rs.first(), rs.last()
|
|
|
|
(True, True, False, True, 0, 4)
|
|
|
|
>>> rs = addset(xs, baseset([]))
|
|
|
|
>>> bool(rs), 0 in rs, 1 in rs, rs.first(), rs.last()
|
|
|
|
(True, True, False, 0, 2)
|
|
|
|
>>> rs = addset(baseset([]), baseset([]))
|
|
|
|
>>> bool(rs), 0 in rs, rs.first(), rs.last()
|
|
|
|
(False, False, None, None)
|
|
|
|
|
|
|
|
iterate unsorted:
|
|
|
|
>>> rs = addset(xs, ys)
|
2016-03-31 19:38:08 +03:00
|
|
|
>>> # (use generator because pypy could call len())
|
|
|
|
>>> list(x for x in rs) # without _genlist
|
2015-03-30 13:51:40 +03:00
|
|
|
[0, 3, 2, 5, 4]
|
|
|
|
>>> assert not rs._genlist
|
|
|
|
>>> len(rs)
|
|
|
|
5
|
|
|
|
>>> [x for x in rs] # with _genlist
|
|
|
|
[0, 3, 2, 5, 4]
|
|
|
|
>>> assert rs._genlist
|
|
|
|
|
|
|
|
iterate ascending:
|
|
|
|
>>> rs = addset(xs, ys, ascending=True)
|
2016-03-31 19:38:08 +03:00
|
|
|
>>> # (use generator because pypy could call len())
|
|
|
|
>>> list(x for x in rs), list(x for x in rs.fastasc()) # without _asclist
|
2015-03-30 13:51:40 +03:00
|
|
|
([0, 2, 3, 4, 5], [0, 2, 3, 4, 5])
|
|
|
|
>>> assert not rs._asclist
|
2015-05-15 10:25:43 +03:00
|
|
|
>>> len(rs)
|
|
|
|
5
|
|
|
|
>>> [x for x in rs], [x for x in rs.fastasc()]
|
|
|
|
([0, 2, 3, 4, 5], [0, 2, 3, 4, 5])
|
2015-03-30 13:51:40 +03:00
|
|
|
>>> assert rs._asclist
|
|
|
|
|
|
|
|
iterate descending:
|
|
|
|
>>> rs = addset(xs, ys, ascending=False)
|
2016-03-31 19:38:08 +03:00
|
|
|
>>> # (use generator because pypy could call len())
|
|
|
|
>>> list(x for x in rs), list(x for x in rs.fastdesc()) # without _asclist
|
2015-03-30 13:51:40 +03:00
|
|
|
([5, 4, 3, 2, 0], [5, 4, 3, 2, 0])
|
|
|
|
>>> assert not rs._asclist
|
2015-05-15 10:25:43 +03:00
|
|
|
>>> len(rs)
|
|
|
|
5
|
|
|
|
>>> [x for x in rs], [x for x in rs.fastdesc()]
|
|
|
|
([5, 4, 3, 2, 0], [5, 4, 3, 2, 0])
|
2015-03-30 13:51:40 +03:00
|
|
|
>>> assert rs._asclist
|
|
|
|
|
|
|
|
iterate ascending without fastasc:
|
|
|
|
>>> rs = addset(xs, generatorset(ys), ascending=True)
|
|
|
|
>>> assert rs.fastasc is None
|
2015-05-15 10:25:43 +03:00
|
|
|
>>> [x for x in rs]
|
|
|
|
[0, 2, 3, 4, 5]
|
2015-03-30 13:51:40 +03:00
|
|
|
|
|
|
|
iterate descending without fastdesc:
|
|
|
|
>>> rs = addset(generatorset(xs), ys, ascending=False)
|
|
|
|
>>> assert rs.fastdesc is None
|
2015-05-15 10:25:43 +03:00
|
|
|
>>> [x for x in rs]
|
|
|
|
[5, 4, 3, 2, 0]
|
2014-03-08 01:48:31 +04:00
|
|
|
"""
|
2014-03-12 03:52:15 +04:00
|
|
|
def __init__(self, revs1, revs2, ascending=None):
|
2014-03-08 01:48:31 +04:00
|
|
|
self._r1 = revs1
|
|
|
|
self._r2 = revs2
|
|
|
|
self._iter = None
|
2014-03-12 03:52:15 +04:00
|
|
|
self._ascending = ascending
|
2014-03-12 03:59:42 +04:00
|
|
|
self._genlist = None
|
2014-10-10 07:15:41 +04:00
|
|
|
self._asclist = None
|
2014-03-12 03:59:42 +04:00
|
|
|
|
2014-03-21 05:55:28 +04:00
|
|
|
def __len__(self):
|
|
|
|
return len(self._list)
|
|
|
|
|
2014-10-03 09:12:22 +04:00
|
|
|
def __nonzero__(self):
|
2014-10-29 00:06:06 +03:00
|
|
|
return bool(self._r1) or bool(self._r2)
|
2014-10-03 09:12:22 +04:00
|
|
|
|
2014-03-12 03:59:42 +04:00
|
|
|
@util.propertycache
|
|
|
|
def _list(self):
|
|
|
|
if not self._genlist:
|
2015-05-15 10:25:43 +03:00
|
|
|
self._genlist = baseset(iter(self))
|
2014-03-12 03:59:42 +04:00
|
|
|
return self._genlist
|
2014-03-08 01:48:31 +04:00
|
|
|
|
2015-05-15 10:25:43 +03:00
|
|
|
def __iter__(self):
|
2014-03-14 00:29:04 +04:00
|
|
|
"""Iterate over both collections without repeating elements
|
|
|
|
|
|
|
|
If the ascending attribute is not set, iterate over the first one and
|
|
|
|
then over the second one checking for membership on the first one so we
|
|
|
|
dont yield any duplicates.
|
|
|
|
|
|
|
|
If the ascending attribute is set, iterate over both collections at the
|
|
|
|
same time, yielding only one value at a time in the given order.
|
|
|
|
"""
|
2014-10-04 07:23:02 +04:00
|
|
|
if self._ascending is None:
|
2015-05-15 10:25:43 +03:00
|
|
|
if self._genlist:
|
|
|
|
return iter(self._genlist)
|
|
|
|
def arbitraryordergen():
|
2014-10-04 07:23:02 +04:00
|
|
|
for r in self._r1:
|
|
|
|
yield r
|
2014-10-10 23:30:00 +04:00
|
|
|
inr1 = self._r1.__contains__
|
2014-10-04 07:23:02 +04:00
|
|
|
for r in self._r2:
|
2014-10-10 23:30:00 +04:00
|
|
|
if not inr1(r):
|
2014-03-08 01:48:31 +04:00
|
|
|
yield r
|
2015-05-15 10:25:43 +03:00
|
|
|
return arbitraryordergen()
|
|
|
|
# try to use our own fast iterator if it exists
|
2014-10-10 07:15:41 +04:00
|
|
|
self._trysetasclist()
|
|
|
|
if self._ascending:
|
2015-05-16 08:05:02 +03:00
|
|
|
attr = 'fastasc'
|
2014-10-10 07:15:41 +04:00
|
|
|
else:
|
2015-05-16 08:05:02 +03:00
|
|
|
attr = 'fastdesc'
|
|
|
|
it = getattr(self, attr)
|
2015-05-15 10:25:43 +03:00
|
|
|
if it is not None:
|
|
|
|
return it()
|
|
|
|
# maybe half of the component supports fast
|
|
|
|
# get iterator for _r1
|
|
|
|
iter1 = getattr(self._r1, attr)
|
|
|
|
if iter1 is None:
|
|
|
|
# let's avoid side effect (not sure it matters)
|
|
|
|
iter1 = iter(sorted(self._r1, reverse=not self._ascending))
|
|
|
|
else:
|
|
|
|
iter1 = iter1()
|
|
|
|
# get iterator for _r2
|
|
|
|
iter2 = getattr(self._r2, attr)
|
|
|
|
if iter2 is None:
|
|
|
|
# let's avoid side effect (not sure it matters)
|
|
|
|
iter2 = iter(sorted(self._r2, reverse=not self._ascending))
|
|
|
|
else:
|
|
|
|
iter2 = iter2()
|
2015-05-16 15:42:09 +03:00
|
|
|
return _iterordered(self._ascending, iter1, iter2)
|
2014-10-10 07:15:41 +04:00
|
|
|
|
|
|
|
def _trysetasclist(self):
|
2014-04-18 00:47:38 +04:00
|
|
|
"""populate the _asclist attribute if possible and necessary"""
|
2014-10-10 07:15:41 +04:00
|
|
|
if self._genlist is not None and self._asclist is None:
|
|
|
|
self._asclist = sorted(self._genlist)
|
2014-03-08 01:48:31 +04:00
|
|
|
|
2014-10-03 08:38:30 +04:00
|
|
|
@property
|
|
|
|
def fastasc(self):
|
2014-10-10 07:15:41 +04:00
|
|
|
self._trysetasclist()
|
|
|
|
if self._asclist is not None:
|
|
|
|
return self._asclist.__iter__
|
2014-10-03 08:38:30 +04:00
|
|
|
iter1 = self._r1.fastasc
|
|
|
|
iter2 = self._r2.fastasc
|
|
|
|
if None in (iter1, iter2):
|
|
|
|
return None
|
2015-05-16 15:42:09 +03:00
|
|
|
return lambda: _iterordered(True, iter1(), iter2())
|
2014-10-03 08:38:30 +04:00
|
|
|
|
|
|
|
@property
|
|
|
|
def fastdesc(self):
|
2014-10-10 07:15:41 +04:00
|
|
|
self._trysetasclist()
|
|
|
|
if self._asclist is not None:
|
|
|
|
return self._asclist.__reversed__
|
2014-10-03 08:38:30 +04:00
|
|
|
iter1 = self._r1.fastdesc
|
|
|
|
iter2 = self._r2.fastdesc
|
|
|
|
if None in (iter1, iter2):
|
|
|
|
return None
|
2015-05-16 15:42:09 +03:00
|
|
|
return lambda: _iterordered(False, iter1(), iter2())
|
2014-10-03 08:28:18 +04:00
|
|
|
|
2014-03-08 01:48:31 +04:00
|
|
|
def __contains__(self, x):
|
|
|
|
return x in self._r1 or x in self._r2
|
|
|
|
|
2014-03-12 04:03:43 +04:00
|
|
|
def sort(self, reverse=False):
|
|
|
|
"""Sort the added set
|
|
|
|
|
|
|
|
For this we use the cached list with all the generated values and if we
|
|
|
|
know they are ascending or descending we can sort them in a smart way.
|
|
|
|
"""
|
2014-10-10 07:15:41 +04:00
|
|
|
self._ascending = not reverse
|
2014-03-12 04:03:43 +04:00
|
|
|
|
2014-03-14 21:24:09 +04:00
|
|
|
def isascending(self):
|
|
|
|
return self._ascending is not None and self._ascending
|
|
|
|
|
|
|
|
def isdescending(self):
|
|
|
|
return self._ascending is not None and not self._ascending
|
|
|
|
|
2016-06-14 13:05:36 +03:00
|
|
|
def istopo(self):
|
|
|
|
# not worth the trouble asserting if the two sets combined are still
|
|
|
|
# in topographical order. Use the sort() predicate to explicitly sort
|
|
|
|
# again instead.
|
|
|
|
return False
|
|
|
|
|
2014-03-14 05:57:30 +04:00
|
|
|
def reverse(self):
|
2014-10-10 07:15:41 +04:00
|
|
|
if self._ascending is None:
|
|
|
|
self._list.reverse()
|
|
|
|
else:
|
2014-03-14 05:57:30 +04:00
|
|
|
self._ascending = not self._ascending
|
|
|
|
|
2014-10-06 22:57:59 +04:00
|
|
|
def first(self):
|
2014-11-02 01:58:30 +03:00
|
|
|
for x in self:
|
|
|
|
return x
|
2014-10-06 22:57:59 +04:00
|
|
|
return None
|
|
|
|
|
|
|
|
def last(self):
|
2014-11-02 01:58:30 +03:00
|
|
|
self.reverse()
|
|
|
|
val = self.first()
|
|
|
|
self.reverse()
|
|
|
|
return val
|
2014-10-06 22:57:59 +04:00
|
|
|
|
2015-03-16 12:15:06 +03:00
|
|
|
def __repr__(self):
|
|
|
|
d = {None: '', False: '-', True: '+'}[self._ascending]
|
|
|
|
return '<%s%s %r, %r>' % (type(self).__name__, d, self._r1, self._r2)
|
|
|
|
|
2014-10-04 07:12:02 +04:00
|
|
|
class generatorset(abstractsmartset):
|
2014-03-13 04:07:38 +04:00
|
|
|
"""Wrap a generator for lazy iteration
|
|
|
|
|
|
|
|
Wrapper structure for generators that provides lazy membership and can
|
2014-02-13 06:45:49 +04:00
|
|
|
be iterated more than once.
|
|
|
|
When asked for membership it generates values until either it finds the
|
|
|
|
requested one or has gone through all the elements in the generator
|
|
|
|
"""
|
2014-10-03 21:36:08 +04:00
|
|
|
def __init__(self, gen, iterasc=None):
|
2014-03-14 21:57:04 +04:00
|
|
|
"""
|
|
|
|
gen: a generator producing the values for the generatorset.
|
|
|
|
"""
|
2014-02-06 03:23:11 +04:00
|
|
|
self._gen = gen
|
2014-10-04 08:01:30 +04:00
|
|
|
self._asclist = None
|
2014-02-06 03:23:11 +04:00
|
|
|
self._cache = {}
|
2014-10-04 07:43:48 +04:00
|
|
|
self._genlist = []
|
2014-02-25 04:36:17 +04:00
|
|
|
self._finished = False
|
2014-10-04 08:11:56 +04:00
|
|
|
self._ascending = True
|
2014-10-03 21:36:08 +04:00
|
|
|
if iterasc is not None:
|
|
|
|
if iterasc:
|
2014-10-04 07:48:28 +04:00
|
|
|
self.fastasc = self._iterator
|
2014-10-03 21:46:34 +04:00
|
|
|
self.__contains__ = self._asccontains
|
2014-10-03 21:36:08 +04:00
|
|
|
else:
|
2014-10-04 07:48:28 +04:00
|
|
|
self.fastdesc = self._iterator
|
2014-10-03 21:46:34 +04:00
|
|
|
self.__contains__ = self._desccontains
|
2014-02-13 06:45:49 +04:00
|
|
|
|
2014-10-03 10:56:57 +04:00
|
|
|
def __nonzero__(self):
|
2015-05-04 22:36:48 +03:00
|
|
|
# Do not use 'for r in self' because it will enforce the iteration
|
|
|
|
# order (default ascending), possibly unrolling a whole descending
|
|
|
|
# iterator.
|
|
|
|
if self._genlist:
|
|
|
|
return True
|
|
|
|
for r in self._consumegen():
|
2014-10-03 10:56:57 +04:00
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
2014-02-06 03:23:11 +04:00
|
|
|
def __contains__(self, x):
|
|
|
|
if x in self._cache:
|
|
|
|
return self._cache[x]
|
|
|
|
|
2014-03-25 07:00:18 +04:00
|
|
|
# Use new values only, as existing values would be cached.
|
|
|
|
for l in self._consumegen():
|
2014-03-04 00:54:46 +04:00
|
|
|
if l == x:
|
|
|
|
return True
|
2014-02-06 03:23:11 +04:00
|
|
|
|
|
|
|
self._cache[x] = False
|
|
|
|
return False
|
|
|
|
|
2014-10-03 21:46:34 +04:00
|
|
|
def _asccontains(self, x):
|
|
|
|
"""version of contains optimised for ascending generator"""
|
|
|
|
if x in self._cache:
|
|
|
|
return self._cache[x]
|
|
|
|
|
|
|
|
# Use new values only, as existing values would be cached.
|
|
|
|
for l in self._consumegen():
|
|
|
|
if l == x:
|
|
|
|
return True
|
|
|
|
if l > x:
|
|
|
|
break
|
|
|
|
|
|
|
|
self._cache[x] = False
|
|
|
|
return False
|
|
|
|
|
|
|
|
def _desccontains(self, x):
|
|
|
|
"""version of contains optimised for descending generator"""
|
|
|
|
if x in self._cache:
|
|
|
|
return self._cache[x]
|
|
|
|
|
|
|
|
# Use new values only, as existing values would be cached.
|
|
|
|
for l in self._consumegen():
|
|
|
|
if l == x:
|
|
|
|
return True
|
|
|
|
if l < x:
|
|
|
|
break
|
|
|
|
|
|
|
|
self._cache[x] = False
|
|
|
|
return False
|
|
|
|
|
2014-02-06 03:23:11 +04:00
|
|
|
def __iter__(self):
|
2014-10-04 08:11:56 +04:00
|
|
|
if self._ascending:
|
|
|
|
it = self.fastasc
|
|
|
|
else:
|
|
|
|
it = self.fastdesc
|
|
|
|
if it is not None:
|
|
|
|
return it()
|
|
|
|
# we need to consume the iterator
|
|
|
|
for x in self._consumegen():
|
|
|
|
pass
|
|
|
|
# recall the same code
|
|
|
|
return iter(self)
|
2014-10-04 07:48:28 +04:00
|
|
|
|
|
|
|
def _iterator(self):
|
2014-03-26 03:10:07 +04:00
|
|
|
if self._finished:
|
2014-05-01 03:56:23 +04:00
|
|
|
return iter(self._genlist)
|
2014-03-25 07:00:18 +04:00
|
|
|
|
2014-09-17 10:42:41 +04:00
|
|
|
# We have to use this complex iteration strategy to allow multiple
|
|
|
|
# iterations at the same time. We need to be able to catch revision
|
2014-04-18 00:47:38 +04:00
|
|
|
# removed from _consumegen and added to genlist in another instance.
|
2014-09-17 10:42:41 +04:00
|
|
|
#
|
|
|
|
# Getting rid of it would provide an about 15% speed up on this
|
|
|
|
# iteration.
|
2014-03-26 03:10:07 +04:00
|
|
|
genlist = self._genlist
|
2014-09-19 02:52:45 +04:00
|
|
|
nextrev = self._consumegen().next
|
|
|
|
_len = len # cache global lookup
|
2014-05-01 03:56:23 +04:00
|
|
|
def gen():
|
|
|
|
i = 0
|
|
|
|
while True:
|
|
|
|
if i < _len(genlist):
|
|
|
|
yield genlist[i]
|
|
|
|
else:
|
|
|
|
yield nextrev()
|
|
|
|
i += 1
|
|
|
|
return gen()
|
2014-03-25 07:00:18 +04:00
|
|
|
|
|
|
|
def _consumegen(self):
|
2014-05-01 03:56:48 +04:00
|
|
|
cache = self._cache
|
|
|
|
genlist = self._genlist.append
|
2014-03-04 00:54:46 +04:00
|
|
|
for item in self._gen:
|
2014-05-01 03:56:48 +04:00
|
|
|
cache[item] = True
|
|
|
|
genlist(item)
|
2014-03-04 00:54:46 +04:00
|
|
|
yield item
|
2014-10-04 08:01:30 +04:00
|
|
|
if not self._finished:
|
|
|
|
self._finished = True
|
|
|
|
asc = self._genlist[:]
|
|
|
|
asc.sort()
|
|
|
|
self._asclist = asc
|
|
|
|
self.fastasc = asc.__iter__
|
|
|
|
self.fastdesc = asc.__reversed__
|
2014-02-25 04:36:17 +04:00
|
|
|
|
2014-10-15 15:28:55 +04:00
|
|
|
def __len__(self):
|
|
|
|
for x in self._consumegen():
|
|
|
|
pass
|
|
|
|
return len(self._genlist)
|
|
|
|
|
2014-02-25 04:36:17 +04:00
|
|
|
def sort(self, reverse=False):
|
2014-10-04 08:11:56 +04:00
|
|
|
self._ascending = not reverse
|
|
|
|
|
|
|
|
def reverse(self):
|
|
|
|
self._ascending = not self._ascending
|
2014-02-25 04:36:17 +04:00
|
|
|
|
2014-10-04 17:17:18 +04:00
|
|
|
def isascending(self):
|
|
|
|
return self._ascending
|
|
|
|
|
|
|
|
def isdescending(self):
|
|
|
|
return not self._ascending
|
|
|
|
|
2016-06-14 13:05:36 +03:00
|
|
|
def istopo(self):
|
|
|
|
# not worth the trouble asserting if the two sets combined are still
|
|
|
|
# in topographical order. Use the sort() predicate to explicitly sort
|
|
|
|
# again instead.
|
|
|
|
return False
|
|
|
|
|
2014-10-06 23:52:36 +04:00
|
|
|
def first(self):
|
|
|
|
if self._ascending:
|
|
|
|
it = self.fastasc
|
|
|
|
else:
|
|
|
|
it = self.fastdesc
|
|
|
|
if it is None:
|
|
|
|
# we need to consume all and try again
|
|
|
|
for x in self._consumegen():
|
|
|
|
pass
|
|
|
|
return self.first()
|
2015-05-18 04:06:09 +03:00
|
|
|
return next(it(), None)
|
2014-10-06 23:52:36 +04:00
|
|
|
|
|
|
|
def last(self):
|
|
|
|
if self._ascending:
|
|
|
|
it = self.fastdesc
|
|
|
|
else:
|
|
|
|
it = self.fastasc
|
|
|
|
if it is None:
|
|
|
|
# we need to consume all and try again
|
|
|
|
for x in self._consumegen():
|
|
|
|
pass
|
|
|
|
return self.first()
|
2015-05-18 04:06:09 +03:00
|
|
|
return next(it(), None)
|
2014-10-06 23:52:36 +04:00
|
|
|
|
2015-03-16 12:15:06 +03:00
|
|
|
def __repr__(self):
|
|
|
|
d = {False: '-', True: '+'}[self._ascending]
|
|
|
|
return '<%s%s>' % (type(self).__name__, d)
|
|
|
|
|
2015-01-08 17:43:15 +03:00
|
|
|
class spanset(abstractsmartset):
|
2014-02-12 22:16:21 +04:00
|
|
|
"""Duck type for baseset class which represents a range of revisions and
|
|
|
|
can work lazily and without having all the range in memory
|
2014-03-14 21:59:51 +04:00
|
|
|
|
|
|
|
Note that spanset(x, y) behave almost like xrange(x, y) except for two
|
|
|
|
notable points:
|
|
|
|
- when x < y it will be automatically descending,
|
|
|
|
- revision filtered with this repoview will be skipped.
|
|
|
|
|
2014-02-12 22:16:21 +04:00
|
|
|
"""
|
2014-02-18 23:38:03 +04:00
|
|
|
def __init__(self, repo, start=0, end=None):
|
2014-03-14 21:59:51 +04:00
|
|
|
"""
|
|
|
|
start: first revision included the set
|
|
|
|
(default to 0)
|
|
|
|
end: first revision excluded (last+1)
|
|
|
|
(default to len(repo)
|
|
|
|
|
|
|
|
Spanset will be descending if `end` < `start`.
|
|
|
|
"""
|
2014-10-03 03:02:17 +04:00
|
|
|
if end is None:
|
|
|
|
end = len(repo)
|
|
|
|
self._ascending = start <= end
|
|
|
|
if not self._ascending:
|
|
|
|
start, end = end + 1, start +1
|
2014-02-12 22:16:21 +04:00
|
|
|
self._start = start
|
2014-10-03 03:02:17 +04:00
|
|
|
self._end = end
|
2014-02-18 23:38:03 +04:00
|
|
|
self._hiddenrevs = repo.changelog.filteredrevs
|
2014-02-11 05:38:43 +04:00
|
|
|
|
2014-10-03 03:02:17 +04:00
|
|
|
def sort(self, reverse=False):
|
|
|
|
self._ascending = not reverse
|
|
|
|
|
|
|
|
def reverse(self):
|
|
|
|
self._ascending = not self._ascending
|
|
|
|
|
2016-06-14 13:05:36 +03:00
|
|
|
def istopo(self):
|
|
|
|
# not worth the trouble asserting if the two sets combined are still
|
|
|
|
# in topographical order. Use the sort() predicate to explicitly sort
|
|
|
|
# again instead.
|
|
|
|
return False
|
|
|
|
|
2014-10-03 03:02:17 +04:00
|
|
|
def _iterfilter(self, iterrange):
|
|
|
|
s = self._hiddenrevs
|
|
|
|
for r in iterrange:
|
|
|
|
if r not in s:
|
|
|
|
yield r
|
|
|
|
|
2014-02-12 22:16:21 +04:00
|
|
|
def __iter__(self):
|
2014-10-03 03:02:17 +04:00
|
|
|
if self._ascending:
|
|
|
|
return self.fastasc()
|
2014-02-12 22:16:21 +04:00
|
|
|
else:
|
2014-10-03 03:02:17 +04:00
|
|
|
return self.fastdesc()
|
2014-02-11 05:38:43 +04:00
|
|
|
|
2014-10-03 03:02:17 +04:00
|
|
|
def fastasc(self):
|
|
|
|
iterrange = xrange(self._start, self._end)
|
2014-02-11 05:38:43 +04:00
|
|
|
if self._hiddenrevs:
|
2014-10-03 03:02:17 +04:00
|
|
|
return self._iterfilter(iterrange)
|
|
|
|
return iter(iterrange)
|
|
|
|
|
|
|
|
def fastdesc(self):
|
|
|
|
iterrange = xrange(self._end - 1, self._start - 1, -1)
|
|
|
|
if self._hiddenrevs:
|
|
|
|
return self._iterfilter(iterrange)
|
|
|
|
return iter(iterrange)
|
2014-02-12 22:16:21 +04:00
|
|
|
|
2014-04-29 03:28:52 +04:00
|
|
|
def __contains__(self, rev):
|
2014-04-26 04:53:58 +04:00
|
|
|
hidden = self._hiddenrevs
|
2014-10-03 02:53:55 +04:00
|
|
|
return ((self._start <= rev < self._end)
|
2014-04-26 04:53:58 +04:00
|
|
|
and not (hidden and rev in hidden))
|
2014-02-12 22:16:21 +04:00
|
|
|
|
2014-03-14 20:07:59 +04:00
|
|
|
def __nonzero__(self):
|
|
|
|
for r in self:
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
2014-02-07 03:56:25 +04:00
|
|
|
def __len__(self):
|
2014-02-11 05:38:43 +04:00
|
|
|
if not self._hiddenrevs:
|
|
|
|
return abs(self._end - self._start)
|
|
|
|
else:
|
|
|
|
count = 0
|
2014-04-26 05:00:07 +04:00
|
|
|
start = self._start
|
|
|
|
end = self._end
|
2014-02-11 05:38:43 +04:00
|
|
|
for rev in self._hiddenrevs:
|
2014-04-29 02:14:11 +04:00
|
|
|
if (end < rev <= start) or (start <= rev < end):
|
2014-02-11 05:38:43 +04:00
|
|
|
count += 1
|
|
|
|
return abs(self._end - self._start) - count
|
2014-02-07 03:56:25 +04:00
|
|
|
|
2014-03-12 04:09:23 +04:00
|
|
|
def isascending(self):
|
2015-01-10 15:31:59 +03:00
|
|
|
return self._ascending
|
2014-03-12 04:09:23 +04:00
|
|
|
|
|
|
|
def isdescending(self):
|
2015-01-10 15:31:59 +03:00
|
|
|
return not self._ascending
|
2014-03-12 04:09:23 +04:00
|
|
|
|
2014-10-06 22:54:53 +04:00
|
|
|
def first(self):
|
|
|
|
if self._ascending:
|
|
|
|
it = self.fastasc
|
|
|
|
else:
|
|
|
|
it = self.fastdesc
|
|
|
|
for x in it():
|
|
|
|
return x
|
|
|
|
return None
|
|
|
|
|
|
|
|
def last(self):
|
|
|
|
if self._ascending:
|
|
|
|
it = self.fastdesc
|
|
|
|
else:
|
|
|
|
it = self.fastasc
|
|
|
|
for x in it():
|
|
|
|
return x
|
|
|
|
return None
|
|
|
|
|
2015-03-16 12:15:06 +03:00
|
|
|
def __repr__(self):
|
|
|
|
d = {False: '-', True: '+'}[self._ascending]
|
|
|
|
return '<%s%s %d:%d>' % (type(self).__name__, d,
|
|
|
|
self._start, self._end - 1)
|
|
|
|
|
2015-01-08 17:43:15 +03:00
|
|
|
class fullreposet(spanset):
|
2014-04-30 06:06:15 +04:00
|
|
|
"""a set containing all revisions in the repo
|
|
|
|
|
2015-01-08 17:05:45 +03:00
|
|
|
This class exists to host special optimization and magic to handle virtual
|
|
|
|
revisions such as "null".
|
2014-04-30 06:06:15 +04:00
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self, repo):
|
|
|
|
super(fullreposet, self).__init__(repo)
|
|
|
|
|
2014-09-25 07:11:36 +04:00
|
|
|
def __and__(self, other):
|
2014-04-18 00:47:38 +04:00
|
|
|
"""As self contains the whole repo, all of the other set should also be
|
|
|
|
in self. Therefore `self & other = other`.
|
2014-09-25 07:11:36 +04:00
|
|
|
|
|
|
|
This boldly assumes the other contains valid revs only.
|
|
|
|
"""
|
|
|
|
# other not a smartset, make is so
|
2014-10-11 00:24:57 +04:00
|
|
|
if not util.safehasattr(other, 'isascending'):
|
2014-09-25 07:11:36 +04:00
|
|
|
# filter out hidden revision
|
|
|
|
# (this boldly assumes all smartset are pure)
|
|
|
|
#
|
|
|
|
# `other` was used with "&", let's assume this is a set like
|
|
|
|
# object.
|
|
|
|
other = baseset(other - self._hiddenrevs)
|
|
|
|
|
2015-06-12 00:00:13 +03:00
|
|
|
# XXX As fullreposet is also used as bootstrap, this is wrong.
|
|
|
|
#
|
|
|
|
# With a giveme312() revset returning [3,1,2], this makes
|
|
|
|
# 'hg log -r "giveme312()"' -> 1, 2, 3 (wrong)
|
|
|
|
# We cannot just drop it because other usage still need to sort it:
|
|
|
|
# 'hg log -r "all() and giveme312()"' -> 1, 2, 3 (right)
|
|
|
|
#
|
|
|
|
# There is also some faulty revset implementations that rely on it
|
|
|
|
# (eg: children as of its state in e8075329c5fb)
|
|
|
|
#
|
|
|
|
# When we fix the two points above we can move this into the if clause
|
2015-01-10 15:36:42 +03:00
|
|
|
other.sort(reverse=self.isdescending())
|
2014-09-25 07:11:36 +04:00
|
|
|
return other
|
|
|
|
|
2015-03-16 12:36:53 +03:00
|
|
|
def prettyformatset(revs):
|
|
|
|
lines = []
|
|
|
|
rs = repr(revs)
|
|
|
|
p = 0
|
|
|
|
while p < len(rs):
|
|
|
|
q = rs.find('<', p + 1)
|
|
|
|
if q < 0:
|
|
|
|
q = len(rs)
|
|
|
|
l = rs.count('<', 0, p) - rs.count('>', 0, p)
|
|
|
|
assert l >= 0
|
|
|
|
lines.append((l, rs[p:q].rstrip()))
|
|
|
|
p = q
|
|
|
|
return '\n'.join(' ' * l + s for l, s in lines)
|
|
|
|
|
2016-03-08 17:04:53 +03:00
|
|
|
def loadpredicate(ui, extname, registrarobj):
|
|
|
|
"""Load revset predicates from specified registrarobj
|
|
|
|
"""
|
|
|
|
for name, func in registrarobj._table.iteritems():
|
|
|
|
symbols[name] = func
|
|
|
|
if func._safe:
|
|
|
|
safesymbols.add(name)
|
|
|
|
|
2016-03-08 17:04:53 +03:00
|
|
|
# load built-in predicates explicitly to setup safesymbols
|
|
|
|
loadpredicate(None, None, predicate)
|
|
|
|
|
2010-10-24 14:52:37 +04:00
|
|
|
# tell hggettext to extract docstrings from these functions:
|
|
|
|
i18nfunctions = symbols.values()
|