15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
from bzrlib import urlutils
19
from bzrlib.bzrdir import BzrDir, BzrDirFormat
20
from bzrlib.errors import NoSuchFile, NotLocalUrl
21
from bzrlib.lockable_files import TransportLock
22
from bzrlib.repository import Repository
23
from bzrlib.trace import info
24
from bzrlib.transport import Transport
23
from bzrlib.bzrdir import (
27
from bzrlib.errors import (
32
from bzrlib.foreign import (
35
from bzrlib.lockable_files import (
38
from bzrlib.repository import (
41
from bzrlib.trace import (
44
from bzrlib.transport import (
26
from bzrlib.plugins.git import lazy_check_versions
48
from bzrlib.plugins.git import (
27
51
lazy_check_versions()
29
from bzrlib.plugins.git.branch import GitBranch
30
from bzrlib.plugins.git.errors import NoSuchRef
31
from bzrlib.plugins.git.dir import GitDir
32
from bzrlib.plugins.git.foreign import ForeignBranch
33
from bzrlib.plugins.git.repository import GitFormat, GitRepository
53
from bzrlib.plugins.git.branch import (
56
from bzrlib.plugins.git.errors import (
57
GitSmartRemoteNotSupported,
60
from bzrlib.plugins.git.dir import (
63
from bzrlib.plugins.git.repository import (
69
from dulwich.errors import (
72
from dulwich.pack import (
41
from dulwich.pack import PackData, Pack, PackIndex
82
from dulwich.pack import load_pack_index
84
from dulwich.pack import PackIndex as load_pack_index
43
87
# Don't run any tests on GitSmartTransport as it is not intended to be
44
88
# a full implementation of Transport
51
95
def __init__(self, url, _client=None):
52
96
Transport.__init__(self, url)
53
97
(scheme, _, loc, _, _) = urlparse.urlsplit(url)
54
assert scheme == "git"
55
98
hostport, self._path = urllib.splithost(loc)
56
99
(self._host, self._port) = urllib.splitnport(hostport, git.protocol.TCP_GIT_PORT)
57
100
self._client = _client
102
def has(self, relpath):
59
105
def _get_client(self):
60
if self._client is not None:
64
return git.client.TCPGitClient(self._host, self._port,
65
capabilities=["multi_ack", "side-band-64k", "ofs-delta", "side-band"])
106
raise NotImplementedError(self._get_client)
67
108
def fetch_pack(self, determine_wants, graph_walker, pack_data, progress=None):
68
109
if progress is None:
69
110
def progress(text):
70
111
info("git: %s" % text)
71
self._get_client().fetch_pack(self._path, determine_wants,
72
graph_walker, pack_data, progress)
112
client = self._get_client()
114
client.fetch_pack(self._path, determine_wants,
115
graph_walker, pack_data, progress)
116
except GitProtocolError, e:
74
119
def get(self, path):
75
120
raise NoSuchFile(path)
85
130
newurl = urlutils.join(self.base, offset)
87
return GitSmartTransport(newurl, self._client)
132
return self.__class__(newurl, self._client)
135
class TCPGitSmartTransport(GitSmartTransport):
137
def _get_client(self):
138
if self._client is not None:
142
return git.client.TCPGitClient(self._host, self._port, thin_packs=False)
145
class SSHGitSmartTransport(GitSmartTransport):
147
def _get_client(self):
148
if self._client is not None:
152
return git.client.SSHGitClient(self._host, self._port, thin_packs=False)
90
155
class RemoteGitDir(GitDir):
98
163
def open_repository(self):
99
164
return RemoteGitRepository(self, self._lockfiles)
101
def open_branch(self, _unsupported=False):
166
def open_branch(self, ignore_fallbacks=False):
102
167
repo = self.open_repository()
103
168
# TODO: Support for multiple branches in one bzrdir in bzrlib!
104
169
return RemoteGitBranch(self, repo, "HEAD", self._lockfiles)
116
181
class TemporaryPackIterator(Pack):
118
183
def __init__(self, path, resolve_ext_ref):
184
super(TemporaryPackIterator, self).__init__(path)
119
185
self.resolve_ext_ref = resolve_ext_ref
120
super(TemporaryPackIterator, self).__init__(path)
124
189
if self._idx is None:
190
if self._data is None:
191
self._data = PackData(self._data_path)
125
192
self._data.create_index_v2(self._idx_path, self.resolve_ext_ref)
126
self._idx = PackIndex(self._idx_path)
193
self._idx = load_pack_index(self._idx_path)
129
196
def __del__(self):
136
203
def __init__(self, gitdir, lockfiles):
137
204
GitRepository.__init__(self, gitdir, lockfiles)
208
def inventories(self):
209
raise GitSmartRemoteNotSupported()
213
raise GitSmartRemoteNotSupported()
217
raise GitSmartRemoteNotSupported()
220
if self._refs is not None:
222
def determine_wants(heads):
225
self.bzrdir.root_transport.fetch_pack(determine_wants, None,
226
lambda x: None, lambda x: mutter("git: %s" % x))
139
229
def fetch_pack(self, determine_wants, graph_walker, pack_data,
150
240
return TemporaryPackIterator(path[:-len(".pack")], resolve_ext_ref)
243
class RemoteGitTagDict(tag.BasicTags):
245
def __init__(self, branch):
247
self.repository = branch.repository
249
def get_tag_dict(self):
251
refs = self.repository.get_refs()
252
for k,v in refs.iteritems():
253
if k.startswith("refs/tags/") and not k.endswith("^{}"):
254
v = refs.get(k+"^{}", v)
255
ret[k[len("refs/tags/"):]] = self.branch.mapping.revision_id_foreign_to_bzr(v)
258
def set_tag(self, name, revid):
259
# FIXME: Not supported yet, should do a push of a new ref
260
raise NotImplementedError(self.set_tag)
153
263
class RemoteGitBranch(GitBranch):
155
265
def __init__(self, bzrdir, repository, name, lockfiles):
156
def determine_wants(heads):
157
if not name in heads:
158
raise NoSuchRef(name)
159
self._ref = heads[name]
160
bzrdir.root_transport.fetch_pack(determine_wants, None, lambda x: None,
161
lambda x: mutter("git: %s" % x))
266
heads = repository.get_refs()
267
if not name in heads:
268
raise NoSuchRef(name)
269
self._ref = heads[name]
162
270
super(RemoteGitBranch, self).__init__(bzrdir, repository, name, self._ref, lockfiles)
164
272
def last_revision(self):