Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 2.1, 2.1.1, and 2.1.2

manifest: optimize subrepo search

In order to show the contents of subrepos in the manifest window, whenever a
file is selected in the manifest we must look for the deepest subrepo containing
the file.

Before this patch, the deepest subrepo search was performed by recursively
searching for subrepos from the top repo down, which could be an expensive
operation.

This patch adds a dictionary to the manifest model, which is generated once when
the model is created, containing path-context pairs (with the paths being the
keys to the dictionary). Then, when a file is selected in the manifest, we can
simply check this "subrepo info" dictionary, which is a much faster operation.

Changeset 47ac907e2b8c

Parent 7ad3aeca6803

by Angel Ezquerra

Changes to 3 files · Browse files at 47ac907e2b8c Showing diff from parent 7ad3aeca6803 Diff from another changeset...

 
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
 
 
 
 
101
102
 
103
104
105
106
107
108
109
110
111
112
113
114
115
116
 
117
118
119
 
213
214
215
216
 
217
218
219
 
225
226
227
228
 
229
230
231
 
286
287
288
289
 
290
291
292
 
86
87
88
 
 
 
 
 
 
 
 
 
 
 
 
89
90
91
92
93
 
94
95
96
 
 
 
 
 
 
 
 
 
 
97
 
98
99
100
101
 
195
196
197
 
198
199
200
201
 
207
208
209
 
210
211
212
213
 
268
269
270
 
271
272
273
274
@@ -86,34 +86,16 @@
  self.flabel += _(' <i>(is a symlink)</i>')   return   - wsub, wfileinsub, sctx = \ - hglib.getDeepestSubrepoContainingFile(wfile, ctx) - if wsub: - topctx = ctx - topwfile = wfile - ctx = sctx - wfile = wfileinsub - if ctx2: - # If a revision to compare to was provided, we must put it in - # the context of the subrepo as well - # Here we had two choices: - # We could translate the seo + if ctx2: + # If a revision to compare to was provided, we must put it in + # the context of the subrepo as well + if ctx2._repo.root != ctx._repo.root:   wsub2, wfileinsub2, sctx2 = \ - hglib.getDeepestSubrepoContainingFile(topwfile, ctx2) + hglib.getDeepestSubrepoContainingFile(wfile, ctx2)   if wsub2:   ctx2 = sctx2 - else: - # Note that this is NOT THE SAME as topctx.p1()! - # [TODO] Perhaps we should try instead to get the context from - # the state of the supreop at topctx.p1(), that is, something - # such as: wsub2, wfileinsub2, ctx2 = \ - # ... hglib.getDeepestSubrepoContainingFile(topwfile, topctx.p1()) - pass # This is set below to ctx2 = ctx.p1() - else: - topctx = ctx - topwfile = wfile   - absfile = repo.wjoin(os.path.join(wsub or '', wfile)) + absfile = repo.wjoin(wfile)   if (wfile in ctx and 'l' in ctx.flags(wfile)) or \   os.path.islink(absfile):   if wfile in ctx: @@ -213,7 +195,7 @@
  out = []   _ui = uimod.ui()   - if srepo is None or (topctx.rev() is not None and ctx.rev() is not None): + if srepo is None or ctx.rev() is not None:   data = []   else:   _ui.pushbuffer() @@ -225,7 +207,7 @@
  out.append(u'\n')     sstatedesc = 'changed' - if topctx.rev() is not None and ctx.rev() is not None: + if ctx.rev() is not None:   sparent = ctx.p1().substate.get(wfile, subrepo.nullstate)[1]   subrepochange, sstatedesc = \   genSubrepoRevChangedDescription(wfile, @@ -286,7 +268,7 @@
  return     if status in ('I', '?', 'C'): - if topctx.rev() is None or ctx.rev() is None: + if ctx.rev() is None:   if status in ('I', '?'):   self.flabel += _(' <i>(is unversioned)</i>')   if os.path.getsize(absfile) > maxdiff:
 
459
460
461
462
 
 
 
 
 
 
 
 
 
 
 
463
464
465
466
 
 
 
 
 
467
468
469
 
459
460
461
 
462
463
464
465
466
467
468
469
470
471
472
473
474
 
 
475
476
477
478
479
480
481
482
@@ -459,11 +459,24 @@
  def setPath(self, path):   """Change path to show"""   self._treeview.setCurrentIndex(self._treemodel.indexFromPath(path)) - + + def displayFile(self): + ctx, path = self._treemodel.fileSubrepoCtxFromPath(self.path) + if ctx is None: + ctx = self._repo[self._rev] + else: + ctx._repo.tabwidth = self._repo.tabwidth + ctx._repo.maxdiff = self._repo.maxdiff + self._fileview.setContext(ctx) + self._fileview.displayFile(path, self.status) +   @pyqtSlot()   def _updatecontent(self): - self._fileview.setContext(self._repo[self._rev]) - self._fileview.displayFile(self.path, self.status) + if True: + self.displayFile() + else: + self._fileview.setContext(self._repo[self._rev]) + self._fileview.displayFile(self.path, self.status)     @pyqtSlot()   def _emitPathChanged(self):
 
32
33
34
 
35
36
37
 
56
57
58
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
60
61
 
224
225
226
227
 
228
229
230
 
235
236
237
238
 
239
240
241
242
243
244
 
245
246
247
248
 
 
249
250
251
 
254
255
256
257
258
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
259
260
261
 
262
263
264
 
 
 
265
266
267
 
268
269
270
 
32
33
34
35
36
37
38
 
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
 
239
240
241
 
242
243
244
245
 
250
251
252
 
253
254
255
256
257
258
 
259
260
261
 
 
262
263
264
265
266
 
269
270
271
 
 
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
 
289
290
291
 
292
293
294
295
296
 
297
298
299
300
@@ -32,6 +32,7 @@
    self._repo = repo   self._rev = rev + self._subinfo = {}     assert util.all(c in 'MARSC' for c in statusfilter)   self._statusfilter = statusfilter @@ -56,6 +57,20 @@
    return index.internalPointer().path   + def fileSubrepoCtx(self, index): + """Return the subrepo context of the specified index""" + path = self.filePath(index) + return self.fileSubrepoCtxFromPath(path) + + def fileSubrepoCtxFromPath(self, path): + """Return the subrepo context of the specified file""" + if not path: + return None, path + for subpath in sorted(self._subinfo.keys())[::-1]: + if path.startswith(subpath): + return self._subinfo[subpath], path[len(subpath)+1:] + return None, path +   def fileIcon(self, index):   ic = QApplication.style().standardIcon(   self.isDir(index) and QStyle.SP_DirIcon or QStyle.SP_FileIcon) @@ -224,7 +239,7 @@
  e.setstatus('C')     # Add subrepos to the tree - def addrepocontentstotree(roote, ctx): + def addrepocontentstotree(roote, ctx, toproot=''):   subpaths = ctx.substate.keys()   for path in subpaths:   if not 'S' in self._statusfilter: @@ -235,17 +250,17 @@
  if not p in e:   e.addchild(p)   e = e[p] - +   p = pathelements[-1]   if not p in e:   e.addchild(p)   e = e[p]   e.setstatus('S') - +   # If the subrepo exists in the working directory   # and it is a mercurial subrepo, - # add the files that it contains to the tree as well, according ot - # the status filter + # add the files that it contains to the tree as well, according + # to the status filter   abspath = os.path.join(ctx._repo.root, path)   if os.path.isdir(abspath):   # Add subrepo files to the tree @@ -254,17 +269,32 @@
  if srev and isinstance(sub, hgsubrepo):   srepo = sub._repo   sctx = srepo[srev] - e = addrepocontentstotree(e, sctx) - + + # Add the subrepo info to the _subinfo dictionary: + # The value is the subrepo context, while the key is + # the path of the subrepo relative to the topmost repo + if toproot: + # Note that we cannot use os.path.join() because we + # need path items to be separated by "/" + toprelpath = '/'.join([toproot, path]) + else: + toprelpath = path + self._subinfo[toprelpath] = sctx + + # Add the subrepo contents to the tree + e = addrepocontentstotree(e, sctx, toprelpath) +   # Add regular files to the tree   status, uncleanpaths, files = getctxtreeinfo(ctx, self._repo) - +   addfilestotree(roote, files, status, uncleanpaths)   return roote - + + # Clear the _subinfo + self._subinfo = {}   roote = _Entry()   ctx = self._repo[self._rev] - +   addrepocontentstotree(roote, ctx)   roote.sort()