6
20
and for applying a changeset.
9
from bzrlib.commands import Command, register_command, OPTIONS
11
class cmd_send_changeset(Command):
12
"""Send a bundled up changset via mail.
14
If no revision has been specified, the last commited change will
17
Subject of the mail can be specified by the --message option,
18
otherwise information from the changeset log will be used.
20
A editor will be spawned where the user may enter a description
21
of the changeset. The description can be read from a file with
22
the --file FILE option.
24
takes_options = ['revision', 'message', 'file']
27
def run(self, to=None, message=None, revision=None, file=None):
28
from bzrlib import find_branch
29
from bzrlib.errors import BzrCommandError
30
from send_changeset import send_changeset
32
if isinstance(revision, (list, tuple)):
34
raise BzrCommandError('We do not support rollup-changesets yet.')
35
revision = revision[0]
41
to = b.controlfile('x-send-address', 'rb').read().strip('\n')
43
raise BzrCommandError('destination address is not known')
45
if not isinstance(revision, (list, tuple)):
48
send_changeset(b, revision, to, message, file)
50
class cmd_changeset(Command):
51
"""Generate a bundled up changeset.
53
This changeset contains all of the meta-information of a
54
diff, rather than just containing the patch information.
56
BASE - This is the target tree with which you want to merge.
57
It will be used as the base for all patches. Anyone
58
wanting to merge the changeset will be required to have BASE
59
TARGET - This is the final revision which is desired to be in the
60
changeset. It defaults to the last committed revision. './@'
61
STARTING-REV-ID - All revisions between STARTING-REV and TARGET will
62
be bundled up in the changeset. By default this is
63
chosen as the merge root.
67
If --verbose, renames will be given as an 'add + delete' style patch.
24
from cStringIO import StringIO
26
from bzrlib.lazy_import import lazy_import
27
lazy_import(globals(), """
32
revision as _mod_revision,
38
from bzrlib.commands import Command
39
from bzrlib.option import Option
40
from bzrlib.trace import note
43
class cmd_bundle_info(Command):
44
"""Output interesting stats about a bundle"""
47
takes_args = ['location']
69
48
takes_options = ['verbose']
70
takes_args = ['base?', 'target?', 'starting-rev-id?']
73
def run(self, base=None, target=None, starting_rev_id=None, verbose=False):
74
from bzrlib.branch import find_branch
75
from bzrlib.commands import parse_spec
76
from bzrlib.errors import BzrCommandError
77
from bzrlib import user_encoding
84
b_target_path, target_revno = parse_spec(target)
85
target_branch = find_branch(b_target_path)
86
if target_revno is None or target_revno == -1:
87
target_rev_id = target_branch.last_patch()
89
target_rev_id = target_branch.lookup_revision(target_revno)
92
base_branch = target_branch
93
target_rev = target_branch.get_revision(target_rev_id)
94
base_rev_id = target_rev.parents[0].revision_id
96
base_path, base_revno = parse_spec(base)
97
base_branch = find_branch(base_path)
98
if base_revno is None or base_revno == -1:
99
base_rev_id = base_branch.last_patch()
101
base_rev_id = base_branch.lookup_revision(base_revno)
103
# outf = codecs.getwriter(user_encoding)(sys.stdout,
106
if starting_rev_id is not None:
107
raise BzrCommandError('Specifying the STARTING-REV-ID'
108
' not yet supported')
110
gen_changeset.show_changeset(base_branch, base_rev_id,
111
target_branch, target_rev_id,
113
to_file=sys.stdout, include_full_diff=verbose)
115
class cmd_verify_changeset(Command):
116
"""Read a written changeset, and make sure it is valid.
119
takes_args = ['filename?']
121
def run(self, filename=None):
123
from read_changeset import read_changeset
124
from bzrlib.branch import find_branch
125
from bzrlib.xml import pack_xml
129
if filename is None or filename == '-':
132
f = open(filename, 'U')
134
cset_info, cset_tree = read_changeset(f, b)
137
pack_xml(cset_tree.inventory, sys.stdout)
141
class cmd_apply_changeset(Command):
142
"""Read in the given changeset, and apply it to the
146
takes_args = ['filename?']
147
takes_options = ['reverse', 'auto-commit']
149
def run(self, filename=None, reverse=False, auto_commit=False):
150
from bzrlib.branch import find_branch
152
import apply_changeset
154
b = find_branch('.') # Make sure we are in a branch
155
if filename is None or filename == '-':
158
# Actually, we should not use Universal newlines
159
# as this potentially modifies the patch.
160
# though it seems mailers save attachments with their
161
# own format of the files.
162
f = open(filename, 'rb')
164
apply_changeset.apply_changeset(b, f, reverse=reverse,
165
auto_commit=auto_commit)
167
register_command(cmd_changeset)
168
register_command(cmd_verify_changeset)
169
register_command(cmd_apply_changeset)
170
register_command(cmd_send_changeset)
172
OPTIONS['reverse'] = None
173
OPTIONS['auto-commit'] = None
176
from doctest import DocTestSuite
177
from unittest import TestSuite, TestLoader
183
suite.addTest(TestLoader().loadTestsFromModule(testchangeset))
184
suite.addTest(DocTestSuite(common))
49
encoding_type = 'exact'
51
def run(self, location, verbose=False):
52
from bzrlib.bundle.serializer import read_bundle
53
from bzrlib.bundle import read_mergeable_from_url
54
from bzrlib import osutils
55
term_encoding = osutils.get_terminal_encoding()
56
bundle_info = read_mergeable_from_url(location)
57
if isinstance(bundle_info, merge_directive._BaseMergeDirective):
58
bundle_file = StringIO(bundle_info.get_raw_bundle())
59
bundle_info = read_bundle(bundle_file)
62
raise errors.BzrCommandError('--verbose requires a merge'
64
reader_method = getattr(bundle_info, 'get_bundle_reader', None)
65
if reader_method is None:
66
raise errors.BzrCommandError('Bundle format not supported')
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:
76
self.outf.write('Records\n')
77
for kind, records in sorted(by_kind.iteritems()):
78
multiparent = sum(1 for b, m, k, r, f in records if
79
len(m.get('parents', [])) > 1)
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))
86
for revision in bundle_info.real_revisions:
87
if 'branch-nick' in revision.properties:
88
nicks.add(revision.properties['branch-nick'])
89
committers.add(revision.committer)
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')))
99
line = bundle_file.readline()
100
line = bundle_file.readline()
101
content = bundle_file.read().decode('bz2')
102
self.outf.write("Decoded contents\n")
103
self.outf.write(content)
104
self.outf.write('\n')