Rev 2949: Fix bug #158333, make sure that Repository.fetch(self) is properly a no-op for all Repository implementations. in http://bzr.arbash-meinel.com/branches/bzr/0.92-dev/repository_fetch_self_158333

John Arbash Meinel john at arbash-meinel.com
Mon Oct 29 21:03:17 GMT 2007


At http://bzr.arbash-meinel.com/branches/bzr/0.92-dev/repository_fetch_self_158333

------------------------------------------------------------
revno: 2949
revision-id:john at arbash-meinel.com-20071029210241-m2gq4o6ss0kcx2zo
parent: pqm at pqm.ubuntu.com-20071029050400-j2jmz8smj2yecfrr
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: repository_fetch_self_158333
timestamp: Mon 2007-10-29 16:02:41 -0500
message:
  Fix bug #158333, make sure that Repository.fetch(self) is properly a no-op for all Repository implementations.
modified:
  bzrlib/remote.py               remote.py-20060720103555-yeeg2x51vn0rbtdp-1
  bzrlib/tests/repository_implementations/test_fetch.py test_fetch.py-20070814052151-5cxha9slx4c93uog-1
-------------- next part --------------
=== modified file 'bzrlib/remote.py'
--- a/bzrlib/remote.py	2007-10-25 01:24:51 +0000
+++ b/bzrlib/remote.py	2007-10-29 21:02:41 +0000
@@ -24,6 +24,7 @@
     errors,
     lockdir,
     repository,
+    revision,
 )
 from bzrlib.branch import Branch, BranchReferenceFormat
 from bzrlib.bzrdir import BzrDir, RemoteBzrDirFormat
@@ -32,7 +33,6 @@
 from bzrlib.errors import NoSuchRevision
 from bzrlib.lockable_files import LockableFiles
 from bzrlib.pack import ContainerReader
-from bzrlib.revision import NULL_REVISION
 from bzrlib.smart import client, vfs
 from bzrlib.symbol_versioning import (
     deprecated_method,
@@ -304,7 +304,7 @@
         """See Repository.get_revision_graph()."""
         if revision_id is None:
             revision_id = ''
-        elif revision_id == NULL_REVISION:
+        elif revision.is_null(revision_id):
             return {}
 
         path = self.bzrdir._path_for_remote_call(self._client)
@@ -352,7 +352,7 @@
     def gather_stats(self, revid=None, committers=None):
         """See Repository.gather_stats()."""
         path = self.bzrdir._path_for_remote_call(self._client)
-        if revid in (None, NULL_REVISION):
+        if revision.is_null(revid):
             fmt_revid = ''
         else:
             fmt_revid = revid
@@ -621,7 +621,7 @@
             # check that last_revision is in 'from' and then return a
             # no-operation.
             if (revision_id is not None and
-                not _mod_revision.is_null(revision_id)):
+                not revision.is_null(revision_id)):
                 self.get_revision(revision_id)
             return 0, []
         self._ensure_real()

=== modified file 'bzrlib/tests/repository_implementations/test_fetch.py'
--- a/bzrlib/tests/repository_implementations/test_fetch.py	2007-10-17 09:39:41 +0000
+++ b/bzrlib/tests/repository_implementations/test_fetch.py	2007-10-29 21:02:41 +0000
@@ -20,6 +20,7 @@
     bzrdir,
     errors,
     gpg,
+    repository,
     )
 from bzrlib.tests import TestSkipped
 from bzrlib.tests.repository_implementations import TestCaseWithRepository
@@ -81,6 +82,31 @@
         rev2_tree = knit3_repo.revision_tree('rev2')
         self.assertEqual('rev1', rev2_tree.inventory.root.revision)
 
+    def test_fetch_all_from_self(self):
+        tree = self.make_branch_and_tree('.')
+        rev_id = tree.commit('one')
+        # This needs to be a new copy of the repository, if this changes, the
+        # test needs to be rewritten
+        repo = tree.branch.repository.bzrdir.open_repository()
+        # This fetch should be a no-op see bug #158333
+        tree.branch.repository.fetch(repo, None)
+
+    def test_fetch_from_self(self):
+        tree = self.make_branch_and_tree('.')
+        rev_id = tree.commit('one')
+        repo = tree.branch.repository.bzrdir.open_repository()
+        # This fetch should be a no-op see bug #158333
+        tree.branch.repository.fetch(repo, rev_id)
+
+    def test_fetch_missing_from_self(self):
+        tree = self.make_branch_and_tree('.')
+        rev_id = tree.commit('one')
+        # Even though the fetch() is a NO-OP it should assert the revision id
+        # is present
+        repo = tree.branch.repository.bzrdir.open_repository()
+        self.assertRaises(errors.NoSuchRevision, tree.branch.repository.fetch,
+                          repo, 'no-such-revision')
+
     def makeARepoWithSignatures(self):
         wt = self.make_branch_and_tree('a-repo-with-sigs')
         wt.commit('rev1', allow_pointless=True, rev_id='rev1')



More information about the bazaar-commits mailing list