Merge lp:~garyvdm/bzr/extdiff-no-tmp-for-wt into lp:bzr

Proposed by Gary van der Merwe
Status: Merged
Approved by: Martin Pool
Approved revision: not available
Merged at revision: not available
Proposed branch: lp:~garyvdm/bzr/extdiff-no-tmp-for-wt
Merge into: lp:bzr
Diff against target: 65 lines (+15/-4)
3 files modified
NEWS (+6/-0)
bzrlib/diff.py (+8/-3)
bzrlib/tests/test_diff.py (+1/-1)
To merge this branch: bzr merge lp:~garyvdm/bzr/extdiff-no-tmp-for-wt
Reviewer Review Type Date Requested Status
Martin Pool Approve
John A Meinel Approve
Review via email: mp+15592@code.launchpad.net

This proposal supersedes a proposal from 2009-12-01.

To post a comment you must log in.
Revision history for this message
Gary van der Merwe (garyvdm) wrote : Posted in a previous version of this proposal

This patch changes bzr behaviour when launching a external diff tool via bzr diff --using. If the file is from a working tree, it does not create a temporary file, rather, it just passes the path to that file in the working tree. This saves writing the file to the disk, but more importantly, allows one to edit the file in diff tools that allow editing, such as meld.

Revision history for this message
Martin Pool (mbp) wrote : Posted in a previous version of this proposal

That's a very nice improvement, and very simple. I recall someone saying there were complications, but if this works for at least some cases, that's great.

review: Approve
Revision history for this message
John A Meinel (jameinel) wrote : Posted in a previous version of this proposal

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Martin Pool wrote:
> Review: Approve
> That's a very nice improvement, and very simple. I recall someone saying there were complications, but if this works for at least some cases, that's great.

It seems to ignore the "force_temp" flag. Would it be better to have:

if not force_temp and isinstance(tree, WorkingTree):
?

John
=:->

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAksVlkcACgkQJdeBCYSNAAORBQCfUKV3Lq1vMuwIBBPGqvp5CD4o
QesAoMVWF+iWA/qqufVMN/xKivyZlTLr
=L/NR
-----END PGP SIGNATURE-----

Revision history for this message
Gary van der Merwe (garyvdm) wrote :

Gary van der Merwe wrote on 2009-12-01

> This patch changes bzr behaviour when launching a external diff tool via bzr
> diff --using. If the file is from a working tree, it does not create a
> temporary file, rather, it just passes the path to that file in the working
> tree. This saves writing the file to the disk, but more importantly, allows
> one to edit the file in diff tools that allow editing, such as meld.

This will now still write the temp file if force_temp is true. There are no tests for this, but it currently is not used from anywhere.

Revision history for this message
John A Meinel (jameinel) wrote :

This seems better than what we currently have. So we should merge it as is.

What about deleted files, though?

Also, self._execute looks like it is using relative paths. Do you know if this still works if you are in a subdir of the working tree, etc?

review: Approve
Revision history for this message
Martin Pool (mbp) :
review: Approve
Revision history for this message
Martin Pool (mbp) wrote :

sent to pqm

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'NEWS'
2--- NEWS 2009-12-03 02:24:54 +0000
3+++ NEWS 2009-12-03 07:40:28 +0000
4@@ -57,6 +57,12 @@
5 new rich-root heads. This can cut a conversion time in half (mysql from
6 13.5h => 6.2h) (John Arbash Meinel, #487632)
7
8+* When launching a external diff tool via bzr diff --using, temporary files
9+ are no longer created, rather, the path to the file in the working tree is
10+ passed to the external diff tool. This allows the file to be edited if the
11+ diff tool provides for this. (Gary van der Merwe, #490738)
12+
13+
14 Improvements
15 ************
16
17
18=== modified file 'bzrlib/diff.py'
19--- bzrlib/diff.py 2009-11-03 01:15:09 +0000
20+++ bzrlib/diff.py 2009-12-03 07:40:28 +0000
21@@ -39,6 +39,8 @@
22 timestamp,
23 views,
24 )
25+
26+from bzrlib.workingtree import WorkingTree
27 """)
28
29 from bzrlib.symbol_versioning import (
30@@ -722,6 +724,9 @@
31
32 def _write_file(self, file_id, tree, prefix, relpath, force_temp=False,
33 allow_write=False):
34+ if not force_temp and isinstance(tree, WorkingTree):
35+ return tree.abspath(tree.id2path(file_id))
36+
37 full_path = osutils.pathjoin(self._root, prefix, relpath)
38 if not force_temp and self._try_symlink_root(tree, prefix):
39 return full_path
40@@ -766,9 +771,9 @@
41 def diff(self, file_id, old_path, new_path, old_kind, new_kind):
42 if (old_kind, new_kind) != ('file', 'file'):
43 return DiffPath.CANNOT_DIFF
44- self._prepare_files(file_id, old_path, new_path)
45- self._execute(osutils.pathjoin('old', old_path),
46- osutils.pathjoin('new', new_path))
47+ (old_disk_path, new_disk_path) = self._prepare_files(
48+ file_id, old_path, new_path)
49+ self._execute(old_disk_path, new_disk_path)
50
51 def edit_file(self, file_id):
52 """Use this tool to edit a file.
53
54=== modified file 'bzrlib/tests/test_diff.py'
55--- bzrlib/tests/test_diff.py 2009-10-31 01:16:23 +0000
56+++ bzrlib/tests/test_diff.py 2009-12-03 07:40:28 +0000
57@@ -1378,7 +1378,7 @@
58 'newname')
59 self.assertContainsRe(old_path, 'old/oldname$')
60 self.assertEqual(0, os.stat(old_path).st_mtime)
61- self.assertContainsRe(new_path, 'new/newname$')
62+ self.assertContainsRe(new_path, 'tree/newname$')
63 self.assertFileEqual('oldcontent', old_path)
64 self.assertFileEqual('newcontent', new_path)
65 if osutils.host_os_dereferences_symlinks():