From: Zac Medico <zmedico@gentoo.org>
Date: Thu, 30 Apr 2009 07:07:31 +0000 (-0000)
Subject: Inside the portdbapi constructor, handle repositories with the same repo_name
X-Git-Tag: v2.1.6.12~81
X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=ff6dc592749b91cddc3ba5711e5e213bae0d3130;p=portage.git

Inside the portdbapi constructor, handle repositories with the same repo_name
by discarding the ones that were encountered earlier. (trunk r13327)

svn path=/main/branches/2.1.6/; revision=13492
---

diff --git a/pym/portage/dbapi/porttree.py b/pym/portage/dbapi/porttree.py
index 1bc08b8fa..a7e074d45 100644
--- a/pym/portage/dbapi/porttree.py
+++ b/pym/portage/dbapi/porttree.py
@@ -125,10 +125,6 @@ class portdbapi(dbapi):
 		# this purpose because doebuild makes many changes to the config
 		# instance that is passed in.
 		self.doebuild_settings = config(clone=self.mysettings)
-
-		porttree_root = os.path.realpath(porttree_root)
-		self.porttree_root = porttree_root
-
 		self.depcachedir = os.path.realpath(self.mysettings.depcachedir)
 
 		if os.environ.get("SANDBOX_ON") == "1":
@@ -140,6 +136,46 @@ class portdbapi(dbapi):
 				os.environ["SANDBOX_WRITE"] = \
 					":".join(filter(None, sandbox_write))
 
+		porttrees = [os.path.realpath(porttree_root)]
+		porttrees.extend(os.path.realpath(x) for x in \
+			self.mysettings.get('PORTDIR_OVERLAY', '').split())
+		treemap = {}
+		repository_map = {}
+		self.treemap = treemap
+		self._repository_map = repository_map
+		identically_named_paths = set()
+		for path in porttrees:
+			if path in repository_map:
+				continue
+			repo_name_path = os.path.join(path, REPO_NAME_LOC)
+			try:
+				repo_name = open(repo_name_path, 'r').readline().strip()
+			except EnvironmentError:
+				# warn about missing repo_name at some other time, since we
+				# don't want to see a warning every time the portage module is
+				# imported.
+				pass
+			else:
+				identically_named_path = treemap.get(repo_name)
+				if identically_named_path is not None:
+					# The earlier one is discarded.
+					del repository_map[identically_named_path]
+					identically_named_paths.add(identically_named_path)
+					if identically_named_path == porttrees[0]:
+						# Found another repo with the same name as
+						# $PORTDIR, so update porttrees[0] to match.
+						porttrees[0] = path
+				treemap[repo_name] = path
+				repository_map[path] = repo_name
+
+		# Ensure that each repo_name is unique. Later paths override
+		# earlier ones that correspond to the same name.
+		porttrees = [x for x in porttrees if x not in identically_named_paths]
+
+		self.porttrees = porttrees
+		porttree_root = porttrees[0]
+		self.porttree_root = porttree_root
+
 		self.eclassdb = eclass_cache.cache(porttree_root)
 
 		# This is used as sanity check for aux_get(). If there is no
@@ -155,22 +191,6 @@ class portdbapi(dbapi):
 		self.xcache = {}
 		self.frozen = 0
 
-		self.porttrees = [self.porttree_root] + \
-			[os.path.realpath(t) for t in self.mysettings["PORTDIR_OVERLAY"].split()]
-		self.treemap = {}
-		self._repository_map = {}
-		for path in self.porttrees:
-			repo_name_path = os.path.join(path, REPO_NAME_LOC)
-			try:
-				repo_name = open(repo_name_path, 'r').readline().strip()
-				self.treemap[repo_name] = path
-				self._repository_map[path] = repo_name
-			except (OSError,IOError):
-				# warn about missing repo_name at some other time, since we
-				# don't want to see a warning every time the portage module is
-				# imported.
-				pass
-
 		self._repo_info = {}
 		eclass_dbs = {porttree_root : self.eclassdb}
 		local_repo_configs = self.mysettings._local_repo_configs