annotate hgext3rd/topic/revset.py @ 3904:d2d03df3956f

builddependencies: build inverse dict from forward dict It's error-prone to keep "dependencies" and "rdependencies" in sync (we don't do it correctly when there are multiple successors or a node). It's easier to just create "rependencies" from "dependencies" after it's complete.
author Martin von Zweigbergk <martinvonz@google.com>
date Wed, 25 Jul 2018 14:33:48 -0700
parents bf583a8dc637
children 054d288680b4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1935
11d740319280 revset: move to new style import
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1923
diff changeset
1 from __future__ import absolute_import
11d740319280 revset: move to new style import
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1923
diff changeset
2
11d740319280 revset: move to new style import
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1923
diff changeset
3 from mercurial import (
2924
430fb1758d28 topic: use registrar.revsetpredicate to register revset predicate functions
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 2915
diff changeset
4 registrar,
1935
11d740319280 revset: move to new style import
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1923
diff changeset
5 revset,
11d740319280 revset: move to new style import
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1923
diff changeset
6 util,
11d740319280 revset: move to new style import
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1923
diff changeset
7 )
1843
0ba067a97d06 revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff changeset
8
1935
11d740319280 revset: move to new style import
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1923
diff changeset
9 from . import (
11d740319280 revset: move to new style import
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1923
diff changeset
10 constants,
11d740319280 revset: move to new style import
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1923
diff changeset
11 destination,
11d740319280 revset: move to new style import
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1923
diff changeset
12 stack,
11d740319280 revset: move to new style import
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1923
diff changeset
13 )
1845
24d8053020a2 constants: extract key for extra into a constant
Augie Fackler <augie@google.com>
parents: 1843
diff changeset
14
1865
558dd43b599d topic: work around stringmatcher moving during development of hg 3.6
Augie Fackler <raf@durin42.com>
parents: 1864
diff changeset
15 try:
558dd43b599d topic: work around stringmatcher moving during development of hg 3.6
Augie Fackler <raf@durin42.com>
parents: 1864
diff changeset
16 mkmatcher = revset._stringmatcher
558dd43b599d topic: work around stringmatcher moving during development of hg 3.6
Augie Fackler <raf@durin42.com>
parents: 1864
diff changeset
17 except AttributeError:
3613
bf583a8dc637 compat: search for stringmatcher in the new location
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3156
diff changeset
18 try:
bf583a8dc637 compat: search for stringmatcher in the new location
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3156
diff changeset
19 from mercurial.utils import stringutil
bf583a8dc637 compat: search for stringmatcher in the new location
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3156
diff changeset
20 mkmatcher = stringutil.stringmatcher
bf583a8dc637 compat: search for stringmatcher in the new location
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3156
diff changeset
21 except (ImportError, AttributeError):
bf583a8dc637 compat: search for stringmatcher in the new location
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3156
diff changeset
22 mkmatcher = util.stringmatcher
1865
558dd43b599d topic: work around stringmatcher moving during development of hg 3.6
Augie Fackler <raf@durin42.com>
parents: 1864
diff changeset
23
2924
430fb1758d28 topic: use registrar.revsetpredicate to register revset predicate functions
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 2915
diff changeset
24 revsetpredicate = registrar.revsetpredicate()
1865
558dd43b599d topic: work around stringmatcher moving during development of hg 3.6
Augie Fackler <raf@durin42.com>
parents: 1864
diff changeset
25
2924
430fb1758d28 topic: use registrar.revsetpredicate to register revset predicate functions
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 2915
diff changeset
26 @revsetpredicate('topic([topic])')
1843
0ba067a97d06 revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff changeset
27 def topicset(repo, subset, x):
2924
430fb1758d28 topic: use registrar.revsetpredicate to register revset predicate functions
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 2915
diff changeset
28 """Specified topic or all changes with any topic specified.
1843
0ba067a97d06 revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff changeset
29
0ba067a97d06 revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff changeset
30 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
31 as a regular expression.
0ba067a97d06 revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff changeset
32
0ba067a97d06 revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff changeset
33 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
34 """
0ba067a97d06 revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff changeset
35 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
36 if args:
0ba067a97d06 revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff changeset
37 # match a specific topic
0ba067a97d06 revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff changeset
38 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
39 if topic == '.':
70d1191fceed topic: allow use of topic(.) to match the p1 topic
Augie Fackler <raf@durin42.com>
parents: 1845
diff changeset
40 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
41 _kind, _pattern, matcher = mkmatcher(topic)
1843
0ba067a97d06 revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff changeset
42 else:
0ba067a97d06 revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff changeset
43 matcher = lambda t: bool(t)
2686
fc3a66ad635b compat: fix topicset for mercurial 4.1
Boris Feld <boris.feld@octobus.net>
parents: 2682
diff changeset
44
2692
96843c68acc8 topic: directly use the '_notpublic' revset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2686
diff changeset
45 mutable = revset._notpublic(repo, revset.fullreposet(repo), ())
2651
6a3df2404472 topic-revset: update the revset to no longer build changectx
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2650
diff changeset
46
6a3df2404472 topic-revset: update the revset to no longer build changectx
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2650
diff changeset
47 rawchange = repo.changelog.changelogrevision
6a3df2404472 topic-revset: update the revset to no longer build changectx
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2650
diff changeset
48 key = constants.extrakey
6a3df2404472 topic-revset: update the revset to no longer build changectx
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2650
diff changeset
49
6a3df2404472 topic-revset: update the revset to no longer build changectx
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2650
diff changeset
50 def matchtopic(r):
6a3df2404472 topic-revset: update the revset to no longer build changectx
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2650
diff changeset
51 topic = rawchange(r).extra.get(key)
6a3df2404472 topic-revset: update the revset to no longer build changectx
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2650
diff changeset
52 if topic is None:
6a3df2404472 topic-revset: update the revset to no longer build changectx
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2650
diff changeset
53 return False
6a3df2404472 topic-revset: update the revset to no longer build changectx
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2650
diff changeset
54 return matcher(topic)
6a3df2404472 topic-revset: update the revset to no longer build changectx
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2650
diff changeset
55 return (subset & mutable).filter(matchtopic)
1843
0ba067a97d06 revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff changeset
56
2924
430fb1758d28 topic: use registrar.revsetpredicate to register revset predicate functions
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 2915
diff changeset
57 @revsetpredicate('ngtip([branch])')
1870
8dd5200b4086 topic: introduce a 'ngtip' concept
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1865
diff changeset
58 def ngtipset(repo, subset, x):
2924
430fb1758d28 topic: use registrar.revsetpredicate to register revset predicate functions
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 2915
diff changeset
59 """The untopiced tip.
1870
8dd5200b4086 topic: introduce a 'ngtip' concept
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1865
diff changeset
60
8dd5200b4086 topic: introduce a 'ngtip' concept
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1865
diff changeset
61 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
62 """
8dd5200b4086 topic: introduce a 'ngtip' concept
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1865
diff changeset
63 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
64 # match a specific topic
8dd5200b4086 topic: introduce a 'ngtip' concept
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1865
diff changeset
65 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
66 if branch == '.':
8dd5200b4086 topic: introduce a 'ngtip' concept
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1865
diff changeset
67 branch = repo['.'].branch()
1986
042356d5ba59 ngtip: rely on topicmap for 'ngtip'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 1943
diff changeset
68 return subset & revset.baseset(destination.ngtip(repo, branch))
1870
8dd5200b4086 topic: introduce a 'ngtip' concept
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1865
diff changeset
69
2924
430fb1758d28 topic: use registrar.revsetpredicate to register revset predicate functions
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 2915
diff changeset
70 @revsetpredicate('stack()')
1910
24986e5a537c stack: add a 'stack()' revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1901
diff changeset
71 def stackset(repo, subset, x):
2924
430fb1758d28 topic: use registrar.revsetpredicate to register revset predicate functions
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 2915
diff changeset
72 """All relevant changes in the current topic,
1910
24986e5a537c stack: add a 'stack()' revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1901
diff changeset
73
24986e5a537c stack: add a 'stack()' revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1901
diff changeset
74 This is roughly equivalent to 'topic(.) - obsolete' with a sorting moving
24986e5a537c stack: add a 'stack()' revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1901
diff changeset
75 unstable changeset after there future parent (as if evolve where already
24986e5a537c stack: add a 'stack()' revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1901
diff changeset
76 run)."""
2681
aa4db71a6224 topics: return a parse error if stack() revset is passed with argument
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2669
diff changeset
77 err = 'stack() takes no argument, it works on current topic'
aa4db71a6224 topics: return a parse error if stack() revset is passed with argument
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2669
diff changeset
78 revset.getargs(x, 0, 0, err)
2669
b933a8068c17 topic: add some initial support for using stack on named branch
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2668
diff changeset
79 topic = None
b933a8068c17 topic: add some initial support for using stack on named branch
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2668
diff changeset
80 branch = None
3156
31493a1b0e39 revset: clean up some messy logic
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2924
diff changeset
81 if repo.currenttopic:
2669
b933a8068c17 topic: add some initial support for using stack on named branch
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2668
diff changeset
82 topic = repo.currenttopic
3156
31493a1b0e39 revset: clean up some messy logic
Pulkit Goyal <7895pulkit@gmail.com>
parents: 2924
diff changeset
83 else:
2669
b933a8068c17 topic: add some initial support for using stack on named branch
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2668
diff changeset
84 branch = repo[None].branch()
2915
b3abdb3d819e stack: replace 'getstack' with direct call to 'stack'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2712
diff changeset
85 return revset.baseset(stack.stack(repo, branch=branch, topic=topic)[1:]) & subset