/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to inventory.py

Fix some more tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
50
50
        self.path = path
51
51
        self.revision = self._inventory.revision_id
52
52
        self.executable = executable
53
 
        self.file_id = self._inventory.mapping.generate_file_id(path.encode('utf-8'))
 
53
        self.file_id = self._inventory.fileid_map.lookup_file_id(
 
54
            path.encode('utf-8'))
54
55
 
55
56
    @property
56
57
    def object(self):
67
68
    _git_class = Blob
68
69
 
69
70
    def __init__(self, inv, parent_id, hexsha, path, basename, executable):
70
 
        super(GitInventoryFile, self).__init__(inv, parent_id, hexsha, path, basename, executable)
 
71
        super(GitInventoryFile, self).__init__(inv, parent_id, hexsha, path,
 
72
            basename, executable)
71
73
        self.kind = 'file'
72
74
        self.text_id = None
73
75
        self.symlink_target = None
74
76
 
75
77
    @property
76
78
    def text_sha1(self):
77
 
        return osutils.sha_string(self.object.data)
 
79
        return osutils.sha_strings(self.object.chunked)
78
80
 
79
81
    @property
80
82
    def text_size(self):
95
97
        return ''
96
98
 
97
99
    def copy(self):
98
 
        other = inventory.InventoryFile(self.file_id, self.name, self.parent_id)
 
100
        other = inventory.InventoryFile(self.file_id, self.name,
 
101
            self.parent_id)
99
102
        other.executable = self.executable
100
103
        other.text_id = self.text_id
101
104
        other.text_sha1 = self.text_sha1
124
127
 
125
128
    def copy(self):
126
129
        other = inventory.InventoryLink(self.file_id, self.name, self.parent_id)
 
130
        other.executable = self.executable
127
131
        other.symlink_target = self.symlink_target
128
132
        other.revision = self.revision
129
133
        return other
175
179
        for mode, name, hexsha in self.object.entries():
176
180
            basename = name.decode("utf-8")
177
181
            child_path = osutils.pathjoin(self.path, basename)
 
182
            if self._inventory.mapping.is_control_file(child_path):
 
183
                continue
178
184
            executable = mode_is_executable(mode)
179
185
            kind_class = {'directory': GitInventoryDirectory,
180
186
                          'file': GitInventoryFile,
181
187
                          'symlink': GitInventoryLink,
182
188
                          'tree-reference': GitInventoryTreeReference}[mode_kind(mode)]
183
 
            self._children[basename] = kind_class(self._inventory, self.file_id, hexsha, child_path, basename, executable)
 
189
            self._children[basename] = kind_class(self._inventory,
 
190
                self.file_id, hexsha, child_path, basename, executable)
184
191
 
185
192
    def copy(self):
186
 
        other = inventory.InventoryDirectory(self.file_id, self.name, 
 
193
        other = inventory.InventoryDirectory(self.file_id, self.name,
187
194
                                             self.parent_id)
188
195
        other.revision = self.revision
189
196
        # note that children are *not* copied; they're pulled across when
193
200
 
194
201
class GitInventory(inventory.Inventory):
195
202
 
196
 
    def __init__(self, tree_id, mapping, store, revision_id):
 
203
    def __init__(self, tree_id, mapping, fileid_map, store, revision_id):
197
204
        super(GitInventory, self).__init__(revision_id=revision_id)
198
205
        self.store = store
 
206
        self.fileid_map = fileid_map
199
207
        self.mapping = mapping
200
208
        self.root = GitInventoryDirectory(self, None, tree_id, u"", u"", False)
201
209
 
205
213
        parts = path.split("/")
206
214
        ie = self.root
207
215
        for name in parts:
208
 
            ie = ie.children[name] 
 
216
            ie = ie.children[name]
209
217
        return ie
210
218
 
211
219
    def has_filename(self, path):
223
231
            return False
224
232
 
225
233
    def id2path(self, file_id):
226
 
        path = self.mapping.parse_file_id(file_id)
 
234
        path = self.fileid_map.lookup_path(file_id)
227
235
        try:
228
236
            ie = self._get_ie(path)
229
237
            assert ie.path == path
239
247
    def __getitem__(self, file_id):
240
248
        if file_id == inventory.ROOT_ID:
241
249
            return self.root
242
 
        path = self.mapping.parse_file_id(file_id)
 
250
        path = self.fileid_map.lookup_path(file_id)
243
251
        try:
244
252
            return self._get_ie(path)
245
253
        except KeyError:
249
257
class GitIndexInventory(inventory.Inventory):
250
258
    """Inventory that retrieves its contents from an index file."""
251
259
 
252
 
    def __init__(self, basis_inventory, mapping, index, store):
 
260
    def __init__(self, basis_inventory, fileid_map, index, store):
253
261
        super(GitIndexInventory, self).__init__(revision_id=None, root_id=basis_inventory.root.file_id)
254
262
        self.basis_inv = basis_inventory
255
 
        self.mapping = mapping
 
263
        self.fileid_map = fileid_map
256
264
        self.index = index
257
265
        self._contents_read = False
258
 
        self.root = self.add_path("", 'directory', 
259
 
            self.mapping.generate_file_id(""), None)
 
266
        self.store = store
 
267
        self.root = self.add_path("", 'directory',
 
268
            self.fileid_map.lookup_file_id(""), None)
260
269
 
261
270
    def iter_entries_by_dir(self, specific_file_ids=None, yield_parents=False):
262
271
        self._read_contents()
263
 
        return super(GitIndexInventory, self).iter_entries_by_dir(specific_file_ids=specific_file_ids, yield_parents=yield_parents)
 
272
        return super(GitIndexInventory, self).iter_entries_by_dir(
 
273
            specific_file_ids=specific_file_ids, yield_parents=yield_parents)
264
274
 
265
275
    def has_id(self, file_id):
 
276
        if type(file_id) != str:
 
277
            raise AssertionError
266
278
        try:
267
279
            self.id2path(file_id)
268
280
            return True
276
288
        return super(GitIndexInventory, self).has_filename(path)
277
289
 
278
290
    def id2path(self, file_id):
279
 
        path = self.mapping.parse_file_id(file_id)
 
291
        if type(file_id) != str:
 
292
            raise AssertionError
 
293
        path = self.fileid_map.lookup_path(file_id)
280
294
        if path in self.index:
281
295
            return path
282
296
        self._read_contents()
284
298
 
285
299
    def path2id(self, path):
286
300
        if path in self.index:
287
 
            return self.mapping.generate_file_id(path)
 
301
            return self.fileid_map.lookup_file_id(path)
288
302
        self._read_contents()
289
303
        return super(GitIndexInventory, self).path2id(path)
290
304
 
299
313
        pb = ui.ui_factory.nested_progress_bar()
300
314
        try:
301
315
            for i, (path, value) in enumerate(self.index.iteritems()):
302
 
                pb.update("creating working inventory from index", 
 
316
                pb.update("creating working inventory from index",
303
317
                        i, len(self.index))
304
318
                assert isinstance(path, str)
305
319
                assert isinstance(value, tuple) and len(value) == 10
309
323
                except KeyError:
310
324
                    old_ie = None
311
325
                if old_ie is None:
312
 
                    file_id = self.mapping.generate_file_id(path)
 
326
                    file_id = self.fileid_map.lookup_file_id(path)
313
327
                else:
314
328
                    file_id = old_ie.file_id
 
329
                if type(file_id) != str:
 
330
                    raise AssertionError
315
331
                kind = mode_kind(mode)
316
332
                if old_ie is not None and old_ie.hexsha == sha:
317
333
                    # Hasn't changed since basis inv
318
334
                    self.add_parents(path)
319
335
                    self.add(old_ie)
320
336
                else:
321
 
                    ie = self.add_path(path, kind, file_id, self.add_parents(path))
322
 
                    data = store[sha].data
 
337
                    ie = self.add_path(path, kind, file_id,
 
338
                        self.add_parents(path))
 
339
                    data = self.store[sha].data
323
340
                    if kind == "symlink":
324
341
                        ie.symlink_target = data
325
342
                    else:
337
354
                parent_fid = None
338
355
            else:
339
356
                parent_fid = self.add_parents(dirname)
340
 
            ie = self.add_path(dirname, 'directory', 
341
 
                    self.mapping.generate_file_id(dirname), parent_fid)
 
357
            ie = self.add_path(dirname, 'directory',
 
358
                    self.fileid_map.lookup_file_id(dirname), parent_fid)
342
359
            if ie.file_id in self.basis_inv:
343
360
                ie.revision = self.basis_inv[ie.file_id].revision
344
361
            file_id = ie.file_id
 
362
        if type(file_id) != str:
 
363
            raise AssertionError
345
364
        return file_id
346
365