Rev 5770: (spiv) Use lazy imports in bzrlib.tree. (Jelmer Vernooij) in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Fri Apr 8 09:54:48 UTC 2011


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

------------------------------------------------------------
revno: 5770 [merge]
revision-id: pqm at pqm.ubuntu.com-20110408095443-euiq0776jpr18w5d
parent: pqm at pqm.ubuntu.com-20110408090417-06s986zz14u67e0d
parent: jelmer at samba.org-20110405135833-lzphu3vh7vzubiz9
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Fri 2011-04-08 09:54:43 +0000
message:
  (spiv) Use lazy imports in bzrlib.tree. (Jelmer Vernooij)
modified:
  bzrlib/tests/test_import_tariff.py test_import_tariff.p-20100207155145-ff9infp7goncs7zh-1
  bzrlib/tree.py                 tree.py-20050309040759-9d5f2496be663e77
  bzrlib/workingtree.py          workingtree.py-20050511021032-29b6ec0a681e02e3
  bzrlib/workingtree_4.py        workingtree_4.py-20070208044105-5fgpc5j3ljlh5q6c-1
=== modified file 'bzrlib/tests/test_import_tariff.py'
--- a/bzrlib/tests/test_import_tariff.py	2011-04-05 13:49:36 +0000
+++ b/bzrlib/tests/test_import_tariff.py	2011-04-05 13:58:33 +0000
@@ -101,6 +101,7 @@
             'bzrlib.bundle.commands',
             'bzrlib.cmd_version_info',
             'bzrlib.externalcommand',
+            'bzrlib.filters',
             # foreign branch plugins import the foreign_vcs_registry from 
             # bzrlib.foreign so it can't be blacklisted
             'bzrlib.gpg',
@@ -110,6 +111,7 @@
             'bzrlib.msgeditor',
             'bzrlib.patiencediff',
             'bzrlib.remote',
+            'bzrlib.rules',
             'bzrlib.sign_my_commits',
             'bzrlib.smart',
             'bzrlib.smart.client',

=== modified file 'bzrlib/tree.py'
--- a/bzrlib/tree.py	2011-04-07 10:36:24 +0000
+++ b/bzrlib/tree.py	2011-04-08 09:54:43 +0000
@@ -18,24 +18,27 @@
 """
 
 import os
-from collections import deque
-
-import bzrlib
+
+from bzrlib.lazy_import import lazy_import
+lazy_import(globals(), """
+import collections
+
 from bzrlib import (
     conflicts as _mod_conflicts,
     debug,
     delta,
     errors,
     filters,
+    inventory,
     osutils,
     revision as _mod_revision,
     rules,
+    trace,
     )
+""")
+
 from bzrlib.decorators import needs_read_lock
-from bzrlib.inventory import InventoryFile
 from bzrlib.inter import InterObject
-from bzrlib.osutils import fingerprint_file
-from bzrlib.trace import note
 
 
 class Tree(object):
@@ -522,7 +525,7 @@
     def _check_retrieved(self, ie, f):
         if not __debug__:
             return
-        fp = fingerprint_file(f)
+        fp = osutils.fingerprint_file(f)
         f.seek(0)
 
         if ie.text_size is not None:
@@ -669,7 +672,7 @@
         prefs = self.iter_search_rules([path], filter_pref_names).next()
         stk = filters._get_filter_stack_for(prefs)
         if 'filters' in debug.debug_flags:
-            note("*** %s content-filter: %s => %r" % (path,prefs,stk))
+            trace.note("*** %s content-filter: %s => %r" % (path,prefs,stk))
         return stk
 
     def _content_filter_stack_provider(self):
@@ -969,7 +972,7 @@
             # All files are unversioned, so just return an empty delta
             # _compare_trees would think we want a complete delta
             result = delta.TreeDelta()
-            fake_entry = InventoryFile('unused', 'unused', 'unused')
+            fake_entry = inventory.InventoryFile('unused', 'unused', 'unused')
             result.unversioned = [(path, None,
                 self.target._comparison_data(fake_entry, path)[0]) for path in
                 specific_files]
@@ -1040,9 +1043,9 @@
                                      self.target.extras()
                 if specific_files is None or
                     osutils.is_inside_any(specific_files, p)])
-            all_unversioned = deque(all_unversioned)
+            all_unversioned = collections.deque(all_unversioned)
         else:
-            all_unversioned = deque()
+            all_unversioned = collections.deque()
         to_paths = {}
         from_entries_by_dir = list(self.source.iter_entries_by_dir(
             specific_file_ids=specific_file_ids))
@@ -1054,7 +1057,7 @@
         # the unversioned path lookup only occurs on real trees - where there
         # can be extras. So the fake_entry is solely used to look up
         # executable it values when execute is not supported.
-        fake_entry = InventoryFile('unused', 'unused', 'unused')
+        fake_entry = inventory.InventoryFile('unused', 'unused', 'unused')
         for target_path, target_entry in to_entries_by_dir:
             while (all_unversioned and
                 all_unversioned[0][0] < target_path.split('/')):

=== modified file 'bzrlib/workingtree.py'
--- a/bzrlib/workingtree.py	2011-04-05 14:47:26 +0000
+++ b/bzrlib/workingtree.py	2011-04-08 09:54:43 +0000
@@ -50,6 +50,7 @@
     conflicts as _mod_conflicts,
     controldir,
     errors,
+    filters as _mod_filters,
     generate_ids,
     globbing,
     graph as _mod_graph,
@@ -92,7 +93,6 @@
     splitpath,
     supports_executable,
     )
-from bzrlib.filters import filtered_input_file
 from bzrlib.trace import mutter, note
 from bzrlib.transport.local import LocalTransport
 from bzrlib.revision import CURRENT_REVISION
@@ -531,7 +531,7 @@
         stat_value = _fstat(file_obj.fileno())
         if filtered and self.supports_content_filtering():
             filters = self._content_filter_stack(path)
-            file_obj = filtered_input_file(file_obj, filters)
+            file_obj = _mod_filters.filtered_input_file(file_obj, filters)
         return (file_obj, stat_value)
 
     def get_file_text(self, file_id, path=None, filtered=True):
@@ -546,7 +546,7 @@
         f = file(path, 'rb')
         if filtered and self.supports_content_filtering():
             filters = self._content_filter_stack(filename)
-            return filtered_input_file(f, filters)
+            return _mod_filters.filtered_input_file(f, filters)
         else:
             return f
 

=== modified file 'bzrlib/workingtree_4.py'
--- a/bzrlib/workingtree_4.py	2011-04-05 14:47:26 +0000
+++ b/bzrlib/workingtree_4.py	2011-04-08 09:54:43 +0000
@@ -37,6 +37,7 @@
     debug,
     dirstate,
     errors,
+    filters as _mod_filters,
     generate_ids,
     osutils,
     revision as _mod_revision,
@@ -48,7 +49,6 @@
 """)
 
 from bzrlib.decorators import needs_read_lock, needs_write_lock
-from bzrlib.filters import filtered_input_file, internal_size_sha_file_byname
 from bzrlib.inventory import Inventory, ROOT_ID, entry_factory
 from bzrlib.lock import LogicalLockResult
 from bzrlib.mutabletree import needs_tree_write_lock
@@ -1320,7 +1320,7 @@
         """See dirstate.SHA1Provider.sha1()."""
         filters = self.tree._content_filter_stack(
             self.tree.relpath(osutils.safe_unicode(abspath)))
-        return internal_size_sha_file_byname(abspath, filters)[1]
+        return _mod_filters.internal_size_sha_file_byname(abspath, filters)[1]
 
     def stat_and_sha1(self, abspath):
         """See dirstate.SHA1Provider.stat_and_sha1()."""
@@ -1330,7 +1330,7 @@
         try:
             statvalue = os.fstat(file_obj.fileno())
             if filters:
-                file_obj = filtered_input_file(file_obj, filters)
+                file_obj = _mod_filters.filtered_input_file(file_obj, filters)
             sha1 = osutils.size_sha_file(file_obj)[1]
         finally:
             file_obj.close()




More information about the bazaar-commits mailing list