~ubuntu-branches/debian/jessie/bzr-git/jessie

« back to all changes in this revision

Viewing changes to object_store.py

  • Committer: Bazaar Package Importer
  • Author(s): Jelmer Vernooij
  • Date: 2010-07-31 00:18:45 UTC
  • mfrom: (1.1.11 upstream) (8.1.5 sid)
  • Revision ID: james.westby@ubuntu.com-20100731001845-su2xo23q9xdqdcyu
* New upstream release.
* Bump standards version to 3.9.1.

Show diffs side-by-side

added added

removed removed

Lines of Context:
43
43
    mapping_registry,
44
44
    symlink_to_blob,
45
45
    )
46
 
from bzrlib.plugins.git.shamap import (
 
46
from bzrlib.plugins.git.cache import (
47
47
    from_repository as cache_from_repository,
48
48
    )
49
49
 
71
71
        self._cache = lru_cache.LRUSizeCache(max_size=MAX_TREE_CACHE_SIZE,
72
72
            after_cleanup_size=None, compute_size=approx_tree_size)
73
73
 
74
 
    def revision_tree(self, revid):            
 
74
    def revision_tree(self, revid):
75
75
        try:
76
 
            return self._cache[revid] 
 
76
            return self._cache[revid]
77
77
        except KeyError:
78
78
            tree = self.repository.revision_tree(revid)
79
79
            self.add(tree)
142
142
            expected_sha))
143
143
 
144
144
 
145
 
def _tree_to_objects(tree, parent_trees, idmap, unusual_modes, dummy_file_name=None):
 
145
def _tree_to_objects(tree, parent_trees, idmap, unusual_modes,
 
146
                     dummy_file_name=None):
146
147
    """Iterate over the objects that were introduced in a revision.
147
148
 
148
149
    :param idmap: id map
149
 
    :param unusual_modes: Unusual file modes
 
150
    :param parent_trees: Parent revision trees
 
151
    :param unusual_modes: Unusual file modes dictionary
150
152
    :param dummy_file_name: File name to use for dummy files
151
153
        in empty directories. None to skip empty directories
152
154
    :return: Yields (path, object, ie) entries
173
175
                    pie.symlink_target == ie.symlink_target):
174
176
                    return pie
175
177
        raise KeyError
 
178
 
 
179
    # Find all the changed blobs
176
180
    for (file_id, path, changed_content, versioned, parent, name, kind,
177
181
         executable) in tree.iter_changes(base_tree):
178
182
        if kind[1] == "file":
206
210
            new_trees[posixpath.dirname(path[1])] = parent[1]
207
211
        elif kind[1] not in (None, "directory"):
208
212
            raise AssertionError(kind[1])
209
 
        if path[0] is not None:
 
213
        if path[0] is not None and parent[0] in tree.inventory and tree.inventory[parent[0]].kind == "directory":
 
214
            # Removal
210
215
            new_trees[posixpath.dirname(path[0])] = parent[0]
211
216
    
 
217
    # Fetch contents of the blobs that were changed
212
218
    for (path, ie), chunks in tree.iter_files_bytes(
213
219
        [(ie.file_id, (path, ie)) for (path, ie) in new_blobs]):
214
220
        obj = Blob()
225
231
        items = new_trees.items()
226
232
        new_trees = {}
227
233
        for path, file_id in items:
228
 
            try:
229
 
                parent_id = tree.inventory[file_id].parent_id
230
 
            except errors.NoSuchId:
231
 
                # Directory was removed recursively perhaps ?
232
 
                continue
 
234
            parent_id = tree.inventory[file_id].parent_id
233
235
            if parent_id is not None:
234
236
                parent_path = urlutils.dirname(path)
235
237
                new_trees[parent_path] = parent_id
396
398
        updater = self._get_updater(rev)
397
399
        for path, obj, ie in self._revision_to_objects(rev, tree,
398
400
            roundtrip=True):
399
 
            updater.add_object(obj, ie)
 
401
            updater.add_object(obj, ie, path)
400
402
        commit_obj = updater.finish()
401
403
        return commit_obj.id
402
404
 
500
502
            if type == "commit":
501
503
                return self.repository.has_revision(type_data[0])
502
504
            elif type == "blob":
503
 
                return self.repository.texts.has_version(type_data)
 
505
                return self.repository.texts.has_key(type_data)
504
506
            elif type == "tree":
505
507
                return self.repository.has_revision(type_data[1])
506
508
            else:
509
511
            return False
510
512
 
511
513
    def lookup_git_shas(self, shas, update_map=True):
 
514
        from dulwich.protocol import ZERO_SHA
512
515
        ret = {}
513
516
        for sha in shas:
 
517
            if sha == ZERO_SHA:
 
518
                ret[sha] = NULL_REVISION
 
519
                continue
514
520
            try:
515
521
                ret[sha] = self._cache.idmap.lookup_git_sha(sha)
516
522
            except KeyError: