Merge lp:~gz/bzr-builddeb/decode_changelog_for_commit_message_853664 into lp:bzr-builddeb

Proposed by Martin Packman
Status: Merged
Approved by: Jelmer Vernooij
Approved revision: 616
Merged at revision: 618
Proposed branch: lp:~gz/bzr-builddeb/decode_changelog_for_commit_message_853664
Merge into: lp:bzr-builddeb
Diff against target: 64 lines (+36/-1)
3 files modified
__init__.py (+2/-1)
tests/blackbox/test_builddeb.py (+21/-0)
tests/test_commit_message.py (+13/-0)
To merge this branch: bzr merge lp:~gz/bzr-builddeb/decode_changelog_for_commit_message_853664
Reviewer Review Type Date Requested Status
Jelmer Vernooij Approve
Review via email: mp+77578@code.launchpad.net

Description of the change

This branch makes builddeb set the commit message correctly again from non-ascii debian/changelog files.

With Bazaar 2.4 there's a new hook to specify the commit message fully rather than just using a template, which builddeb takes advantage of when it's available. The old template hook point expects a byte string, and decodes the result from the user encoding. The new hook point doesn't do any decoding so returning non-ascii bytes results in bzr internals complaining.

According to Debian Policy, "The entire changelog must be encoded in UTF-8." so it should be safe to just decode without need for any fancy error handling:
<http://www.debian.org/doc/debian-policy/ch-source.html#s-dpkgchangelog>

Note the old hook is actually subtly broken, it relies on the program being run in a locale with a UTF-8 encoding or it would break (but in an obvious and fixable way, so it's not that important).

To post a comment you must log in.
Revision history for this message
Jelmer Vernooij (jelmer) wrote :

urgh, I cry every time I see the two space indentation..

Thanks for the fix.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '__init__.py'
2--- __init__.py 2011-06-24 11:37:57 +0000
3+++ __init__.py 2011-09-29 17:56:29 +0000
4@@ -123,7 +123,8 @@
5 bugs_fixed = find_bugs_fixed([changes], commit.work_tree.branch)
6 commit.builder._revprops["bugs"] = "\n".join(bugs_fixed)
7
8- return debian_changelog_commit_message(commit, start_message)
9+ # Debian Policy Manual states that debian/changelog must be UTF-8
10+ return changes.decode("utf-8")
11
12
13 def changelog_merge_hook_factory(merger):
14
15=== modified file 'tests/blackbox/test_builddeb.py'
16--- tests/blackbox/test_builddeb.py 2011-07-19 15:35:48 +0000
17+++ tests/blackbox/test_builddeb.py 2011-09-29 17:56:29 +0000
18@@ -171,4 +171,25 @@
19 self.assertPathExists('pre-export')
20 self.assertInBuildDir(['pre-build', 'post-build'])
21
22+ def test_utf8_changelog(self):
23+ from bzrlib.plugins import builddeb
24+ from bzrlib.msgeditor import hooks
25+ if "set_commit_message" not in hooks:
26+ self.skip("No set_commit_message hook in bzrlib this old")
27+ hooks.install_named_hook("set_commit_message",
28+ builddeb.debian_changelog_commit, "Test builddeb set commit msg hook")
29+ tree = self.make_unpacked_source()
30+ # The changelog is only used for commit message when it already exists and
31+ # is then changed, so need to clear it, commit, then set the contents.
32+ open("debian/changelog", "w").close()
33+ tree.commit("Prepare for release", rev_id="prerel")
34+ c = self.make_changelog()
35+ c.add_change("")
36+ c.add_change(" * \xe2\x80\xa6and another thing")
37+ self.write_changelog(c, "debian/changelog")
38+ self.run_bzr(['commit'])
39+ branch = tree.branch
40+ self.assertEqual(u"* test build\n* \u2026and another thing\n",
41+ branch.repository.get_revision(branch.last_revision()).message)
42+
43 # vim: ts=2 sts=2 sw=2
44
45=== modified file 'tests/test_commit_message.py'
46--- tests/test_commit_message.py 2011-06-13 23:01:14 +0000
47+++ tests/test_commit_message.py 2011-09-29 17:56:29 +0000
48@@ -115,3 +115,16 @@
49 self.assertEqual(commit.builder._revprops,
50 {'bugs': 'https://launchpad.net/bugs/1234 fixed\n'
51 'https://launchpad.net/bugs/4321 fixed'})
52+
53+ def test_set_message_returns_unicode(self):
54+ wt = self.make_branch_and_tree(".")
55+ self.build_tree(['a', 'debian/', 'debian/changelog'])
56+ wt.add(['debian/', 'debian/changelog'])
57+ wt.commit("one")
58+ self.set_changelog_content(" * \xe2\x80\xa6real fix this time\n")
59+ wt.add(['a'])
60+ wt.lock_read()
61+ self.addCleanup(wt.unlock)
62+ commit = self._Commit(wt)
63+ self.assertEqual(debian_changelog_commit(commit, None),
64+ u"\u2026real fix this time\n")

Subscribers

People subscribed via source and target branches