comparison hgext3rd/topic/revset.py @ 4322:41f38bf15b4c

topic: make revsets like 'foo#stack[0]' work 'stack' relation subscript function is another way to refer to s0, s1, etc. But instead of aborting in many cases it will simply return an empty set.
author Anton Shestakov <av6@dwimlabs.net>
date Sun, 16 Dec 2018 11:22:04 +0800
parents 09337aae08d4
children 482992803db6
comparison
equal deleted inserted replaced
4321:00d1963f50e5 4322:41f38bf15b4c
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 if n < 0:
120 return revset.baseset()
121 s = revset.getset(repo, revset.fullreposet(repo), x)
122 if not s:
123 return revset.baseset()
124 revs = []
125 for r in s:
126 topic = repo[r].topic()
127 if topic:
128 st = stack.stack(repo, topic=topic)
129 else:
130 st = stack.stack(repo, branch=repo[r].branch())
131 try:
132 rev = list(st)[n]
133 except IndexError:
134 continue
135 if rev == -1 and n == 0:
136 continue
137 if rev not in revs:
138 revs.append(rev)
139 return subset & revset.baseset(revs)
140
141 revset.subscriptrelations['stack'] = stackrel
142 revset.subscriptrelations['s'] = stackrel