/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-19 23:18:42 UTC
  • mto: (7490.3.4 work)
  • mto: This revision was merged to the branch mainline in revision 7495.
  • Revision ID: jelmer@jelmer.uk-20200219231842-agwjh2db66cpajqg
Consistent return values.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2005-2011 Canonical Ltd
 
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
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
16
 
 
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
 
 
24
from __future__ import absolute_import
 
25
 
 
26
from ... import (
 
27
    errors,
 
28
    )
 
29
 
 
30
from ...lazy_import import lazy_import
 
31
lazy_import(globals(), """
 
32
from breezy import (
 
33
    branch,
 
34
    merge_directive,
 
35
    revision as _mod_revision,
 
36
    urlutils,
 
37
    transport,
 
38
    )
 
39
from breezy.i18n import gettext
 
40
""")
 
41
 
 
42
from ...commands import Command
 
43
from ...sixish import (
 
44
    BytesIO,
 
45
    viewitems,
 
46
    )
 
47
 
 
48
 
 
49
class cmd_bundle_info(Command):
 
50
    __doc__ = """Output interesting stats about a bundle"""
 
51
 
 
52
    hidden = True
 
53
    takes_args = ['location']
 
54
    takes_options = ['verbose']
 
55
    encoding_type = 'exact'
 
56
 
 
57
    def run(self, location, verbose=False):
 
58
        from breezy.bzr.bundle.serializer import read_bundle
 
59
        from breezy.mergeable import read_mergeable_from_url
 
60
        from breezy import osutils
 
61
        term_encoding = osutils.get_terminal_encoding()
 
62
        bundle_info = read_mergeable_from_url(location)
 
63
        if isinstance(bundle_info, merge_directive.BaseMergeDirective):
 
64
            bundle_file = BytesIO(bundle_info.get_raw_bundle())
 
65
            bundle_info = read_bundle(bundle_file)
 
66
        else:
 
67
            if verbose:
 
68
                raise errors.BzrCommandError(gettext(
 
69
                    '--verbose requires a merge directive'))
 
70
        reader_method = getattr(bundle_info, 'get_bundle_reader', None)
 
71
        if reader_method is None:
 
72
            raise errors.BzrCommandError(
 
73
                gettext('Bundle format not supported'))
 
74
 
 
75
        by_kind = {}
 
76
        file_ids = set()
 
77
        for bytes, parents, repo_kind, revision_id, file_id\
 
78
                in reader_method().iter_records():
 
79
            by_kind.setdefault(repo_kind, []).append(
 
80
                (bytes, parents, repo_kind, revision_id, file_id))
 
81
            if file_id is not None:
 
82
                file_ids.add(file_id)
 
83
        self.outf.write(gettext('Records\n'))
 
84
        for kind, records in sorted(viewitems(by_kind)):
 
85
            multiparent = sum(1 for b, m, k, r, f in records if
 
86
                              len(m.get('parents', [])) > 1)
 
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))
 
90
        self.outf.write('\n')
 
91
        nicks = set()
 
92
        committers = set()
 
93
        for revision in bundle_info.real_revisions:
 
94
            if 'branch-nick' in revision.properties:
 
95
                nicks.add(revision.properties['branch-nick'])
 
96
            committers.add(revision.committer)
 
97
 
 
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')))
 
103
        if verbose:
 
104
            self.outf.write('\n')
 
105
            bundle_file.seek(0)
 
106
            line = bundle_file.readline()
 
107
            line = bundle_file.readline()
 
108
            import bz2
 
109
            content = bz2.decompress(bundle_file.read())
 
110
            self.outf.write(gettext("Decoded contents\n"))
 
111
            self.outf.write(content)
 
112
            self.outf.write('\n')