214
207
request = request_class(backing)
215
208
expected = smart_req.SuccessfulSmartServerResponse(
216
209
(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'))
210
local_result.repository_format.network_name(),
211
('branch', local_result.get_branch_format().network_name())))
212
self.assertEqual(expected, request.execute('', 'False'))
221
214
def test_cloning_metadir_reference(self):
222
215
"""The request fails when bzrdir contains a branch reference."""
223
216
backing = self.get_transport()
224
217
referenced_branch = self.make_branch('referenced')
225
218
dir = self.make_controldir('.')
226
dir.cloning_metadir()
227
_mod_bzrbranch.BranchReferenceFormat().initialize(
219
local_result = dir.cloning_metadir()
220
reference = _mod_bzrbranch.BranchReferenceFormat().initialize(
228
221
dir, target_branch=referenced_branch)
229
_mod_bzrbranch.BranchReferenceFormat().get_reference(dir)
222
reference_url = _mod_bzrbranch.BranchReferenceFormat().get_reference(dir)
230
223
# The server shouldn't try to follow the branch reference, so it's fine
231
224
# if the referenced branch isn't reachable.
232
225
backing.rename('referenced', 'moved')
233
226
request_class = smart_dir.SmartServerBzrDirRequestCloningMetaDir
234
227
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):
228
expected = smart_req.FailedSmartServerResponse(('BranchReference',))
229
self.assertEqual(expected, request.execute('', 'False'))
232
class TestSmartServerBzrDirRequestCloningMetaDir(
233
tests.TestCaseWithMemoryTransport):
241
234
"""Tests for BzrDir.checkout_metadir."""
243
236
def test_checkout_metadir(self):
244
237
backing = self.get_transport()
245
238
request = smart_dir.SmartServerBzrDirRequestCheckoutMetaDir(
247
self.make_branch('.', format='2a')
248
response = request.execute(b'')
240
branch = self.make_branch('.', format='2a')
241
response = request.execute('')
249
242
self.assertEqual(
250
243
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')),
244
('Bazaar-NG meta directory, format 1\n',
245
'Bazaar repository format 2a (needs bzr 1.16 or later)\n',
246
'Bazaar Branch Format 7 (needs bzr 1.6)\n')),
257
250
class TestSmartServerBzrDirRequestDestroyBranch(
258
tests.TestCaseWithMemoryTransport):
251
tests.TestCaseWithMemoryTransport):
259
252
"""Tests for BzrDir.destroy_branch."""
261
254
def test_destroy_branch_default(self):
262
255
"""The default branch can be removed."""
263
256
backing = self.get_transport()
264
self.make_branch('.')
257
dir = self.make_branch('.').controldir
265
258
request_class = smart_dir.SmartServerBzrDirRequestDestroyBranch
266
259
request = request_class(backing)
267
expected = smart_req.SuccessfulSmartServerResponse((b'ok',))
268
self.assertEqual(expected, request.execute(b'', None))
260
expected = smart_req.SuccessfulSmartServerResponse(('ok',))
261
self.assertEqual(expected, request.execute('', None))
270
263
def test_destroy_branch_named(self):
271
264
"""A named branch can be removed."""
274
267
dir.create_branch(name="branchname")
275
268
request_class = smart_dir.SmartServerBzrDirRequestDestroyBranch
276
269
request = request_class(backing)
277
expected = smart_req.SuccessfulSmartServerResponse((b'ok',))
278
self.assertEqual(expected, request.execute(b'', b"branchname"))
270
expected = smart_req.SuccessfulSmartServerResponse(('ok',))
271
self.assertEqual(expected, request.execute('', "branchname"))
280
273
def test_destroy_branch_missing(self):
281
274
"""An error is raised if the branch didn't exist."""
282
275
backing = self.get_transport()
283
self.make_controldir('.', format="development-colo")
276
dir = self.make_controldir('.', format="development-colo")
284
277
request_class = smart_dir.SmartServerBzrDirRequestDestroyBranch
285
278
request = request_class(backing)
286
expected = smart_req.FailedSmartServerResponse((b'nobranch',), None)
287
self.assertEqual(expected, request.execute(b'', b"branchname"))
279
expected = smart_req.FailedSmartServerResponse(('nobranch',), None)
280
self.assertEqual(expected, request.execute('', "branchname"))
290
283
class TestSmartServerBzrDirRequestHasWorkingTree(
291
tests.TestCaseWithTransport):
284
tests.TestCaseWithTransport):
292
285
"""Tests for BzrDir.has_workingtree."""
294
287
def test_has_workingtree_yes(self):
295
288
"""A working tree is present."""
296
289
backing = self.get_transport()
297
self.make_branch_and_tree('.')
290
dir = self.make_branch_and_tree('.').controldir
298
291
request_class = smart_dir.SmartServerBzrDirRequestHasWorkingTree
299
292
request = request_class(backing)
300
expected = smart_req.SuccessfulSmartServerResponse((b'yes',))
301
self.assertEqual(expected, request.execute(b''))
293
expected = smart_req.SuccessfulSmartServerResponse(('yes',))
294
self.assertEqual(expected, request.execute(''))
303
296
def test_has_workingtree_no(self):
304
297
"""A working tree is missing."""
305
298
backing = self.get_transport()
306
self.make_controldir('.')
299
dir = self.make_controldir('.')
307
300
request_class = smart_dir.SmartServerBzrDirRequestHasWorkingTree
308
301
request = request_class(backing)
309
expected = smart_req.SuccessfulSmartServerResponse((b'no',))
310
self.assertEqual(expected, request.execute(b''))
302
expected = smart_req.SuccessfulSmartServerResponse(('no',))
303
self.assertEqual(expected, request.execute(''))
313
306
class TestSmartServerBzrDirRequestDestroyRepository(
314
tests.TestCaseWithMemoryTransport):
307
tests.TestCaseWithMemoryTransport):
315
308
"""Tests for BzrDir.destroy_repository."""
317
310
def test_destroy_repository_default(self):
318
311
"""The repository can be removed."""
319
312
backing = self.get_transport()
320
self.make_repository('.')
313
dir = self.make_repository('.').controldir
321
314
request_class = smart_dir.SmartServerBzrDirRequestDestroyRepository
322
315
request = request_class(backing)
323
expected = smart_req.SuccessfulSmartServerResponse((b'ok',))
324
self.assertEqual(expected, request.execute(b''))
316
expected = smart_req.SuccessfulSmartServerResponse(('ok',))
317
self.assertEqual(expected, request.execute(''))
326
319
def test_destroy_repository_missing(self):
327
320
"""An error is raised if the repository didn't exist."""
328
321
backing = self.get_transport()
329
self.make_controldir('.')
322
dir = self.make_controldir('.')
330
323
request_class = smart_dir.SmartServerBzrDirRequestDestroyRepository
331
324
request = request_class(backing)
332
325
expected = smart_req.FailedSmartServerResponse(
333
(b'norepository',), None)
334
self.assertEqual(expected, request.execute(b''))
337
class TestSmartServerRequestCreateRepository(
338
tests.TestCaseWithMemoryTransport):
326
('norepository',), None)
327
self.assertEqual(expected, request.execute(''))
330
class TestSmartServerRequestCreateRepository(tests.TestCaseWithMemoryTransport):
339
331
"""Tests for BzrDir.create_repository."""
341
333
def test_makes_repository(self):
383
375
repo = self.make_repository('.', shared=shared, format=format)
384
376
if repo.supports_rich_root():
388
380
if repo._format.supports_tree_reference:
392
384
if repo._format.supports_external_lookups:
396
388
if (smart_dir.SmartServerRequestFindRepositoryV3 ==
397
self._request_class):
389
self._request_class):
398
390
return smart_req.SuccessfulSmartServerResponse(
399
(b'ok', b'', rich_root, subtrees, external,
391
('ok', '', rich_root, subtrees, external,
400
392
repo._format.network_name()))
401
393
elif (smart_dir.SmartServerRequestFindRepositoryV2 ==
402
self._request_class):
394
self._request_class):
403
395
# All tests so far are on formats, and for non-external
405
397
return smart_req.SuccessfulSmartServerResponse(
406
(b'ok', b'', rich_root, subtrees, external))
398
('ok', '', rich_root, subtrees, external))
408
400
return smart_req.SuccessfulSmartServerResponse(
409
(b'ok', b'', rich_root, subtrees))
401
('ok', '', rich_root, subtrees))
411
403
def test_shared_repository(self):
412
"""for a shared repository, we get 'ok', 'relpath-to-repo'."""
404
"""When there is a shared repository, we get 'ok', 'relpath-to-repo'."""
413
405
backing = self.get_transport()
414
406
request = self._request_class(backing)
415
407
result = self._make_repository_and_result(shared=True)
416
self.assertEqual(result, request.execute(b''))
408
self.assertEqual(result, request.execute(''))
417
409
self.make_controldir('subdir')
418
410
result2 = smart_req.SmartServerResponse(
419
result.args[0:1] + (b'..', ) + result.args[2:])
411
result.args[0:1] + ('..', ) + result.args[2:])
420
412
self.assertEqual(result2,
421
request.execute(b'subdir'))
413
request.execute('subdir'))
422
414
self.make_controldir('subdir/deeper')
423
415
result3 = smart_req.SmartServerResponse(
424
result.args[0:1] + (b'../..', ) + result.args[2:])
416
result.args[0:1] + ('../..', ) + result.args[2:])
425
417
self.assertEqual(result3,
426
request.execute(b'subdir/deeper'))
418
request.execute('subdir/deeper'))
428
420
def test_rich_root_and_subtree_encoding(self):
429
421
"""Test for the format attributes for rich root and subtree support."""
852
828
request = smart_branch.SmartServerBranchRequest(backing)
853
829
self.make_controldir('.')
854
830
self.assertRaises(errors.NotBranchError,
855
request.execute, b'')
857
833
def test_branch_reference(self):
858
834
"""When there is a branch reference, NotBranchError is raised."""
859
835
backing = self.get_transport()
860
836
request = smart_branch.SmartServerBranchRequest(backing)
861
837
branch = self.make_branch('branch')
862
branch.create_checkout('reference', lightweight=True)
838
checkout = branch.create_checkout('reference', lightweight=True)
863
839
self.assertRaises(errors.NotBranchError,
864
request.execute, b'checkout')
840
request.execute, 'checkout')
867
843
class TestSmartServerBranchRequestLastRevisionInfo(
868
tests.TestCaseWithMemoryTransport):
844
tests.TestCaseWithMemoryTransport):
870
846
def test_empty(self):
871
"""For an empty branch, the result is ('ok', '0', b'null:')."""
847
"""For an empty branch, the result is ('ok', '0', 'null:')."""
872
848
backing = self.get_transport()
873
request = smart_branch.SmartServerBranchRequestLastRevisionInfo(
849
request = smart_branch.SmartServerBranchRequestLastRevisionInfo(backing)
875
850
self.make_branch('.')
877
smart_req.SmartServerResponse((b'ok', b'0', b'null:')),
878
request.execute(b''))
880
def test_ghost(self):
881
"""For an empty branch, the result is ('ok', '0', b'null:')."""
882
backing = self.get_transport()
883
request = smart_branch.SmartServerBranchRequestLastRevisionInfo(
885
branch = self.make_branch('.')
887
def last_revision_info():
888
raise errors.GhostRevisionsHaveNoRevno(b'revid1', b'revid2')
889
self.overrideAttr(branch, 'last_revision_info', last_revision_info)
890
self.assertRaises(errors.GhostRevisionsHaveNoRevno,
891
request.do_with_branch, branch)
851
self.assertEqual(smart_req.SmartServerResponse(('ok', '0', 'null:')),
893
854
def test_not_empty(self):
894
855
"""For a non-empty branch, the result is ('ok', 'revno', 'revid')."""
895
856
backing = self.get_transport()
896
request = smart_branch.SmartServerBranchRequestLastRevisionInfo(
857
request = smart_branch.SmartServerBranchRequestLastRevisionInfo(backing)
898
858
tree = self.make_branch_and_memory_tree('.')
899
859
tree.lock_write()
901
861
rev_id_utf8 = u'\xc8'.encode('utf-8')
902
tree.commit('1st commit')
903
tree.commit('2nd commit', rev_id=rev_id_utf8)
862
r1 = tree.commit('1st commit')
863
r2 = tree.commit('2nd commit', rev_id=rev_id_utf8)
905
865
self.assertEqual(
906
smart_req.SmartServerResponse((b'ok', b'2', rev_id_utf8)),
907
request.execute(b''))
866
smart_req.SmartServerResponse(('ok', '2', rev_id_utf8)),
910
870
class TestSmartServerBranchRequestRevisionIdToRevno(
911
tests.TestCaseWithMemoryTransport):
871
tests.TestCaseWithMemoryTransport):
913
873
def test_null(self):
914
874
backing = self.get_transport()
915
875
request = smart_branch.SmartServerBranchRequestRevisionIdToRevno(
917
877
self.make_branch('.')
918
self.assertEqual(smart_req.SmartServerResponse((b'ok', b'0')),
919
request.execute(b'', b'null:'))
921
def test_ghost_revision(self):
922
backing = self.get_transport()
923
request = smart_branch.SmartServerBranchRequestRevisionIdToRevno(
925
branch = self.make_branch('.')
926
def revision_id_to_dotted_revno(revid):
927
raise errors.GhostRevisionsHaveNoRevno(revid, b'ghost-revid')
928
self.overrideAttr(branch, 'revision_id_to_dotted_revno', revision_id_to_dotted_revno)
930
smart_req.FailedSmartServerResponse(
931
(b'GhostRevisionsHaveNoRevno', b'revid', b'ghost-revid')),
932
request.do_with_branch(branch, b'revid'))
878
self.assertEqual(smart_req.SmartServerResponse(('ok', '0')),
879
request.execute('', 'null:'))
934
881
def test_simple(self):
935
882
backing = self.get_transport()
1843
1778
tree = self.make_branch_and_memory_tree('.', format='2a')
1844
1779
tree.lock_write()
1846
tree.commit('1st commit', rev_id=b"rev1")
1847
tree.commit('2nd commit', rev_id=b"rev2")
1781
tree.commit('1st commit', rev_id="rev1")
1782
tree.commit('2nd commit', rev_id="rev2")
1850
self.assertIs(None, request.execute(b''))
1851
response = request.do_body(b"rev1\nrev2")
1785
self.assertIs(None, request.execute(''))
1786
response = request.do_body("rev1\nrev2")
1852
1787
self.assertTrue(response.is_successful())
1853
1788
# Format 2a uses serializer format 10
1854
self.assertEqual(response.args, (b"ok", b"10"))
1789
self.assertEqual(response.args, ("ok", "10"))
1856
1791
self.addCleanup(tree.branch.lock_read().unlock)
1857
1792
entries = [zlib.compress(record.get_bytes_as("fulltext")) for record in
1858
tree.branch.repository.revisions.get_record_stream(
1859
[(b"rev1", ), (b"rev2", )], "unordered", True)]
1793
tree.branch.repository.revisions.get_record_stream(
1794
[("rev1", ), ("rev2", )], "unordered", True)]
1861
contents = b"".join(response.body_stream)
1796
contents = "".join(response.body_stream)
1862
1797
self.assertTrue(contents in (
1863
b"".join([entries[0], entries[1]]),
1864
b"".join([entries[1], entries[0]])))
1798
"".join([entries[0], entries[1]]),
1799
"".join([entries[1], entries[0]])))
1866
1801
def test_missing(self):
1867
1802
backing = self.get_transport()
1868
1803
request = smart_repo.SmartServerRepositoryIterRevisions(backing)
1869
self.make_branch_and_memory_tree('.', format='2a')
1804
tree = self.make_branch_and_memory_tree('.', format='2a')
1871
self.assertIs(None, request.execute(b''))
1872
response = request.do_body(b"rev1\nrev2")
1806
self.assertIs(None, request.execute(''))
1807
response = request.do_body("rev1\nrev2")
1873
1808
self.assertTrue(response.is_successful())
1874
1809
# Format 2a uses serializer format 10
1875
self.assertEqual(response.args, (b"ok", b"10"))
1810
self.assertEqual(response.args, ("ok", "10"))
1877
contents = b"".join(response.body_stream)
1878
self.assertEqual(contents, b"")
1812
contents = "".join(response.body_stream)
1813
self.assertEqual(contents, "")
1881
1816
class GetStreamTestBase(tests.TestCaseWithMemoryTransport):
1898
1833
backing = self.get_transport()
1899
1834
request = smart_repo.SmartServerRepositoryGetStream(backing)
1900
1835
repo, r1, r2 = self.make_two_commit_repo()
1901
fetch_spec = [b'ancestry-of', r2]
1902
lines = b'\n'.join(fetch_spec)
1903
request.execute(b'', repo._format.network_name())
1836
fetch_spec = ['ancestry-of', r2]
1837
lines = '\n'.join(fetch_spec)
1838
request.execute('', repo._format.network_name())
1904
1839
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')
1840
self.assertEqual(('ok',), response.args)
1841
stream_bytes = ''.join(response.body_stream)
1842
self.assertStartsWith(stream_bytes, 'Bazaar pack format 1')
1909
1844
def test_search(self):
1910
1845
"""The search argument may be a 'search' of some explicit keys."""
1911
1846
backing = self.get_transport()
1912
1847
request = smart_repo.SmartServerRepositoryGetStream(backing)
1913
1848
repo, r1, r2 = self.make_two_commit_repo()
1914
fetch_spec = [b'search', r1 + b' ' + r2, b'null:', b'2']
1915
lines = b'\n'.join(fetch_spec)
1916
request.execute(b'', repo._format.network_name())
1849
fetch_spec = ['search', '%s %s' % (r1, r2), 'null:', '2']
1850
lines = '\n'.join(fetch_spec)
1851
request.execute('', repo._format.network_name())
1917
1852
response = request.do_body(lines)
1918
self.assertEqual((b'ok',), response.args)
1919
stream_bytes = b''.join(response.body_stream)
1920
self.assertStartsWith(stream_bytes, b'Bazaar pack format 1')
1853
self.assertEqual(('ok',), response.args)
1854
stream_bytes = ''.join(response.body_stream)
1855
self.assertStartsWith(stream_bytes, 'Bazaar pack format 1')
1922
1857
def test_search_everything(self):
1923
1858
"""A search of 'everything' returns a stream."""
1924
1859
backing = self.get_transport()
1925
1860
request = smart_repo.SmartServerRepositoryGetStream_1_19(backing)
1926
1861
repo, r1, r2 = self.make_two_commit_repo()
1927
serialised_fetch_spec = b'everything'
1928
request.execute(b'', repo._format.network_name())
1862
serialised_fetch_spec = 'everything'
1863
request.execute('', repo._format.network_name())
1929
1864
response = request.do_body(serialised_fetch_spec)
1930
self.assertEqual((b'ok',), response.args)
1931
stream_bytes = b''.join(response.body_stream)
1932
self.assertStartsWith(stream_bytes, b'Bazaar pack format 1')
1865
self.assertEqual(('ok',), response.args)
1866
stream_bytes = ''.join(response.body_stream)
1867
self.assertStartsWith(stream_bytes, 'Bazaar pack format 1')
1935
1870
class TestSmartServerRequestHasRevision(tests.TestCaseWithMemoryTransport):
2542
2476
def test_registered_methods(self):
2543
2477
"""Test that known methods are registered to the correct object."""
2544
self.assertHandlerEqual(b'Branch.break_lock',
2545
smart_branch.SmartServerBranchBreakLock)
2546
self.assertHandlerEqual(b'Branch.get_config_file',
2547
smart_branch.SmartServerBranchGetConfigFile)
2548
self.assertHandlerEqual(b'Branch.put_config_file',
2549
smart_branch.SmartServerBranchPutConfigFile)
2550
self.assertHandlerEqual(b'Branch.get_parent',
2551
smart_branch.SmartServerBranchGetParent)
2552
self.assertHandlerEqual(b'Branch.get_physical_lock_status',
2553
smart_branch.SmartServerBranchRequestGetPhysicalLockStatus)
2554
self.assertHandlerEqual(b'Branch.get_tags_bytes',
2555
smart_branch.SmartServerBranchGetTagsBytes)
2556
self.assertHandlerEqual(b'Branch.lock_write',
2557
smart_branch.SmartServerBranchRequestLockWrite)
2558
self.assertHandlerEqual(b'Branch.last_revision_info',
2559
smart_branch.SmartServerBranchRequestLastRevisionInfo)
2560
self.assertHandlerEqual(b'Branch.revision_history',
2561
smart_branch.SmartServerRequestRevisionHistory)
2562
self.assertHandlerEqual(b'Branch.revision_id_to_revno',
2563
smart_branch.SmartServerBranchRequestRevisionIdToRevno)
2564
self.assertHandlerEqual(b'Branch.set_config_option',
2565
smart_branch.SmartServerBranchRequestSetConfigOption)
2566
self.assertHandlerEqual(b'Branch.set_last_revision',
2567
smart_branch.SmartServerBranchRequestSetLastRevision)
2568
self.assertHandlerEqual(b'Branch.set_last_revision_info',
2569
smart_branch.SmartServerBranchRequestSetLastRevisionInfo)
2570
self.assertHandlerEqual(b'Branch.set_last_revision_ex',
2571
smart_branch.SmartServerBranchRequestSetLastRevisionEx)
2572
self.assertHandlerEqual(b'Branch.set_parent_location',
2573
smart_branch.SmartServerBranchRequestSetParentLocation)
2574
self.assertHandlerEqual(b'Branch.unlock',
2575
smart_branch.SmartServerBranchRequestUnlock)
2576
self.assertHandlerEqual(b'BzrDir.destroy_branch',
2577
smart_dir.SmartServerBzrDirRequestDestroyBranch)
2578
self.assertHandlerEqual(b'BzrDir.find_repository',
2579
smart_dir.SmartServerRequestFindRepositoryV1)
2580
self.assertHandlerEqual(b'BzrDir.find_repositoryV2',
2581
smart_dir.SmartServerRequestFindRepositoryV2)
2582
self.assertHandlerEqual(b'BzrDirFormat.initialize',
2583
smart_dir.SmartServerRequestInitializeBzrDir)
2584
self.assertHandlerEqual(b'BzrDirFormat.initialize_ex_1.16',
2585
smart_dir.SmartServerRequestBzrDirInitializeEx)
2586
self.assertHandlerEqual(b'BzrDir.checkout_metadir',
2587
smart_dir.SmartServerBzrDirRequestCheckoutMetaDir)
2588
self.assertHandlerEqual(b'BzrDir.cloning_metadir',
2589
smart_dir.SmartServerBzrDirRequestCloningMetaDir)
2590
self.assertHandlerEqual(b'BzrDir.get_branches',
2591
smart_dir.SmartServerBzrDirRequestGetBranches)
2592
self.assertHandlerEqual(b'BzrDir.get_config_file',
2593
smart_dir.SmartServerBzrDirRequestConfigFile)
2594
self.assertHandlerEqual(b'BzrDir.open_branch',
2595
smart_dir.SmartServerRequestOpenBranch)
2596
self.assertHandlerEqual(b'BzrDir.open_branchV2',
2597
smart_dir.SmartServerRequestOpenBranchV2)
2598
self.assertHandlerEqual(b'BzrDir.open_branchV3',
2599
smart_dir.SmartServerRequestOpenBranchV3)
2600
self.assertHandlerEqual(b'PackRepository.autopack',
2601
smart_packrepo.SmartServerPackRepositoryAutopack)
2602
self.assertHandlerEqual(b'Repository.add_signature_text',
2603
smart_repo.SmartServerRepositoryAddSignatureText)
2604
self.assertHandlerEqual(b'Repository.all_revision_ids',
2605
smart_repo.SmartServerRepositoryAllRevisionIds)
2606
self.assertHandlerEqual(b'Repository.break_lock',
2607
smart_repo.SmartServerRepositoryBreakLock)
2608
self.assertHandlerEqual(b'Repository.gather_stats',
2609
smart_repo.SmartServerRepositoryGatherStats)
2610
self.assertHandlerEqual(b'Repository.get_parent_map',
2611
smart_repo.SmartServerRepositoryGetParentMap)
2612
self.assertHandlerEqual(b'Repository.get_physical_lock_status',
2613
smart_repo.SmartServerRepositoryGetPhysicalLockStatus)
2614
self.assertHandlerEqual(b'Repository.get_rev_id_for_revno',
2615
smart_repo.SmartServerRepositoryGetRevIdForRevno)
2616
self.assertHandlerEqual(b'Repository.get_revision_graph',
2617
smart_repo.SmartServerRepositoryGetRevisionGraph)
2618
self.assertHandlerEqual(b'Repository.get_revision_signature_text',
2619
smart_repo.SmartServerRepositoryGetRevisionSignatureText)
2620
self.assertHandlerEqual(b'Repository.get_stream',
2621
smart_repo.SmartServerRepositoryGetStream)
2622
self.assertHandlerEqual(b'Repository.get_stream_1.19',
2623
smart_repo.SmartServerRepositoryGetStream_1_19)
2624
self.assertHandlerEqual(b'Repository.iter_revisions',
2625
smart_repo.SmartServerRepositoryIterRevisions)
2626
self.assertHandlerEqual(b'Repository.has_revision',
2627
smart_repo.SmartServerRequestHasRevision)
2628
self.assertHandlerEqual(b'Repository.insert_stream',
2629
smart_repo.SmartServerRepositoryInsertStream)
2630
self.assertHandlerEqual(b'Repository.insert_stream_locked',
2631
smart_repo.SmartServerRepositoryInsertStreamLocked)
2632
self.assertHandlerEqual(b'Repository.is_shared',
2633
smart_repo.SmartServerRepositoryIsShared)
2634
self.assertHandlerEqual(b'Repository.iter_files_bytes',
2635
smart_repo.SmartServerRepositoryIterFilesBytes)
2636
self.assertHandlerEqual(b'Repository.lock_write',
2637
smart_repo.SmartServerRepositoryLockWrite)
2638
self.assertHandlerEqual(b'Repository.make_working_trees',
2639
smart_repo.SmartServerRepositoryMakeWorkingTrees)
2640
self.assertHandlerEqual(b'Repository.pack',
2641
smart_repo.SmartServerRepositoryPack)
2642
self.assertHandlerEqual(b'Repository.reconcile',
2643
smart_repo.SmartServerRepositoryReconcile)
2644
self.assertHandlerEqual(b'Repository.tarball',
2645
smart_repo.SmartServerRepositoryTarball)
2646
self.assertHandlerEqual(b'Repository.unlock',
2647
smart_repo.SmartServerRepositoryUnlock)
2648
self.assertHandlerEqual(b'Repository.start_write_group',
2649
smart_repo.SmartServerRepositoryStartWriteGroup)
2650
self.assertHandlerEqual(b'Repository.check_write_group',
2651
smart_repo.SmartServerRepositoryCheckWriteGroup)
2652
self.assertHandlerEqual(b'Repository.commit_write_group',
2653
smart_repo.SmartServerRepositoryCommitWriteGroup)
2654
self.assertHandlerEqual(b'Repository.abort_write_group',
2655
smart_repo.SmartServerRepositoryAbortWriteGroup)
2656
self.assertHandlerEqual(b'VersionedFileRepository.get_serializer_format',
2657
smart_repo.SmartServerRepositoryGetSerializerFormat)
2658
self.assertHandlerEqual(b'VersionedFileRepository.get_inventories',
2659
smart_repo.SmartServerRepositoryGetInventories)
2660
self.assertHandlerEqual(b'Transport.is_readonly',
2661
smart_req.SmartServerIsReadonly)
2478
self.assertHandlerEqual('Branch.break_lock',
2479
smart_branch.SmartServerBranchBreakLock)
2480
self.assertHandlerEqual('Branch.get_config_file',
2481
smart_branch.SmartServerBranchGetConfigFile)
2482
self.assertHandlerEqual('Branch.put_config_file',
2483
smart_branch.SmartServerBranchPutConfigFile)
2484
self.assertHandlerEqual('Branch.get_parent',
2485
smart_branch.SmartServerBranchGetParent)
2486
self.assertHandlerEqual('Branch.get_physical_lock_status',
2487
smart_branch.SmartServerBranchRequestGetPhysicalLockStatus)
2488
self.assertHandlerEqual('Branch.get_tags_bytes',
2489
smart_branch.SmartServerBranchGetTagsBytes)
2490
self.assertHandlerEqual('Branch.lock_write',
2491
smart_branch.SmartServerBranchRequestLockWrite)
2492
self.assertHandlerEqual('Branch.last_revision_info',
2493
smart_branch.SmartServerBranchRequestLastRevisionInfo)
2494
self.assertHandlerEqual('Branch.revision_history',
2495
smart_branch.SmartServerRequestRevisionHistory)
2496
self.assertHandlerEqual('Branch.revision_id_to_revno',
2497
smart_branch.SmartServerBranchRequestRevisionIdToRevno)
2498
self.assertHandlerEqual('Branch.set_config_option',
2499
smart_branch.SmartServerBranchRequestSetConfigOption)
2500
self.assertHandlerEqual('Branch.set_last_revision',
2501
smart_branch.SmartServerBranchRequestSetLastRevision)
2502
self.assertHandlerEqual('Branch.set_last_revision_info',
2503
smart_branch.SmartServerBranchRequestSetLastRevisionInfo)
2504
self.assertHandlerEqual('Branch.set_last_revision_ex',
2505
smart_branch.SmartServerBranchRequestSetLastRevisionEx)
2506
self.assertHandlerEqual('Branch.set_parent_location',
2507
smart_branch.SmartServerBranchRequestSetParentLocation)
2508
self.assertHandlerEqual('Branch.unlock',
2509
smart_branch.SmartServerBranchRequestUnlock)
2510
self.assertHandlerEqual('BzrDir.destroy_branch',
2511
smart_dir.SmartServerBzrDirRequestDestroyBranch)
2512
self.assertHandlerEqual('BzrDir.find_repository',
2513
smart_dir.SmartServerRequestFindRepositoryV1)
2514
self.assertHandlerEqual('BzrDir.find_repositoryV2',
2515
smart_dir.SmartServerRequestFindRepositoryV2)
2516
self.assertHandlerEqual('BzrDirFormat.initialize',
2517
smart_dir.SmartServerRequestInitializeBzrDir)
2518
self.assertHandlerEqual('BzrDirFormat.initialize_ex_1.16',
2519
smart_dir.SmartServerRequestBzrDirInitializeEx)
2520
self.assertHandlerEqual('BzrDir.checkout_metadir',
2521
smart_dir.SmartServerBzrDirRequestCheckoutMetaDir)
2522
self.assertHandlerEqual('BzrDir.cloning_metadir',
2523
smart_dir.SmartServerBzrDirRequestCloningMetaDir)
2524
self.assertHandlerEqual('BzrDir.get_branches',
2525
smart_dir.SmartServerBzrDirRequestGetBranches)
2526
self.assertHandlerEqual('BzrDir.get_config_file',
2527
smart_dir.SmartServerBzrDirRequestConfigFile)
2528
self.assertHandlerEqual('BzrDir.open_branch',
2529
smart_dir.SmartServerRequestOpenBranch)
2530
self.assertHandlerEqual('BzrDir.open_branchV2',
2531
smart_dir.SmartServerRequestOpenBranchV2)
2532
self.assertHandlerEqual('BzrDir.open_branchV3',
2533
smart_dir.SmartServerRequestOpenBranchV3)
2534
self.assertHandlerEqual('PackRepository.autopack',
2535
smart_packrepo.SmartServerPackRepositoryAutopack)
2536
self.assertHandlerEqual('Repository.add_signature_text',
2537
smart_repo.SmartServerRepositoryAddSignatureText)
2538
self.assertHandlerEqual('Repository.all_revision_ids',
2539
smart_repo.SmartServerRepositoryAllRevisionIds)
2540
self.assertHandlerEqual('Repository.break_lock',
2541
smart_repo.SmartServerRepositoryBreakLock)
2542
self.assertHandlerEqual('Repository.gather_stats',
2543
smart_repo.SmartServerRepositoryGatherStats)
2544
self.assertHandlerEqual('Repository.get_parent_map',
2545
smart_repo.SmartServerRepositoryGetParentMap)
2546
self.assertHandlerEqual('Repository.get_physical_lock_status',
2547
smart_repo.SmartServerRepositoryGetPhysicalLockStatus)
2548
self.assertHandlerEqual('Repository.get_rev_id_for_revno',
2549
smart_repo.SmartServerRepositoryGetRevIdForRevno)
2550
self.assertHandlerEqual('Repository.get_revision_graph',
2551
smart_repo.SmartServerRepositoryGetRevisionGraph)
2552
self.assertHandlerEqual('Repository.get_revision_signature_text',
2553
smart_repo.SmartServerRepositoryGetRevisionSignatureText)
2554
self.assertHandlerEqual('Repository.get_stream',
2555
smart_repo.SmartServerRepositoryGetStream)
2556
self.assertHandlerEqual('Repository.get_stream_1.19',
2557
smart_repo.SmartServerRepositoryGetStream_1_19)
2558
self.assertHandlerEqual('Repository.iter_revisions',
2559
smart_repo.SmartServerRepositoryIterRevisions)
2560
self.assertHandlerEqual('Repository.has_revision',
2561
smart_repo.SmartServerRequestHasRevision)
2562
self.assertHandlerEqual('Repository.insert_stream',
2563
smart_repo.SmartServerRepositoryInsertStream)
2564
self.assertHandlerEqual('Repository.insert_stream_locked',
2565
smart_repo.SmartServerRepositoryInsertStreamLocked)
2566
self.assertHandlerEqual('Repository.is_shared',
2567
smart_repo.SmartServerRepositoryIsShared)
2568
self.assertHandlerEqual('Repository.iter_files_bytes',
2569
smart_repo.SmartServerRepositoryIterFilesBytes)
2570
self.assertHandlerEqual('Repository.lock_write',
2571
smart_repo.SmartServerRepositoryLockWrite)
2572
self.assertHandlerEqual('Repository.make_working_trees',
2573
smart_repo.SmartServerRepositoryMakeWorkingTrees)
2574
self.assertHandlerEqual('Repository.pack',
2575
smart_repo.SmartServerRepositoryPack)
2576
self.assertHandlerEqual('Repository.reconcile',
2577
smart_repo.SmartServerRepositoryReconcile)
2578
self.assertHandlerEqual('Repository.tarball',
2579
smart_repo.SmartServerRepositoryTarball)
2580
self.assertHandlerEqual('Repository.unlock',
2581
smart_repo.SmartServerRepositoryUnlock)
2582
self.assertHandlerEqual('Repository.start_write_group',
2583
smart_repo.SmartServerRepositoryStartWriteGroup)
2584
self.assertHandlerEqual('Repository.check_write_group',
2585
smart_repo.SmartServerRepositoryCheckWriteGroup)
2586
self.assertHandlerEqual('Repository.commit_write_group',
2587
smart_repo.SmartServerRepositoryCommitWriteGroup)
2588
self.assertHandlerEqual('Repository.abort_write_group',
2589
smart_repo.SmartServerRepositoryAbortWriteGroup)
2590
self.assertHandlerEqual('VersionedFileRepository.get_serializer_format',
2591
smart_repo.SmartServerRepositoryGetSerializerFormat)
2592
self.assertHandlerEqual('VersionedFileRepository.get_inventories',
2593
smart_repo.SmartServerRepositoryGetInventories)
2594
self.assertHandlerEqual('Transport.is_readonly',
2595
smart_req.SmartServerIsReadonly)
2664
2598
class SmartTCPServerHookTests(tests.TestCaseWithMemoryTransport):
2765
2695
self.build_tree_contents([("file", b"somecontents")])
2766
2696
t.add(["file"], [b"thefileid"])
2767
2697
t.commit(rev_id=b'somerev', message="add file")
2768
self.assertIs(None, request.execute(b'', b'unordered'))
2769
response = request.do_body(b"")
2770
self.assertTrue(response.is_successful())
2771
self.assertEqual(response.args, (b"ok", ))
2772
self.assertEqual(b"".join(response.body_stream),
2773
b"Bazaar pack format 1 (introduced in 0.18)\nB54\n\nBazaar repository format 2a (needs bzr 1.16 or later)\nE")
2776
class TestSmartServerRepositoryGetStreamForMissingKeys(GetStreamTestBase):
2778
def test_missing(self):
2779
"""The search argument may be a 'ancestry-of' some heads'."""
2780
backing = self.get_transport()
2781
request = smart_repo.SmartServerRepositoryGetStreamForMissingKeys(
2783
repo, r1, r2 = self.make_two_commit_repo()
2784
request.execute(b'', repo._format.network_name())
2785
lines = b'inventories\t' + r1
2786
response = request.do_body(lines)
2787
self.assertEqual((b'ok',), response.args)
2788
stream_bytes = b''.join(response.body_stream)
2789
self.assertStartsWith(stream_bytes, b'Bazaar pack format 1')
2791
def test_unknown_format(self):
2792
"""The format may not be known by the remote server."""
2793
backing = self.get_transport()
2794
request = smart_repo.SmartServerRepositoryGetStreamForMissingKeys(
2796
repo, r1, r2 = self.make_two_commit_repo()
2797
request.execute(b'', b'yada yada yada')
2798
expected = smart_req.FailedSmartServerResponse(
2799
(b'UnknownFormat', b'repository', b'yada yada yada'))
2802
class TestSmartServerRepositoryRevisionArchive(tests.TestCaseWithTransport):
2804
backing = self.get_transport()
2805
request = smart_repo.SmartServerRepositoryRevisionArchive(backing)
2806
t = self.make_branch_and_tree('.')
2807
self.addCleanup(t.lock_write().unlock)
2808
self.build_tree_contents([("file", b"somecontents")])
2809
t.add(["file"], [b"thefileid"])
2810
t.commit(rev_id=b'somerev', message="add file")
2811
response = request.execute(b'', b"somerev", b"tar", b"foo.tar", b"foo")
2812
self.assertTrue(response.is_successful())
2813
self.assertEqual(response.args, (b"ok", ))
2814
b = BytesIO(b"".join(response.body_stream))
2815
with tarfile.open(mode='r', fileobj=b) as tf:
2816
self.assertEqual(['foo/file'], tf.getnames())
2819
class TestSmartServerRepositoryAnnotateFileRevision(tests.TestCaseWithTransport):
2822
backing = self.get_transport()
2823
request = smart_repo.SmartServerRepositoryAnnotateFileRevision(backing)
2824
t = self.make_branch_and_tree('.')
2825
self.addCleanup(t.lock_write().unlock)
2826
self.build_tree_contents([("file", b"somecontents\nmorecontents\n")])
2827
t.add(["file"], [b"thefileid"])
2828
t.commit(rev_id=b'somerev', message="add file")
2829
response = request.execute(b'', b"somerev", b"file")
2830
self.assertTrue(response.is_successful())
2831
self.assertEqual(response.args, (b"ok", ))
2833
[[b'somerev', b'somecontents\n'], [b'somerev', b'morecontents\n']],
2834
bencode.bdecode(response.body))
2837
class TestSmartServerBranchRequestGetAllReferenceInfo(TestLockedBranch):
2839
def test_get_some(self):
2840
backing = self.get_transport()
2841
request = smart_branch.SmartServerBranchRequestGetAllReferenceInfo(backing)
2842
branch = self.make_branch('.')
2843
branch.set_reference_info('some/path', 'http://www.example.com/')
2844
response = request.execute(b'')
2845
self.assertTrue(response.is_successful())
2846
self.assertEqual(response.args, (b"ok", ))
2848
[[b'some/path', b'http://www.example.com/', b'']],
2849
bencode.bdecode(response.body))
2698
self.assertIs(None, request.execute('', 'unordered'))
2699
response = request.do_body("")
2700
self.assertTrue(response.is_successful())
2701
self.assertEqual(response.args, ("ok", ))
2702
self.assertEqual("".join(response.body_stream),
2703
"Bazaar pack format 1 (introduced in 0.18)\nB54\n\nBazaar repository format 2a (needs bzr 1.16 or later)\nE")