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:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
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
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
 
 
 
 
 
 
 
 
 
 
 
463
464
465
466
 
 
 
 
 
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
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
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
 
462
463
464
465
466
467
468
469
470
471
472
473
474
 
 
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
 # manifestdialog.py - Dialog and widget for TortoiseHg manifest view  #  # Copyright (C) 2003-2010 LOGILAB S.A. <http://www.logilab.fr/>  # Copyright (C) 2010 Yuya Nishihara <yuya@tcha.org>  #  # This program is free software; you can redistribute it and/or modify it under  # the terms of the GNU General Public License as published by the Free Software  # Foundation; either version 2 of the License, or (at your option) any later  # version.    import os    from mercurial import util    from PyQt4.QtCore import *  from PyQt4.QtGui import *    from tortoisehg.util import paths, hglib    from tortoisehg.hgqt.i18n import _  from tortoisehg.hgqt import qtlib, qscilib, fileview, status, thgrepo  from tortoisehg.hgqt import visdiff, revert  from tortoisehg.hgqt.filedialogs import FileLogDialog, FileDiffDialog  from tortoisehg.hgqt.manifestmodel import ManifestModel    class ManifestDialog(QMainWindow):   """   Qt4 dialog to display all files of a repo at a given revision   """     finished = pyqtSignal(int)   linkActivated = pyqtSignal(QString)     def __init__(self, repo, rev=None, parent=None):   QMainWindow.__init__(self, parent)   self._repo = repo   self.setWindowIcon(qtlib.geticon('hg-annotate'))   self.resize(400, 300)     self._manifest_widget = ManifestWidget(repo, rev)   self._manifest_widget.revChanged.connect(self._updatewindowtitle)   self._manifest_widget.pathChanged.connect(self._updatewindowtitle)   self._manifest_widget.grepRequested.connect(self._openSearchWidget)   self.setCentralWidget(self._manifest_widget)   self.addToolBar(self._manifest_widget.toolbar)     self.setStatusBar(QStatusBar())   self._manifest_widget.showMessage.connect(self.statusBar().showMessage)   self._manifest_widget.linkActivated.connect(self.linkActivated)     self._readsettings()   self._updatewindowtitle()     @pyqtSlot()   def _updatewindowtitle(self):   self.setWindowTitle(_('Manifest %s@%s') % (   self._manifest_widget.path, self._manifest_widget.rev))     def closeEvent(self, event):   self._writesettings()   super(ManifestDialog, self).closeEvent(event)   self.finished.emit(0) # mimic QDialog exit     def _readsettings(self):   s = QSettings()   self.restoreGeometry(s.value('manifest/geom').toByteArray())   self._manifest_widget.loadSettings(s, 'manifest')     def _writesettings(self):   s = QSettings()   s.setValue('manifest/geom', self.saveGeometry())   self._manifest_widget.saveSettings(s, 'manifest')     def setSource(self, path, rev, line=None):   self._manifest_widget.setSource(path, rev, line)     def setSearchPattern(self, text):   """Set search pattern [unicode]"""   self._manifest_widget._fileview.searchbar.setPattern(text)     @pyqtSlot(unicode, dict)   def _openSearchWidget(self, pattern, opts):   opts = dict((str(k), str(v)) for k, v in opts.iteritems())   from tortoisehg.hgqt import run   run.grep(self._repo.ui, hglib.fromunicode(pattern), **opts)     @pyqtSlot(unicode, object, int)   def _openInEditor(self, path, rev, line):   """Open editor to show the specified file"""   _openineditor(self._repo, path, rev, line,   pattern=self._fileview.searchbar.pattern(), parent=self)    class ManifestWidget(QWidget):   """Display file tree and contents at the specified revision"""     revChanged = pyqtSignal(object)   """Emitted (rev) when the current revision changed"""     pathChanged = pyqtSignal(unicode)   """Emitted (path) when the current file path changed"""     showMessage = pyqtSignal(unicode)   """Emitted when to show revision summary as a hint"""     grepRequested = pyqtSignal(unicode, dict)   """Emitted (pattern, opts) when user request to search changelog"""     linkActivated = pyqtSignal(QString)   """Emitted (path) when user clicks on link"""     filecontextmenu = None   subrepocontextmenu = None     def __init__(self, repo, rev=None, parent=None):   super(ManifestWidget, self).__init__(parent)   self._repo = repo   self._rev = rev   self._selectedrev = rev   self._diff_dialogs = {}   self._nav_dialogs = {}     self._initwidget()   self._initactions()   self._setupmodel()   self._treeview.setCurrentIndex(self._treemodel.index(0, 0))     self.setRev(self._rev)     def _initwidget(self):   self.setLayout(QVBoxLayout())   self._splitter = QSplitter()   self.layout().addWidget(self._splitter)   self.layout().setContentsMargins(2, 2, 2, 2)     navlayout = QVBoxLayout(spacing=0)   navlayout.setContentsMargins(0, 0, 0, 0)   self._toolbar = QToolBar()   self._toolbar.setIconSize(QSize(16,16))   self._treeview = QTreeView(self, headerHidden=True, dragEnabled=True)   self._treeview.setContextMenuPolicy(Qt.CustomContextMenu)   self._treeview.customContextMenuRequested.connect(self.menuRequest)   self._treeview.doubleClicked.connect(self.onDoubleClick)   navlayout.addWidget(self._toolbar)   navlayout.addWidget(self._treeview)   navlayoutw = QWidget()   navlayoutw.setLayout(navlayout)     self._splitter.addWidget(navlayoutw)   self._splitter.setStretchFactor(0, 1)     self._fileview = fileview.HgFileView(self._repo, self)   self._splitter.addWidget(self._fileview)   self._splitter.setStretchFactor(1, 3)   self._fileview.revisionSelected.connect(self.setRev)   self._fileview.linkActivated.connect(self.linkActivated)   for name in ('showMessage', 'grepRequested'):   getattr(self._fileview, name).connect(getattr(self, name))     def loadSettings(self, qs, prefix):   prefix += '/manifest'   self._fileview.loadSettings(qs, prefix+'/fileview')   self._splitter.restoreState(qs.value(prefix+'/splitter').toByteArray())     def saveSettings(self, qs, prefix):   prefix += '/manifest'   self._fileview.saveSettings(qs, prefix+'/fileview')   qs.setValue(prefix+'/splitter', self._splitter.saveState())     def _initactions(self):   self._statusfilter = status.StatusFilterButton(   statustext='MASC', text=_('Status'))   self._toolbar.addWidget(self._statusfilter)     self._actions = {}   for name, desc, icon, key, tip, cb in [   ('navigate', _('File history'), 'hg-log', 'Shift+Return',   _('Show the history of the selected file'), self.navigate),   ('diffnavigate', _('Compare file revisions'), 'compare-files', None,   _('Compare revisions of the selected file'), self.diffNavigate),   ('diff', _('Visual Diff'), 'visualdiff', 'Ctrl+D',   _('View file changes in external diff tool'), self.vdiff),   ('ldiff', _('Visual Diff to Local'), 'ldiff', 'Shift+Ctrl+D',   _('View changes to current in external diff tool'),   self.vdifflocal),   ('edit', _('View at Revision'), 'view-at-revision', 'Alt+Ctrl+E',   _('View file as it appeared at this revision'), self.editfile),   ('ledit', _('Edit Local'), 'edit-file', 'Shift+Ctrl+E',   _('Edit current file in working copy'), self.editlocal),   ('revert', _('Revert to Revision'), 'hg-revert', 'Alt+Ctrl+T',   _('Revert file(s) to contents at this revision'),   self.revertfile),   ('opensubrepo', _('Open subrepository'), 'thg-repository-open',   'Alt+Ctrl+O', _('Open the selected subrepository'),   self.opensubrepo),   ('explore', _('Explore subrepository'), 'system-file-manager',   'Alt+Ctrl+E',   _('Open the selected subrepository in a file browser'),   self.explore),   ('terminal', _('Open terminal in subrepository'),   'utilities-terminal', 'Alt+Ctrl+T',   _('Open a shell terminal in the selected subrepository root'),   self.terminal),   ]:   act = QAction(desc, self)   if icon:   act.setIcon(qtlib.getmenuicon(icon))   if key:   act.setShortcut(key)   if tip:   act.setStatusTip(tip)   if cb:   act.triggered.connect(cb)   self._actions[name] = act   self.addAction(act)     def navigate(self, filename=None):   self._navigate(filename, FileLogDialog, self._nav_dialogs)     def diffNavigate(self, filename=None):   self._navigate(filename, FileDiffDialog, self._diff_dialogs)     def vdiff(self):   if self.path is None:   return   pats = [self.path]   opts = {'change':self.rev}   dlg = visdiff.visualdiff(self._repo.ui, self._repo, pats, opts)   if dlg:   dlg.exec_()     def vdifflocal(self):   if self.path is None:   return   pats = [self.path]   assert type(self.rev) is int   opts = {'rev':['rev(%d)' % self.rev]}   dlg = visdiff.visualdiff(self._repo.ui, self._repo, pats, opts)   if dlg:   dlg.exec_()     def editfile(self):   if self.path is None:   return   if self.rev is None:   qtlib.editfiles(self._repo, [self.path], parent=self)   else:   base, _ = visdiff.snapshot(self._repo, [self.path],   self._repo[self.rev])   files = [os.path.join(base, self.path)]   qtlib.editfiles(self._repo, files, parent=self)     def editlocal(self):   if self.path is None:   return   qtlib.editfiles(self._repo, [self.path], parent=self)     def revertfile(self):   if self.path is None:   return   if self.rev is None:   rev = self._repo['.'].rev()   dlg = revert.RevertDialog(self._repo, [self.path], self.rev, self)   dlg.exec_()     def _navigate(self, filename, dlgclass, dlgdict):   if not filename:   filename = self.path   if filename not in dlgdict:   dlg = dlgclass(self._repo, filename,   repoviewer=self.window())   dlgdict[filename] = dlg   ufname = hglib.tounicode(filename)   dlg.setWindowTitle(_('Hg file log viewer - %s') % ufname)   dlg = dlgdict[filename]   dlg.goto(self.rev)   dlg.show()   dlg.raise_()   dlg.activateWindow()     def opensubrepo(self):   path = self._repo.wjoin(self.path)   if os.path.isdir(path):   self.linkActivated.emit(u'subrepo:'+hglib.tounicode(path))   else:   QMessageBox.warning(self,   _("Cannot open subrepository"),   _("The selected subrepository does not exist on the working directory"))     def explore(self):   root = self._repo.wjoin(self.path)   if os.path.isdir(root):   QDesktopServices.openUrl(QUrl.fromLocalFile(root))     def terminal(self):   root = self._repo.wjoin(self.path)   if os.path.isdir(root):   qtlib.openshell(root)     def showEvent(self, event):   QWidget.showEvent(self, event)   if self._selectedrev != self._rev:   # If the selected revision is not the same as the current revision   # we must "reload" the manifest contents with the selected revision   self.setRev(self._selectedrev)     #@pyqtSlot(QModelIndex)   def onDoubleClick(self, index):   itemissubrepo = (self._treemodel.fileStatus(index) == 'S')   if itemissubrepo:   self.opensubrepo()   else:   self.vdiff()     def menuRequest(self, point):   point = self.mapToGlobal(point)     currentindex = self._treeview.currentIndex()   itemissubrepo = (self._treemodel.fileStatus(currentindex) == 'S')     # Subrepos and regular items have different context menus   if itemissubrepo:   contextmenu = self.subrepocontextmenu   actionlist = ['opensubrepo', 'explore', 'terminal']   else:   contextmenu = self.filecontextmenu   actionlist = ['diff', 'ldiff', 'edit', 'ledit', 'revert',   'navigate', 'diffnavigate']     if not contextmenu:   contextmenu = QMenu(self)   for act in actionlist:   if act:   contextmenu.addAction(self._actions[act])   else:   contextmenu.addSeparator()     if itemissubrepo:   self.subrepocontextmenu = contextmenu   else:   self.filecontextmenu = contextmenu     if actionlist:   contextmenu.exec_(point)     @property   def toolbar(self):   """Return toolbar for manifest widget"""   return self._toolbar     @pyqtSlot(unicode, bool, bool, bool)   def find(self, pattern, icase=False, wrap=False, forward=True):   return self._fileview.find(pattern, icase, wrap, forward)     @pyqtSlot(unicode, bool)   def highlightText(self, pattern, icase=False):   self._fileview.highlightText(pattern, icase)     def _setupmodel(self):   self._treemodel = ManifestModel(self._repo, self._rev,   statusfilter=self._statusfilter.status(),   parent=self)   oldmodel = self._treeview.model()   oldselmodel = self._treeview.selectionModel()   self._treeview.setModel(self._treemodel)   if oldmodel:   oldmodel.deleteLater()   if oldselmodel:   oldselmodel.deleteLater()     selmodel = self._treeview.selectionModel()   selmodel.currentChanged.connect(self._updatecontent)   selmodel.currentChanged.connect(self._emitPathChanged)     self._statusfilter.statusChanged.connect(self._treemodel.setStatusFilter)   self._statusfilter.statusChanged.connect(self._autoexpandtree)   self._autoexpandtree()     @pyqtSlot()   def _autoexpandtree(self):   """expand file tree if the number of the items isn't large"""   if 'C' not in self._statusfilter.status():   self._treeview.expandAll()     def reload(self):   # TODO   pass     def setRepo(self, repo):   self._repo = repo   #self._fileview.setRepo(repo)   self._fileview.repo = repo   if len(repo) <= self._rev:   self._rev = len(repo)-1   self._setupmodel()     @property   def rev(self):   """Return current revision"""   return self._rev     def selectRev(self, rev):   """   Select the revision that must be set when the dialog is shown again   """   self._selectedrev = rev     @pyqtSlot(int)   @pyqtSlot(object)   def setRev(self, rev):   """Change revision to show"""   self._selectedrev = rev   if rev == self._rev:   return   self._rev = rev   path = self.path   self._setupmodel()   ctx = self._repo[rev]   if path and path in ctx:   # recover file selection after reloading the model   self.setPath(path)   self._fileview.setContext(ctx)   self._fileview.displayFile(self.path, self.status)   # update sensitivity of actions   real = type(rev) is int   self._actions['ldiff'].setEnabled(real)   for act in ['diff', 'edit']:   self._actions[act].setEnabled(real or rev is None)   self._actions['revert'].setEnabled(real)     @pyqtSlot(unicode, object)   @pyqtSlot(unicode, object, int)   def setSource(self, path, rev, line=None):   """Change path and revision to show at once"""   if self._rev != rev:   self._rev = rev   self._setupmodel()   self.revChanged.emit(rev)   if path != self.path:   self.setPath(path)   ctx = self._repo[rev]   if self.path in ctx:   self._fileview.displayFile(path, self.status)   if line:   self._fileview.showLine(int(line) - 1)   else:   self._fileview.clearDisplay()     @property   def path(self):   """Return currently selected path"""   return self._treemodel.filePath(self._treeview.currentIndex())     @property   def status(self):   """Return currently selected path"""   return self._treemodel.fileStatus(self._treeview.currentIndex())     @pyqtSlot(unicode)   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):   self.pathChanged.emit(self.path)    def connectsearchbar(manifestwidget, searchbar):   """Connect searchbar to manifest widget"""   searchbar.conditionChanged.connect(manifestwidget.highlightText)   searchbar.searchRequested.connect(manifestwidget.find)    def _openineditor(repo, path, rev, line=None, pattern=None, parent=None):   """Open editor to show the specified file [unicode]"""   path = hglib.fromunicode(path)   pattern = hglib.fromunicode(pattern)   base = visdiff.snapshot(repo, [path], repo[rev])[0]   files = [os.path.join(base, path)]   qtlib.editfiles(repo, files, line, pattern, parent=self)      def run(ui, *pats, **opts):   repo = opts.get('repo') or thgrepo.repository(ui, paths.find_root())   dlg = ManifestDialog(repo, opts.get('rev'))     # set initial state after dialog visible   def init():   try:   if pats:   path = hglib.canonpaths(pats)[0]   elif 'canonpath' in opts:   path = opts['canonpath']   else:   return   line = opts.get('line') and int(opts['line']) or None   dlg.setSource(path, opts.get('rev'), line)   if opts.get('pattern'):   dlg.setSearchPattern(opts['pattern'])   if dlg._manifest_widget._fileview.actionAnnMode.isEnabled():   dlg._manifest_widget._fileview.actionAnnMode.trigger()   except IndexError:   pass   dlg.setSearchPattern(hglib.tounicode(opts.get('pattern')) or '')   QTimer.singleShot(0, init)     return dlg
 
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()