/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: Robert Collins
  • Date: 2010-05-06 23:41:35 UTC
  • mto: This revision was merged to the branch mainline in revision 5223.
  • Revision ID: robertc@robertcollins.net-20100506234135-yivbzczw1sejxnxc
Lock methods on ``Tree``, ``Branch`` and ``Repository`` are now
expected to return an object which can be used to unlock them. This reduces
duplicate code when using cleanups. The previous 'tokens's returned by
``Branch.lock_write`` and ``Repository.lock_write`` are now attributes
on the result of the lock_write. ``repository.RepositoryWriteLockResult``
and ``branch.BranchWriteLockResult`` document this. (Robert Collins)

``log._get_info_for_log_files`` now takes an add_cleanup callable.
(Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2011 Canonical Ltd
 
1
# Copyright (C) 2005-2010 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 __future__ import absolute_import
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
43
 
from ...sixish import (
44
 
    BytesIO,
45
 
    viewitems,
46
 
    )
 
38
from bzrlib.commands import Command
 
39
from bzrlib.option import Option
 
40
from bzrlib.trace import note
47
41
 
48
42
 
49
43
class cmd_bundle_info(Command):
55
49
    encoding_type = 'exact'
56
50
 
57
51
    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
 
52
        from bzrlib.bundle.serializer import read_bundle
 
53
        from bzrlib.bundle import read_mergeable_from_url
 
54
        from bzrlib import osutils
61
55
        term_encoding = osutils.get_terminal_encoding()
62
56
        bundle_info = read_mergeable_from_url(location)
63
57
        if isinstance(bundle_info, merge_directive.BaseMergeDirective):
64
 
            bundle_file = BytesIO(bundle_info.get_raw_bundle())
 
58
            bundle_file = StringIO(bundle_info.get_raw_bundle())
65
59
            bundle_info = read_bundle(bundle_file)
66
60
        else:
67
61
            if verbose:
68
 
                raise errors.BzrCommandError(gettext(
69
 
                    '--verbose requires a merge directive'))
 
62
                raise errors.BzrCommandError('--verbose requires a merge'
 
63
                    ' directive')
70
64
        reader_method = getattr(bundle_info, 'get_bundle_reader', None)
71
65
        if reader_method is None:
72
 
            raise errors.BzrCommandError(
73
 
                gettext('Bundle format not supported'))
 
66
            raise errors.BzrCommandError('Bundle format not supported')
74
67
 
75
68
        by_kind = {}
76
69
        file_ids = set()
77
70
        for bytes, parents, repo_kind, revision_id, file_id\
78
 
                in reader_method().iter_records():
 
71
            in reader_method().iter_records():
79
72
            by_kind.setdefault(repo_kind, []).append(
80
73
                (bytes, parents, repo_kind, revision_id, file_id))
81
74
            if file_id is not None:
82
75
                file_ids.add(file_id)
83
 
        self.outf.write(gettext('Records\n'))
84
 
        for kind, records in sorted(viewitems(by_kind)):
 
76
        self.outf.write('Records\n')
 
77
        for kind, records in sorted(by_kind.iteritems()):
85
78
            multiparent = sum(1 for b, m, k, r, f in records if
86
79
                              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))
 
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))
90
83
        self.outf.write('\n')
91
84
        nicks = set()
92
85
        committers = set()
95
88
                nicks.add(revision.properties['branch-nick'])
96
89
            committers.add(revision.committer)
97
90
 
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')))
 
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')))
103
96
        if verbose:
104
97
            self.outf.write('\n')
105
98
            bundle_file.seek(0)
106
99
            line = bundle_file.readline()
107
100
            line = bundle_file.readline()
108
 
            import bz2
109
 
            content = bz2.decompress(bundle_file.read())
110
 
            self.outf.write(gettext("Decoded contents\n"))
 
101
            content = bundle_file.read().decode('bz2')
 
102
            self.outf.write("Decoded contents\n")
111
103
            self.outf.write(content)
112
104
            self.outf.write('\n')