~bzr-pqm/bzr/bzr.dev

5752.3.8 by John Arbash Meinel
Merge bzr.dev 5764 to resolve release-notes (aka NEWS) conflicts
1
# Copyright (C) 2005-2011 Canonical Ltd
2052.3.1 by John Arbash Meinel
Add tests to cleanup the copyright of all source files
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.5.1 by John Arbash Meinel
Just an initial working step.
16
"""\
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.
21
"""
22
2520.5.4 by Aaron Bentley
Replace 'bundle-revisions' with 'submit' command
23
from cStringIO import StringIO
1185.82.78 by Aaron Bentley
Cleanups
24
1996.3.8 by John Arbash Meinel
lazy_import bundle and bundle.commands
25
from bzrlib.lazy_import import lazy_import
26
lazy_import(globals(), """
27
from bzrlib import (
28
    branch,
29
    errors,
2520.5.4 by Aaron Bentley
Replace 'bundle-revisions' with 'submit' command
30
    merge_directive,
2490.2.28 by Aaron Bentley
Fix handling of null revision
31
    revision as _mod_revision,
1996.3.8 by John Arbash Meinel
lazy_import bundle and bundle.commands
32
    urlutils,
2520.4.35 by Aaron Bentley
zap obsolete changeset commands, add bundle-info command
33
    transport,
1996.3.8 by John Arbash Meinel
lazy_import bundle and bundle.commands
34
    )
35
""")
36
37
from bzrlib.commands import Command
1185.82.78 by Aaron Bentley
Cleanups
38
0.5.1 by John Arbash Meinel
Just an initial working step.
39
2520.4.35 by Aaron Bentley
zap obsolete changeset commands, add bundle-info command
40
class cmd_bundle_info(Command):
5131.2.1 by Martin
Permit bzrlib to run under python -OO by explictly assigning to __doc__ for user-visible docstrings
41
    __doc__ = """Output interesting stats about a bundle"""
2520.4.35 by Aaron Bentley
zap obsolete changeset commands, add bundle-info command
42
43
    hidden = True
44
    takes_args = ['location']
1551.18.4 by Aaron Bentley
Restore bundle-info -v, fix multiparent detection
45
    takes_options = ['verbose']
2520.4.44 by Aaron Bentley
Fix encoding handling in bundle-info
46
    encoding_type = 'exact'
2520.4.35 by Aaron Bentley
zap obsolete changeset commands, add bundle-info command
47
48
    def run(self, location, verbose=False):
49
        from bzrlib.bundle.serializer import read_bundle
2520.5.4 by Aaron Bentley
Replace 'bundle-revisions' with 'submit' command
50
        from bzrlib.bundle import read_mergeable_from_url
2520.4.44 by Aaron Bentley
Fix encoding handling in bundle-info
51
        from bzrlib import osutils
52
        term_encoding = osutils.get_terminal_encoding()
2520.5.4 by Aaron Bentley
Replace 'bundle-revisions' with 'submit' command
53
        bundle_info = read_mergeable_from_url(location)
5086.3.1 by Jelmer Vernooij
``bzrlib.merge_directive._BaseMergeDirective`` has been renamed to
54
        if isinstance(bundle_info, merge_directive.BaseMergeDirective):
1551.18.4 by Aaron Bentley
Restore bundle-info -v, fix multiparent detection
55
            bundle_file = StringIO(bundle_info.get_raw_bundle())
56
            bundle_info = read_bundle(bundle_file)
57
        else:
58
            if verbose:
3221.1.6 by Martin Pool
Better error message from bundle-info
59
                raise errors.BzrCommandError('--verbose requires a merge'
60
                    ' directive')
2520.4.35 by Aaron Bentley
zap obsolete changeset commands, add bundle-info command
61
        reader_method = getattr(bundle_info, 'get_bundle_reader', None)
62
        if reader_method is None:
63
            raise errors.BzrCommandError('Bundle format not supported')
64
65
        by_kind = {}
66
        file_ids = set()
67
        for bytes, parents, repo_kind, revision_id, file_id\
68
            in reader_method().iter_records():
69
            by_kind.setdefault(repo_kind, []).append(
70
                (bytes, parents, repo_kind, revision_id, file_id))
71
            if file_id is not None:
72
                file_ids.add(file_id)
2911.6.1 by Blake Winton
Change 'print >> f,'s to 'f.write('s.
73
        self.outf.write('Records\n')
2520.4.35 by Aaron Bentley
zap obsolete changeset commands, add bundle-info command
74
        for kind, records in sorted(by_kind.iteritems()):
1551.18.4 by Aaron Bentley
Restore bundle-info -v, fix multiparent detection
75
            multiparent = sum(1 for b, m, k, r, f in records if
76
                              len(m.get('parents', [])) > 1)
2911.6.1 by Blake Winton
Change 'print >> f,'s to 'f.write('s.
77
            self.outf.write('%s: %d (%d multiparent)\n' % \
78
                (kind, len(records), multiparent))
79
        self.outf.write('unique files: %d\n' % len(file_ids))
80
        self.outf.write('\n')
2520.4.35 by Aaron Bentley
zap obsolete changeset commands, add bundle-info command
81
        nicks = set()
82
        committers = set()
83
        for revision in bundle_info.real_revisions:
2520.4.42 by Aaron Bentley
Don't assume every revision has a branch nick
84
            if 'branch-nick' in revision.properties:
85
                nicks.add(revision.properties['branch-nick'])
2520.4.35 by Aaron Bentley
zap obsolete changeset commands, add bundle-info command
86
            committers.add(revision.committer)
87
2911.6.1 by Blake Winton
Change 'print >> f,'s to 'f.write('s.
88
        self.outf.write('Revisions\n')
89
        self.outf.write(('nicks: %s\n'
90
            % ', '.join(sorted(nicks))).encode(term_encoding, 'replace'))
91
        self.outf.write(('committers: \n%s\n' %
92
        '\n'.join(sorted(committers)).encode(term_encoding, 'replace')))
2520.4.35 by Aaron Bentley
zap obsolete changeset commands, add bundle-info command
93
        if verbose:
2911.6.1 by Blake Winton
Change 'print >> f,'s to 'f.write('s.
94
            self.outf.write('\n')
2520.4.35 by Aaron Bentley
zap obsolete changeset commands, add bundle-info command
95
            bundle_file.seek(0)
2520.4.74 by Aaron Bentley
bzr info handles patchless bundles
96
            line = bundle_file.readline()
97
            line = bundle_file.readline()
2520.4.76 by Aaron Bentley
Move base64-encoding into merge directives
98
            content = bundle_file.read().decode('bz2')
2911.6.1 by Blake Winton
Change 'print >> f,'s to 'f.write('s.
99
            self.outf.write("Decoded contents\n")
2520.4.35 by Aaron Bentley
zap obsolete changeset commands, add bundle-info command
100
            self.outf.write(content)
2911.6.1 by Blake Winton
Change 'print >> f,'s to 'f.write('s.
101
            self.outf.write('\n')