Rev 4997: (robertc) Set the file mtime when exporting to a directory to prevent in file:///home/pqm/archives/thelove/bzr/%2Btrunk/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Tue Feb 2 01:34:27 GMT 2010
At file:///home/pqm/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 4997 [merge]
revision-id: pqm at pqm.ubuntu.com-20100202013426-w1l8pu1pq8bn7o5s
parent: pqm at pqm.ubuntu.com-20100201135324-cuhuolr97guf5xjp
parent: robertc at robertcollins.net-20100201222228-qr97l7uuwn84zisn
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Tue 2010-02-02 01:34:26 +0000
message:
(robertc) Set the file mtime when exporting to a directory to prevent
triggering make rebuilds unnecessarily. Bug 515631. (Robert Collins)
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/export/dir_exporter.py dir_exporter.py-20051114235828-b51397f56bc7b117
bzrlib/tests/test_export.py test_export.py-20090220201010-tpbxssdnezsvu9pk-1
=== 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