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
=== modified file '__init__.py'
--- __init__.py 2011-06-24 11:37:57 +0000
+++ __init__.py 2011-09-29 17:56:29 +0000
@@ -123,7 +123,8 @@
123 bugs_fixed = find_bugs_fixed([changes], commit.work_tree.branch)123 bugs_fixed = find_bugs_fixed([changes], commit.work_tree.branch)
124 commit.builder._revprops["bugs"] = "\n".join(bugs_fixed)124 commit.builder._revprops["bugs"] = "\n".join(bugs_fixed)
125125
126 return debian_changelog_commit_message(commit, start_message)126 # Debian Policy Manual states that debian/changelog must be UTF-8
127 return changes.decode("utf-8")
127128
128129
129def changelog_merge_hook_factory(merger):130def changelog_merge_hook_factory(merger):
130131
=== modified file 'tests/blackbox/test_builddeb.py'
--- tests/blackbox/test_builddeb.py 2011-07-19 15:35:48 +0000
+++ tests/blackbox/test_builddeb.py 2011-09-29 17:56:29 +0000
@@ -171,4 +171,25 @@
171 self.assertPathExists('pre-export')171 self.assertPathExists('pre-export')
172 self.assertInBuildDir(['pre-build', 'post-build'])172 self.assertInBuildDir(['pre-build', 'post-build'])
173173
174 def test_utf8_changelog(self):
175 from bzrlib.plugins import builddeb
176 from bzrlib.msgeditor import hooks
177 if "set_commit_message" not in hooks:
178 self.skip("No set_commit_message hook in bzrlib this old")
179 hooks.install_named_hook("set_commit_message",
180 builddeb.debian_changelog_commit, "Test builddeb set commit msg hook")
181 tree = self.make_unpacked_source()
182 # The changelog is only used for commit message when it already exists and
183 # is then changed, so need to clear it, commit, then set the contents.
184 open("debian/changelog", "w").close()
185 tree.commit("Prepare for release", rev_id="prerel")
186 c = self.make_changelog()
187 c.add_change("")
188 c.add_change(" * \xe2\x80\xa6and another thing")
189 self.write_changelog(c, "debian/changelog")
190 self.run_bzr(['commit'])
191 branch = tree.branch
192 self.assertEqual(u"* test build\n* \u2026and another thing\n",
193 branch.repository.get_revision(branch.last_revision()).message)
194
174# vim: ts=2 sts=2 sw=2195# vim: ts=2 sts=2 sw=2
175196
=== modified file 'tests/test_commit_message.py'
--- tests/test_commit_message.py 2011-06-13 23:01:14 +0000
+++ tests/test_commit_message.py 2011-09-29 17:56:29 +0000
@@ -115,3 +115,16 @@
115 self.assertEqual(commit.builder._revprops, 115 self.assertEqual(commit.builder._revprops,
116 {'bugs': 'https://launchpad.net/bugs/1234 fixed\n'116 {'bugs': 'https://launchpad.net/bugs/1234 fixed\n'
117 'https://launchpad.net/bugs/4321 fixed'})117 'https://launchpad.net/bugs/4321 fixed'})
118
119 def test_set_message_returns_unicode(self):
120 wt = self.make_branch_and_tree(".")
121 self.build_tree(['a', 'debian/', 'debian/changelog'])
122 wt.add(['debian/', 'debian/changelog'])
123 wt.commit("one")
124 self.set_changelog_content(" * \xe2\x80\xa6real fix this time\n")
125 wt.add(['a'])
126 wt.lock_read()
127 self.addCleanup(wt.unlock)
128 commit = self._Commit(wt)
129 self.assertEqual(debian_changelog_commit(commit, None),
130 u"\u2026real fix this time\n")

Subscribers

People subscribed via source and target branches