summaryrefslogtreecommitdiff
path: root/lib/git
diff options
context:
space:
mode:
Diffstat (limited to 'lib/git')
-rw-r--r--lib/git/objects/base.py32
-rw-r--r--lib/git/odb/db.py22
-rw-r--r--lib/git/repo.py11
3 files changed, 41 insertions, 24 deletions
diff --git a/lib/git/objects/base.py b/lib/git/objects/base.py
index f7043199..446c4406 100644
--- a/lib/git/objects/base.py
+++ b/lib/git/objects/base.py
@@ -4,7 +4,7 @@
# This module is part of GitPython and is released under
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
import os
-from git.utils import LazyMixin, join_path_native
+from git.utils import LazyMixin, join_path_native, stream_copy
import utils
_assertion_msg_format = "Created object %r whose python type %r disagrees with the acutal git object type %r"
@@ -76,10 +76,11 @@ class Object(LazyMixin):
Retrieve object information
"""
if attr == "size":
- hexsha, typename, self.size = self.repo.git.get_object_header(self.sha)
+ typename, self.size = self.repo.odb.object_info(self.sha)
assert typename == self.type, _assertion_msg_format % (self.sha, typename, self.type)
elif attr == "data":
- hexsha, typename, self.size, self.data = self.repo.git.get_object_data(self.sha)
+ typename, self.size, stream = self.repo.odb.object(self.sha)
+ self.data = stream.read() # once we have an own odb, we can delay reading
assert typename == self.type, _assertion_msg_format % (self.sha, typename, self.type)
else:
super(Object,self)._set_cache_(attr)
@@ -121,24 +122,17 @@ class Object(LazyMixin):
@property
def data_stream(self):
- """
- Returns
- File Object compatible stream to the uncompressed raw data of the object
- """
- proc = self.repo.git.cat_file(self.type, self.sha, as_process=True)
- return utils.ProcessStreamAdapter(proc, "stdout")
+ """ :return: File Object compatible stream to the uncompressed raw data of the object
+ :note: returned streams must be read in order"""
+ type, size, stream = self.repo.odb.object(self.sha)
+ return stream
def stream_data(self, ostream):
- """
- Writes our data directly to the given output stream
-
- ``ostream``
- File object compatible stream object.
-
- Returns
- self
- """
- self.repo.git.cat_file(self.type, self.sha, output_stream=ostream)
+ """Writes our data directly to the given output stream
+ :param ostream: File object compatible stream object.
+ :return: self"""
+ type, size, istream = self.repo.odb.object(self.sha)
+ stream_copy(istream, ostream)
return self
diff --git a/lib/git/odb/db.py b/lib/git/odb/db.py
index c970410d..1d1d4c40 100644
--- a/lib/git/odb/db.py
+++ b/lib/git/odb/db.py
@@ -281,9 +281,27 @@ class ReferenceDB(CompoundDB):
"""A database consisting of database referred to in a file"""
-class GitObjectDB(CompoundDB, iObjectDBW):
+#class GitObjectDB(CompoundDB, iObjectDBW):
+class GitObjectDB(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."""
+ 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
+ """
+ __slots__ = ('_git', )
+ def __init__(self, root_path, git):
+ """Initialize this instance with the root and a git command"""
+ super(GitObjectDB, self).__init__(root_path)
+ self._git = git
+
+ def object_info(self, sha):
+ discard, type, size = self._git.get_object_header(sha)
+ return type, size
+
+ def object(self, sha):
+ """For now, all lookup is done by git itself"""
+ discard, type, size, stream = self._git.stream_object_data(sha)
+ return type, size, stream
diff --git a/lib/git/repo.py b/lib/git/repo.py
index 0bd2249c..1afb1eb7 100644
--- a/lib/git/repo.py
+++ b/lib/git/repo.py
@@ -13,7 +13,7 @@ from objects import *
from config import GitConfigParser
from remote import Remote
-from odb.db import LooseObjectDB
+from odb.db import GitObjectDB
import os
import sys
@@ -68,7 +68,7 @@ class Repo(object):
# represents the configuration level of a configuration file
config_level = ("system", "global", "repository")
- def __init__(self, path=None, odbt = LooseObjectDB):
+ def __init__(self, path=None, odbt = GitObjectDB):
""" Create a new Repo instance
:param path: is the path to either the root git directory or the bare git repo::
@@ -128,7 +128,12 @@ class Repo(object):
self.working_dir = self._working_tree_dir or self.git_dir
self.git = Git(self.working_dir)
- self.odb = odbt(os.path.join(self.git_dir, 'objects'))
+
+ # special handling, in special times
+ args = [os.path.join(self.git_dir, 'objects')]
+ if issubclass(odbt, GitObjectDB):
+ args.append(self.git)
+ self.odb = odbt(*args)
def __eq__(self, rhs):
if isinstance(rhs, Repo):