From mboxrd@z Thu Jan  1 00:00:00 1970
Received: from pigeon.gentoo.org ([208.92.234.80] helo=lists.gentoo.org)
	by finch.gentoo.org with esmtp (Exim 4.60)
	(envelope-from <gentoo-commits+bounces-394124-garchives=archives.gentoo.org@lists.gentoo.org>)
	id 1RH3tK-0002lJ-Qd
	for garchives@archives.gentoo.org; Fri, 21 Oct 2011 01:27:23 +0000
Received: from pigeon.gentoo.org (localhost [127.0.0.1])
	by pigeon.gentoo.org (Postfix) with SMTP id 240FE21C064;
	Fri, 21 Oct 2011 01:27:14 +0000 (UTC)
Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183])
	by pigeon.gentoo.org (Postfix) with ESMTP id D40D121C064
	for <gentoo-commits@lists.gentoo.org>; Fri, 21 Oct 2011 01:27:13 +0000 (UTC)
Received: from pelican.gentoo.org (unknown [66.219.59.40])
	(using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by smtp.gentoo.org (Postfix) with ESMTPS id 431AF1B4009
	for <gentoo-commits@lists.gentoo.org>; Fri, 21 Oct 2011 01:27:13 +0000 (UTC)
Received: from localhost.localdomain (localhost [127.0.0.1])
	by pelican.gentoo.org (Postfix) with ESMTP id 5187580042
	for <gentoo-commits@lists.gentoo.org>; Fri, 21 Oct 2011 01:27:12 +0000 (UTC)
From: "Zac Medico" <zmedico@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Content-type: text/plain; charset=UTF-8
Reply-To: gentoo-dev@lists.gentoo.org, "Zac Medico" <zmedico@gentoo.org>
Message-ID: <706abe8ec2e633432d41dfb6553fee3c9604b886.zmedico@gentoo>
Subject: [gentoo-commits] proj/portage:master commit in: pym/repoman/
X-VCS-Repository: proj/portage
X-VCS-Files: pym/repoman/utilities.py
X-VCS-Directories: pym/repoman/
X-VCS-Committer: zmedico
X-VCS-Committer-Name: Zac Medico
X-VCS-Revision: 706abe8ec2e633432d41dfb6553fee3c9604b886
Date: Fri, 21 Oct 2011 01:27:12 +0000 (UTC)
Precedence: bulk
List-Post: <mailto:gentoo-commits@lists.gentoo.org>
List-Help: <mailto:gentoo-commits+help@lists.gentoo.org>
List-Unsubscribe: <mailto:gentoo-commits+unsubscribe@lists.gentoo.org>
List-Subscribe: <mailto:gentoo-commits+subscribe@lists.gentoo.org>
List-Id: Gentoo Linux mail <gentoo-commits.gentoo.org>
X-BeenThere: gentoo-commits@lists.gentoo.org
Content-Transfer-Encoding: quoted-printable
X-Archives-Salt: 
X-Archives-Hash: 17eb2b14341bd37cf1b01498bd8225d7

commit:     706abe8ec2e633432d41dfb6553fee3c9604b886
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Fri Oct 21 01:26:05 2011 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Fri Oct 21 01:26:05 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=3Dproj/portage.git;a=
=3Dcommit;h=3D706abe8e

UpdateChangeLog: handle edge cases

This should handle all kinds of variance in the input ChangeLog and
skel.ChangeLog.

---
 pym/repoman/utilities.py |   38 ++++++++++++++++++++++++++++----------
 1 files changed, 28 insertions(+), 10 deletions(-)

diff --git a/pym/repoman/utilities.py b/pym/repoman/utilities.py
index 325ade5..c1a9da8 100644
--- a/pym/repoman/utilities.py
+++ b/pym/repoman/utilities.py
@@ -632,6 +632,7 @@ def UpdateChangeLog(pkgdir, category, package, new, r=
emoved, changed, \
 	cl_path =3D os.path.join(pkgdir, 'ChangeLog')
 	clold_lines =3D []
 	clnew_lines =3D []
+	old_header_lines =3D []
 	header_lines =3D []
=20
 	try:
@@ -661,15 +662,17 @@ def UpdateChangeLog(pkgdir, category, package, new,=
 removed, changed, \
 		if clold_file is not None:
 			# retain header from old ChangeLog
 			for line in clold_file:
-				line_strip =3D line.strip()
-				clold_lines.append(line)
-				if line_strip[:1] !=3D '#':
+				line_strip =3D  line.strip()
+				if line_strip and line[:1] !=3D "#":
+					clold_lines.append(line)
 					break
-				line =3D re.sub(r'^(# Copyright \d\d\d\d)-\d\d\d\d',
-					r'\1-%s' % year, line)
-				clnew_lines.append(line)
+				old_header_lines.append(line)
+				header_lines.append(
+					re.sub(r'^(# Copyright \d\d\d\d)-\d\d\d\d ',
+					r'\1-%s ' % year, line))
 				if not line_strip:
 					break
+
 		elif clskel_file is not None:
 			# read skel.ChangeLog up to first empty line
 			for line in clskel_file:
@@ -680,11 +683,12 @@ def UpdateChangeLog(pkgdir, category, package, new,=
 removed, changed, \
 				line =3D line.replace('<PACKAGE_NAME>', package)
 				line =3D re.sub(r'^(# Copyright \d\d\d\d)-\d\d\d\d ',
 					r'\1-%s ' % year, line)
-				clnew_lines.append(line)
-			clnew_lines.append(_unicode_decode('\n'))
+				header_lines.append(line)
+			header_lines.append(_unicode_decode('\n'))
 			clskel_file.close()
=20
 		# write new ChangeLog entry
+		clnew_lines.extend(header_lines)
 		newebuild =3D False
 		for fn in new:
 			if not fn.endswith('.ebuild'):
@@ -733,8 +737,22 @@ def UpdateChangeLog(pkgdir, category, package, new, =
removed, changed, \
 		if clold_file is not None:
 			# clold_lines may contain a saved non-header line
 			# that we want to write first.
-			if clold_lines and clold_lines[-1].strip():
-				f.write(clold_lines[-1])
+			# Also, append this line to clnew_lines so that the
+			# unified_diff call doesn't show it as removed.
+			for line in clold_lines:
+				f.write(line)
+				clnew_lines.append(line)
+
+			# Now prepend old_header_lines to clold_lines, for use
+			# in the unified_diff call below.
+			clold_lines =3D old_header_lines + clold_lines
+
+			# ensure that there is no more than one blank
+			# line after our new entry
+			for line in clold_file:
+				if line.strip():
+					f.write(line)
+					break
=20
 			for line in clold_file:
 				f.write(line)