aboutsummaryrefslogtreecommitdiff
path: root/brep
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2015-12-30 20:25:12 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2016-01-08 18:26:00 +0200
commita8bbc544cac714378e18f85b5f18d2988a752c5f (patch)
tree52c4268fa90fdd1132e0ebb14daa6e6f1aea6ca2 /brep
parentdd0f7ec5e776c25cbb0b6715bf62d52a9965f9b1 (diff)
Support package dependency version range
Diffstat (limited to 'brep')
-rw-r--r--brep/mod-repository-details.cxx2
-rw-r--r--brep/package71
-rw-r--r--brep/package-extra.sql12
3 files changed, 43 insertions, 42 deletions
diff --git a/brep/mod-repository-details.cxx b/brep/mod-repository-details.cxx
index 18da188..3147369 100644
--- a/brep/mod-repository-details.cxx
+++ b/brep/mod-repository-details.cxx
@@ -46,7 +46,7 @@ init (scanner& s)
db_ = shared_database (*options_);
- tzset(); // To use butl::to_stream() later on.
+ tzset (); // To use butl::to_stream() later on.
}
bool brep::repository_details::
diff --git a/brep/package b/brep/package
index 9e4dde6..af59462 100644
--- a/brep/package
+++ b/brep/package
@@ -19,6 +19,11 @@
#include <brep/types>
#include <brep/utility>
+// The uint16_t value range is not fully covered by SMALLINT PostgreSQL type
+// to which uint16_t is mapped by default.
+//
+#pragma db value(uint16_t) type("INTEGER")
+
namespace brep
{
// Use an image type to map bpkg::version to the database since there
@@ -32,12 +37,18 @@ namespace brep
string canonical_release;
uint16_t revision;
string upstream;
- string release;
+ optional<string> release;
};
}
#include <bpkg/manifest>
+namespace brep
+{
+ using optional_version = optional<bpkg::version>;
+ using _optional_version = optional<_version>;
+}
+
// Prevent assert() macro expansion in get/set expressions. This should
// appear after all #include directives since the assert() macro is
// redefined in each <assert.h> inclusion.
@@ -50,8 +61,7 @@ void assert (int);
// We have to keep these mappings at the global scope instead of inside
// the brep namespace because they need to be also effective in the
-// bpkg namespace from which we "borrow" types (and some of them use
-// version and comparison).
+// bpkg namespace from which we "borrow" types (and some of them use version).
//
#pragma db map type(bpkg::version) as(brep::_version) \
to(brep::_version{(?).epoch, \
@@ -65,14 +75,24 @@ void assert (int);
std::move ((?).release), \
(?).revision))
-#pragma db map type(bpkg::comparison) as(brep::string) \
- to(bpkg::to_string (?)) \
- from(bpkg::to_comparison (?))
+#pragma db map type(brep::optional_version) as(brep::_optional_version) \
+ to((?) \
+ ? brep::_version{(?)->epoch, \
+ (?)->canonical_upstream, \
+ (?)->canonical_release, \
+ (?)->revision, \
+ (?)->upstream, \
+ (?)->release} \
+ : brep::_optional_version ()) \
+ from((?) \
+ ? bpkg::version ((?)->epoch, \
+ std::move ((?)->upstream), \
+ std::move ((?)->release), \
+ (?)->revision) \
+ : brep::optional_version ())
namespace brep
{
- // @@ If namespace, then should probably call it 'repo'.
- //
// @@ Might make sense to put some heavy members (e.g., description,
// containers) into a separate section.
//
@@ -130,24 +150,6 @@ namespace brep
string canonical_release;
uint16_t revision;
- // @@ The following function will fail the assertion for versions like
- // 0.0.0 (canonical_upstream is empty, canonical_release set to "~").
- // The problem here is that it's possible to specify such a version
- // which canonical representation is indistinguishable from that of
- // the empty version. Example: 0.0.0-
- // This effectivelly make it impossible to use canonical_version as a
- // primary key. Need to think on fixing that problem on the version
- // specification level. Probably canonical upstream (and release) for
- // non-empty version should always start with '.'.
- // Examples: ".00000001.a" for "1.A", ".", for "0.0.0"
- //
- // @@ Also version spec do not mention that trailing zero-only components
- // get removed.
- //
- // @@ If by some reason decide to leave canonical upstream representation
- // as is, then need to drop the function below, make the loader not
- // using it.
- //
bool
empty () const noexcept
{
@@ -172,13 +174,14 @@ namespace brep
#pragma db value transient
struct upstream_version: version
{
- #pragma db member(upstream_) virtual(string) \
- get(this.upstream) \
- set(this = brep::version (0, std::move (?), "~", 0))
+ #pragma db member(upstream_) virtual(string) \
+ get(this.upstream) \
+ set(this = brep::version (0, std::move (?), std::string (), 0))
- #pragma db member(release_) virtual(string) \
- get(this.release) \
- set(this = brep::version (0, this.upstream, std::move (?), 0))
+ #pragma db member(release_) virtual(optional_string) \
+ get(this.release) \
+ set(this = brep::version ( \
+ 0, std::move (this.upstream), std::move (?), 0))
upstream_version () = default;
upstream_version (version v): version (move (v)) {}
@@ -224,12 +227,9 @@ namespace brep
// dependencies
//
- using bpkg::comparison;
using bpkg::dependency_constraint;
#pragma db value(dependency_constraint) definition
- #pragma db member(dependency_constraint::operation) column("")
- #pragma db member(dependency_constraint::version) column("")
#pragma db value
struct package_id
@@ -303,6 +303,7 @@ namespace brep
// Database mapping.
//
#pragma db member(package) column("") not_null
+ #pragma db member(constraint) column("")
};
std::ostream&
diff --git a/brep/package-extra.sql b/brep/package-extra.sql
index acf1489..dc37d1f 100644
--- a/brep/package-extra.sql
+++ b/brep/package-extra.sql
@@ -33,10 +33,10 @@ $$ LANGUAGE SQL STABLE;
--
CREATE FUNCTION
latest_package(INOUT name TEXT,
- OUT version_epoch SMALLINT,
+ OUT version_epoch INTEGER,
OUT version_canonical_upstream TEXT,
OUT version_canonical_release TEXT,
- OUT version_revision SMALLINT)
+ OUT version_revision INTEGER)
RETURNS SETOF record AS $$
SELECT name, version_epoch, version_canonical_upstream,
version_canonical_release, version_revision
@@ -52,10 +52,10 @@ $$ LANGUAGE SQL STABLE;
CREATE FUNCTION
search_latest_packages(IN query tsquery,
OUT name TEXT,
- OUT version_epoch SMALLINT,
+ OUT version_epoch INTEGER,
OUT version_canonical_upstream TEXT,
OUT version_canonical_release TEXT,
- OUT version_revision SMALLINT,
+ OUT version_revision INTEGER,
OUT rank real)
RETURNS SETOF record AS $$
SELECT name, version_epoch, version_canonical_upstream,
@@ -76,10 +76,10 @@ $$ LANGUAGE SQL STABLE;
CREATE FUNCTION
search_packages(IN query tsquery,
INOUT name TEXT,
- OUT version_epoch SMALLINT,
+ OUT version_epoch INTEGER,
OUT version_canonical_upstream TEXT,
OUT version_canonical_release TEXT,
- OUT version_revision SMALLINT,
+ OUT version_revision INTEGER,
OUT rank real)
RETURNS SETOF record AS $$
SELECT name, version_epoch, version_canonical_upstream,