author | Pierre-Yves David <pierre-yves.david@octobus.net> |
Wed, 28 Jun 2017 01:58:09 +0200 | |
changeset 2668 | 1d2c66dc4ee3 |
parent 2651 | 6a3df2404472 |
child 2669 | b933a8068c17 |
permissions | -rw-r--r-- |
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 |
|
1923 | 3 |
from mercurial.i18n import _ |
1935
11d740319280
revset: move to new style import
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1923
diff
changeset
|
4 |
from mercurial import ( |
11d740319280
revset: move to new style import
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1923
diff
changeset
|
5 |
error, |
2650
db788700ed82
topic-revset: changectx creation in the revset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
1986
diff
changeset
|
6 |
phases, |
1935
11d740319280
revset: move to new style import
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1923
diff
changeset
|
7 |
revset, |
11d740319280
revset: move to new style import
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1923
diff
changeset
|
8 |
util, |
11d740319280
revset: move to new style import
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1923
diff
changeset
|
9 |
) |
1843
0ba067a97d06
revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
10 |
|
1935
11d740319280
revset: move to new style import
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1923
diff
changeset
|
11 |
from . import ( |
11d740319280
revset: move to new style import
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1923
diff
changeset
|
12 |
constants, |
11d740319280
revset: move to new style import
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1923
diff
changeset
|
13 |
destination, |
11d740319280
revset: move to new style import
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1923
diff
changeset
|
14 |
stack, |
11d740319280
revset: move to new style import
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1923
diff
changeset
|
15 |
) |
1845
24d8053020a2
constants: extract key for extra into a constant
Augie Fackler <augie@google.com>
parents:
1843
diff
changeset
|
16 |
|
1865
558dd43b599d
topic: work around stringmatcher moving during development of hg 3.6
Augie Fackler <raf@durin42.com>
parents:
1864
diff
changeset
|
17 |
try: |
558dd43b599d
topic: work around stringmatcher moving during development of hg 3.6
Augie Fackler <raf@durin42.com>
parents:
1864
diff
changeset
|
18 |
mkmatcher = revset._stringmatcher |
558dd43b599d
topic: work around stringmatcher moving during development of hg 3.6
Augie Fackler <raf@durin42.com>
parents:
1864
diff
changeset
|
19 |
except AttributeError: |
558dd43b599d
topic: work around stringmatcher moving during development of hg 3.6
Augie Fackler <raf@durin42.com>
parents:
1864
diff
changeset
|
20 |
mkmatcher = util.stringmatcher |
558dd43b599d
topic: work around stringmatcher moving during development of hg 3.6
Augie Fackler <raf@durin42.com>
parents:
1864
diff
changeset
|
21 |
|
558dd43b599d
topic: work around stringmatcher moving during development of hg 3.6
Augie Fackler <raf@durin42.com>
parents:
1864
diff
changeset
|
22 |
|
1843
0ba067a97d06
revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
23 |
def topicset(repo, subset, x): |
0ba067a97d06
revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
24 |
"""`topic([topic])` |
0ba067a97d06
revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
25 |
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
|
26 |
|
0ba067a97d06
revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
27 |
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
|
28 |
as a regular expression. |
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 |
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
|
31 |
""" |
0ba067a97d06
revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
32 |
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
|
33 |
if args: |
0ba067a97d06
revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
34 |
# match a specific topic |
0ba067a97d06
revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
35 |
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
|
36 |
if topic == '.': |
70d1191fceed
topic: allow use of topic(.) to match the p1 topic
Augie Fackler <raf@durin42.com>
parents:
1845
diff
changeset
|
37 |
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
|
38 |
_kind, _pattern, matcher = mkmatcher(topic) |
1843
0ba067a97d06
revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
39 |
else: |
0ba067a97d06
revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
40 |
matcher = lambda t: bool(t) |
2650
db788700ed82
topic-revset: changectx creation in the revset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
1986
diff
changeset
|
41 |
mutable = repo._phasecache.getrevset(repo, (phases.draft, phases.secret)) |
2651
6a3df2404472
topic-revset: update the revset to no longer build changectx
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2650
diff
changeset
|
42 |
|
6a3df2404472
topic-revset: update the revset to no longer build changectx
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2650
diff
changeset
|
43 |
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
|
44 |
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
|
45 |
|
6a3df2404472
topic-revset: update the revset to no longer build changectx
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2650
diff
changeset
|
46 |
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
|
47 |
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
|
48 |
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
|
49 |
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
|
50 |
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
|
51 |
return (subset & mutable).filter(matchtopic) |
1843
0ba067a97d06
revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
52 |
|
1870
8dd5200b4086
topic: introduce a 'ngtip' concept
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1865
diff
changeset
|
53 |
def ngtipset(repo, subset, x): |
8dd5200b4086
topic: introduce a 'ngtip' concept
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1865
diff
changeset
|
54 |
"""`ngtip([branch])` |
8dd5200b4086
topic: introduce a 'ngtip' concept
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1865
diff
changeset
|
55 |
|
8dd5200b4086
topic: introduce a 'ngtip' concept
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1865
diff
changeset
|
56 |
The untopiced tip. |
8dd5200b4086
topic: introduce a 'ngtip' concept
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1865
diff
changeset
|
57 |
|
8dd5200b4086
topic: introduce a 'ngtip' concept
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1865
diff
changeset
|
58 |
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
|
59 |
""" |
8dd5200b4086
topic: introduce a 'ngtip' concept
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1865
diff
changeset
|
60 |
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
|
61 |
# match a specific topic |
8dd5200b4086
topic: introduce a 'ngtip' concept
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1865
diff
changeset
|
62 |
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
|
63 |
if branch == '.': |
8dd5200b4086
topic: introduce a 'ngtip' concept
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1865
diff
changeset
|
64 |
branch = repo['.'].branch() |
1986
042356d5ba59
ngtip: rely on topicmap for 'ngtip'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
1943
diff
changeset
|
65 |
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
|
66 |
|
1910
24986e5a537c
stack: add a 'stack()' revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1901
diff
changeset
|
67 |
def stackset(repo, subset, x): |
24986e5a537c
stack: add a 'stack()' revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1901
diff
changeset
|
68 |
"""`stack()` |
24986e5a537c
stack: add a 'stack()' revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1901
diff
changeset
|
69 |
All relevant changes in the current topic, |
24986e5a537c
stack: add a 'stack()' revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1901
diff
changeset
|
70 |
|
24986e5a537c
stack: add a 'stack()' revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1901
diff
changeset
|
71 |
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
|
72 |
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
|
73 |
run).""" |
24986e5a537c
stack: add a 'stack()' revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1901
diff
changeset
|
74 |
topic = repo.currenttopic |
24986e5a537c
stack: add a 'stack()' revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1901
diff
changeset
|
75 |
if not topic: |
24986e5a537c
stack: add a 'stack()' revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1901
diff
changeset
|
76 |
raise error.Abort(_('no active topic to list')) |
24986e5a537c
stack: add a 'stack()' revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1901
diff
changeset
|
77 |
# ordering hack, boo |
2668
1d2c66dc4ee3
topic: explicitly pass topic as a keyword argument
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2651
diff
changeset
|
78 |
return revset.baseset(stack.getstack(repo, topic=topic)) & subset |
1910
24986e5a537c
stack: add a 'stack()' revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1901
diff
changeset
|
79 |
|
24986e5a537c
stack: add a 'stack()' revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1901
diff
changeset
|
80 |
|
1943
cd56f4d8b5a3
revset: add a ui argument to 'modsetup'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1935
diff
changeset
|
81 |
def modsetup(ui): |
1843
0ba067a97d06
revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
82 |
revset.symbols.update({'topic': topicset}) |
1870
8dd5200b4086
topic: introduce a 'ngtip' concept
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1865
diff
changeset
|
83 |
revset.symbols.update({'ngtip': ngtipset}) |
1910
24986e5a537c
stack: add a 'stack()' revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1901
diff
changeset
|
84 |
revset.symbols.update({'stack': stackset}) |