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