~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_transform.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-12-07 02:59:58 UTC
  • mfrom: (4826.1.8 hardlink-2a-408193)
  • Revision ID: pqm@pqm.ubuntu.com-20091207025958-wrddjbe59f5mjgva
(andrew) Allow '--hardlink' of files from 2a trees for any file that
        is unfiltered. (#408193)

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
import os
18
 
import stat
19
18
from StringIO import StringIO
20
19
import sys
21
20
 
22
21
from bzrlib import (
23
22
    bencode,
24
23
    errors,
 
24
    filters,
25
25
    generate_ids,
26
26
    osutils,
27
27
    progress,
28
28
    revision as _mod_revision,
29
 
    symbol_versioning,
 
29
    rules,
30
30
    tests,
31
31
    urlutils,
32
32
    )
1868
1868
        self.assertEqual([], list(target.iter_changes(revision_tree)))
1869
1869
        self.assertTrue(source.is_executable('file1-id'))
1870
1870
 
 
1871
    def install_rot13_content_filter(self, pattern):
 
1872
        original_registry = filters._reset_registry()
 
1873
        def restore_registry():
 
1874
            filters._reset_registry(original_registry)
 
1875
        self.addCleanup(restore_registry)
 
1876
        def rot13(chunks, context=None):
 
1877
            return [''.join(chunks).encode('rot13')]
 
1878
        rot13filter = filters.ContentFilter(rot13, rot13)
 
1879
        filters.register_filter_stack_map('rot13', {'yes': [rot13filter]}.get)
 
1880
        os.mkdir(self.test_home_dir + '/.bazaar')
 
1881
        rules_filename = self.test_home_dir + '/.bazaar/rules'
 
1882
        f = open(rules_filename, 'wb')
 
1883
        f.write('[name %s]\nrot13=yes\n' % (pattern,))
 
1884
        f.close()
 
1885
        def uninstall_rules():
 
1886
            os.remove(rules_filename)
 
1887
            rules.reset_rules()
 
1888
        self.addCleanup(uninstall_rules)
 
1889
        rules.reset_rules()
 
1890
 
 
1891
    def test_build_tree_content_filtered_files_are_not_hardlinked(self):
 
1892
        """build_tree will not hardlink files that have content filtering rules
 
1893
        applied to them (but will still hardlink other files from the same tree
 
1894
        if it can).
 
1895
        """
 
1896
        self.requireFeature(HardlinkFeature)
 
1897
        self.install_rot13_content_filter('file1')
 
1898
        source = self.create_ab_tree()
 
1899
        target = self.make_branch_and_tree('target')
 
1900
        revision_tree = source.basis_tree()
 
1901
        revision_tree.lock_read()
 
1902
        self.addCleanup(revision_tree.unlock)
 
1903
        build_tree(revision_tree, target, source, hardlink=True)
 
1904
        target.lock_read()
 
1905
        self.addCleanup(target.unlock)
 
1906
        self.assertEqual([], list(target.iter_changes(revision_tree)))
 
1907
        source_stat = os.stat('source/file1')
 
1908
        target_stat = os.stat('target/file1')
 
1909
        self.assertNotEqual(source_stat, target_stat)
 
1910
        source_stat = os.stat('source/file2')
 
1911
        target_stat = os.stat('target/file2')
 
1912
        self.assertEqualStat(source_stat, target_stat)
 
1913
 
1871
1914
    def test_case_insensitive_build_tree_inventory(self):
1872
1915
        if (tests.CaseInsensitiveFilesystemFeature.available()
1873
1916
            or tests.CaseInsCasePresFilenameFeature.available()):