Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 2.0, 2.0.1, and 2.0.2

stable reporegistry: store shortname in xml to reduce overhead of thgrepo creation

This should reduce memory and CPU usage by avoiding unnecessary instantiation
of every thgrepo object listed in reporegistry.

Changeset eba9fe3ae102

Parent 1d9f99848608

by Yuya Nishihara

Changes to 2 files · Browse files at eba9fe3ae102 Showing diff from parent 1d9f99848608 Diff from another changeset...

 
250
251
252
253
 
 
254
 
 
255
256
257
 
250
251
252
 
253
254
255
256
257
258
259
260
@@ -250,8 +250,11 @@
    def addRepo(self, repo):   m = self.tmodel - if m.getRepoItem(repo.root) == None: + it = m.getRepoItem(repo.root) + if it == None:   m.addRepo(None, repo) + else: + it.ensureRepoLoaded()     def openrepo(self, path, reuse=False):   self.openRepoSignal.emit(hglib.tounicode(path), reuse)
 
147
148
149
150
 
 
 
151
152
153
154
155
 
 
 
 
 
 
 
 
156
157
158
 
160
161
162
163
164
165
166
 
167
168
169
 
180
181
182
 
183
184
185
186
187
 
188
189
190
 
198
199
200
 
201
202
 
 
 
 
 
 
 
 
 
203
204
205
 
147
148
149
 
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
 
170
171
172
 
 
 
 
173
174
175
176
 
187
188
189
190
191
192
193
194
195
196
197
198
199
 
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
@@ -147,12 +147,22 @@
 class RepoItem(RepoTreeItem):   def __init__(self, model, repo=None, parent=None):   RepoTreeItem.__init__(self, model, parent) - self._root = repo and repo.root or '' + self._repo = repo + self._root = repo and repo.root or '' # local str + self._shortname = repo and repo.shortname or '' # unicode   self._settingsdlg = None     def rootpath(self):   return self._root   + def shortname(self): + if self._repo: + return self._repo.shortname + elif self._shortname: + return self._shortname + else: + return hglib.tounicode(os.path.basename(self._root)) +   def data(self, column, role):   if role == Qt.DecorationRole:   if column == 0: @@ -160,10 +170,7 @@
  return QVariant(ico)   return QVariant()   if column == 0: - try: - return QVariant(thgrepo.repository(path=self._root).shortname) - except error.RepoError: - return QVariant(hglib.tounicode(os.path.basename(self._root))) + return QVariant(self.shortname())   elif column == 1:   return QVariant(hglib.tounicode(self._root))   return QVariant() @@ -180,11 +187,13 @@
    def dump(self, xw):   xw.writeAttribute('root', hglib.tounicode(self._root)) + xw.writeAttribute('shortname', self.shortname())   RepoTreeItem.dump(self, xw)     def undump(self, xr):   a = xr.attributes()   self._root = hglib.fromunicode(a.value('', 'root').toString()) + self._shortname = unicode(a.value('', 'shortname').toString())   RepoTreeItem.undump(self, xr)     def open(self, reuse=False): @@ -198,8 +207,18 @@
  self._settingsdlg = SettingsDialog(   configrepo=True, focus='web.name', parent=parent,   root=self._root) + self.ensureRepoLoaded()   self._settingsdlg.show()   + def ensureRepoLoaded(self): + """load repo object if necessary + + Until repo loaded, it uses cached shortname for less overhead. + """ + if self._repo: + return + self._repo = thgrepo.repository(path=self._root) +   def details(self):   return _('Local Repository %s') % hglib.tounicode(self._root)