Merge lp:~jelmer/brz/change-editor-consistent into lp:brz

Proposed by Jelmer Vernooij
Status: Merged
Approved by: Jelmer Vernooij
Approved revision: no longer in the source branch.
Merge reported by: The Breezy Bot
Merged at revision: not available
Proposed branch: lp:~jelmer/brz/change-editor-consistent
Merge into: lp:brz
Diff against target: 275 lines (+58/-33)
6 files modified
breezy/builtins.py (+3/-3)
breezy/config.py (+7/-1)
breezy/diff.py (+2/-13)
breezy/tests/test_config.py (+26/-4)
breezy/tests/test_diff.py (+14/-12)
doc/en/release-notes/brz-3.1.txt (+6/-0)
To merge this branch: bzr merge lp:~jelmer/brz/change-editor-consistent
Reviewer Review Type Date Requested Status
Martin Packman Approve
Review via email: mp+369364@code.launchpad.net

Commit message

Use standard syntax for the ``change_editor`` configuration option.

Description of the change

Use standard syntax for the ``change_editor`` configuration option.

Use {old_path} and {new_path} rather than @old_path and @new_path.

To post a comment you must log in.
Revision history for this message
Martin Packman (gz) wrote :

Makes sense, thanks!

review: Approve
Revision history for this message
The Breezy Bot (the-breezy-bot) wrote :
Revision history for this message
The Breezy Bot (the-breezy-bot) wrote :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'breezy/builtins.py'
2--- breezy/builtins.py 2019-06-29 09:30:39 +0000
3+++ breezy/builtins.py 2019-07-07 17:32:39 +0000
4@@ -6571,10 +6571,10 @@
5 editor program to decide what the file remaining in the working copy
6 should look like. To do this, add the configuration option
7
8- change_editor = PROGRAM @new_path @old_path
9+ change_editor = PROGRAM {new_path} {old_path}
10
11- where @new_path is replaced with the path of the new version of the
12- file and @old_path is replaced with the path of the old version of
13+ where {new_path} is replaced with the path of the new version of the
14+ file and {old_path} is replaced with the path of the old version of
15 the file. The PROGRAM should save the new file with the desired
16 contents of the file in the working tree.
17
18
19=== modified file 'breezy/config.py'
20--- breezy/config.py 2019-06-22 11:51:56 +0000
21+++ breezy/config.py 2019-07-07 17:32:39 +0000
22@@ -91,6 +91,7 @@
23
24 from breezy import (
25 atomicfile,
26+ cmdline,
27 controldir,
28 debug,
29 directory_service,
30@@ -328,6 +329,11 @@
31 cmd = self._get_change_editor()
32 if cmd is None:
33 return None
34+ cmd = cmd.replace('@old_path', '{old_path}')
35+ cmd = cmd.replace('@new_path', '{new_path}')
36+ cmd = cmdline.split(cmd)
37+ if '{old_path}' not in cmd:
38+ cmd.extend(['{old_path}', '{new_path}'])
39 return diff.DiffFromTool.from_string(cmd, old_tree, new_tree,
40 sys.stdout)
41
42@@ -831,7 +837,7 @@
43 return POLICY_NONE
44
45 def _get_change_editor(self):
46- return self.get_user_option('change_editor')
47+ return self.get_user_option('change_editor', expand=False)
48
49 def _get_signature_checking(self):
50 """See Config._get_signature_checking."""
51
52=== modified file 'breezy/diff.py'
53--- breezy/diff.py 2019-06-15 17:53:40 +0000
54+++ breezy/diff.py 2019-07-07 17:32:39 +0000
55@@ -19,7 +19,6 @@
56 import difflib
57 import os
58 import re
59-import string
60 import sys
61
62 from .lazy_import import lazy_import
63@@ -30,7 +29,6 @@
64 import tempfile
65
66 from breezy import (
67- cmdline,
68 controldir,
69 errors,
70 osutils,
71@@ -54,12 +52,6 @@
72 DEFAULT_CONTEXT_AMOUNT = 3
73
74
75-class AtTemplate(string.Template):
76- """Templating class that uses @ instead of $."""
77-
78- delimiter = '@'
79-
80-
81 # TODO: Rather than building a changeset object, we should probably
82 # invoke callbacks on an object. That object can either accumulate a
83 # list, write them out directly, etc etc.
84@@ -790,11 +782,8 @@
85 self._root = osutils.mkdtemp(prefix='brz-diff-')
86
87 @classmethod
88- def from_string(klass, command_string, old_tree, new_tree, to_file,
89+ def from_string(klass, command_template, old_tree, new_tree, to_file,
90 path_encoding='utf-8'):
91- command_template = cmdline.split(command_string)
92- if '@' not in command_string:
93- command_template.extend(['@old_path', '@new_path'])
94 return klass(command_template, old_tree, new_tree, to_file,
95 path_encoding)
96
97@@ -810,7 +799,7 @@
98
99 def _get_command(self, old_path, new_path):
100 my_map = {'old_path': old_path, 'new_path': new_path}
101- command = [AtTemplate(t).substitute(my_map) for t in
102+ command = [t.format(**my_map) for t in
103 self.command_template]
104 if sys.platform == 'win32': # Popen doesn't accept unicode on win32
105 command_encoded = []
106
107=== modified file 'breezy/tests/test_config.py'
108--- breezy/tests/test_config.py 2019-06-16 01:03:51 +0000
109+++ breezy/tests/test_config.py 2019-07-07 17:32:39 +0000
110@@ -191,7 +191,7 @@
111 [DEFAULT]
112 email=Erik B\u00e5gfors <erik@bagfors.nu>
113 editor=vim
114-change_editor=vimdiff -of @new_path @old_path
115+change_editor=vimdiff -of {new_path} {old_path}
116 gpg_signing_key=DD4D5088
117 log_format=short
118 validate_signatures_in_log=true
119@@ -395,6 +395,7 @@
120 super(InstrumentedConfig, self).__init__()
121 self._calls = []
122 self._signatures = config.CHECK_NEVER
123+ self._change_editor = 'vimdiff -fo {new_path} {old_path}'
124
125 def _get_user_id(self):
126 self._calls.append('_get_user_id')
127@@ -406,7 +407,7 @@
128
129 def _get_change_editor(self):
130 self._calls.append('_get_change_editor')
131- return 'vimdiff -fo @new_path @old_path'
132+ return self._change_editor
133
134
135 bool_config = b"""[DEFAULT]
136@@ -514,7 +515,28 @@
137 change_editor = my_config.get_change_editor('old_tree', 'new_tree')
138 self.assertEqual(['_get_change_editor'], my_config._calls)
139 self.assertIs(diff.DiffFromTool, change_editor.__class__)
140- self.assertEqual(['vimdiff', '-fo', '@new_path', '@old_path'],
141+ self.assertEqual(['vimdiff', '-fo', '{new_path}', '{old_path}'],
142+ change_editor.command_template)
143+
144+ def test_get_change_editor_implicit_args(self):
145+ # If there are no substitution variables, then assume the
146+ # old and new path are the last arguments.
147+ my_config = InstrumentedConfig()
148+ my_config._change_editor = 'vimdiff -o'
149+ change_editor = my_config.get_change_editor('old_tree', 'new_tree')
150+ self.assertEqual(['_get_change_editor'], my_config._calls)
151+ self.assertIs(diff.DiffFromTool, change_editor.__class__)
152+ self.assertEqual(['vimdiff', '-o', '{old_path}', '{new_path}'],
153+ change_editor.command_template)
154+
155+ def test_get_change_editor_old_style(self):
156+ # Test the old style format for the change_editor setting.
157+ my_config = InstrumentedConfig()
158+ my_config._change_editor = 'vimdiff -o @old_path @new_path'
159+ change_editor = my_config.get_change_editor('old_tree', 'new_tree')
160+ self.assertEqual(['_get_change_editor'], my_config._calls)
161+ self.assertIs(diff.DiffFromTool, change_editor.__class__)
162+ self.assertEqual(['vimdiff', '-o', '{old_path}', '{new_path}'],
163 change_editor.command_template)
164
165
166@@ -1101,7 +1123,7 @@
167 my_config = self._get_sample_config()
168 change_editor = my_config.get_change_editor('old', 'new')
169 self.assertIs(diff.DiffFromTool, change_editor.__class__)
170- self.assertEqual('vimdiff -of @new_path @old_path',
171+ self.assertEqual('vimdiff -of {new_path} {old_path}',
172 ' '.join(change_editor.command_template))
173
174 def test_get_no_change_editor(self):
175
176=== modified file 'breezy/tests/test_diff.py'
177--- breezy/tests/test_diff.py 2019-06-17 23:08:34 +0000
178+++ breezy/tests/test_diff.py 2019-07-07 17:32:39 +0000
179@@ -867,26 +867,28 @@
180 class TestDiffFromTool(tests.TestCaseWithTransport):
181
182 def test_from_string(self):
183- diff_obj = diff.DiffFromTool.from_string('diff', None, None, None)
184+ diff_obj = diff.DiffFromTool.from_string(
185+ ['diff', '{old_path}', '{new_path}'],
186+ None, None, None)
187 self.addCleanup(diff_obj.finish)
188- self.assertEqual(['diff', '@old_path', '@new_path'],
189+ self.assertEqual(['diff', '{old_path}', '{new_path}'],
190 diff_obj.command_template)
191
192 def test_from_string_u5(self):
193- diff_obj = diff.DiffFromTool.from_string('diff "-u 5"',
194- None, None, None)
195+ diff_obj = diff.DiffFromTool.from_string(
196+ ['diff', "-u 5", '{old_path}', '{new_path}'], None, None, None)
197 self.addCleanup(diff_obj.finish)
198- self.assertEqual(['diff', '-u 5', '@old_path', '@new_path'],
199+ self.assertEqual(['diff', '-u 5', '{old_path}', '{new_path}'],
200 diff_obj.command_template)
201 self.assertEqual(['diff', '-u 5', 'old-path', 'new-path'],
202 diff_obj._get_command('old-path', 'new-path'))
203
204 def test_from_string_path_with_backslashes(self):
205 self.requireFeature(features.backslashdir_feature)
206- tool = 'C:\\Tools\\Diff.exe'
207+ tool = ['C:\\Tools\\Diff.exe', '{old_path}', '{new_path}']
208 diff_obj = diff.DiffFromTool.from_string(tool, None, None, None)
209 self.addCleanup(diff_obj.finish)
210- self.assertEqual(['C:\\Tools\\Diff.exe', '@old_path', '@new_path'],
211+ self.assertEqual(['C:\\Tools\\Diff.exe', '{old_path}', '{new_path}'],
212 diff_obj.command_template)
213 self.assertEqual(['C:\\Tools\\Diff.exe', 'old-path', 'new-path'],
214 diff_obj._get_command('old-path', 'new-path'))
215@@ -894,7 +896,7 @@
216 def test_execute(self):
217 output = BytesIO()
218 diff_obj = diff.DiffFromTool([sys.executable, '-c',
219- 'print("@old_path @new_path")'],
220+ 'print("{old_path} {new_path}")'],
221 None, None, output)
222 self.addCleanup(diff_obj.finish)
223 diff_obj._execute('old', 'new')
224@@ -922,7 +924,7 @@
225 basis_tree.lock_read()
226 self.addCleanup(basis_tree.unlock)
227 diff_obj = diff.DiffFromTool([sys.executable, '-c',
228- 'print "@old_path @new_path"'],
229+ 'print "{old_path} {new_path}"'],
230 basis_tree, tree, output)
231 diff_obj._prepare_files('file', 'file', file_id=b'file-id')
232 # The old content should be readonly
233@@ -958,7 +960,7 @@
234 tree.lock_read()
235 self.addCleanup(tree.unlock)
236 diff_obj = diff.DiffFromTool([sys.executable, '-c',
237- 'print "@old_path @new_path"'],
238+ 'print "{old_path} {new_path}"'],
239 old_tree, tree, output)
240 self.addCleanup(diff_obj.finish)
241 self.assertContainsRe(diff_obj._root, 'brz-diff-[^/]*')
242@@ -980,7 +982,7 @@
243 def test_encodable_filename(self):
244 # Just checks file path for external diff tool.
245 # We cannot change CPython's internal encoding used by os.exec*.
246- diffobj = diff.DiffFromTool(['dummy', '@old_path', '@new_path'],
247+ diffobj = diff.DiffFromTool(['dummy', '{old_path}', '{new_path}'],
248 None, None, None)
249 for _, scenario in EncodingAdapter.encoding_scenarios:
250 encoding = scenario['encoding']
251@@ -995,7 +997,7 @@
252 self.assertTrue(fullpath.startswith(diffobj._root + '/safe'))
253
254 def test_unencodable_filename(self):
255- diffobj = diff.DiffFromTool(['dummy', '@old_path', '@new_path'],
256+ diffobj = diff.DiffFromTool(['dummy', '{old_path}', '{new_path}'],
257 None, None, None)
258 for _, scenario in EncodingAdapter.encoding_scenarios:
259 encoding = scenario['encoding']
260
261=== modified file 'doc/en/release-notes/brz-3.1.txt'
262--- doc/en/release-notes/brz-3.1.txt 2019-07-07 16:54:07 +0000
263+++ doc/en/release-notes/brz-3.1.txt 2019-07-07 17:32:39 +0000
264@@ -54,6 +54,12 @@
265 * Automatically upgrade to branch format 8 when setting branch references.
266 (Jelmer Vernooij)
267
268+* The substitution variables for the ``change_editor`` configuration
269+ option are now "{old_path}" and "{new_path}" rather than "@old_path" and
270+ "@new_path". The former is more consistent with the way substitutions
271+ work in other configuration options. The old syntax is still supported.
272+ (Jelmer Vernooij, #708718)
273+
274 * The ``brz inventory`` command now accepts a ``--include-root``
275 argument to show the tree root. (Jelmer Vernooij)
276

Subscribers

People subscribed via source and target branches