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

reporegistry: add "Show Subrepos for remote repositories" toggle to the View menu

I am not particularly pleased with the wording of the menu option. It is perhaps
a little bit too verbose.

Changeset 3be19a77f9f9

Parent e07940b1be60

by Angel Ezquerra

Changes to 4 files · Browse files at 3be19a77f9f9 Showing diff from parent e07940b1be60 Diff from another changeset...

 
180
181
182
183
 
184
185
186
 
 
187
188
189
 
197
198
199
200
 
 
201
202
203
 
215
216
217
 
 
 
 
218
219
220
221
 
222
223
224
 
180
181
182
 
183
184
185
186
187
188
189
190
191
 
199
200
201
 
202
203
204
205
206
 
218
219
220
221
222
223
224
225
226
227
 
228
229
230
231
@@ -180,10 +180,12 @@
  showMessage = pyqtSignal(QString)   openRepo = pyqtSignal(QString, bool)   - def __init__(self, parent, showSubrepos=True): + def __init__(self, parent, showSubrepos=True, showNetworkSubrepos=True):   QDockWidget.__init__(self, parent)     self.showSubrepos = showSubrepos + self.showNetworkSubrepos = showNetworkSubrepos +   self.setFeatures(QDockWidget.DockWidgetClosable |   QDockWidget.DockWidgetMovable |   QDockWidget.DockWidgetFloatable) @@ -197,7 +199,8 @@
  self.contextmenu = QMenu(self)   self.tview = tv = RepoTreeView(self)   tv.setModel(repotreemodel.RepoTreeModel(settingsfilename(), self, - showSubrepos=self.showSubrepos)) + showSubrepos=self.showSubrepos, + showNetworkSubrepos=self.showNetworkSubrepos))   mainframe.layout().addWidget(tv)     tv.setIndentation(10) @@ -215,10 +218,14 @@
  self.showSubrepos = show   self.reloadModel()   + def setShowNetworkSubrepos(self, show): + self.showNetworkSubrepos = show + self.reloadModel() +   def reloadModel(self):   self.tview.setModel(   repotreemodel.RepoTreeModel(settingsfilename(), self, - self.showSubrepos)) + self.showSubrepos, self.showNetworkSubrepos))   self.expand()     def expand(self):
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
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
 # repotreeitem.py - treeitems for the reporegistry  #  # Copyright 2010 Adrian Buehlmann <adrian@cadifra.com>  #  # This software may be used and distributed according to the terms of the  # GNU General Public License version 2 or any later version.    import sys, os    from mercurial import node  from mercurial import ui, hg, util, error   -from tortoisehg.util import hglib +from tortoisehg.util import hglib, paths  from tortoisehg.hgqt.i18n import _  from tortoisehg.hgqt import qtlib  from tortoisehg.hgqt import thgrepo    from PyQt4.QtCore import *  from PyQt4.QtGui import *      xmlClassMap = {   'allgroup': 'AllRepoGroupItem',   'group': 'RepoGroupItem',   'repo': 'RepoItem',   'subrepo': 'SubrepoItem',   'treeitem': 'RepoTreeItem',   }    inverseXmlClassMap = {}    def xmlToClass(ele):   return xmlClassMap[ele]    def classToXml(classname):   if len(inverseXmlClassMap) == 0:   for k,v in xmlClassMap.iteritems():   inverseXmlClassMap[v] = k   return inverseXmlClassMap[classname]    def undumpObject(xr, model):   classname = xmlToClass(str(xr.name().toString()))   class_ = getattr(sys.modules[RepoTreeItem.__module__], classname)   obj = class_(model)   obj.undump(xr)   return obj      class RepoTreeItem(object):   def __init__(self, model, parent=None):   self.model = model   self._parent = parent   self.childs = []   self._row = 0     def appendChild(self, child):   child._row = len(self.childs)   child._parent = self   self.childs.append(child)     def insertChild(self, row, child):   child._row = row   child._parent = self   self.childs.insert(row, child)     def child(self, row):   return self.childs[row]     def childCount(self):   return len(self.childs)     def columnCount(self):   return 2     def data(self, column, role):   return QVariant()     def setData(self, column, value):   return False     def row(self):   return self._row     def parent(self):   return self._parent     def menulist(self):   return []     def flags(self):   return Qt.NoItemFlags     def removeRows(self, row, count):   cs = self.childs   remove = cs[row : row + count]   keep = cs[:row] + cs[row + count:]   self.childs = keep   for c in remove:   c._row = 0   c._parent = None   for i, c in enumerate(keep):   c._row = i   return True     def dump(self, xw):   for c in self.childs:   c.dumpObject(xw)     def undump(self, xr):   while not xr.atEnd():   xr.readNext()   if xr.isStartElement():   item = undumpObject(xr, self.model)   self.appendChild(item)   elif xr.isEndElement():   break     def dumpObject(self, xw):   xw.writeStartElement(classToXml(self.__class__.__name__))   self.dump(xw)   xw.writeEndElement()     def isRepo(self):   return False     def details(self):   return ''     def getRepoItem(self, reporoot):   for c in self.childs:   ri = c.getRepoItem(reporoot)   if ri:   return ri   return None     def okToDelete(self):   return True      class RepoItem(RepoTreeItem):   def __init__(self, model, root=None, parent=None):   RepoTreeItem.__init__(self, model, parent)   self._root = root or ''   self._shortname = u''   self._basenode = node.nullid   self._repotype = 'hg'   # The _valid property is used to display a "warning" icon for repos   # that cannot be open   # If root is set we assume that the repo is valid (an actual validity   # test would require calling hg.repository() which is expensive)   # Regardless, self._valid may be set to False if self.undump() fails   if self._root:   self._valid = True   else:   self._valid = False     def isRepo(self):   return True   def rootpath(self):   return self._root     def shortname(self):   if self._shortname:   return self._shortname   else:   return hglib.tounicode(os.path.basename(self._root))     def repotype(self):   return self._repotype     def basenode(self):   """Return node id of revision 0"""   return self._basenode     def setBaseNode(self, basenode):   self._basenode = basenode     def setShortName(self, uname):   self._shortname = uname     def data(self, column, role):   if role == Qt.DecorationRole:   if column == 0:   ico = qtlib.geticon('hg')   if not self._valid:   ico = _overlaidicon(ico, qtlib.geticon('dialog-warning'))   return QVariant(ico)   return QVariant()   if column == 0:   return QVariant(self.shortname())   elif column == 1:   return QVariant(hglib.tounicode(self._root))   return QVariant()     def menulist(self):   return ['open', 'remove', 'clone', None, 'explore', 'terminal',   None, 'settings']     def flags(self):   return Qt.ItemIsEnabled | Qt.ItemIsSelectable | Qt.ItemIsDragEnabled     def removeRows(self, row, count):   return False     def dump(self, xw):   xw.writeAttribute('root', hglib.tounicode(self._root))   xw.writeAttribute('shortname', self.shortname())   xw.writeAttribute('basenode', node.hex(self.basenode()))     def undump(self, xr):   self._valid = True   a = xr.attributes()   self._root = hglib.fromunicode(a.value('', 'root').toString())   self._shortname = unicode(a.value('', 'shortname').toString())   self._basenode = node.bin(str(a.value('', 'basenode').toString()))   RepoTreeItem.undump(self, xr)   - if self.model and self.model.showSubrepos: + if self.model \ + and (self.model.showSubrepos \ + or (not self.model.showNetworkSubrepos + and paths.netdrive_status(self._root))):   def addSubrepos(ri, repo):   invalidRepoList = []   try:   wctx = repo['.']   for subpath in wctx.substate:   # For now we only support showing mercurial subrepos   subtype = wctx.substate[subpath][2]   sctx = wctx.sub(subpath)   ri.appendChild(   SubrepoItem(self.model, sctx._repo.root, subtype=subtype))   if subtype == 'hg':   # Only recurse into mercurial subrepos   if ri.childCount():   invalidRepoList += \   addSubrepos(   ri.child(ri.childCount()-1), sctx._repo)   except (EnvironmentError, error.RepoError, util.Abort), e:   # Add the repo to the list of repos/subrepos   # that could not be open   invalidRepoList.append(repo.root)     return invalidRepoList     root = self.rootpath()   try:   repo = hg.repository(ui.ui(), root)   except (EnvironmentError, error.RepoError, util.Abort), e:   # Do not try to show the list of subrepos when the top repository   # could not be open   # TODO: Mark the repo with a "warning" icon or similar to indicate   # that the repository cannot be open   self._valid = False   return     invalidRepoList = \   addSubrepos(self, repo)     if invalidRepoList:   self._valid = False   if invalidRepoList[0] == root:   qtlib.WarningMsgBox(_('Could not get subrepository list'),   _('It was not possible to get the subrepository list for '   'the repository in:<br><br><i>%s</i>') % root)   else:   qtlib.WarningMsgBox(_('Could not open some subrepositories'),   _('It was not possible to fully load the subrepository list '   'for the repository in:<br><br><i>%s</i><br><br>'   'The following subrepositories could not be accessed:'   '<br><br><i>%s</i>') %   (root, "<br>".join(invalidRepoList)))     def details(self):   return _('Local Repository %s') % hglib.tounicode(self._root)     def getRepoItem(self, reporoot):   if reporoot == self._root:   return self   return None      def _overlaidicon(base, overlay):   """Generate overlaid icon"""   # TODO: This was copied from manifestmodel.py   # TODO: generalize this function as a utility   pixmap = base.pixmap(16, 16)   painter = QPainter(pixmap)   painter.setCompositionMode(QPainter.CompositionMode_SourceOver)   painter.drawPixmap(0, 0, overlay.pixmap(16, 16))   del painter   return QIcon(pixmap)      class SubrepoItem(RepoItem):   _subrepoType2IcoMap = {   'hg': 'hg',   'git': 'thg-git-subrepo',   'svn': 'thg-svn-subrepo',   }     def __init__(self, model, repo=None, parent=None, parentrepo=None,   subtype='hg'):   RepoItem.__init__(self, model, repo, parent)   self._parentrepo = parentrepo   self._repotype = subtype   if self._repotype != 'hg':   # Make sure that we cannot drag non hg subrepos   # To do so we disable the dumpObject method for non hg subrepos   def doNothing(dummy):   pass   self.dumpObject = doNothing     # Limit the context menu to those actions that are valid for non   # mercurial subrepos   def nonHgMenulist():   return ['remove', None, 'explore', 'terminal']   self.menulist = nonHgMenulist     def data(self, column, role):   if role == Qt.DecorationRole:   if column == 0:   subiconame = SubrepoItem._subrepoType2IcoMap.get(self._repotype, None)   if subiconame is None:   # Unknown (or generic) subrepo type   ico = qtlib.geticon('thg-subrepo')   else:   # Overlay the "subrepo icon" on top of the selected subrepo   # type icon   ico = qtlib.geticon(subiconame)   ico = _overlaidicon(ico, qtlib.geticon('thg-subrepo'))   return QVariant(ico)   return QVariant()   else:   return super(SubrepoItem, self).data(column, role)      class RepoGroupItem(RepoTreeItem):   def __init__(self, model, name=None, parent=None):   RepoTreeItem.__init__(self, model, parent)   if name:   self.name = name   else:   self.name = QString()     def data(self, column, role):   if role == Qt.DecorationRole:   if column == 0:   s = QApplication.style()   ico = s.standardIcon(QStyle.SP_DirIcon)   return QVariant(ico)   return QVariant()   if column == 0:   return QVariant(self.name)   return QVariant()     def setData(self, column, value):   if column == 0:   self.name = value.toString()   return True   return False   def menulist(self):   return ['openAll', 'add', None, 'newGroup', None, 'rename', 'remove',   None, 'reloadRegistry']   def flags(self):   return (Qt.ItemIsEnabled | Qt.ItemIsSelectable | Qt.ItemIsDropEnabled   | Qt.ItemIsDragEnabled | Qt.ItemIsEditable)     def childRoots(self):   return [c._root for c in self.childs]     def dump(self, xw):   xw.writeAttribute('name', self.name)   RepoTreeItem.dump(self, xw)     def undump(self, xr):   a = xr.attributes()   self.name = a.value('', 'name').toString()   RepoTreeItem.undump(self, xr)     def okToDelete(self):   return False      class AllRepoGroupItem(RepoGroupItem):   def __init__(self, model, parent=None):   RepoTreeItem.__init__(self, model, parent)   self.name = _('default')   def menulist(self):   return ['openAll', 'add', None, 'newGroup', None, 'rename',   None, 'reloadRegistry']   def undump(self, xr):   a = xr.attributes()   name = a.value('', 'name').toString()   if name:   self.name = name   RepoTreeItem.undump(self, xr)
 
7
8
9
10
 
11
12
13
14
 
15
16
17
 
64
65
66
67
 
 
68
69
70
 
 
71
72
73
 
231
232
233
234
 
 
235
236
237
 
7
8
9
 
10
11
12
13
14
15
16
17
18
 
65
66
67
 
68
69
70
71
 
72
73
74
75
76
 
234
235
236
 
237
238
239
240
241
@@ -7,11 +7,12 @@
   from mercurial import ui, hg, util, error   -from tortoisehg.util import hglib +from tortoisehg.util import hglib, paths  from tortoisehg.hgqt.i18n import _  from tortoisehg.hgqt import qtlib  from tortoisehg.hgqt import thgrepo   +  from repotreeitem import undumpObject, AllRepoGroupItem, RepoGroupItem  from repotreeitem import RepoItem, SubrepoItem, RepoTreeItem   @@ -64,10 +65,12 @@
   class RepoTreeModel(QAbstractItemModel):   - def __init__(self, filename, parent, showSubrepos=True): + def __init__(self, filename, parent, showSubrepos=True, + showNetworkSubrepos=True):   QAbstractItemModel.__init__(self, parent)   - self.showSubrepos=showSubrepos + self.showSubrepos = showSubrepos + self.showNetworkSubrepos = showNetworkSubrepos     root = None   all = None @@ -231,7 +234,8 @@
  self.beginInsertRows(grp, row, row)   rgi.insertChild(row, RepoItem(self, root))   - if not self.showSubrepos: + if not self.showSubrepos \ + or (not self.showNetworkSubrepos and paths.netdrive_status(root)):   self.endInsertRows()   return  
 
220
221
222
223
 
 
 
 
 
 
 
224
225
226
 
749
750
751
 
 
752
753
754
 
772
773
774
 
 
 
775
776
777
 
220
221
222
 
223
224
225
226
227
228
229
230
231
232
 
755
756
757
758
759
760
761
762
 
780
781
782
783
784
785
786
787
788
@@ -220,7 +220,13 @@
  checkable=True, menu='view')     self.actionShowSubrepos = \ - newaction(_("Show Subrepos on Registry"), self.reporegistry.setShowSubrepos, + newaction(_("Show Subrepos on Registry"), + self.reporegistry.setShowSubrepos, + checkable=True, menu='view') + + self.actionShowNetworkSubrepos = \ + newaction(_("Show Subrepos for remote repositories"), + self.reporegistry.setShowNetworkSubrepos,   checkable=True, menu='view')     a = self.log.toggleViewAction() @@ -749,6 +755,8 @@
  s.setValue(wb + 'windowState', self.saveState())   s.setValue(wb + 'showPaths', self.actionShowPaths.isChecked())   s.setValue(wb + 'showSubrepos', self.actionShowSubrepos.isChecked()) + s.setValue(wb + 'showNetworkSubrepos', + self.actionShowNetworkSubrepos.isChecked())   s.setValue(wb + 'saveRepos', self.actionSaveRepos.isChecked())   repostosave = []   if self.actionSaveRepos.isChecked(): @@ -772,6 +780,9 @@
  QTimer.singleShot(0, lambda: self.actionShowPaths.setChecked(sp))   ssr = s.value(wb + 'showSubrepos', defaultValue=QVariant(True)).toBool()   QTimer.singleShot(0, lambda: self.actionShowSubrepos.setChecked(ssr)) + snsr = s.value(wb + 'showNetworkSubrepos', + defaultValue=QVariant(True)).toBool() + QTimer.singleShot(0, lambda: self.actionShowNetworkSubrepos.setChecked(ssr))     def goto(self, root, rev):   for rw in self._findrepowidget(root):