1
# Copyright (C) 2005 Canonical Ltd
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.
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.
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
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
Routines for extracting all version information from a bzr branch.
24
from bzrlib.rio import RioReader, RioWriter, Stanza
25
from bzrlib.errors import NoWorkingTree
26
from errors import UncleanError
30
Raise an UncleanError if there is anything unclean about this
33
:param branch: The branch to check for changes
34
TODO: jam 20051228 This might be better to ask for a WorkingTree
38
new_tree = branch.working_tree()
40
# Trees without a working tree can't be dirty :)
43
# Look for unknown files in the new tree
44
for info in new_tree.list_files():
48
raise UncleanError(branch, 'path %s is unknown' % (path,))
50
from bzrlib.diff import compare_trees
51
# See if there is anything that has been changed
52
old_tree = branch.basis_tree()
53
delta = compare_trees(old_tree, new_tree, want_unchanged=False)
54
if len(delta.added) > 0:
55
raise UncleanError(branch, 'have added files: %r' % (delta.added,))
56
if len(delta.removed) > 0:
57
raise UncleanError(branch, 'have removed files: %r' % (delta.removed,))
58
if len(delta.modified) > 0:
59
raise UncleanError(branch, 'have modified files: %r' % (delta.modified,))
60
if len(delta.renamed) > 0:
61
raise UncleanError(branch, 'have renamed files: %r' % (delta.renamed,))
64
def generate_rio_version(branch, to_file=sys.stdout,
65
check_for_clean=False,
66
include_revision_history=False,
67
include_log_info=False,
68
include_log_deltas=False):
69
"""Create the version file for this project.
71
:param branch: The branch to write information about
72
:param to_file: The file to write the information
73
:param check_for_clean: If true, check if the branch is clean.
74
This can be expensive for large trees. This is also only
75
valid for branches with working trees.
76
:param include_revision_history: Write out the list of revisions
77
:param include_log_info: Include log information (log summary, etc),
78
only valid if include_revision_history is also True
79
:param include_log_deltas: Include information about what changed in
80
each revision. Only valid if include_log_info is also True
83
# TODO: jam 20051228 This might be better as the datestamp
85
info.add('date', time.strftime('%Y-%m-%d %H:%M:%S (%A, %B %d, %Y, %Z)'))
86
info.add('revno', branch.revno())
87
info.add('revision_id', branch.last_revision())
88
info.add('branch_nick', branch.nick)
91
wt = branch.working_tree()
96
info.update(_get_bzr_info(path=path, full=full))
97
if info['branch_nick'] is not None:
98
info['version'] = '%(branch_nick)s-%(revno)s' % info
99
elif info['revno'] is not None:
100
info['version'] = str(info['revno'])
102
info['version'] = 'unknown'
104
f = open(version_fn, 'wb')
105
f.write(_version_template % info)