/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/bundle/commands.py

  • Committer: Jelmer Vernooij
  • Date: 2019-02-04 01:01:24 UTC
  • mto: This revision was merged to the branch mainline in revision 7268.
  • Revision ID: jelmer@jelmer.uk-20190204010124-ni0i4qc6f5tnbvux
Fix source tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2010 Canonical Ltd
 
1
# Copyright (C) 2005-2011 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
16
 
16
17
"""\
17
18
This is an attempt to take the internal delta object, and represent
18
19
it as a single-file text-only changeset.
20
21
and for applying a changeset.
21
22
"""
22
23
 
23
 
import sys
24
 
from cStringIO import StringIO
 
24
from __future__ import absolute_import
25
25
 
26
 
from bzrlib.lazy_import import lazy_import
 
26
from ..lazy_import import lazy_import
27
27
lazy_import(globals(), """
28
 
from bzrlib import (
 
28
from breezy import (
29
29
    branch,
30
30
    errors,
31
31
    merge_directive,
33
33
    urlutils,
34
34
    transport,
35
35
    )
 
36
from breezy.i18n import gettext
36
37
""")
37
38
 
38
 
from bzrlib.commands import Command
39
 
from bzrlib.option import Option
40
 
from bzrlib.trace import note
 
39
from ..commands import Command
 
40
from ..sixish import (
 
41
    BytesIO,
 
42
    viewitems,
 
43
    )
41
44
 
42
45
 
43
46
class cmd_bundle_info(Command):
49
52
    encoding_type = 'exact'
50
53
 
51
54
    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
        from breezy.bundle.serializer import read_bundle
 
56
        from breezy.bundle import read_mergeable_from_url
 
57
        from breezy import osutils
55
58
        term_encoding = osutils.get_terminal_encoding()
56
59
        bundle_info = read_mergeable_from_url(location)
57
60
        if isinstance(bundle_info, merge_directive.BaseMergeDirective):
58
 
            bundle_file = StringIO(bundle_info.get_raw_bundle())
 
61
            bundle_file = BytesIO(bundle_info.get_raw_bundle())
59
62
            bundle_info = read_bundle(bundle_file)
60
63
        else:
61
64
            if verbose:
62
 
                raise errors.BzrCommandError('--verbose requires a merge'
63
 
                    ' directive')
 
65
                raise errors.BzrCommandError(gettext(
 
66
                    '--verbose requires a merge directive'))
64
67
        reader_method = getattr(bundle_info, 'get_bundle_reader', None)
65
68
        if reader_method is None:
66
 
            raise errors.BzrCommandError('Bundle format not supported')
 
69
            raise errors.BzrCommandError(
 
70
                gettext('Bundle format not supported'))
67
71
 
68
72
        by_kind = {}
69
73
        file_ids = set()
70
74
        for bytes, parents, repo_kind, revision_id, file_id\
71
 
            in reader_method().iter_records():
 
75
                in reader_method().iter_records():
72
76
            by_kind.setdefault(repo_kind, []).append(
73
77
                (bytes, parents, repo_kind, revision_id, file_id))
74
78
            if file_id is not None:
75
79
                file_ids.add(file_id)
76
 
        self.outf.write('Records\n')
77
 
        for kind, records in sorted(by_kind.iteritems()):
 
80
        self.outf.write(gettext('Records\n'))
 
81
        for kind, records in sorted(viewitems(by_kind)):
78
82
            multiparent = sum(1 for b, m, k, r, f in records if
79
83
                              len(m.get('parents', [])) > 1)
80
 
            self.outf.write('%s: %d (%d multiparent)\n' % \
81
 
                (kind, len(records), multiparent))
82
 
        self.outf.write('unique files: %d\n' % len(file_ids))
 
84
            self.outf.write(gettext('{0}: {1} ({2} multiparent)\n').format(
 
85
                kind, len(records), multiparent))
 
86
        self.outf.write(gettext('unique files: %d\n') % len(file_ids))
83
87
        self.outf.write('\n')
84
88
        nicks = set()
85
89
        committers = set()
88
92
                nicks.add(revision.properties['branch-nick'])
89
93
            committers.add(revision.committer)
90
94
 
91
 
        self.outf.write('Revisions\n')
92
 
        self.outf.write(('nicks: %s\n'
93
 
            % ', '.join(sorted(nicks))).encode(term_encoding, 'replace'))
94
 
        self.outf.write(('committers: \n%s\n' %
95
 
        '\n'.join(sorted(committers)).encode(term_encoding, 'replace')))
 
95
        self.outf.write(gettext('Revisions\n'))
 
96
        self.outf.write((gettext('nicks: %s\n')
 
97
                         % ', '.join(sorted(nicks))).encode(term_encoding, 'replace'))
 
98
        self.outf.write((gettext('committers: \n%s\n') %
 
99
                         '\n'.join(sorted(committers)).encode(term_encoding, 'replace')))
96
100
        if verbose:
97
101
            self.outf.write('\n')
98
102
            bundle_file.seek(0)
99
103
            line = bundle_file.readline()
100
104
            line = bundle_file.readline()
101
 
            content = bundle_file.read().decode('bz2')
102
 
            self.outf.write("Decoded contents\n")
 
105
            import bz2
 
106
            content = bz2.decompress(bundle_file.read())
 
107
            self.outf.write(gettext("Decoded contents\n"))
103
108
            self.outf.write(content)
104
109
            self.outf.write('\n')