Mercurial > evolve
annotate hgext3rd/topic/revset.py @ 6919:6859ed744625 mercurial-5.1
test-compat: merge mercurial-5.2 into mercurial-5.1
author | Anton Shestakov <av6@dwimlabs.net> |
---|---|
date | Fri, 25 Oct 2024 17:55:54 +0400 |
parents | 3d16c9a8cf3a |
children | 8a51498b9976 |
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 ( |
4058
90783c9c8609
topic: prepare to handle non-string arguments to topic() revset
Anton Shestakov <av6@dwimlabs.net>
parents:
4057
diff
changeset
|
4 error, |
2924
430fb1758d28
topic: use registrar.revsetpredicate to register revset predicate functions
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
2915
diff
changeset
|
5 registrar, |
1935
11d740319280
revset: move to new style import
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1923
diff
changeset
|
6 revset, |
11d740319280
revset: move to new style import
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1923
diff
changeset
|
7 util, |
11d740319280
revset: move to new style import
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1923
diff
changeset
|
8 ) |
1843
0ba067a97d06
revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
9 |
6221
a1a9e6e43d4c
topic: drop compatibility with hg 4.6 (f99d64e8a4e4)
Anton Shestakov <av6@dwimlabs.net>
parents:
6220
diff
changeset
|
10 from mercurial.utils import stringutil |
a1a9e6e43d4c
topic: drop compatibility with hg 4.6 (f99d64e8a4e4)
Anton Shestakov <av6@dwimlabs.net>
parents:
6220
diff
changeset
|
11 |
1935
11d740319280
revset: move to new style import
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1923
diff
changeset
|
12 from . import ( |
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 |
2924
430fb1758d28
topic: use registrar.revsetpredicate to register revset predicate functions
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
2915
diff
changeset
|
17 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
|
18 |
4063
00c65abf99cd
topic-revset: strictly read string
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4061
diff
changeset
|
19 def getstringstrict(x, err): |
4814
48b30ff742cb
python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents:
4717
diff
changeset
|
20 if x and x[0] == b'string': |
4063
00c65abf99cd
topic-revset: strictly read string
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4061
diff
changeset
|
21 return x[1] |
00c65abf99cd
topic-revset: strictly read string
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4061
diff
changeset
|
22 raise error.ParseError(err) |
00c65abf99cd
topic-revset: strictly read string
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4061
diff
changeset
|
23 |
6261
a2491c578d2b
topic: namespace revset predicate
Anton Shestakov <av6@dwimlabs.net>
parents:
6222
diff
changeset
|
24 @revsetpredicate(b'topicnamespace([string or set])') |
a2491c578d2b
topic: namespace revset predicate
Anton Shestakov <av6@dwimlabs.net>
parents:
6222
diff
changeset
|
25 def topicnamespaceset(repo, subset, x): |
a2491c578d2b
topic: namespace revset predicate
Anton Shestakov <av6@dwimlabs.net>
parents:
6222
diff
changeset
|
26 """All changesets with the specified topic namespace or the topic |
a2491c578d2b
topic: namespace revset predicate
Anton Shestakov <av6@dwimlabs.net>
parents:
6222
diff
changeset
|
27 namespaces of the given changesets. Without the argument, all changesets |
6487
963471ebe26a
topic: make topic namespace use string "none" as the default/empty value
Anton Shestakov <av6@dwimlabs.net>
parents:
6415
diff
changeset
|
28 with any non-empty topic namespace. |
6261
a2491c578d2b
topic: namespace revset predicate
Anton Shestakov <av6@dwimlabs.net>
parents:
6222
diff
changeset
|
29 |
6415
ff103a813110
topic: fix strange indentation in revset docstrings
Anton Shestakov <av6@dwimlabs.net>
parents:
6297
diff
changeset
|
30 Pattern matching is supported for `string`. See |
6261
a2491c578d2b
topic: namespace revset predicate
Anton Shestakov <av6@dwimlabs.net>
parents:
6222
diff
changeset
|
31 :hg:`help revisions.patterns`. |
a2491c578d2b
topic: namespace revset predicate
Anton Shestakov <av6@dwimlabs.net>
parents:
6222
diff
changeset
|
32 """ |
a2491c578d2b
topic: namespace revset predicate
Anton Shestakov <av6@dwimlabs.net>
parents:
6222
diff
changeset
|
33 args = revset.getargs(x, 0, 1, b'topicnamespace takes one or no arguments') |
a2491c578d2b
topic: namespace revset predicate
Anton Shestakov <av6@dwimlabs.net>
parents:
6222
diff
changeset
|
34 |
a2491c578d2b
topic: namespace revset predicate
Anton Shestakov <av6@dwimlabs.net>
parents:
6222
diff
changeset
|
35 mutable = revset._notpublic(repo, revset.fullreposet(repo), ()) |
a2491c578d2b
topic: namespace revset predicate
Anton Shestakov <av6@dwimlabs.net>
parents:
6222
diff
changeset
|
36 |
a2491c578d2b
topic: namespace revset predicate
Anton Shestakov <av6@dwimlabs.net>
parents:
6222
diff
changeset
|
37 if not args: |
6533
3d16c9a8cf3a
topic: update topic namespace revset to use "none" as the default/empty value
Anton Shestakov <av6@dwimlabs.net>
parents:
6487
diff
changeset
|
38 return (subset & mutable).filter(lambda r: repo[r].topic_namespace() != b'none') |
6261
a2491c578d2b
topic: namespace revset predicate
Anton Shestakov <av6@dwimlabs.net>
parents:
6222
diff
changeset
|
39 |
a2491c578d2b
topic: namespace revset predicate
Anton Shestakov <av6@dwimlabs.net>
parents:
6222
diff
changeset
|
40 try: |
a2491c578d2b
topic: namespace revset predicate
Anton Shestakov <av6@dwimlabs.net>
parents:
6222
diff
changeset
|
41 tns = getstringstrict(args[0], b'') |
a2491c578d2b
topic: namespace revset predicate
Anton Shestakov <av6@dwimlabs.net>
parents:
6222
diff
changeset
|
42 except error.ParseError: |
a2491c578d2b
topic: namespace revset predicate
Anton Shestakov <av6@dwimlabs.net>
parents:
6222
diff
changeset
|
43 # not a string, but another revset |
a2491c578d2b
topic: namespace revset predicate
Anton Shestakov <av6@dwimlabs.net>
parents:
6222
diff
changeset
|
44 pass |
a2491c578d2b
topic: namespace revset predicate
Anton Shestakov <av6@dwimlabs.net>
parents:
6222
diff
changeset
|
45 else: |
a2491c578d2b
topic: namespace revset predicate
Anton Shestakov <av6@dwimlabs.net>
parents:
6222
diff
changeset
|
46 kind, pattern, matcher = stringutil.stringmatcher(tns) |
a2491c578d2b
topic: namespace revset predicate
Anton Shestakov <av6@dwimlabs.net>
parents:
6222
diff
changeset
|
47 |
a2491c578d2b
topic: namespace revset predicate
Anton Shestakov <av6@dwimlabs.net>
parents:
6222
diff
changeset
|
48 if tns.startswith(b'literal:') and pattern not in repo.topic_namespaces: |
a2491c578d2b
topic: namespace revset predicate
Anton Shestakov <av6@dwimlabs.net>
parents:
6222
diff
changeset
|
49 raise error.RepoLookupError(b"topic namespace '%s' does not exist" % pattern) |
a2491c578d2b
topic: namespace revset predicate
Anton Shestakov <av6@dwimlabs.net>
parents:
6222
diff
changeset
|
50 |
a2491c578d2b
topic: namespace revset predicate
Anton Shestakov <av6@dwimlabs.net>
parents:
6222
diff
changeset
|
51 def matches(r): |
a2491c578d2b
topic: namespace revset predicate
Anton Shestakov <av6@dwimlabs.net>
parents:
6222
diff
changeset
|
52 tns = repo[r].topic_namespace() |
6533
3d16c9a8cf3a
topic: update topic namespace revset to use "none" as the default/empty value
Anton Shestakov <av6@dwimlabs.net>
parents:
6487
diff
changeset
|
53 if tns == b'none': |
6261
a2491c578d2b
topic: namespace revset predicate
Anton Shestakov <av6@dwimlabs.net>
parents:
6222
diff
changeset
|
54 return False |
a2491c578d2b
topic: namespace revset predicate
Anton Shestakov <av6@dwimlabs.net>
parents:
6222
diff
changeset
|
55 return matcher(tns) |
a2491c578d2b
topic: namespace revset predicate
Anton Shestakov <av6@dwimlabs.net>
parents:
6222
diff
changeset
|
56 |
a2491c578d2b
topic: namespace revset predicate
Anton Shestakov <av6@dwimlabs.net>
parents:
6222
diff
changeset
|
57 return (subset & mutable).filter(matches) |
a2491c578d2b
topic: namespace revset predicate
Anton Shestakov <av6@dwimlabs.net>
parents:
6222
diff
changeset
|
58 |
a2491c578d2b
topic: namespace revset predicate
Anton Shestakov <av6@dwimlabs.net>
parents:
6222
diff
changeset
|
59 s = revset.getset(repo, revset.fullreposet(repo), x) |
a2491c578d2b
topic: namespace revset predicate
Anton Shestakov <av6@dwimlabs.net>
parents:
6222
diff
changeset
|
60 namespaces = {repo[r].topic_namespace() for r in s} |
6533
3d16c9a8cf3a
topic: update topic namespace revset to use "none" as the default/empty value
Anton Shestakov <av6@dwimlabs.net>
parents:
6487
diff
changeset
|
61 namespaces.discard(b'none') |
6261
a2491c578d2b
topic: namespace revset predicate
Anton Shestakov <av6@dwimlabs.net>
parents:
6222
diff
changeset
|
62 |
a2491c578d2b
topic: namespace revset predicate
Anton Shestakov <av6@dwimlabs.net>
parents:
6222
diff
changeset
|
63 def matches(r): |
a2491c578d2b
topic: namespace revset predicate
Anton Shestakov <av6@dwimlabs.net>
parents:
6222
diff
changeset
|
64 tns = repo[r].topic_namespace() |
6533
3d16c9a8cf3a
topic: update topic namespace revset to use "none" as the default/empty value
Anton Shestakov <av6@dwimlabs.net>
parents:
6487
diff
changeset
|
65 if tns == b'none': |
6261
a2491c578d2b
topic: namespace revset predicate
Anton Shestakov <av6@dwimlabs.net>
parents:
6222
diff
changeset
|
66 return False |
a2491c578d2b
topic: namespace revset predicate
Anton Shestakov <av6@dwimlabs.net>
parents:
6222
diff
changeset
|
67 return tns in namespaces |
a2491c578d2b
topic: namespace revset predicate
Anton Shestakov <av6@dwimlabs.net>
parents:
6222
diff
changeset
|
68 |
a2491c578d2b
topic: namespace revset predicate
Anton Shestakov <av6@dwimlabs.net>
parents:
6222
diff
changeset
|
69 return (subset & mutable).filter(matches) |
a2491c578d2b
topic: namespace revset predicate
Anton Shestakov <av6@dwimlabs.net>
parents:
6222
diff
changeset
|
70 |
4717
7b36f9728351
py3: use bytes for revset predicate registrations
Martin von Zweigbergk <martinvonz@google.com>
parents:
4390
diff
changeset
|
71 @revsetpredicate(b'topic([string or set])') |
1843
0ba067a97d06
revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
72 def topicset(repo, subset, x): |
4060
54eade86ac31
topic: handle revsets passed to topic() revset
Anton Shestakov <av6@dwimlabs.net>
parents:
4059
diff
changeset
|
73 """All changesets with the specified topic or the topics of the given |
54eade86ac31
topic: handle revsets passed to topic() revset
Anton Shestakov <av6@dwimlabs.net>
parents:
4059
diff
changeset
|
74 changesets. Without the argument, all changesets with any topic specified. |
1843
0ba067a97d06
revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
75 |
6415
ff103a813110
topic: fix strange indentation in revset docstrings
Anton Shestakov <av6@dwimlabs.net>
parents:
6297
diff
changeset
|
76 Pattern matching is supported for `string`. See |
6222
6020b7e92a86
topic: update topic() revset docstring, mention hg help
Anton Shestakov <av6@dwimlabs.net>
parents:
6221
diff
changeset
|
77 :hg:`help revisions.patterns`. |
1843
0ba067a97d06
revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
78 """ |
4814
48b30ff742cb
python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents:
4717
diff
changeset
|
79 args = revset.getargs(x, 0, 1, b'topic takes one or no arguments') |
4057
054d288680b4
topic: return result early if there are no arguments to topic() revset
Anton Shestakov <av6@dwimlabs.net>
parents:
3613
diff
changeset
|
80 |
054d288680b4
topic: return result early if there are no arguments to topic() revset
Anton Shestakov <av6@dwimlabs.net>
parents:
3613
diff
changeset
|
81 mutable = revset._notpublic(repo, revset.fullreposet(repo), ()) |
054d288680b4
topic: return result early if there are no arguments to topic() revset
Anton Shestakov <av6@dwimlabs.net>
parents:
3613
diff
changeset
|
82 |
054d288680b4
topic: return result early if there are no arguments to topic() revset
Anton Shestakov <av6@dwimlabs.net>
parents:
3613
diff
changeset
|
83 if not args: |
054d288680b4
topic: return result early if there are no arguments to topic() revset
Anton Shestakov <av6@dwimlabs.net>
parents:
3613
diff
changeset
|
84 return (subset & mutable).filter(lambda r: bool(repo[r].topic())) |
4058
90783c9c8609
topic: prepare to handle non-string arguments to topic() revset
Anton Shestakov <av6@dwimlabs.net>
parents:
4057
diff
changeset
|
85 |
90783c9c8609
topic: prepare to handle non-string arguments to topic() revset
Anton Shestakov <av6@dwimlabs.net>
parents:
4057
diff
changeset
|
86 try: |
4814
48b30ff742cb
python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents:
4717
diff
changeset
|
87 topic = getstringstrict(args[0], b'') |
4058
90783c9c8609
topic: prepare to handle non-string arguments to topic() revset
Anton Shestakov <av6@dwimlabs.net>
parents:
4057
diff
changeset
|
88 except error.ParseError: |
90783c9c8609
topic: prepare to handle non-string arguments to topic() revset
Anton Shestakov <av6@dwimlabs.net>
parents:
4057
diff
changeset
|
89 # not a string, but another revset |
4060
54eade86ac31
topic: handle revsets passed to topic() revset
Anton Shestakov <av6@dwimlabs.net>
parents:
4059
diff
changeset
|
90 pass |
4057
054d288680b4
topic: return result early if there are no arguments to topic() revset
Anton Shestakov <av6@dwimlabs.net>
parents:
3613
diff
changeset
|
91 else: |
6221
a1a9e6e43d4c
topic: drop compatibility with hg 4.6 (f99d64e8a4e4)
Anton Shestakov <av6@dwimlabs.net>
parents:
6220
diff
changeset
|
92 kind, pattern, matcher = stringutil.stringmatcher(topic) |
2651
6a3df2404472
topic-revset: update the revset to no longer build changectx
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2650
diff
changeset
|
93 |
4814
48b30ff742cb
python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents:
4717
diff
changeset
|
94 if topic.startswith(b'literal:') and pattern not in repo.topics: |
48b30ff742cb
python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents:
4717
diff
changeset
|
95 raise error.RepoLookupError(b"topic '%s' does not exist" % pattern) |
4095
aabf436c11cb
topic: refactor revset.py slightly
Anton Shestakov <av6@dwimlabs.net>
parents:
4064
diff
changeset
|
96 |
4059
1914a53fe792
topic: handle string argument to topic() revset earlier
Anton Shestakov <av6@dwimlabs.net>
parents:
4058
diff
changeset
|
97 def matches(r): |
1914a53fe792
topic: handle string argument to topic() revset earlier
Anton Shestakov <av6@dwimlabs.net>
parents:
4058
diff
changeset
|
98 topic = repo[r].topic() |
1914a53fe792
topic: handle string argument to topic() revset earlier
Anton Shestakov <av6@dwimlabs.net>
parents:
4058
diff
changeset
|
99 if not topic: |
1914a53fe792
topic: handle string argument to topic() revset earlier
Anton Shestakov <av6@dwimlabs.net>
parents:
4058
diff
changeset
|
100 return False |
1914a53fe792
topic: handle string argument to topic() revset earlier
Anton Shestakov <av6@dwimlabs.net>
parents:
4058
diff
changeset
|
101 return matcher(topic) |
1914a53fe792
topic: handle string argument to topic() revset earlier
Anton Shestakov <av6@dwimlabs.net>
parents:
4058
diff
changeset
|
102 |
4095
aabf436c11cb
topic: refactor revset.py slightly
Anton Shestakov <av6@dwimlabs.net>
parents:
4064
diff
changeset
|
103 return (subset & mutable).filter(matches) |
4059
1914a53fe792
topic: handle string argument to topic() revset earlier
Anton Shestakov <av6@dwimlabs.net>
parents:
4058
diff
changeset
|
104 |
4060
54eade86ac31
topic: handle revsets passed to topic() revset
Anton Shestakov <av6@dwimlabs.net>
parents:
4059
diff
changeset
|
105 s = revset.getset(repo, revset.fullreposet(repo), x) |
4095
aabf436c11cb
topic: refactor revset.py slightly
Anton Shestakov <av6@dwimlabs.net>
parents:
4064
diff
changeset
|
106 topics = {repo[r].topic() for r in s} |
4814
48b30ff742cb
python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents:
4717
diff
changeset
|
107 topics.discard(b'') |
2651
6a3df2404472
topic-revset: update the revset to no longer build changectx
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2650
diff
changeset
|
108 |
4060
54eade86ac31
topic: handle revsets passed to topic() revset
Anton Shestakov <av6@dwimlabs.net>
parents:
4059
diff
changeset
|
109 def matches(r): |
54eade86ac31
topic: handle revsets passed to topic() revset
Anton Shestakov <av6@dwimlabs.net>
parents:
4059
diff
changeset
|
110 topic = repo[r].topic() |
54eade86ac31
topic: handle revsets passed to topic() revset
Anton Shestakov <av6@dwimlabs.net>
parents:
4059
diff
changeset
|
111 if not topic: |
2651
6a3df2404472
topic-revset: update the revset to no longer build changectx
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2650
diff
changeset
|
112 return False |
4060
54eade86ac31
topic: handle revsets passed to topic() revset
Anton Shestakov <av6@dwimlabs.net>
parents:
4059
diff
changeset
|
113 return topic in topics |
54eade86ac31
topic: handle revsets passed to topic() revset
Anton Shestakov <av6@dwimlabs.net>
parents:
4059
diff
changeset
|
114 |
54eade86ac31
topic: handle revsets passed to topic() revset
Anton Shestakov <av6@dwimlabs.net>
parents:
4059
diff
changeset
|
115 return (subset & mutable).filter(matches) |
1843
0ba067a97d06
revset: add a topic() revset for querying topics
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
116 |
4717
7b36f9728351
py3: use bytes for revset predicate registrations
Martin von Zweigbergk <martinvonz@google.com>
parents:
4390
diff
changeset
|
117 @revsetpredicate(b'ngtip([branch])') |
1870
8dd5200b4086
topic: introduce a 'ngtip' concept
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1865
diff
changeset
|
118 def ngtipset(repo, subset, x): |
5603
5e71952c8b4a
ngtip: make revset help text slightly more descriptive
Sietse Brouwer <sbbrouwer@gmail.com>
parents:
5602
diff
changeset
|
119 """The tip of a branch, ignoring changesets with a topic. |
1870
8dd5200b4086
topic: introduce a 'ngtip' concept
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1865
diff
changeset
|
120 |
8dd5200b4086
topic: introduce a 'ngtip' concept
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1865
diff
changeset
|
121 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
|
122 """ |
4814
48b30ff742cb
python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents:
4717
diff
changeset
|
123 args = revset.getargs(x, 1, 1, b'ngtip takes one argument') |
1870
8dd5200b4086
topic: introduce a 'ngtip' concept
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1865
diff
changeset
|
124 # match a specific topic |
4814
48b30ff742cb
python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents:
4717
diff
changeset
|
125 branch = revset.getstring(args[0], b'ngtip requires a string') |
48b30ff742cb
python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents:
4717
diff
changeset
|
126 if branch == b'.': |
48b30ff742cb
python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents:
4717
diff
changeset
|
127 branch = repo[b'.'].branch() |
5602
e25394b6d021
ngtip: fix TypeError: make revset from revs, not nodes (issue6405)
Sietse Brouwer <sbbrouwer@gmail.com>
parents:
5507
diff
changeset
|
128 # list of length 1 |
e25394b6d021
ngtip: fix TypeError: make revset from revs, not nodes (issue6405)
Sietse Brouwer <sbbrouwer@gmail.com>
parents:
5507
diff
changeset
|
129 revs = [repo[node].rev() for node in destination.ngtip(repo, branch)] |
e25394b6d021
ngtip: fix TypeError: make revset from revs, not nodes (issue6405)
Sietse Brouwer <sbbrouwer@gmail.com>
parents:
5507
diff
changeset
|
130 return subset & revset.baseset(revs) |
1870
8dd5200b4086
topic: introduce a 'ngtip' concept
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1865
diff
changeset
|
131 |
4717
7b36f9728351
py3: use bytes for revset predicate registrations
Martin von Zweigbergk <martinvonz@google.com>
parents:
4390
diff
changeset
|
132 @revsetpredicate(b'stack()') |
1910
24986e5a537c
stack: add a 'stack()' revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1901
diff
changeset
|
133 def stackset(repo, subset, x): |
6297
0ef3c127cf28
doc: fix typo in revset/stack() help text
pacien <pacien.trangirard@pacien.net>
parents:
6261
diff
changeset
|
134 """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
|
135 |
6297
0ef3c127cf28
doc: fix typo in revset/stack() help text
pacien <pacien.trangirard@pacien.net>
parents:
6261
diff
changeset
|
136 This is roughly equivalent to 'topic(.) - obsolete()' with a sorting moving |
0ef3c127cf28
doc: fix typo in revset/stack() help text
pacien <pacien.trangirard@pacien.net>
parents:
6261
diff
changeset
|
137 unstable changeset after their future parent (as if evolve were already |
4290
09337aae08d4
topic: make revset argument messages be similar to such messages in core
Anton Shestakov <av6@dwimlabs.net>
parents:
4095
diff
changeset
|
138 run). |
09337aae08d4
topic: make revset argument messages be similar to such messages in core
Anton Shestakov <av6@dwimlabs.net>
parents:
4095
diff
changeset
|
139 """ |
4814
48b30ff742cb
python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents:
4717
diff
changeset
|
140 err = b'stack takes no arguments, it works on current topic' |
2681
aa4db71a6224
topics: return a parse error if stack() revset is passed with argument
Pulkit Goyal <7895pulkit@gmail.com>
parents:
2669
diff
changeset
|
141 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
|
142 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
|
143 branch = None |
3156
31493a1b0e39
revset: clean up some messy logic
Pulkit Goyal <7895pulkit@gmail.com>
parents:
2924
diff
changeset
|
144 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
|
145 topic = repo.currenttopic |
3156
31493a1b0e39
revset: clean up some messy logic
Pulkit Goyal <7895pulkit@gmail.com>
parents:
2924
diff
changeset
|
146 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
|
147 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
|
148 return revset.baseset(stack.stack(repo, branch=branch, topic=topic)[1:]) & subset |
4322
41f38bf15b4c
topic: make revsets like 'foo#stack[0]' work
Anton Shestakov <av6@dwimlabs.net>
parents:
4290
diff
changeset
|
149 |
5335
e5406605d8f5
topic: document the other safehasattr() compatibility check
Anton Shestakov <av6@dwimlabs.net>
parents:
5334
diff
changeset
|
150 # x#y[z] revset operator support (no support for older version) |
e5406605d8f5
topic: document the other safehasattr() compatibility check
Anton Shestakov <av6@dwimlabs.net>
parents:
5334
diff
changeset
|
151 # hg <= 4.8 (e54bfde922f2) |
4322
41f38bf15b4c
topic: make revsets like 'foo#stack[0]' work
Anton Shestakov <av6@dwimlabs.net>
parents:
4290
diff
changeset
|
152 if util.safehasattr(revset, 'subscriptrelations'): |
5332
801bbfc4e2e8
topic: rename stackrel() to stacksubrel()
Anton Shestakov <av6@dwimlabs.net>
parents:
5253
diff
changeset
|
153 def stacksubrel(repo, subset, x, rel, z, order): |
4322
41f38bf15b4c
topic: make revsets like 'foo#stack[0]' work
Anton Shestakov <av6@dwimlabs.net>
parents:
4290
diff
changeset
|
154 """This is a revset-flavored implementation of stack aliases. |
41f38bf15b4c
topic: make revsets like 'foo#stack[0]' work
Anton Shestakov <av6@dwimlabs.net>
parents:
4290
diff
changeset
|
155 |
41f38bf15b4c
topic: make revsets like 'foo#stack[0]' work
Anton Shestakov <av6@dwimlabs.net>
parents:
4290
diff
changeset
|
156 The syntax is: rev#stack[n] or rev#s[n]. Plenty of logic is borrowed |
41f38bf15b4c
topic: make revsets like 'foo#stack[0]' work
Anton Shestakov <av6@dwimlabs.net>
parents:
4290
diff
changeset
|
157 from topic._namemap, but unlike that function, which prefers to abort |
41f38bf15b4c
topic: make revsets like 'foo#stack[0]' work
Anton Shestakov <av6@dwimlabs.net>
parents:
4290
diff
changeset
|
158 (e.g. when stack index is too high), this returns empty set to be more |
41f38bf15b4c
topic: make revsets like 'foo#stack[0]' work
Anton Shestakov <av6@dwimlabs.net>
parents:
4290
diff
changeset
|
159 revset-friendly. |
41f38bf15b4c
topic: make revsets like 'foo#stack[0]' work
Anton Shestakov <av6@dwimlabs.net>
parents:
4290
diff
changeset
|
160 """ |
4390
312b9e8a4c9c
revset: use getintrange() to parse relation subscript
Anton Shestakov <av6@dwimlabs.net>
parents:
4381
diff
changeset
|
161 # hg 4.9 provides a number or None, hg 5.0 provides a tuple of tokens |
312b9e8a4c9c
revset: use getintrange() to parse relation subscript
Anton Shestakov <av6@dwimlabs.net>
parents:
4381
diff
changeset
|
162 if isinstance(z, tuple): |
312b9e8a4c9c
revset: use getintrange() to parse relation subscript
Anton Shestakov <av6@dwimlabs.net>
parents:
4381
diff
changeset
|
163 a, b = revset.getintrange( |
312b9e8a4c9c
revset: use getintrange() to parse relation subscript
Anton Shestakov <av6@dwimlabs.net>
parents:
4381
diff
changeset
|
164 z, |
4814
48b30ff742cb
python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents:
4717
diff
changeset
|
165 b'relation subscript must be an integer or a range', |
48b30ff742cb
python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents:
4717
diff
changeset
|
166 b'relation subscript bounds must be integers', |
4390
312b9e8a4c9c
revset: use getintrange() to parse relation subscript
Anton Shestakov <av6@dwimlabs.net>
parents:
4381
diff
changeset
|
167 None, None) |
4381
5f1d0cff514d
topic: make ranges work in revset relations like 'foo#stack[1:2]'
Anton Shestakov <av6@dwimlabs.net>
parents:
4380
diff
changeset
|
168 else: |
5193
a4d081923c81
compat: update hg-X.Y compat comments and test them
Anton Shestakov <av6@dwimlabs.net>
parents:
4814
diff
changeset
|
169 # hg <= 4.9 (431cf2c8c839+13f7a6a4f0db) |
4390
312b9e8a4c9c
revset: use getintrange() to parse relation subscript
Anton Shestakov <av6@dwimlabs.net>
parents:
4381
diff
changeset
|
170 a = b = z |
4381
5f1d0cff514d
topic: make ranges work in revset relations like 'foo#stack[1:2]'
Anton Shestakov <av6@dwimlabs.net>
parents:
4380
diff
changeset
|
171 |
4322
41f38bf15b4c
topic: make revsets like 'foo#stack[0]' work
Anton Shestakov <av6@dwimlabs.net>
parents:
4290
diff
changeset
|
172 s = revset.getset(repo, revset.fullreposet(repo), x) |
41f38bf15b4c
topic: make revsets like 'foo#stack[0]' work
Anton Shestakov <av6@dwimlabs.net>
parents:
4290
diff
changeset
|
173 if not s: |
41f38bf15b4c
topic: make revsets like 'foo#stack[0]' work
Anton Shestakov <av6@dwimlabs.net>
parents:
4290
diff
changeset
|
174 return revset.baseset() |
4381
5f1d0cff514d
topic: make ranges work in revset relations like 'foo#stack[1:2]'
Anton Shestakov <av6@dwimlabs.net>
parents:
4380
diff
changeset
|
175 |
5f1d0cff514d
topic: make ranges work in revset relations like 'foo#stack[1:2]'
Anton Shestakov <av6@dwimlabs.net>
parents:
4380
diff
changeset
|
176 def getrange(st, a, b): |
5f1d0cff514d
topic: make ranges work in revset relations like 'foo#stack[1:2]'
Anton Shestakov <av6@dwimlabs.net>
parents:
4380
diff
changeset
|
177 start = 1 if a is None else a |
5f1d0cff514d
topic: make ranges work in revset relations like 'foo#stack[1:2]'
Anton Shestakov <av6@dwimlabs.net>
parents:
4380
diff
changeset
|
178 end = len(st.revs) if b is None else b + 1 |
5f1d0cff514d
topic: make ranges work in revset relations like 'foo#stack[1:2]'
Anton Shestakov <av6@dwimlabs.net>
parents:
4380
diff
changeset
|
179 return range(start, end) |
5f1d0cff514d
topic: make ranges work in revset relations like 'foo#stack[1:2]'
Anton Shestakov <av6@dwimlabs.net>
parents:
4380
diff
changeset
|
180 |
4322
41f38bf15b4c
topic: make revsets like 'foo#stack[0]' work
Anton Shestakov <av6@dwimlabs.net>
parents:
4290
diff
changeset
|
181 revs = [] |
41f38bf15b4c
topic: make revsets like 'foo#stack[0]' work
Anton Shestakov <av6@dwimlabs.net>
parents:
4290
diff
changeset
|
182 for r in s: |
41f38bf15b4c
topic: make revsets like 'foo#stack[0]' work
Anton Shestakov <av6@dwimlabs.net>
parents:
4290
diff
changeset
|
183 topic = repo[r].topic() |
41f38bf15b4c
topic: make revsets like 'foo#stack[0]' work
Anton Shestakov <av6@dwimlabs.net>
parents:
4290
diff
changeset
|
184 if topic: |
41f38bf15b4c
topic: make revsets like 'foo#stack[0]' work
Anton Shestakov <av6@dwimlabs.net>
parents:
4290
diff
changeset
|
185 st = stack.stack(repo, topic=topic) |
41f38bf15b4c
topic: make revsets like 'foo#stack[0]' work
Anton Shestakov <av6@dwimlabs.net>
parents:
4290
diff
changeset
|
186 else: |
41f38bf15b4c
topic: make revsets like 'foo#stack[0]' work
Anton Shestakov <av6@dwimlabs.net>
parents:
4290
diff
changeset
|
187 st = stack.stack(repo, branch=repo[r].branch()) |
4381
5f1d0cff514d
topic: make ranges work in revset relations like 'foo#stack[1:2]'
Anton Shestakov <av6@dwimlabs.net>
parents:
4380
diff
changeset
|
188 for n in getrange(st, a, b): |
5f1d0cff514d
topic: make ranges work in revset relations like 'foo#stack[1:2]'
Anton Shestakov <av6@dwimlabs.net>
parents:
4380
diff
changeset
|
189 if abs(n) >= len(st.revs): |
5f1d0cff514d
topic: make ranges work in revset relations like 'foo#stack[1:2]'
Anton Shestakov <av6@dwimlabs.net>
parents:
4380
diff
changeset
|
190 # also means stack base is not accessible with n < 0, which |
5f1d0cff514d
topic: make ranges work in revset relations like 'foo#stack[1:2]'
Anton Shestakov <av6@dwimlabs.net>
parents:
4380
diff
changeset
|
191 # is by design |
5f1d0cff514d
topic: make ranges work in revset relations like 'foo#stack[1:2]'
Anton Shestakov <av6@dwimlabs.net>
parents:
4380
diff
changeset
|
192 continue |
5f1d0cff514d
topic: make ranges work in revset relations like 'foo#stack[1:2]'
Anton Shestakov <av6@dwimlabs.net>
parents:
4380
diff
changeset
|
193 if n == 0 and b != 0 and a != 0: |
5f1d0cff514d
topic: make ranges work in revset relations like 'foo#stack[1:2]'
Anton Shestakov <av6@dwimlabs.net>
parents:
4380
diff
changeset
|
194 # quirk: we don't want stack base unless specifically asked |
5f1d0cff514d
topic: make ranges work in revset relations like 'foo#stack[1:2]'
Anton Shestakov <av6@dwimlabs.net>
parents:
4380
diff
changeset
|
195 # for it (at least one of the indices is 0) |
5f1d0cff514d
topic: make ranges work in revset relations like 'foo#stack[1:2]'
Anton Shestakov <av6@dwimlabs.net>
parents:
4380
diff
changeset
|
196 continue |
5f1d0cff514d
topic: make ranges work in revset relations like 'foo#stack[1:2]'
Anton Shestakov <av6@dwimlabs.net>
parents:
4380
diff
changeset
|
197 rev = st.revs[n] |
5f1d0cff514d
topic: make ranges work in revset relations like 'foo#stack[1:2]'
Anton Shestakov <av6@dwimlabs.net>
parents:
4380
diff
changeset
|
198 if rev == -1 and n == 0: |
5f1d0cff514d
topic: make ranges work in revset relations like 'foo#stack[1:2]'
Anton Shestakov <av6@dwimlabs.net>
parents:
4380
diff
changeset
|
199 continue |
5f1d0cff514d
topic: make ranges work in revset relations like 'foo#stack[1:2]'
Anton Shestakov <av6@dwimlabs.net>
parents:
4380
diff
changeset
|
200 if rev not in revs: |
5f1d0cff514d
topic: make ranges work in revset relations like 'foo#stack[1:2]'
Anton Shestakov <av6@dwimlabs.net>
parents:
4380
diff
changeset
|
201 revs.append(rev) |
5f1d0cff514d
topic: make ranges work in revset relations like 'foo#stack[1:2]'
Anton Shestakov <av6@dwimlabs.net>
parents:
4380
diff
changeset
|
202 |
4322
41f38bf15b4c
topic: make revsets like 'foo#stack[0]' work
Anton Shestakov <av6@dwimlabs.net>
parents:
4290
diff
changeset
|
203 return subset & revset.baseset(revs) |
41f38bf15b4c
topic: make revsets like 'foo#stack[0]' work
Anton Shestakov <av6@dwimlabs.net>
parents:
4290
diff
changeset
|
204 |
5332
801bbfc4e2e8
topic: rename stackrel() to stacksubrel()
Anton Shestakov <av6@dwimlabs.net>
parents:
5253
diff
changeset
|
205 revset.subscriptrelations[b'stack'] = stacksubrel |
801bbfc4e2e8
topic: rename stackrel() to stacksubrel()
Anton Shestakov <av6@dwimlabs.net>
parents:
5253
diff
changeset
|
206 revset.subscriptrelations[b's'] = stacksubrel |
4339
0f015fe4f71f
topic: make revsets like 'foo#topic[0]' work
Anton Shestakov <av6@dwimlabs.net>
parents:
4323
diff
changeset
|
207 |
5334
498dc93c3fa0
topic: rename topicrel() to topicsubrel() while at it
Anton Shestakov <av6@dwimlabs.net>
parents:
5333
diff
changeset
|
208 def topicsubrel(repo, subset, x, *args): |
4379
2893b127923b
topic: make ranges work in revset relations like 'foo#topic[1:2]'
Anton Shestakov <av6@dwimlabs.net>
parents:
4369
diff
changeset
|
209 subset &= topicset(repo, subset, x) |
5252
a828c7a7ace1
topic: use generationssubrel less directly, because it was recently renamed
Anton Shestakov <av6@dwimlabs.net>
parents:
4814
diff
changeset
|
210 # not using revset.generationssubrel directly because it was renamed |
a828c7a7ace1
topic: use generationssubrel less directly, because it was recently renamed
Anton Shestakov <av6@dwimlabs.net>
parents:
4814
diff
changeset
|
211 # hg <= 5.3 (8859de3e83dc) |
a828c7a7ace1
topic: use generationssubrel less directly, because it was recently renamed
Anton Shestakov <av6@dwimlabs.net>
parents:
4814
diff
changeset
|
212 generationssubrel = revset.subscriptrelations[b'generations'] |
a828c7a7ace1
topic: use generationssubrel less directly, because it was recently renamed
Anton Shestakov <av6@dwimlabs.net>
parents:
4814
diff
changeset
|
213 return generationssubrel(repo, subset, x, *args) |
4339
0f015fe4f71f
topic: make revsets like 'foo#topic[0]' work
Anton Shestakov <av6@dwimlabs.net>
parents:
4323
diff
changeset
|
214 |
5334
498dc93c3fa0
topic: rename topicrel() to topicsubrel() while at it
Anton Shestakov <av6@dwimlabs.net>
parents:
5333
diff
changeset
|
215 revset.subscriptrelations[b'topic'] = topicsubrel |
498dc93c3fa0
topic: rename topicrel() to topicsubrel() while at it
Anton Shestakov <av6@dwimlabs.net>
parents:
5333
diff
changeset
|
216 revset.subscriptrelations[b't'] = topicsubrel |
5333
028e4ea75456
topic: support foo#stack syntax
Anton Shestakov <av6@dwimlabs.net>
parents:
5332
diff
changeset
|
217 |
028e4ea75456
topic: support foo#stack syntax
Anton Shestakov <av6@dwimlabs.net>
parents:
5332
diff
changeset
|
218 # x#y revset operator support (no support for older version) |
028e4ea75456
topic: support foo#stack syntax
Anton Shestakov <av6@dwimlabs.net>
parents:
5332
diff
changeset
|
219 # hg <= 5.3 (eca82eb9d777) |
028e4ea75456
topic: support foo#stack syntax
Anton Shestakov <av6@dwimlabs.net>
parents:
5332
diff
changeset
|
220 if util.safehasattr(revset, 'relations'): |
028e4ea75456
topic: support foo#stack syntax
Anton Shestakov <av6@dwimlabs.net>
parents:
5332
diff
changeset
|
221 def stackrel(repo, subset, x, rel, order): |
028e4ea75456
topic: support foo#stack syntax
Anton Shestakov <av6@dwimlabs.net>
parents:
5332
diff
changeset
|
222 z = (b'rangeall', None) |
028e4ea75456
topic: support foo#stack syntax
Anton Shestakov <av6@dwimlabs.net>
parents:
5332
diff
changeset
|
223 return stacksubrel(repo, subset, x, rel, z, order) |
028e4ea75456
topic: support foo#stack syntax
Anton Shestakov <av6@dwimlabs.net>
parents:
5332
diff
changeset
|
224 |
028e4ea75456
topic: support foo#stack syntax
Anton Shestakov <av6@dwimlabs.net>
parents:
5332
diff
changeset
|
225 revset.relations[b'stack'] = stackrel |
028e4ea75456
topic: support foo#stack syntax
Anton Shestakov <av6@dwimlabs.net>
parents:
5332
diff
changeset
|
226 revset.relations[b's'] = stackrel |