Rev 2123: Factor out code we expect to be common in SmartServerRequestHasRevision to SmartServerRepositoryRequest (Robert Collins, Vincent Ladeuil). in file:///home/robertc/source/baz/hpss/

Robert Collins robertc at robertcollins.net
Fri Feb 2 17:05:59 GMT 2007


------------------------------------------------------------
revno: 2123
revision-id: robertc at robertcollins.net-20070202170549-ykriy5021olx98eu
parent: robertc at robertcollins.net-20070202061527-ep28ktwh0th06gbo
committer: Robert Collins <robertc at robertcollins.net>
branch nick: hpss
timestamp: Sat 2007-02-03 04:05:49 +1100
message:
  Factor out code we expect to be common in SmartServerRequestHasRevision to SmartServerRepositoryRequest (Robert Collins, Vincent Ladeuil).
modified:
  bzrlib/smart/repository.py     repository.py-20061128022038-vr5wy5bubyb8xttk-1
  bzrlib/tests/test_smart.py     test_smart.py-20061122024551-ol0l0o0oofsu9b3t-2
=== modified file 'bzrlib/smart/repository.py'
--- a/bzrlib/smart/repository.py	2006-11-28 02:21:24 +0000
+++ b/bzrlib/smart/repository.py	2007-02-02 17:05:49 +0000
@@ -22,21 +22,35 @@
 from bzrlib.smart.request import SmartServerRequest, SmartServerResponse
 
 
-class SmartServerRequestHasRevision(SmartServerRequest):
-
-    def do(self, path, revision_id):
-        """Return ok if a specific revision is in the repository at path.
-
+class SmartServerRepositoryRequest(SmartServerRequest):
+    """Common base class for Repository requests."""
+
+    def do(self, path, *args):
+        """Execute a repository request.
+        
         The repository must be at the exact path - no searching is done.
 
+        The actual logic is delegated to self.do_repository_request.
+
         :param path: The path for the repository.
+        :return: A smart server from self.do_repository_request().
+        """
+        transport = self._backing_transport.clone(path)
+        bzrdir = BzrDir.open_from_transport(transport)
+        repository = bzrdir.open_repository()
+        return self.do_repository_request(repository, *args)
+
+
+class SmartServerRequestHasRevision(SmartServerRepositoryRequest):
+
+    def do_repository_request(self, repository, revision_id):
+        """Return ok if a specific revision is in the repository at path.
+
+        :param repository: The repository to query in.
         :param revision_id: The utf8 encoded revision_id to lookup.
         :return: A smart server response of ('ok', ) if the revision is
             present.
         """
-        transport = self._backing_transport.clone(path)
-        bzrdir = BzrDir.open_from_transport(transport)
-        repository = bzrdir.open_repository()
         decoded_revision_id = revision_id.decode('utf8')
         if repository.has_revision(decoded_revision_id):
             return SmartServerResponse(('ok', ))

=== modified file 'bzrlib/tests/test_smart.py'
--- a/bzrlib/tests/test_smart.py	2007-02-01 17:40:38 +0000
+++ b/bzrlib/tests/test_smart.py	2007-02-02 17:05:49 +0000
@@ -76,42 +76,6 @@
             request.execute(backing.local_abspath('subdir/deeper')))
 
 
-class TestSmartServerRequestHasRevision(tests.TestCaseWithTransport):
-
-    def test_no_repository(self):
-        """NoRepositoryPresent is raised when there is no repository."""
-        # we test this using a shared repository above the named path,
-        # thus checking the right search logic is used.
-        backing = self.get_transport()
-        request = smart.repository.SmartServerRequestHasRevision(backing)
-        self.make_repository('.', shared=True)
-        self.make_bzrdir('subdir')
-        self.assertRaises(errors.NoRepositoryPresent,
-            request.execute, backing.local_abspath('subdir'), 'revid')
-
-    def test_missing_revision(self):
-        """For a missing revision, ('no', ) is returned."""
-        backing = self.get_transport()
-        request = smart.repository.SmartServerRequestHasRevision(backing)
-        self.make_repository('.')
-        self.assertEqual(SmartServerResponse(('no', )),
-            request.execute(backing.local_abspath(''), 'revid'))
-
-    def test_present_revision(self):
-        """For a present revision, ('ok', ) is returned."""
-        backing = self.get_transport()
-        request = smart.repository.SmartServerRequestHasRevision(backing)
-        tree = self.make_branch_and_memory_tree('.')
-        tree.lock_write()
-        tree.add('')
-        r1 = tree.commit('a commit', rev_id=u'\xc8abc')
-        tree.unlock()
-        self.assertTrue(tree.branch.repository.has_revision(u'\xc8abc'))
-        self.assertEqual(SmartServerResponse(('ok', )),
-            request.execute(backing.local_abspath(''),
-                u'\xc8abc'.encode('utf8')))
-
-
 class TestSmartServerRequestInitializeBzrDir(tests.TestCaseWithTransport):
 
     def test_empty_dir(self):
@@ -245,6 +209,48 @@
             request.execute(backing.local_abspath('')))
 
 
+class TestSmartServerRepositoryRequest(tests.TestCaseWithTransport):
+
+    def test_no_repository(self):
+        """Raise NoRepositoryPresent when there is a bzrdir and no repo."""
+        # we test this using a shared repository above the named path,
+        # thus checking the right search logic is used - that is, that
+        # its the exact path being looked at and the server is not
+        # searching.
+        backing = self.get_transport()
+        request = smart.repository.SmartServerRequestHasRevision(backing)
+        self.make_repository('.', shared=True)
+        self.make_bzrdir('subdir')
+        self.assertRaises(errors.NoRepositoryPresent,
+            request.execute, backing.local_abspath('subdir'), 'revid')
+
+
+class TestSmartServerRequestHasRevision(tests.TestCaseWithTransport):
+
+    def test_missing_revision(self):
+        """For a missing revision, ('no', ) is returned."""
+        backing = self.get_transport()
+        request = smart.repository.SmartServerRequestHasRevision(backing)
+        self.make_repository('.')
+        self.assertEqual(SmartServerResponse(('no', )),
+            request.execute(backing.local_abspath(''), 'revid'))
+
+    def test_present_revision(self):
+        """For a present revision, ('ok', ) is returned."""
+        backing = self.get_transport()
+        request = smart.repository.SmartServerRequestHasRevision(backing)
+        tree = self.make_branch_and_memory_tree('.')
+        tree.lock_write()
+        tree.add('')
+        r1 = tree.commit('a commit', rev_id=u'\xc8abc')
+        tree.unlock()
+        self.assertTrue(tree.branch.repository.has_revision(u'\xc8abc'))
+        self.assertEqual(SmartServerResponse(('ok', )),
+            request.execute(backing.local_abspath(''),
+                u'\xc8abc'.encode('utf8')))
+
+
+
 class TestHandlers(tests.TestCase):
     """Tests for the request.request_handlers object."""
 



More information about the bazaar-commits mailing list