annotate hgext3rd/topic/revset.py @ 1901:85390446f8c1

packaging: fix setup.py and install as hgext3rd.topic This changeset is doing two things (gasp): - It fixes various errors in the setup.py - It move the topic source and install into hgext3rd.topic. This last part (code source move) use hgext3rd as namespace package to prevent installation nightmare. This won't be officially supported until Mercurial 3.8, but in the meantime, 3.7 user can enable it using the full package name: [extensions] hgext3rd.topic= Thanks goes to Julien Cristau <julien.cristau@logilab.fr> for the initial version of this.
author Pierre-Yves David <pierre-yves.david@fb.com>
date Thu, 17 Mar 2016 09:12:18 -0700
parents src/topic/revset.py@8dd5200b4086
children 24986e5a537c
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
1865
558dd43b599d topic: work around stringmatcher moving during development of hg 3.6
Augie Fackler <raf@durin42.com>
parents: 1864
diff changeset
2 from mercurial import util
1843
0ba067a97d06 revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff changeset
3
1870
8dd5200b4086 topic: introduce a 'ngtip' concept
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1865
diff changeset
4 from . import constants, destination
1845
24d8053020a2 constants: extract key for extra into a constant
Augie Fackler <augie@google.com>
parents: 1843
diff changeset
5
1865
558dd43b599d topic: work around stringmatcher moving during development of hg 3.6
Augie Fackler <raf@durin42.com>
parents: 1864
diff changeset
6 try:
558dd43b599d topic: work around stringmatcher moving during development of hg 3.6
Augie Fackler <raf@durin42.com>
parents: 1864
diff changeset
7 mkmatcher = revset._stringmatcher
558dd43b599d topic: work around stringmatcher moving during development of hg 3.6
Augie Fackler <raf@durin42.com>
parents: 1864
diff changeset
8 except AttributeError:
558dd43b599d topic: work around stringmatcher moving during development of hg 3.6
Augie Fackler <raf@durin42.com>
parents: 1864
diff changeset
9 mkmatcher = util.stringmatcher
558dd43b599d topic: work around stringmatcher moving during development of hg 3.6
Augie Fackler <raf@durin42.com>
parents: 1864
diff changeset
10
558dd43b599d topic: work around stringmatcher moving during development of hg 3.6
Augie Fackler <raf@durin42.com>
parents: 1864
diff changeset
11
1843
0ba067a97d06 revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff changeset
12 def topicset(repo, subset, x):
0ba067a97d06 revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff changeset
13 """`topic([topic])`
0ba067a97d06 revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff changeset
14 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
15
0ba067a97d06 revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff changeset
16 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
17 as a regular expression.
0ba067a97d06 revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff changeset
18
0ba067a97d06 revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff changeset
19 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
20 """
0ba067a97d06 revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff changeset
21 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
22 if args:
0ba067a97d06 revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff changeset
23 # match a specific topic
0ba067a97d06 revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff changeset
24 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
25 if topic == '.':
70d1191fceed topic: allow use of topic(.) to match the p1 topic
Augie Fackler <raf@durin42.com>
parents: 1845
diff changeset
26 topic = repo['.'].extra().get('topic', '')
1865
558dd43b599d topic: work around stringmatcher moving during development of hg 3.6
Augie Fackler <raf@durin42.com>
parents: 1864
diff changeset
27 _kind, _pattern, matcher = mkmatcher(topic)
1843
0ba067a97d06 revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff changeset
28 else:
0ba067a97d06 revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff changeset
29 matcher = lambda t: bool(t)
0ba067a97d06 revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff changeset
30 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
31 return drafts.filter(
24d8053020a2 constants: extract key for extra into a constant
Augie Fackler <augie@google.com>
parents: 1843
diff changeset
32 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
33
1870
8dd5200b4086 topic: introduce a 'ngtip' concept
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1865
diff changeset
34 def ngtipset(repo, subset, x):
8dd5200b4086 topic: introduce a 'ngtip' concept
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1865
diff changeset
35 """`ngtip([branch])`
8dd5200b4086 topic: introduce a 'ngtip' concept
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1865
diff changeset
36
8dd5200b4086 topic: introduce a 'ngtip' concept
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1865
diff changeset
37 The untopiced tip.
8dd5200b4086 topic: introduce a 'ngtip' concept
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1865
diff changeset
38
8dd5200b4086 topic: introduce a 'ngtip' concept
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1865
diff changeset
39 Name is horrible so that people change it.
8dd5200b4086 topic: introduce a 'ngtip' concept
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1865
diff changeset
40 """
8dd5200b4086 topic: introduce a 'ngtip' concept
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1865
diff changeset
41 args = revset.getargs(x, 1, 1, 'topic takes one')
8dd5200b4086 topic: introduce a 'ngtip' concept
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1865
diff changeset
42 # match a specific topic
8dd5200b4086 topic: introduce a 'ngtip' concept
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1865
diff changeset
43 branch = revset.getstring(args[0], 'ngtip() argument must be a string')
8dd5200b4086 topic: introduce a 'ngtip' concept
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1865
diff changeset
44 if branch == '.':
8dd5200b4086 topic: introduce a 'ngtip' concept
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1865
diff changeset
45 branch = repo['.'].branch()
8dd5200b4086 topic: introduce a 'ngtip' concept
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1865
diff changeset
46 return subset & destination.ngtip(repo, branch)
8dd5200b4086 topic: introduce a 'ngtip' concept
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1865
diff changeset
47
1843
0ba067a97d06 revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff changeset
48 def modsetup():
0ba067a97d06 revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff changeset
49 revset.symbols.update({'topic': topicset})
1870
8dd5200b4086 topic: introduce a 'ngtip' concept
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1865
diff changeset
50 revset.symbols.update({'ngtip': ngtipset})