1
# Copyright (C) 2006 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
17
This is an attempt to take the internal delta object, and represent
18
it as a single-file text-only changeset.
19
This should have commands for both generating a changeset,
20
and for applying a changeset.
24
from cStringIO import StringIO
26
from bzrlib.lazy_import import lazy_import
27
lazy_import(globals(), """
32
revision as _mod_revision,
38
from bzrlib.commands import Command
39
from bzrlib.option import Option
40
from bzrlib.trace import note
43
class cmd_bundle_info(Command):
44
"""Output interesting stats about a bundle"""
47
takes_args = ['location']
49
encoding_type = 'exact'
51
def run(self, location, verbose=False):
52
from bzrlib.bundle.serializer import read_bundle
53
from bzrlib.bundle import read_mergeable_from_url
54
from bzrlib import osutils
55
term_encoding = osutils.get_terminal_encoding()
56
bundle_info = read_mergeable_from_url(location)
57
if isinstance(bundle_info, merge_directive._BaseMergeDirective):
58
bundle_info = read_bundle(StringIO(bundle_info.get_raw_bundle()))
59
reader_method = getattr(bundle_info, 'get_bundle_reader', None)
60
if reader_method is None:
61
raise errors.BzrCommandError('Bundle format not supported')
65
for bytes, parents, repo_kind, revision_id, file_id\
66
in reader_method().iter_records():
67
by_kind.setdefault(repo_kind, []).append(
68
(bytes, parents, repo_kind, revision_id, file_id))
69
if file_id is not None:
71
print >> self.outf, 'Records'
72
for kind, records in sorted(by_kind.iteritems()):
73
multiparent = sum(1 for b, p, k, r, f in records if len(p) > 1)
74
print >> self.outf, '%s: %d (%d multiparent)' % \
75
(kind, len(records), multiparent)
76
print >> self.outf, 'unique files: %d' % len(file_ids)
80
for revision in bundle_info.real_revisions:
81
if 'branch-nick' in revision.properties:
82
nicks.add(revision.properties['branch-nick'])
83
committers.add(revision.committer)
85
print >> self.outf, 'Revisions'
86
print >> self.outf, ('nicks: %s'
87
% ', '.join(sorted(nicks))).encode(term_encoding, 'replace')
88
print >> self.outf, ('committers: \n%s' %
89
'\n'.join(sorted(committers)).encode(term_encoding, 'replace'))
93
line = bundle_file.readline()
94
line = bundle_file.readline()
95
content = bundle_file.read().decode('bz2')
96
print >> self.outf, "Decoded contents"
97
self.outf.write(content)