Browse Source

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 năm trước cách đây
mục cha
commit
b8232bf9ed
1 tập tin đã thay đổi với 5 bổ sung0 xóa
  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())