1
1
# -*- coding: UTF-8 -*-
4
6
__copyright__ = "Copyright � 2005 Canonical Ltd."
5
__author__ = "Gary van der Merwe <garyvdm@gmail.com>"
8
from gi.repository import Gtk
9
from gi.repository import GObject
10
from xml.sax.saxutils import escape
12
from bzrlib.config import parse_username
13
from bzrlib.revision import NULL_REVISION
7
__author__ = "Gary van der Merwe <garyvdm@gmail.com>"
15
from time import (strftime, localtime)
37
class BranchTreeModel(Gtk.ListStore):
38
"""A model of branch's merge history."""
40
def __init__(self, branch, line_graph_data):
41
super(BranchTreeModel, self).__init__(
43
GObject.TYPE_PYOBJECT,
44
GObject.TYPE_PYOBJECT,
45
GObject.TYPE_PYOBJECT,
51
GObject.TYPE_PYOBJECT,
52
GObject.TYPE_PYOBJECT,
53
GObject.TYPE_PYOBJECT,
54
GObject.TYPE_PYOBJECT,
29
class TreeModel(gtk.GenericTreeModel):
32
def __init__ (self, repository, line_graph_data):
33
gtk.GenericTreeModel.__init__(self)
56
34
self.revisions = {}
58
self.repository = branch.repository
59
if self.branch.supports_tags():
60
self.tags = self.branch.tags.get_reverse_tag_dict()
63
self.set_line_graph_data(line_graph_data)
65
def add_tag(self, tag, revid):
66
self.branch.tags.set_tag(tag, revid)
68
self.tags[revid].append(tag)
70
self.tags[revid] = [tag]
72
def _line_graph_item_to_model_row(self, rowref, data):
73
revid, node, lines, parents, children, revno_sequence = data
75
last_lines = self.line_graph_data[rowref - 1][2]
78
revno = ".".join(["%d" % (revno) for revno in revno_sequence])
79
tags = self.tags.get(revid, [])
80
if not revid or revid == NULL_REVISION:
82
elif revid not in self.revisions:
35
self.repository = repository
36
self.line_graph_data = line_graph_data
38
def on_get_flags(self):
39
return gtk.TREE_MODEL_LIST_ONLY
41
def on_get_n_columns(self):
44
def on_get_column_type(self, index):
45
if index == REVID: return gobject.TYPE_STRING
46
if index == NODE: return gobject.TYPE_PYOBJECT
47
if index == LINES: return gobject.TYPE_PYOBJECT
48
if index == LAST_LINES: return gobject.TYPE_PYOBJECT
49
if index == REVNO: return gobject.TYPE_STRING
50
if index == MESSAGE: return gobject.TYPE_STRING
51
if index == COMMITER: return gobject.TYPE_STRING
52
if index == TIMESTAMP: return gobject.TYPE_STRING
53
if index == REVISION: return gobject.TYPE_PYOBJECT
54
if index == PARENTS: return gobject.TYPE_PYOBJECT
55
if index == CHILDREN: return gobject.TYPE_PYOBJECT
57
def on_get_iter(self, path):
60
def on_get_path(self, rowref):
63
def on_get_value(self, rowref, column):
64
(revid, node, lines, parents,
65
children, revno_sequence) = self.line_graph_data[rowref]
66
if column == REVID: return revid
67
if column == NODE: return node
68
if column == LINES: return lines
69
if column == PARENTS: return parents
70
if column == CHILDREN: return children
71
if column == LAST_LINES:
73
return self.line_graph_data[rowref-1][2]
75
if column == REVNO: return ".".join(["%d" % (revno)
76
for revno in revno_sequence])
78
if revid not in self.revisions:
83
79
revision = self.repository.get_revisions([revid])[0]
84
80
self.revisions[revid] = revision
86
82
revision = self.revisions[revid]
88
summary = message = committer = timestamp = authors = None
90
summary = escape(revision.get_summary())
91
message = escape(revision.message)
92
committer = parse_username(revision.committer)[0]
94
"%Y-%m-%d %H:%M", localtime(revision.timestamp))
96
parse_username(author)[0]
97
for author in revision.get_apparent_authors()])
98
return (revid, node, lines, last_lines, revno, summary, message,
99
committer, timestamp, revision, parents, children, tags,
84
if column == REVISION: return revision
85
if column == MESSAGE: return revision.message.split("\n")[0]
86
if column == COMMITER: return re.sub('<.*@.*>', '',
87
revision.committer).strip(' ')
88
if column == TIMESTAMP:
89
return strftime("%Y-%m-%d %H:%M", localtime(revision.timestamp))
102
def set_line_graph_data(self, line_graph_data):
104
self.line_graph_data = line_graph_data
105
for rowref, data in enumerate(self.line_graph_data):
106
row = self._line_graph_item_to_model_row(rowref, data)
91
def on_iter_next(self, rowref):
92
if rowref < len(self.line_graph_data) - 1:
96
def on_iter_children(self, parent):
97
if parent is None: return 0
100
def on_iter_has_child(self, rowref):
103
def on_iter_n_children(self, rowref):
104
if rowref is None: return len(self.line_graph_data)
107
def on_iter_nth_child(self, parent, n):
108
if parent is None: return n
111
def on_iter_parent(self, child):