[PATCH] Use shutil.copystat in copyfile()

Will Maier willmaier at ml1.net
Mon Feb 9 09:50:00 CST 2009


Hi folks-

The patch below causes util.copyfile() to use shutil.copystat()
instead of simply shutil.copymode(). In addition to the source
file's mode, this ensures that the dest has the correct mtime and
atime. 

I think this is probably a Good Thing in general, though I
particularly noticed the old behavior when interactively recording
hunks in a file that I also had open in vim. When the record
extension copied the file under review to and from the temp area, it
updated the mtime, causing vim to think that the file had been
changed. This seems like the wrong behavior because record doesn't
change the file under review at all.

With this change, vim doesn't complain when a user records hunks
while the editor has an open buffer for the file under review. This
change also didn't cause any test failures on my system
(OpenBSD/i386), which suggests that nobody had made assumptions
about the old behavior.

thanks!

1 file changed, 2 insertions(+), 2 deletions(-)
mercurial/util.py |    4 ++--


# HG changeset patch
# User Will Maier <willmaier at ml1.net>
# Date 1234187742 21600
# Node ID e196b90c7032f6e9b51cbabaf72b6d208b0db845
# Parent  5aca12729a0dda97231a5450d586809797cafc7d
Use shutil.copystat in copyfile().

diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -757,7 +757,7 @@
         pass
 
 def copyfile(src, dest):
-    "copy a file, preserving mode"
+    "copy a file, preserving mode and atime/mtime"
     if os.path.islink(src):
         try:
             os.unlink(dest)
@@ -767,7 +767,7 @@
     else:
         try:
             shutil.copyfile(src, dest)
-            shutil.copymode(src, dest)
+            shutil.copystat(src, dest)
         except shutil.Error, inst:
             raise Abort(str(inst))
 

-- 

[Will Maier]-----------------[willmaier at ml1.net|http://www.lfod.us/]


More information about the Mercurial-devel mailing list