Merge lp:~jelmer/brz/change-editor-consistent into lp:brz
- change-editor-consistent
- Merge into trunk
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 | ||||
Related bugs: |
|
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
The Breezy Bot (the-breezy-bot) wrote : | # |
Merging failed
https:/
Revision history for this message
The Breezy Bot (the-breezy-bot) wrote : | # |
Running landing tests failed
https:/
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 | 6571 | editor program to decide what the file remaining in the working copy | 6571 | editor program to decide what the file remaining in the working copy |
6 | 6572 | should look like. To do this, add the configuration option | 6572 | should look like. To do this, add the configuration option |
7 | 6573 | 6573 | ||
9 | 6574 | change_editor = PROGRAM @new_path @old_path | 6574 | change_editor = PROGRAM {new_path} {old_path} |
10 | 6575 | 6575 | ||
13 | 6576 | where @new_path is replaced with the path of the new version of the | 6576 | where {new_path} is replaced with the path of the new version of the |
14 | 6577 | file and @old_path is replaced with the path of the old version of | 6577 | file and {old_path} is replaced with the path of the old version of |
15 | 6578 | the file. The PROGRAM should save the new file with the desired | 6578 | the file. The PROGRAM should save the new file with the desired |
16 | 6579 | contents of the file in the working tree. | 6579 | contents of the file in the working tree. |
17 | 6580 | 6580 | ||
18 | 6581 | 6581 | ||
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 | 91 | 91 | ||
24 | 92 | from breezy import ( | 92 | from breezy import ( |
25 | 93 | atomicfile, | 93 | atomicfile, |
26 | 94 | cmdline, | ||
27 | 94 | controldir, | 95 | controldir, |
28 | 95 | debug, | 96 | debug, |
29 | 96 | directory_service, | 97 | directory_service, |
30 | @@ -328,6 +329,11 @@ | |||
31 | 328 | cmd = self._get_change_editor() | 329 | cmd = self._get_change_editor() |
32 | 329 | if cmd is None: | 330 | if cmd is None: |
33 | 330 | return None | 331 | return None |
34 | 332 | cmd = cmd.replace('@old_path', '{old_path}') | ||
35 | 333 | cmd = cmd.replace('@new_path', '{new_path}') | ||
36 | 334 | cmd = cmdline.split(cmd) | ||
37 | 335 | if '{old_path}' not in cmd: | ||
38 | 336 | cmd.extend(['{old_path}', '{new_path}']) | ||
39 | 331 | return diff.DiffFromTool.from_string(cmd, old_tree, new_tree, | 337 | return diff.DiffFromTool.from_string(cmd, old_tree, new_tree, |
40 | 332 | sys.stdout) | 338 | sys.stdout) |
41 | 333 | 339 | ||
42 | @@ -831,7 +837,7 @@ | |||
43 | 831 | return POLICY_NONE | 837 | return POLICY_NONE |
44 | 832 | 838 | ||
45 | 833 | def _get_change_editor(self): | 839 | def _get_change_editor(self): |
47 | 834 | return self.get_user_option('change_editor') | 840 | return self.get_user_option('change_editor', expand=False) |
48 | 835 | 841 | ||
49 | 836 | def _get_signature_checking(self): | 842 | def _get_signature_checking(self): |
50 | 837 | """See Config._get_signature_checking.""" | 843 | """See Config._get_signature_checking.""" |
51 | 838 | 844 | ||
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 | 19 | import difflib | 19 | import difflib |
57 | 20 | import os | 20 | import os |
58 | 21 | import re | 21 | import re |
59 | 22 | import string | ||
60 | 23 | import sys | 22 | import sys |
61 | 24 | 23 | ||
62 | 25 | from .lazy_import import lazy_import | 24 | from .lazy_import import lazy_import |
63 | @@ -30,7 +29,6 @@ | |||
64 | 30 | import tempfile | 29 | import tempfile |
65 | 31 | 30 | ||
66 | 32 | from breezy import ( | 31 | from breezy import ( |
67 | 33 | cmdline, | ||
68 | 34 | controldir, | 32 | controldir, |
69 | 35 | errors, | 33 | errors, |
70 | 36 | osutils, | 34 | osutils, |
71 | @@ -54,12 +52,6 @@ | |||
72 | 54 | DEFAULT_CONTEXT_AMOUNT = 3 | 52 | DEFAULT_CONTEXT_AMOUNT = 3 |
73 | 55 | 53 | ||
74 | 56 | 54 | ||
75 | 57 | class AtTemplate(string.Template): | ||
76 | 58 | """Templating class that uses @ instead of $.""" | ||
77 | 59 | |||
78 | 60 | delimiter = '@' | ||
79 | 61 | |||
80 | 62 | |||
81 | 63 | # TODO: Rather than building a changeset object, we should probably | 55 | # TODO: Rather than building a changeset object, we should probably |
82 | 64 | # invoke callbacks on an object. That object can either accumulate a | 56 | # invoke callbacks on an object. That object can either accumulate a |
83 | 65 | # list, write them out directly, etc etc. | 57 | # list, write them out directly, etc etc. |
84 | @@ -790,11 +782,8 @@ | |||
85 | 790 | self._root = osutils.mkdtemp(prefix='brz-diff-') | 782 | self._root = osutils.mkdtemp(prefix='brz-diff-') |
86 | 791 | 783 | ||
87 | 792 | @classmethod | 784 | @classmethod |
89 | 793 | def from_string(klass, command_string, old_tree, new_tree, to_file, | 785 | def from_string(klass, command_template, old_tree, new_tree, to_file, |
90 | 794 | path_encoding='utf-8'): | 786 | path_encoding='utf-8'): |
91 | 795 | command_template = cmdline.split(command_string) | ||
92 | 796 | if '@' not in command_string: | ||
93 | 797 | command_template.extend(['@old_path', '@new_path']) | ||
94 | 798 | return klass(command_template, old_tree, new_tree, to_file, | 787 | return klass(command_template, old_tree, new_tree, to_file, |
95 | 799 | path_encoding) | 788 | path_encoding) |
96 | 800 | 789 | ||
97 | @@ -810,7 +799,7 @@ | |||
98 | 810 | 799 | ||
99 | 811 | def _get_command(self, old_path, new_path): | 800 | def _get_command(self, old_path, new_path): |
100 | 812 | my_map = {'old_path': old_path, 'new_path': new_path} | 801 | my_map = {'old_path': old_path, 'new_path': new_path} |
102 | 813 | command = [AtTemplate(t).substitute(my_map) for t in | 802 | command = [t.format(**my_map) for t in |
103 | 814 | self.command_template] | 803 | self.command_template] |
104 | 815 | if sys.platform == 'win32': # Popen doesn't accept unicode on win32 | 804 | if sys.platform == 'win32': # Popen doesn't accept unicode on win32 |
105 | 816 | command_encoded = [] | 805 | command_encoded = [] |
106 | 817 | 806 | ||
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 | 191 | [DEFAULT] | 191 | [DEFAULT] |
112 | 192 | email=Erik B\u00e5gfors <erik@bagfors.nu> | 192 | email=Erik B\u00e5gfors <erik@bagfors.nu> |
113 | 193 | editor=vim | 193 | editor=vim |
115 | 194 | change_editor=vimdiff -of @new_path @old_path | 194 | change_editor=vimdiff -of {new_path} {old_path} |
116 | 195 | gpg_signing_key=DD4D5088 | 195 | gpg_signing_key=DD4D5088 |
117 | 196 | log_format=short | 196 | log_format=short |
118 | 197 | validate_signatures_in_log=true | 197 | validate_signatures_in_log=true |
119 | @@ -395,6 +395,7 @@ | |||
120 | 395 | super(InstrumentedConfig, self).__init__() | 395 | super(InstrumentedConfig, self).__init__() |
121 | 396 | self._calls = [] | 396 | self._calls = [] |
122 | 397 | self._signatures = config.CHECK_NEVER | 397 | self._signatures = config.CHECK_NEVER |
123 | 398 | self._change_editor = 'vimdiff -fo {new_path} {old_path}' | ||
124 | 398 | 399 | ||
125 | 399 | def _get_user_id(self): | 400 | def _get_user_id(self): |
126 | 400 | self._calls.append('_get_user_id') | 401 | self._calls.append('_get_user_id') |
127 | @@ -406,7 +407,7 @@ | |||
128 | 406 | 407 | ||
129 | 407 | def _get_change_editor(self): | 408 | def _get_change_editor(self): |
130 | 408 | self._calls.append('_get_change_editor') | 409 | self._calls.append('_get_change_editor') |
132 | 409 | return 'vimdiff -fo @new_path @old_path' | 410 | return self._change_editor |
133 | 410 | 411 | ||
134 | 411 | 412 | ||
135 | 412 | bool_config = b"""[DEFAULT] | 413 | bool_config = b"""[DEFAULT] |
136 | @@ -514,7 +515,28 @@ | |||
137 | 514 | change_editor = my_config.get_change_editor('old_tree', 'new_tree') | 515 | change_editor = my_config.get_change_editor('old_tree', 'new_tree') |
138 | 515 | self.assertEqual(['_get_change_editor'], my_config._calls) | 516 | self.assertEqual(['_get_change_editor'], my_config._calls) |
139 | 516 | self.assertIs(diff.DiffFromTool, change_editor.__class__) | 517 | self.assertIs(diff.DiffFromTool, change_editor.__class__) |
141 | 517 | self.assertEqual(['vimdiff', '-fo', '@new_path', '@old_path'], | 518 | self.assertEqual(['vimdiff', '-fo', '{new_path}', '{old_path}'], |
142 | 519 | change_editor.command_template) | ||
143 | 520 | |||
144 | 521 | def test_get_change_editor_implicit_args(self): | ||
145 | 522 | # If there are no substitution variables, then assume the | ||
146 | 523 | # old and new path are the last arguments. | ||
147 | 524 | my_config = InstrumentedConfig() | ||
148 | 525 | my_config._change_editor = 'vimdiff -o' | ||
149 | 526 | change_editor = my_config.get_change_editor('old_tree', 'new_tree') | ||
150 | 527 | self.assertEqual(['_get_change_editor'], my_config._calls) | ||
151 | 528 | self.assertIs(diff.DiffFromTool, change_editor.__class__) | ||
152 | 529 | self.assertEqual(['vimdiff', '-o', '{old_path}', '{new_path}'], | ||
153 | 530 | change_editor.command_template) | ||
154 | 531 | |||
155 | 532 | def test_get_change_editor_old_style(self): | ||
156 | 533 | # Test the old style format for the change_editor setting. | ||
157 | 534 | my_config = InstrumentedConfig() | ||
158 | 535 | my_config._change_editor = 'vimdiff -o @old_path @new_path' | ||
159 | 536 | change_editor = my_config.get_change_editor('old_tree', 'new_tree') | ||
160 | 537 | self.assertEqual(['_get_change_editor'], my_config._calls) | ||
161 | 538 | self.assertIs(diff.DiffFromTool, change_editor.__class__) | ||
162 | 539 | self.assertEqual(['vimdiff', '-o', '{old_path}', '{new_path}'], | ||
163 | 518 | change_editor.command_template) | 540 | change_editor.command_template) |
164 | 519 | 541 | ||
165 | 520 | 542 | ||
166 | @@ -1101,7 +1123,7 @@ | |||
167 | 1101 | my_config = self._get_sample_config() | 1123 | my_config = self._get_sample_config() |
168 | 1102 | change_editor = my_config.get_change_editor('old', 'new') | 1124 | change_editor = my_config.get_change_editor('old', 'new') |
169 | 1103 | self.assertIs(diff.DiffFromTool, change_editor.__class__) | 1125 | self.assertIs(diff.DiffFromTool, change_editor.__class__) |
171 | 1104 | self.assertEqual('vimdiff -of @new_path @old_path', | 1126 | self.assertEqual('vimdiff -of {new_path} {old_path}', |
172 | 1105 | ' '.join(change_editor.command_template)) | 1127 | ' '.join(change_editor.command_template)) |
173 | 1106 | 1128 | ||
174 | 1107 | def test_get_no_change_editor(self): | 1129 | def test_get_no_change_editor(self): |
175 | 1108 | 1130 | ||
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 | 867 | class TestDiffFromTool(tests.TestCaseWithTransport): | 867 | class TestDiffFromTool(tests.TestCaseWithTransport): |
181 | 868 | 868 | ||
182 | 869 | def test_from_string(self): | 869 | def test_from_string(self): |
184 | 870 | diff_obj = diff.DiffFromTool.from_string('diff', None, None, None) | 870 | diff_obj = diff.DiffFromTool.from_string( |
185 | 871 | ['diff', '{old_path}', '{new_path}'], | ||
186 | 872 | None, None, None) | ||
187 | 871 | self.addCleanup(diff_obj.finish) | 873 | self.addCleanup(diff_obj.finish) |
189 | 872 | self.assertEqual(['diff', '@old_path', '@new_path'], | 874 | self.assertEqual(['diff', '{old_path}', '{new_path}'], |
190 | 873 | diff_obj.command_template) | 875 | diff_obj.command_template) |
191 | 874 | 876 | ||
192 | 875 | def test_from_string_u5(self): | 877 | def test_from_string_u5(self): |
195 | 876 | diff_obj = diff.DiffFromTool.from_string('diff "-u 5"', | 878 | diff_obj = diff.DiffFromTool.from_string( |
196 | 877 | None, None, None) | 879 | ['diff', "-u 5", '{old_path}', '{new_path}'], None, None, None) |
197 | 878 | self.addCleanup(diff_obj.finish) | 880 | self.addCleanup(diff_obj.finish) |
199 | 879 | self.assertEqual(['diff', '-u 5', '@old_path', '@new_path'], | 881 | self.assertEqual(['diff', '-u 5', '{old_path}', '{new_path}'], |
200 | 880 | diff_obj.command_template) | 882 | diff_obj.command_template) |
201 | 881 | self.assertEqual(['diff', '-u 5', 'old-path', 'new-path'], | 883 | self.assertEqual(['diff', '-u 5', 'old-path', 'new-path'], |
202 | 882 | diff_obj._get_command('old-path', 'new-path')) | 884 | diff_obj._get_command('old-path', 'new-path')) |
203 | 883 | 885 | ||
204 | 884 | def test_from_string_path_with_backslashes(self): | 886 | def test_from_string_path_with_backslashes(self): |
205 | 885 | self.requireFeature(features.backslashdir_feature) | 887 | self.requireFeature(features.backslashdir_feature) |
207 | 886 | tool = 'C:\\Tools\\Diff.exe' | 888 | tool = ['C:\\Tools\\Diff.exe', '{old_path}', '{new_path}'] |
208 | 887 | diff_obj = diff.DiffFromTool.from_string(tool, None, None, None) | 889 | diff_obj = diff.DiffFromTool.from_string(tool, None, None, None) |
209 | 888 | self.addCleanup(diff_obj.finish) | 890 | self.addCleanup(diff_obj.finish) |
211 | 889 | self.assertEqual(['C:\\Tools\\Diff.exe', '@old_path', '@new_path'], | 891 | self.assertEqual(['C:\\Tools\\Diff.exe', '{old_path}', '{new_path}'], |
212 | 890 | diff_obj.command_template) | 892 | diff_obj.command_template) |
213 | 891 | self.assertEqual(['C:\\Tools\\Diff.exe', 'old-path', 'new-path'], | 893 | self.assertEqual(['C:\\Tools\\Diff.exe', 'old-path', 'new-path'], |
214 | 892 | diff_obj._get_command('old-path', 'new-path')) | 894 | diff_obj._get_command('old-path', 'new-path')) |
215 | @@ -894,7 +896,7 @@ | |||
216 | 894 | def test_execute(self): | 896 | def test_execute(self): |
217 | 895 | output = BytesIO() | 897 | output = BytesIO() |
218 | 896 | diff_obj = diff.DiffFromTool([sys.executable, '-c', | 898 | diff_obj = diff.DiffFromTool([sys.executable, '-c', |
220 | 897 | 'print("@old_path @new_path")'], | 899 | 'print("{old_path} {new_path}")'], |
221 | 898 | None, None, output) | 900 | None, None, output) |
222 | 899 | self.addCleanup(diff_obj.finish) | 901 | self.addCleanup(diff_obj.finish) |
223 | 900 | diff_obj._execute('old', 'new') | 902 | diff_obj._execute('old', 'new') |
224 | @@ -922,7 +924,7 @@ | |||
225 | 922 | basis_tree.lock_read() | 924 | basis_tree.lock_read() |
226 | 923 | self.addCleanup(basis_tree.unlock) | 925 | self.addCleanup(basis_tree.unlock) |
227 | 924 | diff_obj = diff.DiffFromTool([sys.executable, '-c', | 926 | diff_obj = diff.DiffFromTool([sys.executable, '-c', |
229 | 925 | 'print "@old_path @new_path"'], | 927 | 'print "{old_path} {new_path}"'], |
230 | 926 | basis_tree, tree, output) | 928 | basis_tree, tree, output) |
231 | 927 | diff_obj._prepare_files('file', 'file', file_id=b'file-id') | 929 | diff_obj._prepare_files('file', 'file', file_id=b'file-id') |
232 | 928 | # The old content should be readonly | 930 | # The old content should be readonly |
233 | @@ -958,7 +960,7 @@ | |||
234 | 958 | tree.lock_read() | 960 | tree.lock_read() |
235 | 959 | self.addCleanup(tree.unlock) | 961 | self.addCleanup(tree.unlock) |
236 | 960 | diff_obj = diff.DiffFromTool([sys.executable, '-c', | 962 | diff_obj = diff.DiffFromTool([sys.executable, '-c', |
238 | 961 | 'print "@old_path @new_path"'], | 963 | 'print "{old_path} {new_path}"'], |
239 | 962 | old_tree, tree, output) | 964 | old_tree, tree, output) |
240 | 963 | self.addCleanup(diff_obj.finish) | 965 | self.addCleanup(diff_obj.finish) |
241 | 964 | self.assertContainsRe(diff_obj._root, 'brz-diff-[^/]*') | 966 | self.assertContainsRe(diff_obj._root, 'brz-diff-[^/]*') |
242 | @@ -980,7 +982,7 @@ | |||
243 | 980 | def test_encodable_filename(self): | 982 | def test_encodable_filename(self): |
244 | 981 | # Just checks file path for external diff tool. | 983 | # Just checks file path for external diff tool. |
245 | 982 | # We cannot change CPython's internal encoding used by os.exec*. | 984 | # We cannot change CPython's internal encoding used by os.exec*. |
247 | 983 | diffobj = diff.DiffFromTool(['dummy', '@old_path', '@new_path'], | 985 | diffobj = diff.DiffFromTool(['dummy', '{old_path}', '{new_path}'], |
248 | 984 | None, None, None) | 986 | None, None, None) |
249 | 985 | for _, scenario in EncodingAdapter.encoding_scenarios: | 987 | for _, scenario in EncodingAdapter.encoding_scenarios: |
250 | 986 | encoding = scenario['encoding'] | 988 | encoding = scenario['encoding'] |
251 | @@ -995,7 +997,7 @@ | |||
252 | 995 | self.assertTrue(fullpath.startswith(diffobj._root + '/safe')) | 997 | self.assertTrue(fullpath.startswith(diffobj._root + '/safe')) |
253 | 996 | 998 | ||
254 | 997 | def test_unencodable_filename(self): | 999 | def test_unencodable_filename(self): |
256 | 998 | diffobj = diff.DiffFromTool(['dummy', '@old_path', '@new_path'], | 1000 | diffobj = diff.DiffFromTool(['dummy', '{old_path}', '{new_path}'], |
257 | 999 | None, None, None) | 1001 | None, None, None) |
258 | 1000 | for _, scenario in EncodingAdapter.encoding_scenarios: | 1002 | for _, scenario in EncodingAdapter.encoding_scenarios: |
259 | 1001 | encoding = scenario['encoding'] | 1003 | encoding = scenario['encoding'] |
260 | 1002 | 1004 | ||
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 | 54 | * Automatically upgrade to branch format 8 when setting branch references. | 54 | * Automatically upgrade to branch format 8 when setting branch references. |
266 | 55 | (Jelmer Vernooij) | 55 | (Jelmer Vernooij) |
267 | 56 | 56 | ||
268 | 57 | * The substitution variables for the ``change_editor`` configuration | ||
269 | 58 | option are now "{old_path}" and "{new_path}" rather than "@old_path" and | ||
270 | 59 | "@new_path". The former is more consistent with the way substitutions | ||
271 | 60 | work in other configuration options. The old syntax is still supported. | ||
272 | 61 | (Jelmer Vernooij, #708718) | ||
273 | 62 | |||
274 | 57 | * The ``brz inventory`` command now accepts a ``--include-root`` | 63 | * The ``brz inventory`` command now accepts a ``--include-root`` |
275 | 58 | argument to show the tree root. (Jelmer Vernooij) | 64 | argument to show the tree root. (Jelmer Vernooij) |
276 | 59 | 65 |
Makes sense, thanks!