209
209
self.assertEqual(self.sorted_ids(ctree), ['a', 'b', 'd', 'e'])
211
211
class CSetTester(InTempDir):
213
from bzrlib.branch import find_branch
213
def get_valid_cset(self, base_rev_id, rev_id):
214
"""Create a changeset from base_rev_id -> rev_id in built-in branch.
215
Make sure that the text generated is valid, and that it
216
can be applied against the base, and generate the same information.
218
:return: The in-memory changeset
220
from cStringIO import StringIO
214
221
from gen_changeset import show_changeset
215
222
from read_changeset import read_changeset
224
cset_txt = StringIO()
225
show_changeset(self.b1, base_rev_id, self.b1, rev_id, to_file=cset_txt)
227
self.assertEqual(cset_txt.readline(), '# Bazaar-NG changeset v0.0.5\n')
228
self.assertEqual(cset_txt.readline(), '# \n')
230
rev = self.b1.get_revision(rev_id)
231
self.assertEqual(cset_txt.readline(), '# committer: %s\n' % rev.committer)
234
# This should also validate the generate changeset
235
cset = read_changeset(cset_txt, self.b1)
236
info, tree, inv = cset
237
for cset_rev in info.real_revisions:
238
# These really should have already been checked in read_changeset
239
# since it computes the sha1 hash for the revision, which
240
# only will match if everything is okay, but lets be
242
branch_rev = self.b1.get_revision(cset_rev.revision_id)
243
for a in ('inventory_id', 'inventory_sha1', 'revision_id',
244
'timestamp', 'timezone', 'message', 'committer'):
245
self.assertEqual(getattr(branch_rev, a), getattr(cset_rev, a))
246
self.assertEqual(len(branch_rev.parents), len(cset_rev.parents))
247
for b_par, c_par in zip(branch_rev.parents, cset_rev.parents):
248
self.assertEqual(b_par.revision_id, c_par.revision_id)
249
# Foolishly, pending-merges generates parents which
250
# may not have revision entries
251
if b_par.revision_sha1 is None:
252
if b_par.revision_id in self.b1.revision_store:
253
sha1 = self.b1.get_revision_sha1(b_par.revision_id)
257
sha1 = b_par.revision_sha1
259
self.assertEqual(sha1, c_par.revision_sha1)
261
self.valid_apply_changeset(base_rev_id, cset)
263
return info, tree, inv
265
def get_checkout(self, rev_id):
266
"""Get a new tree, with the specified revision in it.
268
from bzrlib.branch import find_branch
270
from bzrlib.merge import merge
272
dirname = tempfile.mkdtemp(prefix='test-branch-', dir='.')
273
to_branch = find_branch(dirname, init=True)
274
# TODO: Once root ids are established, remove this if
275
if hasattr(self.b1, 'get_root_id'):
276
to_branch.set_root_id(self.b1.get_root_id())
277
if rev_id is not None:
278
# TODO Worry about making the root id of the branch
280
rh = self.b1.revision_history()
281
self.assert_(rev_id in rh, 'Missing revision %s in base tree' % rev_id)
282
revno = self.b1.revision_history().index(rev_id) + 1
283
to_branch.update_revisions(self.b1, stop_revision=revno)
284
merge((dirname, -1), (dirname, 0), this_dir=dirname,
285
check_clean=False, ignore_zero=True)
288
def valid_apply_changeset(self, base_rev_id, cset):
289
"""Get the base revision, apply the changes, and make
290
sure everything matches the builtin branch.
292
from apply_changeset import _apply_cset
294
to_branch = self.get_checkout(base_rev_id)
295
_apply_cset(to_branch, cset)
298
for rev in info.real_revisions:
299
self.assert_(rev.revision_id in to_branch.revision_store,
300
'Missing revision {%s} after applying changeset'
303
rev = info.real_revisions[-1]
304
base_tree = self.b1.revision_tree(rev.revision_id)
305
to_tree = to_branch.revision_tree(rev.revision_id)
307
# TODO: make sure the target tree is identical to base tree
310
from bzrlib.branch import find_branch
219
from cStringIO import StringIO
220
314
pjoin = os.path.join
224
317
self.b1 = find_branch('b1', init=True)
225
self.b2 = find_branch('b2', init=True)
227
319
open(pjoin('b1/one'), 'wb').write('one\n')
228
320
self.b1.add('one')
229
321
self.b1.commit('add one', rev_id='a@cset-0-1')
231
cset_txt = StringIO()
232
show_changeset(self.b1, None, self.b1, 'a@cset-0-1', to_file=cset_txt)
234
self.assertEqual(cset_txt.readline(), '# Bazaar-NG changeset v0.0.5\n')
235
self.assertEqual(cset_txt.readline(), '# \n')
238
# This should also validate the generate changeset
239
info, tree, inv = read_changeset(cset_txt, self.b1)
323
cset = self.get_valid_cset(None, 'a@cset-0-1')
325
# Make sure we can handle files with spaces, tabs, other
327
files = ['with space.txt',
329
'dir/filein subdir.c',
332
if sys.platform not in ('win32', 'cygwin'):
333
# Tabs are not valid in filenames on windows
334
files.append('with\ttab.txt')
335
self.build_tree(['b1/' + f for f in files])
337
self.b1.commit('add whitespace', rev_id='a@cset-0-2')
339
cset = self.get_valid_cset('a@cset-0-1', 'a@cset-0-2')
340
# Check a rollup changeset
341
cset = self.get_valid_cset(None, 'a@cset-0-2')