summaryrefslogtreecommitdiff
path: root/git/db.py
diff options
context:
space:
mode:
authorSebastian Thiel <byronimo@gmail.com>2010-11-25 18:10:33 +0100
committerSebastian Thiel <byronimo@gmail.com>2010-11-25 18:18:15 +0100
commitf8ce24a835cae8c623e2936bec2618a8855c605b (patch)
treed4c1d392579e24285381613a4ac1b7cc2d6b6fae /git/db.py
parent65747a216c67c3101c6ae2edaa8119d786b793cb (diff)
parent9004e3a1cf33110f2cbc458f1dc3259c930ad9b4 (diff)
downloadgitpython-f8ce24a835cae8c623e2936bec2618a8855c605b.tar.gz
-#######->WARNING<-####### Directory structure changed, see commit message
If you use git-python as a submodule of your own project, which alters the sys.path to import it, you will have to adjust your code to take the changed directory structure into consideration. Previously, you would put the path ./git-python/lib into your syspath. All modules moved one level up into the 'git' subdirectory, which means that the 'git-python' directory now contains the 'git' root package. To allow git to be found, add ./git-python into your path. To finalize your update, run the following commands git submodule update --init --recursive As there will be left-over directories, consider running git-clean
Diffstat (limited to 'git/db.py')
-rw-r--r--git/db.py61
1 files changed, 61 insertions, 0 deletions
diff --git a/git/db.py b/git/db.py
new file mode 100644
index 00000000..b1c65377
--- /dev/null
+++ b/git/db.py
@@ -0,0 +1,61 @@
+"""Module with our own gitdb implementation - it uses the git command"""
+from exc import (
+ GitCommandError,
+ BadObject
+ )
+
+from gitdb.base import (
+ OInfo,
+ OStream
+ )
+
+from gitdb.util import (
+ bin_to_hex,
+ hex_to_bin
+ )
+from gitdb.db import GitDB
+from gitdb.db import LooseObjectDB
+
+
+__all__ = ('GitCmdObjectDB', 'GitDB' )
+
+#class GitCmdObjectDB(CompoundDB, ObjectDBW):
+class GitCmdObjectDB(LooseObjectDB):
+ """A database representing the default git object store, which includes loose
+ objects, pack files and an alternates file
+
+ It will create objects only in the loose object database.
+ :note: for now, we use the git command to do all the lookup, just until he
+ have packs and the other implementations
+ """
+ def __init__(self, root_path, git):
+ """Initialize this instance with the root and a git command"""
+ super(GitCmdObjectDB, self).__init__(root_path)
+ self._git = git
+
+ def info(self, sha):
+ hexsha, typename, size = self._git.get_object_header(bin_to_hex(sha))
+ return OInfo(hex_to_bin(hexsha), typename, size)
+
+ def stream(self, sha):
+ """For now, all lookup is done by git itself"""
+ hexsha, typename, size, stream = self._git.stream_object_data(bin_to_hex(sha))
+ return OStream(hex_to_bin(hexsha), typename, size, stream)
+
+
+ # { Interface
+
+ def partial_to_complete_sha_hex(self, partial_hexsha):
+ """:return: Full binary 20 byte sha from the given partial hexsha
+ :raise AmbiguousObjectName:
+ :raise BadObject:
+ :note: currently we only raise BadObject as git does not communicate
+ AmbiguousObjects separately"""
+ try:
+ hexsha, typename, size = self._git.get_object_header(partial_hexsha)
+ return hex_to_bin(hexsha)
+ except (GitCommandError, ValueError):
+ raise BadObject(partial_hexsha)
+ # END handle exceptions
+
+ #} END interface