/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

Clean up trailing whitespace.

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.fileid_map.lookup_file_id(
54
 
            path.encode('utf-8'))
 
53
        self.file_id = self._inventory.mapping.generate_file_id(path.encode('utf-8'))
55
54
 
56
55
    @property
57
56
    def object(self):
76
75
 
77
76
    @property
78
77
    def text_sha1(self):
79
 
        return osutils.sha_strings(self.object.chunked)
 
78
        return osutils.sha_string(self.object.data)
80
79
 
81
80
    @property
82
81
    def text_size(self):
127
126
 
128
127
    def copy(self):
129
128
        other = inventory.InventoryLink(self.file_id, self.name, self.parent_id)
130
 
        other.executable = self.executable
131
129
        other.symlink_target = self.symlink_target
132
130
        other.revision = self.revision
133
131
        return other
179
177
        for mode, name, hexsha in self.object.entries():
180
178
            basename = name.decode("utf-8")
181
179
            child_path = osutils.pathjoin(self.path, basename)
182
 
            if self._inventory.mapping.is_control_file(child_path):
183
 
                continue
184
180
            executable = mode_is_executable(mode)
185
181
            kind_class = {'directory': GitInventoryDirectory,
186
182
                          'file': GitInventoryFile,
187
183
                          'symlink': GitInventoryLink,
188
184
                          'tree-reference': GitInventoryTreeReference}[mode_kind(mode)]
189
 
            self._children[basename] = kind_class(self._inventory,
190
 
                self.file_id, hexsha, child_path, basename, executable)
 
185
            self._children[basename] = kind_class(self._inventory, self.file_id, hexsha, child_path, basename, executable)
191
186
 
192
187
    def copy(self):
193
188
        other = inventory.InventoryDirectory(self.file_id, self.name,
200
195
 
201
196
class GitInventory(inventory.Inventory):
202
197
 
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):
 
198
    def __init__(self, tree_id, mapping, store, revision_id):
208
199
        super(GitInventory, self).__init__(revision_id=revision_id)
209
200
        self.store = store
210
 
        self.fileid_map = fileid_map
211
201
        self.mapping = mapping
212
202
        self.root = GitInventoryDirectory(self, None, tree_id, u"", u"", False)
213
203
 
214
204
    def _get_ie(self, path):
215
 
        if path == "" or path == []:
 
205
        if path == "":
216
206
            return self.root
217
 
        if isinstance(path, basestring):
218
 
            parts = path.split("/")
219
 
        else:
220
 
            parts = path
 
207
        parts = path.split("/")
221
208
        ie = self.root
222
209
        for name in parts:
223
210
            ie = ie.children[name]
238
225
            return False
239
226
 
240
227
    def id2path(self, file_id):
241
 
        path = self.fileid_map.lookup_path(file_id)
 
228
        path = self.mapping.parse_file_id(file_id)
242
229
        try:
243
230
            ie = self._get_ie(path)
244
231
            assert ie.path == path
254
241
    def __getitem__(self, file_id):
255
242
        if file_id == inventory.ROOT_ID:
256
243
            return self.root
257
 
        path = self.fileid_map.lookup_path(file_id)
 
244
        path = self.mapping.parse_file_id(file_id)
258
245
        try:
259
246
            return self._get_ie(path)
260
247
        except KeyError:
264
251
class GitIndexInventory(inventory.Inventory):
265
252
    """Inventory that retrieves its contents from an index file."""
266
253
 
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)
 
254
    def __init__(self, basis_inventory, mapping, index, store):
 
255
        super(GitIndexInventory, self).__init__(revision_id=None, root_id=basis_inventory.root.file_id)
276
256
        self.basis_inv = basis_inventory
277
 
        self.fileid_map = fileid_map
 
257
        self.mapping = mapping
278
258
        self.index = index
279
259
        self._contents_read = False
280
 
        self.store = store
281
260
        self.root = self.add_path("", 'directory',
282
 
            self.fileid_map.lookup_file_id(""), None)
 
261
            self.mapping.generate_file_id(""), None)
283
262
 
284
263
    def iter_entries_by_dir(self, specific_file_ids=None, yield_parents=False):
285
264
        self._read_contents()
286
 
        return super(GitIndexInventory, self).iter_entries_by_dir(
287
 
            specific_file_ids=specific_file_ids, yield_parents=yield_parents)
 
265
        return super(GitIndexInventory, self).iter_entries_by_dir(specific_file_ids=specific_file_ids, yield_parents=yield_parents)
288
266
 
289
267
    def has_id(self, file_id):
290
 
        if type(file_id) != str:
291
 
            raise AssertionError
292
268
        try:
293
269
            self.id2path(file_id)
294
270
            return True
302
278
        return super(GitIndexInventory, self).has_filename(path)
303
279
 
304
280
    def id2path(self, file_id):
305
 
        if type(file_id) != str:
306
 
            raise AssertionError
307
 
        path = self.fileid_map.lookup_path(file_id)
 
281
        path = self.mapping.parse_file_id(file_id)
308
282
        if path in self.index:
309
283
            return path
310
284
        self._read_contents()
311
285
        return super(GitIndexInventory, self).id2path(file_id)
312
286
 
313
287
    def path2id(self, path):
314
 
        if type(path) in (list, tuple):
315
 
            path = "/".join(path)
316
288
        if path in self.index:
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
 
289
            return self.mapping.generate_file_id(path)
 
290
        self._read_contents()
 
291
        return super(GitIndexInventory, self).path2id(path)
324
292
 
325
293
    def __getitem__(self, file_id):
326
294
        self._read_contents()
338
306
                assert isinstance(path, str)
339
307
                assert isinstance(value, tuple) and len(value) == 10
340
308
                (ctime, mtime, dev, ino, mode, uid, gid, size, sha, flags) = value
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:
 
309
                try:
 
310
                    old_ie = self.basis_inv._get_ie(path)
 
311
                except KeyError:
347
312
                    old_ie = None
348
313
                if old_ie is None:
349
 
                    file_id = self.fileid_map.lookup_file_id(path)
 
314
                    file_id = self.mapping.generate_file_id(path)
350
315
                else:
351
316
                    file_id = old_ie.file_id
352
 
                if type(file_id) != str:
353
 
                    raise AssertionError
354
317
                kind = mode_kind(mode)
355
318
                if old_ie is not None and old_ie.hexsha == sha:
356
319
                    # Hasn't changed since basis inv
359
322
                else:
360
323
                    ie = self.add_path(path, kind, file_id,
361
324
                        self.add_parents(path))
362
 
                    data = self.store[sha].data
 
325
                    data = store[sha].data
363
326
                    if kind == "symlink":
364
327
                        ie.symlink_target = data
365
328
                    else:
378
341
            else:
379
342
                parent_fid = self.add_parents(dirname)
380
343
            ie = self.add_path(dirname, 'directory',
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:
 
344
                    self.mapping.generate_file_id(dirname), parent_fid)
 
345
            if ie.file_id in self.basis_inv:
383
346
                ie.revision = self.basis_inv[ie.file_id].revision
384
347
            file_id = ie.file_id
385
 
        if type(file_id) != str:
386
 
            raise AssertionError
387
348
        return file_id
388
349