/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
4763.2.4 by John Arbash Meinel
merge bzr.2.1 in preparation for NEWS entry.
1
# Copyright (C) 2006, 2009, 2010 Canonical Ltd
0.8.21 by John Arbash Meinel
Splitting up the version info code into a lazy factory style.
2
#
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
0.8.21 by John Arbash Meinel
Splitting up the version info code into a lazy factory style.
16
17
"""A generator which creates a rio stanza of the current tree info"""
18
4216.4.1 by Jelmer Vernooij
Allow hooks to add new entries to version-info.
19
from bzrlib import hooks
4250.1.1 by Jelmer Vernooij
Fix version-info in empty branches.
20
from bzrlib.revision import (
21
    NULL_REVISION,
22
    )
2022.1.3 by John Arbash Meinel
Remove unused imports
23
from bzrlib.rio import RioWriter, Stanza
0.8.21 by John Arbash Meinel
Splitting up the version info code into a lazy factory style.
24
2022.1.1 by John Arbash Meinel
[merge] version-info plugin, and cleanup for layout in bzr
25
from bzrlib.version_info_formats import (
0.8.21 by John Arbash Meinel
Splitting up the version info code into a lazy factory style.
26
    create_date_str,
27
    VersionInfoBuilder,
28
    )
29
30
31
class RioVersionInfoBuilder(VersionInfoBuilder):
32
    """This writes a rio stream out."""
33
34
    def generate(self, to_file):
35
        info = Stanza()
36
        revision_id = self._get_revision_id()
4250.1.1 by Jelmer Vernooij
Fix version-info in empty branches.
37
        if revision_id != NULL_REVISION:
0.8.21 by John Arbash Meinel
Splitting up the version info code into a lazy factory style.
38
            info.add('revision-id', revision_id)
39
            rev = self._branch.repository.get_revision(revision_id)
40
            info.add('date', create_date_str(rev.timestamp, rev.timezone))
41
            revno = str(self._branch.revision_id_to_revno(revision_id))
4216.4.1 by Jelmer Vernooij
Allow hooks to add new entries to version-info.
42
            for hook in RioVersionInfoBuilder.hooks['revision']:
43
                hook(rev, info)
0.8.21 by John Arbash Meinel
Splitting up the version info code into a lazy factory style.
44
        else:
45
            revno = '0'
46
47
        info.add('build-date', create_date_str())
48
        info.add('revno', revno)
49
50
        if self._branch.nick is not None:
51
            info.add('branch-nick', self._branch.nick)
52
53
        if self._check or self._include_file_revs:
54
            self._extract_file_revisions()
55
56
        if self._check:
57
            if self._clean:
58
                info.add('clean', 'True')
59
            else:
60
                info.add('clean', 'False')
61
62
        if self._include_history:
63
            self._extract_revision_history()
64
            log = Stanza()
65
            for (revision_id, message,
66
                 timestamp, timezone) in self._revision_history_info:
67
                log.add('id', revision_id)
68
                log.add('message', message)
69
                log.add('date', create_date_str(timestamp, timezone))
2030.1.2 by John Arbash Meinel
Change the version-info --format=rio to support unicode messages
70
            info.add('revisions', log.to_unicode())
0.8.21 by John Arbash Meinel
Splitting up the version info code into a lazy factory style.
71
72
        if self._include_file_revs:
73
            files = Stanza()
74
            for path in sorted(self._file_revisions.keys()):
75
                files.add('path', path)
76
                files.add('revision', self._file_revisions[path])
2030.1.2 by John Arbash Meinel
Change the version-info --format=rio to support unicode messages
77
            info.add('file-revisions', files.to_unicode())
0.8.21 by John Arbash Meinel
Splitting up the version info code into a lazy factory style.
78
79
        writer = RioWriter(to_file=to_file)
80
        writer.write_stanza(info)
81
82
4216.4.1 by Jelmer Vernooij
Allow hooks to add new entries to version-info.
83
class RioVersionInfoBuilderHooks(hooks.Hooks):
84
    """Hooks for rio-formatted version-info output."""
85
86
    def __init__(self):
4781.1.1 by Vincent Ladeuil
Hooks daughter classes should always call the base constructor
87
        super(RioVersionInfoBuilderHooks, self).__init__()
4216.4.1 by Jelmer Vernooij
Allow hooks to add new entries to version-info.
88
        self.create_hook(hooks.HookPoint('revision',
4216.4.2 by Jelmer Vernooij
Register RioVersionInfoBuilderHooks in the hooks registry.
89
            "Invoked when adding information about a revision to the"
90
            " RIO stanza that is printed. revision is called with a"
4216.4.4 by Jelmer Vernooij
Set 'revision' hook as introduced in 1.15.
91
            " revision object and a RIO stanza.", (1, 15), None))
4216.4.1 by Jelmer Vernooij
Allow hooks to add new entries to version-info.
92
93
RioVersionInfoBuilder.hooks = RioVersionInfoBuilderHooks()