/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: 2018-05-19 13:16:11 UTC
  • mto: (6968.4.3 git-archive)
  • mto: This revision was merged to the branch mainline in revision 6972.
  • Revision ID: jelmer@jelmer.uk-20180519131611-l9h9ud41j7qg1m03
Move tar/zip to breezy.archive.

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