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."""
28
LockWarner = getattr(lockable_files, "_LockWarner", None)
30
from bzrlib.plugins.git import (
40
class GitLock(object):
41
"""A lock that thunks through to Git."""
43
def lock_write(self, token=None):
55
def validate_token(self, token):
59
class GitLockableFiles(lockable_files.LockableFiles):
60
"""Git specific lockable files abstraction."""
62
def __init__(self, transport, lock):
64
self._transaction = None
65
self._lock_mode = None
66
self._transport = transport
67
if LockWarner is None:
71
self._lock_warner = LockWarner(repr(self))
74
class GitDir(bzrdir.BzrDir):
75
"""An adapter to the '.git' dir used by git."""
77
def is_supported(self):
80
def cloning_metadir(self, stacked=False):
81
return get_rich_root_format(stacked)
84
class LocalGitDir(GitDir):
85
"""An adapter to the '.git' dir used by git."""
87
_gitrepository_class = repository.LocalGitRepository
89
def __init__(self, transport, lockfiles, gitrepo, format):
91
self.root_transport = transport
94
self.transport = transport
96
self.transport = transport.clone('.git')
97
self._lockfiles = lockfiles
98
self._mode_check_done = None
100
def is_control_filename(self, filename):
101
return filename == '.git' or filename.startswith('.git/')
103
def get_branch_transport(self, branch_format):
104
if branch_format is None:
105
return self.transport
106
if isinstance(branch_format, LocalGitBzrDirFormat):
107
return self.transport
108
raise errors.bzr_errors.IncompatibleFormat(branch_format, self._format)
110
get_repository_transport = get_branch_transport
111
get_workingtree_transport = get_branch_transport
113
def open_branch(self, ignore_fallbacks=None):
114
"""'create' a branch for this dir."""
115
repo = self.open_repository()
116
return branch.LocalGitBranch(self, repo, "HEAD", self._lockfiles)
118
def open_repository(self, shared=False):
119
"""'open' a repository for this dir."""
120
return self._gitrepository_class(self, self._lockfiles)
122
def open_workingtree(self, recommend_upgrade=True):
123
if (not self._git.bare and
124
os.path.exists(os.path.join(self._git.controldir(), "index"))):
125
return workingtree.GitWorkingTree(self, self.open_repository(),
127
loc = urlutils.unescape_for_display(self.root_transport.base, 'ascii')
128
raise errors.bzr_errors.NoWorkingTree(loc)
130
def create_repository(self, shared=False):
131
return self.open_repository()
133
def create_branch(self):
134
return self.open_branch()