/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/bzr/bundle/commands.py

  • Committer: Jelmer Vernooij
  • Date: 2020-02-14 00:03:37 UTC
  • mto: This revision was merged to the branch mainline in revision 7491.
  • Revision ID: jelmer@jelmer.uk-20200214000337-atq765xgh9487omx
Start on 3.2.

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
25
 
 
26
 
from bzrlib.lazy_import import lazy_import
 
24
from __future__ import absolute_import
 
25
 
 
26
from ... import (
 
27
    errors,
 
28
    )
 
29
 
 
30
from ...lazy_import import lazy_import
27
31
lazy_import(globals(), """
28
 
from bzrlib import (
 
32
from breezy import (
29
33
    branch,
30
 
    errors,
31
34
    merge_directive,
32
35
    revision as _mod_revision,
33
36
    urlutils,
34
37
    transport,
35
38
    )
 
39
from breezy.i18n import gettext
36
40
""")
37
41
 
38
 
from bzrlib.commands import Command
39
 
from bzrlib.option import Option
40
 
from bzrlib.trace import note
 
42
from ...commands import Command
 
43
from ...sixish import (
 
44
    BytesIO,
 
45
    viewitems,
 
46
    )
41
47
 
42
48
 
43
49
class cmd_bundle_info(Command):
49
55
    encoding_type = 'exact'
50
56
 
51
57
    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
 
58
        from breezy.bzr.bundle.serializer import read_bundle
 
59
        from breezy.mergeable import read_mergeable_from_url
 
60
        from breezy import osutils
55
61
        term_encoding = osutils.get_terminal_encoding()
56
62
        bundle_info = read_mergeable_from_url(location)
57
63
        if isinstance(bundle_info, merge_directive.BaseMergeDirective):
58
 
            bundle_file = StringIO(bundle_info.get_raw_bundle())
 
64
            bundle_file = BytesIO(bundle_info.get_raw_bundle())
59
65
            bundle_info = read_bundle(bundle_file)
60
66
        else:
61
67
            if verbose:
62
 
                raise errors.BzrCommandError('--verbose requires a merge'
63
 
                    ' directive')
 
68
                raise errors.BzrCommandError(gettext(
 
69
                    '--verbose requires a merge directive'))
64
70
        reader_method = getattr(bundle_info, 'get_bundle_reader', None)
65
71
        if reader_method is None:
66
 
            raise errors.BzrCommandError('Bundle format not supported')
 
72
            raise errors.BzrCommandError(
 
73
                gettext('Bundle format not supported'))
67
74
 
68
75
        by_kind = {}
69
76
        file_ids = set()
70
77
        for bytes, parents, repo_kind, revision_id, file_id\
71
 
            in reader_method().iter_records():
 
78
                in reader_method().iter_records():
72
79
            by_kind.setdefault(repo_kind, []).append(
73
80
                (bytes, parents, repo_kind, revision_id, file_id))
74
81
            if file_id is not None:
75
82
                file_ids.add(file_id)
76
 
        self.outf.write('Records\n')
77
 
        for kind, records in sorted(by_kind.iteritems()):
 
83
        self.outf.write(gettext('Records\n'))
 
84
        for kind, records in sorted(viewitems(by_kind)):
78
85
            multiparent = sum(1 for b, m, k, r, f in records if
79
86
                              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))
 
87
            self.outf.write(gettext('{0}: {1} ({2} multiparent)\n').format(
 
88
                kind, len(records), multiparent))
 
89
        self.outf.write(gettext('unique files: %d\n') % len(file_ids))
83
90
        self.outf.write('\n')
84
91
        nicks = set()
85
92
        committers = set()
88
95
                nicks.add(revision.properties['branch-nick'])
89
96
            committers.add(revision.committer)
90
97
 
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')))
 
98
        self.outf.write(gettext('Revisions\n'))
 
99
        self.outf.write((gettext('nicks: %s\n')
 
100
                         % ', '.join(sorted(nicks))).encode(term_encoding, 'replace'))
 
101
        self.outf.write((gettext('committers: \n%s\n') %
 
102
                         '\n'.join(sorted(committers)).encode(term_encoding, 'replace')))
96
103
        if verbose:
97
104
            self.outf.write('\n')
98
105
            bundle_file.seek(0)
99
106
            line = bundle_file.readline()
100
107
            line = bundle_file.readline()
101
 
            content = bundle_file.read().decode('bz2')
102
 
            self.outf.write("Decoded contents\n")
 
108
            import bz2
 
109
            content = bz2.decompress(bundle_file.read())
 
110
            self.outf.write(gettext("Decoded contents\n"))
103
111
            self.outf.write(content)
104
112
            self.outf.write('\n')