Rev 3301: Deprecate VersionedFile.has_ghost. in http://people.ubuntu.com/~robertc/baz2.0/versioned_files

Robert Collins robertc at robertcollins.net
Thu Mar 27 01:25:30 GMT 2008


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

------------------------------------------------------------
revno: 3301
revision-id: robertc at robertcollins.net-20080327012524-yfgr0lek5ckiowhn
parent: robertc at robertcollins.net-20080327002741-1vrg4yekrlvv4lfn
committer: Robert Collins <robertc at robertcollins.net>
branch nick: versionedfile.apicleanup
timestamp: Thu 2008-03-27 12:25:24 +1100
message:
  Deprecate VersionedFile.has_ghost.
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/knit.py                 knit.py-20051212171256-f056ac8f0fbe1bd9
  bzrlib/tests/interversionedfile_implementations/test_join.py test_join.py-20060302012326-9b5e9b0f0a03fedc
  bzrlib/tests/test_knit.py      test_knit.py-20051212171302-95d4c00dd5f11f2b
  bzrlib/tests/test_versionedfile.py test_versionedfile.py-20060222045249-db45c9ed14a1c2e5
  bzrlib/versionedfile.py        versionedfile.py-20060222045106-5039c71ee3b65490
=== modified file 'NEWS'
--- a/NEWS	2008-03-26 21:55:55 +0000
+++ b/NEWS	2008-03-27 01:25:24 +0000
@@ -77,6 +77,9 @@
     * ``VersionedFile.get_parents`` is deprecated, please use
       ``VersionedFile.get_parent_map``. (Robert Collins)
 
+    * ``VersionedFile.has_ghost`` is now deprecated, as it is both expensive
+      and unused outside of a single test. (Robert Collins)
+
   TESTING:
 
     * New -Dselftest_debug flag disables clearing of the debug flags during

=== modified file 'bzrlib/knit.py'
--- a/bzrlib/knit.py	2008-03-26 21:42:35 +0000
+++ b/bzrlib/knit.py	2008-03-27 01:25:24 +0000
@@ -108,7 +108,12 @@
     sha_string,
     sha_strings,
     )
-from bzrlib.symbol_versioning import DEPRECATED_PARAMETER, deprecated_passed
+from bzrlib.symbol_versioning import (
+    DEPRECATED_PARAMETER,
+    deprecated_method,
+    deprecated_passed,
+    one_four,
+    )
 from bzrlib.tsort import topo_sort
 from bzrlib.tuned_gzip import GzipFile, bytes_to_gzip
 import bzrlib.ui
@@ -771,18 +776,18 @@
         """See VersionedFile.get_suffixes()."""
         return [DATA_SUFFIX, INDEX_SUFFIX]
 
+    @deprecated_method(one_four)
     def has_ghost(self, version_id):
         """True if there is a ghost reference in the file to version_id."""
         # maybe we have it
         if self.has_version(version_id):
             return False
         # optimisable if needed by memoising the _ghosts set.
-        items = self._index.get_graph()
+        items = self.get_parent_map(self.versions())
         for node, parents in items:
             for parent in parents:
-                if parent not in self._index._cache:
-                    if parent == version_id:
-                        return True
+                if parent == version_id and parent not in items:
+                    return True
         return False
 
     def insert_data_stream(self, (format, data_list, reader_callable)):

=== modified file 'bzrlib/tests/interversionedfile_implementations/test_join.py'
--- a/bzrlib/tests/interversionedfile_implementations/test_join.py	2008-03-26 21:42:35 +0000
+++ b/bzrlib/tests/interversionedfile_implementations/test_join.py	2008-03-27 01:25:24 +0000
@@ -205,41 +205,17 @@
         # does not must discard it, and when filling a ghost for a listed
         # ghost must reconcile it
         source = self.get_source()
-        try:
-            source.has_ghost('a')
-            source_ghosts = True
-        except NotImplementedError:
-            source_ghosts = False
         target = self.get_target()
-        try:
-            target.has_ghost('a')
-            target_ghosts = True
-        except NotImplementedError:
-            target_ghosts = False
-
-        if not source_ghosts and not target_ghosts:
-            # nothing to do
-            return
-        if source_ghosts and not target_ghosts:
-            # switch source and target so source is ghostless
-            t = source
-            source = target
-            target = t
-            source_ghosts = False
-            target_ghosts = True
-        # now target always supports ghosts.
-
         # try filling target with ghosts and filling in reverse -  
-        target.add_lines_with_ghosts('notbase', ['base'], [])
+        try:
+            target.add_lines_with_ghosts('notbase', ['base'], [])
+        except NotImplementedError:
+            # The target does not support ghosts; the test is irrelevant.
+            return
         try:
             source.join(target)
         except errors.RevisionNotPresent:
-            # can't join a ghost containing target onto a non-ghost supporting
-            # source.
-            self.assertFalse(source_ghosts)
             return
-        else:
-            self.assertTrue(source_ghosts)
         # legacy apis should behave
         self.assertEqual(['notbase'], source.get_ancestry(['notbase']))
         self.assertFalse(source.has_version('base'))

=== modified file 'bzrlib/tests/test_knit.py'
--- a/bzrlib/tests/test_knit.py	2008-03-20 01:31:04 +0000
+++ b/bzrlib/tests/test_knit.py	2008-03-27 01:25:24 +0000
@@ -1897,7 +1897,9 @@
         # The target knit object is in a consistent state, i.e. the record we
         # just added is immediately visible.
         self.assertTrue(target.has_version('text-a'))
-        self.assertTrue(target.has_ghost('text-ghost'))
+        self.assertFalse(target.has_version('text-ghost'))
+        self.assertEqual({'text-a':('text-ghost',)},
+            target.get_parent_map(['text-a', 'text-ghost']))
         self.assertEqual(split_lines(TEXT_1), target.get_lines('text-a'))
 
     def test_insert_data_stream_inconsistent_version_lines(self):

=== modified file 'bzrlib/tests/test_versionedfile.py'
--- a/bzrlib/tests/test_versionedfile.py	2008-03-20 00:43:25 +0000
+++ b/bzrlib/tests/test_versionedfile.py	2008-03-27 01:25:24 +0000
@@ -630,7 +630,6 @@
             vf.add_lines_with_ghosts('notbxbfse', [parent_id_utf8], [])
         except NotImplementedError:
             # check the other ghost apis are also not implemented
-            self.assertRaises(NotImplementedError, vf.has_ghost, 'foo')
             self.assertRaises(NotImplementedError, vf.get_ancestry_with_ghosts, ['foo'])
             self.assertRaises(NotImplementedError, vf.get_parents_with_ghosts, 'foo')
             self.assertRaises(NotImplementedError, vf.get_graph_with_ghosts)
@@ -648,7 +647,8 @@
         self.assertEqual([parent_id_utf8, 'notbxbfse'], vf.get_ancestry_with_ghosts(['notbxbfse']))
         self.assertEqual([parent_id_utf8], vf.get_parents_with_ghosts('notbxbfse'))
         self.assertEqual({'notbxbfse':(parent_id_utf8,)}, vf.get_graph_with_ghosts())
-        self.assertTrue(vf.has_ghost(parent_id_utf8))
+        self.assertTrue(self.applyDeprecated(one_four, vf.has_ghost,
+            parent_id_utf8))
         # if we add something that is a ghost of another, it should correct the
         # results of the prior apis
         vf.add_lines(parent_id_utf8, [], [])
@@ -668,7 +668,8 @@
                           'notbxbfse':(parent_id_utf8,),
                           },
                          vf.get_graph_with_ghosts())
-        self.assertFalse(vf.has_ghost(parent_id_utf8))
+        self.assertFalse(self.applyDeprecated(one_four, vf.has_ghost,
+            parent_id_utf8))
 
     def test_add_lines_with_ghosts_after_normal_revs(self):
         # some versioned file formats allow lines to be added with parent
@@ -678,10 +679,9 @@
         vf = self.get_file()
         # probe for ghost support
         try:
-            vf.has_ghost('hoo')
+            vf.add_lines_with_ghosts('base', [], ['line\n', 'line_b\n'])
         except NotImplementedError:
             return
-        vf.add_lines_with_ghosts('base', [], ['line\n', 'line_b\n'])
         vf.add_lines_with_ghosts('references_ghost',
                                  ['base', 'a_ghost'],
                                  ['line\n', 'line_b\n', 'line_c\n'])

=== modified file 'bzrlib/versionedfile.py'
--- a/bzrlib/versionedfile.py	2008-03-26 21:42:35 +0000
+++ b/bzrlib/versionedfile.py	2008-03-27 01:25:24 +0000
@@ -71,6 +71,7 @@
         """Return a unsorted list of versions."""
         raise NotImplementedError(self.versions)
 
+    @deprecated_method(one_four)
     def has_ghost(self, version_id):
         """Returns whether version is present as a ghost."""
         raise NotImplementedError(self.has_ghost)




More information about the bazaar-commits mailing list