From bb440128bdf47cbec0789b1e9453ca726ad3dd50 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Tue, 12 Jun 2012 18:07:58 -0400 Subject: repoman: handle trailing newlines better 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 --- pym/repoman/utilities.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'pym/repoman') diff --git a/pym/repoman/utilities.py b/pym/repoman/utilities.py index 1e07bad4c..013858a6d 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 -- cgit v1.2.3-1-g7c22