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
|
|
|
|
|
|
|
|
import re
|
|
|
|
|
|
|
|
from .i18n import _
|
|
|
|
from . import (
|
2016-10-16 12:03:24 +03:00
|
|
|
dagop,
|
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,
|
2017-07-10 20:56:40 +03:00
|
|
|
obsutil,
|
2015-08-09 04:36:58 +03:00
|
|
|
pathutil,
|
|
|
|
phases,
|
2015-12-29 17:58:30 +03:00
|
|
|
registrar,
|
2015-08-09 04:36:58 +03:00
|
|
|
repoview,
|
2017-02-19 12:19:33 +03:00
|
|
|
revsetlang,
|
2017-06-03 14:39:33 +03:00
|
|
|
scmutil,
|
2016-10-16 11:28:51 +03:00
|
|
|
smartset,
|
2015-08-09 04:36:58 +03:00
|
|
|
util,
|
|
|
|
)
|
2010-06-01 20:18:57 +04:00
|
|
|
|
2017-02-19 12:19:33 +03:00
|
|
|
# helpers for processing parsed tree
|
|
|
|
getsymbol = revsetlang.getsymbol
|
|
|
|
getstring = revsetlang.getstring
|
|
|
|
getinteger = revsetlang.getinteger
|
2017-04-15 12:29:42 +03:00
|
|
|
getboolean = revsetlang.getboolean
|
2017-02-19 12:19:33 +03:00
|
|
|
getlist = revsetlang.getlist
|
|
|
|
getrange = revsetlang.getrange
|
|
|
|
getargs = revsetlang.getargs
|
|
|
|
getargsdict = revsetlang.getargsdict
|
|
|
|
|
2016-10-16 11:28:51 +03:00
|
|
|
baseset = smartset.baseset
|
|
|
|
generatorset = smartset.generatorset
|
|
|
|
spanset = smartset.spanset
|
|
|
|
fullreposet = smartset.fullreposet
|
|
|
|
|
2017-08-30 16:32:47 +03:00
|
|
|
# Constants for ordering requirement, used in getset():
|
|
|
|
#
|
|
|
|
# If 'define', any nested functions and operations MAY change the ordering of
|
|
|
|
# the entries in the set (but if changes the ordering, it MUST ALWAYS change
|
|
|
|
# it). If 'follow', any nested functions and operations MUST 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,
|
|
|
|
#
|
2017-08-30 17:53:30 +03:00
|
|
|
# (X & !Y) | ancestors(Z)
|
|
|
|
# ^ ^
|
|
|
|
# any any
|
2017-08-30 16:32:47 +03:00
|
|
|
#
|
2017-08-30 17:53:30 +03:00
|
|
|
# For 'X & !Y', 'X' decides the order and 'Y' is subtracted from 'X', so the
|
|
|
|
# order of 'Y' does not matter. For 'ancestors(Z)', Z's order does not matter
|
|
|
|
# since 'ancestors' does not care about the order of its argument.
|
2017-08-30 16:32:47 +03:00
|
|
|
#
|
|
|
|
# Currently, most revsets do not care about the order, so 'define' is
|
|
|
|
# equivalent to 'follow' for them, and the resulting order is based on the
|
|
|
|
# 'subset' parameter passed down to them:
|
|
|
|
#
|
2017-08-30 16:41:36 +03:00
|
|
|
# m = revset.match(...)
|
|
|
|
# m(repo, subset, order=defineorder)
|
2017-08-30 16:32:47 +03:00
|
|
|
# ^^^^^^
|
|
|
|
# For most revsets, 'define' means using the order this subset provides
|
|
|
|
#
|
|
|
|
# There are a few revsets that always redefine the order if 'define' is
|
|
|
|
# specified: 'sort(X)', 'reverse(X)', 'x:y'.
|
|
|
|
anyorder = 'any' # don't care the order, could be even random-shuffled
|
|
|
|
defineorder = 'define' # ALWAYS redefine, or ALWAYS follow the current order
|
|
|
|
followorder = 'follow' # MUST follow the current order
|
|
|
|
|
2010-06-01 20:18:57 +04:00
|
|
|
# helpers
|
|
|
|
|
2017-08-20 20:55:11 +03:00
|
|
|
def getset(repo, subset, x, order=defineorder):
|
2010-06-01 20:18:57 +04:00
|
|
|
if not x:
|
2010-06-18 23:31:19 +04:00
|
|
|
raise error.ParseError(_("missing argument"))
|
2017-08-20 20:55:11 +03:00
|
|
|
return methods[x[0]](repo, subset, *x[1:], order=order)
|
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
|
|
|
|
|
2017-08-20 20:55:11 +03:00
|
|
|
def stringset(repo, subset, x, order):
|
2017-06-03 14:39:33 +03:00
|
|
|
x = scmutil.intrev(repo[x])
|
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
|
|
|
|
2017-01-09 10:55:56 +03:00
|
|
|
def rangeall(repo, subset, x, order):
|
|
|
|
assert x is None
|
|
|
|
return _makerangeset(repo, subset, 0, len(repo) - 1, order)
|
|
|
|
|
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)
|
|
|
|
|
2017-01-09 10:55:56 +03:00
|
|
|
def rangepost(repo, subset, x, order):
|
|
|
|
m = getset(repo, fullreposet(repo), x)
|
|
|
|
if not m:
|
|
|
|
return baseset()
|
|
|
|
return _makerangeset(repo, subset, m.first(), len(repo) - 1, 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)
|
2016-10-16 12:03:24 +03:00
|
|
|
xs = dagop.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):
|
2017-08-20 20:55:11 +03:00
|
|
|
if order == anyorder:
|
|
|
|
yorder = anyorder
|
|
|
|
else:
|
|
|
|
yorder = followorder
|
|
|
|
return getset(repo, getset(repo, subset, x, order), y, yorder)
|
|
|
|
|
2017-08-31 02:05:12 +03:00
|
|
|
def andsmallyset(repo, subset, x, y, order):
|
|
|
|
# 'andsmally(x, y)' is equivalent to 'and(x, y)', but faster when y is small
|
2017-08-20 20:55:11 +03:00
|
|
|
if order == anyorder:
|
|
|
|
yorder = anyorder
|
|
|
|
else:
|
|
|
|
yorder = followorder
|
|
|
|
return getset(repo, getset(repo, subset, y, yorder), x, order)
|
2010-06-01 20:18:57 +04:00
|
|
|
|
2016-08-07 11:46:12 +03:00
|
|
|
def differenceset(repo, subset, x, y, order):
|
2017-08-20 20:55:11 +03:00
|
|
|
return getset(repo, subset, x, order) - getset(repo, subset, y, anyorder)
|
2016-02-24 21:41:15 +03:00
|
|
|
|
2017-08-20 20:55:11 +03:00
|
|
|
def _orsetlist(repo, subset, xs, order):
|
2015-07-05 06:50:09 +03:00
|
|
|
assert xs
|
|
|
|
if len(xs) == 1:
|
2017-08-20 20:55:11 +03:00
|
|
|
return getset(repo, subset, xs[0], order)
|
2015-07-05 06:50:09 +03:00
|
|
|
p = len(xs) // 2
|
2017-08-20 20:55:11 +03:00
|
|
|
a = _orsetlist(repo, subset, xs[:p], order)
|
|
|
|
b = _orsetlist(repo, subset, xs[p:], order)
|
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
|
2017-08-20 20:55:11 +03:00
|
|
|
return subset & _orsetlist(repo, fullreposet(repo), xs, anyorder)
|
2016-06-26 12:17:12 +03:00
|
|
|
else:
|
2017-08-20 20:55:11 +03:00
|
|
|
return _orsetlist(repo, subset, xs, order)
|
2016-08-07 11:04:05 +03:00
|
|
|
|
2016-08-07 11:46:12 +03:00
|
|
|
def notset(repo, subset, x, order):
|
2017-08-20 20:55:11 +03:00
|
|
|
return subset - getset(repo, subset, x, anyorder)
|
2010-06-01 20:18:57 +04:00
|
|
|
|
2017-07-08 07:07:59 +03:00
|
|
|
def relationset(repo, subset, x, y, order):
|
|
|
|
raise error.ParseError(_("can't use a relation in this context"))
|
|
|
|
|
|
|
|
def relsubscriptset(repo, subset, x, y, z, order):
|
2017-07-08 07:15:17 +03:00
|
|
|
# this is pretty basic implementation of 'x#y[z]' operator, still
|
|
|
|
# experimental so undocumented. see the wiki for further ideas.
|
|
|
|
# https://www.mercurial-scm.org/wiki/RevsetOperatorPlan
|
|
|
|
rel = getsymbol(y)
|
|
|
|
n = getinteger(z, _("relation subscript must be an integer"))
|
|
|
|
|
|
|
|
# TODO: perhaps this should be a table of relation functions
|
|
|
|
if rel in ('g', 'generations'):
|
|
|
|
# TODO: support range, rewrite tests, and drop startdepth argument
|
|
|
|
# from ancestors() and descendants() predicates
|
|
|
|
if n <= 0:
|
|
|
|
n = -n
|
|
|
|
return _ancestors(repo, subset, x, startdepth=n, stopdepth=n + 1)
|
|
|
|
else:
|
|
|
|
return _descendants(repo, subset, x, startdepth=n, stopdepth=n + 1)
|
|
|
|
|
|
|
|
raise error.UnknownIdentifier(rel, ['generations'])
|
2017-07-08 07:07:59 +03:00
|
|
|
|
|
|
|
def subscriptset(repo, subset, x, y, order):
|
|
|
|
raise error.ParseError(_("can't use a subscript in this context"))
|
|
|
|
|
2017-08-20 20:55:11 +03:00
|
|
|
def listset(repo, subset, *xs, **opts):
|
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
|
|
|
|
2017-08-20 20:55:11 +03:00
|
|
|
def keyvaluepair(repo, subset, k, v, order):
|
2015-06-27 11:05:28 +03:00
|
|
|
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-11-11 00:35:10 +03:00
|
|
|
func = symbols[f]
|
|
|
|
if getattr(func, '_takeorder', False):
|
|
|
|
return func(repo, subset, b, order)
|
|
|
|
return func(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
|
2017-09-02 05:42:09 +03:00
|
|
|
symbols = revsetlang.symbols
|
2015-12-29 17:58:30 +03:00
|
|
|
|
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
|
2017-02-13 22:32:09 +03:00
|
|
|
args = getargsdict(x, 'limit', 'clean')
|
2015-10-15 03:35:44 +03:00
|
|
|
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
|
|
|
|
2017-09-02 05:42:09 +03:00
|
|
|
@predicate('adds(pattern)', safe=True, weight=30)
|
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
|
|
|
|
2017-09-02 05:42:09 +03:00
|
|
|
@predicate('ancestor(*changeset)', safe=True, weight=0.5)
|
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
|
|
|
|
2017-06-17 18:40:58 +03:00
|
|
|
def _ancestors(repo, subset, x, followfirst=False, startdepth=None,
|
|
|
|
stopdepth=None):
|
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()
|
2017-06-17 18:40:58 +03:00
|
|
|
s = dagop.revancestors(repo, heads, followfirst, startdepth, stopdepth)
|
2014-10-01 00:03:54 +04:00
|
|
|
return subset & s
|
2010-06-01 20:18:57 +04:00
|
|
|
|
2017-06-17 18:22:41 +03:00
|
|
|
@predicate('ancestors(set[, depth])', safe=True)
|
2012-04-11 13:25:34 +04:00
|
|
|
def ancestors(repo, subset, x):
|
2017-06-18 16:46:56 +03:00
|
|
|
"""Changesets that are ancestors of changesets in set, including the
|
|
|
|
given changesets themselves.
|
2017-06-17 18:22:41 +03:00
|
|
|
|
|
|
|
If depth is specified, the result only includes changesets up to
|
|
|
|
the specified generation.
|
2012-04-11 13:25:34 +04:00
|
|
|
"""
|
2017-06-17 18:40:58 +03:00
|
|
|
# startdepth is for internal use only until we can decide the UI
|
|
|
|
args = getargsdict(x, 'ancestors', 'set depth startdepth')
|
2017-06-18 06:06:22 +03:00
|
|
|
if 'set' not in args:
|
|
|
|
# i18n: "ancestors" is a keyword
|
|
|
|
raise error.ParseError(_('ancestors takes at least 1 argument'))
|
2017-06-17 18:40:58 +03:00
|
|
|
startdepth = stopdepth = None
|
|
|
|
if 'startdepth' in args:
|
|
|
|
n = getinteger(args['startdepth'],
|
|
|
|
"ancestors expects an integer startdepth")
|
|
|
|
if n < 0:
|
|
|
|
raise error.ParseError("negative startdepth")
|
|
|
|
startdepth = n
|
2017-06-17 18:22:41 +03:00
|
|
|
if 'depth' in args:
|
|
|
|
# i18n: "ancestors" is a keyword
|
|
|
|
n = getinteger(args['depth'], _("ancestors expects an integer depth"))
|
|
|
|
if n < 0:
|
|
|
|
raise error.ParseError(_("negative depth"))
|
|
|
|
stopdepth = n + 1
|
2017-06-17 18:40:58 +03:00
|
|
|
return _ancestors(repo, subset, args['set'],
|
|
|
|
startdepth=startdepth, stopdepth=stopdepth)
|
2012-04-11 13:25:34 +04:00
|
|
|
|
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)
|
|
|
|
|
2017-05-27 20:25:09 +03:00
|
|
|
def _childrenspec(repo, subset, x, n, order):
|
|
|
|
"""Changesets that are the Nth child of a changeset
|
|
|
|
in set.
|
|
|
|
"""
|
|
|
|
cs = set()
|
|
|
|
for r in getset(repo, fullreposet(repo), x):
|
|
|
|
for i in range(n):
|
|
|
|
c = repo[r].children()
|
|
|
|
if len(c) == 0:
|
|
|
|
break
|
|
|
|
if len(c) > 1:
|
|
|
|
raise error.RepoLookupError(
|
|
|
|
_("revision in set has more than one child"))
|
2017-06-18 06:25:23 +03:00
|
|
|
r = c[0].rev()
|
2017-05-27 20:25:09 +03:00
|
|
|
else:
|
|
|
|
cs.add(r)
|
|
|
|
return subset & cs
|
|
|
|
|
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
|
|
|
"""
|
2017-01-09 11:39:44 +03:00
|
|
|
n = getinteger(n, _("~ expects a number"))
|
2017-05-27 20:25:09 +03:00
|
|
|
if n < 0:
|
|
|
|
# children lookup
|
|
|
|
return _childrenspec(repo, subset, x, -n, order)
|
2011-04-30 19:43:04 +04:00
|
|
|
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):
|
2017-05-22 22:38:19 +03:00
|
|
|
try:
|
|
|
|
r = cl.parentrevs(r)[0]
|
|
|
|
except error.WdirUnsupported:
|
|
|
|
r = repo[r].parents()[0].rev()
|
2011-04-30 19:43:04 +04:00
|
|
|
ps.add(r)
|
2014-09-17 21:57:47 +04:00
|
|
|
return subset & ps
|
2011-04-30 19:43:04 +04:00
|
|
|
|
2017-09-02 05:42:09 +03:00
|
|
|
@predicate('author(string)', safe=True, weight=10)
|
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
|
2017-01-12 06:42:10 +03:00
|
|
|
n = getstring(x, _("author requires a string"))
|
|
|
|
kind, pattern, matcher = _substringmatcher(n, casesensitive=False)
|
|
|
|
return subset.filter(lambda x: matcher(repo[x].user()),
|
2016-02-13 14:05:57 +03:00
|
|
|
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
|
|
|
|
2017-01-13 17:48:21 +03:00
|
|
|
Pattern matching is supported for `name`. See :hg:`help revisions.patterns`.
|
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:
|
2017-02-11 03:56:29 +03:00
|
|
|
bms = {repo[r].rev() for r in repo._bookmarks.values()}
|
|
|
|
bms -= {node.nullrev}
|
2014-09-18 06:57:09 +04:00
|
|
|
return subset & bms
|
2010-06-01 20:18:57 +04:00
|
|
|
|
2017-09-02 05:42:09 +03:00
|
|
|
@predicate('branch(string or set)', safe=True, weight=10)
|
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
|
|
|
|
2017-01-08 07:35:35 +03:00
|
|
|
Pattern matching is supported for `string`. See
|
2017-01-13 17:48:21 +03:00
|
|
|
:hg:`help revisions.patterns`.
|
2010-10-23 21:21:51 +04:00
|
|
|
"""
|
2015-02-11 06:57:51 +03:00
|
|
|
getbi = repo.revbranchcache().branchinfo
|
2016-08-20 12:15:19 +03:00
|
|
|
def getbranch(r):
|
|
|
|
try:
|
|
|
|
return getbi(r)[0]
|
|
|
|
except error.WdirUnsupported:
|
|
|
|
return repo[r].branch()
|
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-08-20 12:15:19 +03:00
|
|
|
return subset.filter(lambda r: matcher(getbranch(r)),
|
2016-02-13 14:05:57 +03:00
|
|
|
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-08-20 12:15:19 +03:00
|
|
|
return subset.filter(lambda r: matcher(getbranch(r)),
|
2016-02-13 14:05:57 +03:00
|
|
|
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:
|
2016-08-20 12:15:19 +03:00
|
|
|
b.add(getbranch(r))
|
2014-10-08 13:47:00 +04:00
|
|
|
c = s.__contains__
|
2016-08-20 12:15:19 +03:00
|
|
|
return subset.filter(lambda r: c(r) or getbranch(r) in b,
|
2016-02-13 14:05:57 +03:00
|
|
|
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):
|
2017-08-03 15:08:39 +03:00
|
|
|
msg = ("'bumped()' is deprecated, "
|
|
|
|
"use 'phasedivergent()'")
|
|
|
|
repo.ui.deprecwarn(msg, '4.4')
|
|
|
|
|
|
|
|
return phasedivergent(repo, subset, x)
|
|
|
|
|
|
|
|
@predicate('phasedivergent()', safe=True)
|
|
|
|
def phasedivergent(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
|
|
|
|
2017-08-03 15:08:39 +03:00
|
|
|
Only non-public and non-obsolete changesets can be `phasedivergent`.
|
2017-08-16 17:48:41 +03:00
|
|
|
(EXPERIMENTAL)
|
2012-10-19 02:39:06 +04:00
|
|
|
"""
|
2017-08-03 15:08:39 +03:00
|
|
|
# i18n: "phasedivergent" is a keyword
|
|
|
|
getargs(x, 0, 0, _("phasedivergent takes no arguments"))
|
2017-08-04 20:39:34 +03:00
|
|
|
phasedivergent = obsmod.getrevs(repo, 'phasedivergent')
|
|
|
|
return subset & phasedivergent
|
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()
|
2015-05-23 05:04:11 +03:00
|
|
|
nullrev = node.nullrev
|
2016-06-23 22:39:05 +03:00
|
|
|
for r in subset:
|
2014-03-13 23:34:32 +04:00
|
|
|
if r <= minrev:
|
|
|
|
continue
|
2015-05-23 05:04:11 +03:00
|
|
|
p1, p2 = pr(r)
|
|
|
|
if p1 in parentset:
|
|
|
|
cs.add(r)
|
|
|
|
if p2 != nullrev and p2 in parentset:
|
|
|
|
cs.add(r)
|
2014-03-13 23:34:32 +04:00
|
|
|
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
|
|
|
|
2017-09-02 05:42:09 +03:00
|
|
|
@predicate('closed()', safe=True, weight=10)
|
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
|
|
|
|
2017-09-02 05:42:09 +03:00
|
|
|
@predicate('contains(pattern)', weight=100)
|
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
|
|
|
|
2017-09-02 05:42:09 +03:00
|
|
|
@predicate('date(interval)', safe=True, weight=10)
|
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
|
|
|
|
2017-09-02 05:42:09 +03:00
|
|
|
@predicate('desc(string)', safe=True, weight=10)
|
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.
|
2017-01-08 05:26:32 +03:00
|
|
|
|
2017-01-08 07:35:35 +03:00
|
|
|
Pattern matching is supported for `string`. See
|
2017-01-13 17:48:21 +03:00
|
|
|
:hg:`help revisions.patterns`.
|
2011-06-17 00:47:34 +04:00
|
|
|
"""
|
|
|
|
# i18n: "desc" is a keyword
|
2017-01-08 05:26:32 +03:00
|
|
|
ds = getstring(x, _("desc requires a string"))
|
2014-01-31 03:39:56 +04:00
|
|
|
|
2017-01-08 05:26:32 +03:00
|
|
|
kind, pattern, matcher = _substringmatcher(ds, casesensitive=False)
|
2014-01-31 03:39:56 +04:00
|
|
|
|
2017-01-08 05:26:32 +03:00
|
|
|
return subset.filter(lambda r: matcher(repo[r].description()),
|
|
|
|
condrepr=('<desc %r>', ds))
|
2011-06-17 00:47:34 +04:00
|
|
|
|
revset: add depth limit to descendants() (issue5374)
This is naive implementation using two-pass scanning. Tracking descendants
isn't an easy problem if both start and stop depths are specified. It's
impractical to remember all possible depths of each node while scanning from
roots to descendants because the number of depths explodes. Instead, we could
cache (min, max) depths as a good approximation and track ancestors back when
needed, but that's likely to have off-by-one bug.
Since this implementation appears not significantly slower, and is quite
straightforward, I think it's good enough for practical use cases. The time
and space complexity is O(n) ish.
revisions:
0) 1-pass scanning with (min, max)-depth cache (worst-case quadratic)
1) 2-pass scanning (this version)
repository:
mozilla-central
# descendants(0) (for reference)
*) 0.430353
# descendants(0, depth=1000)
0) 0.264889
1) 0.398289
# descendants(limit(tip:0, 1, offset=10000), depth=1000)
0) 0.025478
1) 0.029099
# descendants(0, depth=2000, startdepth=1000)
0) painfully slow (due to quadratic backtracking of ancestors)
1) 1.531138
2017-06-24 17:05:57 +03:00
|
|
|
def _descendants(repo, subset, x, followfirst=False, startdepth=None,
|
|
|
|
stopdepth=None):
|
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()
|
revset: add depth limit to descendants() (issue5374)
This is naive implementation using two-pass scanning. Tracking descendants
isn't an easy problem if both start and stop depths are specified. It's
impractical to remember all possible depths of each node while scanning from
roots to descendants because the number of depths explodes. Instead, we could
cache (min, max) depths as a good approximation and track ancestors back when
needed, but that's likely to have off-by-one bug.
Since this implementation appears not significantly slower, and is quite
straightforward, I think it's good enough for practical use cases. The time
and space complexity is O(n) ish.
revisions:
0) 1-pass scanning with (min, max)-depth cache (worst-case quadratic)
1) 2-pass scanning (this version)
repository:
mozilla-central
# descendants(0) (for reference)
*) 0.430353
# descendants(0, depth=1000)
0) 0.264889
1) 0.398289
# descendants(limit(tip:0, 1, offset=10000), depth=1000)
0) 0.025478
1) 0.029099
# descendants(0, depth=2000, startdepth=1000)
0) painfully slow (due to quadratic backtracking of ancestors)
1) 1.531138
2017-06-24 17:05:57 +03:00
|
|
|
s = dagop.revdescendants(repo, roots, followfirst, startdepth, stopdepth)
|
2017-06-20 16:26:52 +03:00
|
|
|
return subset & s
|
2010-06-01 20:18:57 +04:00
|
|
|
|
revset: add depth limit to descendants() (issue5374)
This is naive implementation using two-pass scanning. Tracking descendants
isn't an easy problem if both start and stop depths are specified. It's
impractical to remember all possible depths of each node while scanning from
roots to descendants because the number of depths explodes. Instead, we could
cache (min, max) depths as a good approximation and track ancestors back when
needed, but that's likely to have off-by-one bug.
Since this implementation appears not significantly slower, and is quite
straightforward, I think it's good enough for practical use cases. The time
and space complexity is O(n) ish.
revisions:
0) 1-pass scanning with (min, max)-depth cache (worst-case quadratic)
1) 2-pass scanning (this version)
repository:
mozilla-central
# descendants(0) (for reference)
*) 0.430353
# descendants(0, depth=1000)
0) 0.264889
1) 0.398289
# descendants(limit(tip:0, 1, offset=10000), depth=1000)
0) 0.025478
1) 0.029099
# descendants(0, depth=2000, startdepth=1000)
0) painfully slow (due to quadratic backtracking of ancestors)
1) 1.531138
2017-06-24 17:05:57 +03:00
|
|
|
@predicate('descendants(set[, depth])', safe=True)
|
2012-04-11 13:25:34 +04:00
|
|
|
def descendants(repo, subset, x):
|
2017-06-18 16:46:56 +03:00
|
|
|
"""Changesets which are descendants of changesets in set, including the
|
|
|
|
given changesets themselves.
|
revset: add depth limit to descendants() (issue5374)
This is naive implementation using two-pass scanning. Tracking descendants
isn't an easy problem if both start and stop depths are specified. It's
impractical to remember all possible depths of each node while scanning from
roots to descendants because the number of depths explodes. Instead, we could
cache (min, max) depths as a good approximation and track ancestors back when
needed, but that's likely to have off-by-one bug.
Since this implementation appears not significantly slower, and is quite
straightforward, I think it's good enough for practical use cases. The time
and space complexity is O(n) ish.
revisions:
0) 1-pass scanning with (min, max)-depth cache (worst-case quadratic)
1) 2-pass scanning (this version)
repository:
mozilla-central
# descendants(0) (for reference)
*) 0.430353
# descendants(0, depth=1000)
0) 0.264889
1) 0.398289
# descendants(limit(tip:0, 1, offset=10000), depth=1000)
0) 0.025478
1) 0.029099
# descendants(0, depth=2000, startdepth=1000)
0) painfully slow (due to quadratic backtracking of ancestors)
1) 1.531138
2017-06-24 17:05:57 +03:00
|
|
|
|
|
|
|
If depth is specified, the result only includes changesets up to
|
|
|
|
the specified generation.
|
2012-04-11 13:25:34 +04:00
|
|
|
"""
|
revset: add depth limit to descendants() (issue5374)
This is naive implementation using two-pass scanning. Tracking descendants
isn't an easy problem if both start and stop depths are specified. It's
impractical to remember all possible depths of each node while scanning from
roots to descendants because the number of depths explodes. Instead, we could
cache (min, max) depths as a good approximation and track ancestors back when
needed, but that's likely to have off-by-one bug.
Since this implementation appears not significantly slower, and is quite
straightforward, I think it's good enough for practical use cases. The time
and space complexity is O(n) ish.
revisions:
0) 1-pass scanning with (min, max)-depth cache (worst-case quadratic)
1) 2-pass scanning (this version)
repository:
mozilla-central
# descendants(0) (for reference)
*) 0.430353
# descendants(0, depth=1000)
0) 0.264889
1) 0.398289
# descendants(limit(tip:0, 1, offset=10000), depth=1000)
0) 0.025478
1) 0.029099
# descendants(0, depth=2000, startdepth=1000)
0) painfully slow (due to quadratic backtracking of ancestors)
1) 1.531138
2017-06-24 17:05:57 +03:00
|
|
|
# startdepth is for internal use only until we can decide the UI
|
|
|
|
args = getargsdict(x, 'descendants', 'set depth startdepth')
|
2017-06-18 06:06:22 +03:00
|
|
|
if 'set' not in args:
|
|
|
|
# i18n: "descendants" is a keyword
|
|
|
|
raise error.ParseError(_('descendants takes at least 1 argument'))
|
revset: add depth limit to descendants() (issue5374)
This is naive implementation using two-pass scanning. Tracking descendants
isn't an easy problem if both start and stop depths are specified. It's
impractical to remember all possible depths of each node while scanning from
roots to descendants because the number of depths explodes. Instead, we could
cache (min, max) depths as a good approximation and track ancestors back when
needed, but that's likely to have off-by-one bug.
Since this implementation appears not significantly slower, and is quite
straightforward, I think it's good enough for practical use cases. The time
and space complexity is O(n) ish.
revisions:
0) 1-pass scanning with (min, max)-depth cache (worst-case quadratic)
1) 2-pass scanning (this version)
repository:
mozilla-central
# descendants(0) (for reference)
*) 0.430353
# descendants(0, depth=1000)
0) 0.264889
1) 0.398289
# descendants(limit(tip:0, 1, offset=10000), depth=1000)
0) 0.025478
1) 0.029099
# descendants(0, depth=2000, startdepth=1000)
0) painfully slow (due to quadratic backtracking of ancestors)
1) 1.531138
2017-06-24 17:05:57 +03:00
|
|
|
startdepth = stopdepth = None
|
|
|
|
if 'startdepth' in args:
|
|
|
|
n = getinteger(args['startdepth'],
|
|
|
|
"descendants expects an integer startdepth")
|
|
|
|
if n < 0:
|
|
|
|
raise error.ParseError("negative startdepth")
|
|
|
|
startdepth = n
|
|
|
|
if 'depth' in args:
|
|
|
|
# i18n: "descendants" is a keyword
|
|
|
|
n = getinteger(args['depth'], _("descendants expects an integer depth"))
|
|
|
|
if n < 0:
|
|
|
|
raise error.ParseError(_("negative depth"))
|
|
|
|
stopdepth = n + 1
|
|
|
|
return _descendants(repo, subset, args['set'],
|
|
|
|
startdepth=startdepth, stopdepth=stopdepth)
|
2012-04-11 13:25:34 +04:00
|
|
|
|
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)
|
|
|
|
|
2017-09-02 05:42:09 +03:00
|
|
|
@predicate('destination([set])', safe=True, weight=10)
|
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):
|
2017-08-03 15:01:51 +03:00
|
|
|
msg = ("'divergent()' is deprecated, "
|
|
|
|
"use 'contentdivergent()'")
|
|
|
|
repo.ui.deprecwarn(msg, '4.4')
|
|
|
|
|
|
|
|
return contentdivergent(repo, subset, x)
|
|
|
|
|
|
|
|
@predicate('contentdivergent()', safe=True)
|
|
|
|
def contentdivergent(repo, subset, x):
|
2015-12-29 17:58:30 +03:00
|
|
|
"""
|
2017-08-16 17:48:41 +03:00
|
|
|
Final successors of changesets with an alternative set of final
|
|
|
|
successors. (EXPERIMENTAL)
|
2012-12-12 06:12:55 +04:00
|
|
|
"""
|
2017-08-03 15:01:51 +03:00
|
|
|
# i18n: "contentdivergent" is a keyword
|
|
|
|
getargs(x, 0, 0, _("contentdivergent takes no arguments"))
|
2017-08-04 20:36:27 +03:00
|
|
|
contentdivergent = obsmod.getrevs(repo, 'contentdivergent')
|
|
|
|
return subset & contentdivergent
|
2012-12-12 06:12:55 +04:00
|
|
|
|
2017-10-01 12:50:00 +03:00
|
|
|
@predicate('extdata(source)', safe=False, weight=100)
|
|
|
|
def extdata(repo, subset, x):
|
|
|
|
"""Changesets in the specified extdata source. (EXPERIMENTAL)"""
|
|
|
|
# i18n: "extdata" is a keyword
|
|
|
|
args = getargsdict(x, 'extdata', 'source')
|
|
|
|
source = getstring(args.get('source'),
|
|
|
|
# i18n: "extdata" is a keyword
|
|
|
|
_('extdata takes at least 1 string argument'))
|
|
|
|
data = scmutil.extdatasource(repo, source)
|
|
|
|
return subset & baseset(data)
|
|
|
|
|
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.
|
|
|
|
|
2017-01-08 07:35:35 +03:00
|
|
|
Pattern matching is supported for `value`. See
|
2017-01-13 17:48:21 +03:00
|
|
|
:hg:`help revisions.patterns`.
|
2012-05-31 02:14:04 +04:00
|
|
|
"""
|
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
|
|
|
|
2017-09-02 05:42:09 +03:00
|
|
|
@predicate('first(set, [n])', safe=True, takeorder=True, weight=0)
|
2017-06-10 13:48:48 +03:00
|
|
|
def first(repo, subset, x, order):
|
2015-12-29 17:58:30 +03:00
|
|
|
"""An alias for limit().
|
2011-09-17 21:34:47 +04:00
|
|
|
"""
|
2017-06-10 13:48:48 +03:00
|
|
|
return limit(repo, subset, x, order)
|
2011-09-17 21:34:47 +04:00
|
|
|
|
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:
|
2016-10-16 12:03:24 +03:00
|
|
|
s = dagop.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)
|
|
|
|
|
2017-01-16 11:24:47 +03:00
|
|
|
@predicate('followlines(file, fromline:toline[, startrev=., descend=False])',
|
|
|
|
safe=True)
|
2017-01-04 18:47:49 +03:00
|
|
|
def followlines(repo, subset, x):
|
|
|
|
"""Changesets modifying `file` in line range ('fromline', 'toline').
|
|
|
|
|
2017-01-09 10:16:26 +03:00
|
|
|
Line range corresponds to 'file' content at 'startrev' and should hence be
|
|
|
|
consistent with file size. If startrev is not specified, working directory's
|
2017-01-04 18:47:49 +03:00
|
|
|
parent is used.
|
2017-01-16 11:24:47 +03:00
|
|
|
|
|
|
|
By default, ancestors of 'startrev' are returned. If 'descend' is True,
|
|
|
|
descendants of 'startrev' are returned though renames are (currently) not
|
|
|
|
followed in this direction.
|
2017-01-04 18:47:49 +03:00
|
|
|
"""
|
2017-01-16 11:24:47 +03:00
|
|
|
args = getargsdict(x, 'followlines', 'file *lines startrev descend')
|
2017-01-09 11:58:19 +03:00
|
|
|
if len(args['lines']) != 1:
|
|
|
|
raise error.ParseError(_("followlines requires a line range"))
|
2017-01-04 18:47:49 +03:00
|
|
|
|
|
|
|
rev = '.'
|
2017-01-09 10:16:26 +03:00
|
|
|
if 'startrev' in args:
|
|
|
|
revs = getset(repo, fullreposet(repo), args['startrev'])
|
2017-01-09 10:02:56 +03:00
|
|
|
if len(revs) != 1:
|
|
|
|
raise error.ParseError(
|
2017-04-30 23:52:36 +03:00
|
|
|
# i18n: "followlines" is a keyword
|
2017-01-09 10:02:56 +03:00
|
|
|
_("followlines expects exactly one revision"))
|
|
|
|
rev = revs.last()
|
|
|
|
|
|
|
|
pat = getstring(args['file'], _("followlines requires a pattern"))
|
2017-10-04 16:27:43 +03:00
|
|
|
# i18n: "followlines" is a keyword
|
|
|
|
msg = _("followlines expects exactly one file")
|
|
|
|
fname = scmutil.parsefollowlinespattern(repo, rev, pat, msg)
|
2017-04-30 23:52:36 +03:00
|
|
|
# i18n: "followlines" is a keyword
|
2017-01-09 11:58:19 +03:00
|
|
|
lr = getrange(args['lines'][0], _("followlines expects a line range"))
|
2017-01-09 11:39:44 +03:00
|
|
|
fromline, toline = [getinteger(a, _("line range bounds must be integers"))
|
2017-01-09 11:58:19 +03:00
|
|
|
for a in lr]
|
2017-02-24 20:39:08 +03:00
|
|
|
fromline, toline = util.processlinerange(fromline, toline)
|
2017-01-04 18:47:49 +03:00
|
|
|
|
|
|
|
fctx = repo[rev].filectx(fname)
|
2017-04-15 12:29:42 +03:00
|
|
|
descend = False
|
|
|
|
if 'descend' in args:
|
|
|
|
descend = getboolean(args['descend'],
|
2017-04-30 23:52:36 +03:00
|
|
|
# i18n: "descend" is a keyword
|
|
|
|
_("descend argument must be a boolean"))
|
2017-04-15 12:29:42 +03:00
|
|
|
if descend:
|
2017-01-16 11:24:47 +03:00
|
|
|
rs = generatorset(
|
|
|
|
(c.rev() for c, _linerange
|
2017-02-19 13:37:14 +03:00
|
|
|
in dagop.blockdescendants(fctx, fromline, toline)),
|
2017-01-16 11:24:47 +03:00
|
|
|
iterasc=True)
|
|
|
|
else:
|
|
|
|
rs = generatorset(
|
|
|
|
(c.rev() for c, _linerange
|
2017-02-19 13:37:14 +03:00
|
|
|
in dagop.blockancestors(fctx, fromline, toline)),
|
2017-01-16 11:24:47 +03:00
|
|
|
iterasc=False)
|
|
|
|
return subset & rs
|
2017-01-04 18:47:49 +03:00
|
|
|
|
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
|
|
|
|
2017-09-02 05:42:09 +03:00
|
|
|
@predicate('grep(regex)', weight=10)
|
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
|
|
|
|
2017-09-02 05:42:09 +03:00
|
|
|
@predicate('file(pattern)', safe=True, weight=10)
|
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
|
|
|
|
2017-09-02 05:42:09 +03:00
|
|
|
@predicate('keyword(string)', safe=True, weight=10)
|
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.
|
2017-01-12 07:13:51 +03:00
|
|
|
|
|
|
|
For a regular expression or case sensitive search of these fields, use
|
|
|
|
``grep(regex)``.
|
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
|
|
|
|
2017-09-02 05:42:09 +03:00
|
|
|
@predicate('limit(set[, n[, offset]])', safe=True, takeorder=True, weight=0)
|
2017-06-10 13:48:48 +03:00
|
|
|
def limit(repo, subset, x, order):
|
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"))
|
2017-01-09 11:45:11 +03:00
|
|
|
# i18n: "limit" is a keyword
|
|
|
|
lim = getinteger(args.get('n'), _("limit expects a number"), default=1)
|
2017-06-10 12:35:11 +03:00
|
|
|
if lim < 0:
|
|
|
|
raise error.ParseError(_("negative number to select"))
|
2017-01-09 11:45:11 +03:00
|
|
|
# i18n: "limit" is a keyword
|
|
|
|
ofs = getinteger(args.get('offset'), _("limit expects a number"), default=0)
|
2017-01-09 11:39:44 +03:00
|
|
|
if ofs < 0:
|
|
|
|
raise error.ParseError(_("negative offset"))
|
2015-10-12 11:19:22 +03:00
|
|
|
os = getset(repo, fullreposet(repo), args['set'])
|
2015-03-23 18:14:53 +03:00
|
|
|
ls = os.slice(ofs, ofs + lim)
|
2017-06-10 13:48:48 +03:00
|
|
|
if order == followorder and lim > 1:
|
|
|
|
return subset & ls
|
2017-06-10 13:41:42 +03:00
|
|
|
return ls & subset
|
2011-04-08 18:47:58 +04:00
|
|
|
|
2017-06-10 13:48:48 +03:00
|
|
|
@predicate('last(set, [n])', safe=True, takeorder=True)
|
|
|
|
def last(repo, subset, x, order):
|
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"))
|
2017-01-09 11:39:44 +03:00
|
|
|
lim = 1
|
|
|
|
if len(l) == 2:
|
2011-04-30 19:56:43 +04:00
|
|
|
# i18n: "last" is a keyword
|
2017-01-09 11:39:44 +03:00
|
|
|
lim = getinteger(l[1], _("last expects a number"))
|
2017-06-10 12:35:11 +03:00
|
|
|
if lim < 0:
|
|
|
|
raise error.ParseError(_("negative number to select"))
|
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()
|
2015-03-23 18:14:53 +03:00
|
|
|
ls = os.slice(0, lim)
|
2017-06-10 13:48:48 +03:00
|
|
|
if order == followorder and lim > 1:
|
|
|
|
return subset & ls
|
2017-06-10 13:41:42 +03:00
|
|
|
ls.reverse()
|
|
|
|
return ls & subset
|
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
|
|
|
|
2017-09-02 05:42:09 +03:00
|
|
|
@predicate('modifies(pattern)', safe=True, weight=30)
|
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
|
|
|
|
2017-01-08 07:35:35 +03:00
|
|
|
Pattern matching is supported for `namespace`. See
|
2017-01-13 17:48:21 +03:00
|
|
|
:hg:`help revisions.patterns`.
|
2015-01-14 02:07:08 +03:00
|
|
|
"""
|
|
|
|
# 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
|
|
|
|
2017-02-11 03:56:29 +03:00
|
|
|
names -= {node.nullrev}
|
2015-01-14 02:07:08 +03:00
|
|
|
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))
|
2017-06-03 14:39:33 +03:00
|
|
|
except error.WdirUnsupported:
|
|
|
|
rn = node.wdirrev
|
2015-04-20 10:52:20 +03:00
|
|
|
except (LookupError, TypeError):
|
|
|
|
rn = None
|
2011-04-08 18:47:58 +04:00
|
|
|
else:
|
2012-05-15 03:25:13 +04:00
|
|
|
rn = None
|
2016-08-19 12:26:04 +03:00
|
|
|
try:
|
|
|
|
pm = repo.changelog._partialmatch(n)
|
|
|
|
if pm is not None:
|
2017-06-03 14:39:33 +03:00
|
|
|
rn = repo.changelog.rev(pm)
|
2016-08-19 12:26:04 +03:00
|
|
|
except error.WdirUnsupported:
|
|
|
|
rn = node.wdirrev
|
2012-05-15 03:25:13 +04:00
|
|
|
|
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()
|
|
|
|
|
2016-10-16 12:03:24 +03:00
|
|
|
descendants = set(dagop.revdescendants(repo, include, False))
|
2014-12-03 16:52:54 +03:00
|
|
|
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
|
2016-10-18 00:16:55 +03:00
|
|
|
# some optimizations 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
|
|
|
|
|
2017-02-11 03:56:29 +03:00
|
|
|
o = {_firstsrc(r) for r in dests}
|
|
|
|
o -= {None}
|
2015-06-12 01:45:02 +03:00
|
|
|
# XXX we should turn this into a baseset instead of a set, smartset may do
|
2016-10-18 00:16:55 +03:00
|
|
|
# some optimizations 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
|
|
|
|
2017-09-02 05:42:09 +03:00
|
|
|
@predicate('outgoing([path])', safe=False, weight=10)
|
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
|
2017-02-11 03:56:29 +03:00
|
|
|
o = {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):
|
2017-05-19 17:36:45 +03:00
|
|
|
try:
|
|
|
|
ps.add(cl.parentrevs(r)[0])
|
|
|
|
except error.WdirUnsupported:
|
|
|
|
ps.add(repo[r].parents()[0].rev())
|
2017-02-11 03:56:29 +03:00
|
|
|
ps -= {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
|
2016-10-18 00:16:55 +03:00
|
|
|
# some optimizations 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):
|
2017-05-21 23:44:22 +03:00
|
|
|
try:
|
|
|
|
ps.add(cl.parentrevs(r)[1])
|
|
|
|
except error.WdirUnsupported:
|
|
|
|
parents = repo[r].parents()
|
|
|
|
if len(parents) == 2:
|
|
|
|
ps.add(parents[1])
|
2017-02-11 03:56:29 +03:00
|
|
|
ps -= {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
|
2016-10-18 00:16:55 +03:00
|
|
|
# some optimizations 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):
|
2017-05-21 23:33:43 +03:00
|
|
|
try:
|
2015-07-03 09:46:18 +03:00
|
|
|
up(parentrevs(r))
|
2017-05-21 23:33:43 +03:00
|
|
|
except error.WdirUnsupported:
|
|
|
|
up(p.rev() for p in repo[r].parents())
|
2017-02-11 03:56:29 +03:00
|
|
|
ps -= {node.nullrev}
|
2014-09-17 15:55:55 +04:00
|
|
|
return subset & ps
|
2010-06-01 20:18:57 +04:00
|
|
|
|
2017-02-18 11:39:31 +03:00
|
|
|
def _phase(repo, subset, *targets):
|
|
|
|
"""helper to select all rev in <targets> phases"""
|
|
|
|
s = repo._phasecache.getrevset(repo, targets)
|
|
|
|
return subset & s
|
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:
|
2017-05-21 22:31:45 +03:00
|
|
|
try:
|
|
|
|
ps.add(cl.parentrevs(r)[0])
|
|
|
|
except error.WdirUnsupported:
|
|
|
|
ps.add(repo[r].parents()[0].rev())
|
2017-05-21 23:08:00 +03:00
|
|
|
else:
|
2017-05-21 22:31:45 +03:00
|
|
|
try:
|
|
|
|
parents = cl.parentrevs(r)
|
|
|
|
if parents[1] != node.nullrev:
|
|
|
|
ps.add(parents[1])
|
|
|
|
except error.WdirUnsupported:
|
|
|
|
parents = repo[r].parents()
|
|
|
|
if len(parents) == 2:
|
|
|
|
ps.add(parents[1].rev())
|
2014-01-25 04:57:44 +04:00
|
|
|
return subset & ps
|
2011-04-30 19:43:04 +04:00
|
|
|
|
2017-08-20 20:55:11 +03:00
|
|
|
@predicate('present(set)', safe=True, takeorder=True)
|
|
|
|
def present(repo, subset, x, order):
|
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:
|
2017-08-20 20:55:11 +03:00
|
|
|
return getset(repo, subset, x, order)
|
2010-08-13 20:11:41 +04:00
|
|
|
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")
|
2017-02-18 11:39:31 +03:00
|
|
|
return _phase(repo, subset, phases.draft, phases.secret)
|
2015-04-25 00:30:30 +03:00
|
|
|
|
2017-08-29 00:49:00 +03:00
|
|
|
# for internal use
|
|
|
|
@predicate('_phaseandancestors(phasename, set)', safe=True)
|
|
|
|
def _phaseandancestors(repo, subset, x):
|
|
|
|
# equivalent to (phasename() & ancestors(set)) but more efficient
|
|
|
|
# phasename could be one of 'draft', 'secret', or '_notpublic'
|
|
|
|
args = getargs(x, 2, 2, "_phaseandancestors requires two arguments")
|
|
|
|
phasename = getsymbol(args[0])
|
|
|
|
s = getset(repo, fullreposet(repo), args[1])
|
|
|
|
|
|
|
|
draft = phases.draft
|
|
|
|
secret = phases.secret
|
|
|
|
phasenamemap = {
|
|
|
|
'_notpublic': draft,
|
|
|
|
'draft': draft, # follow secret's ancestors
|
|
|
|
'secret': secret,
|
|
|
|
}
|
|
|
|
if phasename not in phasenamemap:
|
|
|
|
raise error.ParseError('%r is not a valid phasename' % phasename)
|
|
|
|
|
|
|
|
minimalphase = phasenamemap[phasename]
|
|
|
|
getphase = repo._phasecache.phase
|
|
|
|
|
|
|
|
def cutfunc(rev):
|
|
|
|
return getphase(repo, rev) < minimalphase
|
|
|
|
|
|
|
|
revs = dagop.revancestors(repo, s, cutfunc=cutfunc)
|
|
|
|
|
|
|
|
if phasename == 'draft': # need to remove secret changesets
|
|
|
|
revs = revs.filter(lambda r: getphase(repo, r) == draft)
|
|
|
|
return subset & revs
|
|
|
|
|
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
|
|
|
|
2017-01-20 15:33:18 +03:00
|
|
|
@predicate('remote([id [,path]])', safe=False)
|
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
|
|
|
|
2017-09-02 05:42:09 +03:00
|
|
|
@predicate('removes(pattern)', safe=True, weight=30)
|
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"))
|
2017-06-03 14:39:33 +03:00
|
|
|
if l not in repo.changelog and l not in (node.nullrev, node.wdirrev):
|
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
|
|
|
|
2017-09-02 05:42:09 +03:00
|
|
|
@predicate('reverse(set)', safe=True, takeorder=True, weight=0)
|
2016-05-03 07:36:12 +03:00
|
|
|
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
|
|
|
"""
|
2017-08-20 20:55:11 +03:00
|
|
|
l = getset(repo, subset, x, order)
|
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
|
|
|
|
|
2017-09-02 05:42:09 +03:00
|
|
|
@predicate('sort(set[, [-]key... [, ...]])', safe=True, takeorder=True,
|
|
|
|
weight=10)
|
2016-05-03 07:36:12 +03:00
|
|
|
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)
|
2017-08-20 20:55:11 +03:00
|
|
|
revs = getset(repo, subset, s, order)
|
2016-06-15 15:26:45 +03:00
|
|
|
|
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-10-16 12:03:24 +03:00
|
|
|
revs = baseset(dagop.toposort(revs, repo.changelog.parentrevs,
|
|
|
|
firstbranch),
|
2016-06-13 20:20:00 +03:00
|
|
|
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
|
|
|
|
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
|
|
|
|
2017-07-10 20:56:40 +03:00
|
|
|
def _mapbynodefunc(repo, s, f):
|
|
|
|
"""(repo, smartset, [node] -> [node]) -> smartset
|
|
|
|
|
|
|
|
Helper method to map a smartset to another smartset given a function only
|
|
|
|
talking about nodes. Handles converting between rev numbers and nodes, and
|
|
|
|
filtering.
|
|
|
|
"""
|
|
|
|
cl = repo.unfiltered().changelog
|
|
|
|
torev = cl.rev
|
|
|
|
tonode = cl.node
|
|
|
|
nodemap = cl.nodemap
|
|
|
|
result = set(torev(n) for n in f(tonode(r) for r in s) if n in nodemap)
|
|
|
|
return smartset.baseset(result - repo.changelog.filteredrevs)
|
|
|
|
|
|
|
|
@predicate('successors(set)', safe=True)
|
|
|
|
def successors(repo, subset, x):
|
|
|
|
"""All successors for set, including the given set themselves"""
|
|
|
|
s = getset(repo, fullreposet(repo), x)
|
|
|
|
f = lambda nodes: obsutil.allsuccessors(repo.obsstore, nodes)
|
|
|
|
d = _mapbynodefunc(repo, s, f)
|
|
|
|
return subset & d
|
|
|
|
|
2017-01-12 06:42:10 +03:00
|
|
|
def _substringmatcher(pattern, casesensitive=True):
|
|
|
|
kind, pattern, matcher = util.stringmatcher(pattern,
|
|
|
|
casesensitive=casesensitive)
|
2012-05-31 02:13:58 +04:00
|
|
|
if kind == 'literal':
|
2017-01-12 06:42:10 +03:00
|
|
|
if not casesensitive:
|
|
|
|
pattern = encoding.lower(pattern)
|
|
|
|
matcher = lambda s: pattern in encoding.lower(s)
|
|
|
|
else:
|
|
|
|
matcher = lambda s: pattern in s
|
2012-05-31 02:13:58 +04:00
|
|
|
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
|
|
|
|
2017-01-08 07:35:35 +03:00
|
|
|
Pattern matching is supported for `name`. See
|
2017-01-13 17:48:21 +03:00
|
|
|
:hg:`help revisions.patterns`.
|
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)
|
2017-02-11 03:56:29 +03:00
|
|
|
s = {repo[tn].rev()}
|
2012-05-31 02:13:33 +04:00
|
|
|
else:
|
2017-02-11 03:56:29 +03:00
|
|
|
s = {cl.rev(n) for t, n in repo.tagslist() if matcher(t)}
|
2010-10-10 21:41:36 +04:00
|
|
|
else:
|
2017-02-11 03:56:29 +03:00
|
|
|
s = {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):
|
2017-08-03 14:48:39 +03:00
|
|
|
msg = ("'unstable()' is deprecated, "
|
|
|
|
"use 'orphan()'")
|
|
|
|
repo.ui.deprecwarn(msg, '4.4')
|
|
|
|
|
|
|
|
return orphan(repo, subset, x)
|
|
|
|
|
|
|
|
@predicate('orphan()', safe=True)
|
|
|
|
def orphan(repo, subset, x):
|
2017-08-16 17:48:41 +03:00
|
|
|
"""Non-obsolete changesets with obsolete ancestors. (EXPERIMENTAL)
|
2012-07-30 17:48:04 +04:00
|
|
|
"""
|
2017-08-03 14:48:39 +03:00
|
|
|
# i18n: "orphan" is a keyword
|
|
|
|
getargs(x, 0, 0, _("orphan takes no arguments"))
|
2017-08-04 20:27:39 +03:00
|
|
|
orphan = obsmod.getrevs(repo, 'orphan')
|
|
|
|
return subset & orphan
|
2012-07-06 02:18:09 +04:00
|
|
|
|
|
|
|
|
2017-09-02 05:42:09 +03:00
|
|
|
@predicate('user(string)', safe=True, weight=10)
|
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
|
|
|
|
2017-01-08 07:35:35 +03:00
|
|
|
Pattern matching is supported for `string`. See
|
2017-01-13 17:48:21 +03:00
|
|
|
:hg:`help revisions.patterns`.
|
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
|
|
|
|
2017-09-02 05:42:09 +03:00
|
|
|
@predicate('wdir()', safe=True, weight=0)
|
2014-08-16 08:44:16 +04:00
|
|
|
def wdir(repo, subset, x):
|
2017-01-05 16:53:42 +03:00
|
|
|
"""Working directory. (EXPERIMENTAL)"""
|
2014-08-16 08:44:16 +04:00
|
|
|
# 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:
|
2017-08-20 20:55:11 +03:00
|
|
|
revs = stringset(repo, subset, t, defineorder)
|
2015-09-02 02:46:05 +03:00
|
|
|
|
|
|
|
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
|
2017-09-02 05:42:09 +03:00
|
|
|
@predicate('_intlist', safe=True, takeorder=True, weight=0)
|
2016-06-26 12:41:28 +03:00
|
|
|
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,
|
2017-01-09 10:55:56 +03:00
|
|
|
"rangeall": rangeall,
|
2016-10-01 14:20:11 +03:00
|
|
|
"rangepre": rangepre,
|
2017-01-09 10:55:56 +03:00
|
|
|
"rangepost": rangepost,
|
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,
|
2017-08-31 02:05:12 +03:00
|
|
|
"andsmally": andsmallyset,
|
2010-06-01 20:18:57 +04:00
|
|
|
"or": orset,
|
|
|
|
"not": notset,
|
2016-02-24 21:41:15 +03:00
|
|
|
"difference": differenceset,
|
2017-07-08 07:07:59 +03:00
|
|
|
"relation": relationset,
|
|
|
|
"relsubscript": relsubscriptset,
|
|
|
|
"subscript": subscriptset,
|
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
|
|
|
}
|
|
|
|
|
2015-03-25 00:24:55 +03:00
|
|
|
def posttreebuilthook(tree, repo):
|
|
|
|
# hook for extensions to execute code on the optimized tree
|
|
|
|
pass
|
|
|
|
|
2017-08-30 16:41:36 +03:00
|
|
|
def match(ui, spec, repo=None):
|
|
|
|
"""Create a matcher for a single revision spec"""
|
|
|
|
return matchany(ui, [spec], repo=repo)
|
2015-08-07 15:31:16 +03:00
|
|
|
|
2017-08-30 16:41:36 +03:00
|
|
|
def matchany(ui, specs, repo=None, localalias=None):
|
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
|
|
|
|
|
2017-06-25 01:29:42 +03:00
|
|
|
If localalias is not None, it is a dict {name: definitionstring}. It takes
|
|
|
|
precedence over [revsetalias] config section.
|
2016-05-03 08:18:28 +03:00
|
|
|
"""
|
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:
|
2017-02-19 12:19:33 +03:00
|
|
|
tree = revsetlang.parse(specs[0], lookup)
|
2015-08-07 15:39:38 +03:00
|
|
|
else:
|
2017-02-19 12:19:33 +03:00
|
|
|
tree = ('or',
|
|
|
|
('list',) + tuple(revsetlang.parse(s, lookup) for s in specs))
|
2015-08-07 15:39:38 +03:00
|
|
|
|
2017-06-25 01:29:42 +03:00
|
|
|
aliases = []
|
|
|
|
warn = None
|
2011-07-21 23:04:57 +04:00
|
|
|
if ui:
|
2017-06-25 01:29:42 +03:00
|
|
|
aliases.extend(ui.configitems('revsetalias'))
|
|
|
|
warn = ui.warn
|
|
|
|
if localalias:
|
|
|
|
aliases.extend(localalias.items())
|
|
|
|
if aliases:
|
|
|
|
tree = revsetlang.expandaliases(tree, aliases, warn=warn)
|
2017-02-19 12:19:33 +03:00
|
|
|
tree = revsetlang.foldconcat(tree)
|
2017-08-20 20:55:11 +03:00
|
|
|
tree = revsetlang.analyze(tree)
|
2017-02-19 12:19:33 +03:00
|
|
|
tree = revsetlang.optimize(tree)
|
2015-03-25 00:24:55 +03:00
|
|
|
posttreebuilthook(tree, repo)
|
2017-08-30 16:41:36 +03:00
|
|
|
return makematcher(tree)
|
2016-08-21 05:37:00 +03:00
|
|
|
|
2017-08-30 16:41:36 +03:00
|
|
|
def makematcher(tree):
|
2016-08-21 05:37:00 +03:00
|
|
|
"""Create a matcher from an evaluatable tree"""
|
2017-08-30 16:51:28 +03:00
|
|
|
def mfunc(repo, subset=None, order=None):
|
|
|
|
if order is None:
|
|
|
|
if subset is None:
|
|
|
|
order = defineorder # 'x'
|
|
|
|
else:
|
|
|
|
order = followorder # 'subset & x'
|
2015-02-02 16:21:07 +03:00
|
|
|
if subset is None:
|
2015-01-08 17:46:54 +03:00
|
|
|
subset = fullreposet(repo)
|
2017-08-20 20:55:11 +03:00
|
|
|
return getset(repo, subset, tree, order)
|
2010-06-01 20:18:57 +04:00
|
|
|
return mfunc
|
2010-10-23 21:21:51 +04:00
|
|
|
|
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()
|