~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
    )
6150.3.3 by Jonathan Riddell
gettext() bzrlib/bundle
35
from bzrlib.i18n import gettext
1996.3.8 by John Arbash Meinel
lazy_import bundle and bundle.commands
36
""")
37
38
from bzrlib.commands import Command
1185.82.78 by Aaron Bentley
Cleanups
39
0.5.1 by John Arbash Meinel
Just an initial working step.
40
2520.4.35 by Aaron Bentley
zap obsolete changeset commands, add bundle-info command
41
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
42
    __doc__ = """Output interesting stats about a bundle"""
2520.4.35 by Aaron Bentley
zap obsolete changeset commands, add bundle-info command
43
44
    hidden = True
45
    takes_args = ['location']
1551.18.4 by Aaron Bentley
Restore bundle-info -v, fix multiparent detection
46
    takes_options = ['verbose']
2520.4.44 by Aaron Bentley
Fix encoding handling in bundle-info
47
    encoding_type = 'exact'
2520.4.35 by Aaron Bentley
zap obsolete changeset commands, add bundle-info command
48
49
    def run(self, location, verbose=False):
50
        from bzrlib.bundle.serializer import read_bundle
2520.5.4 by Aaron Bentley
Replace 'bundle-revisions' with 'submit' command
51
        from bzrlib.bundle import read_mergeable_from_url
2520.4.44 by Aaron Bentley
Fix encoding handling in bundle-info
52
        from bzrlib import osutils
53
        term_encoding = osutils.get_terminal_encoding()
2520.5.4 by Aaron Bentley
Replace 'bundle-revisions' with 'submit' command
54
        bundle_info = read_mergeable_from_url(location)
5086.3.1 by Jelmer Vernooij
``bzrlib.merge_directive._BaseMergeDirective`` has been renamed to
55
        if isinstance(bundle_info, merge_directive.BaseMergeDirective):
1551.18.4 by Aaron Bentley
Restore bundle-info -v, fix multiparent detection
56
            bundle_file = StringIO(bundle_info.get_raw_bundle())
57
            bundle_info = read_bundle(bundle_file)
58
        else:
59
            if verbose:
6150.3.3 by Jonathan Riddell
gettext() bzrlib/bundle
60
                raise errors.BzrCommandError(gettext(
61
                            '--verbose requires a merge directive'))
2520.4.35 by Aaron Bentley
zap obsolete changeset commands, add bundle-info command
62
        reader_method = getattr(bundle_info, 'get_bundle_reader', None)
63
        if reader_method is None:
6150.3.3 by Jonathan Riddell
gettext() bzrlib/bundle
64
            raise errors.BzrCommandError(gettext('Bundle format not supported'))
2520.4.35 by Aaron Bentley
zap obsolete changeset commands, add bundle-info command
65
66
        by_kind = {}
67
        file_ids = set()
68
        for bytes, parents, repo_kind, revision_id, file_id\
69
            in reader_method().iter_records():
70
            by_kind.setdefault(repo_kind, []).append(
71
                (bytes, parents, repo_kind, revision_id, file_id))
72
            if file_id is not None:
73
                file_ids.add(file_id)
6150.3.3 by Jonathan Riddell
gettext() bzrlib/bundle
74
        self.outf.write(gettext('Records\n'))
2520.4.35 by Aaron Bentley
zap obsolete changeset commands, add bundle-info command
75
        for kind, records in sorted(by_kind.iteritems()):
1551.18.4 by Aaron Bentley
Restore bundle-info -v, fix multiparent detection
76
            multiparent = sum(1 for b, m, k, r, f in records if
77
                              len(m.get('parents', [])) > 1)
6150.3.3 by Jonathan Riddell
gettext() bzrlib/bundle
78
            self.outf.write(gettext('{0}: {1} ({2} multiparent)\n').format(
6150.3.11 by Jonathan Riddell
syntax fixes
79
                kind, len(records), multiparent))
6150.3.3 by Jonathan Riddell
gettext() bzrlib/bundle
80
        self.outf.write(gettext('unique files: %d\n') % len(file_ids))
2911.6.1 by Blake Winton
Change 'print >> f,'s to 'f.write('s.
81
        self.outf.write('\n')
2520.4.35 by Aaron Bentley
zap obsolete changeset commands, add bundle-info command
82
        nicks = set()
83
        committers = set()
84
        for revision in bundle_info.real_revisions:
2520.4.42 by Aaron Bentley
Don't assume every revision has a branch nick
85
            if 'branch-nick' in revision.properties:
86
                nicks.add(revision.properties['branch-nick'])
2520.4.35 by Aaron Bentley
zap obsolete changeset commands, add bundle-info command
87
            committers.add(revision.committer)
88
6150.3.3 by Jonathan Riddell
gettext() bzrlib/bundle
89
        self.outf.write(gettext('Revisions\n'))
90
        self.outf.write((gettext('nicks: %s\n')
2911.6.1 by Blake Winton
Change 'print >> f,'s to 'f.write('s.
91
            % ', '.join(sorted(nicks))).encode(term_encoding, 'replace'))
6150.3.3 by Jonathan Riddell
gettext() bzrlib/bundle
92
        self.outf.write((gettext('committers: \n%s\n') %
2911.6.1 by Blake Winton
Change 'print >> f,'s to 'f.write('s.
93
        '\n'.join(sorted(committers)).encode(term_encoding, 'replace')))
2520.4.35 by Aaron Bentley
zap obsolete changeset commands, add bundle-info command
94
        if verbose:
2911.6.1 by Blake Winton
Change 'print >> f,'s to 'f.write('s.
95
            self.outf.write('\n')
2520.4.35 by Aaron Bentley
zap obsolete changeset commands, add bundle-info command
96
            bundle_file.seek(0)
2520.4.74 by Aaron Bentley
bzr info handles patchless bundles
97
            line = bundle_file.readline()
98
            line = bundle_file.readline()
2520.4.76 by Aaron Bentley
Move base64-encoding into merge directives
99
            content = bundle_file.read().decode('bz2')
6150.3.3 by Jonathan Riddell
gettext() bzrlib/bundle
100
            self.outf.write(gettext("Decoded contents\n"))
2520.4.35 by Aaron Bentley
zap obsolete changeset commands, add bundle-info command
101
            self.outf.write(content)
2911.6.1 by Blake Winton
Change 'print >> f,'s to 'f.write('s.
102
            self.outf.write('\n')