Merge lp:~jameinel/bzr/2.0.3-433779-sanitize-commit-m into lp:bzr

Proposed by John A Meinel
Status: Merged
Merged at revision: not available
Proposed branch: lp:~jameinel/bzr/2.0.3-433779-sanitize-commit-m
Merge into: lp:bzr
Diff against target: 132 lines
5 files modified
NEWS (+38/-0)
bzr (+4/-0)
bzrlib/__init__.py (+4/-0)
bzrlib/builtins.py (+3/-0)
bzrlib/tests/blackbox/test_commit.py (+18/-0)
To merge this branch: bzr merge lp:~jameinel/bzr/2.0.3-433779-sanitize-commit-m
Reviewer Review Type Date Requested Status
Vincent Ladeuil Approve
Review via email: mp+14377@code.launchpad.net
To post a comment you must log in.
Revision history for this message
John A Meinel (jameinel) wrote :

This is a basic bugfix for bug #433779. The change is that if you supply a commit message (via -m ...) it sanitizes '\r\n' => '\n' and '\r' => '\n'.

The reason we don't allow '\r' is because our XML parsers silently translates it anyway, so we want to make sure that users are getting what they entered.

*Personally* I would have preferred Emac's bzr integration to pass '\n' appropriately rather than '\r\n', but this is a reasonable compromise.

Note that this code translates '\r\n' always, rather than only on Windows, etc... It also doesn't try to translate the message from '--file', because we open that file in 'text' mode anyway.

The test is pretty straightforward. Without the patch, the test fails with "ValueError" because we don't allow '\r'.

I did the patch on top on top of 2.0 in case we want to have it there. It was 'just' at the threshold of what I would be comfortable with, which is why I'm proposing it for bzr.dev/2.1 first.

Revision history for this message
Vincent Ladeuil (vila) wrote :

Thanks for that.

I fail to see what can possibly go wrong, why is why I agree we should land it in 2.1 first ;)

For the sake of example, you could have used the shell-like tests here, up to the run_bzr part.

review: Approve
Revision history for this message
John A Meinel (jameinel) wrote :

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Vincent Ladeuil wrote:
> Review: Approve
> Thanks for that.
>
> I fail to see what can possibly go wrong, why is why I agree we should land it in 2.1 first ;)
>
> For the sake of example, you could have used the shell-like tests here, up to the run_bzr part.
>
>

Except I feel that setting up the test should be done in bzrlib code and
not in 'shell' code. If I wanted to do that, I would have used 'run_bzr'
everywhere.

But thanks for the review.
John
=:->
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkrwkAwACgkQJdeBCYSNAAN6lwCfS5vCl72+7xNIFd9hI7KxGy6t
VmQAn3HTairobpUxkkvKBgKZyW46zCvm
=/SJL
-----END PGP SIGNATURE-----

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'NEWS'
2--- NEWS 2009-11-03 03:58:26 +0000
3+++ NEWS 2009-11-03 18:41:12 +0000
4@@ -5,6 +5,7 @@
5 .. contents:: List of Releases
6 :depth: 1
7
8+<<<<<<< TREE
9
10 bzr 2.1.0b3 (not released yet)
11 ##############################
12@@ -192,6 +193,43 @@
13 peak memory for initial copies (~200MB). (John Arbash Meinel)
14
15
16+=======
17+bzr 2.0.3 (not released yet)
18+############################
19+
20+:Codename: template
21+:2.0.3: ???
22+
23+Compatibility Breaks
24+********************
25+
26+New Features
27+************
28+
29+Bug Fixes
30+*********
31+* Sanitize commit messages that come in from the '-m' flag. We translate
32+ '\r\n' => '\n' and a plain '\r' => '\n'. The storage layer doesn't
33+ allow those because XML store silently translate it anyway. (The parser
34+ auto-translates \r\n => \n in ways that are hard for us to catch.)
35+
36+Improvements
37+************
38+
39+Documentation
40+*************
41+
42+API Changes
43+***********
44+
45+Internals
46+*********
47+
48+Testing
49+*******
50+
51+
52+>>>>>>> MERGE-SOURCE
53 bzr 2.0.2
54 #########
55
56
57=== modified file 'bzr'
58--- bzr 2009-10-30 16:13:05 +0000
59+++ bzr 2009-11-03 18:41:12 +0000
60@@ -23,7 +23,11 @@
61 import warnings
62
63 # update this on each release
64+<<<<<<< TREE
65 _script_version = (2, 1, 0)
66+=======
67+_script_version = (2, 0, 3)
68+>>>>>>> MERGE-SOURCE
69
70 if __doc__ is None:
71 print "bzr does not support python -OO."
72
73=== modified file 'bzrlib/__init__.py'
74--- bzrlib/__init__.py 2009-10-30 16:13:05 +0000
75+++ bzrlib/__init__.py 2009-11-03 18:41:13 +0000
76@@ -44,7 +44,11 @@
77 # Python version 2.0 is (2, 0, 0, 'final', 0)." Additionally we use a
78 # releaselevel of 'dev' for unreleased under-development code.
79
80+<<<<<<< TREE
81 version_info = (2, 1, 0, 'dev', 3)
82+=======
83+version_info = (2, 0, 3, 'dev', 0)
84+>>>>>>> MERGE-SOURCE
85
86 # API compatibility version: bzrlib is currently API compatible with 1.15.
87 api_minimum_version = (2, 1, 0)
88
89=== modified file 'bzrlib/builtins.py'
90--- bzrlib/builtins.py 2009-10-29 21:13:16 +0000
91+++ bzrlib/builtins.py 2009-11-03 18:41:12 +0000
92@@ -3027,6 +3027,9 @@
93 def get_message(commit_obj):
94 """Callback to get commit message"""
95 my_message = message
96+ if my_message is not None and '\r' in my_message:
97+ my_message = my_message.replace('\r\n', '\n')
98+ my_message = my_message.replace('\r', '\n')
99 if my_message is None and not file:
100 t = make_commit_message_template_encoded(tree,
101 selected_list, diff=show_diff,
102
103=== modified file 'bzrlib/tests/blackbox/test_commit.py'
104--- bzrlib/tests/blackbox/test_commit.py 2009-08-28 05:00:33 +0000
105+++ bzrlib/tests/blackbox/test_commit.py 2009-11-03 18:41:12 +0000
106@@ -170,6 +170,24 @@
107 self.assertEqual(err, 'Committing to: %s\n'
108 'Committed revision 2.\n' % expected)
109
110+ def test_commit_sanitizes_CR_in_message(self):
111+ # See bug #433779, basically Emacs likes to pass '\r\n' style line
112+ # endings to 'bzr commit -m ""' which breaks because we don't allow
113+ # '\r' in commit messages. (Mostly because of issues where XML style
114+ # formats arbitrarily strip it out of the data while parsing.)
115+ # To make life easier for users, we just always translate '\r\n' =>
116+ # '\n'. And '\r' => '\n'.
117+ a_tree = self.make_branch_and_tree('a')
118+ self.build_tree(['a/b'])
119+ a_tree.add('b')
120+ self.run_bzr(['commit',
121+ '-m', 'a string\r\n\r\nwith mixed\r\rendings\n'],
122+ working_dir='a')
123+ rev_id = a_tree.branch.last_revision()
124+ rev = a_tree.branch.repository.get_revision(rev_id)
125+ self.assertEqualDiff('a string\n\nwith mixed\n\nendings\n',
126+ rev.message)
127+
128 def test_commit_merge_reports_all_modified_files(self):
129 # the commit command should show all the files that are shown by
130 # bzr diff or bzr status when committing, even when they were not
131
132=== modified file 'setup.py'