/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
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
6379.6.3 by Jelmer Vernooij
Use absolute_import.
16
0.5.1 by John Arbash Meinel
Just an initial working step.
17
"""\
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.
22
"""
23
6379.6.7 by Jelmer Vernooij
Move importing from future until after doc string, otherwise the doc string will disappear.
24
from __future__ import absolute_import
25
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
26
from ..lazy_import import lazy_import
1996.3.8 by John Arbash Meinel
lazy_import bundle and bundle.commands
27
lazy_import(globals(), """
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
28
from breezy import (
1996.3.8 by John Arbash Meinel
lazy_import bundle and bundle.commands
29
    branch,
30
    errors,
2520.5.4 by Aaron Bentley
Replace 'bundle-revisions' with 'submit' command
31
    merge_directive,
2490.2.28 by Aaron Bentley
Fix handling of null revision
32
    revision as _mod_revision,
1996.3.8 by John Arbash Meinel
lazy_import bundle and bundle.commands
33
    urlutils,
2520.4.35 by Aaron Bentley
zap obsolete changeset commands, add bundle-info command
34
    transport,
1996.3.8 by John Arbash Meinel
lazy_import bundle and bundle.commands
35
    )
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
36
from breezy.i18n import gettext
1996.3.8 by John Arbash Meinel
lazy_import bundle and bundle.commands
37
""")
38
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
39
from ..commands import Command
40
from ..sixish import (
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
41
    BytesIO,
42
    )
1185.82.78 by Aaron Bentley
Cleanups
43
0.5.1 by John Arbash Meinel
Just an initial working step.
44
2520.4.35 by Aaron Bentley
zap obsolete changeset commands, add bundle-info command
45
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
46
    __doc__ = """Output interesting stats about a bundle"""
2520.4.35 by Aaron Bentley
zap obsolete changeset commands, add bundle-info command
47
48
    hidden = True
49
    takes_args = ['location']
1551.18.4 by Aaron Bentley
Restore bundle-info -v, fix multiparent detection
50
    takes_options = ['verbose']
2520.4.44 by Aaron Bentley
Fix encoding handling in bundle-info
51
    encoding_type = 'exact'
2520.4.35 by Aaron Bentley
zap obsolete changeset commands, add bundle-info command
52
53
    def run(self, location, verbose=False):
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
54
        from breezy.bundle.serializer import read_bundle
55
        from breezy.bundle import read_mergeable_from_url
56
        from breezy import osutils
2520.4.44 by Aaron Bentley
Fix encoding handling in bundle-info
57
        term_encoding = osutils.get_terminal_encoding()
2520.5.4 by Aaron Bentley
Replace 'bundle-revisions' with 'submit' command
58
        bundle_info = read_mergeable_from_url(location)
5086.3.1 by Jelmer Vernooij
``bzrlib.merge_directive._BaseMergeDirective`` has been renamed to
59
        if isinstance(bundle_info, merge_directive.BaseMergeDirective):
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
60
            bundle_file = BytesIO(bundle_info.get_raw_bundle())
1551.18.4 by Aaron Bentley
Restore bundle-info -v, fix multiparent detection
61
            bundle_info = read_bundle(bundle_file)
62
        else:
63
            if verbose:
6150.3.3 by Jonathan Riddell
gettext() bzrlib/bundle
64
                raise errors.BzrCommandError(gettext(
65
                            '--verbose requires a merge directive'))
2520.4.35 by Aaron Bentley
zap obsolete changeset commands, add bundle-info command
66
        reader_method = getattr(bundle_info, 'get_bundle_reader', None)
67
        if reader_method is None:
6150.3.3 by Jonathan Riddell
gettext() bzrlib/bundle
68
            raise errors.BzrCommandError(gettext('Bundle format not supported'))
2520.4.35 by Aaron Bentley
zap obsolete changeset commands, add bundle-info command
69
70
        by_kind = {}
71
        file_ids = set()
72
        for bytes, parents, repo_kind, revision_id, file_id\
73
            in reader_method().iter_records():
74
            by_kind.setdefault(repo_kind, []).append(
75
                (bytes, parents, repo_kind, revision_id, file_id))
76
            if file_id is not None:
77
                file_ids.add(file_id)
6150.3.3 by Jonathan Riddell
gettext() bzrlib/bundle
78
        self.outf.write(gettext('Records\n'))
2520.4.35 by Aaron Bentley
zap obsolete changeset commands, add bundle-info command
79
        for kind, records in sorted(by_kind.iteritems()):
1551.18.4 by Aaron Bentley
Restore bundle-info -v, fix multiparent detection
80
            multiparent = sum(1 for b, m, k, r, f in records if
81
                              len(m.get('parents', [])) > 1)
6150.3.3 by Jonathan Riddell
gettext() bzrlib/bundle
82
            self.outf.write(gettext('{0}: {1} ({2} multiparent)\n').format(
6150.3.11 by Jonathan Riddell
syntax fixes
83
                kind, len(records), multiparent))
6150.3.3 by Jonathan Riddell
gettext() bzrlib/bundle
84
        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.
85
        self.outf.write('\n')
2520.4.35 by Aaron Bentley
zap obsolete changeset commands, add bundle-info command
86
        nicks = set()
87
        committers = set()
88
        for revision in bundle_info.real_revisions:
2520.4.42 by Aaron Bentley
Don't assume every revision has a branch nick
89
            if 'branch-nick' in revision.properties:
90
                nicks.add(revision.properties['branch-nick'])
2520.4.35 by Aaron Bentley
zap obsolete changeset commands, add bundle-info command
91
            committers.add(revision.committer)
92
6150.3.3 by Jonathan Riddell
gettext() bzrlib/bundle
93
        self.outf.write(gettext('Revisions\n'))
94
        self.outf.write((gettext('nicks: %s\n')
2911.6.1 by Blake Winton
Change 'print >> f,'s to 'f.write('s.
95
            % ', '.join(sorted(nicks))).encode(term_encoding, 'replace'))
6150.3.3 by Jonathan Riddell
gettext() bzrlib/bundle
96
        self.outf.write((gettext('committers: \n%s\n') %
2911.6.1 by Blake Winton
Change 'print >> f,'s to 'f.write('s.
97
        '\n'.join(sorted(committers)).encode(term_encoding, 'replace')))
2520.4.35 by Aaron Bentley
zap obsolete changeset commands, add bundle-info command
98
        if verbose:
2911.6.1 by Blake Winton
Change 'print >> f,'s to 'f.write('s.
99
            self.outf.write('\n')
2520.4.35 by Aaron Bentley
zap obsolete changeset commands, add bundle-info command
100
            bundle_file.seek(0)
2520.4.74 by Aaron Bentley
bzr info handles patchless bundles
101
            line = bundle_file.readline()
102
            line = bundle_file.readline()
2520.4.76 by Aaron Bentley
Move base64-encoding into merge directives
103
            content = bundle_file.read().decode('bz2')
6150.3.3 by Jonathan Riddell
gettext() bzrlib/bundle
104
            self.outf.write(gettext("Decoded contents\n"))
2520.4.35 by Aaron Bentley
zap obsolete changeset commands, add bundle-info command
105
            self.outf.write(content)
2911.6.1 by Blake Winton
Change 'print >> f,'s to 'f.write('s.
106
            self.outf.write('\n')