/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
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
1185.82.78 by Aaron Bentley
Cleanups
24
1996.3.8 by John Arbash Meinel
lazy_import bundle and bundle.commands
25
from bzrlib.lazy_import import lazy_import
26
lazy_import(globals(), """
27
from bzrlib import (
28
    branch,
29
    errors,
2490.2.28 by Aaron Bentley
Fix handling of null revision
30
    revision as _mod_revision,
1996.3.8 by John Arbash Meinel
lazy_import bundle and bundle.commands
31
    urlutils,
2520.4.35 by Aaron Bentley
zap obsolete changeset commands, add bundle-info command
32
    transport,
1996.3.8 by John Arbash Meinel
lazy_import bundle and bundle.commands
33
    )
34
""")
35
36
from bzrlib.commands import Command
0.5.121 by John Arbash Meinel
Fixing options to apply-changeset
37
from bzrlib.option import Option
1185.84.4 by Aaron Bentley
Use parent branch as default base branch
38
from bzrlib.trace import note
1185.82.78 by Aaron Bentley
Cleanups
39
0.5.1 by John Arbash Meinel
Just an initial working step.
40
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
41
class cmd_bundle_revisions(Command):
42
    """Generate a revision bundle.
0.5.1 by John Arbash Meinel
Just an initial working step.
43
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
44
    This bundle contains all of the meta-information of a
0.5.1 by John Arbash Meinel
Just an initial working step.
45
    diff, rather than just containing the patch information.
0.5.7 by John Arbash Meinel
Added a bunch more information about changesets. Can now read back in all of the meta information.
46
1185.82.81 by Aaron Bentley
Remove unused functionality
47
    You can apply it to another tree using 'bzr merge'.
48
1185.84.1 by Aaron Bentley
Use full command name in bundle-revisions help
49
    bzr bundle-revisions
1793.2.14 by Aaron Bentley
Clean up bundle revision specification
50
        - Generate a bundle relative to a remembered location
2374.1.1 by Ian Clatworthy
Help and man page fixes
51
1185.84.1 by Aaron Bentley
Use full command name in bundle-revisions help
52
    bzr bundle-revisions BASE
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
53
        - Bundle to apply the current tree into BASE
2374.1.1 by Ian Clatworthy
Help and man page fixes
54
1185.84.1 by Aaron Bentley
Use full command name in bundle-revisions help
55
    bzr bundle-revisions --revision A
1793.2.14 by Aaron Bentley
Clean up bundle revision specification
56
        - Bundle to apply revision A to remembered location 
2374.1.1 by Ian Clatworthy
Help and man page fixes
57
1185.84.1 by Aaron Bentley
Use full command name in bundle-revisions help
58
    bzr bundle-revisions --revision A..B
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
59
        - Bundle to transform A into B
0.5.1 by John Arbash Meinel
Just an initial working step.
60
    """
2379.5.1 by John Arbash Meinel
(Robert Widhopf-Fenk, bug #98591) Remove --verbose flag from 'bzr bundle'.
61
    takes_options = ['revision', 'remember',
1744.1.1 by Alexander Belchenko
Added --output option for bundle-revisions command
62
                     Option("output", help="write bundle to specified file",
63
                            type=unicode)]
1185.82.10 by John Arbash Meinel
Worked out the changeset command.
64
    takes_args = ['base?']
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
65
    aliases = ['bundle']
2178.4.4 by Alexander Belchenko
encoding_type = 'exact' force sys.stdout to be binary stream on win32
66
    encoding_type = 'exact'
0.5.1 by John Arbash Meinel
Just an initial working step.
67
1804.1.1 by Aaron Bentley
Add support for submit location to bundles
68
    def run(self, base=None, revision=None, output=None, remember=False):
0.5.81 by John Arbash Meinel
Cleaning up from pychecker.
69
        from bzrlib import user_encoding
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
70
        from bzrlib.bundle.serializer import write_bundle
1185.82.10 by John Arbash Meinel
Worked out the changeset command.
71
1996.3.8 by John Arbash Meinel
lazy_import bundle and bundle.commands
72
        target_branch = branch.Branch.open_containing(u'.')[0]
2520.4.49 by Aaron Bentley
Fix lock handling in bundle command
73
        target_branch.lock_write()
74
        locked = [target_branch]
2520.4.52 by Aaron Bentley
Merge bzr.dev
75
1927.1.1 by John Arbash Meinel
Lock the repository more often
76
        try:
2520.4.49 by Aaron Bentley
Fix lock handling in bundle command
77
            if base is None:
78
                base_specified = False
79
            else:
80
                base_specified = True
81
82
            if revision is None:
83
                target_revision = target_branch.last_revision()
84
            elif len(revision) < 3:
85
                target_revision = revision[-1].in_history(target_branch).rev_id
86
                if len(revision) == 2:
87
                    if base_specified:
88
                        raise errors.BzrCommandError(
89
                            'Cannot specify base as well as two revision'
90
                            ' arguments.')
91
                    revspec = revision[0].in_history(target_branch)
92
                    base_revision = revspec.rev_id
93
            else:
94
                raise errors.BzrCommandError('--revision takes 1 or 2 '
95
                                             'parameters')
96
97
            if revision is None or len(revision) < 2:
98
                submit_branch = target_branch.get_submit_branch()
99
                if base is None:
100
                    base = submit_branch
101
                if base is None:
102
                    base = target_branch.get_parent()
103
                if base is None:
104
                    raise errors.BzrCommandError("No base branch known or"
105
                                                 " specified.")
106
                elif not base_specified:
107
                    # FIXME:
108
                    # note() doesn't pay attention to terminal_encoding() so
109
                    # we must format with 'ascii' to be safe
110
                    note('Using saved location: %s',
111
                         urlutils.unescape_for_display(base, 'ascii'))
112
                base_branch = branch.Branch.open(base)
113
                base_branch.lock_read()
114
                locked.append(base_branch)
115
                if submit_branch is None or remember:
116
                    if base_specified:
117
                        target_branch.set_submit_branch(base_branch.base)
118
                    elif remember:
119
                        raise errors.BzrCommandError(
120
                            '--remember requires a branch to be specified.')
121
                target_branch.repository.fetch(base_branch.repository,
122
                                               base_branch.last_revision())
123
                graph = target_branch.repository.get_graph()
124
                base_revision = graph.find_unique_lca(
2520.4.52 by Aaron Bentley
Merge bzr.dev
125
                    _mod_revision.ensure_null(base_branch.last_revision()),
126
                    _mod_revision.ensure_null(target_revision))
2520.4.49 by Aaron Bentley
Fix lock handling in bundle command
127
128
            if output is not None:
129
                fileobj = file(output, 'wb')
130
            else:
131
                fileobj = sys.stdout
1927.1.1 by John Arbash Meinel
Lock the repository more often
132
            write_bundle(target_branch.repository, target_revision,
133
                         base_revision, fileobj)
134
        finally:
2520.4.49 by Aaron Bentley
Fix lock handling in bundle command
135
            for item in reversed(locked):
136
                item.unlock()
1185.82.10 by John Arbash Meinel
Worked out the changeset command.
137
0.5.1 by John Arbash Meinel
Just an initial working step.
138
2520.4.35 by Aaron Bentley
zap obsolete changeset commands, add bundle-info command
139
class cmd_bundle_info(Command):
2520.4.36 by Aaron Bentley
Speed up bundle reading, tweak help for bundle-info
140
    """Output interesting stats about a bundle"""
2520.4.35 by Aaron Bentley
zap obsolete changeset commands, add bundle-info command
141
142
    hidden = True
143
    takes_args = ['location']
2520.4.39 by Aaron Bentley
Rename container => bundle(reader) where appropriate
144
    takes_options = [Option('verbose', help="output decoded contents",
145
                            short_name='v')]
2520.4.44 by Aaron Bentley
Fix encoding handling in bundle-info
146
    encoding_type = 'exact'
2520.4.35 by Aaron Bentley
zap obsolete changeset commands, add bundle-info command
147
148
    def run(self, location, verbose=False):
149
        from bzrlib.bundle.serializer import read_bundle
2520.4.44 by Aaron Bentley
Fix encoding handling in bundle-info
150
        from bzrlib import osutils
151
        term_encoding = osutils.get_terminal_encoding()
2520.4.35 by Aaron Bentley
zap obsolete changeset commands, add bundle-info command
152
        dirname, basename = urlutils.split(location)
153
        bundle_file = transport.get_transport(dirname).get(basename)
154
        bundle_info = read_bundle(bundle_file)
155
        reader_method = getattr(bundle_info, 'get_bundle_reader', None)
156
        if reader_method is None:
157
            raise errors.BzrCommandError('Bundle format not supported')
158
159
        by_kind = {}
160
        file_ids = set()
161
        for bytes, parents, repo_kind, revision_id, file_id\
162
            in reader_method().iter_records():
163
            by_kind.setdefault(repo_kind, []).append(
164
                (bytes, parents, repo_kind, revision_id, file_id))
165
            if file_id is not None:
166
                file_ids.add(file_id)
167
        print >> self.outf, 'Records'
168
        for kind, records in sorted(by_kind.iteritems()):
169
            multiparent = sum(1 for b, p, k, r, f in records if len(p) > 1)
170
            print >> self.outf, '%s: %d (%d multiparent)' % \
171
                (kind, len(records), multiparent)
172
        print >> self.outf, 'unique files: %d' % len(file_ids)
173
        print >> self.outf
174
        nicks = set()
175
        committers = set()
176
        for revision in bundle_info.real_revisions:
2520.4.42 by Aaron Bentley
Don't assume every revision has a branch nick
177
            if 'branch-nick' in revision.properties:
178
                nicks.add(revision.properties['branch-nick'])
2520.4.35 by Aaron Bentley
zap obsolete changeset commands, add bundle-info command
179
            committers.add(revision.committer)
180
181
        print >> self.outf, 'Revisions'
2520.4.44 by Aaron Bentley
Fix encoding handling in bundle-info
182
        print >> self.outf, ('nicks: %s'
183
            % ', '.join(sorted(nicks))).encode(term_encoding, 'replace')
184
        print >> self.outf, ('committers: \n%s' %
185
        '\n'.join(sorted(committers)).encode(term_encoding, 'replace'))
2520.4.35 by Aaron Bentley
zap obsolete changeset commands, add bundle-info command
186
        if verbose:
187
            print >> self.outf
188
            bundle_file.seek(0)
2520.4.74 by Aaron Bentley
bzr info handles patchless bundles
189
            line = bundle_file.readline()
190
            line = bundle_file.readline()
2520.4.76 by Aaron Bentley
Move base64-encoding into merge directives
191
            content = bundle_file.read().decode('bz2')
2520.4.35 by Aaron Bentley
zap obsolete changeset commands, add bundle-info command
192
            print >> self.outf, "Decoded contents"
193
            self.outf.write(content)
2520.4.40 by Aaron Bentley
Add human-readable diff to bundles
194
            print >> self.outf