Rev 6297: (jelmer) Add HPSS call for ``Branch.revision_id_to_revno``. (Jelmer Vernooij) in file:///srv/pqm.bazaar-vcs.org/archives/thelove/bzr/%2Btrunk/
Patch Queue Manager
pqm at pqm.ubuntu.com
Fri Nov 25 13:57:41 UTC 2011
At file:///srv/pqm.bazaar-vcs.org/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 6297 [merge]
revision-id: pqm at pqm.ubuntu.com-20111125135741-kbnof2f16li9l1ws
parent: pqm at pqm.ubuntu.com-20111125130937-9b1kbg3t983cm80o
parent: jelmer at samba.org-20111125133119-jz4lb0h73riw9dfo
committer: Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Fri 2011-11-25 13:57:41 +0000
message:
(jelmer) Add HPSS call for ``Branch.revision_id_to_revno``. (Jelmer Vernooij)
modified:
bzrlib/remote.py remote.py-20060720103555-yeeg2x51vn0rbtdp-1
bzrlib/smart/branch.py branch.py-20061124031907-mzh3pla28r83r97f-1
bzrlib/smart/request.py request.py-20061108095550-gunadhxmzkdjfeek-1
bzrlib/tests/blackbox/test_revno.py test_revno.py-20051204214528-2f0bf83a71b7656a
bzrlib/tests/blackbox/test_tags.py test_tags.py-20070116132048-5h4qak2cm22jlb9e-1
bzrlib/tests/test_remote.py test_remote.py-20060720103555-yeeg2x51vn0rbtdp-2
bzrlib/tests/test_smart.py test_smart.py-20061122024551-ol0l0o0oofsu9b3t-2
doc/en/release-notes/bzr-2.5.txt bzr2.5.txt-20110708125756-587p0hpw7oke4h05-1
=== modified file 'bzrlib/remote.py'
--- a/bzrlib/remote.py 2011-11-25 12:03:11 +0000
+++ b/bzrlib/remote.py 2011-11-25 13:31:19 +0000
@@ -3234,9 +3234,40 @@
return self._lock_count >= 1
@needs_read_lock
+ def revision_id_to_dotted_revno(self, revision_id):
+ """Given a revision id, return its dotted revno.
+
+ :return: a tuple like (1,) or (400,1,3).
+ """
+ try:
+ response = self._call('Branch.revision_id_to_revno',
+ self._remote_path(), revision_id)
+ except errors.UnknownSmartMethod:
+ self._ensure_real()
+ return self._real_branch.revision_id_to_revno(revision_id)
+ if response[0] == 'ok':
+ return tuple([int(x) for x in response[1:]])
+ else:
+ raise errors.UnexpectedSmartServerResponse(response)
+
+ @needs_read_lock
def revision_id_to_revno(self, revision_id):
- self._ensure_real()
- return self._real_branch.revision_id_to_revno(revision_id)
+ """Given a revision id on the branch mainline, return its revno.
+
+ :return: an integer
+ """
+ try:
+ response = self._call('Branch.revision_id_to_revno',
+ self._remote_path(), revision_id)
+ except errors.UnknownSmartMethod:
+ self._ensure_real()
+ return self._real_branch.revision_id_to_revno(revision_id)
+ if response[0] == 'ok':
+ if len(response) == 2:
+ return int(response[1])
+ raise NoSuchRevision(self, revision_id)
+ else:
+ raise errors.UnexpectedSmartServerResponse(response)
@needs_write_lock
def set_last_revision_info(self, revno, revision_id):
=== modified file 'bzrlib/smart/branch.py'
--- a/bzrlib/smart/branch.py 2011-11-22 22:26:33 +0000
+++ b/bzrlib/smart/branch.py 2011-11-25 13:31:19 +0000
@@ -235,6 +235,23 @@
return SuccessfulSmartServerResponse(('ok', str(revno), last_revision))
+class SmartServerBranchRequestRevisionIdToRevno(SmartServerBranchRequest):
+
+ def do_with_branch(self, branch, revid):
+ """Return branch.revision_id_to_revno().
+
+ New in 2.5.
+
+ The revno is encoded in decimal, the revision_id is encoded as utf8.
+ """
+ try:
+ dotted_revno = branch.revision_id_to_dotted_revno(revid)
+ except errors.NoSuchRevision:
+ return FailedSmartServerResponse(('NoSuchRevision', revid))
+ return SuccessfulSmartServerResponse(
+ ('ok', ) + tuple(map(str, dotted_revno)))
+
+
class SmartServerSetTipRequest(SmartServerLockedBranchRequest):
"""Base class for handling common branch request logic for requests that
update the branch tip.
=== modified file 'bzrlib/smart/request.py'
--- a/bzrlib/smart/request.py 2011-11-25 12:03:11 +0000
+++ b/bzrlib/smart/request.py 2011-11-25 13:31:19 +0000
@@ -540,6 +540,8 @@
request_handlers.register_lazy(
'Branch.unlock', 'bzrlib.smart.branch', 'SmartServerBranchRequestUnlock')
request_handlers.register_lazy(
+ 'Branch.revision_id_to_revno', 'bzrlib.smart.branch', 'SmartServerBranchRequestRevisionIdToRevno')
+request_handlers.register_lazy(
'BzrDir.cloning_metadir', 'bzrlib.smart.bzrdir',
'SmartServerBzrDirRequestCloningMetaDir')
request_handlers.register_lazy(
=== modified file 'bzrlib/tests/blackbox/test_revno.py'
--- a/bzrlib/tests/blackbox/test_revno.py 2011-11-22 23:40:50 +0000
+++ b/bzrlib/tests/blackbox/test_revno.py 2011-11-23 12:12:34 +0000
@@ -153,7 +153,7 @@
# being too low. If rpc_count increases, more network roundtrips have
# become necessary for this use case. Please do not adjust this number
# upwards without agreement from bzr's network support maintainers.
- self.assertLength(14, self.hpss_calls)
+ self.assertLength(6, self.hpss_calls)
def test_simple_branch_revno_lookup(self):
self.setup_smart_server_with_call_log()
@@ -170,4 +170,4 @@
# being too low. If rpc_count increases, more network roundtrips have
# become necessary for this use case. Please do not adjust this number
# upwards without agreement from bzr's network support maintainers.
- self.assertLength(13, self.hpss_calls)
+ self.assertLength(5, self.hpss_calls)
=== modified file 'bzrlib/tests/blackbox/test_tags.py'
--- a/bzrlib/tests/blackbox/test_tags.py 2011-11-22 23:33:35 +0000
+++ b/bzrlib/tests/blackbox/test_tags.py 2011-11-23 12:12:34 +0000
@@ -440,4 +440,4 @@
# being too low. If rpc_count increases, more network roundtrips have
# become necessary for this use case. Please do not adjust this number
# upwards without agreement from bzr's network support maintainers.
- self.assertLength(16, self.hpss_calls)
+ self.assertLength(6, self.hpss_calls)
=== modified file 'bzrlib/tests/test_remote.py'
--- a/bzrlib/tests/test_remote.py 2011-11-25 12:03:11 +0000
+++ b/bzrlib/tests/test_remote.py 2011-11-25 13:31:19 +0000
@@ -1978,6 +1978,49 @@
self.assertFinished(client)
+class TestBranchRevisionIdToRevno(RemoteBranchTestCase):
+
+ def test_simple(self):
+ transport = MemoryTransport()
+ client = FakeClient(transport.base)
+ client.add_expected_call(
+ 'Branch.get_stacked_on_url', ('quack/',),
+ 'error', ('NotStacked',),)
+ client.add_expected_call(
+ 'Branch.revision_id_to_revno', ('quack/', 'null:'),
+ 'success', ('ok', '0',),)
+ client.add_expected_call(
+ 'Branch.revision_id_to_revno', ('quack/', 'unknown'),
+ 'error', ('NoSuchRevision', 'unknown',),)
+ transport.mkdir('quack')
+ transport = transport.clone('quack')
+ branch = self.make_remote_branch(transport, client)
+ self.assertEquals(0, branch.revision_id_to_revno('null:'))
+ self.assertRaises(errors.NoSuchRevision,
+ branch.revision_id_to_revno, 'unknown')
+ self.assertFinished(client)
+
+ def test_dotted(self):
+ transport = MemoryTransport()
+ client = FakeClient(transport.base)
+ client.add_expected_call(
+ 'Branch.get_stacked_on_url', ('quack/',),
+ 'error', ('NotStacked',),)
+ client.add_expected_call(
+ 'Branch.revision_id_to_revno', ('quack/', 'null:'),
+ 'success', ('ok', '0',),)
+ client.add_expected_call(
+ 'Branch.revision_id_to_revno', ('quack/', 'unknown'),
+ 'error', ('NoSuchRevision', 'unknown',),)
+ transport.mkdir('quack')
+ transport = transport.clone('quack')
+ branch = self.make_remote_branch(transport, client)
+ self.assertEquals((0, ), branch.revision_id_to_dotted_revno('null:'))
+ self.assertRaises(errors.NoSuchRevision,
+ branch.revision_id_to_dotted_revno, 'unknown')
+ self.assertFinished(client)
+
+
class TestBzrDirGetSetConfig(RemoteBzrDirTestCase):
def test__get_config(self):
=== modified file 'bzrlib/tests/test_smart.py'
--- a/bzrlib/tests/test_smart.py 2011-11-25 12:03:11 +0000
+++ b/bzrlib/tests/test_smart.py 2011-11-25 13:31:19 +0000
@@ -783,6 +783,41 @@
request.execute(''))
+class TestSmartServerBranchRequestRevisionIdToRevno(
+ tests.TestCaseWithMemoryTransport):
+
+ def test_null(self):
+ backing = self.get_transport()
+ request = smart_branch.SmartServerBranchRequestRevisionIdToRevno(
+ backing)
+ self.make_branch('.')
+ self.assertEqual(smart_req.SmartServerResponse(('ok', '0')),
+ request.execute('', 'null:'))
+
+ def test_simple(self):
+ backing = self.get_transport()
+ request = smart_branch.SmartServerBranchRequestRevisionIdToRevno(
+ backing)
+ tree = self.make_branch_and_memory_tree('.')
+ tree.lock_write()
+ tree.add('')
+ r1 = tree.commit('1st commit')
+ tree.unlock()
+ self.assertEqual(
+ smart_req.SmartServerResponse(('ok', '1')),
+ request.execute('', r1))
+
+ def test_not_found(self):
+ backing = self.get_transport()
+ request = smart_branch.SmartServerBranchRequestRevisionIdToRevno(
+ backing)
+ branch = self.make_branch('.')
+ self.assertEqual(
+ smart_req.FailedSmartServerResponse(
+ ('NoSuchRevision', 'idontexist')),
+ request.execute('', 'idontexist'))
+
+
class TestSmartServerBranchRequestGetConfigFile(
tests.TestCaseWithMemoryTransport):
@@ -2097,6 +2132,8 @@
smart_branch.SmartServerBranchRequestLastRevisionInfo)
self.assertHandlerEqual('Branch.revision_history',
smart_branch.SmartServerRequestRevisionHistory)
+ self.assertHandlerEqual('Branch.revision_id_to_revno',
+ smart_branch.SmartServerBranchRequestRevisionIdToRevno)
self.assertHandlerEqual('Branch.set_config_option',
smart_branch.SmartServerBranchRequestSetConfigOption)
self.assertHandlerEqual('Branch.set_last_revision',
=== modified file 'doc/en/release-notes/bzr-2.5.txt'
--- a/doc/en/release-notes/bzr-2.5.txt 2011-11-25 12:03:11 +0000
+++ b/doc/en/release-notes/bzr-2.5.txt 2011-11-25 13:31:19 +0000
@@ -47,6 +47,9 @@
remote ones. See ``bzr help configuration`` for more details.
(Vincent Ladeuil, #843211)
+* Add HPSS call for looking up revision numbers from revision ids on
+ remote repositories. (Jelmer Vernooij, #640253)
+
* Cope with missing revision ids being specified to
``Repository.gather_stats`` HPSS call. (Jelmer Vernooij, #411290)
More information about the bazaar-commits
mailing list