Gentoo Logo
Gentoo Spaceship




Note: Due to technical difficulties, the Archives are currently not up to date. GMANE provides an alternative service for most mailing lists.
c.f. bug 424647
List Archive: gentoo-portage-dev
Navigation:
Lists: gentoo-portage-dev: < Prev By Thread Next > < Prev By Date Next >
Headers:
To: gentoo-portage-dev@g.o
From: Mike Frysinger <vapier@g.o>
Subject: [PATCH 2/2] repoman: handle trailing newlines better
Date: Tue, 12 Jun 2012 18:13:41 -0400
Automatically strip trailing newlines from the ChangeLog, and be
better about not adding them in the first place (still not perfect,
but getting there).

Signed-off-by: Mike Frysinger <vapier@g.o>
---
 pym/portage/tests/repoman/test_echangelog.py |    9 +++++++++
 pym/repoman/utilities.py                     |   11 ++++++++---
 2 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/pym/portage/tests/repoman/test_echangelog.py b/pym/portage/tests/repoman/test_echangelog.py
index 71d6d5e..74aa1c5 100644
--- a/pym/portage/tests/repoman/test_echangelog.py
+++ b/pym/portage/tests/repoman/test_echangelog.py
@@ -83,6 +83,7 @@ class RepomanEchangelogTestCase(TestCase):
 		UpdateChangeLog(self.pkgdir, self.user, 'test!', self.skel_changelog, self.cat, self.pkg, quiet=True)
 		actual_cl = self._readlines(self.changelog)
 		self.assertEqual(actual_cl[0], self.header_pkg)
+		self.assertNotEqual(actual_cl[-1], '\n')
 
 	def testExistingGoodHeader(self):
 		# Test existing ChangeLog (correct values)
@@ -99,3 +100,11 @@ class RepomanEchangelogTestCase(TestCase):
 		UpdateChangeLog(self.pkgdir, self.user, 'test!', self.skel_changelog, self.cat, self.pkg, quiet=True)
 		actual_cl = self._readlines(self.changelog)
 		self.assertEqual(actual_cl[0], self.header_pkg)
+
+	def testTrailingNewlines(self):
+		# Make sure trailing newlines get chomped.
+		self._writelines(self.changelog, ['#\n', 'foo\n', '\n', 'bar\n', '\n', '\n'])
+
+		UpdateChangeLog(self.pkgdir, self.user, 'test!', self.skel_changelog, self.cat, self.pkg, quiet=True)
+		actual_cl = self._readlines(self.changelog)
+		self.assertNotEqual(actual_cl[-1], '\n')
diff --git a/pym/repoman/utilities.py b/pym/repoman/utilities.py
index 1e07bad..013858a 100644
--- a/pym/repoman/utilities.py
+++ b/pym/repoman/utilities.py
@@ -807,7 +807,9 @@ def UpdateChangeLog(pkgdir, user, msg, skel_path, category, package,
 		for line in textwrap.wrap(msg, 80, \
 				initial_indent='  ', subsequent_indent='  '):
 			clnew_lines.append(_unicode_decode('%s\n' % line))
-		clnew_lines.append(_unicode_decode('\n'))
+		# Don't append a trailing newline if the file is new.
+		if clold_file is not None:
+			clnew_lines.append(_unicode_decode('\n'))
 
 		f = io.open(f, mode='w', encoding=_encodings['repo.content'],
 			errors='backslashreplace')
@@ -839,9 +841,12 @@ def UpdateChangeLog(pkgdir, user, msg, skel_path, category, package,
 			# in the unified_diff call below.
 			clold_lines = old_header_lines + clold_lines
 
-			for line in clold_file:
-				f.write(line)
+			# Trim any trailing newlines.
+			lines = clold_file.readlines()
 			clold_file.close()
+			while lines and lines[-1] == '\n':
+				del lines[-1]
+			f.writelines(lines)
 		f.close()
 
 		# show diff
-- 
1.7.9.7



Replies:
Re: [PATCH 2/2] repoman: handle trailing newlines better
-- Zac Medico
References:
[PATCH 1/2] repoman: update cat/pkg info in header all the time
-- Mike Frysinger
Navigation:
Lists: gentoo-portage-dev: < Prev By Thread Next > < Prev By Date Next >
Previous by thread:
[PATCH 1/2] repoman: update cat/pkg info in header all the time
Next by thread:
Re: [PATCH 2/2] repoman: handle trailing newlines better
Previous by date:
[PATCH 1/2] repoman: update cat/pkg info in header all the time
Next by date:
Re: [PATCH 1/2] repoman: update cat/pkg info in header all the time


Updated Jun 13, 2012

Summary: Archive of the gentoo-portage-dev mailing list.

Donate to support our development efforts.

Copyright 2001-2013 Gentoo Foundation, Inc. Questions, Comments? Contact us.