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
=== modified file 'breezy/builtins.py'
--- breezy/builtins.py 2019-06-29 09:30:39 +0000
+++ breezy/builtins.py 2019-07-07 17:32:39 +0000
@@ -6571,10 +6571,10 @@
6571 editor program to decide what the file remaining in the working copy6571 editor program to decide what the file remaining in the working copy
6572 should look like. To do this, add the configuration option6572 should look like. To do this, add the configuration option
65736573
6574 change_editor = PROGRAM @new_path @old_path6574 change_editor = PROGRAM {new_path} {old_path}
65756575
6576 where @new_path is replaced with the path of the new version of the6576 where {new_path} is replaced with the path of the new version of the
6577 file and @old_path is replaced with the path of the old version of6577 file and {old_path} is replaced with the path of the old version of
6578 the file. The PROGRAM should save the new file with the desired6578 the file. The PROGRAM should save the new file with the desired
6579 contents of the file in the working tree.6579 contents of the file in the working tree.
65806580
65816581
=== modified file 'breezy/config.py'
--- breezy/config.py 2019-06-22 11:51:56 +0000
+++ breezy/config.py 2019-07-07 17:32:39 +0000
@@ -91,6 +91,7 @@
9191
92from breezy import (92from breezy import (
93 atomicfile,93 atomicfile,
94 cmdline,
94 controldir,95 controldir,
95 debug,96 debug,
96 directory_service,97 directory_service,
@@ -328,6 +329,11 @@
328 cmd = self._get_change_editor()329 cmd = self._get_change_editor()
329 if cmd is None:330 if cmd is None:
330 return None331 return None
332 cmd = cmd.replace('@old_path', '{old_path}')
333 cmd = cmd.replace('@new_path', '{new_path}')
334 cmd = cmdline.split(cmd)
335 if '{old_path}' not in cmd:
336 cmd.extend(['{old_path}', '{new_path}'])
331 return diff.DiffFromTool.from_string(cmd, old_tree, new_tree,337 return diff.DiffFromTool.from_string(cmd, old_tree, new_tree,
332 sys.stdout)338 sys.stdout)
333339
@@ -831,7 +837,7 @@
831 return POLICY_NONE837 return POLICY_NONE
832838
833 def _get_change_editor(self):839 def _get_change_editor(self):
834 return self.get_user_option('change_editor')840 return self.get_user_option('change_editor', expand=False)
835841
836 def _get_signature_checking(self):842 def _get_signature_checking(self):
837 """See Config._get_signature_checking."""843 """See Config._get_signature_checking."""
838844
=== modified file 'breezy/diff.py'
--- breezy/diff.py 2019-06-15 17:53:40 +0000
+++ breezy/diff.py 2019-07-07 17:32:39 +0000
@@ -19,7 +19,6 @@
19import difflib19import difflib
20import os20import os
21import re21import re
22import string
23import sys22import sys
2423
25from .lazy_import import lazy_import24from .lazy_import import lazy_import
@@ -30,7 +29,6 @@
30import tempfile29import tempfile
3130
32from breezy import (31from breezy import (
33 cmdline,
34 controldir,32 controldir,
35 errors,33 errors,
36 osutils,34 osutils,
@@ -54,12 +52,6 @@
54DEFAULT_CONTEXT_AMOUNT = 352DEFAULT_CONTEXT_AMOUNT = 3
5553
5654
57class AtTemplate(string.Template):
58 """Templating class that uses @ instead of $."""
59
60 delimiter = '@'
61
62
63# TODO: Rather than building a changeset object, we should probably55# TODO: Rather than building a changeset object, we should probably
64# invoke callbacks on an object. That object can either accumulate a56# invoke callbacks on an object. That object can either accumulate a
65# list, write them out directly, etc etc.57# list, write them out directly, etc etc.
@@ -790,11 +782,8 @@
790 self._root = osutils.mkdtemp(prefix='brz-diff-')782 self._root = osutils.mkdtemp(prefix='brz-diff-')
791783
792 @classmethod784 @classmethod
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,
794 path_encoding='utf-8'):786 path_encoding='utf-8'):
795 command_template = cmdline.split(command_string)
796 if '@' not in command_string:
797 command_template.extend(['@old_path', '@new_path'])
798 return klass(command_template, old_tree, new_tree, to_file,787 return klass(command_template, old_tree, new_tree, to_file,
799 path_encoding)788 path_encoding)
800789
@@ -810,7 +799,7 @@
810799
811 def _get_command(self, old_path, new_path):800 def _get_command(self, old_path, new_path):
812 my_map = {'old_path': old_path, 'new_path': new_path}801 my_map = {'old_path': old_path, 'new_path': new_path}
813 command = [AtTemplate(t).substitute(my_map) for t in802 command = [t.format(**my_map) for t in
814 self.command_template]803 self.command_template]
815 if sys.platform == 'win32': # Popen doesn't accept unicode on win32804 if sys.platform == 'win32': # Popen doesn't accept unicode on win32
816 command_encoded = []805 command_encoded = []
817806
=== modified file 'breezy/tests/test_config.py'
--- breezy/tests/test_config.py 2019-06-16 01:03:51 +0000
+++ breezy/tests/test_config.py 2019-07-07 17:32:39 +0000
@@ -191,7 +191,7 @@
191[DEFAULT]191[DEFAULT]
192email=Erik B\u00e5gfors <erik@bagfors.nu>192email=Erik B\u00e5gfors <erik@bagfors.nu>
193editor=vim193editor=vim
194change_editor=vimdiff -of @new_path @old_path194change_editor=vimdiff -of {new_path} {old_path}
195gpg_signing_key=DD4D5088195gpg_signing_key=DD4D5088
196log_format=short196log_format=short
197validate_signatures_in_log=true197validate_signatures_in_log=true
@@ -395,6 +395,7 @@
395 super(InstrumentedConfig, self).__init__()395 super(InstrumentedConfig, self).__init__()
396 self._calls = []396 self._calls = []
397 self._signatures = config.CHECK_NEVER397 self._signatures = config.CHECK_NEVER
398 self._change_editor = 'vimdiff -fo {new_path} {old_path}'
398399
399 def _get_user_id(self):400 def _get_user_id(self):
400 self._calls.append('_get_user_id')401 self._calls.append('_get_user_id')
@@ -406,7 +407,7 @@
406407
407 def _get_change_editor(self):408 def _get_change_editor(self):
408 self._calls.append('_get_change_editor')409 self._calls.append('_get_change_editor')
409 return 'vimdiff -fo @new_path @old_path'410 return self._change_editor
410411
411412
412bool_config = b"""[DEFAULT]413bool_config = b"""[DEFAULT]
@@ -514,7 +515,28 @@
514 change_editor = my_config.get_change_editor('old_tree', 'new_tree')515 change_editor = my_config.get_change_editor('old_tree', 'new_tree')
515 self.assertEqual(['_get_change_editor'], my_config._calls)516 self.assertEqual(['_get_change_editor'], my_config._calls)
516 self.assertIs(diff.DiffFromTool, change_editor.__class__)517 self.assertIs(diff.DiffFromTool, change_editor.__class__)
517 self.assertEqual(['vimdiff', '-fo', '@new_path', '@old_path'],518 self.assertEqual(['vimdiff', '-fo', '{new_path}', '{old_path}'],
519 change_editor.command_template)
520
521 def test_get_change_editor_implicit_args(self):
522 # If there are no substitution variables, then assume the
523 # old and new path are the last arguments.
524 my_config = InstrumentedConfig()
525 my_config._change_editor = 'vimdiff -o'
526 change_editor = my_config.get_change_editor('old_tree', 'new_tree')
527 self.assertEqual(['_get_change_editor'], my_config._calls)
528 self.assertIs(diff.DiffFromTool, change_editor.__class__)
529 self.assertEqual(['vimdiff', '-o', '{old_path}', '{new_path}'],
530 change_editor.command_template)
531
532 def test_get_change_editor_old_style(self):
533 # Test the old style format for the change_editor setting.
534 my_config = InstrumentedConfig()
535 my_config._change_editor = 'vimdiff -o @old_path @new_path'
536 change_editor = my_config.get_change_editor('old_tree', 'new_tree')
537 self.assertEqual(['_get_change_editor'], my_config._calls)
538 self.assertIs(diff.DiffFromTool, change_editor.__class__)
539 self.assertEqual(['vimdiff', '-o', '{old_path}', '{new_path}'],
518 change_editor.command_template)540 change_editor.command_template)
519541
520542
@@ -1101,7 +1123,7 @@
1101 my_config = self._get_sample_config()1123 my_config = self._get_sample_config()
1102 change_editor = my_config.get_change_editor('old', 'new')1124 change_editor = my_config.get_change_editor('old', 'new')
1103 self.assertIs(diff.DiffFromTool, change_editor.__class__)1125 self.assertIs(diff.DiffFromTool, change_editor.__class__)
1104 self.assertEqual('vimdiff -of @new_path @old_path',1126 self.assertEqual('vimdiff -of {new_path} {old_path}',
1105 ' '.join(change_editor.command_template))1127 ' '.join(change_editor.command_template))
11061128
1107 def test_get_no_change_editor(self):1129 def test_get_no_change_editor(self):
11081130
=== modified file 'breezy/tests/test_diff.py'
--- breezy/tests/test_diff.py 2019-06-17 23:08:34 +0000
+++ breezy/tests/test_diff.py 2019-07-07 17:32:39 +0000
@@ -867,26 +867,28 @@
867class TestDiffFromTool(tests.TestCaseWithTransport):867class TestDiffFromTool(tests.TestCaseWithTransport):
868868
869 def test_from_string(self):869 def test_from_string(self):
870 diff_obj = diff.DiffFromTool.from_string('diff', None, None, None)870 diff_obj = diff.DiffFromTool.from_string(
871 ['diff', '{old_path}', '{new_path}'],
872 None, None, None)
871 self.addCleanup(diff_obj.finish)873 self.addCleanup(diff_obj.finish)
872 self.assertEqual(['diff', '@old_path', '@new_path'],874 self.assertEqual(['diff', '{old_path}', '{new_path}'],
873 diff_obj.command_template)875 diff_obj.command_template)
874876
875 def test_from_string_u5(self):877 def test_from_string_u5(self):
876 diff_obj = diff.DiffFromTool.from_string('diff "-u 5"',878 diff_obj = diff.DiffFromTool.from_string(
877 None, None, None)879 ['diff', "-u 5", '{old_path}', '{new_path}'], None, None, None)
878 self.addCleanup(diff_obj.finish)880 self.addCleanup(diff_obj.finish)
879 self.assertEqual(['diff', '-u 5', '@old_path', '@new_path'],881 self.assertEqual(['diff', '-u 5', '{old_path}', '{new_path}'],
880 diff_obj.command_template)882 diff_obj.command_template)
881 self.assertEqual(['diff', '-u 5', 'old-path', 'new-path'],883 self.assertEqual(['diff', '-u 5', 'old-path', 'new-path'],
882 diff_obj._get_command('old-path', 'new-path'))884 diff_obj._get_command('old-path', 'new-path'))
883885
884 def test_from_string_path_with_backslashes(self):886 def test_from_string_path_with_backslashes(self):
885 self.requireFeature(features.backslashdir_feature)887 self.requireFeature(features.backslashdir_feature)
886 tool = 'C:\\Tools\\Diff.exe'888 tool = ['C:\\Tools\\Diff.exe', '{old_path}', '{new_path}']
887 diff_obj = diff.DiffFromTool.from_string(tool, None, None, None)889 diff_obj = diff.DiffFromTool.from_string(tool, None, None, None)
888 self.addCleanup(diff_obj.finish)890 self.addCleanup(diff_obj.finish)
889 self.assertEqual(['C:\\Tools\\Diff.exe', '@old_path', '@new_path'],891 self.assertEqual(['C:\\Tools\\Diff.exe', '{old_path}', '{new_path}'],
890 diff_obj.command_template)892 diff_obj.command_template)
891 self.assertEqual(['C:\\Tools\\Diff.exe', 'old-path', 'new-path'],893 self.assertEqual(['C:\\Tools\\Diff.exe', 'old-path', 'new-path'],
892 diff_obj._get_command('old-path', 'new-path'))894 diff_obj._get_command('old-path', 'new-path'))
@@ -894,7 +896,7 @@
894 def test_execute(self):896 def test_execute(self):
895 output = BytesIO()897 output = BytesIO()
896 diff_obj = diff.DiffFromTool([sys.executable, '-c',898 diff_obj = diff.DiffFromTool([sys.executable, '-c',
897 'print("@old_path @new_path")'],899 'print("{old_path} {new_path}")'],
898 None, None, output)900 None, None, output)
899 self.addCleanup(diff_obj.finish)901 self.addCleanup(diff_obj.finish)
900 diff_obj._execute('old', 'new')902 diff_obj._execute('old', 'new')
@@ -922,7 +924,7 @@
922 basis_tree.lock_read()924 basis_tree.lock_read()
923 self.addCleanup(basis_tree.unlock)925 self.addCleanup(basis_tree.unlock)
924 diff_obj = diff.DiffFromTool([sys.executable, '-c',926 diff_obj = diff.DiffFromTool([sys.executable, '-c',
925 'print "@old_path @new_path"'],927 'print "{old_path} {new_path}"'],
926 basis_tree, tree, output)928 basis_tree, tree, output)
927 diff_obj._prepare_files('file', 'file', file_id=b'file-id')929 diff_obj._prepare_files('file', 'file', file_id=b'file-id')
928 # The old content should be readonly930 # The old content should be readonly
@@ -958,7 +960,7 @@
958 tree.lock_read()960 tree.lock_read()
959 self.addCleanup(tree.unlock)961 self.addCleanup(tree.unlock)
960 diff_obj = diff.DiffFromTool([sys.executable, '-c',962 diff_obj = diff.DiffFromTool([sys.executable, '-c',
961 'print "@old_path @new_path"'],963 'print "{old_path} {new_path}"'],
962 old_tree, tree, output)964 old_tree, tree, output)
963 self.addCleanup(diff_obj.finish)965 self.addCleanup(diff_obj.finish)
964 self.assertContainsRe(diff_obj._root, 'brz-diff-[^/]*')966 self.assertContainsRe(diff_obj._root, 'brz-diff-[^/]*')
@@ -980,7 +982,7 @@
980 def test_encodable_filename(self):982 def test_encodable_filename(self):
981 # Just checks file path for external diff tool.983 # Just checks file path for external diff tool.
982 # We cannot change CPython's internal encoding used by os.exec*.984 # We cannot change CPython's internal encoding used by os.exec*.
983 diffobj = diff.DiffFromTool(['dummy', '@old_path', '@new_path'],985 diffobj = diff.DiffFromTool(['dummy', '{old_path}', '{new_path}'],
984 None, None, None)986 None, None, None)
985 for _, scenario in EncodingAdapter.encoding_scenarios:987 for _, scenario in EncodingAdapter.encoding_scenarios:
986 encoding = scenario['encoding']988 encoding = scenario['encoding']
@@ -995,7 +997,7 @@
995 self.assertTrue(fullpath.startswith(diffobj._root + '/safe'))997 self.assertTrue(fullpath.startswith(diffobj._root + '/safe'))
996998
997 def test_unencodable_filename(self):999 def test_unencodable_filename(self):
998 diffobj = diff.DiffFromTool(['dummy', '@old_path', '@new_path'],1000 diffobj = diff.DiffFromTool(['dummy', '{old_path}', '{new_path}'],
999 None, None, None)1001 None, None, None)
1000 for _, scenario in EncodingAdapter.encoding_scenarios:1002 for _, scenario in EncodingAdapter.encoding_scenarios:
1001 encoding = scenario['encoding']1003 encoding = scenario['encoding']
10021004
=== modified file 'doc/en/release-notes/brz-3.1.txt'
--- doc/en/release-notes/brz-3.1.txt 2019-07-07 16:54:07 +0000
+++ doc/en/release-notes/brz-3.1.txt 2019-07-07 17:32:39 +0000
@@ -54,6 +54,12 @@
54* Automatically upgrade to branch format 8 when setting branch references.54* Automatically upgrade to branch format 8 when setting branch references.
55 (Jelmer Vernooij)55 (Jelmer Vernooij)
5656
57* The substitution variables for the ``change_editor`` configuration
58 option are now "{old_path}" and "{new_path}" rather than "@old_path" and
59 "@new_path". The former is more consistent with the way substitutions
60 work in other configuration options. The old syntax is still supported.
61 (Jelmer Vernooij, #708718)
62
57* The ``brz inventory`` command now accepts a ``--include-root``63* The ``brz inventory`` command now accepts a ``--include-root``
58 argument to show the tree root. (Jelmer Vernooij)64 argument to show the tree root. (Jelmer Vernooij)
5965

Subscribers

People subscribed via source and target branches