Rev 2889: (robertc) Move same-repo fetch checking logic to the repository class user visible function for more reuse. (Robert Collins) in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Thu Oct 4 23:33:16 BST 2007


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

------------------------------------------------------------
revno: 2889
revision-id: pqm at pqm.ubuntu.com-20071004223314-qpih4e2os3o2627a
parent: pqm at pqm.ubuntu.com-20071004215001-549ul8av89cwpnjp
parent: robertc at robertcollins.net-20071004012406-20bfylx7ngky01r5
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Thu 2007-10-04 23:33:14 +0100
message:
  (robertc) Move same-repo fetch checking logic to the repository class user visible function for more reuse. (Robert Collins)
modified:
  bzrlib/debug.py                debug.py-20061102062349-vdhrw9qdpck8cl35-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/interrepository_implementations/test_interrepository.py test_interrepository.py-20060220061411-1ec13fa99e5e3eee
    ------------------------------------------------------------
    revno: 2881.4.1
    merged: robertc at robertcollins.net-20071004012406-20bfylx7ngky01r5
    parent: pqm at pqm.ubuntu.com-20071003232450-c831pepea3skddct
    committer: Robert Collins <robertc at robertcollins.net>
    branch nick: fetch
    timestamp: Thu 2007-10-04 11:24:06 +1000
    message:
      Move responsibility for detecting same-repo fetching from the
      per-repository fetch logic to the wrapper function that is the official
      API. (Robert Collins)
=== modified file 'bzrlib/debug.py'
--- a/bzrlib/debug.py	2007-08-28 01:41:12 +0000
+++ b/bzrlib/debug.py	2007-10-04 01:24:06 +0000
@@ -27,6 +27,7 @@
  
  * evil - capture call sites that do expensive or badly-scaling operations.
  * error - show stack traces for all top level exceptions
+ * fetch - trace history copying between repositories
  * hooks - trace hook execution
  * hpss - trace smart protocol requests and responses
  * index - trace major index operations

=== modified file 'bzrlib/fetch.py'
--- a/bzrlib/fetch.py	2007-09-03 02:58:58 +0000
+++ b/bzrlib/fetch.py	2007-10-04 01:24:06 +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):
@@ -80,11 +80,10 @@
         self.failed_revisions = []
         self.count_copied = 0
         if to_repository.has_same_location(from_repository):
-            # check that last_revision is in 'from' and then return a
-            # no-operation.
-            if last_revision is not None and not is_null(last_revision):
-                to_repository.get_revision(last_revision)
-            return
+            # repository.fetch should be taking care of this case.
+            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-10-03 05:25:50 +0000
+++ b/bzrlib/remote.py	2007-10-04 01:24:06 +0000
@@ -607,6 +607,13 @@
         return False
 
     def fetch(self, source, revision_id=None, pb=None):
+        if self.has_same_location(source):
+            # 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)):
+                self.get_revision(revision_id)
+            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-10-03 06:15:06 +0000
+++ b/bzrlib/repository.py	2007-10-04 01:24:06 +0000
@@ -629,10 +629,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
@@ -792,7 +793,9 @@
         """
         if self._write_group is not self.get_transaction():
             # has an unlock or relock occured ?
-            raise errors.BzrError('mismatched lock context and write group.')
+            raise errors.BzrError('mismatched lock context %r and '
+                'write group %r.' %
+                (self.get_transaction(), self._write_group))
         self._commit_write_group()
         self._write_group = None
 
@@ -811,6 +814,14 @@
         If revision_id is None all content is copied.
         """
         revision_id = osutils.safe_revision_id(revision_id)
+        # fast path same-url fetch operations
+        if self.has_same_location(source):
+            # 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)):
+                self.get_revision(revision_id)
+            return 0, []
         inter = InterRepository.get(source, self)
         try:
             return inter.fetch(revision_id=revision_id, pb=pb)
@@ -919,7 +930,7 @@
     def has_revision(self, revision_id):
         """True if this repository has a copy of the revision."""
         if 'evil' in debug.debug_flags:
-            mutter_callsite(2, "has_revision is a LBYL symptom.")
+            mutter_callsite(3, "has_revision is a LBYL symptom.")
         revision_id = osutils.safe_revision_id(revision_id)
         return self._revision_store.has_revision_id(revision_id,
                                                     self.get_transaction())
@@ -1239,7 +1250,7 @@
         :return: a Graph object with the graph reachable from revision_ids.
         """
         if 'evil' in debug.debug_flags:
-            mutter_callsite(2,
+            mutter_callsite(3,
                 "get_revision_graph_with_ghosts scales with size of history.")
         result = deprecated_graph.Graph()
         if not revision_ids:
@@ -1891,9 +1902,9 @@
     'bzrlib.repofmt.weaverepo',
     'RepositoryFormat7'
     )
+
 # KEEP in sync with bzrdir.format_registry default, which controls the overall
 # default control directory format
-
 format_registry.register_lazy(
     'Bazaar-NG Knit Repository Format 1',
     'bzrlib.repofmt.knitrepo',
@@ -1967,6 +1978,15 @@
         # that we've decided we need.
         return [rev_id for rev_id in source_ids if rev_id in result_set]
 
+    @staticmethod
+    def _same_model(source, target):
+        """True if source and target have the same data representation."""
+        if source.supports_rich_root() != target.supports_rich_root():
+            return False
+        if source._serializer != target._serializer:
+            return False
+        return True
+
 
 class InterSameDataRepository(InterRepository):
     """Code for converting between repositories that represent the same data.
@@ -1986,11 +2006,7 @@
 
     @staticmethod
     def is_compatible(source, target):
-        if source.supports_rich_root() != target.supports_rich_root():
-            return False
-        if source._serializer != target._serializer:
-            return False
-        return True
+        return InterRepository._same_model(source, target)
 
     @needs_write_lock
     def copy_content(self, revision_id=None):
@@ -2173,12 +2189,13 @@
         could lead to confusing results, and there is no need to be 
         overly general.
         """
-        from bzrlib.repofmt.knitrepo import RepositoryFormatKnit1
+        from bzrlib.repofmt.knitrepo import RepositoryFormatKnit
         try:
-            return (isinstance(source._format, (RepositoryFormatKnit1)) and
-                    isinstance(target._format, (RepositoryFormatKnit1)))
+            are_knits = (isinstance(source._format, RepositoryFormatKnit) and
+                isinstance(target._format, RepositoryFormatKnit))
         except AttributeError:
             return False
+        return are_knits and InterRepository._same_model(source, target)
 
     @needs_write_lock
     def fetch(self, revision_id=None, pb=None):

=== modified file 'bzrlib/tests/interrepository_implementations/test_interrepository.py'
--- a/bzrlib/tests/interrepository_implementations/test_interrepository.py	2007-09-27 21:11:38 +0000
+++ b/bzrlib/tests/interrepository_implementations/test_interrepository.py	2007-10-04 01:24:06 +0000
@@ -178,7 +178,8 @@
         source = source_tree.branch.repository
         target = self.make_to_repository('target')
     
-        # start by adding a file so the data for hte file exists.
+        # start by adding a file so the data knit for the file exists in
+        # repositories that have specific files for each fileid.
         self.build_tree(['source/id'])
         source_tree.add(['id'], ['id'])
         source_tree.commit('a', rev_id='a')
@@ -262,7 +263,7 @@
     def test_missing_revision_ids(self):
         # revision ids in repository A but not B are returned, fake ones
         # are stripped. (fake meaning no revision object, but an inventory 
-        # as some formats keyed off inventory data in the past.
+        # as some formats keyed off inventory data in the past.)
         # make a repository to compare against that claims to have rev1
         repo_b = self.make_to_repository('rev1_only')
         repo_a = self.bzrdir.open_repository()




More information about the bazaar-commits mailing list