1
# Copyright (C) 2007 Canonical Ltd
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
"""An adapter between a Git control dir and a Bazaar BzrDir"""
22
from bzrlib.lazy_import import lazy_import
29
lazy_import(globals(), """
30
from bzrlib.lockable_files import TransportLock
31
from bzrlib.plugins.git import (
39
from bzrlib.plugins.git import LocalGitBzrDirFormat
43
class GitLock(object):
44
"""A lock that thunks through to Git."""
46
def lock_write(self, token=None):
58
def validate_token(self, token):
62
class GitLockableFiles(lockable_files.LockableFiles):
63
"""Git specific lockable files abstraction."""
65
def __init__(self, transport, lock):
67
self._transaction = None
68
self._lock_mode = None
70
self._transport = transport
73
class GitDir(bzrdir.BzrDir):
74
"""An adapter to the '.git' dir used by git."""
76
def is_supported(self):
79
def cloning_metadir(self, stacked=False):
80
return bzrlib.bzrdir.format_registry.make_bzrdir("1.9-rich-root")
83
class LocalGitDir(GitDir):
84
"""An adapter to the '.git' dir used by git."""
86
_gitrepository_class = repository.LocalGitRepository
88
def __init__(self, transport, lockfiles, gitrepo, format):
90
self.root_transport = transport
93
self.transport = transport
95
self.transport = transport.clone('.git')
96
self._lockfiles = lockfiles
98
def get_branch_transport(self, branch_format):
99
if branch_format is None:
100
return self.transport
101
if isinstance(branch_format, LocalGitBzrDirFormat):
102
return self.transport
103
raise errors.bzr_errors.IncompatibleFormat(branch_format, self._format)
105
get_repository_transport = get_branch_transport
106
get_workingtree_transport = get_branch_transport
108
def open_branch(self, ignored=None):
109
"""'create' a branch for this dir."""
110
repo = self.open_repository()
111
return branch.LocalGitBranch(self, repo, "HEAD", repo._git.head(), self._lockfiles)
113
def open_repository(self, shared=False):
114
"""'open' a repository for this dir."""
115
return self._gitrepository_class(self, self._lockfiles)
117
def open_workingtree(self, recommend_upgrade=True):
118
if (not self._git.bare and
119
os.path.exists(os.path.join(self._git.controldir(), "index"))):
120
return workingtree.GitWorkingTree(self, self.open_repository(),
122
loc = urlutils.unescape_for_display(self.root_transport.base, 'ascii')
123
raise errors.bzr_errors.NoWorkingTree(loc)
125
def create_repository(self, shared=False):
126
return self.open_repository()