Rev 2610: Add limit_to_revisions parameter to Repository.sprout(), BzrDir.sprout() and Repository.fetch() in file:///data/jelmer/bzr/shallow/

Jelmer Vernooij jelmer at samba.org
Fri Jul 13 12:03:09 BST 2007


At file:///data/jelmer/bzr/shallow/

------------------------------------------------------------
revno: 2610
revision-id: jelmer at samba.org-20070712152423-i7sjuhgszpffnwaj
parent: jelmer at samba.org-20070712144206-5e230fhf3swbzkwo
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: shallow
timestamp: Thu 2007-07-12 18:24:23 +0300
message:
  Add limit_to_revisions parameter to Repository.sprout(), BzrDir.sprout() and Repository.fetch()
modified:
  bzrlib/bzrdir.py               bzrdir.py-20060131065624-156dfea39c4387cb
  bzrlib/remote.py               remote.py-20060720103555-yeeg2x51vn0rbtdp-1
  bzrlib/repository.py           rev_storage.py-20051111201905-119e9401e46257e3
  bzrlib/tests/bzrdir_implementations/test_bzrdir.py test_bzrdir.py-20060131065642-0ebeca5e30e30866
=== modified file 'bzrlib/bzrdir.py'
--- a/bzrlib/bzrdir.py	2007-06-28 06:01:18 +0000
+++ b/bzrlib/bzrdir.py	2007-07-12 15:24:23 +0000
@@ -743,7 +743,7 @@
         return self.cloning_metadir()
 
     def sprout(self, url, revision_id=None, force_new_repo=False,
-               recurse='down'):
+               recurse='down', limit_to_revisions=None):
         """Create a copy of this bzrdir prepared for use as a new line of
         development.
 
@@ -756,6 +756,8 @@
 
         if revision_id is not None, then the clone operation may tune
             itself to download less data.
+
+        :param limit_to_revisions: Fetch just specified set of revisions.
         """
         target_transport = get_transport(url)
         target_transport.ensure_base()
@@ -784,14 +786,16 @@
             result.create_repository()
         elif source_repository is not None and result_repo is None:
             # have source, and want to make a new target repo
-            result_repo = source_repository.sprout(result, revision_id=revision_id)
+            result_repo = source_repository.sprout(result, revision_id=revision_id, 
+                limit_to_revisions=limit_to_revisions)
         else:
             # fetch needed content into target.
             if source_repository is not None:
                 # would rather do 
                 # source_repository.copy_content_into(result_repo, revision_id=revision_id)
                 # so we can override the copy method
-                result_repo.fetch(source_repository, revision_id=revision_id)
+                result_repo.fetch(source_repository, revision_id=revision_id, 
+                                  limit_to_revisions=limit_to_revisions)
         if source_branch is not None:
             source_branch.sprout(result, revision_id=revision_id)
         else:
@@ -958,9 +962,14 @@
         self._check_supported(format, unsupported)
         return format.open(self, _found=True)
 
-    def sprout(self, url, revision_id=None, force_new_repo=False):
+    def sprout(self, url, revision_id=None, force_new_repo=False,
+               limit_to_revisions=None):
         """See BzrDir.sprout()."""
         from bzrlib.workingtree import WorkingTreeFormat2
+        if limit_to_revisions is not None:
+            # Presplitout clones which preserves format and 
+            # therefore limit_to_revisions doesn't make sense
+            raise errors.PartialCloningNotSupported(self)
         self._make_tail(url)
         result = self._format._initialize_for_clone(url)
         try:

=== modified file 'bzrlib/remote.py'
--- a/bzrlib/remote.py	2007-06-27 04:33:04 +0000
+++ b/bzrlib/remote.py	2007-07-12 15:24:23 +0000
@@ -458,8 +458,10 @@
         else:
             raise errors.SmartServerError(error_code=response)
 
-    def sprout(self, to_bzrdir, revision_id=None):
+    def sprout(self, to_bzrdir, revision_id=None, limit_to_revisions=None):
         # TODO: Option to control what format is created?
+        if limit_to_revisions is not None:
+            raise errors.PartialCloningNotSupported(self)
         to_repo = to_bzrdir.create_repository()
         self._copy_repository_tarball(to_repo, revision_id)
         return to_repo
@@ -522,10 +524,11 @@
         """RemoteRepositories never create working trees by default."""
         return False
 
-    def fetch(self, source, revision_id=None, pb=None):
+    def fetch(self, source, revision_id=None, pb=None, limit_to_revisions=None):
         self._ensure_real()
         return self._real_repository.fetch(
-            source, revision_id=revision_id, pb=pb)
+            source, revision_id=revision_id, pb=pb, 
+            limit_to_revisions=limit_to_revisions)
 
     @property
     def control_weaves(self):

=== modified file 'bzrlib/repository.py'
--- a/bzrlib/repository.py	2007-07-12 07:22:52 +0000
+++ b/bzrlib/repository.py	2007-07-12 15:24:23 +0000
@@ -353,7 +353,7 @@
         revision_id = osutils.safe_revision_id(revision_id)
         return InterRepository.get(self, destination).copy_content(revision_id)
 
-    def fetch(self, source, revision_id=None, pb=None):
+    def fetch(self, source, revision_id=None, pb=None, limit_to_revisions=None):
         """Fetch the content required to construct revision_id from source.
 
         If revision_id is None all content is copied.
@@ -361,7 +361,8 @@
         revision_id = osutils.safe_revision_id(revision_id)
         inter = InterRepository.get(source, self)
         try:
-            return inter.fetch(revision_id=revision_id, pb=pb)
+            return inter.fetch(revision_id=revision_id, pb=pb, 
+                               limit_to_revisions=limit_to_revisions)
         except NotImplementedError:
             raise errors.IncompatibleRepositories(source, self)
 
@@ -402,13 +403,14 @@
         return dest_repo
 
     @needs_read_lock
-    def sprout(self, to_bzrdir, revision_id=None):
+    def sprout(self, to_bzrdir, revision_id=None, limit_to_revisions=None):
         """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)
+        dest_repo.fetch(self, revision_id=revision_id, 
+                limit_to_revisions=limit_to_revisions)
         return dest_repo
 
     def _create_sprouting_repo(self, a_bzrdir, shared):
@@ -1367,7 +1369,7 @@
     def copy_content(self, revision_id=None):
         raise NotImplementedError(self.copy_content)
 
-    def fetch(self, revision_id=None, pb=None):
+    def fetch(self, revision_id=None, pb=None, limit_to_revisions=None):
         """Fetch the content required to construct revision_id.
 
         The content is copied from self.source to self.target.
@@ -1377,6 +1379,8 @@
         :param pb: optional progress bar to use for progress reports. If not
                    provided a default one will be created.
 
+        :param limit_to_revisions: Fetch just specified set of revisions.
+
         Returns the copied revision count and the failed revisions in a tuple:
         (copied, failures).
         """
@@ -1455,12 +1459,14 @@
         self.target.fetch(self.source, revision_id=revision_id)
 
     @needs_write_lock
-    def fetch(self, revision_id=None, pb=None):
+    def fetch(self, revision_id=None, pb=None, limit_to_revisions=None):
         """See InterRepository.fetch()."""
         from bzrlib.fetch import GenericRepoFetcher
         mutter("Using fetch logic to copy between %s(%s) and %s(%s)",
                self.source, self.source._format, self.target, 
                self.target._format)
+        if limit_to_revisions is not None:
+            raise errors.PartialCloningNotSupported(self)
         # TODO: jam 20070210 This should be an assert, not a translate
         revision_id = osutils.safe_revision_id(revision_id)
         f = GenericRepoFetcher(to_repository=self.target,
@@ -1534,11 +1540,13 @@
             self.target.fetch(self.source, revision_id=revision_id)
 
     @needs_write_lock
-    def fetch(self, revision_id=None, pb=None):
+    def fetch(self, revision_id=None, pb=None, limit_to_revisions=None):
         """See InterRepository.fetch()."""
         from bzrlib.fetch import GenericRepoFetcher
         mutter("Using fetch logic to copy between %s(%s) and %s(%s)",
                self.source, self.source._format, self.target, self.target._format)
+        if limit_to_revisions is not None:
+            raise errors.PartialCloningNotSupported(self)
         # TODO: jam 20070210 This should be an assert, not a translate
         revision_id = osutils.safe_revision_id(revision_id)
         f = GenericRepoFetcher(to_repository=self.target,
@@ -1613,11 +1621,13 @@
             return False
 
     @needs_write_lock
-    def fetch(self, revision_id=None, pb=None):
+    def fetch(self, revision_id=None, pb=None, limit_to_revisions=None):
         """See InterRepository.fetch()."""
         from bzrlib.fetch import KnitRepoFetcher
         mutter("Using fetch logic to copy between %s(%s) and %s(%s)",
                self.source, self.source._format, self.target, self.target._format)
+        if limit_to_revisions is not None:
+            raise errors.PartialCloningNotSupported(self)
         # TODO: jam 20070210 This should be an assert, not a translate
         revision_id = osutils.safe_revision_id(revision_id)
         f = KnitRepoFetcher(to_repository=self.target,
@@ -1671,9 +1681,11 @@
             return False
 
     @needs_write_lock
-    def fetch(self, revision_id=None, pb=None):
+    def fetch(self, revision_id=None, pb=None, limit_to_revisions=None):
         """See InterRepository.fetch()."""
         from bzrlib.fetch import Model1toKnit2Fetcher
+        if limit_to_revisions is not None:
+            raise errors.PartialCloningNotSupported(self)
         # TODO: jam 20070210 This should be an assert, not a translate
         revision_id = osutils.safe_revision_id(revision_id)
         f = Model1toKnit2Fetcher(to_repository=self.target,
@@ -1724,12 +1736,14 @@
             return False
 
     @needs_write_lock
-    def fetch(self, revision_id=None, pb=None):
+    def fetch(self, revision_id=None, pb=None, limit_to_revisions=None):
         """See InterRepository.fetch()."""
         from bzrlib.fetch import Knit1to2Fetcher
         mutter("Using fetch logic to copy between %s(%s) and %s(%s)",
                self.source, self.source._format, self.target, 
                self.target._format)
+        if limit_to_revisions is not None:
+            raise errors.PartialCloningNotSupported(self)
         # TODO: jam 20070210 This should be an assert, not a translate
         revision_id = osutils.safe_revision_id(revision_id)
         f = Knit1to2Fetcher(to_repository=self.target,
@@ -1770,8 +1784,9 @@
     def copy_content(self, revision_id=None):
         self.real_inter.copy_content(revision_id=revision_id)
 
-    def fetch(self, revision_id=None, pb=None):
-        self.real_inter.fetch(revision_id=revision_id, pb=pb)
+    def fetch(self, revision_id=None, pb=None, limit_to_revisions=None):
+        self.real_inter.fetch(revision_id=revision_id, pb=pb, 
+                              limit_to_revisions=limit_to_revisions)
 
     @classmethod
     def _get_repo_format_to_test(self):

=== modified file 'bzrlib/tests/bzrdir_implementations/test_bzrdir.py'
--- a/bzrlib/tests/bzrdir_implementations/test_bzrdir.py	2007-07-11 19:44:51 +0000
+++ b/bzrlib/tests/bzrdir_implementations/test_bzrdir.py	2007-07-12 15:24:23 +0000
@@ -123,7 +123,7 @@
                               % a_bzrdir.transport)
 
     def sproutOrSkip(self, from_bzrdir, to_url, revision_id=None,
-                     force_new_repo=False):
+                     force_new_repo=False, limit_to_revisions=None):
         """Sprout from_bzrdir into to_url, or raise TestSkipped.
         
         A simple wrapper for from_bzrdir.sprout that translates NotLocalUrl into
@@ -131,7 +131,8 @@
         """
         try:
             target = from_bzrdir.sprout(to_url, revision_id=revision_id,
-                                        force_new_repo=force_new_repo)
+                force_new_repo=force_new_repo, 
+                limit_to_revisions=limit_to_revisions)
         except errors.NotLocalUrl:
             raise TestSkipped('Cannot sprout to remote bzrdirs.')
         return target
@@ -871,6 +872,23 @@
         dir = source.bzrdir
         target = self.sproutOrSkip(dir, self.get_url('target'), revision_id='1')
         self.assertEqual('1', target.open_branch().last_revision())
+
+    def test_sprout_bzrdir_partial(self):
+        tree = self.make_branch_and_tree('source')
+        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
+        tree.add('foo')
+        rev1 = tree.commit('revision 1')
+        tree.bzrdir.transport.clone('..').put_bytes('foo', 'bar')
+        rev2 = tree.commit('revision 2')
+        dir = tree.bzrdir
+        try: 
+            target = self.sproutOrSkip(dir, self.get_url('target'), 
+                    limit_to_revisions=set([rev2]))
+        except errors.PartialCloningNotSupported:
+            return # Not all repository formats can support partial cloning
+        repository = target.open_repository()
+        self.assertTrue(repository.has_revision(rev2))
+        self.assertFalse(repository.has_revision(rev1))
         
     def test_sprout_bzrdir_tree_branch_repo(self):
         tree = self.make_branch_and_tree('source')




More information about the bazaar-commits mailing list