Rev 4997: Set the file mtime when exporting to a directory to prevent triggering make rebuilds unnecessarily. in http://bazaar.launchpad.net/~lifeless/bzr/bug-515631

Robert Collins robertc at robertcollins.net
Mon Feb 1 22:22:38 GMT 2010


At http://bazaar.launchpad.net/~lifeless/bzr/bug-515631

------------------------------------------------------------
revno: 4997
revision-id: robertc at robertcollins.net-20100201222228-qr97l7uuwn84zisn
parent: pqm at pqm.ubuntu.com-20100201135324-cuhuolr97guf5xjp
fixes bug(s): https://launchpad.net/bugs/515631
committer: Robert Collins <robertc at robertcollins.net>
branch nick: bug-515631
timestamp: Tue 2010-02-02 09:22:28 +1100
message:
  Set the file mtime when exporting to a directory to prevent triggering make rebuilds unnecessarily.
=== modified file 'NEWS'
--- a/NEWS	2010-02-01 11:40:56 +0000
+++ b/NEWS	2010-02-01 22:22:28 +0000
@@ -25,6 +25,10 @@
 * Fix "AttributeError in Inter1and2Helper" during fetch.
   (Martin Pool, #513432)
 
+* Set the mtime of files exported to a directory by ``bzr export`` all to
+  the same value to avoid confusing ``make`` and other date-based build
+  systems. (Robert Collins, #515631)
+
 Improvements
 ************
 

=== modified file 'bzrlib/export/dir_exporter.py'
--- a/bzrlib/export/dir_exporter.py	2009-12-18 05:38:40 +0000
+++ b/bzrlib/export/dir_exporter.py	2010-02-01 22:22:28 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 2005, 2009 Canonical Ltd
+# Copyright (C) 2005, 2009-2010 Canonical Ltd
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -14,12 +14,12 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
-"""Export a Tree to a non-versioned directory.
-"""
+"""Export a bzrlib.tree.Tree to a new or empty directory."""
 
 import errno
 import os
 import StringIO
+import time
 
 from bzrlib import errors, osutils
 from bzrlib.export import _export_iter_entries
@@ -33,14 +33,11 @@
 def dir_exporter(tree, dest, root, subdir, filtered=False):
     """Export this tree to a new directory.
 
-    `dest` should not exist, and will be created holding the
-    contents of this tree.
-
-    TODO: To handle subdirectories we need to create the
-           directories first.
+    `dest` should either not exist or should be empty. If it does not exist it
+    will be created holding the contents of this tree.
 
     :note: If the export fails, the destination directory will be
-           left in a half-assed state.
+           left in an incompletely exported state: export is not transactional.
     """
     mutter('export version %r', tree)
     try:
@@ -79,6 +76,7 @@
     # The data returned here can be in any order, but we've already created all
     # the directories
     flags = os.O_CREAT | os.O_TRUNC | os.O_WRONLY | getattr(os, 'O_BINARY', 0)
+    now = time.time()
     for (relpath, executable), chunks in tree.iter_files_bytes(to_fetch):
         if filtered:
             filters = tree._content_filter_stack(relpath)
@@ -94,3 +92,4 @@
             out.writelines(chunks)
         finally:
             out.close()
+        os.utime(fullpath, (now, now))

=== modified file 'bzrlib/tests/test_export.py'
--- a/bzrlib/tests/test_export.py	2009-07-29 13:46:55 +0000
+++ b/bzrlib/tests/test_export.py	2010-02-01 22:22:28 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 2009 Canonical Ltd
+# Copyright (C) 2009-2010 Canonical Ltd
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
 import os
-
+import time
 
 from bzrlib import (
     errors,
@@ -62,3 +62,30 @@
         wt.commit('1')
         self.build_tree(['target/', 'target/foo'])
         self.assertRaises(errors.BzrError, export.export, wt, 'target', format="dir")
+
+    def test_dir_export_files_same_timestamp(self):
+        builder = self.make_branch_builder('source')
+        builder.start_series()
+        builder.build_snapshot(None, None, [
+            ('add', ('', 'root-id', 'directory', '')),
+            ('add', ('a', 'a-id', 'file', 'content\n'))])
+        builder.build_snapshot(None, None, [
+            ('add', ('b', 'b-id', 'file', 'content\n'))])
+        builder.finish_series()
+        b = builder.get_branch()
+        b.lock_read()
+        self.addCleanup(b.unlock)
+        tree = b.basis_tree()
+        orig_iter_files_bytes = tree.iter_files_bytes
+        # Make iter_files_bytes slower, so we provoke mtime skew
+        def iter_files_bytes(to_fetch):
+            for thing in orig_iter_files_bytes(to_fetch):
+                yield thing
+                time.sleep(1)
+        tree.iter_files_bytes = iter_files_bytes
+        export.export(tree, 'target', format='dir')
+        t = self.get_transport('target')
+        st_a = t.stat('a')
+        st_b = t.stat('b')
+        # All files must be given the same mtime.
+        self.assertEqual(st_a.st_mtime, st_b.st_mtime)




More information about the bazaar-commits mailing list