6
6
__copyright__ = "Copyright � 2005 Canonical Ltd."
7
__author__ = "Gary van der Merwe <garyvdm@gmail.com>"
7
__author__ = "Gary van der Merwe <garyvdm@gmail.com>"
10
from gi.repository import Gtk
11
from gi.repository import GObject
14
12
from xml.sax.saxutils import escape
14
from bzrlib.config import parse_username
15
15
from bzrlib.revision import NULL_REVISION
17
from time import (strftime, localtime)
33
class TreeModel(gtk.GenericTreeModel):
36
def __init__ (self, branch, line_graph_data):
37
gtk.GenericTreeModel.__init__(self)
40
self.repository = branch.repository
41
self.line_graph_data = line_graph_data
43
if self.branch.supports_tags():
38
class BranchTreeModel(Gtk.TreeStore):
39
"""A model of branch's merge history."""
41
def __init__(self, branch, line_graph_data):
42
super(BranchTreeModel, self).__init__(
44
GObject.TYPE_PYOBJECT,
45
GObject.TYPE_PYOBJECT,
46
GObject.TYPE_PYOBJECT,
52
GObject.TYPE_PYOBJECT,
53
GObject.TYPE_PYOBJECT,
54
GObject.TYPE_PYOBJECT,
55
GObject.TYPE_PYOBJECT,
59
self.repository = branch.repository
60
if self.branch.supports_tags():
61
self.tags = self.branch.tags.get_reverse_tag_dict()
64
self.set_line_graph_data(line_graph_data)
66
def add_tag(self, tag, revid):
67
self.branch.tags.set_tag(tag, revid)
69
self.tags[revid].append(tag)
71
self.tags[revid] = [tag]
73
def set_line_graph_data(self, line_graph_data):
75
self.line_graph_data = line_graph_data
76
# (None, (0, 0), (), (), (), ())
77
for rowref, data in enumerate(self.line_graph_data):
78
revid, node, lines, parents, children, revno_sequence = data
80
last_lines = self.line_graph_data[rowref - 1][2]
83
revno = ".".join(["%d" % (revno) for revno in revno_sequence])
84
tags = self.tags.get(revid, [])
85
if not revid or revid == NULL_REVISION:
87
elif revid not in self.revisions:
88
revision = self.repository.get_revisions([revid])[0]
89
self.revisions[revid] = revision
91
revision = self.revisions[revid]
93
summary = message = committer = timestamp = authors = None
95
summary = escape(revision.get_summary())
96
message = escape(revision.message)
97
committer = parse_username(revision.committer)[0]
99
"%Y-%m-%d %H:%M", localtime(revision.timestamp))
100
authors = ", ".join([
101
parse_username(author)[0]
102
for author in revision.get_apparent_authors()])
105
(revid, node, lines, last_lines, revno, summary, message,
106
committer, timestamp, revision, parents, children, tags,
110
class TreeModel(Gtk.TreeStore):
112
def __init__(self, branch, line_graph_data):
113
Gtk.TreeStore.__init__(self)
116
self.repository = branch.repository
117
self.line_graph_data = line_graph_data
119
if self.branch.supports_tags():
44
120
self.tags = self.branch.tags.get_reverse_tag_dict()
53
129
self.tags[revid] = [tag]
55
131
def on_get_flags(self):
56
return gtk.TREE_MODEL_LIST_ONLY
132
return Gtk.TREE_MODEL_LIST_ONLY
58
134
def on_get_n_columns(self):
61
137
def on_get_column_type(self, index):
62
if index == REVID: return gobject.TYPE_STRING
63
if index == NODE: return gobject.TYPE_PYOBJECT
64
if index == LINES: return gobject.TYPE_PYOBJECT
65
if index == LAST_LINES: return gobject.TYPE_PYOBJECT
66
if index == REVNO: return gobject.TYPE_STRING
67
if index == SUMMARY: return gobject.TYPE_STRING
68
if index == MESSAGE: return gobject.TYPE_STRING
69
if index == COMMITTER: return gobject.TYPE_STRING
70
if index == TIMESTAMP: return gobject.TYPE_STRING
71
if index == REVISION: return gobject.TYPE_PYOBJECT
72
if index == PARENTS: return gobject.TYPE_PYOBJECT
73
if index == CHILDREN: return gobject.TYPE_PYOBJECT
74
if index == TAGS: return gobject.TYPE_PYOBJECT
138
if index == REVID: return GObject.TYPE_STRING
139
if index == NODE: return GObject.TYPE_PYOBJECT
140
if index == LINES: return GObject.TYPE_PYOBJECT
141
if index == LAST_LINES: return GObject.TYPE_PYOBJECT
142
if index == REVNO: return GObject.TYPE_STRING
143
if index == SUMMARY: return GObject.TYPE_STRING
144
if index == MESSAGE: return GObject.TYPE_STRING
145
if index == COMMITTER: return GObject.TYPE_STRING
146
if index == TIMESTAMP: return GObject.TYPE_STRING
147
if index == REVISION: return GObject.TYPE_PYOBJECT
148
if index == PARENTS: return GObject.TYPE_PYOBJECT
149
if index == CHILDREN: return GObject.TYPE_PYOBJECT
150
if index == TAGS: return GObject.TYPE_PYOBJECT
151
if index == AUTHORS: return GObject.TYPE_STRING
76
153
def on_get_iter(self, path):
154
# XXX sinzui 2011-08-12: maybe path.get_indices()[0]?
79
157
def on_get_path(self, rowref):
82
160
def on_get_value(self, rowref, column):
83
161
if len(self.line_graph_data) > 0:
84
162
(revid, node, lines, parents,
108
186
self.revisions[revid] = revision
110
188
revision = self.revisions[revid]
112
190
if column == REVISION: return revision
113
191
if column == SUMMARY: return escape(revision.get_summary())
114
192
if column == MESSAGE: return escape(revision.message)
115
if column == COMMITTER: return re.sub('<.*@.*>', '',
116
revision.committer).strip(' ')
117
if column == TIMESTAMP:
193
if column == COMMITTER: return parse_username(revision.committer)[0]
194
if column == TIMESTAMP:
118
195
return strftime("%Y-%m-%d %H:%M", localtime(revision.timestamp))
196
if column == AUTHORS:
198
parse_username(author)[0] for author in revision.get_apparent_authors()])
120
200
def on_iter_next(self, rowref):
121
201
if rowref < len(self.line_graph_data) - 1:
125
205
def on_iter_children(self, parent):
126
206
if parent is None: return 0
129
209
def on_iter_has_child(self, rowref):
132
212
def on_iter_n_children(self, rowref):
133
213
if rowref is None: return len(self.line_graph_data)
136
216
def on_iter_nth_child(self, parent, n):
137
217
if parent is None: return n
140
220
def on_iter_parent(self, child):