~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/repository_implementations/test_fileid_involved.py

  • Committer: Robert Collins
  • Date: 2007-07-04 08:08:13 UTC
  • mfrom: (2572 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2587.
  • Revision ID: robertc@robertcollins.net-20070704080813-wzebx0r88fvwj5rq
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005 by Canonical Ltd
 
1
# Copyright (C) 2005 Canonical Ltd
2
2
#
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
17
17
import os
18
18
import sys
19
19
 
20
 
from bzrlib.add import smart_add
21
20
from bzrlib.builtins import merge
22
 
from bzrlib.errors import IllegalPath
 
21
from bzrlib.errors import IllegalPath, NonAsciiRevisionId
23
22
from bzrlib.tests import TestSkipped
24
23
from bzrlib.tests.repository_implementations.test_repository import TestCaseWithRepository
25
24
from bzrlib.transform import TreeTransform
28
27
 
29
28
class FileIdInvolvedBase(TestCaseWithRepository):
30
29
 
31
 
    def touch(self,filename):
32
 
        f = file(filename,"a")
33
 
        f.write("appended line\n")
34
 
        f.close( )
 
30
    def touch(self, tree, filename):
 
31
        # use the trees transport to not depend on the tree's location or type.
 
32
        tree.bzrdir.root_transport.append_bytes(filename, "appended line\n")
35
33
 
36
34
    def compare_tree_fileids(self, branch, old_rev, new_rev):
37
35
        old_tree = self.branch.repository.revision_tree(old_rev)
89
87
 
90
88
        #-------- end A -----------
91
89
 
92
 
        d1 = main_branch.bzrdir.clone('branch1')
93
 
        b1 = d1.open_branch()
 
90
        bt1 = self.make_branch_and_tree('branch1')
 
91
        bt1.pull(main_branch)
 
92
        b1 = bt1.branch
94
93
        self.build_tree(["branch1/d"])
95
 
        bt1 = d1.open_workingtree()
96
94
        bt1.add(['d'], ['file-d'])
97
95
        bt1.commit("branch1, Commit one", rev_id="rev-E")
98
96
 
99
97
        #-------- end E -----------
100
98
 
101
 
        self.touch("main/a")
 
99
        self.touch(main_wt, "a")
102
100
        main_wt.commit("Commit two", rev_id="rev-B")
103
101
 
104
102
        #-------- end B -----------
105
103
 
106
 
        d2 = main_branch.bzrdir.clone('branch2')
107
 
        branch2_branch = d2.open_branch()
108
 
        bt2 = d2.open_workingtree()
 
104
        bt2 = self.make_branch_and_tree('branch2')
 
105
        bt2.pull(main_branch)
 
106
        branch2_branch = bt2.branch
109
107
        set_executability(bt2, 'b', True)
110
108
        bt2.commit("branch2, Commit one", rev_id="rev-J")
111
109
 
121
119
 
122
120
        #-------- end F -----------
123
121
 
124
 
        self.touch("branch2/c")
 
122
        self.touch(bt2, "c")
125
123
        bt2.commit("branch2, commit two", rev_id="rev-K")
126
124
 
127
125
        #-------- end K -----------
128
126
 
129
127
        main_wt.merge_from_branch(b1)
130
 
        self.touch("main/b")
 
128
        self.touch(main_wt, "b")
131
129
        # D gets some funky characters to make sure the unescaping works
132
130
        main_wt.commit("merge branch1, rev-12", rev_id="rev-<D>")
133
131
 
176
174
    def fileids_altered_by_revision_ids(self, revision_ids):
177
175
        """This is a wrapper to strip TREE_ROOT if it occurs"""
178
176
        repo = self.branch.repository
 
177
        root_id = self.branch.basis_tree().inventory.root.file_id
179
178
        result = repo.fileids_altered_by_revision_ids(revision_ids)
180
 
        if 'TREE_ROOT' in result:
181
 
            del result['TREE_ROOT']
 
179
        if root_id in result:
 
180
            del result[root_id]
182
181
        return result
183
182
 
184
183
    def test_fileids_altered_by_revision_ids(self):
222
221
                self.assertEquals(l1, l2)
223
222
 
224
223
 
 
224
class TestFileIdInvolvedNonAscii(FileIdInvolvedBase):
 
225
 
 
226
    def test_utf8_file_ids_and_revision_ids(self):
 
227
        main_wt = self.make_branch_and_tree('main')
 
228
        main_branch = main_wt.branch
 
229
        self.build_tree(["main/a"])
 
230
 
 
231
        file_id = u'a-f\xedle-id'.encode('utf8')
 
232
        main_wt.add(['a'], [file_id])
 
233
        revision_id = u'r\xe9v-a'.encode('utf8')
 
234
        try:
 
235
            main_wt.commit('a', rev_id=revision_id)
 
236
        except NonAsciiRevisionId:
 
237
            raise TestSkipped('non-ascii revision ids not supported by %s'
 
238
                              % self.repository_format)
 
239
 
 
240
        repo = main_wt.branch.repository
 
241
        file_ids = repo.fileids_altered_by_revision_ids([revision_id])
 
242
        root_id = main_wt.basis_tree().path2id('')
 
243
        if root_id in file_ids:
 
244
            self.assertEqual({file_id:set([revision_id]),
 
245
                              root_id:set([revision_id])
 
246
                             }, file_ids)
 
247
        else:
 
248
            self.assertEqual({file_id:set([revision_id])}, file_ids)
 
249
 
 
250
 
225
251
class TestFileIdInvolvedSuperset(FileIdInvolvedBase):
226
252
 
227
253
    def setUp(self):
247
273
            # This is not a known error condition
248
274
            raise
249
275
 
250
 
        branch2_bzrdir = main_branch.bzrdir.sprout("branch2")
 
276
        branch2_wt = self.make_branch_and_tree('branch2')
 
277
        branch2_wt.pull(main_branch)
 
278
        branch2_bzrdir = branch2_wt.bzrdir
251
279
        branch2_branch = branch2_bzrdir.open_branch()
252
 
        branch2_wt = branch2_bzrdir.open_workingtree()
253
280
        set_executability(branch2_wt, 'b', True)
254
281
        branch2_wt.commit("branch2, Commit one", rev_id="rev-J")
255
282