瀏覽代碼

Avoid useless write and file stats change #479

Avoid writing file when no change happen and so writing file without modification will change file stats  #479
Benoît HERVIER 8 年之前
父節點
當前提交
b8232bf9ed
共有 1 個文件被更改,包括 5 次插入0 次删除
  1. 5 0
      dulwich/index.py

+ 5 - 0
dulwich/index.py

@@ -434,6 +434,11 @@ def build_file_from_blob(blob, mode, target_path, honor_filemode=True):
             else:
                 raise
     else:
+        if os.path.exists(target_path):
+            with open(target_path, 'rb') as f:
+                if f.read() == blob.as_raw_string():
+                    return
+
         with open(target_path, 'wb') as f:
             # Write out file
             f.write(blob.as_raw_string())