annotate src/topic/revset.py @ 1864:70d1191fceed

topic: allow use of topic(.) to match the p1 topic As far as I can tell this matches the behavior of branch(.) in core hg in tht it matches p1's value rather than the wdir value.
author Augie Fackler <raf@durin42.com>
date Wed, 30 Sep 2015 18:06:42 -0400
parents 24d8053020a2
children 558dd43b599d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1843
0ba067a97d06 revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff changeset
1 from mercurial import revset
0ba067a97d06 revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff changeset
2
1845
24d8053020a2 constants: extract key for extra into a constant
Augie Fackler <augie@google.com>
parents: 1843
diff changeset
3 from . import constants
24d8053020a2 constants: extract key for extra into a constant
Augie Fackler <augie@google.com>
parents: 1843
diff changeset
4
1843
0ba067a97d06 revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff changeset
5 def topicset(repo, subset, x):
0ba067a97d06 revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff changeset
6 """`topic([topic])`
0ba067a97d06 revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff changeset
7 Specified topic or all changes with any topic specified.
0ba067a97d06 revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff changeset
8
0ba067a97d06 revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff changeset
9 If `topic` starts with `re:` the remainder of the name is treated
0ba067a97d06 revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff changeset
10 as a regular expression.
0ba067a97d06 revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff changeset
11
0ba067a97d06 revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff changeset
12 TODO: make `topic(revset)` work the same as `branch(revset)`.
0ba067a97d06 revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff changeset
13 """
0ba067a97d06 revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff changeset
14 args = revset.getargs(x, 0, 1, 'topic takes one or no arguments')
0ba067a97d06 revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff changeset
15 if args:
0ba067a97d06 revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff changeset
16 # match a specific topic
0ba067a97d06 revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff changeset
17 topic = revset.getstring(args[0], 'topic() argument must be a string')
1864
70d1191fceed topic: allow use of topic(.) to match the p1 topic
Augie Fackler <raf@durin42.com>
parents: 1845
diff changeset
18 if topic == '.':
70d1191fceed topic: allow use of topic(.) to match the p1 topic
Augie Fackler <raf@durin42.com>
parents: 1845
diff changeset
19 topic = repo['.'].extra().get('topic', '')
1843
0ba067a97d06 revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff changeset
20 _kind, _pattern, matcher = revset._stringmatcher(topic)
0ba067a97d06 revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff changeset
21 else:
0ba067a97d06 revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff changeset
22 matcher = lambda t: bool(t)
0ba067a97d06 revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff changeset
23 drafts = subset.filter(lambda r: repo[r].mutable())
1845
24d8053020a2 constants: extract key for extra into a constant
Augie Fackler <augie@google.com>
parents: 1843
diff changeset
24 return drafts.filter(
24d8053020a2 constants: extract key for extra into a constant
Augie Fackler <augie@google.com>
parents: 1843
diff changeset
25 lambda r: matcher(repo[r].extra().get(constants.extrakey, '')))
1843
0ba067a97d06 revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff changeset
26
0ba067a97d06 revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff changeset
27 def modsetup():
0ba067a97d06 revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff changeset
28 revset.symbols.update({'topic': topicset})