~qbzr-dev/qbzr/show-merge-depth

« back to all changes in this revision

Viewing changes to lib/logmodel.py

  • Committer: Gary van der Merwe
  • Date: 2009-08-19 12:41:14 UTC
  • mfrom: (677.1.243 trunk)
  • Revision ID: garyvdm@gmail.com-20090819124114-jz8zf4o4dlcl0a4r
Merge Trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 
23
23
from bzrlib import lazy_regex
24
24
from bzrlib.revision import NULL_REVISION, CURRENT_REVISION
 
25
 
 
26
from bzrlib.plugins.qbzr.lib.bugs import get_bug_id
25
27
from bzrlib.plugins.qbzr.lib.loggraphprovider import LogGraphProvider
26
28
from bzrlib.plugins.qbzr.lib.lazycachedrevloader import cached_revisions
27
29
from bzrlib.plugins.qbzr.lib.revtreeview import RevIdRole as im_RevIdRole
49
51
 COL_MERGE_DEPTH,
50
52
) = range(5)
51
53
 
52
 
_bug_id_re = lazy_regex.lazy_compile(r'(?:'
53
 
    r'bugs/'                    # Launchpad bugs URL
54
 
    r'|ticket/'                 # Trac bugs URL
55
 
    r'|show_bug\.cgi\?id='      # Bugzilla bugs URL
56
 
    r'|issues/show/'            # Redmine bugs URL
57
 
    r'|DispForm.aspx\?ID='      # Microsoft SharePoint URL
58
 
    r'|default.asp\?'           # Fogbugz URL
59
 
    r'|issue'                   # Roundup issue tracker URL
60
 
    r'|view.php\?id='           # Mantis bug tracker URL
61
 
    r')(\d+)(?:\b|$)')
62
 
 
63
 
 
64
 
def get_bug_id(bug_url):
65
 
    match = _bug_id_re.search(bug_url)
66
 
    if match:
67
 
        return match.group(1)
68
 
    return None
69
54
 
70
55
try:
71
56
    QVariant_fromList = QtCore.QVariant.fromList
136
121
        self.graph_provider.compute_graph_lines()
137
122
        self.emit(QtCore.SIGNAL("dataChanged(QModelIndex, QModelIndex)"),
138
123
                  self.createIndex (0, COL_MESSAGE, QtCore.QModelIndex()),
139
 
                  self.createIndex (len(self.graph_provider.merge_sorted_revisions),
 
124
                  self.createIndex (len(self.graph_provider.revisions),
140
125
                                    COL_MESSAGE, QtCore.QModelIndex()))
 
126
        self.emit(QtCore.SIGNAL("linesUpdated()"))
141
127
    
142
128
    def colapse_expand_rev(self, revid, visible):
143
 
        self.clicked_row = self.graph_provider.revid_msri[revid]
 
129
        self.clicked_row = self.graph_provider.revid_rev[revid].index
144
130
        clicked_row_index = self.createIndex (self.clicked_row,
145
131
                                              COL_MESSAGE,
146
132
                                              QtCore.QModelIndex())
178
164
    def rowCount(self, parent):
179
165
        if parent.isValid():
180
166
            return 0
181
 
        return len(self.graph_provider.merge_sorted_revisions)
 
167
        return len(self.graph_provider.revisions)
182
168
    
183
169
    def data(self, index, role):
184
170
        if not index.isValid():
185
171
            return QtCore.QVariant()
186
172
        
187
 
        if index.row() in self.graph_provider.msri_index \
188
 
                and len(self.graph_provider.graph_line_data)> \
189
 
                self.graph_provider.msri_index[index.row()]:
190
 
            (msri,
191
 
             node,
192
 
             lines,
193
 
             twisty_state,
194
 
             twisty_branch_ids) = self.graph_provider.graph_line_data\
195
 
                                  [self.graph_provider.msri_index[index.row()]]
196
 
        else:
197
 
            (msri,
198
 
             node,
199
 
             lines,
200
 
             twisty_state,
201
 
             twisty_branch_ids) = (index.row(), None, [], None, [])
 
173
        
 
174
        gp = self.graph_provider
 
175
        if self.last_rev_is_placeholder and \
 
176
                index.row() == len(gp.revisions) - 1:
 
177
            if role == GraphNodeRole:
 
178
                return QVariant_fromList([QtCore.QVariant(-1),
 
179
                                          QtCore.QVariant(0)])
 
180
            return QtCore.QVariant()
 
181
        
 
182
        rev_info = gp.revisions[index.row()]
202
183
        
203
184
        if role == GraphLinesRole:
204
185
            qlines = []
205
 
            for start, end, color, direct in lines:
 
186
            for start, end, color, direct in rev_info.lines:
206
187
                qlines.append(QVariant_fromList(
207
188
                    [QtCore.QVariant(start),
208
189
                     QtCore.QVariant(end),
211
192
            return QVariant_fromList(qlines)
212
193
        
213
194
        if self.last_rev_is_placeholder and \
214
 
                msri == len(self.graph_provider.merge_sorted_revisions) - 1:
 
195
                rev_info.index == len(self.graph_provider.revisions) - 1:
215
196
            if role == GraphNodeRole:
216
197
                return QVariant_fromList([QtCore.QVariant(-1), QtCore.QVariant(0)])
217
198
            if role == QtCore.Qt.DisplayRole:
219
200
            return QtCore.QVariant()
220
201
 
221
202
        if role == GraphNodeRole:
222
 
            if node is None:
 
203
            if rev_info.col_index is None:
223
204
                return QtCore.QVariant()
224
 
            return QVariant_fromList([QtCore.QVariant(nodei) for nodei in node])
 
205
            return QVariant_fromList([QtCore.QVariant(rev_info.col_index),
 
206
                                      QtCore.QVariant(rev_info.color)])
225
207
        
226
208
        if role == GraphTwistyStateRole:
227
 
            if twisty_state is None:
 
209
            if rev_info.twisty_state is None:
228
210
                return QtCore.QVariant()
229
211
            if index.row() == self.clicked_row:
230
212
                return QtCore.QVariant(-1)
231
 
            return QtCore.QVariant(twisty_state)
232
 
        
233
 
        (sequence_number, revid, merge_depth, revno_sequence, end_of_merge) = \
234
 
            self.graph_provider.merge_sorted_revisions[index.row()]
 
213
            return QtCore.QVariant(rev_info.twisty_state)
235
214
        
236
215
        if (role == QtCore.Qt.DisplayRole and index.column() == COL_REV) :
237
 
            revnos = ".".join(["%d" % (revno)
238
 
                                      for revno in revno_sequence])
239
 
            if revid == CURRENT_REVISION:
240
 
                revnos += " ?"
241
 
            return QtCore.QVariant(revnos)
 
216
            return QtCore.QVariant(rev_info.revno_str)
242
217
        
243
218
        if (role == QtCore.Qt.DisplayRole and index.column() == COL_MERGE_DEPTH) :
244
 
            return QtCore.QVariant("%d" % merge_depth)
 
219
            return QtCore.QVariant("%d" % rev_info.merge_depth)
245
220
        
246
221
        if role == TagsRole:
247
222
            tags = []
248
 
            if revid in self.graph_provider.tags:
249
 
                tags = list(self.graph_provider.tags[revid])
 
223
            if rev_info.revid in gp.tags:
 
224
                tags = list(gp.tags[rev_info.revid])
250
225
            return QtCore.QVariant(QtCore.QStringList(tags))
251
226
        
252
227
        if role == BranchTagsRole:
253
228
            tags = []
254
 
            if revid in self.graph_provider.branch_tags:
 
229
            if rev_info.revid in gp.branch_tags:
255
230
                tags = [tag for tag \
256
 
                        in self.graph_provider.branch_tags[revid] if tag]
 
231
                        in gp.branch_tags[rev_info.revid] if tag]
257
232
            return QtCore.QVariant(QtCore.QStringList(tags))
258
233
        
259
234
        if role == RevIdRole:
260
 
            return QtCore.QVariant(revid)
 
235
            return QtCore.QVariant(rev_info.revid)
261
236
        
262
237
        #Everything from here foward will need to have the revision loaded.
263
 
        if not revid or revid not in cached_revisions:
 
238
        if rev_info.revid not in cached_revisions:
264
239
            if role == QtCore.Qt.DisplayRole:
265
240
                return QtCore.QVariant("")
266
241
            return QtCore.QVariant()
267
242
        
268
 
        revision = cached_revisions[revid]
 
243
        revision = cached_revisions[rev_info.revid]
269
244
        
270
245
        if role == QtCore.Qt.DisplayRole and index.column() == COL_DATE:
271
246
            return QtCore.QVariant(strftime("%Y-%m-%d %H:%M",
279
254
            bugs = []
280
255
            for bug in revision.properties.get('bugs', '').split('\n'):
281
256
                if bug:
282
 
                    url, space, status = bug.partition(' ')
 
257
                    url = bug.split(' ', 1)[0]
283
258
                    bug_id = get_bug_id(url)
284
259
                    if bug_id:
285
260
                        bugs.append(bugtext % bug_id)
302
277
    
303
278
 
304
279
    def indexFromRevId(self, revid, columns=None):
305
 
        msri = self.graph_provider.revid_msri[revid]
 
280
        rev = self.graph_provider.revid_rev[revid]
306
281
        if columns:
307
 
            return [self.index (msri, column, QtCore.QModelIndex())\
 
282
            return [self.index (rev.index, column, QtCore.QModelIndex())\
308
283
                    for column in columns]
309
 
        return self.index (msri, 0, QtCore.QModelIndex())
 
284
        return self.index (rev.index, 0, QtCore.QModelIndex())
310
285
 
311
286
    def on_revisions_loaded(self, revisions, last_call):
312
287
        for revid in revisions.iterkeys():