comparison hgext3rd/topic/stack.py @ 2916:17749d9d3968

stack: move data computation on the object We gather multiple data about the stack on the object. Let us move this on the object and keep it cached there.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Mon, 04 Sep 2017 12:41:30 +0200
parents b3abdb3d819e
children 0437158e0ed6
comparison
equal deleted inserted replaced
2915:b3abdb3d819e 2916:17749d9d3968
47 47
48 def index(self, item): 48 def index(self, item):
49 return self.revs.index(item) 49 return self.revs.index(item)
50 50
51 @util.propertycache 51 @util.propertycache
52 def _dependencies(self):
53 return builddependencies(self._repo, self.revs[1:])
54
55 @util.propertycache
52 def revs(self): 56 def revs(self):
53 revs = _orderrevs(self._repo, self._revs) 57 revs = _orderrevs(self._repo, self._revs)
54 if revs: 58 if revs:
55 pt1 = self._repo[revs[0]].p1() 59 pt1 = self._repo[revs[0]].p1()
56 if pt1.obsolete(): 60 if pt1.obsolete():
57 pt1 = self._repo[_singlesuccessor(self._repo, pt1)] 61 pt1 = self._repo[_singlesuccessor(self._repo, pt1)]
58 revs.insert(0, pt1.rev()) 62 revs.insert(0, pt1.rev())
59 return revs 63 return revs
64
65 @util.propertycache
66 def changesetcount(self):
67 return len(self._revs)
68
69 @util.propertycache
70 def troubledcount(self):
71 return len([r for r in self._revs if self._repo[r].isunstable()])
72
73 @util.propertycache
74 def heads(self):
75 revs = self.revs[1:]
76 deps, rdeps = self._dependencies
77 return [r for r in revs if not rdeps[r]]
78
79 @util.propertycache
80 def behindcount(self):
81 revs = self.revs[1:]
82 deps, rdeps = self._dependencies
83 if revs:
84 minroot = [min(r for r in revs if not deps[r])]
85 try:
86 dest = destutil.destmerge(self._repo, action='rebase',
87 sourceset=minroot,
88 onheadcheck=False)
89 return len(self._repo.revs("only(%d, %ld)", dest, minroot))
90 except error.NoMergeDestAbort:
91 return 0
92 except error.ManyMergeDestAbort:
93 return -1
94 return 0
95
96 @util.propertycache
97 def branches(self):
98 return sorted(set(self._repo[r].branch() for r in self._revs))
60 99
61 def labelsgen(prefix, labelssuffix): 100 def labelsgen(prefix, labelssuffix):
62 """ Takes a label prefix and a list of suffixes. Returns a string of the prefix 101 """ Takes a label prefix and a list of suffixes. Returns a string of the prefix
63 formatted with each suffix separated with a space. 102 formatted with each suffix separated with a space.
64 """ 103 """
195 :troubledcount: number on troubled changesets 234 :troubledcount: number on troubled changesets
196 :headcount: number of heads on the topic 235 :headcount: number of heads on the topic
197 :behindcount: number of changeset on rebase destination 236 :behindcount: number of changeset on rebase destination
198 """ 237 """
199 data = {} 238 data = {}
200 revs = stack(repo, branch, topic)[1:] 239 current = stack(repo, branch, topic)
201 data['changesetcount'] = len(revs) 240 data['changesetcount'] = current.changesetcount
202 data['troubledcount'] = len([r for r in revs if repo[r].isunstable()]) 241 data['troubledcount'] = current.troubledcount
203 deps, rdeps = builddependencies(repo, revs) 242 data['headcount'] = len(current.heads)
204 data['headcount'] = len([r for r in revs if not rdeps[r]]) 243 data['behindcount'] = current.behindcount
205 data['behindcount'] = 0 244 data['branches'] = current.branches
206 if revs:
207 minroot = [min(r for r in revs if not deps[r])]
208 try:
209 dest = destutil.destmerge(repo, action='rebase',
210 sourceset=minroot,
211 onheadcheck=False)
212 data['behindcount'] = len(repo.revs("only(%d, %ld)", dest,
213 minroot))
214 except error.NoMergeDestAbort:
215 data['behindcount'] = 0
216 except error.ManyMergeDestAbort:
217 data['behindcount'] = -1
218 data['branches'] = sorted(set(repo[r].branch() for r in revs))
219
220 return data 245 return data