aboutsummaryrefslogtreecommitdiff
path: root/git/objects
diff options
context:
space:
mode:
Diffstat (limited to 'git/objects')
-rw-r--r--git/objects/base.py68
-rw-r--r--git/objects/blob.py8
-rw-r--r--git/objects/commit.py267
-rw-r--r--git/objects/fun.py2
-rw-r--r--git/objects/submodule/__init__.py4
-rw-r--r--git/objects/submodule/base.py41
-rw-r--r--git/objects/submodule/root.py5
-rw-r--r--git/objects/submodule/util.py4
-rw-r--r--git/objects/tag.py26
-rw-r--r--git/objects/tree.py25
-rw-r--r--git/objects/util.py1
11 files changed, 264 insertions, 187 deletions
diff --git a/git/objects/base.py b/git/objects/base.py
index 5f2f7809..61b3e674 100644
--- a/git/objects/base.py
+++ b/git/objects/base.py
@@ -3,15 +3,20 @@
#
# This module is part of GitPython and is released under
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
-from git.util import LazyMixin, join_path_native, stream_copy
+
from util import get_object_type_by_name
-from gitdb.util import (
+from git.util import (
hex_to_bin,
bin_to_hex,
- basename
+ dirname,
+ basename,
+ LazyMixin,
+ join_path_native,
+ stream_copy
)
-
-import gitdb.typ as dbtyp
+from git.db.interface import RepositoryPathsMixin
+from git.exc import UnsupportedOperation
+from git.typ import ObjectType
_assertion_msg_format = "Created object %r whose python type %r disagrees with the acutal git object type %r"
@@ -22,24 +27,26 @@ class Object(LazyMixin):
NULL_HEX_SHA = '0'*40
NULL_BIN_SHA = '\0'*20
- TYPES = (dbtyp.str_blob_type, dbtyp.str_tree_type, dbtyp.str_commit_type, dbtyp.str_tag_type)
- __slots__ = ("repo", "binsha", "size" )
+ TYPES = (ObjectType.blob, ObjectType.tree, ObjectType.commit, ObjectType.tag)
+ __slots__ = ("odb", "binsha", "size" )
+
type = None # to be set by subclass
+ type_id = None # to be set by subclass
- def __init__(self, repo, binsha):
+ def __init__(self, odb, binsha):
"""Initialize an object by identifying it by its binary sha.
All keyword arguments will be set on demand if None.
- :param repo: repository this object is located in
+ :param odb: repository this object is located in
:param binsha: 20 byte SHA1"""
super(Object,self).__init__()
- self.repo = repo
+ self.odb = odb
self.binsha = binsha
assert len(binsha) == 20, "Require 20 byte binary sha, got %r, len = %i" % (binsha, len(binsha))
@classmethod
- def new(cls, repo, id):
+ def new(cls, odb, id):
"""
:return: New Object instance of a type appropriate to the object type behind
id. The id of the newly created object will be a binsha even though
@@ -49,27 +56,27 @@ class Object(LazyMixin):
:note: This cannot be a __new__ method as it would always call __init__
with the input id which is not necessarily a binsha."""
- return repo.rev_parse(str(id))
+ return odb.rev_parse(str(id))
@classmethod
- def new_from_sha(cls, repo, sha1):
+ def new_from_sha(cls, odb, sha1):
"""
:return: new object instance of a type appropriate to represent the given
binary sha1
:param sha1: 20 byte binary sha1"""
if sha1 == cls.NULL_BIN_SHA:
# the NULL binsha is always the root commit
- return get_object_type_by_name('commit')(repo, sha1)
+ return get_object_type_by_name('commit')(odb, sha1)
#END handle special case
- oinfo = repo.odb.info(sha1)
- inst = get_object_type_by_name(oinfo.type)(repo, oinfo.binsha)
+ oinfo = odb.info(sha1)
+ inst = get_object_type_by_name(oinfo.type)(odb, oinfo.binsha)
inst.size = oinfo.size
return inst
def _set_cache_(self, attr):
"""Retrieve object information"""
if attr == "size":
- oinfo = self.repo.odb.info(self.binsha)
+ oinfo = self.odb.info(self.binsha)
self.size = oinfo.size
# assert oinfo.type == self.type, _assertion_msg_format % (self.binsha, oinfo.type, self.type)
else:
@@ -77,10 +84,14 @@ class Object(LazyMixin):
def __eq__(self, other):
""":return: True if the objects have the same SHA1"""
+ if not hasattr(other, 'binsha'):
+ return False
return self.binsha == other.binsha
def __ne__(self, other):
""":return: True if the objects do not have the same SHA1 """
+ if not hasattr(other, 'binsha'):
+ return True
return self.binsha != other.binsha
def __hash__(self):
@@ -104,13 +115,13 @@ class Object(LazyMixin):
def data_stream(self):
""" :return: File Object compatible stream to the uncompressed raw data of the object
:note: returned streams must be read in order"""
- return self.repo.odb.stream(self.binsha)
+ return self.odb.stream(self.binsha)
def stream_data(self, ostream):
"""Writes our data directly to the given output stream
:param ostream: File object compatible stream object.
:return: self"""
- istream = self.repo.odb.stream(self.binsha)
+ istream = self.odb.stream(self.binsha)
stream_copy(istream, ostream)
return self
@@ -123,9 +134,9 @@ class IndexObject(Object):
# for compatability with iterable lists
_id_attribute_ = 'path'
- def __init__(self, repo, binsha, mode=None, path=None):
+ def __init__(self, odb, binsha, mode=None, path=None):
"""Initialize a newly instanced IndexObject
- :param repo: is the Repo we are located in
+ :param odb: is the object database we are located in
:param binsha: 20 byte sha1
:param mode: is the stat compatible file mode as int, use the stat module
to evaluate the infomration
@@ -135,7 +146,7 @@ class IndexObject(Object):
:note:
Path may not be set of the index object has been created directly as it cannot
be retrieved without knowing the parent tree."""
- super(IndexObject, self).__init__(repo, binsha)
+ super(IndexObject, self).__init__(odb, binsha)
if mode is not None:
self.mode = mode
if path is not None:
@@ -167,6 +178,15 @@ class IndexObject(Object):
Absolute path to this index object in the file system ( as opposed to the
.path field which is a path relative to the git repository ).
- The returned path will be native to the system and contains '\' on windows. """
- return join_path_native(self.repo.working_tree_dir, self.path)
+ The returned path will be native to the system and contains '\' on windows.
+ :raise UnsupportedOperation: if underlying odb does not support the required method to obtain a working dir"""
+ # TODO: Here we suddenly need something better than a plain object database
+ # which indicates our odb should better be named repo !
+ root = ''
+ if isinstance(self.odb, RepositoryPathsMixin):
+ root = self.odb.working_tree_dir
+ else:
+ raise UnsupportedOperation("Cannot provide absolute path from a database without Repository path support")
+ #END handle odb type
+ return join_path_native(root, self.path)
diff --git a/git/objects/blob.py b/git/objects/blob.py
index f52d1a53..9c51f99f 100644
--- a/git/objects/blob.py
+++ b/git/objects/blob.py
@@ -4,15 +4,19 @@
# This module is part of GitPython and is released under
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
+from git.util import RepoAliasMixin
from mimetypes import guess_type
+from git.typ import ObjectType
+
import base
__all__ = ('Blob', )
-class Blob(base.IndexObject):
+class Blob(base.IndexObject, RepoAliasMixin):
"""A Blob encapsulates a git blob object"""
DEFAULT_MIME_TYPE = "text/plain"
- type = "blob"
+ type = ObjectType.blob
+ type_id = ObjectType.blob_id
# valid blob modes
executable_mode = 0100755
diff --git a/git/objects/commit.py b/git/objects/commit.py
index fd4187b0..c32bbf1a 100644
--- a/git/objects/commit.py
+++ b/git/objects/commit.py
@@ -3,42 +3,45 @@
#
# This module is part of GitPython and is released under
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
+import base
-from git.util import (
- Actor,
- Iterable,
- Stats,
- )
-from git.diff import Diffable
+from git.typ import ObjectType
from tree import Tree
-from gitdb import IStream
from cStringIO import StringIO
-import base
-from gitdb.util import (
- hex_to_bin
+from git.util import (
+ hex_to_bin,
+ Actor,
+ RepoAliasMixin,
+ Iterable,
+ Actor,
+ Stats
)
+
from util import (
- Traversable,
- Serializable,
- parse_date,
- altz_to_utctz_str,
- parse_actor_and_date
- )
-from time import (
- time,
- altzone
+ Traversable,
+ Serializable,
+ altz_to_utctz_str,
+ parse_actor_and_date
)
+from git.diff import Diffable
+from git.base import IStream
+from cStringIO import StringIO
+
+from util import parse_date
+from time import altzone, time
+
import os
import sys
__all__ = ('Commit', )
-class Commit(base.Object, Iterable, Diffable, Traversable, Serializable):
+class Commit(Diffable, Iterable, RepoAliasMixin, base.Object, Traversable, Serializable):
"""Wraps a git Commit object.
This class will act lazily on some of its attributes and will query the
value on demand only if it involves calling the git binary."""
+ __slots__ = tuple()
# ENVIRONMENT VARIABLES
# read when creating new commits
@@ -53,92 +56,16 @@ class Commit(base.Object, Iterable, Diffable, Traversable, Serializable):
# object configuration
- type = "commit"
+ type = ObjectType.commit
+ type_id = ObjectType.commit_id
+
__slots__ = ("tree",
"author", "authored_date", "author_tz_offset",
"committer", "committed_date", "committer_tz_offset",
"message", "parents", "encoding")
_id_attribute_ = "binsha"
- def __init__(self, repo, binsha, tree=None, author=None, authored_date=None, author_tz_offset=None,
- committer=None, committed_date=None, committer_tz_offset=None,
- message=None, parents=None, encoding=None):
- """Instantiate a new Commit. All keyword arguments taking None as default will
- be implicitly set on first query.
-
- :param binsha: 20 byte sha1
- :param parents: tuple( Commit, ... )
- is a tuple of commit ids or actual Commits
- :param tree: Tree
- Tree object
- :param author: Actor
- is the author string ( will be implicitly converted into an Actor object )
- :param authored_date: int_seconds_since_epoch
- is the authored DateTime - use time.gmtime() to convert it into a
- different format
- :param author_tz_offset: int_seconds_west_of_utc
- is the timezone that the authored_date is in
- :param committer: Actor
- is the committer string
- :param committed_date: int_seconds_since_epoch
- is the committed DateTime - use time.gmtime() to convert it into a
- different format
- :param committer_tz_offset: int_seconds_west_of_utc
- is the timezone that the authored_date is in
- :param message: string
- is the commit message
- :param encoding: string
- encoding of the message, defaults to UTF-8
- :param parents:
- List or tuple of Commit objects which are our parent(s) in the commit
- dependency graph
- :return: git.Commit
-
- :note: Timezone information is in the same format and in the same sign
- as what time.altzone returns. The sign is inverted compared to git's
- UTC timezone."""
- super(Commit,self).__init__(repo, binsha)
- if tree is not None:
- assert isinstance(tree, Tree), "Tree needs to be a Tree instance, was %s" % type(tree)
- if tree is not None:
- self.tree = tree
- if author is not None:
- self.author = author
- if authored_date is not None:
- self.authored_date = authored_date
- if author_tz_offset is not None:
- self.author_tz_offset = author_tz_offset
- if committer is not None:
- self.committer = committer
- if committed_date is not None:
- self.committed_date = committed_date
- if committer_tz_offset is not None:
- self.committer_tz_offset = committer_tz_offset
- if message is not None:
- self.message = message
- if parents is not None:
- self.parents = parents
- if encoding is not None:
- self.encoding = encoding
-
- @classmethod
- def _get_intermediate_items(cls, commit):
- return commit.parents
-
- def _set_cache_(self, attr):
- if attr in Commit.__slots__:
- # read the data in a chunk, its faster - then provide a file wrapper
- binsha, typename, self.size, stream = self.repo.odb.stream(self.binsha)
- self._deserialize(StringIO(stream.read()))
- else:
- super(Commit, self)._set_cache_(attr)
- # END handle attrs
-
- @property
- def summary(self):
- """:return: First line of the commit message"""
- return self.message.split('\n', 1)[0]
-
+
def count(self, paths='', **kwargs):
"""Count the number of commits reachable from this commit
@@ -225,33 +152,6 @@ class Commit(base.Object, Iterable, Diffable, Traversable, Serializable):
text = self.repo.git.diff(self.parents[0].hexsha, self.hexsha, '--', numstat=True)
return Stats._list_from_string(self.repo, text)
- @classmethod
- def _iter_from_process_or_stream(cls, repo, proc_or_stream):
- """Parse out commit information into a list of Commit objects
- We expect one-line per commit, and parse the actual commit information directly
- from our lighting fast object database
-
- :param proc: git-rev-list process instance - one sha per line
- :return: iterator returning Commit objects"""
- stream = proc_or_stream
- if not hasattr(stream,'readline'):
- stream = proc_or_stream.stdout
-
- readline = stream.readline
- while True:
- line = readline()
- if not line:
- break
- hexsha = line.strip()
- if len(hexsha) > 40:
- # split additional information, as returned by bisect for instance
- hexsha, rest = line.split(None, 1)
- # END handle extra info
-
- assert len(hexsha) == 40, "Invalid line: %s" % hexsha
- yield Commit(repo, hex_to_bin(hexsha))
- # END for each line in stream
-
@classmethod
def create_from_tree(cls, repo, tree, message, parent_commits=None, head=False):
@@ -361,6 +261,112 @@ class Commit(base.Object, Iterable, Diffable, Traversable, Serializable):
# END advance head handling
return new_commit
+
+ def __init__(self, odb, binsha, tree=None, author=None, authored_date=None, author_tz_offset=None,
+ committer=None, committed_date=None, committer_tz_offset=None,
+ message=None, parents=None, encoding=None):
+ """Instantiate a new Commit. All keyword arguments taking None as default will
+ be implicitly set on first query.
+
+ :param binsha: 20 byte sha1
+ :param parents: tuple( Commit, ... )
+ is a tuple of commit ids or actual Commits
+ :param tree: Tree
+ Tree object
+ :param author: Actor
+ is the author string ( will be implicitly converted into an Actor object )
+ :param authored_date: int_seconds_since_epoch
+ is the authored DateTime - use time.gmtime() to convert it into a
+ different format
+ :param author_tz_offset: int_seconds_west_of_utc
+ is the timezone that the authored_date is in
+ :param committer: Actor
+ is the committer string
+ :param committed_date: int_seconds_since_epoch
+ is the committed DateTime - use time.gmtime() to convert it into a
+ different format
+ :param committer_tz_offset: int_seconds_west_of_utc
+ is the timezone that the authored_date is in
+ :param message: string
+ is the commit message
+ :param encoding: string
+ encoding of the message, defaults to UTF-8
+ :param parents:
+ List or tuple of Commit objects which are our parent(s) in the commit
+ dependency graph
+ :return: git.Commit
+
+ :note: Timezone information is in the same format and in the same sign
+ as what time.altzone returns. The sign is inverted compared to git's
+ UTC timezone."""
+ super(Commit,self).__init__(odb, binsha)
+ if tree is not None:
+ assert isinstance(tree, Tree), "Tree needs to be a Tree instance, was %s" % type(tree)
+ if tree is not None:
+ self.tree = tree
+ if author is not None:
+ self.author = author
+ if authored_date is not None:
+ self.authored_date = authored_date
+ if author_tz_offset is not None:
+ self.author_tz_offset = author_tz_offset
+ if committer is not None:
+ self.committer = committer
+ if committed_date is not None:
+ self.committed_date = committed_date
+ if committer_tz_offset is not None:
+ self.committer_tz_offset = committer_tz_offset
+ if message is not None:
+ self.message = message
+ if parents is not None:
+ self.parents = parents
+ if encoding is not None:
+ self.encoding = encoding
+
+ @classmethod
+ def _get_intermediate_items(cls, commit):
+ return commit.parents
+
+ def _set_cache_(self, attr):
+ if attr in Commit.__slots__:
+ # read the data in a chunk, its faster - then provide a file wrapper
+ binsha, typename, self.size, stream = self.odb.stream(self.binsha)
+ self._deserialize(StringIO(stream.read()))
+ else:
+ super(Commit, self)._set_cache_(attr)
+ # END handle attrs
+
+ @property
+ def summary(self):
+ """:return: First line of the commit message"""
+ return self.message.split('\n', 1)[0]
+
+ @classmethod
+ def _iter_from_process_or_stream(cls, odb, proc_or_stream):
+ """Parse out commit information into a list of Commit objects
+ We expect one-line per commit, and parse the actual commit information directly
+ from our lighting fast object database
+
+ :param proc: git-rev-list process instance - one sha per line
+ :return: iterator returning Commit objects"""
+ stream = proc_or_stream
+ if not hasattr(stream,'readline'):
+ stream = proc_or_stream.stdout
+
+ readline = stream.readline
+ while True:
+ line = readline()
+ if not line:
+ break
+ hexsha = line.strip()
+ if len(hexsha) > 40:
+ # split additional information, as returned by bisect for instance
+ hexsha, rest = line.split(None, 1)
+ # END handle extra info
+
+ assert len(hexsha) == 40, "Invalid line: %s" % hexsha
+ yield cls(odb, hex_to_bin(hexsha))
+ # END for each line in stream
#{ Serializable Implementation
@@ -408,7 +414,7 @@ class Commit(base.Object, Iterable, Diffable, Traversable, Serializable):
""":param from_rev_list: if true, the stream format is coming from the rev-list command
Otherwise it is assumed to be a plain data stream from our object"""
readline = stream.readline
- self.tree = Tree(self.repo, hex_to_bin(readline().split()[1]), Tree.tree_id<<12, '')
+ self.tree = Tree(self.odb, hex_to_bin(readline().split()[1]), Tree.tree_id<<12, '')
self.parents = list()
next_line = None
@@ -418,7 +424,7 @@ class Commit(base.Object, Iterable, Diffable, Traversable, Serializable):
next_line = parent_line
break
# END abort reading parents
- self.parents.append(type(self)(self.repo, hex_to_bin(parent_line.split()[-1])))
+ self.parents.append(type(self)(self.odb, hex_to_bin(parent_line.split()[-1])))
# END for each parent line
self.parents = tuple(self.parents)
@@ -461,5 +467,6 @@ class Commit(base.Object, Iterable, Diffable, Traversable, Serializable):
print >> sys.stderr, "Failed to decode message '%s' using encoding %s" % (self.message, self.encoding)
# END exception handling
return self
-
+
#} END serializable implementation
+
diff --git a/git/objects/fun.py b/git/objects/fun.py
index 9b0a377c..6f2eaaad 100644
--- a/git/objects/fun.py
+++ b/git/objects/fun.py
@@ -1,4 +1,5 @@
"""Module with functions which are supposed to be as fast as possible"""
+
from stat import S_ISDIR
__all__ = ('tree_to_stream', 'tree_entries_from_data', 'traverse_trees_recursive',
@@ -197,3 +198,4 @@ def traverse_tree_recursive(odb, tree_sha, path_prefix):
# END for each item
return entries
+
diff --git a/git/objects/submodule/__init__.py b/git/objects/submodule/__init__.py
index 82df59b0..c8bf2d49 100644
--- a/git/objects/submodule/__init__.py
+++ b/git/objects/submodule/__init__.py
@@ -1,2 +1,6 @@
+# Copyright (C) 2010, 2011 Sebastian Thiel (byronimo@gmail.com) and contributors
+#
+# This module is part of GitDB and is released under
+# the New BSD License: http://www.opensource.org/licenses/bsd-license.php
# NOTE: Cannot import anything here as the top-level _init_ has to handle
# our dependencies
diff --git a/git/objects/submodule/base.py b/git/objects/submodule/base.py
index 2160299b..0fdb121d 100644
--- a/git/objects/submodule/base.py
+++ b/git/objects/submodule/base.py
@@ -1,3 +1,8 @@
+# Copyright (C) 2010, 2011 Sebastian Thiel (byronimo@gmail.com) and contributors
+#
+# This module is part of GitDB and is released under
+# the New BSD License: http://www.opensource.org/licenses/bsd-license.php
+from git.util import RepoAliasMixin
import util
from util import (
mkhead,
@@ -13,9 +18,10 @@ from git.util import (
Iterable,
join_path_native,
to_native_path_linux,
- RemoteProgress
)
+from git.db.interface import RemoteProgress
+
from git.config import SectionConstraint
from git.exc import (
InvalidGitRepositoryError,
@@ -23,7 +29,7 @@ from git.exc import (
)
import stat
-import git
+import git # we use some types indirectly to prevent cyclic imports !
import os
import sys
@@ -53,7 +59,7 @@ UPDWKTREE = UpdateProgress.UPDWKTREE
# IndexObject comes via util module, its a 'hacky' fix thanks to pythons import
# mechanism which cause plenty of trouble of the only reason for packages and
# modules is refactoring - subpackages shoudn't depend on parent packages
-class Submodule(util.IndexObject, Iterable, Traversable):
+class Submodule(util.IndexObject, Iterable, Traversable, RepoAliasMixin):
"""Implements access to a git submodule. They are special in that their sha
represents a commit in the submodule's repository which is to be checked out
at the path of this instance.
@@ -71,6 +77,9 @@ class Submodule(util.IndexObject, Iterable, Traversable):
# this is a bogus type for base class compatability
type = 'submodule'
+ # this type doesn't really have a type id
+ type_id = 0
+
__slots__ = ('_parent_commit', '_url', '_branch_path', '_name', '__weakref__')
_cache_attrs = ('path', '_url', '_branch_path')
@@ -195,7 +204,7 @@ class Submodule(util.IndexObject, Iterable, Traversable):
#{ Edit Interface
@classmethod
- def add(cls, repo, name, path, url=None, branch=None, no_checkout=False):
+ def add(cls, repo, name, path, url=None, branch=None, no_checkout=False, repoType=None):
"""Add a new submodule to the given repository. This will alter the index
as well as the .gitmodules file, but will not create a new commit.
If the submodule already exists, no matter if the configuration differs
@@ -220,6 +229,8 @@ class Submodule(util.IndexObject, Iterable, Traversable):
Examples are 'master' or 'feature/new'
:param no_checkout: if True, and if the repository has to be cloned manually,
no checkout will be performed
+ :param repoType: The repository type to use. It must provide the clone_from method.
+ If None, the default implementation is used.
:return: The newly created submodule instance
:note: works atomically, such that no change will be done if the repository
update fails for instance"""
@@ -227,6 +238,8 @@ class Submodule(util.IndexObject, Iterable, Traversable):
raise InvalidGitRepositoryError("Cannot add submodules to bare repositories")
# END handle bare repos
+ repoType = repoType or git.Repo
+
path = to_native_path_linux(path)
if path.endswith('/'):
path = path[:-1]
@@ -280,7 +293,7 @@ class Submodule(util.IndexObject, Iterable, Traversable):
if not branch_is_default:
kwargs['b'] = br.name
# END setup checkout-branch
- mrepo = git.Repo.clone_from(url, path, **kwargs)
+ mrepo = repoType.clone_from(url, path, **kwargs)
# END verify url
# update configuration and index
@@ -306,7 +319,7 @@ class Submodule(util.IndexObject, Iterable, Traversable):
return sm
def update(self, recursive=False, init=True, to_latest_revision=False, progress=None,
- dry_run=False):
+ dry_run=False, ):
"""Update the repository of this submodule to point to the checkout
we point at with the binsha of this instance.
@@ -368,7 +381,6 @@ class Submodule(util.IndexObject, Iterable, Traversable):
if not init:
return self
# END early abort if init is not allowed
- import git
# there is no git-repository yet - but delete empty paths
module_path = join_path_native(self.repo.working_tree_dir, self.path)
@@ -384,7 +396,7 @@ class Submodule(util.IndexObject, Iterable, Traversable):
# branch according to the remote-HEAD if possible
progress.update(BEGIN|CLONE, 0, 1, prefix+"Cloning %s to %s in submodule %r" % (self.url, module_path, self.name))
if not dry_run:
- mrepo = git.Repo.clone_from(self.url, module_path, n=True)
+ mrepo = type(self.repo).clone_from(self.url, module_path, n=True)
#END handle dry-run
progress.update(END|CLONE, 0, 1, prefix+"Done cloning to %s" % module_path)
@@ -760,14 +772,19 @@ class Submodule(util.IndexObject, Iterable, Traversable):
#{ Query Interface
@unbare_repo
- def module(self):
- """:return: Repo instance initialized from the repository at our submodule path
+ def module(self, repoType=None):
+ """:return: Repository instance initialized from the repository at our submodule path
+ :param repoType: The type of repository to be created. It must be possible to instatiate it
+ from a single repository path.
+ If None, a default repository type will be used
:raise InvalidGitRepositoryError: if a repository was not available. This could
also mean that it was not yet initialized"""
# late import to workaround circular dependencies
- module_path = self.abspath
+ module_path = self.abspath
+ repoType = repoType or git.Repo
+
try:
- repo = git.Repo(module_path)
+ repo = repoType(module_path)
if repo != self.repo:
return repo
# END handle repo uninitialized
diff --git a/git/objects/submodule/root.py b/git/objects/submodule/root.py
index 132604f6..5e4cad2d 100644
--- a/git/objects/submodule/root.py
+++ b/git/objects/submodule/root.py
@@ -1,3 +1,7 @@
+# Copyright (C) 2010, 2011 Sebastian Thiel (byronimo@gmail.com) and contributors
+#
+# This module is part of GitDB and is released under
+# the New BSD License: http://www.opensource.org/licenses/bsd-license.php
from base import Submodule, UpdateProgress
from util import (
find_first_remote_branch
@@ -24,6 +28,7 @@ BRANCHCHANGE = RootUpdateProgress.BRANCHCHANGE
URLCHANGE = RootUpdateProgress.URLCHANGE
PATHCHANGE = RootUpdateProgress.PATHCHANGE
+
class RootModule(Submodule):
"""A (virtual) Root of all submodules in the given repository. It can be used
to more easily traverse all submodules of the master repository"""
diff --git a/git/objects/submodule/util.py b/git/objects/submodule/util.py
index 9b32807a..2c5f6bc1 100644
--- a/git/objects/submodule/util.py
+++ b/git/objects/submodule/util.py
@@ -1,3 +1,7 @@
+# Copyright (C) 2010, 2011 Sebastian Thiel (byronimo@gmail.com) and contributors
+#
+# This module is part of GitDB and is released under
+# the New BSD License: http://www.opensource.org/licenses/bsd-license.php
import git
from git.exc import InvalidGitRepositoryError
from git.config import GitConfigParser
diff --git a/git/objects/tag.py b/git/objects/tag.py
index c7d02abe..5dcd9bf9 100644
--- a/git/objects/tag.py
+++ b/git/objects/tag.py
@@ -5,24 +5,28 @@
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
""" Module containing all object based types. """
import base
-from gitdb.util import hex_to_bin
+from git.util import RepoAliasMixin
+from git.util import hex_to_bin
from util import (
- get_object_type_by_name,
- parse_actor_and_date
- )
+ get_object_type_by_name,
+ parse_actor_and_date
+ )
+from git.typ import ObjectType
__all__ = ("TagObject", )
-class TagObject(base.Object):
+class TagObject(base.Object, RepoAliasMixin):
"""Non-Lightweight tag carrying additional information about an object we are pointing to."""
- type = "tag"
+ type = ObjectType.tag
+ type_id = ObjectType.tag_id
+
__slots__ = ( "object", "tag", "tagger", "tagged_date", "tagger_tz_offset", "message" )
- def __init__(self, repo, binsha, object=None, tag=None,
+ def __init__(self, odb, binsha, object=None, tag=None,
tagger=None, tagged_date=None, tagger_tz_offset=None, message=None):
"""Initialize a tag object with additional data
- :param repo: repository this object is located in
+ :param odb: repository this object is located in
:param binsha: 20 byte SHA1
:param object: Object instance of object we are pointing to
:param tag: name of this tag
@@ -32,7 +36,7 @@ class TagObject(base.Object):
it into a different format
:param tagged_tz_offset: int_seconds_west_of_utc is the timezone that the
authored_date is in, in a format similar to time.altzone"""
- super(TagObject, self).__init__(repo, binsha )
+ super(TagObject, self).__init__(odb, binsha )
if object is not None:
self.object = object
if tag is not None:
@@ -49,12 +53,12 @@ class TagObject(base.Object):
def _set_cache_(self, attr):
"""Cache all our attributes at once"""
if attr in TagObject.__slots__:
- ostream = self.repo.odb.stream(self.binsha)
+ ostream = self.odb.stream(self.binsha)
lines = ostream.read().splitlines()
obj, hexsha = lines[0].split(" ") # object <hexsha>
type_token, type_name = lines[1].split(" ") # type <type_name>
- self.object = get_object_type_by_name(type_name)(self.repo, hex_to_bin(hexsha))
+ self.object = get_object_type_by_name(type_name)(self.odb, hex_to_bin(hexsha))
self.tag = lines[2][4:] # tag <tag name>
diff --git a/git/objects/tree.py b/git/objects/tree.py
index 67431686..31f2602d 100644
--- a/git/objects/tree.py
+++ b/git/objects/tree.py
@@ -3,21 +3,23 @@
#
# This module is part of GitPython and is released under
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
-import util
+from git.util import RepoAliasMixin
+import git.diff as diff
+from git.typ import ObjectType
from base import IndexObject
-from git.util import join_path
from blob import Blob
from submodule.base import Submodule
-import git.diff as diff
from fun import (
tree_entries_from_data,
tree_to_stream
)
-from gitdb.util import (
- to_bin_sha,
+from git.util import (
+ to_bin_sha,
+ join_path
)
+import util
__all__ = ("TreeModifier", "Tree")
@@ -100,7 +102,7 @@ class TreeModifier(object):
#} END mutators
-class Tree(IndexObject, diff.Diffable, util.Traversable, util.Serializable):
+class Tree(IndexObject, diff.Diffable, util.Traversable, util.Serializable, RepoAliasMixin):
"""Tree objects represent an ordered list of Blobs and other Trees.
``Tree as a list``::
@@ -112,7 +114,9 @@ class Tree(IndexObject, diff.Diffable, util.Traversable, util.Serializable):
blob = tree[0]
"""
- type = "tree"
+ type = ObjectType.tree
+ type_id = ObjectType.tree_id
+
__slots__ = "_cache"
# actual integer ids for comparison
@@ -121,6 +125,9 @@ class Tree(IndexObject, diff.Diffable, util.Traversable, util.Serializable):
symlink_id = 012
tree_id = 004
+ #{ Configuration
+
+ # override in subclass if you would like your own types to be instantiated instead
_map_id_to_type = {
commit_id : Submodule,
blob_id : Blob,
@@ -128,6 +135,8 @@ class Tree(IndexObject, diff.Diffable, util.Traversable, util.Serializable):
# tree id added once Tree is defined
}
+ #} end configuration
+
def __init__(self, repo, binsha, mode=tree_id<<12, path=None):
super(Tree, self).__init__(repo, binsha, mode, path)
@@ -141,7 +150,7 @@ class Tree(IndexObject, diff.Diffable, util.Traversable, util.Serializable):
def _set_cache_(self, attr):
if attr == "_cache":
# Set the data when we need it
- ostream = self.repo.odb.stream(self.binsha)
+ ostream = self.odb.stream(self.binsha)
self._cache = tree_entries_from_data(ostream.read())
else:
super(Tree, self)._set_cache_(attr)
diff --git a/git/objects/util.py b/git/objects/util.py
index 4c9323b8..8ac590f2 100644
--- a/git/objects/util.py
+++ b/git/objects/util.py
@@ -20,6 +20,7 @@ __all__ = ('get_object_type_by_name', 'parse_date', 'parse_actor_and_date',
'ProcessStreamAdapter', 'Traversable', 'altz_to_utctz_str', 'utctz_to_altz',
'verify_utctz', 'Actor')
+
#{ Functions
def mode_str_to_int(modestr):