1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
|
#!/usr/bin/env python
"""\
This is an attempt to take the internal delta object, and represent
it as a single-file text-only changeset.
This should have commands for both generating a changeset,
and for applying a changeset.
"""
import sys
from bzrlib.branch import Branch
from bzrlib.commands import Command, register_command
import bzrlib.errors as errors
from bzrlib.option import Option
from bzrlib.revision import (common_ancestor, MultipleRevisionSources,
NULL_REVISION)
from bzrlib.revisionspec import RevisionSpec
class cmd_send_changeset(Command):
"""Send a bundled up changset via mail.
If no revision has been specified, the last commited change will
be sent.
Subject of the mail can be specified by the --message option,
otherwise information from the changeset log will be used.
A editor will be spawned where the user may enter a description
of the changeset. The description can be read from a file with
the --file FILE option.
"""
takes_options = ['revision', 'message', 'file']
takes_args = ['to?']
def run(self, to=None, message=None, revision=None, file=None):
from bzrlib.errors import BzrCommandError
from send_changeset import send_changeset
if isinstance(revision, (list, tuple)):
if len(revision) > 1:
raise BzrCommandError('We do not support rollup-changesets yet.')
revision = revision[0]
b = Branch.open_containing('.')
if not to:
try:
to = b.controlfile('x-send-address', 'rb').read().strip('\n')
except:
raise BzrCommandError('destination address is not known')
if not isinstance(revision, (list, tuple)):
revision = [revision]
send_changeset(b, revision, to, message, file)
class cmd_bundle_revisions(Command):
"""Generate a revision bundle.
This bundle contains all of the meta-information of a
diff, rather than just containing the patch information.
You can apply it to another tree using 'bzr merge'.
bzr bundle
- Bundle for the last commit
bzr bundle BASE
- Bundle to apply the current tree into BASE
bzr bundle --revision A
- Bundle for revision A
bzr bundle --revision A..B
- Bundle to transform A into B
bzr bundle --revision A..B BASE
- Bundle to transform revision A of BASE into revision B
of the local tree
"""
takes_options = ['verbose', 'revision']
takes_args = ['base?']
aliases = ['bundle']
def run(self, base=None, revision=None):
from bzrlib import user_encoding
from bzrlib.bundle.serializer import write_bundle
if base is None:
base_branch = None
else:
base_branch = Branch.open(base)
# We don't want to lock the same branch across
# 2 different branches
target_branch = Branch.open_containing(u'.')[0]
if base_branch is not None and target_branch.base == base_branch.base:
base_branch = None
base_revision = None
if revision is None:
target_revision = target_branch.last_revision()
elif len(revision) == 1:
target_revision = revision[0].in_history(target_branch).rev_id
if base_branch is not None:
base_revision = base_branch.last_revision()
elif len(revision) == 2:
target_revision = revision[1].in_history(target_branch).rev_id
if base_branch is not None:
base_revision = revision[0].in_history(base_branch).rev_id
else:
base_revision = revision[0].in_history(target_branch).rev_id
else:
raise errors.BzrCommandError('--revision takes 1 or 2 parameters')
if revision is None or len(revision) == 1:
if base_branch is not None:
target_branch.repository.fetch(base_branch.repository,
base_branch.last_revision())
base_revision = common_ancestor(base_branch.last_revision(),
target_revision,
target_branch.repository)
if base_revision is None:
base_revision = NULL_REVISION
if base_revision is None:
rev = target_branch.repository.get_revision(target_revision)
if rev.parent_ids:
base_revision = rev.parent_ids[0]
else:
base_revision = NULL_REVISION
if base_branch is not None:
target_branch.repository.fetch(base_branch.repository,
revision_id=base_revision)
del base_branch
write_bundle(target_branch.repository, target_revision, base_revision,
sys.stdout)
class cmd_verify_changeset(Command):
"""Read a written changeset, and make sure it is valid.
"""
takes_args = ['filename?']
def run(self, filename=None):
from read_changeset import read_changeset
#from bzrlib.xml import serializer_v4
b, relpath = Branch.open_containing('.')
if filename is None or filename == '-':
f = sys.stdin
else:
f = open(filename, 'U')
cset_info, cset_tree = read_changeset(f, b)
# print cset_info
# print cset_tree
#serializer_v4.write(cset_tree.inventory, sys.stdout)
|