1
1
# Copyright (C) 2007 Canonical Ltd
2
# Copyright (C) 2010 Jelmer Vernooij
3
4
# This program is free software; you can redistribute it and/or modify
4
5
# it under the terms of the GNU General Public License as published by
75
75
def is_supported(self):
78
def can_convert_format(self):
78
81
def cloning_metadir(self, stacked=False):
79
return get_rich_root_format(stacked)
82
return bzrdir.format_registry.make_bzrdir("default")
81
84
def _branch_name_to_ref(self, name):
82
from bzrlib.plugins.git.branch import branch_name_to_ref
83
return branch_name_to_ref(name)
85
raise NotImplementedError(self._branch_name_to_ref)
85
87
if bzrlib_version >= (2, 2):
86
def open_branch(self, name=None, ignore_fallbacks=None,
88
def open_branch(self, name=None, unsupported=False,
89
ignore_fallbacks=None):
88
90
return self._open_branch(name=name,
89
91
ignore_fallbacks=ignore_fallbacks, unsupported=unsupported)
113
115
self._lockfiles = lockfiles
114
116
self._mode_check_done = None
118
def _branch_name_to_ref(self, name):
119
from bzrlib.plugins.git.refs import branch_name_to_ref
120
ref = branch_name_to_ref(name, None)
122
from dulwich.repo import SYMREF
123
refcontents = self._git.refs.read_ref(ref)
124
if refcontents.startswith(SYMREF):
125
ref = refcontents[len(SYMREF):]
116
128
def is_control_filename(self, filename):
117
129
return filename == '.git' or filename.startswith('.git/')
119
def get_branch_transport(self, branch_format):
131
def get_branch_transport(self, branch_format, name=None):
120
132
if branch_format is None:
121
133
return self.transport
122
134
if isinstance(branch_format, LocalGitBzrDirFormat):
123
135
return self.transport
124
136
raise bzr_errors.IncompatibleFormat(branch_format, self._format)
126
get_repository_transport = get_branch_transport
127
get_workingtree_transport = get_branch_transport
138
def get_repository_transport(self, format):
140
return self.transport
141
if isinstance(format, LocalGitBzrDirFormat):
142
return self.transport
143
raise bzr_errors.IncompatibleFormat(format, self._format)
145
def get_workingtree_transport(self, format):
147
return self.transport
148
if isinstance(format, LocalGitBzrDirFormat):
149
return self.transport
150
raise bzr_errors.IncompatibleFormat(format, self._format)
129
152
def _open_branch(self, name=None, ignore_fallbacks=None, unsupported=False):
130
153
"""'create' a branch for this dir."""
136
159
def destroy_branch(self, name=None):
137
del self._git.refs[self._branch_name_to_ref(name)]
160
refname = self._branch_name_to_ref(name)
161
if not refname in self._git.refs:
162
raise bzr_errors.NotBranchError(self.root_transport.base,
164
del self._git.refs[refname]
166
def destroy_repository(self):
167
raise bzr_errors.UnsupportedOperation(self.destroy_repository, self)
169
def destroy_workingtree(self):
170
raise bzr_errors.UnsupportedOperation(self.destroy_workingtree, self)
172
def needs_format_conversion(self, format=None):
173
return not isinstance(self._format, format.__class__)
139
175
def list_branches(self):
141
177
for name in self._git.get_refs():
142
if name.startswith("refs/heads/") or name == "HEAD":
178
if name.startswith("refs/heads/"):
143
179
ret.append(self.open_branch(name=name))
159
195
from bzrlib.plugins.git.workingtree import GitWorkingTree
160
return GitWorkingTree(self, repo, self.open_branch(), index)
197
branch = self.open_branch()
198
except bzr_errors.NotBranchError:
201
return GitWorkingTree(self, repo, branch, index)
161
202
loc = urlutils.unescape_for_display(self.root_transport.base, 'ascii')
162
203
raise bzr_errors.NoWorkingTree(loc)
167
208
def create_branch(self, name=None):
168
209
refname = self._branch_name_to_ref(name)
169
self._git.refs[refname] = "0" * 40
210
from dulwich.protocol import ZERO_SHA
211
self._git.refs[refname or "HEAD"] = ZERO_SHA
170
212
return self.open_branch(name)
172
214
def backup_bzrdir(self):