Rev 6272: (jelmer) Avoid _ensure_real in a few more places in bzrlib.remote. (Jelmer in file:///srv/pqm.bazaar-vcs.org/archives/thelove/bzr/%2Btrunk/

Patch Queue Manager pqm at pqm.ubuntu.com
Thu Nov 17 16:35:43 UTC 2011


At file:///srv/pqm.bazaar-vcs.org/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 6272 [merge]
revision-id: pqm at pqm.ubuntu.com-20111117163543-1wumacqhy65ii76k
parent: pqm at pqm.ubuntu.com-20111117144642-ftfb38t0hbnxoysq
parent: jelmer at samba.org-20111117161015-t45j5i52f5c70434
committer: Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Thu 2011-11-17 16:35:43 +0000
message:
  (jelmer) Avoid _ensure_real in a few more places in bzrlib.remote. (Jelmer
   Vernooij)
modified:
  bzrlib/remote.py               remote.py-20060720103555-yeeg2x51vn0rbtdp-1
  bzrlib/tests/per_repository/test_repository.py test_repository.py-20060131092128-ad07f494f5c9d26c
=== modified file 'bzrlib/remote.py'
--- a/bzrlib/remote.py	2011-11-17 11:22:28 +0000
+++ b/bzrlib/remote.py	2011-11-17 16:35:43 +0000
@@ -41,10 +41,12 @@
     SmartProtocolError,
     )
 from bzrlib.i18n import gettext
+from bzrlib.inventory import Inventory
 from bzrlib.lockable_files import LockableFiles
 from bzrlib.smart import client, vfs, repository as smart_repo
 from bzrlib.smart.client import _SmartClient
 from bzrlib.revision import NULL_REVISION
+from bzrlib.revisiontree import InventoryRevisionTree
 from bzrlib.repository import RepositoryWriteLockResult, _LazyListJoin
 from bzrlib.trace import mutter, note, warning
 
@@ -698,12 +700,6 @@
         """Upgrading of remote bzrdirs is not supported yet."""
         return False
 
-    def clone(self, url, revision_id=None, force_new_repo=False,
-              preserve_stacking=False):
-        self._ensure_real()
-        return self._real_bzrdir.clone(url, revision_id=revision_id,
-            force_new_repo=force_new_repo, preserve_stacking=preserve_stacking)
-
     def _get_config(self):
         return RemoteBzrDirConfig(self)
 
@@ -1479,19 +1475,39 @@
             return t
         raise errors.UnexpectedSmartServerResponse(response)
 
+    @needs_read_lock
     def sprout(self, to_bzrdir, revision_id=None):
-        # TODO: Option to control what format is created?
-        self._ensure_real()
-        dest_repo = self._real_repository._format.initialize(to_bzrdir,
-                                                             shared=False)
+        """Create a descendent repository for new development.
+
+        Unlike clone, this does not copy the settings of the repository.
+        """
+        dest_repo = self._create_sprouting_repo(to_bzrdir, shared=False)
         dest_repo.fetch(self, revision_id=revision_id)
         return dest_repo
 
+    def _create_sprouting_repo(self, a_bzrdir, shared):
+        if not isinstance(a_bzrdir._format, self.bzrdir._format.__class__):
+            # use target default format.
+            dest_repo = a_bzrdir.create_repository()
+        else:
+            # Most control formats need the repository to be specifically
+            # created, but on some old all-in-one formats it's not needed
+            try:
+                dest_repo = self._format.initialize(a_bzrdir, shared=shared)
+            except errors.UninitializableFormat:
+                dest_repo = a_bzrdir.open_repository()
+        return dest_repo
+
     ### These methods are just thin shims to the VFS object for now.
 
+    @needs_read_lock
     def revision_tree(self, revision_id):
-        self._ensure_real()
-        return self._real_repository.revision_tree(revision_id)
+        revision_id = _mod_revision.ensure_null(revision_id)
+        if revision_id == _mod_revision.NULL_REVISION:
+            return InventoryRevisionTree(self,
+                Inventory(root_id=None), _mod_revision.NULL_REVISION)
+        else:
+            return list(self.revision_trees([revision_id]))[0]
 
     def get_serializer_format(self):
         self._ensure_real()
@@ -1575,8 +1591,7 @@
 
     @needs_read_lock
     def get_revision(self, revision_id):
-        self._ensure_real()
-        return self._real_repository.get_revision(revision_id)
+        return self.get_revisions([revision_id])[0]
 
     def get_transaction(self):
         self._ensure_real()
@@ -1584,8 +1599,10 @@
 
     @needs_read_lock
     def clone(self, a_bzrdir, revision_id=None):
-        self._ensure_real()
-        return self._real_repository.clone(a_bzrdir, revision_id=revision_id)
+        dest_repo = self._create_sprouting_repo(
+            a_bzrdir, shared=self.is_shared())
+        self.copy_content_into(dest_repo, revision_id)
+        return dest_repo
 
     def make_working_trees(self):
         """See Repository.make_working_trees"""
@@ -1859,9 +1876,9 @@
 
     @needs_read_lock
     def get_revision_delta(self, revision_id, specific_fileids=None):
-        self._ensure_real()
-        return self._real_repository.get_revision_delta(revision_id,
-            specific_fileids=specific_fileids)
+        r = self.get_revision(revision_id)
+        return list(self.get_deltas_for_revisions([r],
+            specific_fileids=specific_fileids))[0]
 
     @needs_read_lock
     def revision_trees(self, revision_ids):
@@ -1880,9 +1897,13 @@
             callback_refs=callback_refs, check_repo=check_repo)
 
     def copy_content_into(self, destination, revision_id=None):
-        self._ensure_real()
-        return self._real_repository.copy_content_into(
-            destination, revision_id=revision_id)
+        """Make a complete copy of the content in self into destination.
+
+        This is a destructive operation! Do not use it on existing
+        repositories.
+        """
+        interrepo = _mod_repository.InterRepository.get(self, destination)
+        return interrepo.copy_content(revision_id)
 
     def _copy_repository_tarball(self, to_bzrdir, revision_id=None):
         # get a tarball of the remote repository, and copy from that into the
@@ -2001,10 +2022,10 @@
     def _serializer(self):
         return self._format._serializer
 
+    @needs_write_lock
     def store_revision_signature(self, gpg_strategy, plaintext, revision_id):
-        self._ensure_real()
-        return self._real_repository.store_revision_signature(
-            gpg_strategy, plaintext, revision_id)
+        signature = gpg_strategy.sign(plaintext)
+        self.add_signature_text(revision_id, signature)
 
     def add_signature_text(self, revision_id, signature):
         self._ensure_real()

=== modified file 'bzrlib/tests/per_repository/test_repository.py'
--- a/bzrlib/tests/per_repository/test_repository.py	2011-11-13 14:07:38 +0000
+++ b/bzrlib/tests/per_repository/test_repository.py	2011-11-17 16:10:15 +0000
@@ -591,7 +591,9 @@
                 "Cannot lock_read old formats like AllInOne over HPSS.")
         remote_backing_repo = controldir.ControlDir.open(
             self.get_vfs_only_url('remote')).open_repository()
-        self.assertEqual(remote_backing_repo._format, local_repo._format)
+        self.assertEqual(
+            remote_backing_repo._format.network_name(),
+            local_repo._format.network_name())
 
     def test_sprout_branch_from_hpss_preserves_repo_format(self):
         """branch.sprout from a smart server preserves the repository format.




More information about the bazaar-commits mailing list