20
20
from bzrlib import (
21
21
errors as bzr_errors,
24
25
version_info as bzrlib_version,
27
from bzrlib.bzrdir import CreateRepository
28
from bzrlib.transport import do_catching_redirections
27
30
LockWarner = getattr(lockable_files, "_LockWarner", None)
29
from bzrlib.plugins.git import (
30
BareLocalGitControlDirFormat,
31
LocalGitControlDirFormat,
32
from bzrlib.controldir import (
34
from bzrlib.controldir import (
40
from bzrlib.bzrdir import (
47
39
class GitLock(object):
48
40
"""A lock that thunks through to Git."""
43
self.lock_name = "git lock"
50
45
def lock_write(self, token=None):
121
133
def get_config(self):
122
134
return GitDirConfig()
136
def clone_on_transport(self, transport, revision_id=None,
137
force_new_repo=False, preserve_stacking=False, stacked_on=None,
138
create_prefix=False, use_existing_dir=True, no_tree=False):
139
from dulwich.protocol import ZERO_SHA
140
"""See ControlDir.clone_on_transport."""
142
format = BareLocalGitControlDirFormat()
144
format = LocalGitControlDirFormat()
145
(target_repo, target_controldir, stacking, repo_policy) = format.initialize_on_transport_ex(transport, use_existing_dir=use_existing_dir, create_prefix=create_prefix, force_new_repo=force_new_repo)
146
target_git_repo = target_repo._git
147
source_repo = self.open_repository()
148
source_git_repo = source_repo._git
149
if revision_id is not None:
150
git_sha, mapping = source_repo.lookup_bzr_revision_id(revision_id)
151
if git_sha == ZERO_SHA:
155
determine_wants = lambda heads: wants
157
determine_wants = target_git_repo.object_store.determine_wants_all
158
refs = source_git_repo.fetch(target_git_repo, determine_wants)
159
for name, val in refs.iteritems():
160
target_git_repo.refs[name] = val
161
lockfiles = GitLockableFiles(transport, GitLock())
162
return self.__class__(transport, lockfiles, target_git_repo, format)
165
class LocalGitControlDirFormat(GitControlDirFormat):
166
"""The .git directory control format."""
171
def _known_formats(self):
172
return set([LocalGitControlDirFormat()])
175
def repository_format(self):
176
from bzrlib.plugins.git.repository import GitRepositoryFormat
177
return GitRepositoryFormat()
179
def get_branch_format(self):
180
from bzrlib.plugins.git.branch import GitBranchFormat
181
return GitBranchFormat()
183
def open(self, transport, _found=None):
184
"""Open this directory.
187
from bzrlib.plugins.git.transportgit import TransportRepo
188
gitrepo = TransportRepo(transport)
189
lockfiles = GitLockableFiles(transport, GitLock())
190
return LocalGitDir(transport, lockfiles, gitrepo, self)
192
def get_format_description(self):
193
return "Local Git Repository"
195
def initialize_on_transport(self, transport):
196
from bzrlib.plugins.git.transportgit import TransportRepo
197
TransportRepo.init(transport, bare=self.bare)
198
return self.open(transport)
200
def initialize_on_transport_ex(self, transport, use_existing_dir=False,
201
create_prefix=False, force_new_repo=False, stacked_on=None,
202
stack_on_pwd=None, repo_format_name=None, make_working_trees=None,
203
shared_repo=False, vfs_only=False):
204
def make_directory(transport):
207
def redirected(transport, e, redirection_notice):
208
trace.note(redirection_notice)
209
return transport._redirected_to(e.source, e.target)
211
transport = do_catching_redirections(make_directory, transport,
213
except bzr_errors.FileExists:
214
if not use_existing_dir:
216
except bzr_errors.NoSuchFile:
217
if not create_prefix:
219
transport.create_prefix()
220
controldir = self.initialize_on_transport(transport)
221
repository = controldir.open_repository()
222
repository.lock_write()
223
return (repository, controldir, False, CreateRepository(controldir))
225
def is_supported(self):
229
class BareLocalGitControlDirFormat(LocalGitControlDirFormat):
232
supports_workingtrees = False
234
def get_format_description(self):
235
return "Local Git Repository (bare)"
125
238
class LocalGitDir(GitDir):
126
239
"""An adapter to the '.git' dir used by git."""