14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
18
from bzrlib import (
74
from dulwich.pack import load_pack_index
77
# Don't run any tests on GitSmartTransport as it is not intended to be
75
from dulwich.pack import load_pack_index
77
from dulwich.pack import PackIndex as load_pack_index
80
# Don't run any tests on GitSmartTransport as it is not intended to be
78
81
# a full implementation of Transport
79
82
def get_test_permutations():
85
88
def __init__(self, url, _client=None):
86
89
Transport.__init__(self, url)
87
90
(scheme, _, loc, _, _) = urlparse.urlsplit(url)
88
hostport, escaped_path = urllib.splithost(loc)
89
self._path = urllib.unquote(escaped_path)
90
(self._username, hostport) = urllib.splituser(hostport)
91
hostport, self._path = urllib.splithost(loc)
91
92
(self._host, self._port) = urllib.splitnport(hostport, None)
92
93
self._client = _client
94
def external_url(self):
97
95
def has(self, relpath):
100
def _get_client(self, thin_packs):
98
def _get_client(self):
101
99
raise NotImplementedError(self._get_client)
106
101
def fetch_pack(self, determine_wants, graph_walker, pack_data, progress=None):
107
102
if progress is None:
108
103
def progress(text):
109
104
info("git: %s" % text)
110
client = self._get_client(thin_packs=False)
105
client = self._get_client()
112
return client.fetch_pack(self._get_path(), determine_wants,
107
return client.fetch_pack(self._path, determine_wants,
113
108
graph_walker, pack_data, progress)
114
109
except GitProtocolError, e:
115
110
raise BzrError(e)
117
112
def send_pack(self, get_changed_refs, generate_pack_contents):
118
client = self._get_client(thin_packs=False)
113
client = self._get_client()
120
return client.send_pack(self._get_path(), get_changed_refs,
115
return client.send_pack(self._path, get_changed_refs,
121
116
generate_pack_contents)
122
117
except GitProtocolError, e:
123
118
raise BzrError(e)
145
def _get_client(self, thin_packs):
140
def _get_client(self):
146
141
if self._client is not None:
147
142
ret = self._client
148
143
self._client = None
150
return git.client.TCPGitClient(self._host, self._port, thin_packs=thin_packs,
145
return git.client.TCPGitClient(self._host, self._port, thin_packs=False,
151
146
report_activity=self._report_activity)
156
151
_scheme = 'git+ssh'
159
if self._path.startswith("/~/"):
160
return self._path[3:]
163
def _get_client(self, thin_packs):
153
def _get_client(self):
164
154
if self._client is not None:
165
155
ret = self._client
166
156
self._client = None
168
return git.client.SSHGitClient(self._host, self._port, self._username,
169
thin_packs=thin_packs, report_activity=self._report_activity)
158
return git.client.SSHGitClient(self._host, self._port, thin_packs=False,
159
report_activity=self._report_activity)
172
162
class RemoteGitDir(GitDir):
186
176
# TODO: Support for multiple branches in one bzrdir in bzrlib!
187
177
return RemoteGitBranch(self, repo, "HEAD", self._lockfiles)
189
def open_workingtree(self, recommend_upgrade=False):
179
def open_workingtree(self):
190
180
raise NotLocalUrl(self.transport.base)
203
193
self.resolve_ext_ref = resolve_ext_ref
207
if self._data is None:
208
self._data = PackData(self._data_path)
213
197
if self._idx is None:
214
if not os.path.exists(self._idx_path):
215
pb = ui.ui_factory.nested_progress_bar()
217
def report_progress(cur, total):
218
pb.update("generating index", cur, total)
219
self.data.create_index(self._idx_path, self.resolve_ext_ref,
220
progress=report_progress)
198
if self._data is None:
199
self._data = PackData(self._data_path)
200
pb = ui.ui_factory.nested_progress_bar()
202
def report_progress(cur, total):
203
pb.update("generating index", cur, total)
204
self._data.create_index_v2(self._idx_path, self.resolve_ext_ref,
205
progress=report_progress)
223
208
self._idx = load_pack_index(self._idx_path)
226
211
def __del__(self):
227
if self._idx is not None:
229
os.remove(self._idx_path)
230
if self._data is not None:
232
os.remove(self._data_path)
212
os.remove(self._data_path)
213
os.remove(self._idx_path)
235
216
class RemoteGitRepository(GitRepository):
253
234
def get_refs(self):
254
235
if self._refs is not None:
255
236
return self._refs
256
self._refs = self.bzrdir.root_transport.fetch_pack(lambda x: [], None,
257
lambda x: None, lambda x: trace.mutter("git: %s" % x))
237
self._refs = self.bzrdir.root_transport.fetch_pack(lambda x: [], None,
238
lambda x: None, lambda x: mutter("git: %s" % x))
258
239
return self._refs
260
def fetch_pack(self, determine_wants, graph_walker, pack_data,
241
def fetch_pack(self, determine_wants, graph_walker, pack_data,
262
243
return self._transport.fetch_pack(determine_wants, graph_walker,
263
244
pack_data, progress)
265
246
def send_pack(self, get_changed_refs, generate_pack_contents):
266
247
return self._transport.send_pack(get_changed_refs, generate_pack_contents)
268
def fetch_objects(self, determine_wants, graph_walker, resolve_ext_ref,
249
def fetch_objects(self, determine_wants, graph_walker, resolve_ext_ref, progress=None):
270
250
fd, path = tempfile.mkstemp(suffix=".pack")
271
self.fetch_pack(determine_wants, graph_walker,
272
lambda x: os.write(fd, x), progress)
251
self.fetch_pack(determine_wants, graph_walker, lambda x: os.write(fd, x), progress)
274
253
if os.path.getsize(path) == 0:
275
254
return EmptyObjectStoreIterator()
276
255
return TemporaryPackIterator(path[:-len(".pack")], resolve_ext_ref)
278
def lookup_bzr_revision_id(self, bzr_revid):
257
def lookup_git_revid(self, bzr_revid):
279
258
# This won't work for any round-tripped bzr revisions, but it's a start..
281
260
return mapping_registry.revision_id_bzr_to_foreign(bzr_revid)
290
269
self.repository = branch.repository
292
271
def get_tag_dict(self):
294
for k, v in extract_tags(self.repository.get_refs()).iteritems():
295
tags[k] = self.branch.mapping.revision_id_foreign_to_bzr(v)
273
refs = self.repository.get_refs()
274
for k,v in refs.iteritems():
275
if k.startswith("refs/tags/") and not k.endswith("^{}"):
276
v = refs.get(k+"^{}", v)
277
ret[k[len("refs/tags/"):]] = self.branch.mapping.revision_id_foreign_to_bzr(v)
298
280
def set_tag(self, name, revid):
299
281
# FIXME: Not supported yet, should do a push of a new ref
305
287
def __init__(self, bzrdir, repository, name, lockfiles):
307
super(RemoteGitBranch, self).__init__(bzrdir, repository, name,
289
super(RemoteGitBranch, self).__init__(bzrdir, repository, name,
310
292
def revision_history(self):
313
295
def last_revision(self):
314
296
return self.mapping.revision_id_foreign_to_bzr(self.head)
316
def _get_config(self):
317
class EmptyConfig(object):
319
def _get_configobj(self):
320
return config.ConfigObj()
326
if self._ref is not None:
300
if self._ref is None:
328
heads = self.repository.get_refs()
329
if not self.name in heads:
330
raise NoSuchRef(self.name)
331
self._ref = heads[self.name]
302
heads = repository.get_refs()
303
if not name in heads:
304
raise NoSuchRef(name)
305
self._ref = heads[name]
334
308
def _synchronize_history(self, destination, revision_id):
335
309
"""See Branch._synchronize_history()."""
336
310
destination.generate_revision_history(self.last_revision())
338
def get_push_location(self):
341
def set_push_location(self, url):