diff options
author | Sebastian Thiel <byronimo@gmail.com> | 2010-06-18 16:20:27 +0200 |
---|---|---|
committer | Sebastian Thiel <byronimo@gmail.com> | 2010-06-18 16:20:27 +0200 |
commit | b82dbf538ac0d03968a0f5b7e2318891abefafaa (patch) | |
tree | 3ee7f95497cba4bdfc19c65e5677f7b0489affb8 | |
parent | e837b901dcfac82e864f806c80f4a9cbfdb9c9f3 (diff) | |
download | gitpython-b82dbf538ac0d03968a0f5b7e2318891abefafaa.tar.gz |
GitCmd implementation of gitdb base moved to git-python where it belongs. Previously it was located in gitdb, which doesn't have any facilities to use the git command
-rw-r--r-- | lib/git/db.py | 33 | ||||
m--------- | lib/git/ext/gitdb | 0 | ||||
-rw-r--r-- | lib/git/repo.py | 6 | ||||
-rw-r--r-- | lib/git/utils.py | 16 |
4 files changed, 51 insertions, 4 deletions
diff --git a/lib/git/db.py b/lib/git/db.py new file mode 100644 index 00000000..4e860bb6 --- /dev/null +++ b/lib/git/db.py @@ -0,0 +1,33 @@ +"""Module with our own gitdb implementation - it uses the git command""" +from gitdb.base import ( + OInfo, + OStream + ) + +from gitdb.db import LooseObjectDB + +__all__ = ('GitCmdObjectDB', ) + +#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): + t = self._git.get_object_header(sha) + return OInfo(*t) + + def stream(self, sha): + """For now, all lookup is done by git itself""" + t = self._git.stream_object_data(sha) + return OStream(*t) + diff --git a/lib/git/ext/gitdb b/lib/git/ext/gitdb -Subproject 099ec0dbd23bf46cba7618768e628ceeac7c2e1 +Subproject 3cee78ed377b0a73febdbd772ddba2999313023 diff --git a/lib/git/repo.py b/lib/git/repo.py index 85f12300..72f7ba06 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 gitdb import GitObjectDB +from db import GitCmdObjectDB 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 = GitObjectDB): + def __init__(self, path=None, odbt = GitCmdObjectDB): """ Create a new Repo instance :param path: is the path to either the root git directory or the bare git repo:: @@ -131,7 +131,7 @@ class Repo(object): # special handling, in special times args = [os.path.join(self.git_dir, 'objects')] - if issubclass(odbt, GitObjectDB): + if issubclass(odbt, GitCmdObjectDB): args.append(self.git) self.odb = odbt(*args) diff --git a/lib/git/utils.py b/lib/git/utils.py index bd7cc0f3..3fb7fbf8 100644 --- a/lib/git/utils.py +++ b/lib/git/utils.py @@ -10,7 +10,6 @@ import time import tempfile from gitdb.util import ( - stream_copy, make_sha, FDStreamWrapper, LockedFD, @@ -19,6 +18,21 @@ from gitdb.util import ( ) +def stream_copy(source, destination, chunk_size=512*1024): + """Copy all data from the source stream into the destination stream in chunks + of size chunk_size + + :return: amount of bytes written""" + br = 0 + while True: + chunk = source.read(chunk_size) + destination.write(chunk) + br += len(chunk) + if len(chunk) < chunk_size: + break + # END reading output stream + return br + def join_path(a, *p): """Join path tokens together similar to os.path.join, but always use '/' instead of possibly '\' on windows.""" |