Mercurial > evolve
comparison hgext3rd/topic/revset.py @ 2924:430fb1758d28
topic: use registrar.revsetpredicate to register revset predicate functions
Now, using registrar.revsetpredicate of Mercurial directly in topic
extension should be safe enough. because it has been available since
Mercurial 3.8, and minimum Mercurial version for topic extension is
4.0.
This patch also removes modsetup() in topic/revset.py, because it is
useless.
BTW, this patch fixes an issue of "hg help revsets" output that custom
revset predicates are not displayed as same as others, because they
are not "inline literal" in reST syntax (``NAME``).
author | FUJIWARA Katsunori <foozy@lares.dti.ne.jp> |
---|---|
date | Mon, 07 Aug 2017 23:17:13 +0900 |
parents | b3abdb3d819e |
children |
comparison
equal
deleted
inserted
replaced
2923:8c2d3c474fc6 | 2924:430fb1758d28 |
---|---|
1 from __future__ import absolute_import | 1 from __future__ import absolute_import |
2 | 2 |
3 from mercurial import ( | 3 from mercurial import ( |
4 registrar, | |
4 revset, | 5 revset, |
5 util, | 6 util, |
6 ) | 7 ) |
7 | 8 |
8 from . import ( | 9 from . import ( |
14 try: | 15 try: |
15 mkmatcher = revset._stringmatcher | 16 mkmatcher = revset._stringmatcher |
16 except AttributeError: | 17 except AttributeError: |
17 mkmatcher = util.stringmatcher | 18 mkmatcher = util.stringmatcher |
18 | 19 |
20 revsetpredicate = registrar.revsetpredicate() | |
19 | 21 |
22 @revsetpredicate('topic([topic])') | |
20 def topicset(repo, subset, x): | 23 def topicset(repo, subset, x): |
21 """`topic([topic])` | 24 """Specified topic or all changes with any topic specified. |
22 Specified topic or all changes with any topic specified. | |
23 | 25 |
24 If `topic` starts with `re:` the remainder of the name is treated | 26 If `topic` starts with `re:` the remainder of the name is treated |
25 as a regular expression. | 27 as a regular expression. |
26 | 28 |
27 TODO: make `topic(revset)` work the same as `branch(revset)`. | 29 TODO: make `topic(revset)` work the same as `branch(revset)`. |
46 if topic is None: | 48 if topic is None: |
47 return False | 49 return False |
48 return matcher(topic) | 50 return matcher(topic) |
49 return (subset & mutable).filter(matchtopic) | 51 return (subset & mutable).filter(matchtopic) |
50 | 52 |
53 @revsetpredicate('ngtip([branch])') | |
51 def ngtipset(repo, subset, x): | 54 def ngtipset(repo, subset, x): |
52 """`ngtip([branch])` | 55 """The untopiced tip. |
53 | |
54 The untopiced tip. | |
55 | 56 |
56 Name is horrible so that people change it. | 57 Name is horrible so that people change it. |
57 """ | 58 """ |
58 args = revset.getargs(x, 1, 1, 'topic takes one') | 59 args = revset.getargs(x, 1, 1, 'topic takes one') |
59 # match a specific topic | 60 # match a specific topic |
60 branch = revset.getstring(args[0], 'ngtip() argument must be a string') | 61 branch = revset.getstring(args[0], 'ngtip() argument must be a string') |
61 if branch == '.': | 62 if branch == '.': |
62 branch = repo['.'].branch() | 63 branch = repo['.'].branch() |
63 return subset & revset.baseset(destination.ngtip(repo, branch)) | 64 return subset & revset.baseset(destination.ngtip(repo, branch)) |
64 | 65 |
66 @revsetpredicate('stack()') | |
65 def stackset(repo, subset, x): | 67 def stackset(repo, subset, x): |
66 """`stack()` | 68 """All relevant changes in the current topic, |
67 All relevant changes in the current topic, | |
68 | 69 |
69 This is roughly equivalent to 'topic(.) - obsolete' with a sorting moving | 70 This is roughly equivalent to 'topic(.) - obsolete' with a sorting moving |
70 unstable changeset after there future parent (as if evolve where already | 71 unstable changeset after there future parent (as if evolve where already |
71 run).""" | 72 run).""" |
72 err = 'stack() takes no argument, it works on current topic' | 73 err = 'stack() takes no argument, it works on current topic' |
77 if not topic and repo.currenttopic: | 78 if not topic and repo.currenttopic: |
78 topic = repo.currenttopic | 79 topic = repo.currenttopic |
79 if not topic: | 80 if not topic: |
80 branch = repo[None].branch() | 81 branch = repo[None].branch() |
81 return revset.baseset(stack.stack(repo, branch=branch, topic=topic)[1:]) & subset | 82 return revset.baseset(stack.stack(repo, branch=branch, topic=topic)[1:]) & subset |
82 | |
83 | |
84 def modsetup(ui): | |
85 revset.symbols.update({'topic': topicset}) | |
86 revset.symbols.update({'ngtip': ngtipset}) | |
87 revset.symbols.update({'stack': stackset}) |