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
79
80
return get_rich_root_format(stacked)
81
82
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)
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)
86
96
class LocalGitDir(GitDir):
103
113
self._lockfiles = lockfiles
104
114
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")
106
127
def is_control_filename(self, filename):
107
128
return filename == '.git' or filename.startswith('.git/')
109
def get_branch_transport(self, branch_format):
130
def get_branch_transport(self, branch_format, name):
110
131
if branch_format is None:
111
132
return self.transport
112
133
if isinstance(branch_format, LocalGitBzrDirFormat):
113
134
return self.transport
114
135
raise bzr_errors.IncompatibleFormat(branch_format, self._format)
116
get_repository_transport = get_branch_transport
117
get_workingtree_transport = get_branch_transport
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)
119
151
def _open_branch(self, name=None, ignore_fallbacks=None, unsupported=False):
120
152
"""'create' a branch for this dir."""
123
155
return LocalGitBranch(self, repo, self._branch_name_to_ref(name),
126
if bzrlib_version >= (2, 2):
127
open_branch = _open_branch
129
def open_branch(self, ignore_fallbacks=None, unsupported=False):
130
return self._open_branch(name=None,
131
ignore_fallbacks=ignore_fallbacks, unsupported=unsupported)
133
158
def destroy_branch(self, name=None):
134
159
del self._git.refs[self._branch_name_to_ref(name)]
136
161
def list_branches(self):
138
163
for name in self._git.get_refs():
139
if name.startswith("refs/heads/") or name == "HEAD":
164
if name.startswith("refs/heads/"):
140
165
ret.append(self.open_branch(name=name))
147
172
def open_workingtree(self, recommend_upgrade=True):
148
173
if not self._git.bare:
149
174
from dulwich.errors import NoIndexPresent
175
repo = self.open_repository()
151
from bzrlib.plugins.git.workingtree import GitWorkingTree
152
return GitWorkingTree(self, self.open_repository(),
177
index = repo._git.open_index()
154
178
except NoIndexPresent:
181
from bzrlib.plugins.git.workingtree import GitWorkingTree
182
return GitWorkingTree(self, repo, self.open_branch(), index)
156
183
loc = urlutils.unescape_for_display(self.root_transport.base, 'ascii')
157
184
raise bzr_errors.NoWorkingTree(loc)
162
189
def create_branch(self, name=None):
163
190
refname = self._branch_name_to_ref(name)
164
self._git.refs[refname] = "0" * 40
191
from dulwich.protocol import ZERO_SHA
192
self._git.refs[refname] = ZERO_SHA
165
193
return self.open_branch(name)
167
195
def backup_bzrdir(self):