Patchwork archive: pass thru mtime for directory archives, like the other archive types do

login
register
mail settings
Submitter James May
Date Dec. 1, 2017, 6:41 a.m.
Message ID <b7a1f6fbfe150ab776c2.1512110491@LAU0719.mshome.net>
Download mbox | patch
Permalink /patch/25866/
State Accepted
Headers show

Comments

James May - Dec. 1, 2017, 6:41 a.m.
# HG changeset patch
# User James May <james.may@draeger.com>
# Date 1512110361 -39600
#      Fri Dec 01 17:39:21 2017 +1100
# Node ID b7a1f6fbfe150ab776c2cb48c120aab97f6d7e7f
# Parent  6864c405f0235d5c42937658049f0405d5d1abdc
archive: pass thru mtime for directory archives, like the 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 avaialble to run
anything more thourugh, unfortunately.
Yuya Nishihara - Dec. 3, 2017, 6:57 a.m.
On Fri, 1 Dec 2017 17:41:31 +1100, James May wrote:
> # HG changeset patch
> # User James May <james.may@draeger.com>
> # Date 1512110361 -39600
> #      Fri Dec 01 17:39:21 2017 +1100
> # Node ID b7a1f6fbfe150ab776c2cb48c120aab97f6d7e7f
> # Parent  6864c405f0235d5c42937658049f0405d5d1abdc
> archive: pass thru mtime for directory archives, like the 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 avaialble to run
> anything more thourugh, unfortunately.

Makes sense. Queued, thanks.

Patch

diff -r 6864c405f023 -r b7a1f6fbfe15 mercurial/archival.py
--- a/mercurial/archival.py	Thu Nov 30 22:32:13 2017 +0900
+++ 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,11 @@ 
 
     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:
--- This communication contains confidential information. If you are not the intended recipient please return this email to the sender and delete it from your records. Diese Nachricht enthaelt vertrauliche Informationen. Sollten Sie nicht der beabsichtigte Empfaenger dieser E-mail sein, senden Sie bitte diese an den Absender zurueck und loeschen Sie die E-mail aus Ihrem System.