From a12a7618a1f6f61a4c97ddf4cc422158c3fa72ba Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Thu, 7 Apr 2011 20:17:00 +0200 Subject: Updated objects to use the ones defined in gitdb as basis. Only the submodule implementation is left in git-python as it requires some advanced features. No tests where run yet --- git/objects/submodule/base.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'git/objects/submodule') diff --git a/git/objects/submodule/base.py b/git/objects/submodule/base.py index 2160299b..7997e5e5 100644 --- a/git/objects/submodule/base.py +++ b/git/objects/submodule/base.py @@ -1,3 +1,5 @@ +from git.util import RepoAliasMixin +from gitdb.object.submodule import Submodule as GitDB_Submodule import util from util import ( mkhead, @@ -53,7 +55,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(GitDB_Submodule, 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. -- cgit v1.2.3 From 4177eefd7bdaea96a529b00ba9cf751924ede202 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Thu, 5 May 2011 19:43:22 +0200 Subject: Added all code from gitdb to gitpython. Next is to make it generally work. Then the tests will need some work --- git/objects/submodule/base.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'git/objects/submodule') diff --git a/git/objects/submodule/base.py b/git/objects/submodule/base.py index 7997e5e5..9b45d9b6 100644 --- a/git/objects/submodule/base.py +++ b/git/objects/submodule/base.py @@ -73,6 +73,9 @@ class Submodule(GitDB_Submodule, Iterable, Traversable, RepoAliasMixin): # 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') -- cgit v1.2.3 From acf5e6ea64a2f24117f1d419c208ed1c38c43690 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Fri, 6 May 2011 15:03:14 +0200 Subject: replaced all gitdb strings with git --- git/objects/submodule/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'git/objects/submodule') diff --git a/git/objects/submodule/base.py b/git/objects/submodule/base.py index 9b45d9b6..f6cf278a 100644 --- a/git/objects/submodule/base.py +++ b/git/objects/submodule/base.py @@ -1,5 +1,5 @@ from git.util import RepoAliasMixin -from gitdb.object.submodule import Submodule as GitDB_Submodule +from git.object.submodule import Submodule as GitDB_Submodule import util from util import ( mkhead, -- cgit v1.2.3 From 7ae36c3e019a5cc16924d1b6007774bfb625036f Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Fri, 6 May 2011 18:53:59 +0200 Subject: Started to fix imports - tests still have no chance to work as database changed drastically. Now the actual work begins --- git/objects/submodule/base.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'git/objects/submodule') diff --git a/git/objects/submodule/base.py b/git/objects/submodule/base.py index f6cf278a..62f4feee 100644 --- a/git/objects/submodule/base.py +++ b/git/objects/submodule/base.py @@ -1,5 +1,4 @@ from git.util import RepoAliasMixin -from git.object.submodule import Submodule as GitDB_Submodule import util from util import ( mkhead, @@ -55,7 +54,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(GitDB_Submodule, Iterable, Traversable, RepoAliasMixin): +class Submodule(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. -- cgit v1.2.3 From cd26aaebbda94dc3740e41bbd3f91ba6b1a25c10 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Tue, 10 May 2011 10:21:26 +0200 Subject: Made repository paths methods a property to be compatible with the existing repo interface. Added submodule interface ... goal is to provide all of the extra repo functionality in custom interfaces --- git/objects/submodule/__init__.py | 4 ++++ git/objects/submodule/base.py | 4 ++++ git/objects/submodule/root.py | 5 +++++ git/objects/submodule/util.py | 4 ++++ 4 files changed, 17 insertions(+) (limited to 'git/objects/submodule') 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 62f4feee..a57111d3 100644 --- a/git/objects/submodule/base.py +++ b/git/objects/submodule/base.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 git.util import RepoAliasMixin import util from util import ( 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 -- cgit v1.2.3 From 1f71ed94578799ee1667ba54b66a369e307f415b Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Mon, 30 May 2011 16:32:56 +0200 Subject: git cmd implementation of repository appears to work, at least this is what the test suggests. Pure python implementation still has some trouble, but this should be very fixable --- git/objects/submodule/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'git/objects/submodule') diff --git a/git/objects/submodule/base.py b/git/objects/submodule/base.py index a57111d3..e38b94f8 100644 --- a/git/objects/submodule/base.py +++ b/git/objects/submodule/base.py @@ -58,7 +58,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(Iterable, Traversable, RepoAliasMixin): +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. -- cgit v1.2.3 From 9bf3fdec93fe427bb5f0bd39c986a4e977969f41 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Tue, 7 Jun 2011 13:38:48 +0200 Subject: First run in order to fix the remote handling. Cleaned up interfaces and figured out that the implementation really should be specific to the git command. This leaves the interface open for other implemntations which use a different way to provide feedback (as we do not make assumptions about the format of a feedback line) --- git/objects/submodule/base.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'git/objects/submodule') diff --git a/git/objects/submodule/base.py b/git/objects/submodule/base.py index e38b94f8..c1cc51aa 100644 --- a/git/objects/submodule/base.py +++ b/git/objects/submodule/base.py @@ -18,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, -- cgit v1.2.3 From f7ca1ce511b535b088ffcbd764415fe0d33f368e Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Tue, 7 Jun 2011 17:14:57 +0200 Subject: Submodule tests are nearly working. Only root module needs more attention --- git/objects/submodule/base.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'git/objects/submodule') diff --git a/git/objects/submodule/base.py b/git/objects/submodule/base.py index c1cc51aa..019fe18c 100644 --- a/git/objects/submodule/base.py +++ b/git/objects/submodule/base.py @@ -29,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 @@ -769,14 +769,18 @@ class Submodule(util.IndexObject, Iterable, Traversable, RepoAliasMixin): #{ 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 -- cgit v1.2.3 From fd5c46eb283090e84a90ac394d056decc742f8f4 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Tue, 7 Jun 2011 18:24:22 +0200 Subject: submodule now doesn't use hardcoded repository implementations anymore. Instead it allows the user to override the type in the classmethod he calls. Otherwise the type of the own repo will be respected --- git/objects/submodule/base.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'git/objects/submodule') diff --git a/git/objects/submodule/base.py b/git/objects/submodule/base.py index 019fe18c..0fdb121d 100644 --- a/git/objects/submodule/base.py +++ b/git/objects/submodule/base.py @@ -204,7 +204,7 @@ class Submodule(util.IndexObject, Iterable, Traversable, RepoAliasMixin): #{ 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 @@ -229,6 +229,8 @@ class Submodule(util.IndexObject, Iterable, Traversable, RepoAliasMixin): 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""" @@ -236,6 +238,8 @@ class Submodule(util.IndexObject, Iterable, Traversable, RepoAliasMixin): 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] @@ -289,7 +293,7 @@ class Submodule(util.IndexObject, Iterable, Traversable, RepoAliasMixin): 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 @@ -315,7 +319,7 @@ class Submodule(util.IndexObject, Iterable, Traversable, RepoAliasMixin): 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. @@ -377,7 +381,6 @@ class Submodule(util.IndexObject, Iterable, Traversable, RepoAliasMixin): 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) @@ -393,7 +396,7 @@ class Submodule(util.IndexObject, Iterable, Traversable, RepoAliasMixin): # 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) @@ -779,6 +782,7 @@ class Submodule(util.IndexObject, Iterable, Traversable, RepoAliasMixin): # late import to workaround circular dependencies module_path = self.abspath repoType = repoType or git.Repo + try: repo = repoType(module_path) if repo != self.repo: -- cgit v1.2.3