From 4bb5107cff6f205f5c6e73a6f8bd22fc56f48cf4 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Thu, 7 Jul 2011 14:53:37 +0200 Subject: Initial version of the DulwichType inheritance. For now, it inherits everything from the existing implementation, but one by one things can be reimplmented to use dulwich. It also shows that py 2.6 is quite plagued from its new feature, which is actually a bug, as objects inability to accept any args makes mixins hard to use ... --- git/db/py/base.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'git/db/py/base.py') diff --git a/git/db/py/base.py b/git/db/py/base.py index 2c21c136..fb6e2f4a 100644 --- a/git/db/py/base.py +++ b/git/db/py/base.py @@ -104,7 +104,6 @@ class PureRootPathDB(RootPathDB): super(PureRootPathDB, self).__init__(root_path) - #{ Interface def root_path(self): return self._root_path @@ -233,7 +232,7 @@ class PureCompoundDB(CompoundDB, PureObjectDBR, LazyMixin, CachingDB): class PureRepositoryPathsMixin(RepositoryPathsMixin): # slots has no effect here, its just to keep track of used attrs - __slots__ = ("_git_path", '_bare') + __slots__ = ("_git_path", '_bare', '_working_tree_dir') #{ Configuration repo_dir = '.git' @@ -272,14 +271,16 @@ class PureRepositoryPathsMixin(RepositoryPathsMixin): raise InvalidGitRepositoryError(epath) # END path not found - self._bare = self._git_path.endswith(self.repo_dir) + self._bare = self._working_tree_dir is None if hasattr(self, 'config_reader'): try: self._bare = self.config_reader("repository").getboolean('core','bare') except Exception: # lets not assume the option exists, although it should pass + #END handle exception #END check bare flag + self._working_tree_dir = self._bare and None or self._working_tree_dir #} end subclass interface @@ -313,7 +314,7 @@ class PureRepositoryPathsMixin(RepositoryPathsMixin): @property def working_tree_dir(self): - if self.is_bare: + if self._working_tree_dir is None: raise AssertionError("Repository at %s is bare and does not have a working tree directory" % self.git_dir) #END assertion return dirname(self.git_dir) @@ -354,6 +355,10 @@ class PureConfigurationMixin(ConfigurationMixin): repo_config_file_name = "config" #} END + def __new__(cls, *args, **kwargs): + """This is just a stupid workaround for the evil py2.6 change which makes mixins quite impossible""" + return super(PureConfigurationMixin, cls).__new__(cls, *args, **kwargs) + def __init__(self, *args, **kwargs): """Verify prereqs""" try: @@ -421,7 +426,11 @@ class PureAlternatesFileMixin(object): #} END configuration def __init__(self, *args, **kwargs): - super(PureAlternatesFileMixin, self).__init__(*args, **kwargs) + try: + super(PureAlternatesFileMixin, self).__init__(*args, **kwargs) + except TypeError: + pass + #END handle py2.6 code breaking changes self._alternates_path() # throws on incompatible type #{ Interface -- cgit v1.2.1 From 6a10c8a82adcbe1f18c2e79a9135c7f5c753b826 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Thu, 7 Jul 2011 21:47:02 +0200 Subject: Removed cache in PureCompoundDB as it had the tendency to slow things down actually --- git/db/py/base.py | 46 +++++++++++++++++----------------------------- 1 file changed, 17 insertions(+), 29 deletions(-) (limited to 'git/db/py/base.py') diff --git a/git/db/py/base.py b/git/db/py/base.py index fb6e2f4a..49f28a8d 100644 --- a/git/db/py/base.py +++ b/git/db/py/base.py @@ -131,44 +131,33 @@ class PureCompoundDB(CompoundDB, PureObjectDBR, LazyMixin, CachingDB): def _set_cache_(self, attr): if attr == '_dbs': self._dbs = list() - elif attr == '_obj_cache': - self._obj_cache = dict() else: super(PureCompoundDB, self)._set_cache_(attr) - def _db_query(self, sha): - """:return: database containing the given 20 byte sha - :raise BadObject:""" - # most databases use binary representations, prevent converting - # it everytime a database is being queried - try: - return self._obj_cache[sha] - except KeyError: - pass - # END first level cache - - for db in self._dbs: - if db.has_object(sha): - self._obj_cache[sha] = db - return db - # END for each database - raise BadObject(sha) - #{ PureObjectDBR interface def has_object(self, sha): - try: - self._db_query(sha) - return True - except BadObject: - return False - # END handle exceptions + for db in self._dbs: + if db.has_object(sha): + return True + #END for each db + return False def info(self, sha): - return self._db_query(sha).info(sha) + for db in self._dbs: + try: + return db.info(sha) + except BadObject: + pass + #END for each db def stream(self, sha): - return self._db_query(sha).stream(sha) + for db in self._dbs: + try: + return db.stream(sha) + except BadObject: + pass + #END for each db def size(self): return reduce(lambda x,y: x+y, (db.size() for db in self._dbs), 0) @@ -185,7 +174,6 @@ class PureCompoundDB(CompoundDB, PureObjectDBR, LazyMixin, CachingDB): def update_cache(self, force=False): # something might have changed, clear everything - self._obj_cache.clear() stat = False for db in self._dbs: if isinstance(db, CachingDB): -- cgit v1.2.1