comparison mercurial/revset.py @ 16821:0946502fd3d5

revset: add pattern matching to 'branch' revset expression
author Simon King <simon@simonking.org.uk>
date Wed, 30 May 2012 23:13:33 +0100
parents 20f55613fb2a
children da55d8a77390
comparison
equal deleted inserted replaced
16820:20f55613fb2a 16821:0946502fd3d5
323 323
324 def branch(repo, subset, x): 324 def branch(repo, subset, x):
325 """``branch(string or set)`` 325 """``branch(string or set)``
326 All changesets belonging to the given branch or the branches of the given 326 All changesets belonging to the given branch or the branches of the given
327 changesets. 327 changesets.
328
329 If `string` starts with `re:`, the remainder of the name is treated as
330 a regular expression. To match a branch that actually starts with `re:`,
331 use the prefix `literal:`.
328 """ 332 """
329 try: 333 try:
330 b = getstring(x, '') 334 b = getstring(x, '')
331 if b in repo.branchmap():
332 return [r for r in subset if repo[r].branch() == b]
333 except error.ParseError: 335 except error.ParseError:
334 # not a string, but another revspec, e.g. tip() 336 # not a string, but another revspec, e.g. tip()
335 pass 337 pass
338 else:
339 kind, pattern, matcher = _stringmatcher(b)
340 if kind == 'literal':
341 # note: falls through to the revspec case if no branch with
342 # this name exists
343 if pattern in repo.branchmap():
344 return [r for r in subset if matcher(repo[r].branch())]
345 else:
346 return [r for r in subset if matcher(repo[r].branch())]
336 347
337 s = getset(repo, range(len(repo)), x) 348 s = getset(repo, range(len(repo)), x)
338 b = set() 349 b = set()
339 for r in s: 350 for r in s:
340 b.add(repo[r].branch()) 351 b.add(repo[r].branch())