104 if repo.currenttopic: |
104 if repo.currenttopic: |
105 topic = repo.currenttopic |
105 topic = repo.currenttopic |
106 else: |
106 else: |
107 branch = repo[None].branch() |
107 branch = repo[None].branch() |
108 return revset.baseset(stack.stack(repo, branch=branch, topic=topic)[1:]) & subset |
108 return revset.baseset(stack.stack(repo, branch=branch, topic=topic)[1:]) & subset |
|
109 |
|
110 if util.safehasattr(revset, 'subscriptrelations'): |
|
111 def stackrel(repo, subset, x, rel, n, order): |
|
112 """This is a revset-flavored implementation of stack aliases. |
|
113 |
|
114 The syntax is: rev#stack[n] or rev#s[n]. Plenty of logic is borrowed |
|
115 from topic._namemap, but unlike that function, which prefers to abort |
|
116 (e.g. when stack index is too high), this returns empty set to be more |
|
117 revset-friendly. |
|
118 """ |
|
119 s = revset.getset(repo, revset.fullreposet(repo), x) |
|
120 if not s: |
|
121 return revset.baseset() |
|
122 revs = [] |
|
123 for r in s: |
|
124 topic = repo[r].topic() |
|
125 if topic: |
|
126 st = stack.stack(repo, topic=topic) |
|
127 else: |
|
128 st = stack.stack(repo, branch=repo[r].branch()) |
|
129 if n < 0: |
|
130 st = list(st)[1:] |
|
131 else: |
|
132 st = list(st) |
|
133 try: |
|
134 rev = st[n] |
|
135 except IndexError: |
|
136 continue |
|
137 if rev == -1 and n == 0: |
|
138 continue |
|
139 if rev not in revs: |
|
140 revs.append(rev) |
|
141 return subset & revset.baseset(revs) |
|
142 |
|
143 revset.subscriptrelations['stack'] = stackrel |
|
144 revset.subscriptrelations['s'] = stackrel |
|
145 |
|
146 def topicrel(repo, subset, x, rel, n, order): |
|
147 ancestors = revset._ancestors |
|
148 descendants = revset._descendants |
|
149 subset = topicset(repo, subset, x) |
|
150 if n <= 0: |
|
151 n = -n |
|
152 return ancestors(repo, subset, x, startdepth=n, stopdepth=n + 1) |
|
153 else: |
|
154 return descendants(repo, subset, x, startdepth=n, stopdepth=n + 1) |
|
155 |
|
156 revset.subscriptrelations['topic'] = topicrel |
|
157 revset.subscriptrelations['t'] = topicrel |