[merge] make "bzr testament" work with unicode commit messages
John A Meinel
john at arbash-meinel.com
Sun Feb 12 23:23:41 GMT 2006
Marien Zwart wrote:
> Currently "bzr testament" explodes with a UnicodeDecodeError if you
> committed something with a non-ascii character in the commit message.
> I have a branch from bzr.dev available at
> http://mzz.mine.nu/bzr/bzr.dev which fixes this, adds a tests, and
> cleans up an unnecessary function.
>
> I am pretty sure the effect of the fix is ok, since it makes the
> function do what the docstring says it does. If the fix is not
> thorough enough or should be done in a different way please let me
> know.
>
> $ bzr diff
> === modified file 'bzrlib/testament.py'
> --- bzrlib/testament.py
> +++ bzrlib/testament.py
> @@ -114,8 +114,7 @@
> hashed in that encoding.
> """
> r = []
> - def a(s):
> - r.append(s)
> + a = r.append
> a('bazaar-ng testament version 1\n')
> a('revision-id: %s\n' % self.revision_id)
> a('committer: %s\n' % self.committer)
> @@ -137,7 +136,7 @@
> for l in r:
> assert isinstance(l, basestring), \
> '%r of type %s is not a plain string' % (l, type(l))
> - return r
> + return [line.encode('utf-8') for line in r]
>
> def _escape_path(self, path):
> assert not contains_linebreaks(path)
>
> === modified file 'bzrlib/tests/test_testament.py'
> --- bzrlib/tests/test_testament.py
> +++ bzrlib/tests/test_testament.py
> @@ -118,6 +118,16 @@
> t = Testament.from_revision(self.b.repository, 'test at user-3')
> self.assertEqualDiff(t.as_text(), REV_PROPS_TESTAMENT)
>
> + def test_testament_unicode_commit_message(self):
> + self.b.working_tree().commit(
> + message=u'non-ascii commit \N{COPYRIGHT SIGN} me',
> + timestamp=1129025493,
> + timezone=36000,
> + rev_id='test at user-3',
> + committer='test at user')
> + t = Testament.from_revision(self.b.repository, 'test at user-3')
> + self.assertEqualDiff(t.as_text(), REV_UNICODE_COMMIT_TESTAMENT)
> +
> def test___init__(self):
> revision = self.b.repository.get_revision('test at user-2')
> inventory = self.b.repository.get_inventory('test at user-2')
> @@ -220,3 +230,22 @@
> branch-nick:
> test branch
> """
> +
> +REV_UNICODE_COMMIT_TESTAMENT = u"""\
> +bazaar-ng testament version 1
> +revision-id: test at user-3
> +committer: test at user
> +timestamp: 1129025493
> +timezone: 36000
> +parents:
> + test at user-2
> +message:
> + non-ascii commit \N{COPYRIGHT SIGN} me
> +inventory:
> + file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73
> + directory src src-id
> + file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24
> +properties:
> + branch-nick:
> + test branch
> +""".encode('utf-8')
You really need 2 spaces before the REV_UNICODE_COMMIT_TESTAMENT. but
otherwise it looks good. We can clean up the whitespace when merging. +1
from me.
John
=:->
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 249 bytes
Desc: OpenPGP digital signature
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20060212/7455520d/attachment.pgp
More information about the bazaar
mailing list