1
# Copyright (C) 2005-2011 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
This is an attempt to take the internal delta object, and represent
19
it as a single-file text-only changeset.
20
This should have commands for both generating a changeset,
21
and for applying a changeset.
24
from __future__ import absolute_import
26
from cStringIO import StringIO
28
from bzrlib.lazy_import import lazy_import
29
lazy_import(globals(), """
34
revision as _mod_revision,
38
from bzrlib.i18n import gettext
41
from bzrlib.commands import Command
44
class cmd_bundle_info(Command):
45
__doc__ = """Output interesting stats about a bundle"""
48
takes_args = ['location']
49
takes_options = ['verbose']
50
encoding_type = 'exact'
52
def run(self, location, verbose=False):
53
from bzrlib.bundle.serializer import read_bundle
54
from bzrlib.bundle import read_mergeable_from_url
55
from bzrlib import osutils
56
term_encoding = osutils.get_terminal_encoding()
57
bundle_info = read_mergeable_from_url(location)
58
if isinstance(bundle_info, merge_directive.BaseMergeDirective):
59
bundle_file = StringIO(bundle_info.get_raw_bundle())
60
bundle_info = read_bundle(bundle_file)
63
raise errors.BzrCommandError(gettext(
64
'--verbose requires a merge directive'))
65
reader_method = getattr(bundle_info, 'get_bundle_reader', None)
66
if reader_method is None:
67
raise errors.BzrCommandError(gettext('Bundle format not supported'))
71
for bytes, parents, repo_kind, revision_id, file_id\
72
in reader_method().iter_records():
73
by_kind.setdefault(repo_kind, []).append(
74
(bytes, parents, repo_kind, revision_id, file_id))
75
if file_id is not None:
77
self.outf.write(gettext('Records\n'))
78
for kind, records in sorted(by_kind.iteritems()):
79
multiparent = sum(1 for b, m, k, r, f in records if
80
len(m.get('parents', [])) > 1)
81
self.outf.write(gettext('{0}: {1} ({2} multiparent)\n').format(
82
kind, len(records), multiparent))
83
self.outf.write(gettext('unique files: %d\n') % len(file_ids))
87
for revision in bundle_info.real_revisions:
88
if 'branch-nick' in revision.properties:
89
nicks.add(revision.properties['branch-nick'])
90
committers.add(revision.committer)
92
self.outf.write(gettext('Revisions\n'))
93
self.outf.write((gettext('nicks: %s\n')
94
% ', '.join(sorted(nicks))).encode(term_encoding, 'replace'))
95
self.outf.write((gettext('committers: \n%s\n') %
96
'\n'.join(sorted(committers)).encode(term_encoding, 'replace')))
100
line = bundle_file.readline()
101
line = bundle_file.readline()
102
content = bundle_file.read().decode('bz2')
103
self.outf.write(gettext("Decoded contents\n"))
104
self.outf.write(content)
105
self.outf.write('\n')