~bzr-pqm/bzr/bzr.dev

2052.3.1 by John Arbash Meinel
Add tests to cleanup the copyright of all source files
1
# Copyright (C) 2006 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
0.5.1 by John Arbash Meinel
Just an initial working step.
16
"""\
17
This is an attempt to take the internal delta object, and represent
18
it as a single-file text-only changeset.
19
This should have commands for both generating a changeset,
20
and for applying a changeset.
21
"""
22
0.5.99 by John Arbash Meinel
Updating to current Branch.open() and RevisionSpec changes.
23
import sys
2520.5.4 by Aaron Bentley
Replace 'bundle-revisions' with 'submit' command
24
from cStringIO import StringIO
1185.82.78 by Aaron Bentley
Cleanups
25
1996.3.8 by John Arbash Meinel
lazy_import bundle and bundle.commands
26
from bzrlib.lazy_import import lazy_import
27
lazy_import(globals(), """
28
from bzrlib import (
29
    branch,
30
    errors,
2520.5.4 by Aaron Bentley
Replace 'bundle-revisions' with 'submit' command
31
    merge_directive,
2490.2.28 by Aaron Bentley
Fix handling of null revision
32
    revision as _mod_revision,
1996.3.8 by John Arbash Meinel
lazy_import bundle and bundle.commands
33
    urlutils,
2520.4.35 by Aaron Bentley
zap obsolete changeset commands, add bundle-info command
34
    transport,
1996.3.8 by John Arbash Meinel
lazy_import bundle and bundle.commands
35
    )
36
""")
37
38
from bzrlib.commands import Command
0.5.121 by John Arbash Meinel
Fixing options to apply-changeset
39
from bzrlib.option import Option
1185.84.4 by Aaron Bentley
Use parent branch as default base branch
40
from bzrlib.trace import note
1185.82.78 by Aaron Bentley
Cleanups
41
0.5.1 by John Arbash Meinel
Just an initial working step.
42
2520.4.35 by Aaron Bentley
zap obsolete changeset commands, add bundle-info command
43
class cmd_bundle_info(Command):
2520.4.36 by Aaron Bentley
Speed up bundle reading, tweak help for bundle-info
44
    """Output interesting stats about a bundle"""
2520.4.35 by Aaron Bentley
zap obsolete changeset commands, add bundle-info command
45
46
    hidden = True
47
    takes_args = ['location']
1551.18.4 by Aaron Bentley
Restore bundle-info -v, fix multiparent detection
48
    takes_options = ['verbose']
2520.4.44 by Aaron Bentley
Fix encoding handling in bundle-info
49
    encoding_type = 'exact'
2520.4.35 by Aaron Bentley
zap obsolete changeset commands, add bundle-info command
50
51
    def run(self, location, verbose=False):
52
        from bzrlib.bundle.serializer import read_bundle
2520.5.4 by Aaron Bentley
Replace 'bundle-revisions' with 'submit' command
53
        from bzrlib.bundle import read_mergeable_from_url
2520.4.44 by Aaron Bentley
Fix encoding handling in bundle-info
54
        from bzrlib import osutils
55
        term_encoding = osutils.get_terminal_encoding()
2520.5.4 by Aaron Bentley
Replace 'bundle-revisions' with 'submit' command
56
        bundle_info = read_mergeable_from_url(location)
57
        if isinstance(bundle_info, merge_directive._BaseMergeDirective):
1551.18.4 by Aaron Bentley
Restore bundle-info -v, fix multiparent detection
58
            bundle_file = StringIO(bundle_info.get_raw_bundle())
59
            bundle_info = read_bundle(bundle_file)
60
        else:
61
            if verbose:
3221.1.6 by Martin Pool
Better error message from bundle-info
62
                raise errors.BzrCommandError('--verbose requires a merge'
63
                    ' directive')
2520.4.35 by Aaron Bentley
zap obsolete changeset commands, add bundle-info command
64
        reader_method = getattr(bundle_info, 'get_bundle_reader', None)
65
        if reader_method is None:
66
            raise errors.BzrCommandError('Bundle format not supported')
67
68
        by_kind = {}
69
        file_ids = set()
70
        for bytes, parents, repo_kind, revision_id, file_id\
71
            in reader_method().iter_records():
72
            by_kind.setdefault(repo_kind, []).append(
73
                (bytes, parents, repo_kind, revision_id, file_id))
74
            if file_id is not None:
75
                file_ids.add(file_id)
2911.6.1 by Blake Winton
Change 'print >> f,'s to 'f.write('s.
76
        self.outf.write('Records\n')
2520.4.35 by Aaron Bentley
zap obsolete changeset commands, add bundle-info command
77
        for kind, records in sorted(by_kind.iteritems()):
1551.18.4 by Aaron Bentley
Restore bundle-info -v, fix multiparent detection
78
            multiparent = sum(1 for b, m, k, r, f in records if
79
                              len(m.get('parents', [])) > 1)
2911.6.1 by Blake Winton
Change 'print >> f,'s to 'f.write('s.
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))
83
        self.outf.write('\n')
2520.4.35 by Aaron Bentley
zap obsolete changeset commands, add bundle-info command
84
        nicks = set()
85
        committers = set()
86
        for revision in bundle_info.real_revisions:
2520.4.42 by Aaron Bentley
Don't assume every revision has a branch nick
87
            if 'branch-nick' in revision.properties:
88
                nicks.add(revision.properties['branch-nick'])
2520.4.35 by Aaron Bentley
zap obsolete changeset commands, add bundle-info command
89
            committers.add(revision.committer)
90
2911.6.1 by Blake Winton
Change 'print >> f,'s to 'f.write('s.
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')))
2520.4.35 by Aaron Bentley
zap obsolete changeset commands, add bundle-info command
96
        if verbose:
2911.6.1 by Blake Winton
Change 'print >> f,'s to 'f.write('s.
97
            self.outf.write('\n')
2520.4.35 by Aaron Bentley
zap obsolete changeset commands, add bundle-info command
98
            bundle_file.seek(0)
2520.4.74 by Aaron Bentley
bzr info handles patchless bundles
99
            line = bundle_file.readline()
100
            line = bundle_file.readline()
2520.4.76 by Aaron Bentley
Move base64-encoding into merge directives
101
            content = bundle_file.read().decode('bz2')
2911.6.1 by Blake Winton
Change 'print >> f,'s to 'f.write('s.
102
            self.outf.write("Decoded contents\n")
2520.4.35 by Aaron Bentley
zap obsolete changeset commands, add bundle-info command
103
            self.outf.write(content)
2911.6.1 by Blake Winton
Change 'print >> f,'s to 'f.write('s.
104
            self.outf.write('\n')