Merge lp:~wgrant/launchpad/diff-no-newline into lp:launchpad

Proposed by William Grant
Status: Merged
Merged at revision: 17618
Proposed branch: lp:~wgrant/launchpad/diff-no-newline
Merge into: lp:launchpad
Diff against target: 53 lines (+14/-11)
2 files modified
lib/lp/code/mail/codereviewcomment.py (+12/-10)
lib/lp/code/mail/tests/test_codereviewcomment.py (+2/-1)
To merge this branch: bzr merge lp:~wgrant/launchpad/diff-no-newline
Reviewer Review Type Date Requested Status
Kit Randel (community) Approve
Review via email: mp+264254@code.launchpad.net

Commit message

Cope with "No newline at end of file" lines in diff emails, which bzrlib merges into the previous line.

Description of the change

Cope with "No newline at end of file" lines in diff emails, which bzrlib merges into the previous line. Look for NO_NL in patches.py to see the weird parsing implementation.

To post a comment you must log in.
Revision history for this message
Kit Randel (blr) wrote :

Glad you added a comment; not what I would have expected!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/code/mail/codereviewcomment.py'
2--- lib/lp/code/mail/codereviewcomment.py 2015-07-09 05:40:01 +0000
3+++ lib/lp/code/mail/codereviewcomment.py 2015-07-09 10:44:14 +0000
4@@ -244,16 +244,18 @@
5 hunk_lines.extend(format_comment(comment))
6 hunk_comment = True
7
8- for line in hunk.lines:
9- line_count += 1 # inc hunk lines
10-
11- # line is a ContextLine/ReplaceLine
12- hunk_lines.append(u'> %s' % str(line).rstrip('\n').decode(
13- 'utf-8', 'replace'))
14- comment = comments.get(str(line_count))
15- if comment:
16- hunk_lines.extend(format_comment(comment))
17- hunk_comment = True
18+ for hunk_line in hunk.lines:
19+ # A single HunkLine can actually represent multiple
20+ # lines in the "No newline at end of file" case.
21+ hunk_line = str(hunk_line)
22+ for line in hunk_line.splitlines():
23+ line_count += 1 # inc hunk lines
24+ hunk_lines.append(u'> %s' % line.rstrip('\n').decode(
25+ 'utf-8', 'replace'))
26+ comment = comments.get(str(line_count))
27+ if comment:
28+ hunk_lines.extend(format_comment(comment))
29+ hunk_comment = True
30
31 # preserve hunks for context if comment in patch header
32 if patch_comment or hunk_comment:
33
34=== modified file 'lib/lp/code/mail/tests/test_codereviewcomment.py'
35--- lib/lp/code/mail/tests/test_codereviewcomment.py 2015-07-09 03:12:29 +0000
36+++ lib/lp/code/mail/tests/test_codereviewcomment.py 2015-07-09 10:44:14 +0000
37@@ -404,6 +404,7 @@
38 " c\n"
39 "+d\n"
40 "+e\n"
41+ "\\ No newline at end of file\n"
42 "\n"
43 "=== modified file 'fulango.py'\n"
44 "--- fulano.py\t2014-08-26 15:53:34.000000000 -0400\n"
45@@ -618,7 +619,7 @@
46 self.getSection(comments).splitlines()[4:12])
47
48 def test_comment_in_patch_after_linebreak(self):
49- comments = {'31': 'que?'}
50+ comments = {'32': 'que?'}
51 self.assertEqual(
52 map(unicode, [
53 "> ",