188
188
return format.open(transport)
191
class CacheUpdater(object):
193
def __init__(self, cache, rev, content_cache_types):
195
self.content_cache_types = content_cache_types
196
self.revid = rev.revision_id
197
self.parent_revids = rev.parent_ids
201
def add_object(self, obj, ie):
202
if obj.type_name == "commit":
205
elif obj.type_name in ("blob", "tree"):
206
if obj.type_name == "blob":
207
revision = ie.revision
209
revision = self.revid
210
self._entries.append((ie.file_id, obj.type_name, obj.id, revision))
213
if (self.cache.content_cache and
214
obj.type_name in self.content_cache_types):
215
self.cache.content_cache.add(obj)
218
if self._commit is None:
219
raise AssertionError("No commit object added")
220
self.cache.idmap.add_entries(self.revid, self.parent_revids,
221
self._commit.id, self._commit.tree, self._entries)
225
class BzrGitCache(object):
226
"""Caching backend."""
228
def __init__(self, idmap, content_cache):
230
self.content_cache = content_cache
232
def get_updater(self, rev, content_cache_types):
233
return CacheUpdater(self, rev, content_cache_types)
191
236
class DictGitShaMap(GitShaMap):
193
238
def __init__(self):
227
272
basepath = transport.local_abspath(".")
228
273
except bzrlib.errors.NotLocalUrl:
229
274
basepath = get_cache_dir()
230
return SqliteGitShaMap(os.path.join(get_cache_dir(), "idmap.db")), None
276
SqliteGitShaMap(os.path.join(get_cache_dir(), "idmap.db")),
233
280
class SqliteGitShaMap(GitShaMap):
364
411
except bzrlib.errors.NotLocalUrl:
365
412
basepath = get_cache_dir()
367
return (TdbGitShaMap(os.path.join(get_cache_dir(), "idmap.tdb")),
415
TdbGitShaMap(os.path.join(get_cache_dir(), "idmap.tdb")),
369
417
except ImportError:
370
418
raise ImportError(
417
465
def __repr__(self):
418
466
return "%s(%r)" % (self.__class__.__name__, self.path)
421
def from_repository(cls, repository):
423
transport = getattr(repository, "_transport", None)
424
if transport is not None:
425
return cls(os.path.join(transport.local_abspath("."), "shamap.tdb"))
426
except bzrlib.errors.NotLocalUrl:
428
return cls(os.path.join(get_cache_dir(), "remote.tdb"))
430
468
def lookup_commit(self, revid):
431
469
return sha_to_hex(self.db["commit\0" + revid][:20])