1
1
# Copyright (C) 2004-2006 by Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
5
5
# the Free Software Foundation; either version 2 of the License, or
6
6
# (at your option) any later version.
8
8
# This program is distributed in the hope that it will be useful,
9
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
11
# GNU General Public License for more details.
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26
27
from bzrlib.bundle.serializer import write_bundle, read_bundle
27
28
from bzrlib.branch import Branch
28
29
from bzrlib.diff import internal_diff
29
from bzrlib.delta import compare_trees
30
30
from bzrlib.errors import BzrError, TestamentMismatch, NotABundle, BadBundle
31
31
from bzrlib.merge import Merge3Merger
32
32
from bzrlib.osutils import has_symlinks, sha_file
290
290
def test_iteration(self):
291
291
"""Ensure that iteration through ids works properly"""
292
292
btree = self.make_tree_1()[0]
293
self.assertEqual(self.sorted_ids(btree), ['a', 'b', 'c', 'd'])
293
self.assertEqual(self.sorted_ids(btree),
294
[inventory.ROOT_ID, 'a', 'b', 'c', 'd'])
294
295
btree.note_deletion("grandparent/parent/file")
295
296
btree.note_id("e", "grandparent/alt_parent/fool", kind="directory")
296
297
btree.note_last_changed("grandparent/alt_parent/fool",
297
298
"revisionidiguess")
298
self.assertEqual(self.sorted_ids(btree), ['a', 'b', 'd', 'e'])
299
self.assertEqual(self.sorted_ids(btree),
300
[inventory.ROOT_ID, 'a', 'b', 'd', 'e'])
301
303
class BundleTester(TestCaseWithTransport):
373
375
def test_crlf_bundle(self):
375
read_bundle(StringIO('# Bazaar revision bundle v0.7\r\n'))
377
read_bundle(StringIO('# Bazaar revision bundle v0.8\r\n'))
376
378
except BadBundle:
377
379
# It is currently permitted for bundles with crlf line endings to
378
380
# make read_bundle raise a BadBundle, but this should be fixed.
400
402
new = tree.branch.repository.revision_tree(ancestor)
402
404
# Check that there aren't any inventory level changes
403
delta = compare_trees(old, new)
405
delta = new.changes_from(old)
404
406
self.assertFalse(delta.has_changed(),
405
407
'Revision %s not copied correctly.'
419
421
rh = self.b1.revision_history()
420
422
tree.branch.set_revision_history(rh[:rh.index(rev_id)+1])
422
delta = compare_trees(self.b1.repository.revision_tree(rev_id),
424
delta = tree.changes_from(self.b1.repository.revision_tree(rev_id))
424
425
self.assertFalse(delta.has_changed(),
425
426
'Working tree has modifications')
610
611
self.tree1 = BzrDir.create_standalone_workingtree('b1')
611
612
self.b1 = self.tree1.branch
612
613
tt = TreeTransform(self.tree1)
613
tt.new_file('file', tt.root, '\x00\xff', 'binary-1')
614
tt.new_file('file2', tt.root, '\x00\xff', 'binary-2')
616
tt.new_file('file', tt.root, '\x00\n\x00\r\x01\n\x02\r\xff', 'binary-1')
617
tt.new_file('file2', tt.root, '\x01\n\x02\r\x03\n\x04\r\xff', 'binary-2')
616
619
self.tree1.commit('add binary', rev_id='b@cset-0-1')
617
620
self.get_valid_bundle(None, 'b@cset-0-1')
618
623
tt = TreeTransform(self.tree1)
619
624
trans_id = tt.trans_id_tree_file_id('binary-1')
620
625
tt.delete_contents(trans_id)
622
627
self.tree1.commit('delete binary', rev_id='b@cset-0-2')
623
628
self.get_valid_bundle('b@cset-0-1', 'b@cset-0-2')
624
631
tt = TreeTransform(self.tree1)
625
632
trans_id = tt.trans_id_tree_file_id('binary-2')
626
633
tt.adjust_path('file3', tt.root, trans_id)
627
634
tt.delete_contents(trans_id)
628
tt.create_file('filecontents\x00', trans_id)
635
tt.create_file('file\rcontents\x00\n\x00', trans_id)
630
637
self.tree1.commit('rename and modify binary', rev_id='b@cset-0-3')
631
638
self.get_valid_bundle('b@cset-0-2', 'b@cset-0-3')
632
641
tt = TreeTransform(self.tree1)
633
642
trans_id = tt.trans_id_tree_file_id('binary-2')
634
643
tt.delete_contents(trans_id)
635
tt.create_file('\x00filecontents', trans_id)
644
tt.create_file('\x00file\rcontents', trans_id)
637
646
self.tree1.commit('just modify binary', rev_id='b@cset-0-4')
638
647
self.get_valid_bundle('b@cset-0-3', 'b@cset-0-4')
650
self.get_valid_bundle(None, 'b@cset-0-4')
640
652
def test_last_modified(self):
641
653
self.tree1 = BzrDir.create_standalone_workingtree('b1')
642
654
self.b1 = self.tree1.branch
769
781
# Now test a complet roll-up
770
782
bundle = self.get_valid_bundle(None, 'white-4')
784
def test_alt_timezone_bundle(self):
785
self.tree1 = self.make_branch_and_tree('b1')
786
self.b1 = self.tree1.branch
788
self.build_tree(['b1/newfile'])
789
self.tree1.add(['newfile'])
791
# Asia/Colombo offset = 5 hours 30 minutes
792
self.tree1.commit('non-hour offset timezone', rev_id='tz-1',
793
timezone=19800, timestamp=1152544886.0)
795
bundle = self.get_valid_bundle(None, 'tz-1')
797
rev = bundle.revisions[0]
798
self.assertEqual('Mon 2006-07-10 20:51:26.000000000 +0530', rev.date)
799
self.assertEqual(19800, rev.timezone)
800
self.assertEqual(1152544886.0, rev.timestamp)
773
803
class MungedBundleTester(TestCaseWithTransport):
780
810
wt.commit('add one', rev_id='a@cset-0-1')
781
811
self.build_tree(['b1/two'])
783
wt.commit('add two', rev_id='a@cset-0-2')
813
wt.commit('add two', rev_id='a@cset-0-2',
814
revprops={'branch-nick':'test'})
785
816
bundle_txt = StringIO()
786
817
rev_ids = write_bundle(wt.branch.repository, 'a@cset-0-2',
792
823
def check_valid(self, bundle):
793
824
"""Check that after whatever munging, the final object is valid."""
794
self.assertEqual(['a@cset-0-2'],
825
self.assertEqual(['a@cset-0-2'],
795
826
[r.revision_id for r in bundle.real_revisions])
797
828
def test_extra_whitespace(self):
830
861
# creates a blank line at the end, and fails if that
831
862
# line is stripped
832
863
self.assertEqual('\n\n', raw[-2:])
833
bundle_text = StringIO(raw[:-1])
835
bundle = read_bundle(bundle_txt)
836
self.check_valid(bundle)
864
bundle_txt = StringIO(raw[:-1])
866
bundle = read_bundle(bundle_txt)
867
self.check_valid(bundle)
869
def test_opening_text(self):
870
bundle_txt = self.build_test_bundle()
872
bundle_txt = StringIO("Some random\nemail comments\n"
873
+ bundle_txt.getvalue())
875
bundle = read_bundle(bundle_txt)
876
self.check_valid(bundle)
878
def test_trailing_text(self):
879
bundle_txt = self.build_test_bundle()
881
bundle_txt = StringIO(bundle_txt.getvalue() +
882
"Some trailing\nrandom\ntext\n")
884
bundle = read_bundle(bundle_txt)
885
self.check_valid(bundle)