From ad53b2152e10b133165c95f08f218e80f1dd8580 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Wed, 25 Oct 2023 18:14:35 +0300 Subject: Improve pkg-build's 'unable to upgrade package' diagnostics --- bpkg/package.hxx | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 60 insertions(+), 6 deletions(-) (limited to 'bpkg/package.hxx') diff --git a/bpkg/package.hxx b/bpkg/package.hxx index 06278cd..8f4b46c 100644 --- a/bpkg/package.hxx +++ b/bpkg/package.hxx @@ -1614,12 +1614,6 @@ namespace bpkg package_key (database& d, package_name n): db (d), name (move (n)) {} - // Create a pseudo-package (command line as a dependent, etc). - // - package_key (database& d, string n) - : db (d), - name (n.empty () ? package_name () : package_name (move (n))) {} - bool operator== (const package_key& v) const { @@ -1651,6 +1645,66 @@ namespace bpkg return os << p.string (); } + // Database, package name, and package version. + // + // It is normally used as a key for maps containing data for package + // versions across multiple linked configurations. Assumes that the + // respective databases are not detached during such map lifetimes. + // Considers all package name, package version, and database for objects + // comparison. + // + // The package name can be a pseudo-package (command line as a dependent, + // etc), in which case the version is absent. The version can also be empty, + // denoting a package of an unknown version. + // + struct package_version_key + { + reference_wrapper db; + package_name name; + optional version; + + package_version_key (database& d, package_name n, bpkg::version v) + : db (d), name (move (n)), version (move (v)) {} + + // Create a pseudo-package (command line as a dependent, etc). + // + package_version_key (database& d, string n) + : db (d), + name (move (n), package_name::raw_string) {} + + bool + operator== (const package_version_key& v) const + { + // See operator==(database, database). + // + return name == v.name && + version == v.version && + &db.get () == &v.db.get (); + } + + bool + operator!= (const package_version_key& v) const + { + return !(*this == v); + } + + bool + operator< (const package_version_key&) const; + + // Return the package string representation in the form: + // + // [/] [ ] + // + std::string + string (bool ignore_version = false) const; + }; + + inline ostream& + operator<< (ostream& os, const package_version_key& p) + { + return os << p.string (); + } + // Return a count of repositories that contain this repository fragment. // #pragma db view table("main.repository_fragments") -- cgit v1.1