[Python-modules-commits] [dulwich] 03/10: Avoid double call to os.lstat.

Jelmer Vernooij jelmer at moszumanska.debian.org
Sat Jan 14 20:35:22 UTC 2017


This is an automated email from the git hooks/post-receive script.

jelmer pushed a commit to branch master
in repository dulwich.

commit f9030f0462721ab1039ae926b51b7ada56ed1c62
Author: Jelmer Vernooij <jelmer at jelmer.uk>
Date:   Sat Jan 14 19:46:04 2017 +0000

    Avoid double call to os.lstat.
---
 dulwich/index.py | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/dulwich/index.py b/dulwich/index.py
index 1984453..f8245d1 100644
--- a/dulwich/index.py
+++ b/dulwich/index.py
@@ -421,9 +421,10 @@ def build_file_from_blob(blob, mode, target_path, honor_filemode=True):
     :param target_path: Path to write to
     :param honor_filemode: An optional flag to honor core.filemode setting in
         config file, default is core.filemode=True, change executable bit
+    :return: stat object for the file
     """
     try:
-        oldstat = os.stat(target_path)
+        oldstat = os.lstat(target_path)
     except OSError as e:
         if e.errno == errno.ENOENT:
             oldstat = None
@@ -439,7 +440,7 @@ def build_file_from_blob(blob, mode, target_path, honor_filemode=True):
         if oldstat is not None and oldstat.st_size == len(contents):
             with open(target_path, 'rb') as f:
                 if f.read() == contents:
-                    return
+                    return oldstat
 
         with open(target_path, 'wb') as f:
             # Write out file
@@ -448,6 +449,8 @@ def build_file_from_blob(blob, mode, target_path, honor_filemode=True):
         if honor_filemode:
             os.chmod(target_path, mode)
 
+    return os.lstat(target_path)
+
 
 INVALID_DOTNAMES = (b".git", b".", b"..", b"")
 
@@ -508,12 +511,12 @@ def build_index_from_tree(root_path, index_path, object_store, tree_id,
         # FIXME: Merge new index into working tree
         if S_ISGITLINK(entry.mode):
             os.mkdir(full_path)
+            st = os.lstat(full_path)
         else:
             obj = object_store[entry.sha]
-            build_file_from_blob(obj, entry.mode, full_path,
+            st = build_file_from_blob(obj, entry.mode, full_path,
                 honor_filemode=honor_filemode)
         # Add file to index
-        st = os.lstat(full_path)
         if not honor_filemode or S_ISGITLINK(entry.mode):
             # we can not use tuple slicing to build a new tuple,
             # because on windows that will convert the times to

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/dulwich.git



More information about the Python-modules-commits mailing list