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

  • Committer: John Ferlito
  • Date: 2009-09-02 04:31:45 UTC
  • mto: (4665.7.1 serve-init)
  • mto: This revision was merged to the branch mainline in revision 4913.
  • Revision ID: johnf@inodes.org-20090902043145-gxdsfw03ilcwbyn5
Add a debian init script for bzr --serve

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2011 Canonical Ltd
 
1
# Copyright (C) 2006 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
 
 
17
16
"""\
18
17
This is an attempt to take the internal delta object, and represent
19
18
it as a single-file text-only changeset.
21
20
and for applying a changeset.
22
21
"""
23
22
 
24
 
from io import BytesIO
25
 
 
26
 
from ... import (
27
 
    errors,
28
 
    )
29
 
 
30
 
from ...lazy_import import lazy_import
 
23
import sys
 
24
from cStringIO import StringIO
 
25
 
 
26
from bzrlib.lazy_import import lazy_import
31
27
lazy_import(globals(), """
32
 
from breezy import (
 
28
from bzrlib import (
33
29
    branch,
 
30
    errors,
34
31
    merge_directive,
35
32
    revision as _mod_revision,
36
33
    urlutils,
37
34
    transport,
38
35
    )
39
 
from breezy.i18n import gettext
40
36
""")
41
37
 
42
 
from ...commands import Command
 
38
from bzrlib.commands import Command
 
39
from bzrlib.option import Option
 
40
from bzrlib.trace import note
43
41
 
44
42
 
45
43
class cmd_bundle_info(Command):
46
 
    __doc__ = """Output interesting stats about a bundle"""
 
44
    """Output interesting stats about a bundle"""
47
45
 
48
46
    hidden = True
49
47
    takes_args = ['location']
51
49
    encoding_type = 'exact'
52
50
 
53
51
    def run(self, location, verbose=False):
54
 
        from breezy.bzr.bundle.serializer import read_bundle
55
 
        from breezy.mergeable import read_mergeable_from_url
56
 
        from breezy import osutils
 
52
        from bzrlib.bundle.serializer import read_bundle
 
53
        from bzrlib.bundle import read_mergeable_from_url
 
54
        from bzrlib import osutils
57
55
        term_encoding = osutils.get_terminal_encoding()
58
56
        bundle_info = read_mergeable_from_url(location)
59
 
        if isinstance(bundle_info, merge_directive.BaseMergeDirective):
60
 
            bundle_file = BytesIO(bundle_info.get_raw_bundle())
 
57
        if isinstance(bundle_info, merge_directive._BaseMergeDirective):
 
58
            bundle_file = StringIO(bundle_info.get_raw_bundle())
61
59
            bundle_info = read_bundle(bundle_file)
62
60
        else:
63
61
            if verbose:
64
 
                raise errors.CommandError(gettext(
65
 
                    '--verbose requires a merge directive'))
 
62
                raise errors.BzrCommandError('--verbose requires a merge'
 
63
                    ' directive')
66
64
        reader_method = getattr(bundle_info, 'get_bundle_reader', None)
67
65
        if reader_method is None:
68
 
            raise errors.CommandError(
69
 
                gettext('Bundle format not supported'))
 
66
            raise errors.BzrCommandError('Bundle format not supported')
70
67
 
71
68
        by_kind = {}
72
69
        file_ids = set()
73
70
        for bytes, parents, repo_kind, revision_id, file_id\
74
 
                in reader_method().iter_records():
 
71
            in reader_method().iter_records():
75
72
            by_kind.setdefault(repo_kind, []).append(
76
73
                (bytes, parents, repo_kind, revision_id, file_id))
77
74
            if file_id is not None:
78
75
                file_ids.add(file_id)
79
 
        self.outf.write(gettext('Records\n'))
80
 
        for kind, records in sorted(by_kind.items()):
 
76
        self.outf.write('Records\n')
 
77
        for kind, records in sorted(by_kind.iteritems()):
81
78
            multiparent = sum(1 for b, m, k, r, f in records if
82
79
                              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))
 
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))
86
83
        self.outf.write('\n')
87
84
        nicks = set()
88
85
        committers = set()
91
88
                nicks.add(revision.properties['branch-nick'])
92
89
            committers.add(revision.committer)
93
90
 
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')))
 
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')))
99
96
        if verbose:
100
97
            self.outf.write('\n')
101
98
            bundle_file.seek(0)
102
99
            line = bundle_file.readline()
103
100
            line = bundle_file.readline()
104
 
            import bz2
105
 
            content = bz2.decompress(bundle_file.read())
106
 
            self.outf.write(gettext("Decoded contents\n"))
 
101
            content = bundle_file.read().decode('bz2')
 
102
            self.outf.write("Decoded contents\n")
107
103
            self.outf.write(content)
108
104
            self.outf.write('\n')