/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz
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
# -*- coding: UTF-8 -*-
"""BranchTreeModel."""

__copyright__ = "Copyright © 2005 Canonical Ltd."
__author__ = "Gary van der Merwe <garyvdm@gmail.com>"


from gi.repository import Gtk
from gi.repository import GObject
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 BranchTreeModel(Gtk.ListStore):
    """A model of branch's merge history."""

    def __init__(self, branch, line_graph_data):
        super(BranchTreeModel, self).__init__(
            GObject.TYPE_STRING,
            GObject.TYPE_PYOBJECT,
            GObject.TYPE_PYOBJECT,
            GObject.TYPE_PYOBJECT,
            GObject.TYPE_STRING,
            GObject.TYPE_STRING,
            GObject.TYPE_STRING,
            GObject.TYPE_STRING,
            GObject.TYPE_STRING,
            GObject.TYPE_PYOBJECT,
            GObject.TYPE_PYOBJECT,
            GObject.TYPE_PYOBJECT,
            GObject.TYPE_PYOBJECT,
            GObject.TYPE_STRING)
        self.revisions = {}
        self.branch = branch
        self.repository = branch.repository
        if self.branch.supports_tags():
            self.tags = self.branch.tags.get_reverse_tag_dict()
        else:
            self.tags = {}
        self.set_line_graph_data(line_graph_data)

    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 _line_graph_item_to_model_row(self, rowref, data):
        revid, node, lines, parents, children, revno_sequence = data
        if rowref > 0:
            last_lines = self.line_graph_data[rowref - 1][2]
        else:
            last_lines = []
        revno = ".".join(["%d" % (revno) for revno in revno_sequence])
        tags = self.tags.get(revid, [])
        if not revid or revid == NULL_REVISION:
            revision = None
        elif revid not in self.revisions:
            revision = self.repository.get_revisions([revid])[0]
            self.revisions[revid] = revision
        else:
            revision = self.revisions[revid]
        if revision is None:
            summary = message = committer = timestamp = authors = None
        else:
            summary = escape(revision.get_summary())
            message = escape(revision.message)
            committer = parse_username(revision.committer)[0]
            timestamp = strftime(
                "%Y-%m-%d %H:%M", localtime(revision.timestamp))
            authors = ", ".join([
                parse_username(author)[0]
                for author in revision.get_apparent_authors()])
        return (revid, node, lines, last_lines, revno, summary, message,
                committer, timestamp, revision, parents, children, tags,
                authors)

    def set_line_graph_data(self, line_graph_data):
        self.clear()
        self.line_graph_data = line_graph_data
        for rowref, data in enumerate(self.line_graph_data):
            row = self._line_graph_item_to_model_row(rowref, data)
            self.append(row)