Rev 86: Avoiding triggering loading of unused bzrlib xml serializers. in http://people.canonical.com/~robertc/baz2.0/plugins/search/trunk

Robert Collins robertc at robertcollins.net
Sat Apr 23 23:14:15 UTC 2011


At http://people.canonical.com/~robertc/baz2.0/plugins/search/trunk

------------------------------------------------------------
revno: 86 [merge]
revision-id: robertc at robertcollins.net-20110423231407-vp2tsjyquotpxmct
parent: robertc at robertcollins.net-20110201044744-vvozddwys1vmo2zl
parent: jelmer at samba.org-20110314224242-rc3bi1katm44ahuk
committer: Robert Collins <robertc at robertcollins.net>
branch nick: trunk
timestamp: Sun 2011-04-24 11:14:07 +1200
message:
  Avoiding triggering loading of unused bzrlib xml serializers.
  (Jelmer Vernooij)
modified:
  NEWS                           news-20080608052041-z5bahsl8kwl0uf4x-2
  index.py                       index.py-20080608055509-hnimeek7q8tctkqf-2
=== modified file 'NEWS'
--- a/NEWS	2011-02-01 04:47:44 +0000
+++ b/NEWS	2011-04-23 23:14:07 +0000
@@ -43,6 +43,9 @@
     * Compatibility with split-inventory repositories (requires a bzrlib that
       supports them). (Robert Collins)
 
+    * Avoiding triggering loading of unused bzrlib xml serializers.
+      (Jelmer Vernooij)
+
     * Will now index revision committers, authors and bugs.
       (#320236, Gary van der Merwe)
 

=== modified file 'index.py'
--- a/index.py	2011-02-01 04:20:25 +0000
+++ b/index.py	2011-03-14 22:42:42 +0000
@@ -46,32 +46,40 @@
 from bzrlib.plugins.search.transport import FileView
 from bzrlib.multiparent import NewText
 from bzrlib.revision import NULL_REVISION
-xml_serializers = []
-try:
-    from bzrlib.xml4 import _Serializer_v4
-    xml_serializers.append(_Serializer_v4)
-except ImportError:
-    pass
-try:
-    from bzrlib.xml5 import Serializer_v5
-    xml_serializers.append(Serializer_v5)
-except ImportError:
-    pass
-try:
-    from bzrlib.xml6 import Serializer_v6
-    xml_serializers.append(Serializer_v6)
-except ImportError:
-    pass
-try:
-    from bzrlib.xml7 import Serializer_v7
-    xml_serializers.append(Serializer_v7)
-except ImportError:
-    pass
-try:
-    from bzrlib.xml8 import Serializer_v8
-    xml_serializers.append(Serializer_v8)
-except ImportError:
-    pass
+
+_xml_serializers = None
+def xml_serializers():
+    global _xml_serializers
+    if _xml_serializers is not None:
+        return _xml_serializers
+    _xml_serializers = []
+    try:
+        from bzrlib.xml4 import _Serializer_v4
+        _xml_serializers.append(_Serializer_v4)
+    except ImportError:
+        pass
+    try:
+        from bzrlib.xml5 import Serializer_v5
+        _xml_serializers.append(Serializer_v5)
+    except ImportError:
+        pass
+    try:
+        from bzrlib.xml6 import Serializer_v6
+        _xml_serializers.append(Serializer_v6)
+    except ImportError:
+        pass
+    try:
+        from bzrlib.xml7 import Serializer_v7
+        _xml_serializers.append(Serializer_v7)
+    except ImportError:
+        pass
+    try:
+        from bzrlib.xml8 import Serializer_v8
+        _xml_serializers.append(Serializer_v8)
+    except ImportError:
+        pass
+    return _xml_serializers
+
 from bzrlib.transport import get_transport
 from bzrlib.tsort import topo_sort
 
@@ -717,7 +725,7 @@
                 bar.update("Extract revision paths", offset, groups)
                 inventory_group = order[offset * group_size:(offset + 1) * group_size]
                 serializer = repository._serializer
-                if type(serializer) in xml_serializers:
+                if type(serializer) in xml_serializers():
                     # Fast path for flat-file serializers.
                     group_keys = [(revid,) for revid in inventory_group]
                     stream = repository.inventories.get_record_stream(




More information about the bazaar-commits mailing list