match_from_list: =* op with revision, bug #467826
authorZac Medico <zmedico@gentoo.org>
Sun, 9 Jun 2013 00:22:50 +0000 (17:22 -0700)
committerZac Medico <zmedico@gentoo.org>
Sun, 9 Jun 2013 00:22:50 +0000 (17:22 -0700)
pym/portage/dep/__init__.py
pym/portage/tests/dep/test_match_from_list.py

index 7776f895838232e73807d6870d9c36dc1830d865..798903f1128cceebafd51f0a2b97a98582283756 100644 (file)
@@ -2164,15 +2164,37 @@ def match_from_list(mydep, candidate_list):
                myver = mycpv_cps[2].lstrip("0")
                if not myver or not myver[0].isdigit():
                        myver = "0"+myver
-               mycpv_cmp = mycpv_cps[0] + "/" + mycpv_cps[1] + "-" + myver
+               if myver == mycpv_cps[2]:
+                       mycpv_cmp = mycpv
+               else:
+                       # Use replace to preserve the revision part if it exists
+                       # (mycpv_cps[3] can't be trusted because in contains r0
+                       # even when the input has no revision part).
+                       mycpv_cmp = mycpv.replace(
+                               mydep.cp + "-" + mycpv_cps[2],
+                               mydep.cp + "-" + myver, 1)
                for x in candidate_list:
-                       xs = getattr(x, "cpv_split", None)
-                       if xs is None:
-                               xs = catpkgsplit(remove_slot(x))
+                       try:
+                               x.cp
+                       except AttributeError:
+                               try:
+                                       pkg = _pkg_str(remove_slot(x))
+                               except InvalidData:
+                                       continue
+                       else:
+                               pkg = x
+
+                       xs = pkg.cpv_split
                        myver = xs[2].lstrip("0")
                        if not myver or not myver[0].isdigit():
                                myver = "0"+myver
-                       xcpv = xs[0]+"/"+xs[1]+"-"+myver
+                       if myver == xs[2]:
+                               xcpv = pkg.cpv
+                       else:
+                               # Use replace to preserve the revision part if it exists.
+                               xcpv = pkg.cpv.replace(
+                                       pkg.cp + "-" + xs[2],
+                                       pkg.cp + "-" + myver, 1)
                        if xcpv.startswith(mycpv_cmp):
                                mylist.append(x)
 
index b64862447e394578a8a25a09b7a94cf898d54bf7..8a1c9e22ae86f86042b9a095eae7482ef91a48b0 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright 2006-2012 Gentoo Foundation
+# Copyright 2006-2013 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
 import sys
@@ -71,6 +71,11 @@ class Test_match_from_list(TestCase):
                        (">sys-apps/portage-047", ["sys-apps/portage-046-r1"], []),
                        ("sys-apps/portage:0", [Package("=sys-apps/portage-045:0")], ["sys-apps/portage-045"]),
                        ("sys-apps/portage:0", [Package("=sys-apps/portage-045:1")], []),
+                       ("=cat/pkg-1-r1*", ["cat/pkg-1_alpha1"], []),
+                       ("=cat/pkg-1-r1*", ["cat/pkg-1-r11"], ["cat/pkg-1-r11"]),
+                       ("=cat/pkg-1-r1*", ["cat/pkg-01-r11"], ["cat/pkg-01-r11"]),
+                       ("=cat/pkg-01-r1*", ["cat/pkg-1-r11"], ["cat/pkg-1-r11"]),
+                       ("=cat/pkg-01-r1*", ["cat/pkg-001-r11"], ["cat/pkg-001-r11"]),
                        ("=sys-fs/udev-1*", ["sys-fs/udev-123"], ["sys-fs/udev-123"]),
                        ("=sys-fs/udev-4*", ["sys-fs/udev-456"], ["sys-fs/udev-456"]),
                        ("*/*", ["sys-fs/udev-456"], ["sys-fs/udev-456"]),