1
# Copyright (C) 2006, 2007, 2008 Canonical Ltd
1
# Copyright (C) 2006, 2007, 2008, 2009, 2010 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
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
18
from StringIO import StringIO
22
22
from bzrlib import (
28
29
revision as _mod_revision,
136
137
transform.finalize()
137
138
transform.finalize()
140
def test_create_files_same_timestamp(self):
141
transform, root = self.get_transform()
142
self.wt.lock_tree_write()
143
self.addCleanup(self.wt.unlock)
144
# Roll back the clock, so that we know everything is being set to the
146
transform._creation_mtime = creation_mtime = time.time() - 20.0
147
transform.create_file('content-one',
148
transform.create_path('one', root))
149
time.sleep(1) # *ugly*
150
transform.create_file('content-two',
151
transform.create_path('two', root))
153
fo, st1 = self.wt.get_file_with_stat(None, path='one', filtered=False)
155
fo, st2 = self.wt.get_file_with_stat(None, path='two', filtered=False)
157
# We only guarantee 2s resolution
158
self.assertTrue(abs(creation_mtime - st1.st_mtime) < 2.0,
159
"%s != %s within 2 seconds" % (creation_mtime, st1.st_mtime))
160
# But if we have more than that, all files should get the same result
161
self.assertEqual(st1.st_mtime, st2.st_mtime)
139
163
def test_hardlink(self):
140
164
self.requireFeature(HardlinkFeature)
141
165
transform, root = self.get_transform()
1868
1892
self.assertEqual([], list(target.iter_changes(revision_tree)))
1869
1893
self.assertTrue(source.is_executable('file1-id'))
1895
def install_rot13_content_filter(self, pattern):
1896
original_registry = filters._reset_registry()
1897
def restore_registry():
1898
filters._reset_registry(original_registry)
1899
self.addCleanup(restore_registry)
1900
def rot13(chunks, context=None):
1901
return [''.join(chunks).encode('rot13')]
1902
rot13filter = filters.ContentFilter(rot13, rot13)
1903
filters.register_filter_stack_map('rot13', {'yes': [rot13filter]}.get)
1904
os.mkdir(self.test_home_dir + '/.bazaar')
1905
rules_filename = self.test_home_dir + '/.bazaar/rules'
1906
f = open(rules_filename, 'wb')
1907
f.write('[name %s]\nrot13=yes\n' % (pattern,))
1909
def uninstall_rules():
1910
os.remove(rules_filename)
1912
self.addCleanup(uninstall_rules)
1915
def test_build_tree_content_filtered_files_are_not_hardlinked(self):
1916
"""build_tree will not hardlink files that have content filtering rules
1917
applied to them (but will still hardlink other files from the same tree
1920
self.requireFeature(HardlinkFeature)
1921
self.install_rot13_content_filter('file1')
1922
source = self.create_ab_tree()
1923
target = self.make_branch_and_tree('target')
1924
revision_tree = source.basis_tree()
1925
revision_tree.lock_read()
1926
self.addCleanup(revision_tree.unlock)
1927
build_tree(revision_tree, target, source, hardlink=True)
1929
self.addCleanup(target.unlock)
1930
self.assertEqual([], list(target.iter_changes(revision_tree)))
1931
source_stat = os.stat('source/file1')
1932
target_stat = os.stat('target/file1')
1933
self.assertNotEqual(source_stat, target_stat)
1934
source_stat = os.stat('source/file2')
1935
target_stat = os.stat('target/file2')
1936
self.assertEqualStat(source_stat, target_stat)
1871
1938
def test_case_insensitive_build_tree_inventory(self):
1872
1939
if (tests.CaseInsensitiveFilesystemFeature.available()
1873
1940
or tests.CaseInsCasePresFilenameFeature.available()):
1951
2018
branch, tt = self.get_branch_and_transform()
1952
2019
tt.new_file('file', tt.root, 'contents', 'file-id')
1953
2020
trans_id = tt.new_directory('dir', tt.root, 'dir-id')
1954
tt.new_symlink('symlink', trans_id, 'target', 'symlink-id')
2021
if SymlinkFeature.available():
2022
tt.new_symlink('symlink', trans_id, 'target', 'symlink-id')
1955
2023
rev = tt.commit(branch, 'message')
1956
2024
tree = branch.basis_tree()
1957
2025
self.assertEqual('file', tree.id2path('file-id'))
1958
2026
self.assertEqual('contents', tree.get_file_text('file-id'))
1959
2027
self.assertEqual('dir', tree.id2path('dir-id'))
1960
self.assertEqual('dir/symlink', tree.id2path('symlink-id'))
1961
self.assertEqual('target', tree.get_symlink_target('symlink-id'))
2028
if SymlinkFeature.available():
2029
self.assertEqual('dir/symlink', tree.id2path('symlink-id'))
2030
self.assertEqual('target', tree.get_symlink_target('symlink-id'))
1963
2032
def test_add_unversioned(self):
1964
2033
branch, tt = self.get_branch_and_transform()
2454
2523
self.assertEqual(('missing', None, None, None), summary)
2456
2525
def test_file_content_summary_executable(self):
2457
if not osutils.supports_executable():
2458
raise TestNotApplicable()
2459
2526
preview = self.get_empty_preview()
2460
2527
path_id = preview.new_file('path', preview.root, 'contents', 'path-id')
2461
2528
preview.set_executability(True, path_id)
2754
2821
branch = self.make_branch('any')
2755
2822
tree = branch.repository.revision_tree(_mod_revision.NULL_REVISION)
2756
2823
tt = TransformPreview(tree)
2824
self.addCleanup(tt.finalize)
2757
2825
foo_id = tt.new_directory('', ROOT_PARENT)
2758
2826
bar_id = tt.new_file(u'\u1234bar', foo_id, 'contents')
2759
2827
limbo_path = tt._limbo_name(bar_id)