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

reporegistry: improvements to subrepo support

The addRepo local function was moved from the repoitem.undump method into the
repo tree model class. Also, the warning message that is shown when some subrepo
or repo cannot be accessed has been improved.

Changeset 0dbd5cfd9c54

Parent a588ed5b336c

by Angel Ezquerra

Changes to 2 files · Browse files at 0dbd5cfd9c54 Showing diff from parent a588ed5b336c Diff from another changeset...

 
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
 
278
279
280
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
281
282
283
 
215
216
217
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
218
219
220
 
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
@@ -215,61 +215,6 @@
  self._basenode = node.bin(str(a.value('', 'basenode').toString()))   RepoTreeItem.undump(self, xr)   - 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)   @@ -278,6 +223,44 @@
  return self   return None   + def appendSubrepos(self, repo=None): + invalidRepoList = [] + try: + sri = None + if repo is None: + repo = hg.repository(ui.ui(), self._root) + wctx = repo['.'] + for subpath in wctx.substate: + sri = None + abssubpath = repo.wjoin(subpath) + subtype = wctx.substate[subpath][2] + sriIsValid = os.path.isdir(abssubpath) + sri = SubrepoItem(self.model, abssubpath, subtype=subtype) + sri._valid = False + self.appendChild(sri) + + if not sriIsValid: + self._valid = False + sri._valid = False + invalidRepoList.append(repo.wjoin(subpath)) + return invalidRepoList + continue + + if subtype == 'hg': + # Only recurse into mercurial subrepos + sctx = wctx.sub(subpath) + invalidRepoList += \ + sri.appendSubrepos(sctx._repo) + except (EnvironmentError, error.RepoError, util.Abort), e: + # Add the repo to the list of repos/subrepos + # that could not be open + self._valid = False + if sri: + sri._valid = False + invalidRepoList.append(abssubpath) + invalidRepoList.append(self._root) + + return invalidRepoList    def _overlaidicon(base, overlay):   """Generate overlaid icon"""
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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
 # repotreemodel.py - model 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.    from mercurial import ui, hg, util, error    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    from PyQt4.QtCore import *  from PyQt4.QtGui import *      extractXmlElementName = 'reporegextract'  reporegistryXmlElementName = 'reporegistry'    repoRegMimeType = 'application/thg-reporegistry'  repoRegGroupMimeType = 'application/thg-reporegistrygroup'  repoExternalMimeType = 'text/uri-list'      def writeXml(target, item, rootElementName):   xw = QXmlStreamWriter(target)   xw.setAutoFormatting(True)   xw.setAutoFormattingIndent(2)   xw.writeStartDocument()   xw.writeStartElement(rootElementName)   item.dumpObject(xw)   xw.writeEndElement()   xw.writeEndDocument()    def readXml(source, rootElementName, model):   itemread = None   xr = QXmlStreamReader(source)   if xr.readNextStartElement():   ele = str(xr.name().toString())   if ele != rootElementName:   print "unexpected xml element '%s' "\   "(was looking for %s)" % (ele, rootElementName)   return   if xr.hasError():   print str(xr.errorString())   if xr.readNextStartElement():   itemread = undumpObject(xr, model)   xr.skipCurrentElement()   if xr.hasError():   print str(xr.errorString())   return itemread    def iterRepoItemFromXml(source, model=None):   xr = QXmlStreamReader(source)   while not xr.atEnd():   t = xr.readNext()   if t == QXmlStreamReader.StartElement and xr.name() == 'repo':   yield undumpObject(xr, model)   +def getRepoItemList(root): + repoItemList = [] + if not isinstance(root, RepoTreeItem): + return repoItemList + for c in root.childs: + if isinstance(c, RepoItem): + repoItemList.append(c) + else: + repoItemList += getRepoItemList(c) + return repoItemList + +  class RepoTreeModel(QAbstractItemModel):     def __init__(self, filename, parent, showSubrepos=True,   showNetworkSubrepos=True):   QAbstractItemModel.__init__(self, parent)     self.showSubrepos = showSubrepos   self.showNetworkSubrepos = showNetworkSubrepos     root = None   all = None     if filename:   f = QFile(filename)   if f.open(QIODevice.ReadOnly):   root = readXml(f, reporegistryXmlElementName, self)   f.close()   if root:   for c in root.childs:   if isinstance(c, AllRepoGroupItem):   all = c   break   + if self.showSubrepos: + self.loadSubrepos(root) +   if not root:   root = RepoTreeItem(self)   all = AllRepoGroupItem(self)   root.appendChild(all)     self.rootItem = root   self.allrepos = all     # see http://doc.qt.nokia.com/4.6/model-view-model-subclassing.html     # overrides from QAbstractItemModel     def index(self, row, column, parent):   if not self.hasIndex(row, column, parent):   return QModelIndex()   if (not parent.isValid()):   parentItem = self.rootItem   else:   parentItem = parent.internalPointer()   childItem = parentItem.child(row)   if childItem:   return self.createIndex(row, column, childItem)   else:   return QModelIndex()     def parent(self, index):   if not index.isValid():   return QModelIndex()   childItem = index.internalPointer()   parentItem = childItem.parent()   if parentItem is self.rootItem:   return QModelIndex()   return self.createIndex(parentItem.row(), 0, parentItem)     def rowCount(self, parent):   if parent.column() > 0:   return 0   if not parent.isValid():   parentItem = self.rootItem;   else:   parentItem = parent.internalPointer()   return parentItem.childCount()     def columnCount(self, parent):   if parent.isValid():   return parent.internalPointer().columnCount()   else:   return self.rootItem.columnCount()     def data(self, index, role):   if not index.isValid():   return QVariant()   if role not in (Qt.DisplayRole, Qt.EditRole, Qt.DecorationRole):   return QVariant()   item = index.internalPointer()   return item.data(index.column(), role)     def headerData(self, section, orientation, role):   if role == Qt.DisplayRole:   if orientation == Qt.Horizontal:   if section == 1:   return QString(_('Path'))   return QVariant()     def flags(self, index):   if not index.isValid():   return Qt.NoItemFlags   item = index.internalPointer()   return item.flags()     def supportedDropActions(self):   return Qt.CopyAction | Qt.MoveAction | Qt.LinkAction     def removeRows(self, row, count, parent):   item = parent.internalPointer()   if item is None:   item = self.rootItem   self.beginRemoveRows(parent, row, row+count-1)   res = item.removeRows(row, count)   self.endRemoveRows()   return res     def mimeTypes(self):   return QStringList([repoRegMimeType, repoRegGroupMimeType,   repoExternalMimeType])     def mimeData(self, indexes):   i = indexes[0]   item = i.internalPointer()   buf = QByteArray()   writeXml(buf, item, extractXmlElementName)   d = QMimeData()   if isinstance(item, RepoItem):   d.setData(repoRegMimeType, buf)   d.setUrls([QUrl.fromLocalFile(hglib.tounicode(item.rootpath()))])   else:   d.setData(repoRegGroupMimeType, buf)   d.setText(QString(item.name))   return d     def dropMimeData(self, data, action, row, column, parent):   group = parent.internalPointer()   if data.hasUrls():   d = str(data.data(repoRegMimeType))   else:   row = parent.row()   group = self.rootItem   parent = QModelIndex()   d = str(data.data(repoRegGroupMimeType))   itemread = readXml(d, extractXmlElementName, self)   if itemread is None:   return False   if group is None:   return False   if row < 0:   row = 0   self.beginInsertRows(parent, row, row)   group.insertChild(row, itemread)   self.endInsertRows()   return True     def setData(self, index, value, role):   if not index.isValid() or role != Qt.EditRole:   return False   s = value.toString()   if s.isEmpty():   return False   item = index.internalPointer()   if item.setData(index.column(), value):   self.dataChanged.emit(index, index)   return True   return False     # functions not defined in QAbstractItemModel     def allreposIndex(self):   return self.createIndex(0, 0, self.allrepos)     def addRepo(self, group, root, row=-1):   grp = group   if grp == None:   grp = self.allreposIndex()   rgi = grp.internalPointer()   if row < 0:   row = rgi.childCount()   self.beginInsertRows(grp, row, row) - rgi.insertChild(row, RepoItem(self, root)) + ri = RepoItem(self, root) + rgi.insertChild(row, ri)     if not self.showSubrepos \   or (not self.showNetworkSubrepos and paths.netdrive_status(root)):   self.endInsertRows()   return   - 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.insertChild(row, - SubrepoItem(self, 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 - - try: - repo = hg.repository(ui.ui(), root) - invalidRepoList = \ - addSubrepos(rgi.child(rgi.childCount()-1), repo) - except (EnvironmentError, error.RepoError, util.Abort), e: - # TODO: Mark the repo with a "warning" icon or similar to indicate - # that the repository cannot be open - invalidRepoList = [root] + invalidRepoList = ri.appendSubrepos()     self.endInsertRows()     if invalidRepoList:   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>') % + _('It was not possible to fully load the subrepository ' + 'list for the repository in:<br><br><i>%s</i><br><br>' + 'The following subrepositories may be missing, broken or ' + 'on an inconsistent state and cannot be accessed:' + '<br><br><i>%s</i>') %   (root, "<br>".join(invalidRepoList)))     def getRepoItem(self, reporoot):   return self.rootItem.getRepoItem(reporoot)     def addGroup(self, name):   ri = self.rootItem   cc = ri.childCount()   self.beginInsertRows(QModelIndex(), cc, cc + 1)   ri.appendChild(RepoGroupItem(self, name, ri))   self.endInsertRows()     def write(self, fn):   f = QFile(fn)   f.open(QIODevice.WriteOnly)   writeXml(f, self.rootItem, reporegistryXmlElementName)   f.close()     def depth(self, index):   count = 1   while True:   index = index.parent()   if index.row() < 0:   return count   count += 1 + + def loadSubrepos(self, root): + globalInvalidRepoList = [] + globalInvalidSubrepoList = [] + warningmsg = '' + for c in getRepoItemList(root): + if self.showNetworkSubrepos \ + or not paths.netdrive_status(c.rootpath()): + + invalidRepoList = c.appendSubrepos() + + if invalidRepoList: + # The top repo or some of its subrepos could not be loaded + warningmsg += "<li>" + c.rootpath() + if invalidRepoList[0] == c.rootpath(): + invalidRepoList = invalidRepoList[1:] + if invalidRepoList: + warningmsg += "<ul><li>" + warningmsg += "<li>".join(invalidRepoList) + warningmsg += "</ul>" + + # If some repos or subrepos could not be loaded, show a warning message + if False: + warningmsg = '' + if globalInvalidRepoList: + warningmsg = _('Some repos could not be fully loaded:') + warningmsg += "<ul><li>" + warningmsg += "<li>".join(globalInvalidRepoList) + warningmsg += "</ul><br>" + + if globalInvalidSubrepoList: + if warningmsg: + warningmsg += "<br>" + warningmsg = _('Some subrepos could not be loaded:') + warningmsg += "<br>" + warningmsg += "<br>".join(globalInvalidSubrepoList) + + if warningmsg: + warningmsg = _('Some repos could not be fully loaded:') + \ + "<ul>" + warningmsg + '</ul>' + QTimer.singleShot(0, \ + lambda: qtlib.WarningMsgBox( + _('Missing or invalid repos or subrepos ' + 'on the repository registry'), + warningmsg))