Rev 5742: (jelmer) Move Branch.fetch implementation to InterBranch. (Jelmer Vernooij) in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Sat Mar 26 15:46:18 UTC 2011


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 5742 [merge]
revision-id: pqm at pqm.ubuntu.com-20110326154616-y6h2rjf9bs1wvvfs
parent: pqm at pqm.ubuntu.com-20110324123539-eq5j9mdxk9p4wqs1
parent: jelmer at samba.org-20110326015334-dmedeywtieouui02
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Sat 2011-03-26 15:46:16 +0000
message:
  (jelmer) Move Branch.fetch implementation to InterBranch. (Jelmer Vernooij)
added:
  bzrlib/tests/per_interbranch/test_fetch.py test_fetch.py-20110326014954-0viktxgz0w71zcld-1
modified:
  bzrlib/branch.py               branch.py-20050309040759-e4baf4e0d046576e
  bzrlib/tests/per_branch/test_branch.py testbranch.py-20050711070244-121d632bc37d7253
  bzrlib/tests/per_interbranch/__init__.py __init__.py-20090225010018-l7w4uvvt73ea2vj9-1
=== modified file 'bzrlib/branch.py'
--- a/bzrlib/branch.py	2011-03-23 05:15:48 +0000
+++ b/bzrlib/branch.py	2011-03-26 01:37:08 +0000
@@ -682,21 +682,8 @@
             last_revision.
         :return: None
         """
-        if fetch_spec is not None and last_revision is not None:
-            raise AssertionError(
-                "fetch_spec and last_revision are mutually exclusive.")
-        if self.base == from_branch.base:
-            return (0, [])
-        from_branch.lock_read()
-        try:
-            if last_revision is None and fetch_spec is None:
-                last_revision = from_branch.last_revision()
-                last_revision = _mod_revision.ensure_null(last_revision)
-            return self.repository.fetch(from_branch.repository,
-                                         revision_id=last_revision,
-                                         fetch_spec=fetch_spec)
-        finally:
-            from_branch.unlock()
+        return InterBranch.get(from_branch, self).fetch(last_revision,
+            fetch_spec)
 
     def get_bound_location(self):
         """Return the URL of the branch we are bound to.
@@ -3331,6 +3318,15 @@
         """
         raise NotImplementedError(self.copy_content_into)
 
+    @needs_write_lock
+    def fetch(self, stop_revision=None, fetch_spec=None):
+        """Fetch revisions.
+
+        :param stop_revision: Last revision to fetch
+        :param fetch_spec: Fetch spec.
+        """
+        raise NotImplementedError(self.fetch)
+
 
 class GenericInterBranch(InterBranch):
     """InterBranch implementation that uses public Branch functions."""
@@ -3371,6 +3367,23 @@
             self.source.tags.merge_to(self.target.tags)
 
     @needs_write_lock
+    def fetch(self, stop_revision=None, fetch_spec=None):
+        if fetch_spec is not None and stop_revision is not None:
+            raise AssertionError(
+                "fetch_spec and last_revision are mutually exclusive.")
+        if self.target.base == self.source.base:
+            return (0, [])
+        self.source.lock_read()
+        try:
+            if stop_revision is None and fetch_spec is None:
+                stop_revision = self.source.last_revision()
+                stop_revision = _mod_revision.ensure_null(stop_revision)
+            return self.target.repository.fetch(self.source.repository,
+                revision_id=stop_revision, fetch_spec=fetch_spec)
+        finally:
+            self.source.unlock()
+
+    @needs_write_lock
     def update_revisions(self, stop_revision=None, overwrite=False,
         graph=None, fetch_tags=True):
         """See InterBranch.update_revisions()."""

=== modified file 'bzrlib/tests/per_branch/test_branch.py'
--- a/bzrlib/tests/per_branch/test_branch.py	2011-03-23 05:15:48 +0000
+++ b/bzrlib/tests/per_branch/test_branch.py	2011-03-26 01:40:41 +0000
@@ -25,16 +25,13 @@
     gpg,
     merge,
     urlutils,
-    transactions,
     transport,
     remote,
     repository,
     revision,
     tests,
     )
-from bzrlib.symbol_versioning import deprecated_in
 from bzrlib.tests import (
-    http_server,
     per_branch,
     )
 from bzrlib.tests.http_server import HttpServer

=== modified file 'bzrlib/tests/per_interbranch/__init__.py'
--- a/bzrlib/tests/per_interbranch/__init__.py	2011-03-08 15:55:54 +0000
+++ b/bzrlib/tests/per_interbranch/__init__.py	2011-03-26 01:53:34 +0000
@@ -37,11 +37,6 @@
     BzrDirFormat,
     BzrDirMetaFormat1,
     )
-from bzrlib.errors import (
-    FileExists,
-    NotBranchError,
-    UninitializableFormat,
-    )
 from bzrlib.tests import (
     TestCaseWithTransport,
     multiply_tests,
@@ -171,6 +166,7 @@
 
 def load_tests(standard_tests, module, loader):
     submod_tests = loader.loadTestsFromModuleNames([
+        'bzrlib.tests.per_interbranch.test_fetch',
         'bzrlib.tests.per_interbranch.test_get',
         'bzrlib.tests.per_interbranch.test_copy_content_into',
         'bzrlib.tests.per_interbranch.test_pull',

=== added file 'bzrlib/tests/per_interbranch/test_fetch.py'
--- a/bzrlib/tests/per_interbranch/test_fetch.py	1970-01-01 00:00:00 +0000
+++ b/bzrlib/tests/per_interbranch/test_fetch.py	2011-03-26 01:53:34 +0000
@@ -0,0 +1,47 @@
+# Copyright (C) 2011 Canonical Ltd
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+"""Tests for InterBranch.fetch."""
+
+from bzrlib.revision import NULL_REVISION
+from bzrlib.tests.per_interbranch import (
+    TestCaseWithInterBranch,
+    )
+
+
+class TestInterBranchFetch(TestCaseWithInterBranch):
+
+    def test_fetch_revisions(self):
+        """Test fetch-revision operation."""
+        wt = self.make_from_branch_and_tree('b1')
+        b1 = wt.branch
+        self.build_tree_contents([('b1/foo', 'hello')])
+        wt.add(['foo'], ['foo-id'])
+        wt.commit('lala!', rev_id='revision-1', allow_pointless=False)
+
+        b2 = self.make_to_branch('b2')
+        b2.fetch(b1)
+
+        # fetch does not update the last revision
+        self.assertEquals(NULL_REVISION, b2.last_revision())
+
+        rev = b2.repository.get_revision('revision-1')
+        tree = b2.repository.revision_tree('revision-1')
+        tree.lock_read()
+        self.addCleanup(tree.unlock)
+        self.assertEqual(tree.get_file_text('foo-id'), 'hello')
+
+




More information about the bazaar-commits mailing list