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
|
# -*- coding: UTF-8 -*-
"""Tree model.
"""
__copyright__ = "Copyright © 2005 Canonical Ltd."
__author__ = "Gary van der Merwe <garyvdm@gmail.com>"
import gtk
import gobject
import re
from xml.sax.saxutils import escape
from bzrlib.config import parse_username
from bzrlib.revision import NULL_REVISION
from time import (strftime, localtime)
REVID = 0
NODE = 1
LINES = 2
LAST_LINES = 3
REVNO = 4
SUMMARY = 5
MESSAGE = 6
COMMITTER = 7
TIMESTAMP = 8
REVISION = 9
PARENTS = 10
CHILDREN = 11
TAGS = 12
AUTHORS = 13
class TreeModel(gtk.GenericTreeModel):
def __init__ (self, branch, line_graph_data):
gtk.GenericTreeModel.__init__(self)
self.revisions = {}
self.branch = branch
self.repository = branch.repository
self.line_graph_data = line_graph_data
if self.branch.supports_tags():
self.tags = self.branch.tags.get_reverse_tag_dict()
else:
self.tags = {}
def add_tag(self, tag, revid):
self.branch.tags.set_tag(tag, revid)
try:
self.tags[revid].append(tag)
except KeyError:
self.tags[revid] = [tag]
def on_get_flags(self):
return gtk.TREE_MODEL_LIST_ONLY
def on_get_n_columns(self):
return 14
def on_get_column_type(self, index):
if index == REVID: return gobject.TYPE_STRING
if index == NODE: return gobject.TYPE_PYOBJECT
if index == LINES: return gobject.TYPE_PYOBJECT
if index == LAST_LINES: return gobject.TYPE_PYOBJECT
if index == REVNO: return gobject.TYPE_STRING
if index == SUMMARY: return gobject.TYPE_STRING
if index == MESSAGE: return gobject.TYPE_STRING
if index == COMMITTER: return gobject.TYPE_STRING
if index == TIMESTAMP: return gobject.TYPE_STRING
if index == REVISION: return gobject.TYPE_PYOBJECT
if index == PARENTS: return gobject.TYPE_PYOBJECT
if index == CHILDREN: return gobject.TYPE_PYOBJECT
if index == TAGS: return gobject.TYPE_PYOBJECT
if index == AUTHORS: return gobject.TYPE_STRING
def on_get_iter(self, path):
return path[0]
def on_get_path(self, rowref):
return rowref
def on_get_value(self, rowref, column):
if len(self.line_graph_data) > 0:
(revid, node, lines, parents,
children, revno_sequence) = self.line_graph_data[rowref]
else:
(revid, node, lines, parents,
children, revno_sequence) = (None, (0, 0), (), (),
(), ())
if column == REVID: return revid
if column == NODE: return node
if column == LINES: return lines
if column == PARENTS: return parents
if column == CHILDREN: return children
if column == LAST_LINES:
if rowref>0:
return self.line_graph_data[rowref-1][2]
return []
if column == REVNO: return ".".join(["%d" % (revno)
for revno in revno_sequence])
if column == TAGS: return self.tags.get(revid, [])
if not revid or revid == NULL_REVISION:
return None
if revid not in self.revisions:
revision = self.repository.get_revisions([revid])[0]
self.revisions[revid] = revision
else:
revision = self.revisions[revid]
if column == REVISION: return revision
if column == SUMMARY: return escape(revision.get_summary())
if column == MESSAGE: return escape(revision.message)
if column == COMMITTER: return parse_username(revision.committer)[0]
if column == TIMESTAMP:
return strftime("%Y-%m-%d %H:%M", localtime(revision.timestamp))
if column == AUTHORS:
return ", ".join([
parse_username(author)[0] for author in revision.get_apparent_authors()])
def on_iter_next(self, rowref):
if rowref < len(self.line_graph_data) - 1:
return rowref+1
return None
def on_iter_children(self, parent):
if parent is None: return 0
return None
def on_iter_has_child(self, rowref):
return False
def on_iter_n_children(self, rowref):
if rowref is None: return len(self.line_graph_data)
return 0
def on_iter_nth_child(self, parent, n):
if parent is None: return n
return None
def on_iter_parent(self, child):
return None
|