3
This is an attempt to take the internal delta object, and represent
4
it as a single-file text-only changeset.
5
This should have commands for both generating a changeset,
6
and for applying a changeset.
10
from bzrlib.commands import Command, register_command
11
from bzrlib.branch import Branch
12
from bzrlib.revisionspec import RevisionSpec
13
from bzrlib.option import Option
14
from bzrlib.revision import (common_ancestor, MultipleRevisionSources,
15
get_intervening_revisions, NULL_REVISION)
16
import bzrlib.errors as errors
18
class cmd_send_changeset(Command):
19
"""Send a bundled up changset via mail.
21
If no revision has been specified, the last commited change will
24
Subject of the mail can be specified by the --message option,
25
otherwise information from the changeset log will be used.
27
A editor will be spawned where the user may enter a description
28
of the changeset. The description can be read from a file with
29
the --file FILE option.
31
takes_options = ['revision', 'message', 'file']
34
def run(self, to=None, message=None, revision=None, file=None):
35
from bzrlib.errors import BzrCommandError
36
from send_changeset import send_changeset
38
if isinstance(revision, (list, tuple)):
40
raise BzrCommandError('We do not support rollup-changesets yet.')
41
revision = revision[0]
43
b = Branch.open_containing('.')
47
to = b.controlfile('x-send-address', 'rb').read().strip('\n')
49
raise BzrCommandError('destination address is not known')
51
if not isinstance(revision, (list, tuple)):
54
send_changeset(b, revision, to, message, file)
57
class cmd_changeset(Command):
58
"""Generate a bundled up changeset.
60
This changeset contains all of the meta-information of a
61
diff, rather than just containing the patch information.
64
- Changeset for the last commit
66
- Changeset to apply the current tree into BASE
68
- Changeset for revision A
69
bzr cset --revision A..B
70
- Changeset to transform A into B
71
bzr cset --revision A..B BASE
72
- Changeset to transform revision A of BASE into revision B
75
takes_options = ['verbose', 'revision']
76
takes_args = ['base?']
79
def run(self, base=None, revision=None):
80
from bzrlib import user_encoding
81
from bzrlib.changeset.serializer import write
86
base_branch = Branch.open(base)
88
# We don't want to lock the same branch across
89
# 2 different branches
90
target_branch = Branch.open_containing(u'.')[0]
91
if base_branch is not None and target_branch.base == base_branch.base:
96
target_revision = target_branch.last_revision()
97
if base_branch is not None:
98
base_revision = base_branch.last_revision()
99
elif len(revision) == 1:
100
target_revision = revision[0].in_history(target_branch).rev_id
101
if base_branch is not None:
102
base_revision = base_branch.last_revision()
103
elif len(revision) == 2:
104
target_revision = revision[0].in_history(target_branch).rev_id
105
if base_branch is not None:
106
base_revision = revision[1].in_history(base_branch).rev_id
108
base_revision = revision[1].in_history(target_branch).rev_id
110
raise errors.BzrCommandError('--revision takes 1 or 2 parameters')
112
if base_revision is None:
113
rev = target_branch.repository.get_revision(target_revision)
115
base_revision = rev.parent_ids[0]
117
base_revision = NULL_REVISION
119
if base_branch is not None:
120
target_branch.repository.fetch(base_branch.repository,
121
revision_id=base_revision)
123
revision_id_list = get_intervening_revisions(base_revision,
125
target_branch.repository,
126
target_branch.revision_history())
128
write(target_branch.repository, revision_id_list, sys.stdout)
131
class cmd_verify_changeset(Command):
132
"""Read a written changeset, and make sure it is valid.
135
takes_args = ['filename?']
137
def run(self, filename=None):
138
from read_changeset import read_changeset
139
#from bzrlib.xml import serializer_v4
141
b, relpath = Branch.open_containing('.')
143
if filename is None or filename == '-':
146
f = open(filename, 'U')
148
cset_info, cset_tree = read_changeset(f, b)
151
#serializer_v4.write(cset_tree.inventory, sys.stdout)
155
class cmd_apply_changeset(Command):
156
"""Read in the given changeset, and apply it to the
160
takes_args = ['filename?']
161
takes_options = [Option('reverse'), Option('auto-commit')]
163
def run(self, filename=None, reverse=False, auto_commit=False):
164
import apply_changeset
166
b, relpath = Branch.open_containing('.') # Make sure we are in a branch
167
if filename is None or filename == '-':
170
# Actually, we should not use Universal newlines
171
# as this potentially modifies the patch.
172
# though it seems mailers save attachments with their
173
# own format of the files.
174
f = open(filename, 'rb')
176
apply_changeset.apply_changeset(b, f, reverse=reverse,
177
auto_commit=auto_commit)
180
register_command(cmd_changeset)
181
register_command(cmd_verify_changeset)
182
register_command(cmd_apply_changeset)
183
register_command(cmd_send_changeset)
185
#OPTIONS['reverse'] = None
186
#OPTIONS['auto-commit'] = None
189
from doctest import DocTestSuite
190
from unittest import TestSuite, TestLoader
191
import test_changeset
197
suite.addTest(TestLoader().loadTestsFromModule(test_changeset))
198
suite.addTest(TestLoader().loadTestsFromModule(patches))
199
suite.addTest(DocTestSuite(common))