Przeglądaj źródła

Lazily load tempfile in a few more places.

Jelmer Vernooij 4 lat temu
rodzic
commit
d4f71f44b6
2 zmienionych plików z 3 dodań i 2 usunięć
  1. 1 1
      dulwich/hooks.py
  2. 2 1
      dulwich/object_store.py

+ 1 - 1
dulwich/hooks.py

@@ -22,7 +22,6 @@
 
 import os
 import subprocess
-import tempfile
 
 from dulwich.errors import (
     HookError,
@@ -137,6 +136,7 @@ class CommitMsgShellHook(ShellHook):
         filepath = os.path.join(controldir, 'hooks', 'commit-msg')
 
         def prepare_msg(*args):
+            import tempfile
             (fd, path) = tempfile.mkstemp()
 
             with os.fdopen(fd, 'wb') as f:

+ 2 - 1
dulwich/object_store.py

@@ -26,7 +26,6 @@ from io import BytesIO
 import os
 import stat
 import sys
-import tempfile
 
 from dulwich.diff_tree import (
     tree_changes,
@@ -757,6 +756,7 @@ class DiskObjectStore(PackBasedObjectStore):
         Returns: A Pack object pointing at the now-completed thin pack in the
             objects/pack directory.
         """
+        import tempfile
         fd, path = tempfile.mkstemp(dir=self.path, prefix='tmp_pack_')
         with os.fdopen(fd, 'w+b') as f:
             indexer = PackIndexer(f, resolve_ext_ref=self.get_raw)
@@ -804,6 +804,7 @@ class DiskObjectStore(PackBasedObjectStore):
             call when the pack is finished and an abort
             function.
         """
+        import tempfile
         fd, path = tempfile.mkstemp(dir=self.pack_dir, suffix=".pack")
         f = os.fdopen(fd, 'wb')