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-392064-garchives=archives.gentoo.org@lists.gentoo.org>)
	id 1REuXF-00050n-K6
	for garchives@archives.gentoo.org; Sat, 15 Oct 2011 03:03:41 +0000
Received: from pigeon.gentoo.org (localhost [127.0.0.1])
	by pigeon.gentoo.org (Postfix) with SMTP id 4A1E721C045;
	Sat, 15 Oct 2011 03:03:34 +0000 (UTC)
Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183])
	by pigeon.gentoo.org (Postfix) with ESMTP id 0A8F021C068
	for <gentoo-commits@lists.gentoo.org>; Sat, 15 Oct 2011 03:03:33 +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 757321B402A
	for <gentoo-commits@lists.gentoo.org>; Sat, 15 Oct 2011 03:03:33 +0000 (UTC)
Received: from localhost.localdomain (localhost [127.0.0.1])
	by pelican.gentoo.org (Postfix) with ESMTP id C03E58003C
	for <gentoo-commits@lists.gentoo.org>; Sat, 15 Oct 2011 03:03:32 +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: <9c9145a9e3c2d8d1bcebf791ce2188add656fee2.zmedico@gentoo>
Subject: [gentoo-commits] proj/portage:master commit in: bin/
X-VCS-Repository: proj/portage
X-VCS-Files: bin/repoman
X-VCS-Directories: bin/
X-VCS-Committer: zmedico
X-VCS-Committer-Name: Zac Medico
X-VCS-Revision: 9c9145a9e3c2d8d1bcebf791ce2188add656fee2
Date: Sat, 15 Oct 2011 03:03:32 +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: 42bfe226098ab5dd7c845b43b1fc7249

commit:     9c9145a9e3c2d8d1bcebf791ce2188add656fee2
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Sat Oct 15 03:03:21 2011 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Sat Oct 15 03:03:21 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=3Dproj/portage.git;a=
=3Dcommit;h=3D9c9145a9

repoman: optimize --if-modified and --echangelog

Avoid unnecessary nested loops.

---
 bin/repoman |   64 +++++++++++++++++++++++++++++++++++------------------=
-----
 1 files changed, 39 insertions(+), 25 deletions(-)

diff --git a/bin/repoman b/bin/repoman
index 2b4cd28..4a157e5 100755
--- a/bin/repoman
+++ b/bin/repoman
@@ -906,6 +906,37 @@ scanlist.sort()
=20
 logging.debug("Found the following packages to scan:\n%s" % '\n'.join(sc=
anlist))
=20
+def vcs_files_to_cps(vcs_file_iter):
+	"""
+	Iterate over the given modified file paths returned from the vcs,
+	and return a frozenset containing category/pn strings for each
+	modified package.
+	"""
+
+	modified_cps =3D []
+
+	if repolevel =3D=3D 3:
+		if next(vcs_file_iter, None) is not None:
+			modified_cps.append("/".join(reposplit[-2:]))
+
+	elif repolevel =3D=3D 2:
+		category =3D reposplit[-1]
+		for filename in vcs_file_iter:
+			f_split =3D filename.split(os.sep)
+			# ['.', pn,...]
+			if len(f_split) > 2:
+				modified_cps.append(category + "/" + f_split[1])
+
+	else:
+		# repolevel =3D=3D 1
+		for filename in vcs_file_iter:
+			f_split =3D filename.split(os.sep)
+			# ['.', category, pn,...]
+			if len(f_split) > 3:
+				modified_cps.append("/".join(f_split[1:3]))
+
+	return frozenset(modified_cps)
+
 def dev_keywords(profiles):
 	"""
 	Create a set of KEYWORDS values that exist in 'dev'
@@ -1150,9 +1181,12 @@ except FileNotFound:
 	# disable for non-gentoo repoman users who may not have herds.
 	herd_base =3D None
=20
-modified_pkgs =3D 0
+effective_scanlist =3D scanlist
+if options.if_modified =3D=3D "y":
+	effective_scanlist =3D sorted(vcs_files_to_cps(
+		chain(mychanged, mynew, myremoved)))
=20
-for x in scanlist:
+for x in effective_scanlist:
 	#ebuilds and digests added to cvs respectively.
 	logging.info("checking package %s" % x)
 	eadded=3D[]
@@ -1164,18 +1198,6 @@ for x in scanlist:
 	if repolevel < 2:
 		checkdir_relative =3D os.path.join(catdir, checkdir_relative)
 	checkdir_relative =3D os.path.join(".", checkdir_relative)
-
-	if options.if_modified =3D=3D "y":
-		checkdir_modified =3D False
-		checkdir_pattern =3D checkdir_relative.rstrip(os.sep) + os.sep
-		for f in chain(mychanged, mynew, myremoved):
-			if f.startswith(checkdir_pattern):
-				checkdir_modified =3D True
-				modified_pkgs +=3D 1
-				break
-		if not checkdir_modified:
-			continue
-
 	generated_manifest =3D False
=20
 	if options.mode =3D=3D "manifest" or \
@@ -2102,7 +2124,7 @@ for x in scanlist:
 				"%s/metadata.xml: unused local USE-description: '%s'" % \
 				(x, myflag))
=20
-if options.if_modified =3D=3D "y" and modified_pkgs < 1:
+if options.if_modified =3D=3D "y" and len(effective_scanlist) < 1:
 	logging.warn("--if-modified is enabled, but no modified packages were f=
ound!")
=20
 if options.mode =3D=3D "manifest":
@@ -2434,7 +2456,8 @@ else:
=20
 	if options.echangelog =3D=3D 'y':
 		logging.info("checking for unmodified ChangeLog files")
-		for x in scanlist:
+		for x in sorted(vcs_files_to_cps(
+			chain(myupdates, mymanifests, myremoved))):
 			catdir, pkgdir =3D x.split("/")
 			checkdir =3D repodir + "/" + x
 			checkdir_relative =3D ""
@@ -2449,15 +2472,6 @@ else:
 			if changelog_modified:
 				continue
=20
-			checkdir_modified =3D False
-			checkdir_pattern =3D checkdir_relative.rstrip(os.sep) + os.sep
-			for f in chain(myupdates, mymanifests, myremoved):
-				if f.startswith(checkdir_pattern):
-					checkdir_modified =3D True
-					break
-			if not checkdir_modified:
-				continue
-
 			myupdates.append(changelog_path)
 			logging.info("calling echangelog for package %s" % x)
 			# --no-strict is required if only manifest(s) have changed