summaryrefslogtreecommitdiff
path: root/git/db/py
diff options
context:
space:
mode:
authorSebastian Thiel <byronimo@gmail.com>2011-05-30 01:23:28 +0200
committerSebastian Thiel <byronimo@gmail.com>2011-05-30 01:23:28 +0200
commit112bb1672d6b28f203e7839e320b985486636800 (patch)
tree755fb8dcab211678697f6e03cf37122592b7c573 /git/db/py
parent0996049122842a343e0ea7fbbecafddb2b4ba9d3 (diff)
downloadgitpython-112bb1672d6b28f203e7839e320b985486636800.tar.gz
Finished moving all repository methods to the respective interfaces and implementations. It seems theoretically work together now, although it clearly is much more complex than ever before.
The repo package was slimmed down to being a module once again, which is only there for compatability actually
Diffstat (limited to 'git/db/py')
-rw-r--r--git/db/py/base.py14
-rw-r--r--git/db/py/complex.py12
-rw-r--r--git/db/py/resolve.py26
3 files changed, 48 insertions, 4 deletions
diff --git a/git/db/py/base.py b/git/db/py/base.py
index cc326c27..74b8beb9 100644
--- a/git/db/py/base.py
+++ b/git/db/py/base.py
@@ -20,6 +20,7 @@ from git.util import (
is_git_dir
)
+from git.index import IndexFile
from git.config import GitConfigParser
from git.exc import (
BadObject,
@@ -35,7 +36,8 @@ import os
__all__ = ( 'PureObjectDBR', 'PureObjectDBW', 'PureRootPathDB', 'PureCompoundDB',
- 'PureConfigurationMixin', 'PureRepositoryPathsMixin', 'PureAlternatesFileMixin')
+ 'PureConfigurationMixin', 'PureRepositoryPathsMixin', 'PureAlternatesFileMixin',
+ 'PureIndexDB')
class PureObjectDBR(ObjectDBR):
@@ -386,6 +388,16 @@ class PureConfigurationMixin(ConfigurationMixin):
#} END interface
+class PureIndexDB(IndexDB):
+ #{ Configuration
+ IndexCls = IndexFile
+ #} END configuration
+
+ @property
+ def index(self):
+ return self.IndexCls(self)
+
+
class PureAlternatesFileMixin(object):
"""Utility able to read and write an alternates file through the alternates property
It needs to be part of a type with the git_dir or db_path property.
diff --git a/git/db/py/complex.py b/git/db/py/complex.py
index 6504b3ed..efcbb2ba 100644
--- a/git/db/py/complex.py
+++ b/git/db/py/complex.py
@@ -2,6 +2,7 @@
#
# This module is part of PureGitDB and is released under
# the New BSD License: http://www.opensource.org/licenses/bsd-license.php
+from git.db.interface import HighLevelRepository
from base import (
PureCompoundDB,
PureObjectDBW,
@@ -9,6 +10,7 @@ from base import (
PureRepositoryPathsMixin,
PureConfigurationMixin,
PureAlternatesFileMixin,
+ PureIndexDB,
)
from resolve import PureReferencesMixin
@@ -36,8 +38,7 @@ import os
__all__ = ('PureGitODB', 'PureGitDB', 'PureCompatibilityGitDB')
-class PureGitODB(PureRootPathDB, PureObjectDBW, PureCompoundDB,
- PureSubmoduleDB, PureAlternatesFileMixin):
+class PureGitODB(PureRootPathDB, PureObjectDBW, PureCompoundDB):
"""A git-style object-only database, which contains all objects in the 'objects'
subdirectory.
:note: The type needs to be initialized on the ./objects directory to function,
@@ -102,7 +103,12 @@ class PureGitODB(PureRootPathDB, PureObjectDBW, PureCompoundDB,
-class PureGitDB(PureGitODB, PureRepositoryPathsMixin, PureConfigurationMixin, PureReferencesMixin):
+class PureGitDB(PureGitODB,
+ PureRepositoryPathsMixin, PureConfigurationMixin,
+ PureReferencesMixin, PureSubmoduleDB, PureAlternatesFileMixin,
+ PureIndexDB,
+ # HighLevelRepository Currently not implemented !
+ ):
"""Git like database with support for object lookup as well as reference resolution.
Our rootpath is set to the actual .git directory (bare on unbare).
diff --git a/git/db/py/resolve.py b/git/db/py/resolve.py
index 94992d11..d0685747 100644
--- a/git/db/py/resolve.py
+++ b/git/db/py/resolve.py
@@ -5,6 +5,7 @@ from git.db.interface import ReferencesMixin
from git.exc import BadObject
from git.refs import SymbolicReference
from git.objects.base import Object
+from git.objects.commit import Commit
from git.refs.head import HEAD
from git.refs.headref import Head
from git.refs.tag import TagReference
@@ -290,6 +291,7 @@ class PureReferencesMixin(ReferencesMixin):
HeadCls = Head
ReferenceCls = Reference
HEADCls = HEAD
+ CommitCls = Commit
#} END configuration
def resolve(self, name):
@@ -313,6 +315,30 @@ class PureReferencesMixin(ReferencesMixin):
def tag(self, name):
return self.tags[name]
+
+ def commit(self, rev=None):
+ if rev is None:
+ return self.head.commit
+ else:
+ return self.resolve_object(str(rev)+"^0")
+ #END handle revision
+
+ def iter_trees(self, *args, **kwargs):
+ return ( c.tree for c in self.iter_commits(*args, **kwargs) )
+
+ def tree(self, rev=None):
+ if rev is None:
+ return self.head.commit.tree
+ else:
+ return self.resolve_object(str(rev)+"^{tree}")
+
+ def iter_commits(self, rev=None, paths='', **kwargs):
+ if rev is None:
+ rev = self.head.commit
+
+ return self.CommitCls.iter_items(self, rev, paths, **kwargs)
+
+
@property
def head(self):
return self.HEADCls(self,'HEAD')