Merge lp:~anj/bzr-keywords/fix-505038 into lp:bzr-keywords

Proposed by Andrew Johnson
Status: Merged
Approved by: Jelmer Vernooij
Approved revision: 18
Merged at revision: 17
Proposed branch: lp:~anj/bzr-keywords/fix-505038
Merge into: lp:bzr-keywords
Diff against target: 72 lines (+14/-6)
2 files modified
__init__.py (+12/-5)
tests/test_conversion.py (+2/-1)
To merge this branch: bzr merge lp:~anj/bzr-keywords/fix-505038
Reviewer Review Type Date Requested Status
Jelmer Vernooij (community) code Approve
Ian Clatworthy Pending
Review via email: mp+37294@code.launchpad.net

Description of the change

This branch causes the compress_keywords() function to avoid compressing keywords that are not found in the keyword registry. The expand_keywords() code already knows not to touch them. Includes a modification to the test suite.

This fixes bug #505038.

To post a comment you must log in.
lp:~anj/bzr-keywords/fix-505038 updated
18. By Andrew Johnson

Fix help text to match.

Revision history for this message
Jelmer Vernooij (jelmer) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file '__init__.py'
--- __init__.py 2009-04-06 22:40:14 +0000
+++ __init__.py 2010-10-01 19:46:11 +0000
@@ -31,8 +31,7 @@
3131
32When expanding, the existing text is retained if an unknown keyword is32When expanding, the existing text is retained if an unknown keyword is
33found. If the keyword is already expanded but known, the value is replaced.33found. If the keyword is already expanded but known, the value is replaced.
34When compressing, values are always removed, whether the keyword is known34When compressing, the values of known keywords are removed.
35or not.
3635
37Keyword filtering needs to be enabled for selected branches and files via36Keyword filtering needs to be enabled for selected branches and files via
38rules. See ``bzr help rules`` for general information on defining rules.37rules. See ``bzr help rules`` for general information on defining rules.
@@ -262,10 +261,13 @@
262 return ""261 return ""
263262
264263
265def compress_keywords(s):264def compress_keywords(s, keyword_dicts):
266 """Replace cooked style keywords with raw style in a string.265 """Replace cooked style keywords with raw style in a string.
267 266
267 Note: If the keyword is not known, the text is not modified.
268
268 :param s: the string269 :param s: the string
270 :param keyword_dicts: an iterable of keyword dictionaries.
269 :return: the string with keywords compressed271 :return: the string with keywords compressed
270 """272 """
271 _raw_style = _keyword_style_registry.get('raw')273 _raw_style = _keyword_style_registry.get('raw')
@@ -277,7 +279,12 @@
277 break279 break
278 result += rest[:match.start()]280 result += rest[:match.start()]
279 keyword = match.group(1)281 keyword = match.group(1)
280 result += _raw_style % {'name': keyword}282 expansion = _get_from_dicts(keyword_dicts, keyword)
283 if expansion is None:
284 # Unknown expansion - leave as is
285 result += match.group(0)
286 else:
287 result += _raw_style % {'name': keyword}
281 rest = rest[match.end():]288 rest = rest[match.end():]
282 return result + rest289 return result + rest
283290
@@ -351,7 +358,7 @@
351def _kw_compressor(chunks, context=None):358def _kw_compressor(chunks, context=None):
352 """Filter that replaces keywords with their compressed form."""359 """Filter that replaces keywords with their compressed form."""
353 text = ''.join(chunks)360 text = ''.join(chunks)
354 return [compress_keywords(text)]361 return [compress_keywords(text, [keyword_registry])]
355362
356363
357def _kw_expander(chunks, context, encoder=None):364def _kw_expander(chunks, context, encoder=None):
358365
=== modified file 'tests/test_conversion.py'
--- tests/test_conversion.py 2008-07-27 13:04:54 +0000
+++ tests/test_conversion.py 2010-10-01 19:46:11 +0000
@@ -34,6 +34,7 @@
34 ('$Foo$$Bar$', '$Foo: FOO! $$Bar: bar $'),34 ('$Foo$$Bar$', '$Foo: FOO! $$Bar: bar $'),
35 ('abc $Foo$ xyz $Bar$ qwe', 'abc $Foo: FOO! $ xyz $Bar: bar $ qwe'),35 ('abc $Foo$ xyz $Bar$ qwe', 'abc $Foo: FOO! $ xyz $Bar: bar $ qwe'),
36 ('$Unknown$$Bar$', '$Unknown$$Bar: bar $'),36 ('$Unknown$$Bar$', '$Unknown$$Bar: bar $'),
37 ('$Unknown: unkn $$Bar$', '$Unknown: unkn $$Bar: bar $'),
37 ('$Foo$$Unknown$', '$Foo: FOO! $$Unknown$'),38 ('$Foo$$Unknown$', '$Foo: FOO! $$Unknown$'),
38 ('$CallMe$', '$CallMe: now! $'),39 ('$CallMe$', '$CallMe: now! $'),
39 ]40 ]
@@ -44,7 +45,7 @@
44 def test_compression(self):45 def test_compression(self):
45 # Test keyword expansion46 # Test keyword expansion
46 for raw, cooked in _samples:47 for raw, cooked in _samples:
47 self.assertEqual(raw, compress_keywords(cooked))48 self.assertEqual(raw, compress_keywords(cooked, [_keywords]))
4849
49 def test_expansion(self):50 def test_expansion(self):
50 # Test keyword expansion51 # Test keyword expansion

Subscribers

People subscribed via source and target branches