80
78
return get_rich_root_format(stacked)
82
80
def _branch_name_to_ref(self, name):
83
raise NotImplementedError(self._branch_name_to_ref)
85
if bzrlib_version >= (2, 2):
86
def open_branch(self, name=None, ignore_fallbacks=None,
88
return self._open_branch(name=name,
89
ignore_fallbacks=ignore_fallbacks, unsupported=unsupported)
91
def open_branch(self, ignore_fallbacks=None, unsupported=False):
92
return self._open_branch(name=None,
93
ignore_fallbacks=ignore_fallbacks, unsupported=unsupported)
81
if name is None and name != "HEAD":
84
return "refs/heads/%s" % name
96
89
class LocalGitDir(GitDir):
113
106
self._lockfiles = lockfiles
114
107
self._mode_check_done = None
116
def _branch_name_to_ref(self, name):
117
from bzrlib.plugins.git.refs import branch_name_to_ref
118
if name in (None, "HEAD"):
119
from dulwich.repo import SYMREF
120
refcontents = self._git.refs.read_ref("HEAD")
121
if refcontents.startswith(SYMREF):
122
name = refcontents[len(SYMREF):]
125
return branch_name_to_ref(name, "HEAD")
127
109
def is_control_filename(self, filename):
128
110
return filename == '.git' or filename.startswith('.git/')
130
def get_branch_transport(self, branch_format, name):
112
def get_branch_transport(self, branch_format):
131
113
if branch_format is None:
132
114
return self.transport
133
115
if isinstance(branch_format, LocalGitBzrDirFormat):
134
116
return self.transport
135
117
raise bzr_errors.IncompatibleFormat(branch_format, self._format)
137
def get_repository_transport(self, format):
139
return self.transport
140
if isinstance(format, LocalGitBzrDirFormat):
141
return self.transport
142
raise bzr_errors.IncompatibleFormat(format, self._format)
144
def get_workingtree_transport(self, format):
146
return self.transport
147
if isinstance(format, LocalGitBzrDirFormat):
148
return self.transport
149
raise bzr_errors.IncompatibleFormat(format, self._format)
151
def _open_branch(self, name=None, ignore_fallbacks=None, unsupported=False):
119
get_repository_transport = get_branch_transport
120
get_workingtree_transport = get_branch_transport
123
def open_branch(self, ignore_fallbacks=None, name=None, unsupported=False):
152
124
"""'create' a branch for this dir."""
153
125
repo = self.open_repository()
154
126
from bzrlib.plugins.git.branch import LocalGitBranch
161
133
def list_branches(self):
163
135
for name in self._git.get_refs():
164
if name.startswith("refs/heads/"):
165
ret.append(self.open_branch(name=name))
136
ret.append(self.open_branch(name=name))
168
139
def open_repository(self, shared=False):
172
143
def open_workingtree(self, recommend_upgrade=True):
173
144
if not self._git.bare:
174
145
from dulwich.errors import NoIndexPresent
175
repo = self.open_repository()
177
index = repo._git.open_index()
147
from bzrlib.plugins.git.workingtree import GitWorkingTree
148
return GitWorkingTree(self, self.open_repository(),
178
150
except NoIndexPresent:
181
from bzrlib.plugins.git.workingtree import GitWorkingTree
182
return GitWorkingTree(self, repo, self.open_branch(), index)
183
152
loc = urlutils.unescape_for_display(self.root_transport.base, 'ascii')
184
153
raise bzr_errors.NoWorkingTree(loc)
189
158
def create_branch(self, name=None):
190
159
refname = self._branch_name_to_ref(name)
191
from dulwich.protocol import ZERO_SHA
192
self._git.refs[refname] = ZERO_SHA
160
self._git.refs[refname] = "0" * 40
193
161
return self.open_branch(name)
195
163
def backup_bzrdir(self):