Rev 87: Remove cache usage. in http://people.samba.org/bzr/jelmer/bzr-git/trunk
Jelmer Vernooij
jelmer at samba.org
Sat Jul 26 19:46:06 BST 2008
At http://people.samba.org/bzr/jelmer/bzr-git/trunk
------------------------------------------------------------
revno: 87
revision-id: jelmer at samba.org-20080726184605-h3jtq9ceulnbbqr9
parent: jelmer at samba.org-20080726181231-qwbahvnx8gv5x7in
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: trunk
timestamp: Sat 2008-07-26 20:46:05 +0200
message:
Remove cache usage.
removed:
cache.py cache.py-20071230042306-i3pe0d9idcb273n5-1
modified:
git_repository.py git_repository.py-20071108234408-ygidvy5hviixghsd-2
=== removed file 'cache.py'
--- a/cache.py 2008-01-08 21:46:29 +0000
+++ b/cache.py 1970-01-01 00:00:00 +0000
@@ -1,69 +0,0 @@
-# Copyright (C) 2006-2007 Jelmer Vernooij <jelmer at samba.org>
-# 2007 David Allouche <ddaa at ddaa.net>
-
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-"""Git cache directory access."""
-
-# Shamelessly copied from bzr-svn.
-
-import os
-
-import bzrlib
-from bzrlib.config import config_dir, ensure_config_dir_exists
-from bzrlib.trace import warning
-
-
-def create_cache_dir():
- """Create the top-level bzr-git cache directory.
-
- :return: Path to cache directory.
- """
- ensure_config_dir_exists()
- cache_dir = os.path.join(config_dir(), 'git-cache')
-
- if not os.path.exists(cache_dir):
- os.mkdir(cache_dir)
-
- open(os.path.join(cache_dir, "README"), 'w').write(
-"""This directory contains information cached by the bzr-git plugin.
-
-It is used for performance reasons only and can be removed
-without losing data.
-
-""")
- return cache_dir
-
-
-def check_pysqlite_version(sqlite3):
- """Check that sqlite library is compatible.
-
- """
- if (sqlite3.sqlite_version_info[0] < 3 or
- (sqlite3.sqlite_version_info[0] == 3 and
- sqlite3.sqlite_version_info[1] < 3)):
- warning('Needs at least sqlite 3.3.x')
- raise bzrlib.errors.BzrError("incompatible sqlite library")
-
-try:
- try:
- import sqlite3
- check_pysqlite_version(sqlite3)
- except (ImportError, bzrlib.errors.BzrError), e:
- from pysqlite2 import dbapi2 as sqlite3
- check_pysqlite_version(sqlite3)
-except:
- warning('Needs at least Python2.5 or Python2.4 with the pysqlite2 '
- 'module')
- raise bzrlib.errors.BzrError("missing sqlite library")
=== modified file 'git_repository.py'
--- a/git_repository.py 2008-07-26 18:05:55 +0000
+++ b/git_repository.py 2008-07-26 18:46:05 +0000
@@ -40,9 +40,6 @@
)
-cachedbs = {}
-
-
class GitRepository(repository.Repository):
"""An adapter to git repositories for bzr."""
@@ -53,38 +50,15 @@
self.bzrdir = gitdir
self.control_files = lockfiles
self._git = git.repo.Repo(gitdir.root_transport.local_abspath("."))
- self._blob_cache = {}
- self._blob_info_cache = {}
cache_dir = cache.create_cache_dir()
cachedir_transport = get_transport(cache_dir)
cache_file = os.path.join(cache_dir, 'cache-%s' % ids.NAMESPACE)
- if not cachedbs.has_key(cache_file):
- cachedbs[cache_file] = cache.sqlite3.connect(cache_file)
- self.cachedb = cachedbs[cache_file]
- self._init_cachedb()
self.texts = None
self.signatures = versionedfile.VirtualSignatureTexts(self)
self.revisions = versionedfile.VirtualRevisionTexts(self)
self._format = GitFormat()
self._fallback_repositories = []
- def _init_cachedb(self):
- self.cachedb.executescript("""
- create table if not exists inventory (
- revid blob);
- create unique index if not exists inventory_revid
- on inventory (revid);
- create table if not exists entry_revision (
- inventory blob,
- path blob,
- gitid blob,
- executable integer,
- revision blob);
- create unique index if not exists entry_revision_revid_path
- on entry_revision (inventory, path);
- """)
- self.cachedb.commit()
-
def _all_revision_ids(self):
if self._git.heads == []:
return set()
@@ -186,114 +160,10 @@
return GitRevisionTree(self, revision_id)
- def _fetch_blob(self, git_id):
- lines = self._git.cat_file('blob', git_id)
- # print "fetched blob:", git_id
- if self._building_inventory is not None:
- self._building_inventory.git_file_data[git_id] = lines
- return lines
-
- def _get_blob(self, git_id):
- try:
- return self._blob_cache[git_id]
- except KeyError:
- return self._fetch_blob(git_id)
-
- def _get_blob_caching(self, git_id):
- try:
- return self._blob_cache[git_id]
- except KeyError:
- lines = self._fetch_blob(git_id)
- self._blob_cache[git_id] = lines
- return lines
-
- def _get_blob_info(self, git_id):
- try:
- return self._blob_info_cache[git_id]
- except KeyError:
- lines = self._get_blob(git_id)
- size = sum(len(line) for line in lines)
- sha1 = osutils.sha_strings(lines)
- self._blob_info_cache[git_id] = (size, sha1)
- return size, sha1
-
def get_inventory(self, revision_id):
assert revision_id != None
return self.revision_tree(revision_id).inventory
- def _set_entry_text_info(self, inv, entry, git_id):
- if entry.kind == 'directory':
- return
- size, sha1 = self._get_blob_info(git_id)
- entry.text_size = size
- entry.text_sha1 = sha1
- if entry.kind == 'symlink':
- lines = self._get_blob_caching(git_id)
- entry.symlink_target = ''.join(lines)
-
- def _get_file_revision(self, revision_id, path):
- lines = self._git.rev_list(
- [ids.convert_revision_id_bzr_to_git(revision_id)],
- max_count=1, topo_order=True, paths=[path])
- [line] = lines
- result = ids.convert_revision_id_git_to_bzr(line[:-1])
- # print "fetched file revision", line[:-1], path
- return result
-
- def _get_entry_revision_from_db(self, revid, path, git_id, executable):
- result = self.cachedb.execute(
- "select revision from entry_revision where"
- " inventory=? and path=? and gitid=? and executable=?",
- (revid, path, git_id, executable)).fetchone()
- if result is None:
- return None
- [revision] = result
- return revision
-
- def _set_entry_revision_in_db(self, revid, path, git_id, executable, revision):
- self.cachedb.execute(
- "insert into entry_revision"
- " (inventory, path, gitid, executable, revision)"
- " values (?, ?, ?, ?, ?)",
- (revid, path, git_id, executable, revision))
-
- def _all_inventories_in_db(self, revids):
- for revid in revids:
- result = self.cachedb.execute(
- "select count(*) from inventory where revid = ?",
- (revid,)).fetchone()
- if result is None:
- return False
- return True
-
- def _set_entry_revision(self, entry, revid, path, git_id):
- # If a revision is in the cache, we assume it contains entries for the
- # whole inventory. So if all parent revisions are in the cache, but no
- # parent entry is present, then the entry revision is the current
- # revision. That amortizes the number of _get_file_revision calls for
- # large pulls to a "small number".
- entry_rev = self._get_entry_revision_from_db(
- revid, path, git_id, entry.executable)
- if entry_rev is not None:
- entry.revision = entry_rev
- return
-
- revision = self.get_revision(revid)
- for parent_id in revision.parent_ids:
- entry_rev = self._get_entry_revision_from_db(
- parent_id, path, git_id, entry.executable)
- if entry_rev is not None:
- break
- else:
- if self._all_inventories_in_db(revision.parent_ids):
- entry_rev = revid
- else:
- entry_rev = self._get_file_revision(revid, path)
- self._set_entry_revision_in_db(
- revid, path, git_id, entry.executable, entry_rev)
- #self.cachedb.commit()
- entry.revision = entry_rev
-
def escape_file_id(file_id):
return file_id.replace('_', '__').replace(' ', '_s')
@@ -313,9 +183,9 @@
def get_revision_id(self):
return self.revision_id
- def get_file_lines(self, file_id):
+ def get_file_text(self, file_id):
entry = self._inventory[file_id]
- if entry.kind == 'directory': return []
+ if entry.kind == 'directory': return ""
git_id = self._inventory.git_ids[file_id]
if git_id in self._inventory.git_file_data:
return self._inventory.git_file_data[git_id]
More information about the bazaar-commits
mailing list