/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

  • Committer: Jelmer Vernooij
  • Date: 2009-09-10 13:13:15 UTC
  • mto: (0.200.602 trunk)
  • mto: This revision was merged to the branch mainline in revision 6960.
  • Revision ID: jelmer@samba.org-20090910131315-6890xg58pl2jseml
Allow serving remote URLs.

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