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/cmd.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'lib/git/cmd.py') diff --git a/lib/git/cmd.py b/lib/git/cmd.py index d3a7e36b..1a764ed3 100644 --- a/lib/git/cmd.py +++ b/lib/git/cmd.py @@ -12,12 +12,13 @@ class Git(MethodMissingMixin): """ The Git class manages communication with the Git binary """ - def __init__(self, git_dir=None): + def __init__(self, git_dir=None, bare_repo=False): super(Git, self).__init__() if git_dir: self._location = os.path.abspath(git_dir) else: self._location = os.getcwd() + self._is_bare_repo = bare_repo self.refresh() def refresh(self): @@ -25,7 +26,7 @@ class Git(MethodMissingMixin): self._is_in_repo = not not self.get_git_dir() self._work_tree = None self._cwd = self._git_dir - if self._git_dir: + if self._git_dir and not self._is_bare_repo: self._cwd = self.get_work_tree() def _is_git_dir(self, d): @@ -61,6 +62,8 @@ class Git(MethodMissingMixin): return self._git_dir def get_work_tree(self): + if self._is_bare_repo: + return None if not self._work_tree: self._work_tree = os.getenv('GIT_WORK_TREE') if not self._work_tree or not os.path.isdir(self._work_tree): -- cgit v1.2.1