Rev 2745: Merge some test fixes from Martin. in http://people.ubuntu.com/~robertc/baz2.0/repository

Robert Collins robertc at robertcollins.net
Tue Aug 28 23:19:25 BST 2007


At http://people.ubuntu.com/~robertc/baz2.0/repository

------------------------------------------------------------
revno: 2745
revision-id: robertc at robertcollins.net-20070828221915-fkprmgth95yihpyw
parent: robertc at robertcollins.net-20070828021813-4p3w6xklwghhzwg9
parent: mbp at sourcefrog.net-20070828105641-pd0vwkmeop9e09rf
committer: Robert Collins <robertc at robertcollins.net>
branch nick: repository
timestamp: Wed 2007-08-29 08:19:15 +1000
message:
  Merge some test fixes from Martin.
modified:
  bzrlib/bundle/serializer/v4.py v10.py-20070611062757-5ggj7k18s9dej0fr-1
  bzrlib/fetch.py                fetch.py-20050818234941-26fea6105696365d
  bzrlib/remote.py               remote.py-20060720103555-yeeg2x51vn0rbtdp-1
  bzrlib/repository.py           rev_storage.py-20051111201905-119e9401e46257e3
  bzrlib/tests/blackbox/test_reconcile.py test_fix.py-20060223013051-9a188e15a5ee9451
  bzrlib/tests/test_info.py      test_info.py-20070320150933-m0xxm1g7xi9v6noe-1
    ------------------------------------------------------------
    revno: 2744.1.5
    revision-id: mbp at sourcefrog.net-20070828105641-pd0vwkmeop9e09rf
    parent: mbp at sourcefrog.net-20070828102850-a8qyqtb948y43rth
    committer: Martin Pool <mbp at sourcefrog.net>
    branch nick: pack-repository
    timestamp: Tue 2007-08-28 20:56:41 +1000
    message:
      Add Repository.base on all repositories.
      
      Repository.has_same_location now *just* checks the location, not the class -
      this seems to fix problems in interaction between remote and vfs repositories.
      
      Add str and repr on RemoteRepository.
       
      RemoteRepository.fetch shortcircuits when given two repositories at the same
      location, which is required by the underlying fetch code.
    modified:
      bzrlib/fetch.py                fetch.py-20050818234941-26fea6105696365d
      bzrlib/remote.py               remote.py-20060720103555-yeeg2x51vn0rbtdp-1
      bzrlib/repository.py           rev_storage.py-20051111201905-119e9401e46257e3
    ------------------------------------------------------------
    revno: 2744.1.4
    revision-id: mbp at sourcefrog.net-20070828102850-a8qyqtb948y43rth
    parent: mbp at sourcefrog.net-20070828102638-hljo5fm7a4bjthg2
    committer: Martin Pool <mbp at sourcefrog.net>
    branch nick: pack-repository
    timestamp: Tue 2007-08-28 20:28:50 +1000
    message:
      better message for attempted fetch between aliased repositories
    modified:
      bzrlib/fetch.py                fetch.py-20050818234941-26fea6105696365d
    ------------------------------------------------------------
    revno: 2744.1.3
    revision-id: mbp at sourcefrog.net-20070828102638-hljo5fm7a4bjthg2
    parent: mbp at sourcefrog.net-20070828095109-8ljoy65xsu2dv0pf
    committer: Martin Pool <mbp at sourcefrog.net>
    branch nick: pack-repository
    timestamp: Tue 2007-08-28 20:26:38 +1000
    message:
      Add convenience Repository.call_in_write_group and use this for tests that
      access Repository.add_inventory directly.
    modified:
      bzrlib/repository.py           rev_storage.py-20051111201905-119e9401e46257e3
      bzrlib/tests/blackbox/test_reconcile.py test_fix.py-20060223013051-9a188e15a5ee9451
      bzrlib/tests/interrepository_implementations/test_interrepository.py test_interrepository.py-20060220061411-1ec13fa99e5e3eee
      bzrlib/tests/repository_implementations/test_reconcile.py test_reconcile.py-20060223022332-572ef70a3288e369
    ------------------------------------------------------------
    revno: 2744.1.2
    revision-id: mbp at sourcefrog.net-20070828095109-8ljoy65xsu2dv0pf
    parent: mbp at sourcefrog.net-20070828081705-xej6l2h4wpp3fyi2
    committer: Martin Pool <mbp at sourcefrog.net>
    branch nick: pack-repository
    timestamp: Tue 2007-08-28 19:51:09 +1000
    message:
      exempt experimental-* formats from test_describe_checkout_format
    modified:
      bzrlib/tests/test_info.py      test_info.py-20070320150933-m0xxm1g7xi9v6noe-1
    ------------------------------------------------------------
    revno: 2744.1.1
    revision-id: mbp at sourcefrog.net-20070828081705-xej6l2h4wpp3fyi2
    parent: robertc at robertcollins.net-20070828021813-4p3w6xklwghhzwg9
    committer: Martin Pool <mbp at sourcefrog.net>
    branch nick: pack-repository
    timestamp: Tue 2007-08-28 18:17:05 +1000
    message:
      RevisionInstaller now creates a write group for its work
    modified:
      bzrlib/bundle/serializer/v4.py v10.py-20070611062757-5ggj7k18s9dej0fr-1
=== modified file 'bzrlib/bundle/serializer/v4.py'
--- a/bzrlib/bundle/serializer/v4.py	2007-08-17 00:53:48 +0000
+++ b/bzrlib/bundle/serializer/v4.py	2007-08-28 08:17:05 +0000
@@ -466,7 +466,20 @@
         self._info = None
 
     def install(self):
-        """Perform the installation"""
+        """Perform the installation.
+        
+        Must be called with the Repository locked.
+        """
+        self._repository.start_write_group()
+        try:
+            result = self._install_in_group()
+        except:
+            self._repository.abort_write_group()
+            raise
+        self._repository.commit_write_group()
+        return result
+
+    def _install_in_group(self):
         current_file = None
         current_versionedfile = None
         pending_file_records = []

=== modified file 'bzrlib/fetch.py'
--- a/bzrlib/fetch.py	2007-08-26 02:06:11 +0000
+++ b/bzrlib/fetch.py	2007-08-28 22:19:15 +0000
@@ -72,7 +72,7 @@
     after running:
     count_copied -- number of revisions copied
 
-    This should not be used directory, its essential a object to encapsulate
+    This should not be used directly, it's essential a object to encapsulate
     the logic in InterRepository.fetch().
     """
     def __init__(self, to_repository, from_repository, last_revision=None, pb=None):
@@ -81,8 +81,9 @@
         self.count_copied = 0
         if to_repository.has_same_location(from_repository):
             # repository.fetch should be taking care of this case.
-            raise errors.BzrError('unreachable code - Interrepository fetch'
-                ' with the same repository.')
+            raise errors.BzrError('RepoFetcher run '
+                    'between two objects at the same location: '
+                    '%r and %r' % (to_repository, from_repository))
         self.to_repository = to_repository
         self.from_repository = from_repository
         # must not mutate self._last_revision as its potentially a shared instance

=== modified file 'bzrlib/remote.py'
--- a/bzrlib/remote.py	2007-08-22 06:30:25 +0000
+++ b/bzrlib/remote.py	2007-08-28 22:19:15 +0000
@@ -254,6 +254,12 @@
         self._leave_lock = False
         # for tests
         self._reconcile_does_inventory_gc = True
+        self.base = self.bzrdir.transport.base
+
+    def __str__(self):
+        return "%s(%s)" % (self.__class__.__name__, self.base)
+
+    __repr__ = __str__
 
     def abort_write_group(self):
         """Complete a write group on the decorated repository.
@@ -328,8 +334,7 @@
         return response[0] == 'yes'
 
     def has_same_location(self, other):
-        return (self.__class__ == other.__class__ and
-                self.bzrdir.transport.base == other.bzrdir.transport.base)
+        return (self.base == other.base)
         
     def get_graph(self, other_repository=None):
         """Return the graph for this repository format"""
@@ -586,6 +591,8 @@
         return False
 
     def fetch(self, source, revision_id=None, pb=None):
+        if self.has_same_location(source) or source.has_same_location(self):
+            return 0, []
         self._ensure_real()
         return self._real_repository.fetch(
             source, revision_id=revision_id, pb=pb)

=== modified file 'bzrlib/repository.py'
--- a/bzrlib/repository.py	2007-08-26 02:06:11 +0000
+++ b/bzrlib/repository.py	2007-08-28 10:56:41 +0000
@@ -260,10 +260,11 @@
         # on whether escaping is required.
         self._warn_if_deprecated()
         self._write_group = None
+        self.base = control_files._transport.base
 
     def __repr__(self):
-        return '%s(%r)' % (self.__class__.__name__, 
-                           self.bzrdir.transport.base)
+        return '%s(%r)' % (self.__class__.__name__,
+                           self.base)
 
     def has_same_location(self, other):
         """Returns a boolean indicating if this repository is at the same
@@ -272,10 +273,9 @@
         This might return False even when two repository objects are accessing
         the same physical repository via different URLs.
         """
-        if self.__class__ is not other.__class__:
-            return False
-        return (self.control_files._transport.base ==
-                other.control_files._transport.base)
+        ## if self.__class__ is not other.__class__:
+        ##     return False
+        return (self.base == other.base)
 
     def is_in_write_group(self):
         """Return True if there is an open write group.
@@ -526,6 +526,27 @@
         # so we can detect unlock/relock - the write group is now entered.
         self._write_group = self.get_transaction()
 
+    @needs_write_lock
+    def call_in_write_group(self, fn, *args, **kwargs):
+        """Call a callable within a write group.
+
+        On error the write group is aborted and on success it is commited.
+
+        This method may not be called if the repository is already in a 
+        write group.
+
+        This can be used for testing methods normally used within a larger 
+        write group.
+        """
+        self.start_write_group()
+        try:
+            result = fn(*args, **kwargs)
+        except:
+            self.abort_write_group()
+            raise
+        self.commit_write_group()
+        return result
+
     def _start_write_group(self):
         """Template method for per-repository write group startup.
         

=== modified file 'bzrlib/tests/blackbox/test_reconcile.py'
--- a/bzrlib/tests/blackbox/test_reconcile.py	2007-06-27 19:13:50 +0000
+++ b/bzrlib/tests/blackbox/test_reconcile.py	2007-08-28 22:19:15 +0000
@@ -54,7 +54,7 @@
         repo = t.branch.repository
         inv = Inventory(revision_id='missing')
         inv.root.revision='missing'
-        repo.add_inventory('missing', inv, [])
+        repo.call_in_write_group(repo.add_inventory, 'missing', inv, [])
         (out, err) = self.run_bzr('reconcile')
         self.assertEqualDiff(out, "Reconciling repository %s\n"
                                   "Backup Inventory created.\n"

=== modified file 'bzrlib/tests/test_info.py'
--- a/bzrlib/tests/test_info.py	2007-07-06 21:20:10 +0000
+++ b/bzrlib/tests/test_info.py	2007-08-28 09:51:09 +0000
@@ -97,8 +97,11 @@
                 bzrdir.format_registry.make_bzrdir(format).workingtree_format
             control.create_workingtree()
             tree = workingtree.WorkingTree.open('%s_co' % format)
-            self.assertEqual(expected, info.describe_format(tree.bzrdir,
-                tree.branch.repository, tree.branch, tree))
+            format_description = info.describe_format(tree.bzrdir,
+                    tree.branch.repository, tree.branch, tree)
+            self.assertEqual(expected, format_description,
+                "checkout of format called %r was described as %r" %
+                (expected, format_description))
         finally:
             control._format.workingtree_format = old_format
 
@@ -128,7 +131,10 @@
 
     def test_describe_checkout_format(self):
         for key in bzrdir.format_registry.keys():
-            if key in ('default', 'weave'):
+            if key in ('default', 'weave', 'experimental'):
+                continue
+            if key.startswith('experimental-'):
+                # these are typically hidden or aliases for other formats
                 continue
             expected = None
             if key in ('dirstate', 'dirstate-tags', 'dirstate-with-subtree'):



More information about the bazaar-commits mailing list