archive: pass thru mtime for directory archives, like other archive types do
authorJames May <james.may@draeger.com>
Fri, 01 Dec 2017 17:39:21 +1100
changeset 35202 760fef6aca74
parent 35201 ec71518acd4a
child 35203 4ee493ea1c13
archive: pass thru mtime for directory archives, like other archive types do Without this files in the output archive directory have their mtimes set to whatever time they were written their. This is in this inconsistent with the other archivers, eg. zip, which use exactly the same time for all files. Works on my machine (Windows), but I don't have a *nix box available to run anything more thorough, unfortunately.
mercurial/archival.py
--- a/mercurial/archival.py	Fri Dec 01 20:33:02 2017 +0800
+++ b/mercurial/archival.py	Fri Dec 01 17:39:21 2017 +1100
@@ -262,6 +262,7 @@
     def __init__(self, name, mtime):
         self.basedir = name
         self.opener = vfsmod.vfs(self.basedir)
+        self.mtime = mtime
 
     def addfile(self, name, mode, islink, data):
         if islink:
@@ -272,6 +273,8 @@
         f.close()
         destfile = os.path.join(self.basedir, name)
         os.chmod(destfile, mode)
+        if self.mtime is not None:
+            os.utime(destfile, (self.mtime, self.mtime))
 
     def done(self):
         pass
@@ -299,7 +302,12 @@
 
     matchfn is function to filter names of files to write to archive.
 
-    prefix is name of path to put before every archive member.'''
+    prefix is name of path to put before every archive member.
+
+    mtime is the modified time, in seconds, or None to use the changeset time.
+
+    subrepos tells whether to include subrepos.
+    '''
 
     if kind == 'files':
         if prefix: