/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

More work on roundtrip push support.

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(
 
53
        self.file_id = self._inventory.fileid_map.lookup_file_id(
54
54
            path.encode('utf-8'))
55
55
 
56
56
    @property
76
76
 
77
77
    @property
78
78
    def text_sha1(self):
79
 
        return osutils.sha_string(self.object.data)
 
79
        return osutils.sha_strings(self.object.chunked)
80
80
 
81
81
    @property
82
82
    def text_size(self):
179
179
        for mode, name, hexsha in self.object.entries():
180
180
            basename = name.decode("utf-8")
181
181
            child_path = osutils.pathjoin(self.path, basename)
 
182
            if self._inventory.mapping.is_control_file(child_path):
 
183
                continue
182
184
            executable = mode_is_executable(mode)
183
185
            kind_class = {'directory': GitInventoryDirectory,
184
186
                          'file': GitInventoryFile,
198
200
 
199
201
class GitInventory(inventory.Inventory):
200
202
 
201
 
    def __init__(self, tree_id, mapping, store, revision_id):
 
203
    def __repr__(self):
 
204
        return "<%s for %r in %r>" % (self.__class__.__name__,
 
205
                self.root.hexsha, self.store)
 
206
 
 
207
    def __init__(self, tree_id, mapping, fileid_map, store, revision_id):
202
208
        super(GitInventory, self).__init__(revision_id=revision_id)
203
209
        self.store = store
 
210
        self.fileid_map = fileid_map
204
211
        self.mapping = mapping
205
212
        self.root = GitInventoryDirectory(self, None, tree_id, u"", u"", False)
206
213
 
207
214
    def _get_ie(self, path):
208
 
        if path == "":
 
215
        if path == "" or path == []:
209
216
            return self.root
210
 
        parts = path.split("/")
 
217
        if isinstance(path, basestring):
 
218
            parts = path.split("/")
 
219
        else:
 
220
            parts = path
211
221
        ie = self.root
212
222
        for name in parts:
213
223
            ie = ie.children[name]
228
238
            return False
229
239
 
230
240
    def id2path(self, file_id):
231
 
        path = self.mapping.parse_file_id(file_id)
 
241
        path = self.fileid_map.lookup_path(file_id)
232
242
        try:
233
243
            ie = self._get_ie(path)
234
244
            assert ie.path == path
244
254
    def __getitem__(self, file_id):
245
255
        if file_id == inventory.ROOT_ID:
246
256
            return self.root
247
 
        path = self.mapping.parse_file_id(file_id)
 
257
        path = self.fileid_map.lookup_path(file_id)
248
258
        try:
249
259
            return self._get_ie(path)
250
260
        except KeyError:
254
264
class GitIndexInventory(inventory.Inventory):
255
265
    """Inventory that retrieves its contents from an index file."""
256
266
 
257
 
    def __init__(self, basis_inventory, mapping, index, store):
258
 
        super(GitIndexInventory, self).__init__(revision_id=None, root_id=basis_inventory.root.file_id)
 
267
    def __repr__(self):
 
268
        return "<%s for %r>" % (self.__class__.__name__, self.index)
 
269
 
 
270
    def __init__(self, basis_inventory, fileid_map, index, store):
 
271
        if basis_inventory is None:
 
272
            root_id = None
 
273
        else:
 
274
            root_id = basis_inventory.root.file_id
 
275
        super(GitIndexInventory, self).__init__(revision_id=None, root_id=root_id)
259
276
        self.basis_inv = basis_inventory
260
 
        self.mapping = mapping
 
277
        self.fileid_map = fileid_map
261
278
        self.index = index
262
279
        self._contents_read = False
263
280
        self.store = store
264
281
        self.root = self.add_path("", 'directory',
265
 
            self.mapping.generate_file_id(""), None)
 
282
            self.fileid_map.lookup_file_id(""), None)
266
283
 
267
284
    def iter_entries_by_dir(self, specific_file_ids=None, yield_parents=False):
268
285
        self._read_contents()
287
304
    def id2path(self, file_id):
288
305
        if type(file_id) != str:
289
306
            raise AssertionError
290
 
        path = self.mapping.parse_file_id(file_id)
 
307
        path = self.fileid_map.lookup_path(file_id)
291
308
        if path in self.index:
292
309
            return path
293
310
        self._read_contents()
294
311
        return super(GitIndexInventory, self).id2path(file_id)
295
312
 
296
313
    def path2id(self, path):
 
314
        if type(path) in (list, tuple):
 
315
            path = "/".join(path)
297
316
        if path in self.index:
298
 
            return self.mapping.generate_file_id(path)
299
 
        self._read_contents()
300
 
        return super(GitIndexInventory, self).path2id(path)
 
317
            file_id = self.fileid_map.lookup_file_id(path)
 
318
        else:
 
319
            self._read_contents()
 
320
            file_id = super(GitIndexInventory, self).path2id(path)
 
321
        if file_id is not None and type(file_id) is not str:
 
322
            raise AssertionError
 
323
        return file_id
301
324
 
302
325
    def __getitem__(self, file_id):
303
326
        self._read_contents()
315
338
                assert isinstance(path, str)
316
339
                assert isinstance(value, tuple) and len(value) == 10
317
340
                (ctime, mtime, dev, ino, mode, uid, gid, size, sha, flags) = value
318
 
                try:
319
 
                    old_ie = self.basis_inv._get_ie(path)
320
 
                except KeyError:
 
341
                if self.basis_inv is not None:
 
342
                    try:
 
343
                        old_ie = self.basis_inv._get_ie(path)
 
344
                    except KeyError:
 
345
                        old_ie = None
 
346
                else:
321
347
                    old_ie = None
322
348
                if old_ie is None:
323
 
                    file_id = self.mapping.generate_file_id(path)
 
349
                    file_id = self.fileid_map.lookup_file_id(path)
324
350
                else:
325
351
                    file_id = old_ie.file_id
326
352
                if type(file_id) != str:
352
378
            else:
353
379
                parent_fid = self.add_parents(dirname)
354
380
            ie = self.add_path(dirname, 'directory',
355
 
                    self.mapping.generate_file_id(dirname), parent_fid)
356
 
            if ie.file_id in self.basis_inv:
 
381
                    self.fileid_map.lookup_file_id(dirname), parent_fid)
 
382
            if self.basis_inv is not None and ie.file_id in self.basis_inv:
357
383
                ie.revision = self.basis_inv[ie.file_id].revision
358
384
            file_id = ie.file_id
359
385
        if type(file_id) != str: