58
def validate_token(self, token):
62
55
class GitLockableFiles(lockable_files.LockableFiles):
63
56
"""Git specific lockable files abstraction."""
65
def __init__(self, transport, lock):
58
def __init__(self, lock):
67
60
self._transaction = None
68
61
self._lock_mode = None
69
62
self._lock_count = 0
70
self._transport = transport
73
65
class GitDir(bzrdir.BzrDir):
74
66
"""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
68
_gitrepository_class = repository.GitRepository
88
70
def __init__(self, transport, lockfiles, gitrepo, format):
89
71
self._format = format
98
80
def get_branch_transport(self, branch_format):
99
81
if branch_format is None:
100
82
return self.transport
101
if isinstance(branch_format, LocalGitBzrDirFormat):
83
if isinstance(branch_format, GitBzrDirFormat):
102
84
return self.transport
103
85
raise errors.bzr_errors.IncompatibleFormat(branch_format, self._format)
105
87
get_repository_transport = get_branch_transport
106
88
get_workingtree_transport = get_branch_transport
90
def is_supported(self):
108
93
def open_branch(self, ignored=None):
109
94
"""'create' a branch for this dir."""
110
95
repo = self.open_repository()
111
return branch.LocalGitBranch(self, repo, "HEAD", repo._git.head(), self._lockfiles)
96
if repo._git.heads == []:
99
head = repo._git.heads[0].commit.id
100
return branch.GitBranch(self, repo, head,
101
self.root_transport.base, self._lockfiles)
113
103
def open_repository(self, shared=False):
114
104
"""'open' a repository for this dir."""
115
105
return self._gitrepository_class(self, self._lockfiles)
117
107
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"))):
109
loc = urlutils.unescape_for_display(self.root_transport.base, 'ascii')
110
raise errors.bzr_errors.NoWorkingTree(loc)
120
112
return workingtree.GitWorkingTree(self, self.open_repository(),
121
113
self.open_branch())
122
loc = urlutils.unescape_for_display(self.root_transport.base, 'ascii')
123
raise errors.bzr_errors.NoWorkingTree(loc)
115
def cloning_metadir(self):
116
return bzrdir.BzrDirFormat.get_default_format()
125
118
def create_repository(self, shared=False):
126
119
return self.open_repository()
122
class GitBzrDirFormat(bzrdir.BzrDirFormat):
123
"""The .git directory control format."""
125
_gitdir_class = GitDir
126
_lock_class = TransportLock
129
def _known_formats(self):
130
return set([GitBzrDirFormat()])
132
def open(self, transport, _found=None):
133
"""Open this directory.
136
# we dont grok readonly - git isn't integrated with transport.
138
if url.startswith('readonly+'):
139
url = url[len('readonly+'):]
142
gitrepo = git.repo.Repo(transport.local_abspath("."))
143
except errors.bzr_errors.NotLocalUrl:
144
raise errors.bzr_errors.NotBranchError(path=transport.base)
145
lockfiles = GitLockableFiles(GitLock())
146
return self._gitdir_class(transport, lockfiles, gitrepo, self)
149
def probe_transport(klass, transport):
150
"""Our format is present if the transport ends in '.not/'."""
151
# little ugly, but works
153
# delegate to the main opening code. This pays a double rtt cost at the
154
# moment, so perhaps we want probe_transport to return the opened thing
155
# rather than an openener ? or we could return a curried thing with the
156
# dir to open already instantiated ? Needs more thought.
158
format.open(transport)
161
raise errors.bzr_errors.NotBranchError(path=transport.base)
162
raise errors.bzr_errors.NotBranchError(path=transport.base)
164
def get_format_description(self):
165
return "Local Git Repository"
167
def get_format_string(self):
168
return "Local Git Repository"
170
def initialize_on_transport(self, transport):
171
from bzrlib.transport.local import LocalTransport
173
if not isinstance(transport, LocalTransport):
174
raise NotImplementedError(self.initialize,
175
"Can't create Git Repositories/branches on "
176
"non-local transports")
178
git.repo.Repo.create(transport.local_abspath("."))
179
return self.open(transport)
182
bzrdir.BzrDirFormat.register_control_format(GitBzrDirFormat)