From c5083752d5d02d6c46bc2f18ba53a28d119af5b9 Mon Sep 17 00:00:00 2001 From: Govind Salinas Date: Fri, 6 Jun 2008 22:49:15 -0500 Subject: Determine git_dir and git_work_tree in python. Calling git to find the git_dir and work_tree is very costly. This patch uses the same mechanisim to find the git_dir as native git does without shelling out. Signed-off-by: Govind Salinas --- lib/git/repo.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'lib/git/repo.py') diff --git a/lib/git/repo.py b/lib/git/repo.py index 5853356e..72291dc9 100644 --- a/lib/git/repo.py +++ b/lib/git/repo.py @@ -12,7 +12,7 @@ from tree import Tree class Repo(object): DAEMON_EXPORT_FILE = 'git-daemon-export-ok' - def __init__(self, path): + def __init__(self, path=None): """ Create a new Repo instance @@ -27,19 +27,19 @@ class Repo(object): Returns ``GitPython.Repo`` """ - epath = os.path.abspath(path) + self.git = Git(path) + epath = self.git.get_work_tree() + self.path = self.git.get_git_dir() if os.path.exists(os.path.join(epath, '.git')): - self.path = os.path.join(epath, '.git') self.bare = False - elif os.path.exists(epath) and re.search('\.git$', epath): - self.path = epath + elif os.path.exists(epath) and epath.endswith('.git'): self.bare = True elif os.path.exists(epath): raise InvalidGitRepositoryError(epath) else: raise NoSuchPathError(epath) - self.git = Git(self.path) + @property def description(self): -- cgit v1.2.1 From 52654c0216dcbe3fa2d9afb1de12c65d18f6a7a4 Mon Sep 17 00:00:00 2001 From: David Aguilar Date: Thu, 12 Jun 2008 02:57:00 -0700 Subject: repo: these changes make Govind's latest changes pass the test cases Signed-off-by: David Aguilar --- lib/git/repo.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'lib/git/repo.py') diff --git a/lib/git/repo.py b/lib/git/repo.py index 72291dc9..8b519c1c 100644 --- a/lib/git/repo.py +++ b/lib/git/repo.py @@ -27,9 +27,14 @@ class Repo(object): Returns ``GitPython.Repo`` """ + if not os.path.exists(path): + raise NoSuchPathError(path) + self.git = Git(path) - epath = self.git.get_work_tree() self.path = self.git.get_git_dir() + if not self.path: + raise InvalidGitRepositoryError(path) + epath = self.git.get_work_tree() if os.path.exists(os.path.join(epath, '.git')): self.bare = False -- cgit v1.2.1 From fd5f111439e7a2e730b602a155aa533c68badbf8 Mon Sep 17 00:00:00 2001 From: David Aguilar Date: Sun, 15 Jun 2008 16:45:29 -0700 Subject: cmd: better support for bare repositories In order to avoid the expense of parsing .git/config just to know whether or not a repository is bare at __init__ time, we just pass an optional flag to Git.__init__(): bare_repo with a default value of False. Repo.init_bare() was updated to pass this flag. We could have an optional Git.read_bare_status() function that does the expensive lookup. Then, users can optionally call it at runtime if they really need to know whether or not a repository is bare. That seems like a decent tradeoff between speed, correctness, and common use cases. Signed-off-by: David Aguilar --- lib/git/repo.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/git/repo.py') diff --git a/lib/git/repo.py b/lib/git/repo.py index 8b519c1c..5a9855ac 100644 --- a/lib/git/repo.py +++ b/lib/git/repo.py @@ -280,7 +280,7 @@ class Repo(object): if mkdir and not os.path.exists(path): os.makedirs(path, 0755) - git = Git(path) + git = Git(path, bare_repo=True) output = git.init(**kwargs) return Repo(path) create = init_bare -- cgit v1.2.1