/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,
30
    urlutils,
31
    )
32
""")
33
34
from bzrlib.commands import Command
0.5.121 by John Arbash Meinel
Fixing options to apply-changeset
35
from bzrlib.option import Option
1185.84.4 by Aaron Bentley
Use parent branch as default base branch
36
from bzrlib.trace import note
1185.82.78 by Aaron Bentley
Cleanups
37
0.5.1 by John Arbash Meinel
Just an initial working step.
38
0.5.81 by John Arbash Meinel
Cleaning up from pychecker.
39
class cmd_send_changeset(Command):
0.5.24 by John Arbash Meinel
Adding send-changeset from Johan Rydberg
40
    """Send a bundled up changset via mail.
41
42
    If no revision has been specified, the last commited change will
43
    be sent.
44
0.5.30 by John Arbash Meinel
Merging send-changeset updates from jrydberg
45
    Subject of the mail can be specified by the --message option,
0.5.24 by John Arbash Meinel
Adding send-changeset from Johan Rydberg
46
    otherwise information from the changeset log will be used.
0.5.30 by John Arbash Meinel
Merging send-changeset updates from jrydberg
47
48
    A editor will be spawned where the user may enter a description
49
    of the changeset.  The description can be read from a file with
50
    the --file FILE option.
0.5.24 by John Arbash Meinel
Adding send-changeset from Johan Rydberg
51
    """
0.5.31 by John Arbash Meinel
Some cleanup to the send_changeset work.
52
    takes_options = ['revision', 'message', 'file']
0.5.24 by John Arbash Meinel
Adding send-changeset from Johan Rydberg
53
    takes_args = ['to?']
54
0.5.31 by John Arbash Meinel
Some cleanup to the send_changeset work.
55
    def run(self, to=None, message=None, revision=None, file=None):
0.5.68 by John Arbash Meinel
(broken), starting to change the syntax of the command to allow cset to take a base and a target.
56
        from bzrlib.errors import BzrCommandError
0.5.31 by John Arbash Meinel
Some cleanup to the send_changeset work.
57
        from send_changeset import send_changeset
0.5.30 by John Arbash Meinel
Merging send-changeset updates from jrydberg
58
        
0.5.24 by John Arbash Meinel
Adding send-changeset from Johan Rydberg
59
        if isinstance(revision, (list, tuple)):
60
            if len(revision) > 1:
61
                raise BzrCommandError('We do not support rollup-changesets yet.')
62
            revision = revision[0]
63
1996.3.8 by John Arbash Meinel
lazy_import bundle and bundle.commands
64
        b = branch.Branch.open_containing('.')
0.5.24 by John Arbash Meinel
Adding send-changeset from Johan Rydberg
65
66
        if not to:
67
            try:
68
                to = b.controlfile('x-send-address', 'rb').read().strip('\n')
69
            except:
70
                raise BzrCommandError('destination address is not known')
71
0.5.31 by John Arbash Meinel
Some cleanup to the send_changeset work.
72
        if not isinstance(revision, (list, tuple)):
73
            revision = [revision]
0.5.24 by John Arbash Meinel
Adding send-changeset from Johan Rydberg
74
0.5.31 by John Arbash Meinel
Some cleanup to the send_changeset work.
75
        send_changeset(b, revision, to, message, file)
0.5.24 by John Arbash Meinel
Adding send-changeset from Johan Rydberg
76
1185.82.10 by John Arbash Meinel
Worked out the changeset command.
77
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
78
class cmd_bundle_revisions(Command):
79
    """Generate a revision bundle.
0.5.1 by John Arbash Meinel
Just an initial working step.
80
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
81
    This bundle contains all of the meta-information of a
0.5.1 by John Arbash Meinel
Just an initial working step.
82
    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.
83
1185.82.81 by Aaron Bentley
Remove unused functionality
84
    You can apply it to another tree using 'bzr merge'.
85
1185.84.1 by Aaron Bentley
Use full command name in bundle-revisions help
86
    bzr bundle-revisions
1793.2.14 by Aaron Bentley
Clean up bundle revision specification
87
        - Generate a bundle relative to a remembered location
2374.1.1 by Ian Clatworthy
Help and man page fixes
88
1185.84.1 by Aaron Bentley
Use full command name in bundle-revisions help
89
    bzr bundle-revisions BASE
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
90
        - Bundle to apply the current tree into BASE
2374.1.1 by Ian Clatworthy
Help and man page fixes
91
1185.84.1 by Aaron Bentley
Use full command name in bundle-revisions help
92
    bzr bundle-revisions --revision A
1793.2.14 by Aaron Bentley
Clean up bundle revision specification
93
        - Bundle to apply revision A to remembered location 
2374.1.1 by Ian Clatworthy
Help and man page fixes
94
1185.84.1 by Aaron Bentley
Use full command name in bundle-revisions help
95
    bzr bundle-revisions --revision A..B
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
96
        - Bundle to transform A into B
0.5.1 by John Arbash Meinel
Just an initial working step.
97
    """
2379.5.1 by John Arbash Meinel
(Robert Widhopf-Fenk, bug #98591) Remove --verbose flag from 'bzr bundle'.
98
    takes_options = ['revision', 'remember',
1744.1.1 by Alexander Belchenko
Added --output option for bundle-revisions command
99
                     Option("output", help="write bundle to specified file",
100
                            type=unicode)]
1185.82.10 by John Arbash Meinel
Worked out the changeset command.
101
    takes_args = ['base?']
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
102
    aliases = ['bundle']
2178.4.4 by Alexander Belchenko
encoding_type = 'exact' force sys.stdout to be binary stream on win32
103
    encoding_type = 'exact'
0.5.1 by John Arbash Meinel
Just an initial working step.
104
1804.1.1 by Aaron Bentley
Add support for submit location to bundles
105
    def run(self, base=None, revision=None, output=None, remember=False):
0.5.81 by John Arbash Meinel
Cleaning up from pychecker.
106
        from bzrlib import user_encoding
1185.82.130 by Aaron Bentley
Rename changesets to revision bundles
107
        from bzrlib.bundle.serializer import write_bundle
1185.82.10 by John Arbash Meinel
Worked out the changeset command.
108
1996.3.8 by John Arbash Meinel
lazy_import bundle and bundle.commands
109
        target_branch = branch.Branch.open_containing(u'.')[0]
1804.1.1 by Aaron Bentley
Add support for submit location to bundles
110
111
        if base is None:
112
            base_specified = False
113
        else:
114
            base_specified = True
1185.84.4 by Aaron Bentley
Use parent branch as default base branch
115
1185.82.10 by John Arbash Meinel
Worked out the changeset command.
116
        if revision is None:
117
            target_revision = target_branch.last_revision()
1793.2.14 by Aaron Bentley
Clean up bundle revision specification
118
        elif len(revision) < 3:
119
            target_revision = revision[-1].in_history(target_branch).rev_id
120
            if len(revision) == 2:
121
                if base_specified:
122
                    raise errors.BzrCommandError('Cannot specify base as well'
123
                                                 ' as two revision arguments.')
1185.82.85 by Aaron Bentley
Swap meaning of two-argument 'changeset' to match 'merge'
124
                base_revision = revision[0].in_history(target_branch).rev_id
1185.82.10 by John Arbash Meinel
Worked out the changeset command.
125
        else:
126
            raise errors.BzrCommandError('--revision takes 1 or 2 parameters')
127
1793.2.14 by Aaron Bentley
Clean up bundle revision specification
128
        if revision is None or len(revision) < 2:
129
            submit_branch = target_branch.get_submit_branch()
130
            if base is None:
131
                base = submit_branch
132
            if base is None:
133
                base = target_branch.get_parent()
134
            if base is None:
135
                raise errors.BzrCommandError("No base branch known or"
136
                                             " specified.")
137
            elif not base_specified:
1793.2.16 by Aaron Bentley
More notes on 'note'
138
                # FIXME:
139
                # note() doesn't pay attention to terminal_encoding() so
140
                # we must format with 'ascii' to be safe
141
                note('Using saved location: %s',
142
                     urlutils.unescape_for_display(base, 'ascii'))
1996.3.8 by John Arbash Meinel
lazy_import bundle and bundle.commands
143
            base_branch = branch.Branch.open(base)
1793.2.14 by Aaron Bentley
Clean up bundle revision specification
144
145
            # We don't want to lock the same branch across
146
            # 2 different branches
147
            if target_branch.base == base_branch.base:
148
                base_branch = target_branch 
149
            if submit_branch is None or remember:
150
                if base_specified:
151
                    target_branch.set_submit_branch(base_branch.base)
152
                elif remember:
153
                    raise errors.BzrCommandError('--remember requires a branch'
154
                                                 ' to be specified.')
1185.82.23 by Aaron Bentley
Switch the fetcher
155
            target_branch.repository.fetch(base_branch.repository, 
1793.2.14 by Aaron Bentley
Clean up bundle revision specification
156
                                           base_branch.last_revision())
2490.2.21 by Aaron Bentley
Rename graph to deprecated_graph
157
            graph = target_branch.repository.get_graph()
158
            base_revision = graph.find_unique_lca(
2490.2.13 by Aaron Bentley
Update distinct -> lowest, refactor, add ParentsProvider concept
159
                base_branch.last_revision(), target_revision)
1744.1.1 by Alexander Belchenko
Added --output option for bundle-revisions command
160
161
        if output is not None:
162
            fileobj = file(output, 'wb')
163
        else:
164
            fileobj = sys.stdout
1927.1.1 by John Arbash Meinel
Lock the repository more often
165
        target_branch.repository.lock_read()
166
        try:
167
            write_bundle(target_branch.repository, target_revision,
168
                         base_revision, fileobj)
169
        finally:
170
            target_branch.repository.unlock()
1185.82.10 by John Arbash Meinel
Worked out the changeset command.
171
0.5.1 by John Arbash Meinel
Just an initial working step.
172
0.5.81 by John Arbash Meinel
Cleaning up from pychecker.
173
class cmd_verify_changeset(Command):
0.5.7 by John Arbash Meinel
Added a bunch more information about changesets. Can now read back in all of the meta information.
174
    """Read a written changeset, and make sure it is valid.
175
176
    """
177
    takes_args = ['filename?']
178
179
    def run(self, filename=None):
0.5.81 by John Arbash Meinel
Cleaning up from pychecker.
180
        from read_changeset import read_changeset
0.5.103 by John Arbash Meinel
Updated to having a changeset specific message.
181
        #from bzrlib.xml import serializer_v4
0.5.56 by John Arbash Meinel
A couple more fixups, it seems actually capable now of writing out a changeset, and reading it back.
182
1996.3.8 by John Arbash Meinel
lazy_import bundle and bundle.commands
183
        b, relpath = branch.Branch.open_containing('.')
0.5.56 by John Arbash Meinel
A couple more fixups, it seems actually capable now of writing out a changeset, and reading it back.
184
0.5.7 by John Arbash Meinel
Added a bunch more information about changesets. Can now read back in all of the meta information.
185
        if filename is None or filename == '-':
186
            f = sys.stdin
187
        else:
0.5.33 by John Arbash Meinel
Use universal newlines wherever appropriate.
188
            f = open(filename, 'U')
0.5.7 by John Arbash Meinel
Added a bunch more information about changesets. Can now read back in all of the meta information.
189
0.5.88 by John Arbash Meinel
Fixed a bug in the rename code, added more tests.
190
        cset_info, cset_tree = read_changeset(f, b)
0.5.103 by John Arbash Meinel
Updated to having a changeset specific message.
191
        # print cset_info
192
        # print cset_tree
193
        #serializer_v4.write(cset_tree.inventory, sys.stdout)