/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz
256.2.29 by Gary van der Merwe
Implement a TreeModel that loads revisions incrementaly.
1
# -*- coding: UTF-8 -*-
734.1.43 by Curtis Hovey
Removed unused code.
2
"""BranchTreeModel."""
256.2.29 by Gary van der Merwe
Implement a TreeModel that loads revisions incrementaly.
3
4
__copyright__ = "Copyright © 2005 Canonical Ltd."
734.1.39 by Curtis Hovey
A quick spike to verify that subclassing TreeStore is easier than
5
__author__ = "Gary van der Merwe <garyvdm@gmail.com>"
256.2.29 by Gary van der Merwe
Implement a TreeModel that loads revisions incrementaly.
6
7
734.1.21 by Curtis Hovey
Replaced the missing GenericCellRenderer with CellRenderer.
8
from gi.repository import Gtk
9
from gi.repository import GObject
413 by Daniel Schierbeck
Made the treeview escape XML in the revision messages.
10
from xml.sax.saxutils import escape
713.1.1 by Jelmer Vernooij
'bzr viz' now shows authors instead of committers.
11
12
from bzrlib.config import parse_username
464.2.1 by Adrian Wilkins
Detect the reserved null: revision in appropriate places.
13
from bzrlib.revision import NULL_REVISION
256.2.29 by Gary van der Merwe
Implement a TreeModel that loads revisions incrementaly.
14
724 by Jelmer Vernooij
Fix formatting, imports.
15
from time import (
16
    strftime,
17
    localtime,
18
    )
256.2.29 by Gary van der Merwe
Implement a TreeModel that loads revisions incrementaly.
19
734.1.43 by Curtis Hovey
Removed unused code.
20
423.4.6 by Daniel Schierbeck
Removed unnecessary spaces.
21
REVID = 0
22
NODE = 1
23
LINES = 2
24
LAST_LINES = 3
25
REVNO = 4
26
SUMMARY = 5
27
MESSAGE = 6
28
COMMITTER = 7
29
TIMESTAMP = 8
30
REVISION = 9
423.4.5 by Daniel Schierbeck
Fixed indendation issues.
31
PARENTS = 10
32
CHILDREN = 11
423.5.10 by Daniel Schierbeck
Merged with trunk.
33
TAGS = 12
713 by Jelmer Vernooij
Remove some unused imports, fix some formatting.
34
AUTHORS = 13
256.2.29 by Gary van der Merwe
Implement a TreeModel that loads revisions incrementaly.
35
734.1.39 by Curtis Hovey
A quick spike to verify that subclassing TreeStore is easier than
36
734.1.43 by Curtis Hovey
Removed unused code.
37
class BranchTreeModel(Gtk.ListStore):
734.1.39 by Curtis Hovey
A quick spike to verify that subclassing TreeStore is easier than
38
    """A model of branch's merge history."""
39
40
    def __init__(self, branch, line_graph_data):
734.1.42 by Curtis Hovey
Small performance improvement.
41
        super(BranchTreeModel, self).__init__(
42
            GObject.TYPE_STRING,
43
            GObject.TYPE_PYOBJECT,
44
            GObject.TYPE_PYOBJECT,
45
            GObject.TYPE_PYOBJECT,
46
            GObject.TYPE_STRING,
47
            GObject.TYPE_STRING,
48
            GObject.TYPE_STRING,
49
            GObject.TYPE_STRING,
50
            GObject.TYPE_STRING,
51
            GObject.TYPE_PYOBJECT,
52
            GObject.TYPE_PYOBJECT,
53
            GObject.TYPE_PYOBJECT,
54
            GObject.TYPE_PYOBJECT,
55
            GObject.TYPE_STRING)
734.1.39 by Curtis Hovey
A quick spike to verify that subclassing TreeStore is easier than
56
        self.revisions = {}
57
        self.branch = branch
58
        self.repository = branch.repository
59
        if self.branch.supports_tags():
60
            self.tags = self.branch.tags.get_reverse_tag_dict()
61
        else:
62
            self.tags = {}
734.1.42 by Curtis Hovey
Small performance improvement.
63
        self.set_line_graph_data(line_graph_data)
734.1.39 by Curtis Hovey
A quick spike to verify that subclassing TreeStore is easier than
64
65
    def add_tag(self, tag, revid):
66
        self.branch.tags.set_tag(tag, revid)
67
        try:
68
            self.tags[revid].append(tag)
69
        except KeyError:
70
            self.tags[revid] = [tag]
71
72
    def set_line_graph_data(self, line_graph_data):
73
        self.clear()
74
        self.line_graph_data = line_graph_data
75
        # (None, (0, 0), (), (), (), ())
76
        for rowref, data in enumerate(self.line_graph_data):
77
            revid, node, lines, parents, children, revno_sequence = data
78
            if rowref > 0:
79
                last_lines = self.line_graph_data[rowref - 1][2]
80
            else:
81
                last_lines = []
82
            revno = ".".join(["%d" % (revno) for revno in revno_sequence])
83
            tags = self.tags.get(revid, [])
84
            if not revid or revid == NULL_REVISION:
85
                revision = None
86
            elif revid not in self.revisions:
87
                revision = self.repository.get_revisions([revid])[0]
88
                self.revisions[revid] = revision
89
            else:
90
                revision = self.revisions[revid]
91
            if revision is None:
92
                summary = message = committer = timestamp = authors = None
93
            else:
94
                summary = escape(revision.get_summary())
95
                message = escape(revision.message)
96
                committer = parse_username(revision.committer)[0]
97
                timestamp = strftime(
98
                    "%Y-%m-%d %H:%M", localtime(revision.timestamp))
99
                authors = ", ".join([
100
                    parse_username(author)[0]
101
                    for author in revision.get_apparent_authors()])
734.1.43 by Curtis Hovey
Removed unused code.
102
            self.append((
103
                revid, node, lines, last_lines, revno, summary, message,
734.1.39 by Curtis Hovey
A quick spike to verify that subclassing TreeStore is easier than
104
                committer, timestamp, revision, parents, children, tags,
105
                authors))