Mercurial > hg
comparison mercurial/revset.py @ 22499:8c9f9e346acc
revset: unify code flow in `bookmark`
We refactor the code of the bookmark revset to have a single return. This will
allow us to sanitize the content of the set.
author | Pierre-Yves David <pierre-yves.david@fb.com> |
---|---|
date | Wed, 17 Sep 2014 10:58:25 -0700 |
parents | 64673dc48931 |
children | 171015d3b30c |
comparison
equal
deleted
inserted
replaced
22498:64673dc48931 | 22499:8c9f9e346acc |
---|---|
446 if args: | 446 if args: |
447 bm = getstring(args[0], | 447 bm = getstring(args[0], |
448 # i18n: "bookmark" is a keyword | 448 # i18n: "bookmark" is a keyword |
449 _('the argument to bookmark must be a string')) | 449 _('the argument to bookmark must be a string')) |
450 kind, pattern, matcher = _stringmatcher(bm) | 450 kind, pattern, matcher = _stringmatcher(bm) |
451 bms = set() | |
451 if kind == 'literal': | 452 if kind == 'literal': |
452 bmrev = repo._bookmarks.get(pattern, None) | 453 bmrev = repo._bookmarks.get(pattern, None) |
453 if not bmrev: | 454 if not bmrev: |
454 raise util.Abort(_("bookmark '%s' does not exist") % bm) | 455 raise util.Abort(_("bookmark '%s' does not exist") % bm) |
455 bmrev = repo[bmrev].rev() | 456 bms.add(repo[bmrev].rev()) |
456 return subset.filter(lambda r: r == bmrev) | |
457 else: | 457 else: |
458 matchrevs = set() | 458 matchrevs = set() |
459 for name, bmrev in repo._bookmarks.iteritems(): | 459 for name, bmrev in repo._bookmarks.iteritems(): |
460 if matcher(name): | 460 if matcher(name): |
461 matchrevs.add(bmrev) | 461 matchrevs.add(bmrev) |
462 if not matchrevs: | 462 if not matchrevs: |
463 raise util.Abort(_("no bookmarks exist that match '%s'") | 463 raise util.Abort(_("no bookmarks exist that match '%s'") |
464 % pattern) | 464 % pattern) |
465 bmrevs = set() | |
466 for bmrev in matchrevs: | 465 for bmrev in matchrevs: |
467 bmrevs.add(repo[bmrev].rev()) | 466 bms.add(repo[bmrev].rev()) |
468 return subset & bmrevs | 467 else: |
469 | 468 bms = set([repo[r].rev() |
470 bms = set([repo[r].rev() | 469 for r in repo._bookmarks.values()]) |
471 for r in repo._bookmarks.values()]) | |
472 return subset.filter(bms.__contains__) | 470 return subset.filter(bms.__contains__) |
473 | 471 |
474 def branch(repo, subset, x): | 472 def branch(repo, subset, x): |
475 """``branch(string or set)`` | 473 """``branch(string or set)`` |
476 All changesets belonging to the given branch or the branches of the given | 474 All changesets belonging to the given branch or the branches of the given |