1
# Copyright (C) 2005-2010 Canonical Ltd
1
# Copyright (C) 2005-2011 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
"""Commands for generating snapshot information about a bzr tree."""
17
"""Commands for generating snapshot information about a brz tree."""
19
from bzrlib.lazy_import import lazy_import
19
from .lazy_import import lazy_import
21
21
lazy_import(globals(), """
26
24
version_info_formats,
27
from breezy.i18n import gettext
31
from bzrlib.commands import Command
32
from bzrlib.option import Option, RegistryOption
33
from .commands import Command
34
from .option import Option, RegistryOption
35
37
def _parse_version_info_format(format):
42
44
return version_info_formats.get_builder(format)
44
46
formats = version_info_formats.get_builder_formats()
45
raise errors.BzrCommandError('No known version info format %s.'
46
' Supported types are: %s'
47
raise errors.CommandError(
48
gettext('No known version info format {0}.'
49
' Supported types are: {1}').format(format, formats))
50
52
class cmd_version_info(Command):
74
76
takes_options = [RegistryOption('format',
75
'Select the output format.',
77
lazy_registry=('bzrlib.version_info_formats',
77
'Select the output format.',
79
lazy_registry=('breezy.version_info_formats',
79
81
Option('all', help='Include all possible information.'),
80
82
Option('check-clean', help='Check if tree is clean.'),
81
83
Option('include-history',
82
84
help='Include the revision-history.'),
83
85
Option('include-file-revisions',
84
86
help='Include the last revision for each file.'),
85
Option('template', type=str, help='Template for the output.'),
87
Option('template', type=str,
88
help='Template for the output.'),
87
91
takes_args = ['location?']
89
encoding_type = 'exact'
93
encoding_type = 'replace'
91
95
def run(self, location=None, format=None,
92
96
all=False, check_clean=False, include_history=False,
93
include_file_revisions=False, template=None):
97
include_file_revisions=False, template=None,
100
if revision and len(revision) > 1:
101
raise errors.CommandError(
102
gettext('brz version-info --revision takes exactly'
103
' one revision specifier'))
95
105
if location is None:
98
108
if format is None:
99
109
format = version_info_formats.format_registry.get()
103
112
wt = workingtree.WorkingTree.open_containing(location)[0]
104
113
except errors.NoWorkingTree:
105
114
b = branch.Branch.open(location)
110
120
include_history = True
111
121
check_clean = True
112
include_file_revisions=True
122
include_file_revisions = True
124
include_history = True
125
include_file_revisions = True
126
if '{clean}' in template:
129
if revision is not None:
130
revision_id = revision[0].as_revision_id(b)
114
134
builder = format(b, working_tree=wt,
115
check_for_clean=check_clean,
116
include_revision_history=include_history,
117
include_file_revisions=include_file_revisions,
119
builder.generate(ui.ui_factory.make_output_stream())
135
check_for_clean=check_clean,
136
include_revision_history=include_history,
137
include_file_revisions=include_file_revisions,
138
template=template, revision_id=revision_id)
139
builder.generate(self.outf)