Rev 3159: diff --using uses symlinks if possible, in file:///home/pqm/archives/thelove/bzr/%2Btrunk/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Thu Jan 3 16:01:15 GMT 2008
At file:///home/pqm/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 3159
revision-id:pqm at pqm.ubuntu.com-20080103160106-v6qfwv4ta8sorx1q
parent: pqm at pqm.ubuntu.com-20080103103822-fj2udnviy9ilfsst
parent: abentley at panoramicfeedback.com-20071227153722-elvg2skfwd3vorbq
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Thu 2008-01-03 16:01:06 +0000
message:
diff --using uses symlinks if possible,
marks temp files read-only (abentley)
modified:
bzrlib/diff.py diff.py-20050309040759-26944fbbf2ebbf36
bzrlib/tests/test_diff.py testdiff.py-20050727164403-d1a3496ebb12e339
------------------------------------------------------------
revno: 3123.4.1.1.8
revision-id:abentley at panoramicfeedback.com-20071227153722-elvg2skfwd3vorbq
parent: abentley at panoramicfeedback.com-20071227153207-h4wh0zkuwlhjhnl8
committer: Aaron Bentley <abentley at panoramicfeedback.com>
branch nick: no-inventory2
timestamp: Thu 2007-12-27 10:37:22 -0500
message:
Us osutils.rmtree instead of shutil.rmtree, now that some files are readonly
modified:
bzrlib/diff.py diff.py-20050309040759-26944fbbf2ebbf36
------------------------------------------------------------
revno: 3123.4.1.1.7
revision-id:abentley at panoramicfeedback.com-20071227153207-h4wh0zkuwlhjhnl8
parent: abentley at panoramicfeedback.com-20071227152145-sg5pv77kbulraxve
committer: Aaron Bentley <abentley at panoramicfeedback.com>
branch nick: no-inventory2
timestamp: Thu 2007-12-27 10:32:07 -0500
message:
Mark temporary files read-only
modified:
bzrlib/diff.py diff.py-20050309040759-26944fbbf2ebbf36
------------------------------------------------------------
revno: 3123.4.1.1.6
revision-id:abentley at panoramicfeedback.com-20071227152145-sg5pv77kbulraxve
parent: abentley at panoramicfeedback.com-20071227151103-s6vuss3n63b6933a
committer: Aaron Bentley <abentley at panoramicfeedback.com>
branch nick: no-inventory2
timestamp: Thu 2007-12-27 10:21:45 -0500
message:
Use relpath for get_file
modified:
bzrlib/diff.py diff.py-20050309040759-26944fbbf2ebbf36
------------------------------------------------------------
revno: 3123.4.1.1.5
revision-id:abentley at panoramicfeedback.com-20071227151103-s6vuss3n63b6933a
parent: abentley at panoramicfeedback.com-20071227144939-ubtewvnji522xtxk
committer: Aaron Bentley <abentley at panoramicfeedback.com>
branch nick: no-inventory2
timestamp: Thu 2007-12-27 10:11:03 -0500
message:
Symlink to real files if possible
modified:
bzrlib/diff.py diff.py-20050309040759-26944fbbf2ebbf36
bzrlib/tests/test_diff.py testdiff.py-20050727164403-d1a3496ebb12e339
------------------------------------------------------------
revno: 3123.4.1.1.4
revision-id:abentley at panoramicfeedback.com-20071227144939-ubtewvnji522xtxk
parent: aaron.bentley at utoronto.ca-20071227022814-e1ance6116xmbmqk
committer: Aaron Bentley <abentley at panoramicfeedback.com>
branch nick: no-inventory2
timestamp: Thu 2007-12-27 09:49:39 -0500
message:
Set mtime (and atime) on files for --using
modified:
bzrlib/diff.py diff.py-20050309040759-26944fbbf2ebbf36
bzrlib/tests/test_diff.py testdiff.py-20050727164403-d1a3496ebb12e339
=== modified file 'bzrlib/diff.py'
--- a/bzrlib/diff.py 2007-12-28 16:52:08 +0000
+++ b/bzrlib/diff.py 2008-01-03 16:01:06 +0000
@@ -785,24 +785,40 @@
self.to_file.write(proc.stdout.read())
return proc.wait()
- def _write_file(self, file_id, tree, prefix, old_path):
- full_old_path = osutils.pathjoin(self._root, prefix, old_path)
- parent_dir = osutils.dirname(full_old_path)
+ def _try_symlink_root(self, tree, prefix):
+ if not (getattr(tree, 'abspath', None) is not None
+ and osutils.has_symlinks()):
+ return False
+ try:
+ os.symlink(tree.abspath(''), osutils.pathjoin(self._root, prefix))
+ except OSError, e:
+ if e.errno != errno.EEXIST:
+ raise
+ return True
+
+ def _write_file(self, file_id, tree, prefix, relpath):
+ full_path = osutils.pathjoin(self._root, prefix, relpath)
+ if self._try_symlink_root(tree, prefix):
+ return full_path
+ parent_dir = osutils.dirname(full_path)
try:
os.makedirs(parent_dir)
except OSError, e:
if e.errno != errno.EEXIST:
raise
- source = tree.get_file(file_id)
+ source = tree.get_file(file_id, relpath)
try:
- target = open(full_old_path, 'wb')
+ target = open(full_path, 'wb')
try:
osutils.pumpfile(source, target)
finally:
target.close()
finally:
source.close()
- return full_old_path
+ osutils.make_readonly(full_path)
+ mtime = tree.get_file_mtime(file_id)
+ os.utime(full_path, (mtime, mtime))
+ return full_path
def _prepare_files(self, file_id, old_path, new_path):
old_disk_path = self._write_file(file_id, self.old_tree, 'old',
@@ -812,7 +828,7 @@
return old_disk_path, new_disk_path
def finish(self):
- shutil.rmtree(self._root)
+ osutils.rmtree(self._root)
def diff(self, file_id, old_path, new_path, old_kind, new_kind):
if (old_kind, new_kind) != ('file', 'file'):
=== modified file 'bzrlib/tests/test_diff.py'
--- a/bzrlib/tests/test_diff.py 2007-12-28 16:37:46 +0000
+++ b/bzrlib/tests/test_diff.py 2008-01-03 16:01:06 +0000
@@ -15,6 +15,7 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
import os
+import os.path
from cStringIO import StringIO
import errno
import subprocess
@@ -1270,13 +1271,16 @@
def test_prepare_files(self):
output = StringIO()
tree = self.make_branch_and_tree('tree')
- self.build_tree_contents([('tree/file', 'oldcontent')])
- tree.add('file', 'file-id')
- tree.commit('old tree')
- self.build_tree_contents([('tree/file', 'newcontent')])
+ self.build_tree_contents([('tree/oldname', 'oldcontent')])
+ tree.add('oldname', 'file-id')
+ tree.commit('old tree', timestamp=0)
+ tree.rename_one('oldname', 'newname')
+ self.build_tree_contents([('tree/newname', 'newcontent')])
old_tree = tree.basis_tree()
old_tree.lock_read()
self.addCleanup(old_tree.unlock)
+ tree.lock_read()
+ self.addCleanup(tree.unlock)
diff_obj = DiffFromTool(['python', '-c',
'print "%(old_path)s %(new_path)s"'],
old_tree, tree, output)
@@ -1285,8 +1289,11 @@
old_path, new_path = diff_obj._prepare_files('file-id', 'oldname',
'newname')
self.assertContainsRe(old_path, 'old/oldname$')
+ self.assertEqual(0, os.stat(old_path).st_mtime)
self.assertContainsRe(new_path, 'new/newname$')
self.assertFileEqual('oldcontent', old_path)
self.assertFileEqual('newcontent', new_path)
+ if osutils.has_symlinks():
+ self.assertTrue(os.path.samefile('tree/newname', new_path))
# make sure we can create files with the same parent directories
diff_obj._prepare_files('file-id', 'oldname2', 'newname2')
More information about the bazaar-commits
mailing list