summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2017-12-02 21:29:01 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2017-12-02 22:27:44 +0000
commitf19aae1c6744b88756aeeb00415b95d95b81a49b (patch)
tree9e4e6785e37a6c11a5afc12aab4c861105d3dc42
parentRemove the ~ operator for ebuildversionrange (diff)
downloadgentoobrowse-api-f19aae1c6744b88756aeeb00415b95d95b81a49b.tar.bz2
gentoobrowse-api-f19aae1c6744b88756aeeb00415b95d95b81a49b.tar.xz
gentoobrowse-api-f19aae1c6744b88756aeeb00415b95d95b81a49b.zip
Adds getEbuildsByFilter to Portage API
This new method accepts a standard atom specifier and returns an array of matching ebuilds. We can now use it to thoroughly test a mostly re-written ebuildfilter function.
-rw-r--r--gentoobrowse-api/api/portage.ice1
-rw-r--r--gentoobrowse-api/db/schema.sql48
-rw-r--r--gentoobrowse-api/service/portageimpl.cpp7
-rw-r--r--gentoobrowse-api/service/portageimpl.h1
-rw-r--r--gentoobrowse-api/service/sql/portage/getEbuildsByFilter.sql4
-rw-r--r--gentoobrowse-api/unittests/fixtures/ebuilds.dat4
-rw-r--r--gentoobrowse-api/unittests/testPortage.cpp29
7 files changed, 74 insertions, 20 deletions
diff --git a/gentoobrowse-api/api/portage.ice b/gentoobrowse-api/api/portage.ice
index c63b0d9..1366b38 100644
--- a/gentoobrowse-api/api/portage.ice
+++ b/gentoobrowse-api/api/portage.ice
@@ -31,6 +31,7 @@ module Gentoo {
idempotent Packages getUserTrackedPackages(int userid);
idempotent Ebuilds getUserTrackedRecentVersions(int userid, int limit);
idempotent StringList getPackageUrls(int id);
+ idempotent Ebuilds getEbuildsByFilter(string filter);
idempotent Use getUse(string flag) throws Slicer::NoRowsReturned;
idempotent Uses getGlobalUses();
diff --git a/gentoobrowse-api/db/schema.sql b/gentoobrowse-api/db/schema.sql
index e449d36..0a5e109 100644
--- a/gentoobrowse-api/db/schema.sql
+++ b/gentoobrowse-api/db/schema.sql
@@ -105,39 +105,51 @@ ALTER FUNCTION gentoobrowse.textclean(t text) OWNER TO gentoo;
-- Name: ebuildfilter(text); Type: FUNCTION; Schema: gentoobrowse; Owner: gentoo
CREATE FUNCTION ebuildfilter(atomspec text) RETURNS SETOF integer
LANGUAGE plpgsql
- AS $_$
+ AS $$
declare
- op text;
- cat text;
- pkg text;
+ parts text[];
ver gentoobrowse.ebuildversion;
+ matchVerLen boolean = true;
begin
if (atomspec like '=%*') then
atomspec = '~' || substr(atomspec, 2, length(atomspec) - 2);
+ matchVerLen = false;
end if;
-op = (regexp_matches(atomspec, '^([^a-z]*)'))[1];
-cat = (regexp_matches(atomspec, '^[^a-z]*([^/]+)/'))[1];
-pkg = (regexp_matches(atomspec, '/(.+?)((-[0-9])|$)'))[1];
-ver = gentoobrowse.ebuildversion_constructor((regexp_matches(atomspec, '-([0-9]+.*)$'))[1]);
+parts = regexp_matches(atomspec,
+ '([[:punct:]]+)?' || -- op
+ '([[:alnum:]-]+)\/' || -- cat
+ '(.+?)' || -- package
+ '(?:-([0-9][.0-9]*[[:alpha:]]?\*?(?:(?:_(?:alpha|beta|pre|rc|p))?[[:digit:]]*)*(?:-r[[:digit:]]+)?))?' || -- version
+ '(?::([^/ []+(?:\/[^ []+)?))?'); -- slot
+ver = gentoobrowse.ebuildversion_constructor(parts[4]);
return query select ebuildid
from gentoobrowse.ebuilds e, gentoobrowse.packages p, gentoobrowse.categories c
where e.packageid = p.packageid
and p.categoryid = c.categoryid
-and p.name = pkg
-and c.name = cat
+and p.name = parts[3]
+and c.name = parts[2]
and case
- when op = '=' then e.versioninst = ver
- when op = '>=' then e.versioninst >= ver
- when op = '<=' then e.versioninst <= ver
- when op = '<' then e.versioninst < ver
- when op = '>' then e.versioninst > ver
- when op = '~' then gentoobrowse.ebuildversionrange(e.versioninst, ver)
- when op = '' then true
+ when parts[1] = '=' then e.versioninst = ver
+ when parts[1] = '>=' then e.versioninst >= ver
+ when parts[1] = '<=' then e.versioninst <= ver
+ when parts[1] = '<' then e.versioninst < ver
+ when parts[1] = '>' then e.versioninst > ver
+ when parts[1] = '~' and not matchVerLen then
+ gentoobrowse.ebuildversionrange(e.versioninst, ver)
+ when parts[1] = '~' and matchVerLen then
+ gentoobrowse.ebuildversionrange(e.versioninst, ver)
+ and array_length(ver.ver, 1) = array_length((e.versioninst).ver, 1)
+ when parts[1] is null then true
else false
end
+and case
+ when parts[5] is null then true
+ when position('/' in parts[5]) > 0 then e.slot = parts[5]
+ else split_part(e.slot, '/', 1) = parts[5]
+end
;
end;
-$_$;
+$$;
ALTER FUNCTION gentoobrowse.ebuildfilter(atomspec text) OWNER TO gentoo;
-- Name: ebuildversion_constructor(text); Type: FUNCTION; Schema: gentoobrowse; Owner: gentoo
CREATE FUNCTION ebuildversion_constructor(val text) RETURNS ebuildversion
diff --git a/gentoobrowse-api/service/portageimpl.cpp b/gentoobrowse-api/service/portageimpl.cpp
index d74de73..1885952 100644
--- a/gentoobrowse-api/service/portageimpl.cpp
+++ b/gentoobrowse-api/service/portageimpl.cpp
@@ -24,6 +24,7 @@
#include <sql/portage/getPackagesDepending.sql.h>
#include <sql/portage/getPackageMasks.sql.h>
#include <sql/portage/getPackageUses.sql.h>
+#include <sql/portage/getEbuildsByFilter.sql.h>
#include <sql/portage/getUse.sql.h>
#include <sql/portage/getGlobalUses.sql.h>
#include <sql/portage/getGroupUses.sql.h>
@@ -174,6 +175,12 @@ Portage::getPackageUrls(Ice::Int id, const Ice::Current &)
return fetchCache<Gentoo::StringList>(sql::portage::getPackageUrls, 30, id);
}
+Gentoo::Ebuilds
+Portage::getEbuildsByFilter(const std::string & filter, const Ice::Current &)
+{
+ return fetchCache<Gentoo::Ebuilds>(sql::portage::getEbuildsByFilter, 30, filter);
+}
+
Gentoo::Categories
Portage::getCategoriesWithRecentAdditions(Ice::Int syncDays, const Ice::Current &)
{
diff --git a/gentoobrowse-api/service/portageimpl.h b/gentoobrowse-api/service/portageimpl.h
index 4d60b19..42459c2 100644
--- a/gentoobrowse-api/service/portageimpl.h
+++ b/gentoobrowse-api/service/portageimpl.h
@@ -38,6 +38,7 @@ class DLL_PUBLIC Portage : public Gentoo::Portage, IceTray::AbstractCachingDatab
Gentoo::Packages getUserTrackedPackages(Ice::Int userid, const Ice::Current &) override;
Gentoo::Ebuilds getUserTrackedRecentVersions(Ice::Int userid, Ice::Int limit, const Ice::Current &) override;
Gentoo::StringList getPackageUrls(Ice::Int id, const Ice::Current &) override;
+ Gentoo::Ebuilds getEbuildsByFilter(const std::string &, const Ice::Current &) override;
Gentoo::UsePtr getUse(const std::string &, const Ice::Current &) override;
Gentoo::Uses getGlobalUses(const Ice::Current &) override;
diff --git a/gentoobrowse-api/service/sql/portage/getEbuildsByFilter.sql b/gentoobrowse-api/service/sql/portage/getEbuildsByFilter.sql
new file mode 100644
index 0000000..ce49210
--- /dev/null
+++ b/gentoobrowse-api/service/sql/portage/getEbuildsByFilter.sql
@@ -0,0 +1,4 @@
+SELECT e.ebuildid, e.packageid, e.repoid, e.version, e.slot, e.firstseen, e.moddate, e.license
+FROM gentoobrowse.ebuildfilter(?) f, gentoobrowse.ebuilds e
+WHERE f = e.ebuildid
+ORDER BY e.versioninst
diff --git a/gentoobrowse-api/unittests/fixtures/ebuilds.dat b/gentoobrowse-api/unittests/fixtures/ebuilds.dat
index 120c41d..8f73e95 100644
--- a/gentoobrowse-api/unittests/fixtures/ebuilds.dat
+++ b/gentoobrowse-api/unittests/fixtures/ebuilds.dat
@@ -50,8 +50,8 @@
628106 49039 0.8 ("{0,8}",@,0,0,0) 0 GPL-3 2015-08-06 22:44:41.026233 2015-08-10 02:08:09 17
628102 49039 0.5.1 ("{0,5,1}",@,0,0,0) 0 GPL-2 2015-08-06 22:44:41.026233 2015-11-09 05:07:18 17
628955 58252 5.20141231 ("{5,20141231}",@,0,0,0) 0 GPL-3 2015-08-06 22:44:41.026233 2015-12-01 15:10:49 17
-628959 51120 2.10.0-r1 ("{2,10,0}",@,0,0,1) 0/2.10.0 GPL-2 2015-08-06 22:44:41.026233 2015-12-01 15:10:48 17
-628964 51120 2.10.1 ("{2,10,1}",@,0,0,0) 0/2.10.1 GPL-2 2015-08-06 22:44:41.026233 2015-12-01 15:10:48 17
+628959 51120 2.10.0-r1 ("{2,10,0}",@,0,0,1) 1/2.10.0 GPL-2 2015-08-06 22:44:41.026233 2015-12-01 15:10:48 17
+628964 51120 2.10.1 ("{2,10,1}",@,0,0,0) 1/2.10.1 GPL-2 2015-08-06 22:44:41.026233 2015-12-01 15:10:48 17
628966 58252 5.20150710 ("{5,20150710}",@,0,0,0) 0 GPL-3 2015-08-06 22:44:41.026233 2015-12-01 15:10:49 17
616719 49424 3.5 ("{3,5}",@,0,0,0) 0 BSD 2015-08-06 22:44:41.026233 2015-11-09 05:07:18 17
616713 49732 4.3 ("{4,3}",@,0,0,0) 0 public-domain GPL-2 2015-08-06 22:44:41.026233 2015-08-10 02:08:21 17
diff --git a/gentoobrowse-api/unittests/testPortage.cpp b/gentoobrowse-api/unittests/testPortage.cpp
index 5386e1a..149949f 100644
--- a/gentoobrowse-api/unittests/testPortage.cpp
+++ b/gentoobrowse-api/unittests/testPortage.cpp
@@ -194,6 +194,35 @@ BOOST_AUTO_TEST_CASE( getPackageVersions )
BOOST_REQUIRE_EQUAL(629067, es.back()->ebuildid);
}
+BOOST_AUTO_TEST_CASE( getEbuildsByFilter )
+{
+ BOOST_REQUIRE_EQUAL(p->getEbuildsByFilter("dev-vcs/darcs").size(), 7);
+ BOOST_REQUIRE_EQUAL(p->getEbuildsByFilter("~dev-vcs/darcs-2").size(), 0);
+ BOOST_REQUIRE_EQUAL(p->getEbuildsByFilter("~dev-vcs/darcs-2.8").size(), 0);
+ BOOST_REQUIRE_EQUAL(p->getEbuildsByFilter("~dev-vcs/darcs-2.8.4").size(), 3);
+ BOOST_REQUIRE_EQUAL(p->getEbuildsByFilter("~dev-vcs/darcs-2.10.0").size(), 1);
+ BOOST_REQUIRE_EQUAL(p->getEbuildsByFilter("~dev-vcs/darcs-2.10.1").size(), 1);
+ BOOST_REQUIRE_EQUAL(p->getEbuildsByFilter("<dev-vcs/darcs-3").size(), 7);
+ BOOST_REQUIRE_EQUAL(p->getEbuildsByFilter(">dev-vcs/darcs-2").size(), 7);
+ BOOST_REQUIRE_EQUAL(p->getEbuildsByFilter(">dev-vcs/darcs-2.10").size(), 2);
+ BOOST_REQUIRE_EQUAL(p->getEbuildsByFilter("<dev-vcs/darcs-2.10").size(), 5);
+ BOOST_REQUIRE_EQUAL(p->getEbuildsByFilter("=dev-vcs/darcs-2.8.4*").size(), 3);
+ BOOST_REQUIRE_EQUAL(p->getEbuildsByFilter("=dev-vcs/darcs-2.8*").size(), 5);
+ BOOST_REQUIRE_EQUAL(p->getEbuildsByFilter("=dev-vcs/darcs-2.8").size(), 0);
+ BOOST_REQUIRE_EQUAL(p->getEbuildsByFilter("=dev-vcs/darcs-2.8.4").size(), 1);
+ BOOST_REQUIRE_EQUAL(p->getEbuildsByFilter("=dev-vcs/darcs-2.8.5").size(), 0);
+ BOOST_REQUIRE_EQUAL(p->getEbuildsByFilter("=dev-vcs/darcs-2.8.5-r3").size(), 1);
+ BOOST_REQUIRE_EQUAL(p->getEbuildsByFilter("<=dev-vcs/darcs-2.8.4-r3").size(), 2);
+ BOOST_REQUIRE_EQUAL(p->getEbuildsByFilter("<=dev-vcs/darcs-2.8.4-r6").size(), 3);
+ BOOST_REQUIRE_EQUAL(p->getEbuildsByFilter(">=dev-vcs/darcs-2.8.5-r4").size(), 3);
+ BOOST_REQUIRE_EQUAL(p->getEbuildsByFilter(">=dev-vcs/darcs-2.8.5-r3").size(), 4);
+ BOOST_REQUIRE_EQUAL(p->getEbuildsByFilter("<=dev-vcs/darcs-2.8.5-r3:0/2.8.5").size(), 1);
+ BOOST_REQUIRE_EQUAL(p->getEbuildsByFilter("<=dev-vcs/darcs-2.8.5-r3:0").size(), 4);
+ BOOST_REQUIRE_EQUAL(p->getEbuildsByFilter("<=dev-vcs/darcs-2.8.5-r3:1").size(), 0);
+ BOOST_REQUIRE_EQUAL(p->getEbuildsByFilter("dev-vcs/darcs:1").size(), 2);
+ BOOST_REQUIRE_EQUAL(p->getEbuildsByFilter("dev-vcs/darcs:0").size(), 5);
+}
+
BOOST_AUTO_TEST_CASE( getPackageVersionDetails )
{
auto es = p->getPackageVersionDetails(58252);