Merge lp:~parthm/bzr/518609-version-info-unicodedecodeerror into lp:bzr

Proposed by Parth Malwankar
Status: Rejected
Rejected by: Robert Collins
Proposed branch: lp:~parthm/bzr/518609-version-info-unicodedecodeerror
Merge into: lp:bzr
Diff against target: 68 lines (+11/-4)
3 files modified
NEWS (+4/-0)
bzrlib/rio.py (+1/-1)
bzrlib/tests/test_version_info.py (+6/-3)
To merge this branch: bzr merge lp:~parthm/bzr/518609-version-info-unicodedecodeerror
Reviewer Review Type Date Requested Status
Robert Collins (community) Needs Fixing
Review via email: mp+22801@code.launchpad.net

Description of the change

=== Fixes Bug #518609 ===
This fixes unicode handling of 'version-info --include-history'. UnicodeDecodeError exception is not thrown. This was discussed on the mailing list[1].

Stanza.write now uses to_file.write(self.to_unicode()) rather than to_file.writelines(self.to_lines()).

The tests are updated for this. As cStringIO object cannot handle unicode, the impacted tests use StringIO (imported as UnicodeStringIO) to allow writing of unicode. To allow UnicodeStringIO to behave like a file (write unicode, read str), the buffer is encoded as utf-8 on read before being passed to the caller.

Manual testing was done to ensure that unicode messages are shown correctly. E.g.:
< message: (Luk?? Lalinsk?) Add a global write lock for cmd_uncommit (related to #172649)
---
> message: (Lukáš Lalinský) Add a global write lock for cmd_uncommit (related to #172649)

[1] http://article.gmane.org/gmane.comp.version-control.bazaar-ng.general/67403

To post a comment you must log in.
Revision history for this message
Robert Collins (lifeless) wrote :

This really is the wrong approach I think. See the list discussion.

review: Needs Fixing

Unmerged revisions

5131. By Parth Malwankar

updated NEWS

5130. By Parth Malwankar

merged in trunk

5129. By Parth Malwankar

#518609. version-info --include histroy handes unicode.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'NEWS'
2--- NEWS 2010-04-02 15:10:54 +0000
3+++ NEWS 2010-04-05 13:15:31 +0000
4@@ -23,6 +23,10 @@
5 that are not part of the ancestry anymore.
6 (Vincent Ladeuil, #474807)
7
8+* ``version-info --include-history`` handles unicode better and does not
9+ throw UnicodeDecodeError exception.
10+ (Parth Malwankar, #518609)
11+
12 Improvements
13 ************
14
15
16=== modified file 'bzrlib/rio.py'
17--- bzrlib/rio.py 2009-09-11 06:36:50 +0000
18+++ bzrlib/rio.py 2010-04-05 13:15:31 +0000
19@@ -212,7 +212,7 @@
20
21 def write(self, to_file):
22 """Write stanza to a file"""
23- to_file.writelines(self.to_lines())
24+ to_file.write(self.to_unicode())
25
26 def get(self, tag):
27 """Return the value for a field wih given tag.
28
29=== modified file 'bzrlib/tests/test_version_info.py'
30--- bzrlib/tests/test_version_info.py 2010-01-25 17:48:22 +0000
31+++ bzrlib/tests/test_version_info.py 2010-04-05 13:15:31 +0000
32@@ -17,6 +17,7 @@
33 """Tests for version_info"""
34
35 from cStringIO import StringIO
36+from StringIO import StringIO as UnicodeStringIO
37 import imp
38 import os
39 import sys
40@@ -68,11 +69,11 @@
41 wt = self.create_branch()
42
43 def regen(**kwargs):
44- sio = StringIO()
45+ sio = UnicodeStringIO()
46 builder = RioVersionInfoBuilder(wt.branch, working_tree=wt,
47 **kwargs)
48 builder.generate(sio)
49- val = sio.getvalue()
50+ val = sio.getvalue().encode('utf-8')
51 return val
52
53 val = regen()
54@@ -121,11 +122,13 @@
55 wt = self.create_branch()
56
57 def regen(**kwargs):
58- sio = StringIO()
59+ sio = UnicodeStringIO()
60+
61 builder = RioVersionInfoBuilder(wt.branch, working_tree=wt,
62 **kwargs)
63 builder.generate(sio)
64 sio.seek(0)
65+ sio.buf = sio.buf.encode('utf-8')
66 stanzas = list(read_stanzas(sio))
67 self.assertEqual(1, len(stanzas))
68 return stanzas[0]