216 return subset - getset(repo, subset, x, anyorder) |
216 return subset - getset(repo, subset, x, anyorder) |
217 |
217 |
218 def relationset(repo, subset, x, y, order): |
218 def relationset(repo, subset, x, y, order): |
219 raise error.ParseError(_("can't use a relation in this context")) |
219 raise error.ParseError(_("can't use a relation in this context")) |
220 |
220 |
|
221 def generationsrel(repo, subset, x, rel, n, order): |
|
222 # TODO: support range, rewrite tests, and drop startdepth argument |
|
223 # from ancestors() and descendants() predicates |
|
224 if n <= 0: |
|
225 n = -n |
|
226 return _ancestors(repo, subset, x, startdepth=n, stopdepth=n + 1) |
|
227 else: |
|
228 return _descendants(repo, subset, x, startdepth=n, stopdepth=n + 1) |
|
229 |
221 def relsubscriptset(repo, subset, x, y, z, order): |
230 def relsubscriptset(repo, subset, x, y, z, order): |
222 # this is pretty basic implementation of 'x#y[z]' operator, still |
231 # this is pretty basic implementation of 'x#y[z]' operator, still |
223 # experimental so undocumented. see the wiki for further ideas. |
232 # experimental so undocumented. see the wiki for further ideas. |
224 # https://www.mercurial-scm.org/wiki/RevsetOperatorPlan |
233 # https://www.mercurial-scm.org/wiki/RevsetOperatorPlan |
225 rel = getsymbol(y) |
234 rel = getsymbol(y) |
226 n = getinteger(z, _("relation subscript must be an integer")) |
235 n = getinteger(z, _("relation subscript must be an integer")) |
227 |
236 |
228 # TODO: perhaps this should be a table of relation functions |
237 if rel in subscriptrelations: |
229 if rel in ('g', 'generations'): |
238 return subscriptrelations[rel](repo, subset, x, rel, n, order) |
230 # TODO: support range, rewrite tests, and drop startdepth argument |
239 |
231 # from ancestors() and descendants() predicates |
240 relnames = [r for r in subscriptrelations.keys() if len(r) > 1] |
232 if n <= 0: |
241 raise error.UnknownIdentifier(rel, relnames) |
233 n = -n |
|
234 return _ancestors(repo, subset, x, startdepth=n, stopdepth=n + 1) |
|
235 else: |
|
236 return _descendants(repo, subset, x, startdepth=n, stopdepth=n + 1) |
|
237 |
|
238 raise error.UnknownIdentifier(rel, ['generations']) |
|
239 |
242 |
240 def subscriptset(repo, subset, x, y, order): |
243 def subscriptset(repo, subset, x, y, order): |
241 raise error.ParseError(_("can't use a subscript in this context")) |
244 raise error.ParseError(_("can't use a subscript in this context")) |
242 |
245 |
243 def listset(repo, subset, *xs, **opts): |
246 def listset(repo, subset, *xs, **opts): |
2213 "ancestor": ancestorspec, |
2216 "ancestor": ancestorspec, |
2214 "parent": parentspec, |
2217 "parent": parentspec, |
2215 "parentpost": parentpost, |
2218 "parentpost": parentpost, |
2216 } |
2219 } |
2217 |
2220 |
|
2221 subscriptrelations = { |
|
2222 "g": generationsrel, |
|
2223 "generations": generationsrel, |
|
2224 } |
|
2225 |
2218 def lookupfn(repo): |
2226 def lookupfn(repo): |
2219 return lambda symbol: scmutil.isrevsymbol(repo, symbol) |
2227 return lambda symbol: scmutil.isrevsymbol(repo, symbol) |
2220 |
2228 |
2221 def match(ui, spec, lookup=None): |
2229 def match(ui, spec, lookup=None): |
2222 """Create a matcher for a single revision spec""" |
2230 """Create a matcher for a single revision spec""" |