|
1 from mercurial import revset |
|
2 from mercurial import util |
|
3 |
|
4 from . import constants, destination |
|
5 |
|
6 try: |
|
7 mkmatcher = revset._stringmatcher |
|
8 except AttributeError: |
|
9 mkmatcher = util.stringmatcher |
|
10 |
|
11 |
|
12 def topicset(repo, subset, x): |
|
13 """`topic([topic])` |
|
14 Specified topic or all changes with any topic specified. |
|
15 |
|
16 If `topic` starts with `re:` the remainder of the name is treated |
|
17 as a regular expression. |
|
18 |
|
19 TODO: make `topic(revset)` work the same as `branch(revset)`. |
|
20 """ |
|
21 args = revset.getargs(x, 0, 1, 'topic takes one or no arguments') |
|
22 if args: |
|
23 # match a specific topic |
|
24 topic = revset.getstring(args[0], 'topic() argument must be a string') |
|
25 if topic == '.': |
|
26 topic = repo['.'].extra().get('topic', '') |
|
27 _kind, _pattern, matcher = mkmatcher(topic) |
|
28 else: |
|
29 matcher = lambda t: bool(t) |
|
30 drafts = subset.filter(lambda r: repo[r].mutable()) |
|
31 return drafts.filter( |
|
32 lambda r: matcher(repo[r].extra().get(constants.extrakey, ''))) |
|
33 |
|
34 def ngtipset(repo, subset, x): |
|
35 """`ngtip([branch])` |
|
36 |
|
37 The untopiced tip. |
|
38 |
|
39 Name is horrible so that people change it. |
|
40 """ |
|
41 args = revset.getargs(x, 1, 1, 'topic takes one') |
|
42 # match a specific topic |
|
43 branch = revset.getstring(args[0], 'ngtip() argument must be a string') |
|
44 if branch == '.': |
|
45 branch = repo['.'].branch() |
|
46 return subset & destination.ngtip(repo, branch) |
|
47 |
|
48 def modsetup(): |
|
49 revset.symbols.update({'topic': topicset}) |
|
50 revset.symbols.update({'ngtip': ngtipset}) |