170
162
def test_translate_client_path(self):
171
163
transport = self.get_transport()
172
164
request = smart_req.SmartServerRequest(transport, 'foo/')
173
self.assertEqual('./', request.translate_client_path(b'foo/'))
175
urlutils.InvalidURLJoin, request.translate_client_path, b'foo/..')
177
errors.PathNotChild, request.translate_client_path, b'/')
179
errors.PathNotChild, request.translate_client_path, b'bar/')
180
self.assertEqual('./baz', request.translate_client_path(b'foo/baz'))
181
e_acute = u'\N{LATIN SMALL LETTER E WITH ACUTE}'
183
u'./' + urlutils.escape(e_acute),
184
request.translate_client_path(b'foo/' + e_acute.encode('utf-8')))
165
self.assertEqual('./', request.translate_client_path('foo/'))
167
errors.InvalidURLJoin, request.translate_client_path, 'foo/..')
169
errors.PathNotChild, request.translate_client_path, '/')
171
errors.PathNotChild, request.translate_client_path, 'bar/')
172
self.assertEqual('./baz', request.translate_client_path('foo/baz'))
173
e_acute = u'\N{LATIN SMALL LETTER E WITH ACUTE}'.encode('utf-8')
174
self.assertEqual('./' + urlutils.escape(e_acute),
175
request.translate_client_path('foo/' + e_acute))
186
177
def test_translate_client_path_vfs(self):
187
178
"""VfsRequests receive escaped paths rather than raw UTF-8."""
188
179
transport = self.get_transport()
189
180
request = vfs.VfsRequest(transport, 'foo/')
190
e_acute = u'\N{LATIN SMALL LETTER E WITH ACUTE}'
191
escaped = urlutils.escape(u'foo/' + e_acute)
193
'./' + urlutils.escape(e_acute),
194
request.translate_client_path(escaped.encode('ascii')))
181
e_acute = u'\N{LATIN SMALL LETTER E WITH ACUTE}'.encode('utf-8')
182
escaped = urlutils.escape('foo/' + e_acute)
183
self.assertEqual('./' + urlutils.escape(e_acute),
184
request.translate_client_path(escaped))
196
186
def test_transport_from_client_path(self):
197
187
transport = self.get_transport()
198
188
request = smart_req.SmartServerRequest(transport, 'foo/')
199
189
self.assertEqual(
201
request.transport_from_client_path(b'foo/').base)
191
request.transport_from_client_path('foo/').base)
204
194
class TestSmartServerBzrDirRequestCloningMetaDir(
205
tests.TestCaseWithMemoryTransport):
195
tests.TestCaseWithMemoryTransport):
206
196
"""Tests for BzrDir.cloning_metadir."""
208
198
def test_cloning_metadir(self):
209
199
"""When there is a bzrdir present, the call succeeds."""
210
200
backing = self.get_transport()
211
dir = self.make_controldir('.')
201
dir = self.make_bzrdir('.')
212
202
local_result = dir.cloning_metadir()
213
203
request_class = smart_dir.SmartServerBzrDirRequestCloningMetaDir
214
204
request = request_class(backing)
215
205
expected = smart_req.SuccessfulSmartServerResponse(
216
206
(local_result.network_name(),
217
local_result.repository_format.network_name(),
218
(b'branch', local_result.get_branch_format().network_name())))
219
self.assertEqual(expected, request.execute(b'', b'False'))
207
local_result.repository_format.network_name(),
208
('branch', local_result.get_branch_format().network_name())))
209
self.assertEqual(expected, request.execute('', 'False'))
221
211
def test_cloning_metadir_reference(self):
222
212
"""The request fails when bzrdir contains a branch reference."""
223
213
backing = self.get_transport()
224
214
referenced_branch = self.make_branch('referenced')
225
dir = self.make_controldir('.')
226
dir.cloning_metadir()
227
_mod_bzrbranch.BranchReferenceFormat().initialize(
215
dir = self.make_bzrdir('.')
216
local_result = dir.cloning_metadir()
217
reference = _mod_branch.BranchReferenceFormat().initialize(
228
218
dir, target_branch=referenced_branch)
229
_mod_bzrbranch.BranchReferenceFormat().get_reference(dir)
219
reference_url = _mod_branch.BranchReferenceFormat().get_reference(dir)
230
220
# The server shouldn't try to follow the branch reference, so it's fine
231
221
# if the referenced branch isn't reachable.
232
222
backing.rename('referenced', 'moved')
233
223
request_class = smart_dir.SmartServerBzrDirRequestCloningMetaDir
234
224
request = request_class(backing)
235
expected = smart_req.FailedSmartServerResponse((b'BranchReference',))
236
self.assertEqual(expected, request.execute(b'', b'False'))
239
class TestSmartServerBzrDirRequestCheckoutMetaDir(
240
tests.TestCaseWithMemoryTransport):
225
expected = smart_req.FailedSmartServerResponse(('BranchReference',))
226
self.assertEqual(expected, request.execute('', 'False'))
229
class TestSmartServerBzrDirRequestCloningMetaDir(
230
tests.TestCaseWithMemoryTransport):
241
231
"""Tests for BzrDir.checkout_metadir."""
243
233
def test_checkout_metadir(self):
244
234
backing = self.get_transport()
245
235
request = smart_dir.SmartServerBzrDirRequestCheckoutMetaDir(
247
self.make_branch('.', format='2a')
248
response = request.execute(b'')
237
branch = self.make_branch('.', format='2a')
238
response = request.execute('')
249
239
self.assertEqual(
250
240
smart_req.SmartServerResponse(
251
(b'Bazaar-NG meta directory, format 1\n',
252
b'Bazaar repository format 2a (needs bzr 1.16 or later)\n',
253
b'Bazaar Branch Format 7 (needs bzr 1.6)\n')),
241
('Bazaar-NG meta directory, format 1\n',
242
'Bazaar repository format 2a (needs bzr 1.16 or later)\n',
243
'Bazaar Branch Format 7 (needs bzr 1.6)\n')),
257
247
class TestSmartServerBzrDirRequestDestroyBranch(
258
tests.TestCaseWithMemoryTransport):
248
tests.TestCaseWithMemoryTransport):
259
249
"""Tests for BzrDir.destroy_branch."""
261
251
def test_destroy_branch_default(self):
262
252
"""The default branch can be removed."""
263
253
backing = self.get_transport()
264
self.make_branch('.')
254
dir = self.make_branch('.').bzrdir
265
255
request_class = smart_dir.SmartServerBzrDirRequestDestroyBranch
266
256
request = request_class(backing)
267
expected = smart_req.SuccessfulSmartServerResponse((b'ok',))
268
self.assertEqual(expected, request.execute(b'', None))
257
expected = smart_req.SuccessfulSmartServerResponse(('ok',))
258
self.assertEqual(expected, request.execute('', None))
270
260
def test_destroy_branch_named(self):
271
261
"""A named branch can be removed."""
272
262
backing = self.get_transport()
273
dir = self.make_repository('.', format="development-colo").controldir
263
dir = self.make_repository('.', format="development-colo").bzrdir
274
264
dir.create_branch(name="branchname")
275
265
request_class = smart_dir.SmartServerBzrDirRequestDestroyBranch
276
266
request = request_class(backing)
277
expected = smart_req.SuccessfulSmartServerResponse((b'ok',))
278
self.assertEqual(expected, request.execute(b'', b"branchname"))
267
expected = smart_req.SuccessfulSmartServerResponse(('ok',))
268
self.assertEqual(expected, request.execute('', "branchname"))
280
270
def test_destroy_branch_missing(self):
281
271
"""An error is raised if the branch didn't exist."""
282
272
backing = self.get_transport()
283
self.make_controldir('.', format="development-colo")
273
dir = self.make_bzrdir('.', format="development-colo")
284
274
request_class = smart_dir.SmartServerBzrDirRequestDestroyBranch
285
275
request = request_class(backing)
286
expected = smart_req.FailedSmartServerResponse((b'nobranch',), None)
287
self.assertEqual(expected, request.execute(b'', b"branchname"))
276
expected = smart_req.FailedSmartServerResponse(('nobranch',), None)
277
self.assertEqual(expected, request.execute('', "branchname"))
290
280
class TestSmartServerBzrDirRequestHasWorkingTree(
291
tests.TestCaseWithTransport):
281
tests.TestCaseWithTransport):
292
282
"""Tests for BzrDir.has_workingtree."""
294
284
def test_has_workingtree_yes(self):
295
285
"""A working tree is present."""
296
286
backing = self.get_transport()
297
self.make_branch_and_tree('.')
287
dir = self.make_branch_and_tree('.').bzrdir
298
288
request_class = smart_dir.SmartServerBzrDirRequestHasWorkingTree
299
289
request = request_class(backing)
300
expected = smart_req.SuccessfulSmartServerResponse((b'yes',))
301
self.assertEqual(expected, request.execute(b''))
290
expected = smart_req.SuccessfulSmartServerResponse(('yes',))
291
self.assertEqual(expected, request.execute(''))
303
293
def test_has_workingtree_no(self):
304
294
"""A working tree is missing."""
305
295
backing = self.get_transport()
306
self.make_controldir('.')
296
dir = self.make_bzrdir('.')
307
297
request_class = smart_dir.SmartServerBzrDirRequestHasWorkingTree
308
298
request = request_class(backing)
309
expected = smart_req.SuccessfulSmartServerResponse((b'no',))
310
self.assertEqual(expected, request.execute(b''))
299
expected = smart_req.SuccessfulSmartServerResponse(('no',))
300
self.assertEqual(expected, request.execute(''))
313
303
class TestSmartServerBzrDirRequestDestroyRepository(
314
tests.TestCaseWithMemoryTransport):
304
tests.TestCaseWithMemoryTransport):
315
305
"""Tests for BzrDir.destroy_repository."""
317
307
def test_destroy_repository_default(self):
318
308
"""The repository can be removed."""
319
309
backing = self.get_transport()
320
self.make_repository('.')
310
dir = self.make_repository('.').bzrdir
321
311
request_class = smart_dir.SmartServerBzrDirRequestDestroyRepository
322
312
request = request_class(backing)
323
expected = smart_req.SuccessfulSmartServerResponse((b'ok',))
324
self.assertEqual(expected, request.execute(b''))
313
expected = smart_req.SuccessfulSmartServerResponse(('ok',))
314
self.assertEqual(expected, request.execute(''))
326
316
def test_destroy_repository_missing(self):
327
317
"""An error is raised if the repository didn't exist."""
328
318
backing = self.get_transport()
329
self.make_controldir('.')
319
dir = self.make_bzrdir('.')
330
320
request_class = smart_dir.SmartServerBzrDirRequestDestroyRepository
331
321
request = request_class(backing)
332
322
expected = smart_req.FailedSmartServerResponse(
333
(b'norepository',), None)
334
self.assertEqual(expected, request.execute(b''))
337
class TestSmartServerRequestCreateRepository(
338
tests.TestCaseWithMemoryTransport):
323
('norepository',), None)
324
self.assertEqual(expected, request.execute(''))
327
class TestSmartServerRequestCreateRepository(tests.TestCaseWithMemoryTransport):
339
328
"""Tests for BzrDir.create_repository."""
341
330
def test_makes_repository(self):
342
331
"""When there is a bzrdir present, the call succeeds."""
343
332
backing = self.get_transport()
344
self.make_controldir('.')
333
self.make_bzrdir('.')
345
334
request_class = smart_dir.SmartServerRequestCreateRepository
346
335
request = request_class(backing)
347
336
reference_bzrdir_format = controldir.format_registry.get('pack-0.92')()
348
337
reference_format = reference_bzrdir_format.repository_format
349
338
network_name = reference_format.network_name()
350
339
expected = smart_req.SuccessfulSmartServerResponse(
351
(b'ok', b'no', b'no', b'no', network_name))
352
self.assertEqual(expected, request.execute(b'', network_name, b'True'))
340
('ok', 'no', 'no', 'no', network_name))
341
self.assertEqual(expected, request.execute('', network_name, 'True'))
355
344
class TestSmartServerRequestFindRepository(tests.TestCaseWithMemoryTransport):
356
345
"""Tests for BzrDir.find_repository."""
358
347
def test_no_repository(self):
359
"""If no repository is found, ('norepository', ) is returned."""
348
"""When there is no repository to be found, ('norepository', ) is returned."""
360
349
backing = self.get_transport()
361
350
request = self._request_class(backing)
362
self.make_controldir('.')
363
self.assertEqual(smart_req.SmartServerResponse((b'norepository', )),
364
request.execute(b''))
351
self.make_bzrdir('.')
352
self.assertEqual(smart_req.SmartServerResponse(('norepository', )),
366
355
def test_nonshared_repository(self):
367
356
# nonshared repositorys only allow 'find' to return a handle when the
383
372
repo = self.make_repository('.', shared=shared, format=format)
384
373
if repo.supports_rich_root():
388
377
if repo._format.supports_tree_reference:
392
381
if repo._format.supports_external_lookups:
396
385
if (smart_dir.SmartServerRequestFindRepositoryV3 ==
397
self._request_class):
386
self._request_class):
398
387
return smart_req.SuccessfulSmartServerResponse(
399
(b'ok', b'', rich_root, subtrees, external,
388
('ok', '', rich_root, subtrees, external,
400
389
repo._format.network_name()))
401
390
elif (smart_dir.SmartServerRequestFindRepositoryV2 ==
402
self._request_class):
391
self._request_class):
403
392
# All tests so far are on formats, and for non-external
405
394
return smart_req.SuccessfulSmartServerResponse(
406
(b'ok', b'', rich_root, subtrees, external))
395
('ok', '', rich_root, subtrees, external))
408
397
return smart_req.SuccessfulSmartServerResponse(
409
(b'ok', b'', rich_root, subtrees))
398
('ok', '', rich_root, subtrees))
411
400
def test_shared_repository(self):
412
"""for a shared repository, we get 'ok', 'relpath-to-repo'."""
401
"""When there is a shared repository, we get 'ok', 'relpath-to-repo'."""
413
402
backing = self.get_transport()
414
403
request = self._request_class(backing)
415
404
result = self._make_repository_and_result(shared=True)
416
self.assertEqual(result, request.execute(b''))
417
self.make_controldir('subdir')
405
self.assertEqual(result, request.execute(''))
406
self.make_bzrdir('subdir')
418
407
result2 = smart_req.SmartServerResponse(
419
result.args[0:1] + (b'..', ) + result.args[2:])
408
result.args[0:1] + ('..', ) + result.args[2:])
420
409
self.assertEqual(result2,
421
request.execute(b'subdir'))
422
self.make_controldir('subdir/deeper')
410
request.execute('subdir'))
411
self.make_bzrdir('subdir/deeper')
423
412
result3 = smart_req.SmartServerResponse(
424
result.args[0:1] + (b'../..', ) + result.args[2:])
413
result.args[0:1] + ('../..', ) + result.args[2:])
425
414
self.assertEqual(result3,
426
request.execute(b'subdir/deeper'))
415
request.execute('subdir/deeper'))
428
417
def test_rich_root_and_subtree_encoding(self):
429
418
"""Test for the format attributes for rich root and subtree support."""
837
823
"""When there is a bzrdir and no branch, NotBranchError is raised."""
838
824
backing = self.get_transport()
839
825
request = smart_branch.SmartServerBranchRequest(backing)
840
self.make_controldir('.')
826
self.make_bzrdir('.')
841
827
self.assertRaises(errors.NotBranchError,
842
request.execute, b'')
844
830
def test_branch_reference(self):
845
831
"""When there is a branch reference, NotBranchError is raised."""
846
832
backing = self.get_transport()
847
833
request = smart_branch.SmartServerBranchRequest(backing)
848
834
branch = self.make_branch('branch')
849
branch.create_checkout('reference', lightweight=True)
835
checkout = branch.create_checkout('reference',lightweight=True)
850
836
self.assertRaises(errors.NotBranchError,
851
request.execute, b'checkout')
837
request.execute, 'checkout')
854
840
class TestSmartServerBranchRequestLastRevisionInfo(
855
tests.TestCaseWithMemoryTransport):
841
tests.TestCaseWithMemoryTransport):
857
843
def test_empty(self):
858
"""For an empty branch, the result is ('ok', '0', b'null:')."""
844
"""For an empty branch, the result is ('ok', '0', 'null:')."""
859
845
backing = self.get_transport()
860
request = smart_branch.SmartServerBranchRequestLastRevisionInfo(
846
request = smart_branch.SmartServerBranchRequestLastRevisionInfo(backing)
862
847
self.make_branch('.')
864
smart_req.SmartServerResponse((b'ok', b'0', b'null:')),
865
request.execute(b''))
867
def test_ghost(self):
868
"""For an empty branch, the result is ('ok', '0', b'null:')."""
869
backing = self.get_transport()
870
request = smart_branch.SmartServerBranchRequestLastRevisionInfo(
872
branch = self.make_branch('.')
874
def last_revision_info():
875
raise errors.GhostRevisionsHaveNoRevno(b'revid1', b'revid2')
876
self.overrideAttr(branch, 'last_revision_info', last_revision_info)
877
self.assertRaises(errors.GhostRevisionsHaveNoRevno,
878
request.do_with_branch, branch)
848
self.assertEqual(smart_req.SmartServerResponse(('ok', '0', 'null:')),
880
851
def test_not_empty(self):
881
852
"""For a non-empty branch, the result is ('ok', 'revno', 'revid')."""
882
853
backing = self.get_transport()
883
request = smart_branch.SmartServerBranchRequestLastRevisionInfo(
854
request = smart_branch.SmartServerBranchRequestLastRevisionInfo(backing)
885
855
tree = self.make_branch_and_memory_tree('.')
886
856
tree.lock_write()
888
858
rev_id_utf8 = u'\xc8'.encode('utf-8')
889
tree.commit('1st commit')
890
tree.commit('2nd commit', rev_id=rev_id_utf8)
859
r1 = tree.commit('1st commit')
860
r2 = tree.commit('2nd commit', rev_id=rev_id_utf8)
892
862
self.assertEqual(
893
smart_req.SmartServerResponse((b'ok', b'2', rev_id_utf8)),
894
request.execute(b''))
863
smart_req.SmartServerResponse(('ok', '2', rev_id_utf8)),
897
867
class TestSmartServerBranchRequestRevisionIdToRevno(
898
tests.TestCaseWithMemoryTransport):
868
tests.TestCaseWithMemoryTransport):
900
870
def test_null(self):
901
871
backing = self.get_transport()
902
872
request = smart_branch.SmartServerBranchRequestRevisionIdToRevno(
904
874
self.make_branch('.')
905
self.assertEqual(smart_req.SmartServerResponse((b'ok', b'0')),
906
request.execute(b'', b'null:'))
908
def test_ghost_revision(self):
909
backing = self.get_transport()
910
request = smart_branch.SmartServerBranchRequestRevisionIdToRevno(
912
branch = self.make_branch('.')
913
def revision_id_to_dotted_revno(revid):
914
raise errors.GhostRevisionsHaveNoRevno(revid, b'ghost-revid')
915
self.overrideAttr(branch, 'revision_id_to_dotted_revno', revision_id_to_dotted_revno)
917
smart_req.FailedSmartServerResponse(
918
(b'GhostRevisionsHaveNoRevno', b'revid', b'ghost-revid')),
919
request.do_with_branch(branch, b'revid'))
875
self.assertEqual(smart_req.SmartServerResponse(('ok', '0')),
876
request.execute('', 'null:'))
921
878
def test_simple(self):
922
879
backing = self.get_transport()
1830
1775
tree = self.make_branch_and_memory_tree('.', format='2a')
1831
1776
tree.lock_write()
1833
tree.commit('1st commit', rev_id=b"rev1")
1834
tree.commit('2nd commit', rev_id=b"rev2")
1778
tree.commit('1st commit', rev_id="rev1")
1779
tree.commit('2nd commit', rev_id="rev2")
1837
self.assertIs(None, request.execute(b''))
1838
response = request.do_body(b"rev1\nrev2")
1782
self.assertIs(None, request.execute(''))
1783
response = request.do_body("rev1\nrev2")
1839
1784
self.assertTrue(response.is_successful())
1840
1785
# Format 2a uses serializer format 10
1841
self.assertEqual(response.args, (b"ok", b"10"))
1786
self.assertEqual(response.args, ("ok", "10"))
1843
1788
self.addCleanup(tree.branch.lock_read().unlock)
1844
1789
entries = [zlib.compress(record.get_bytes_as("fulltext")) for record in
1845
tree.branch.repository.revisions.get_record_stream(
1846
[(b"rev1", ), (b"rev2", )], "unordered", True)]
1790
tree.branch.repository.revisions.get_record_stream(
1791
[("rev1", ), ("rev2", )], "unordered", True)]
1848
contents = b"".join(response.body_stream)
1793
contents = "".join(response.body_stream)
1849
1794
self.assertTrue(contents in (
1850
b"".join([entries[0], entries[1]]),
1851
b"".join([entries[1], entries[0]])))
1795
"".join([entries[0], entries[1]]),
1796
"".join([entries[1], entries[0]])))
1853
1798
def test_missing(self):
1854
1799
backing = self.get_transport()
1855
1800
request = smart_repo.SmartServerRepositoryIterRevisions(backing)
1856
self.make_branch_and_memory_tree('.', format='2a')
1801
tree = self.make_branch_and_memory_tree('.', format='2a')
1858
self.assertIs(None, request.execute(b''))
1859
response = request.do_body(b"rev1\nrev2")
1803
self.assertIs(None, request.execute(''))
1804
response = request.do_body("rev1\nrev2")
1860
1805
self.assertTrue(response.is_successful())
1861
1806
# Format 2a uses serializer format 10
1862
self.assertEqual(response.args, (b"ok", b"10"))
1807
self.assertEqual(response.args, ("ok", "10"))
1864
contents = b"".join(response.body_stream)
1865
self.assertEqual(contents, b"")
1809
contents = "".join(response.body_stream)
1810
self.assertEqual(contents, "")
1868
1813
class GetStreamTestBase(tests.TestCaseWithMemoryTransport):
1885
1830
backing = self.get_transport()
1886
1831
request = smart_repo.SmartServerRepositoryGetStream(backing)
1887
1832
repo, r1, r2 = self.make_two_commit_repo()
1888
fetch_spec = [b'ancestry-of', r2]
1889
lines = b'\n'.join(fetch_spec)
1890
request.execute(b'', repo._format.network_name())
1833
fetch_spec = ['ancestry-of', r2]
1834
lines = '\n'.join(fetch_spec)
1835
request.execute('', repo._format.network_name())
1891
1836
response = request.do_body(lines)
1892
self.assertEqual((b'ok',), response.args)
1893
stream_bytes = b''.join(response.body_stream)
1894
self.assertStartsWith(stream_bytes, b'Bazaar pack format 1')
1837
self.assertEqual(('ok',), response.args)
1838
stream_bytes = ''.join(response.body_stream)
1839
self.assertStartsWith(stream_bytes, 'Bazaar pack format 1')
1896
1841
def test_search(self):
1897
1842
"""The search argument may be a 'search' of some explicit keys."""
1898
1843
backing = self.get_transport()
1899
1844
request = smart_repo.SmartServerRepositoryGetStream(backing)
1900
1845
repo, r1, r2 = self.make_two_commit_repo()
1901
fetch_spec = [b'search', r1 + b' ' + r2, b'null:', b'2']
1902
lines = b'\n'.join(fetch_spec)
1903
request.execute(b'', repo._format.network_name())
1846
fetch_spec = ['search', '%s %s' % (r1, r2), 'null:', '2']
1847
lines = '\n'.join(fetch_spec)
1848
request.execute('', repo._format.network_name())
1904
1849
response = request.do_body(lines)
1905
self.assertEqual((b'ok',), response.args)
1906
stream_bytes = b''.join(response.body_stream)
1907
self.assertStartsWith(stream_bytes, b'Bazaar pack format 1')
1850
self.assertEqual(('ok',), response.args)
1851
stream_bytes = ''.join(response.body_stream)
1852
self.assertStartsWith(stream_bytes, 'Bazaar pack format 1')
1909
1854
def test_search_everything(self):
1910
1855
"""A search of 'everything' returns a stream."""
1911
1856
backing = self.get_transport()
1912
1857
request = smart_repo.SmartServerRepositoryGetStream_1_19(backing)
1913
1858
repo, r1, r2 = self.make_two_commit_repo()
1914
serialised_fetch_spec = b'everything'
1915
request.execute(b'', repo._format.network_name())
1859
serialised_fetch_spec = 'everything'
1860
request.execute('', repo._format.network_name())
1916
1861
response = request.do_body(serialised_fetch_spec)
1917
self.assertEqual((b'ok',), response.args)
1918
stream_bytes = b''.join(response.body_stream)
1919
self.assertStartsWith(stream_bytes, b'Bazaar pack format 1')
1862
self.assertEqual(('ok',), response.args)
1863
stream_bytes = ''.join(response.body_stream)
1864
self.assertStartsWith(stream_bytes, 'Bazaar pack format 1')
1922
1867
class TestSmartServerRequestHasRevision(tests.TestCaseWithMemoryTransport):
2529
2473
def test_registered_methods(self):
2530
2474
"""Test that known methods are registered to the correct object."""
2531
self.assertHandlerEqual(b'Branch.break_lock',
2532
smart_branch.SmartServerBranchBreakLock)
2533
self.assertHandlerEqual(b'Branch.get_config_file',
2534
smart_branch.SmartServerBranchGetConfigFile)
2535
self.assertHandlerEqual(b'Branch.put_config_file',
2536
smart_branch.SmartServerBranchPutConfigFile)
2537
self.assertHandlerEqual(b'Branch.get_parent',
2538
smart_branch.SmartServerBranchGetParent)
2539
self.assertHandlerEqual(b'Branch.get_physical_lock_status',
2540
smart_branch.SmartServerBranchRequestGetPhysicalLockStatus)
2541
self.assertHandlerEqual(b'Branch.get_tags_bytes',
2542
smart_branch.SmartServerBranchGetTagsBytes)
2543
self.assertHandlerEqual(b'Branch.lock_write',
2544
smart_branch.SmartServerBranchRequestLockWrite)
2545
self.assertHandlerEqual(b'Branch.last_revision_info',
2546
smart_branch.SmartServerBranchRequestLastRevisionInfo)
2547
self.assertHandlerEqual(b'Branch.revision_history',
2548
smart_branch.SmartServerRequestRevisionHistory)
2549
self.assertHandlerEqual(b'Branch.revision_id_to_revno',
2550
smart_branch.SmartServerBranchRequestRevisionIdToRevno)
2551
self.assertHandlerEqual(b'Branch.set_config_option',
2552
smart_branch.SmartServerBranchRequestSetConfigOption)
2553
self.assertHandlerEqual(b'Branch.set_last_revision',
2554
smart_branch.SmartServerBranchRequestSetLastRevision)
2555
self.assertHandlerEqual(b'Branch.set_last_revision_info',
2556
smart_branch.SmartServerBranchRequestSetLastRevisionInfo)
2557
self.assertHandlerEqual(b'Branch.set_last_revision_ex',
2558
smart_branch.SmartServerBranchRequestSetLastRevisionEx)
2559
self.assertHandlerEqual(b'Branch.set_parent_location',
2560
smart_branch.SmartServerBranchRequestSetParentLocation)
2561
self.assertHandlerEqual(b'Branch.unlock',
2562
smart_branch.SmartServerBranchRequestUnlock)
2563
self.assertHandlerEqual(b'BzrDir.destroy_branch',
2564
smart_dir.SmartServerBzrDirRequestDestroyBranch)
2565
self.assertHandlerEqual(b'BzrDir.find_repository',
2566
smart_dir.SmartServerRequestFindRepositoryV1)
2567
self.assertHandlerEqual(b'BzrDir.find_repositoryV2',
2568
smart_dir.SmartServerRequestFindRepositoryV2)
2569
self.assertHandlerEqual(b'BzrDirFormat.initialize',
2570
smart_dir.SmartServerRequestInitializeBzrDir)
2571
self.assertHandlerEqual(b'BzrDirFormat.initialize_ex_1.16',
2572
smart_dir.SmartServerRequestBzrDirInitializeEx)
2573
self.assertHandlerEqual(b'BzrDir.checkout_metadir',
2574
smart_dir.SmartServerBzrDirRequestCheckoutMetaDir)
2575
self.assertHandlerEqual(b'BzrDir.cloning_metadir',
2576
smart_dir.SmartServerBzrDirRequestCloningMetaDir)
2577
self.assertHandlerEqual(b'BzrDir.get_branches',
2578
smart_dir.SmartServerBzrDirRequestGetBranches)
2579
self.assertHandlerEqual(b'BzrDir.get_config_file',
2580
smart_dir.SmartServerBzrDirRequestConfigFile)
2581
self.assertHandlerEqual(b'BzrDir.open_branch',
2582
smart_dir.SmartServerRequestOpenBranch)
2583
self.assertHandlerEqual(b'BzrDir.open_branchV2',
2584
smart_dir.SmartServerRequestOpenBranchV2)
2585
self.assertHandlerEqual(b'BzrDir.open_branchV3',
2586
smart_dir.SmartServerRequestOpenBranchV3)
2587
self.assertHandlerEqual(b'PackRepository.autopack',
2588
smart_packrepo.SmartServerPackRepositoryAutopack)
2589
self.assertHandlerEqual(b'Repository.add_signature_text',
2590
smart_repo.SmartServerRepositoryAddSignatureText)
2591
self.assertHandlerEqual(b'Repository.all_revision_ids',
2592
smart_repo.SmartServerRepositoryAllRevisionIds)
2593
self.assertHandlerEqual(b'Repository.break_lock',
2594
smart_repo.SmartServerRepositoryBreakLock)
2595
self.assertHandlerEqual(b'Repository.gather_stats',
2596
smart_repo.SmartServerRepositoryGatherStats)
2597
self.assertHandlerEqual(b'Repository.get_parent_map',
2598
smart_repo.SmartServerRepositoryGetParentMap)
2599
self.assertHandlerEqual(b'Repository.get_physical_lock_status',
2600
smart_repo.SmartServerRepositoryGetPhysicalLockStatus)
2601
self.assertHandlerEqual(b'Repository.get_rev_id_for_revno',
2602
smart_repo.SmartServerRepositoryGetRevIdForRevno)
2603
self.assertHandlerEqual(b'Repository.get_revision_graph',
2604
smart_repo.SmartServerRepositoryGetRevisionGraph)
2605
self.assertHandlerEqual(b'Repository.get_revision_signature_text',
2606
smart_repo.SmartServerRepositoryGetRevisionSignatureText)
2607
self.assertHandlerEqual(b'Repository.get_stream',
2608
smart_repo.SmartServerRepositoryGetStream)
2609
self.assertHandlerEqual(b'Repository.get_stream_1.19',
2610
smart_repo.SmartServerRepositoryGetStream_1_19)
2611
self.assertHandlerEqual(b'Repository.iter_revisions',
2612
smart_repo.SmartServerRepositoryIterRevisions)
2613
self.assertHandlerEqual(b'Repository.has_revision',
2614
smart_repo.SmartServerRequestHasRevision)
2615
self.assertHandlerEqual(b'Repository.insert_stream',
2616
smart_repo.SmartServerRepositoryInsertStream)
2617
self.assertHandlerEqual(b'Repository.insert_stream_locked',
2618
smart_repo.SmartServerRepositoryInsertStreamLocked)
2619
self.assertHandlerEqual(b'Repository.is_shared',
2620
smart_repo.SmartServerRepositoryIsShared)
2621
self.assertHandlerEqual(b'Repository.iter_files_bytes',
2622
smart_repo.SmartServerRepositoryIterFilesBytes)
2623
self.assertHandlerEqual(b'Repository.lock_write',
2624
smart_repo.SmartServerRepositoryLockWrite)
2625
self.assertHandlerEqual(b'Repository.make_working_trees',
2626
smart_repo.SmartServerRepositoryMakeWorkingTrees)
2627
self.assertHandlerEqual(b'Repository.pack',
2628
smart_repo.SmartServerRepositoryPack)
2629
self.assertHandlerEqual(b'Repository.reconcile',
2630
smart_repo.SmartServerRepositoryReconcile)
2631
self.assertHandlerEqual(b'Repository.tarball',
2632
smart_repo.SmartServerRepositoryTarball)
2633
self.assertHandlerEqual(b'Repository.unlock',
2634
smart_repo.SmartServerRepositoryUnlock)
2635
self.assertHandlerEqual(b'Repository.start_write_group',
2636
smart_repo.SmartServerRepositoryStartWriteGroup)
2637
self.assertHandlerEqual(b'Repository.check_write_group',
2638
smart_repo.SmartServerRepositoryCheckWriteGroup)
2639
self.assertHandlerEqual(b'Repository.commit_write_group',
2640
smart_repo.SmartServerRepositoryCommitWriteGroup)
2641
self.assertHandlerEqual(b'Repository.abort_write_group',
2642
smart_repo.SmartServerRepositoryAbortWriteGroup)
2643
self.assertHandlerEqual(b'VersionedFileRepository.get_serializer_format',
2644
smart_repo.SmartServerRepositoryGetSerializerFormat)
2645
self.assertHandlerEqual(b'VersionedFileRepository.get_inventories',
2646
smart_repo.SmartServerRepositoryGetInventories)
2647
self.assertHandlerEqual(b'Transport.is_readonly',
2648
smart_req.SmartServerIsReadonly)
2475
self.assertHandlerEqual('Branch.break_lock',
2476
smart_branch.SmartServerBranchBreakLock)
2477
self.assertHandlerEqual('Branch.get_config_file',
2478
smart_branch.SmartServerBranchGetConfigFile)
2479
self.assertHandlerEqual('Branch.put_config_file',
2480
smart_branch.SmartServerBranchPutConfigFile)
2481
self.assertHandlerEqual('Branch.get_parent',
2482
smart_branch.SmartServerBranchGetParent)
2483
self.assertHandlerEqual('Branch.get_physical_lock_status',
2484
smart_branch.SmartServerBranchRequestGetPhysicalLockStatus)
2485
self.assertHandlerEqual('Branch.get_tags_bytes',
2486
smart_branch.SmartServerBranchGetTagsBytes)
2487
self.assertHandlerEqual('Branch.lock_write',
2488
smart_branch.SmartServerBranchRequestLockWrite)
2489
self.assertHandlerEqual('Branch.last_revision_info',
2490
smart_branch.SmartServerBranchRequestLastRevisionInfo)
2491
self.assertHandlerEqual('Branch.revision_history',
2492
smart_branch.SmartServerRequestRevisionHistory)
2493
self.assertHandlerEqual('Branch.revision_id_to_revno',
2494
smart_branch.SmartServerBranchRequestRevisionIdToRevno)
2495
self.assertHandlerEqual('Branch.set_config_option',
2496
smart_branch.SmartServerBranchRequestSetConfigOption)
2497
self.assertHandlerEqual('Branch.set_last_revision',
2498
smart_branch.SmartServerBranchRequestSetLastRevision)
2499
self.assertHandlerEqual('Branch.set_last_revision_info',
2500
smart_branch.SmartServerBranchRequestSetLastRevisionInfo)
2501
self.assertHandlerEqual('Branch.set_last_revision_ex',
2502
smart_branch.SmartServerBranchRequestSetLastRevisionEx)
2503
self.assertHandlerEqual('Branch.set_parent_location',
2504
smart_branch.SmartServerBranchRequestSetParentLocation)
2505
self.assertHandlerEqual('Branch.unlock',
2506
smart_branch.SmartServerBranchRequestUnlock)
2507
self.assertHandlerEqual('BzrDir.destroy_branch',
2508
smart_dir.SmartServerBzrDirRequestDestroyBranch)
2509
self.assertHandlerEqual('BzrDir.find_repository',
2510
smart_dir.SmartServerRequestFindRepositoryV1)
2511
self.assertHandlerEqual('BzrDir.find_repositoryV2',
2512
smart_dir.SmartServerRequestFindRepositoryV2)
2513
self.assertHandlerEqual('BzrDirFormat.initialize',
2514
smart_dir.SmartServerRequestInitializeBzrDir)
2515
self.assertHandlerEqual('BzrDirFormat.initialize_ex_1.16',
2516
smart_dir.SmartServerRequestBzrDirInitializeEx)
2517
self.assertHandlerEqual('BzrDir.checkout_metadir',
2518
smart_dir.SmartServerBzrDirRequestCheckoutMetaDir)
2519
self.assertHandlerEqual('BzrDir.cloning_metadir',
2520
smart_dir.SmartServerBzrDirRequestCloningMetaDir)
2521
self.assertHandlerEqual('BzrDir.get_branches',
2522
smart_dir.SmartServerBzrDirRequestGetBranches)
2523
self.assertHandlerEqual('BzrDir.get_config_file',
2524
smart_dir.SmartServerBzrDirRequestConfigFile)
2525
self.assertHandlerEqual('BzrDir.open_branch',
2526
smart_dir.SmartServerRequestOpenBranch)
2527
self.assertHandlerEqual('BzrDir.open_branchV2',
2528
smart_dir.SmartServerRequestOpenBranchV2)
2529
self.assertHandlerEqual('BzrDir.open_branchV3',
2530
smart_dir.SmartServerRequestOpenBranchV3)
2531
self.assertHandlerEqual('PackRepository.autopack',
2532
smart_packrepo.SmartServerPackRepositoryAutopack)
2533
self.assertHandlerEqual('Repository.add_signature_text',
2534
smart_repo.SmartServerRepositoryAddSignatureText)
2535
self.assertHandlerEqual('Repository.all_revision_ids',
2536
smart_repo.SmartServerRepositoryAllRevisionIds)
2537
self.assertHandlerEqual('Repository.break_lock',
2538
smart_repo.SmartServerRepositoryBreakLock)
2539
self.assertHandlerEqual('Repository.gather_stats',
2540
smart_repo.SmartServerRepositoryGatherStats)
2541
self.assertHandlerEqual('Repository.get_parent_map',
2542
smart_repo.SmartServerRepositoryGetParentMap)
2543
self.assertHandlerEqual('Repository.get_physical_lock_status',
2544
smart_repo.SmartServerRepositoryGetPhysicalLockStatus)
2545
self.assertHandlerEqual('Repository.get_rev_id_for_revno',
2546
smart_repo.SmartServerRepositoryGetRevIdForRevno)
2547
self.assertHandlerEqual('Repository.get_revision_graph',
2548
smart_repo.SmartServerRepositoryGetRevisionGraph)
2549
self.assertHandlerEqual('Repository.get_revision_signature_text',
2550
smart_repo.SmartServerRepositoryGetRevisionSignatureText)
2551
self.assertHandlerEqual('Repository.get_stream',
2552
smart_repo.SmartServerRepositoryGetStream)
2553
self.assertHandlerEqual('Repository.get_stream_1.19',
2554
smart_repo.SmartServerRepositoryGetStream_1_19)
2555
self.assertHandlerEqual('Repository.iter_revisions',
2556
smart_repo.SmartServerRepositoryIterRevisions)
2557
self.assertHandlerEqual('Repository.has_revision',
2558
smart_repo.SmartServerRequestHasRevision)
2559
self.assertHandlerEqual('Repository.insert_stream',
2560
smart_repo.SmartServerRepositoryInsertStream)
2561
self.assertHandlerEqual('Repository.insert_stream_locked',
2562
smart_repo.SmartServerRepositoryInsertStreamLocked)
2563
self.assertHandlerEqual('Repository.is_shared',
2564
smart_repo.SmartServerRepositoryIsShared)
2565
self.assertHandlerEqual('Repository.iter_files_bytes',
2566
smart_repo.SmartServerRepositoryIterFilesBytes)
2567
self.assertHandlerEqual('Repository.lock_write',
2568
smart_repo.SmartServerRepositoryLockWrite)
2569
self.assertHandlerEqual('Repository.make_working_trees',
2570
smart_repo.SmartServerRepositoryMakeWorkingTrees)
2571
self.assertHandlerEqual('Repository.pack',
2572
smart_repo.SmartServerRepositoryPack)
2573
self.assertHandlerEqual('Repository.reconcile',
2574
smart_repo.SmartServerRepositoryReconcile)
2575
self.assertHandlerEqual('Repository.tarball',
2576
smart_repo.SmartServerRepositoryTarball)
2577
self.assertHandlerEqual('Repository.unlock',
2578
smart_repo.SmartServerRepositoryUnlock)
2579
self.assertHandlerEqual('Repository.start_write_group',
2580
smart_repo.SmartServerRepositoryStartWriteGroup)
2581
self.assertHandlerEqual('Repository.check_write_group',
2582
smart_repo.SmartServerRepositoryCheckWriteGroup)
2583
self.assertHandlerEqual('Repository.commit_write_group',
2584
smart_repo.SmartServerRepositoryCommitWriteGroup)
2585
self.assertHandlerEqual('Repository.abort_write_group',
2586
smart_repo.SmartServerRepositoryAbortWriteGroup)
2587
self.assertHandlerEqual('VersionedFileRepository.get_serializer_format',
2588
smart_repo.SmartServerRepositoryGetSerializerFormat)
2589
self.assertHandlerEqual('VersionedFileRepository.get_inventories',
2590
smart_repo.SmartServerRepositoryGetInventories)
2591
self.assertHandlerEqual('Transport.is_readonly',
2592
smart_req.SmartServerIsReadonly)
2651
2595
class SmartTCPServerHookTests(tests.TestCaseWithMemoryTransport):
2720
2660
base_inv = repository.revision_tree(base_revid).root_inventory
2721
2661
inv = repository.revision_tree(revid).root_inventory
2722
2662
inv_delta = inv._make_delta(base_inv)
2723
serializer = inventory_delta.InventoryDeltaSerializer(True, True)
2724
return b"".join(serializer.delta_to_lines(base_revid, revid, inv_delta))
2663
serializer = inventory_delta.InventoryDeltaSerializer(True, False)
2664
return "".join(serializer.delta_to_lines(base_revid, revid, inv_delta))
2726
2666
def test_single(self):
2727
2667
backing = self.get_transport()
2728
2668
request = smart_repo.SmartServerRepositoryGetInventories(backing)
2729
2669
t = self.make_branch_and_tree('.', format='2a')
2730
2670
self.addCleanup(t.lock_write().unlock)
2731
self.build_tree_contents([("file", b"somecontents")])
2732
t.add(["file"], [b"thefileid"])
2733
t.commit(rev_id=b'somerev', message="add file")
2734
self.assertIs(None, request.execute(b'', b'unordered'))
2735
response = request.do_body(b"somerev\n")
2671
self.build_tree_contents([("file", "somecontents")])
2672
t.add(["file"], ["thefileid"])
2673
t.commit(rev_id='somerev', message="add file")
2674
self.assertIs(None, request.execute('', 'unordered'))
2675
response = request.do_body("somerev\n")
2736
2676
self.assertTrue(response.is_successful())
2737
self.assertEqual(response.args, (b"ok", ))
2677
self.assertEqual(response.args, ("ok", ))
2738
2678
stream = [('inventory-deltas', [
2739
versionedfile.FulltextContentFactory(b'somerev', None, None,
2740
self._get_serialized_inventory_delta(
2741
t.branch.repository, b'null:', b'somerev'))])]
2679
versionedfile.FulltextContentFactory('somerev', None, None,
2680
self._get_serialized_inventory_delta(
2681
t.branch.repository, 'null:', 'somerev'))])]
2742
2682
fmt = controldir.format_registry.get('2a')().repository_format
2743
2683
self.assertEqual(
2744
b"".join(response.body_stream),
2745
b"".join(smart_repo._stream_to_byte_stream(stream, fmt)))
2684
"".join(response.body_stream),
2685
"".join(smart_repo._stream_to_byte_stream(stream, fmt)))
2747
2687
def test_empty(self):
2748
2688
backing = self.get_transport()
2749
2689
request = smart_repo.SmartServerRepositoryGetInventories(backing)
2750
2690
t = self.make_branch_and_tree('.', format='2a')
2751
2691
self.addCleanup(t.lock_write().unlock)
2752
self.build_tree_contents([("file", b"somecontents")])
2753
t.add(["file"], [b"thefileid"])
2754
t.commit(rev_id=b'somerev', message="add file")
2755
self.assertIs(None, request.execute(b'', b'unordered'))
2756
response = request.do_body(b"")
2757
self.assertTrue(response.is_successful())
2758
self.assertEqual(response.args, (b"ok", ))
2759
self.assertEqual(b"".join(response.body_stream),
2760
b"Bazaar pack format 1 (introduced in 0.18)\nB54\n\nBazaar repository format 2a (needs bzr 1.16 or later)\nE")
2763
class TestSmartServerRepositoryGetStreamForMissingKeys(GetStreamTestBase):
2765
def test_missing(self):
2766
"""The search argument may be a 'ancestry-of' some heads'."""
2767
backing = self.get_transport()
2768
request = smart_repo.SmartServerRepositoryGetStreamForMissingKeys(
2770
repo, r1, r2 = self.make_two_commit_repo()
2771
request.execute(b'', repo._format.network_name())
2772
lines = b'inventories\t' + r1
2773
response = request.do_body(lines)
2774
self.assertEqual((b'ok',), response.args)
2775
stream_bytes = b''.join(response.body_stream)
2776
self.assertStartsWith(stream_bytes, b'Bazaar pack format 1')
2778
def test_unknown_format(self):
2779
"""The format may not be known by the remote server."""
2780
backing = self.get_transport()
2781
request = smart_repo.SmartServerRepositoryGetStreamForMissingKeys(
2783
repo, r1, r2 = self.make_two_commit_repo()
2784
request.execute(b'', b'yada yada yada')
2785
expected = smart_req.FailedSmartServerResponse(
2786
(b'UnknownFormat', b'repository', b'yada yada yada'))
2789
class TestSmartServerRepositoryRevisionArchive(tests.TestCaseWithTransport):
2791
backing = self.get_transport()
2792
request = smart_repo.SmartServerRepositoryRevisionArchive(backing)
2793
t = self.make_branch_and_tree('.')
2794
self.addCleanup(t.lock_write().unlock)
2795
self.build_tree_contents([("file", b"somecontents")])
2796
t.add(["file"], [b"thefileid"])
2797
t.commit(rev_id=b'somerev', message="add file")
2798
response = request.execute(b'', b"somerev", b"tar", b"foo.tar", b"foo")
2799
self.assertTrue(response.is_successful())
2800
self.assertEqual(response.args, (b"ok", ))
2801
b = BytesIO(b"".join(response.body_stream))
2802
with tarfile.open(mode='r', fileobj=b) as tf:
2803
self.assertEqual(['foo/file'], tf.getnames())
2806
class TestSmartServerRepositoryAnnotateFileRevision(tests.TestCaseWithTransport):
2809
backing = self.get_transport()
2810
request = smart_repo.SmartServerRepositoryAnnotateFileRevision(backing)
2811
t = self.make_branch_and_tree('.')
2812
self.addCleanup(t.lock_write().unlock)
2813
self.build_tree_contents([("file", b"somecontents\nmorecontents\n")])
2814
t.add(["file"], [b"thefileid"])
2815
t.commit(rev_id=b'somerev', message="add file")
2816
response = request.execute(b'', b"somerev", b"file")
2817
self.assertTrue(response.is_successful())
2818
self.assertEqual(response.args, (b"ok", ))
2820
[[b'somerev', b'somecontents\n'], [b'somerev', b'morecontents\n']],
2821
bencode.bdecode(response.body))
2824
class TestSmartServerBranchRequestGetAllReferenceInfo(TestLockedBranch):
2826
def test_get_some(self):
2827
backing = self.get_transport()
2828
request = smart_branch.SmartServerBranchRequestGetAllReferenceInfo(backing)
2829
branch = self.make_branch('.')
2830
branch.set_reference_info('some/path', 'http://www.example.com/')
2831
response = request.execute(b'')
2832
self.assertTrue(response.is_successful())
2833
self.assertEqual(response.args, (b"ok", ))
2835
[[b'some/path', b'http://www.example.com/', b'']],
2836
bencode.bdecode(response.body))
2692
self.build_tree_contents([("file", "somecontents")])
2693
t.add(["file"], ["thefileid"])
2694
t.commit(rev_id='somerev', message="add file")
2695
self.assertIs(None, request.execute('', 'unordered'))
2696
response = request.do_body("")
2697
self.assertTrue(response.is_successful())
2698
self.assertEqual(response.args, ("ok", ))
2699
self.assertEqual("".join(response.body_stream),
2700
"Bazaar pack format 1 (introduced in 0.18)\nB54\n\nBazaar repository format 2a (needs bzr 1.16 or later)\nE")