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 years ago
parent
commit
b8232bf9ed
1 changed files with 5 additions and 0 deletions
  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:
             else:
                 raise
                 raise
     else:
     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:
         with open(target_path, 'wb') as f:
             # Write out file
             # Write out file
             f.write(blob.as_raw_string())
             f.write(blob.as_raw_string())