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/dulwich/complex.py | 59 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 git/db/dulwich/complex.py (limited to 'git/db/dulwich/complex.py') diff --git a/git/db/dulwich/complex.py b/git/db/dulwich/complex.py new file mode 100644 index 00000000..6c3645a4 --- /dev/null +++ b/git/db/dulwich/complex.py @@ -0,0 +1,59 @@ + +__all__ = ['DulwichGitODB', 'DulwichGitDB', 'DulwichCompatibilityGitDB'] + +from git.db.py.complex import PureGitODB +from git.db.py.base import ( + PureRepositoryPathsMixin, + PureConfigurationMixin, + PureIndexDB, + ) +from git.db.py.resolve import PureReferencesMixin +from git.db.py.transport import PureTransportDB +from git.db.py.submodule import PureSubmoduleDB + +from git.db.cmd.complex import CmdHighLevelRepository, GitCommandMixin +from git.db.compat import RepoCompatibilityInterfaceNoBare + +#from git.db.interface import ObjectDBW, ObjectDBR +from dulwich.repo import Repo as DulwichRepo + +import os + + +class DulwichGitODB(PureGitODB): + """A full fledged database to read and write object files from all kinds of sources.""" + + def __init__(self, objects_root): + """Initalize this instance""" + PureGitODB.__init__(self, objects_root) + self._dw_repo = DulwichRepo(self.working_dir) + + def __getattr__(self, attr): + try: + # supply LazyMixin with this call first + return super(DulwichGitODB, self).__getattr__(attr) + except AttributeError: + # now assume its on the dulwich repository ... for now + return getattr(self._dw_repo, attr) + #END handle attr + + +class DulwichGitDB( PureRepositoryPathsMixin, PureConfigurationMixin, + PureReferencesMixin, PureSubmoduleDB, + PureIndexDB, + PureTransportDB, # not fully implemented + GitCommandMixin, + CmdHighLevelRepository, + DulwichGitODB): # must come last, as it doesn't pass on __init__ with super + + + def __init__(self, root_path): + """Initialize ourselves on the .git directory, or the .git/objects directory.""" + PureRepositoryPathsMixin._initialize(self, root_path) + super(DulwichGitDB, self).__init__(self.objects_dir) + + +class DulwichCompatibilityGitDB(RepoCompatibilityInterfaceNoBare, DulwichGitDB): + """Basic dulwich compatibility database""" + pass + -- cgit v1.2.1 From 8b3b222565199eab67196a5ab840b9e2770bfc53 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Thu, 7 Jul 2011 19:34:25 +0200 Subject: Added default performance tests - these should help to measure something at least, which implicitly includes pack handling. For the pack specific tests to work, one would need a pack interface though, which is currently not planned to be specifically exposed --- git/db/dulwich/complex.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'git/db/dulwich/complex.py') diff --git a/git/db/dulwich/complex.py b/git/db/dulwich/complex.py index 6c3645a4..3fa7c1cd 100644 --- a/git/db/dulwich/complex.py +++ b/git/db/dulwich/complex.py @@ -26,7 +26,12 @@ class DulwichGitODB(PureGitODB): def __init__(self, objects_root): """Initalize this instance""" PureGitODB.__init__(self, objects_root) - self._dw_repo = DulwichRepo(self.working_dir) + if hasattr(self, 'working_dir'): + wd = self.working_dir + else: + wd = os.path.dirname(os.path.dirname(objects_root)) + #END try to figure out good entry for dulwich, which doesn't do an extensive search + self._dw_repo = DulwichRepo(wd) def __getattr__(self, attr): try: -- cgit v1.2.1 From 09064504e52a5ec8bfc4825a3176239b731380d2 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Thu, 7 Jul 2011 21:28:08 +0200 Subject: Added trivial implementation for info and stream methods - info is very inefficient, but can't help it. Basic repo tests don't work as dulwich ignores alternate files --- git/db/dulwich/complex.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'git/db/dulwich/complex.py') diff --git a/git/db/dulwich/complex.py b/git/db/dulwich/complex.py index 3fa7c1cd..e1dad01d 100644 --- a/git/db/dulwich/complex.py +++ b/git/db/dulwich/complex.py @@ -17,6 +17,10 @@ from git.db.compat import RepoCompatibilityInterfaceNoBare #from git.db.interface import ObjectDBW, ObjectDBR from dulwich.repo import Repo as DulwichRepo +from git.base import OInfo, OStream +from git.fun import type_id_to_type_map + +from cStringIO import StringIO import os @@ -42,6 +46,18 @@ class DulwichGitODB(PureGitODB): return getattr(self._dw_repo, attr) #END handle attr + #{ Object DBR + + def info(self, binsha): + type_id, uncomp_data = self._dw_repo.object_store.get_raw(binsha) + return OInfo(binsha, type_id_to_type_map[type_id], len(uncomp_data)) + + def stream(self, binsha): + type_id, uncomp_data = self._dw_repo.object_store.get_raw(binsha) + return OStream(binsha, type_id_to_type_map[type_id], len(uncomp_data), StringIO(uncomp_data)) + + #}END object dbr + class DulwichGitDB( PureRepositoryPathsMixin, PureConfigurationMixin, PureReferencesMixin, PureSubmoduleDB, -- cgit v1.2.1 From f4f330f8588dacd43af6513e1e1e1a50237da1e7 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Thu, 7 Jul 2011 23:37:04 +0200 Subject: Added store support. Now the basic object IO is implemented, which shall be enough for the first batch of work --- git/db/dulwich/complex.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'git/db/dulwich/complex.py') diff --git a/git/db/dulwich/complex.py b/git/db/dulwich/complex.py index e1dad01d..ad5b97a4 100644 --- a/git/db/dulwich/complex.py +++ b/git/db/dulwich/complex.py @@ -16,9 +16,10 @@ from git.db.compat import RepoCompatibilityInterfaceNoBare #from git.db.interface import ObjectDBW, ObjectDBR from dulwich.repo import Repo as DulwichRepo +from dulwich.objects import ShaFile from git.base import OInfo, OStream -from git.fun import type_id_to_type_map +from git.fun import type_id_to_type_map, type_to_type_id_map from cStringIO import StringIO import os @@ -57,7 +58,16 @@ class DulwichGitODB(PureGitODB): return OStream(binsha, type_id_to_type_map[type_id], len(uncomp_data), StringIO(uncomp_data)) #}END object dbr + + #{ Object DBW + + def store(self, istream): + obj = ShaFile.from_raw_string(type_to_type_id_map[istream.type], istream.read()) + self._dw_repo.object_store.add_object(obj) + istream.binsha = obj.sha().digest() + return istream + #}END object dbw class DulwichGitDB( PureRepositoryPathsMixin, PureConfigurationMixin, PureReferencesMixin, PureSubmoduleDB, -- cgit v1.2.1