1 |
Automatically strip trailing newlines from the ChangeLog, and be |
2 |
better about not adding them in the first place (still not perfect, |
3 |
but getting there). |
4 |
|
5 |
Signed-off-by: Mike Frysinger <vapier@g.o> |
6 |
--- |
7 |
pym/portage/tests/repoman/test_echangelog.py | 9 +++++++++ |
8 |
pym/repoman/utilities.py | 11 ++++++++--- |
9 |
2 files changed, 17 insertions(+), 3 deletions(-) |
10 |
|
11 |
diff --git a/pym/portage/tests/repoman/test_echangelog.py b/pym/portage/tests/repoman/test_echangelog.py |
12 |
index 71d6d5e..74aa1c5 100644 |
13 |
--- a/pym/portage/tests/repoman/test_echangelog.py |
14 |
+++ b/pym/portage/tests/repoman/test_echangelog.py |
15 |
@@ -83,6 +83,7 @@ class RepomanEchangelogTestCase(TestCase): |
16 |
UpdateChangeLog(self.pkgdir, self.user, 'test!', self.skel_changelog, self.cat, self.pkg, quiet=True) |
17 |
actual_cl = self._readlines(self.changelog) |
18 |
self.assertEqual(actual_cl[0], self.header_pkg) |
19 |
+ self.assertNotEqual(actual_cl[-1], '\n') |
20 |
|
21 |
def testExistingGoodHeader(self): |
22 |
# Test existing ChangeLog (correct values) |
23 |
@@ -99,3 +100,11 @@ class RepomanEchangelogTestCase(TestCase): |
24 |
UpdateChangeLog(self.pkgdir, self.user, 'test!', self.skel_changelog, self.cat, self.pkg, quiet=True) |
25 |
actual_cl = self._readlines(self.changelog) |
26 |
self.assertEqual(actual_cl[0], self.header_pkg) |
27 |
+ |
28 |
+ def testTrailingNewlines(self): |
29 |
+ # Make sure trailing newlines get chomped. |
30 |
+ self._writelines(self.changelog, ['#\n', 'foo\n', '\n', 'bar\n', '\n', '\n']) |
31 |
+ |
32 |
+ UpdateChangeLog(self.pkgdir, self.user, 'test!', self.skel_changelog, self.cat, self.pkg, quiet=True) |
33 |
+ actual_cl = self._readlines(self.changelog) |
34 |
+ self.assertNotEqual(actual_cl[-1], '\n') |
35 |
diff --git a/pym/repoman/utilities.py b/pym/repoman/utilities.py |
36 |
index 1e07bad..013858a 100644 |
37 |
--- a/pym/repoman/utilities.py |
38 |
+++ b/pym/repoman/utilities.py |
39 |
@@ -807,7 +807,9 @@ def UpdateChangeLog(pkgdir, user, msg, skel_path, category, package, |
40 |
for line in textwrap.wrap(msg, 80, \ |
41 |
initial_indent=' ', subsequent_indent=' '): |
42 |
clnew_lines.append(_unicode_decode('%s\n' % line)) |
43 |
- clnew_lines.append(_unicode_decode('\n')) |
44 |
+ # Don't append a trailing newline if the file is new. |
45 |
+ if clold_file is not None: |
46 |
+ clnew_lines.append(_unicode_decode('\n')) |
47 |
|
48 |
f = io.open(f, mode='w', encoding=_encodings['repo.content'], |
49 |
errors='backslashreplace') |
50 |
@@ -839,9 +841,12 @@ def UpdateChangeLog(pkgdir, user, msg, skel_path, category, package, |
51 |
# in the unified_diff call below. |
52 |
clold_lines = old_header_lines + clold_lines |
53 |
|
54 |
- for line in clold_file: |
55 |
- f.write(line) |
56 |
+ # Trim any trailing newlines. |
57 |
+ lines = clold_file.readlines() |
58 |
clold_file.close() |
59 |
+ while lines and lines[-1] == '\n': |
60 |
+ del lines[-1] |
61 |
+ f.writelines(lines) |
62 |
f.close() |
63 |
|
64 |
# show diff |
65 |
-- |
66 |
1.7.9.7 |