From bc965df24ffae81e9a05f63b31d46fa01a8d52d9 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Sat, 10 Oct 2015 15:37:13 +0200 Subject: Rename package_version class to package --- brep/package | 124 +++++++++++++++++---------------------- brep/package-search.cxx | 26 ++++---- brep/package-version-details.cxx | 60 +++++++++---------- brep/package-version-search.cxx | 50 ++++++++-------- brep/package.cxx | 50 ++++++++-------- 5 files changed, 147 insertions(+), 163 deletions(-) (limited to 'brep') diff --git a/brep/package b/brep/package index 98e0ca4..800f716 100644 --- a/brep/package +++ b/brep/package @@ -72,7 +72,7 @@ namespace brep // Forward declarations. // class repository; - class package_version; + class package; using strings = std::vector; @@ -106,9 +106,9 @@ namespace brep using repository_location = bpkg::repository_location; #pragma db value - struct package_version_id + struct package_id { - std::string package; + std::string name; #pragma db value struct version_type @@ -180,8 +180,8 @@ namespace brep // tricky. Can stick to just a package name until get some clarity on // "foreign" package resolution. // - // 4. As we get rid of the package class the dependency resolution come to - // finding the best matching package version object. The question is + // 4. As we left just the the package class the dependency resolution come to + // finding the best version matching package object. The question is // if to resolve dependencies on the loading phase or in the WEB interface // when required. The arguments in favour of doing that during loading // phase are: @@ -207,11 +207,6 @@ namespace brep using requirements = std::vector; - // Intended for instantiating key classes for maps used for simulation of - // 2-dimensional value type containers. Parameter type T not being used in - // template implementation is required to instantiate unrelated key - // classes to achieve proper table column naming with ODB pragmas. - // #pragma db object pointer(std::shared_ptr) session class repository { @@ -272,12 +267,8 @@ namespace brep repository () = default; }; - // @@ While it's very tempting to rename package_version to package wouldn't - // it be confusing having package denoting both specific package version - // and package as a collection of versions. - // #pragma db object pointer(std::shared_ptr) session - class package_version + class package { public: using repository_type = brep::repository; @@ -289,26 +280,26 @@ namespace brep using dependencies_type = brep::dependencies; using requirements_type = brep::requirements; - // Create internal package version object. + // Create internal package object. // - package_version (std::string name, - version_type, - priority_type, - std::string summary, - license_alternatives_type, - strings tags, - optional description, - std::string changes, - url_type, - optional package_url, - email_type, - optional package_email, - dependencies_type, - requirements_type, - optional location, - std::shared_ptr); - - // Create external package version object. + package (std::string name, + version_type, + priority_type, + std::string summary, + license_alternatives_type, + strings tags, + optional description, + std::string changes, + url_type, + optional package_url, + email_type, + optional package_email, + dependencies_type, + requirements_type, + optional location, + std::shared_ptr); + + // Create external package object. // // External repository packages can appear on the WEB interface only on // the package version details page in dependency list in the form of a @@ -316,9 +307,9 @@ namespace brep // required to compose such a link is the package name, version, and // repository location. // - package_version (std::string name, - version_type, - std::shared_ptr); + package (std::string name, + version_type, + std::shared_ptr); // Manifest data. // @@ -338,8 +329,8 @@ namespace brep requirements_type requirements; odb::lazy_shared_ptr internal_repository; - // Path to the package file. Set only for package versions present in - // internal repository. + // Path to the package file. Set only for packages present in internal + // repository. // optional location; @@ -354,7 +345,7 @@ namespace brep struct _id_type { #pragma db column("") - package_version_id data; + package_id data; #pragma db column("version_upstream") std::string upstream; @@ -434,43 +425,40 @@ namespace brep private: friend class odb::access; - package_version () = default; + package () = default; }; - // Find the latest version of an internal package. + // Find an internal package of the latest version. // - #pragma db view object(package_version) \ - object(package_version = v: \ - package_version::id.data.package == v::id.data.package && \ - package_version::id.data.version < v::id.data.version) \ - query((package_version::internal_repository.is_not_null () && \ - v::id.data.package.is_null ()) + "AND" + (?)) - struct latest_internal_package_version + #pragma db view object(package) \ + object(package = p: \ + package::id.data.name == p::id.data.name && \ + package::id.data.version < p::id.data.version) \ + query((package::internal_repository.is_not_null () && \ + p::id.data.name.is_null ()) + "AND" + (?)) + struct latest_internal_package { - using package_version_type = brep::package_version; - std::shared_ptr package_version; - - operator const std::shared_ptr& () const - {return package_version;} + using package_type = brep::package; + std::shared_ptr package; - explicit operator package_version_type& () const - {return *package_version;} + operator const std::shared_ptr& () const {return package;} + explicit operator package_type& () const {return *package;} }; - #pragma db view object(package_version) \ - query(package_version::internal_repository.is_not_null () && (?)) - struct internal_package_count + // Count number of internal packages distinct names. + // + #pragma db view object(package) \ + query(package::internal_repository.is_not_null () && (?)) + struct internal_package_name_count { - #pragma db column("count(DISTINCT" + \ - package_version::id.data.package+ ")") - + #pragma db column("count(DISTINCT" + package::id.data.name+ ")") std::size_t result; operator std::size_t () const {return result;} }; - #pragma db view object(package_version) - struct package_version_count + #pragma db view object(package) + struct package_count { #pragma db column("count(*)") std::size_t result; @@ -480,7 +468,7 @@ namespace brep // Version comparison operators. // - // They allow comparing objects that have epoch, canonical_upstream, + // They allow comparing objects that have epoch, canonical_upstream // and revision data members. // template @@ -553,11 +541,9 @@ namespace brep } inline bool - operator< (const package_version_id& x, const package_version_id& y) + operator< (const package_id& x, const package_id& y) { - int r (x.package.compare (y.package)); - - if (r != 0) + if (int r = x.name.compare (y.name)) return r < 0; return x.version < y.version; diff --git a/brep/package-search.cxx b/brep/package-search.cxx index cc15e02..27709c8 100644 --- a/brep/package-search.cxx +++ b/brep/package-search.cxx @@ -82,37 +82,35 @@ namespace brep << ~HEAD << BODY; - string q ( - pr.query ().empty () ? "" : "q=" + mime_url_encode (pr.query ())); - + string q (pr.query ().empty () ? "" : "q=" + mime_url_encode (pr.query ())); size_t rop (options_->results_on_page ()); transaction t (db_->begin ()); // @@ Query will include search criteria if specified. // - size_t pc (db_->query_value ()); + size_t pc (db_->query_value ()); s << DIV(ID="packages") << "Packages (" << pc << ")" << ~DIV; // @@ Query will also include search criteria if specified. // - using query = query; + using query = query; auto r ( - db_->query (query (true) + - "ORDER BY" + query::package_version::id.data.package + + db_->query (query (true) + + "ORDER BY" + query::package::id.data.name + "OFFSET" + to_string (pr.page () * rop) + "LIMIT" + to_string (rop))); for (const auto& ip: r) { - const package_version& v (ip); + const package& p (ip); s << DIV(CLASS="package") << DIV(CLASS="name") << A - << HREF << "/go/" << mime_url_encode (v.name); + << HREF << "/go/" << mime_url_encode (p.name); // Propagate search criteria to the package version search url. // @@ -120,14 +118,14 @@ namespace brep s << "?" << q; s << ~HREF - << v.name + << p.name << ~A << ~DIV - << DIV(CLASS="summary") << v.summary << ~DIV - << DIV_TAGS (v.tags) - << DIV_LICENSES (v.license_alternatives) + << DIV(CLASS="summary") << p.summary << ~DIV + << DIV_TAGS (p.tags) + << DIV_LICENSES (p.license_alternatives) << DIV(CLASS="dependencies") - << "Dependencies: " << v.dependencies.size () + << "Dependencies: " << p.dependencies.size () << ~DIV << ~DIV; } diff --git a/brep/package-version-details.cxx b/brep/package-version-details.cxx index 0ad86d7..543f3b6 100644 --- a/brep/package-version-details.cxx +++ b/brep/package-version-details.cxx @@ -63,7 +63,7 @@ namespace brep } assert (i != rq.path ().rend ()); - const string& p (*i); + const string& n (*i); params::package_version_details pr; @@ -80,7 +80,7 @@ namespace brep const char* ident ("\n "); const string& vs (v.string ()); - const string name (p + " " + vs); + const string name (n + " " + vs); const string title ("Package Version " + name); serializer s (rs.content (), title); @@ -108,24 +108,24 @@ namespace brep << ~HEAD << BODY << DIV(ID="name") - << A << HREF << "/go/" << mime_url_encode (p) << ~HREF << p << ~A + << A << HREF << "/go/" << mime_url_encode (n) << ~HREF << n << ~A << " " << vs << ~DIV; bool not_found (false); - shared_ptr pv; + shared_ptr p; transaction t (db_->begin ()); try { - package_version_id id {p, v.epoch, v.canonical_upstream, v.revision}; - pv = db_->load (id); + package_id id {n, v.epoch, v.canonical_upstream, v.revision}; + p = db_->load (id); - // If the requested package version turned up to be an "external" one - // just respond that no "internal" package version is present. + // If the requested package turned up to be an "external" one just + // respond that no "internal" package is present. // - not_found = pv->internal_repository == nullptr; + not_found = p->internal_repository == nullptr; } catch (const object_not_persistent& ) { @@ -135,27 +135,27 @@ namespace brep if (not_found) throw invalid_request (404, "Package '" + name + "' not found"); - assert (pv->location); - const string u (pv->internal_repository.load ()->location.string () + - "/" + pv->location->string ()); + assert (p->location); + const string u (p->internal_repository.load ()->location.string () + + "/" + p->location->string ()); s << DIV(CLASS="url") << A << HREF << u << ~HREF << u << ~A << ~DIV - << DIV(ID="summary") << pv->summary << ~DIV - << DIV_URL (pv->url) - << DIV_EMAIL (pv->email); + << DIV(ID="summary") << p->summary << ~DIV + << DIV_URL (p->url) + << DIV_EMAIL (p->email); - if (pv->description) - s << DIV(ID="description") << *pv->description << ~DIV; + if (p->description) + s << DIV(ID="description") << *p->description << ~DIV; - const priority& pt (pv->priority); + const priority& pt (p->priority); - s << DIV_TAGS (pv->tags) + s << DIV_TAGS (p->tags) << DIV_PRIORITY (pt); if (!pt.comment.empty ()) s << DIV(CLASS="comment") << pt.comment << ~DIV; - const auto& ls (pv->license_alternatives); + const auto& ls (p->license_alternatives); s << DIV(ID="licenses") << "Licenses:" @@ -182,7 +182,7 @@ namespace brep s << ~UL << ~DIV; - const auto& ds (pv->dependencies); + const auto& ds (p->dependencies); if (!ds.empty ()) { @@ -219,7 +219,7 @@ namespace brep << ~DIV; } - const auto& rm (pv->requirements); + const auto& rm (p->requirements); if (!rm.empty ()) { @@ -260,23 +260,23 @@ namespace brep << ~DIV; } - if (pv->package_url || pv->package_email) + if (p->package_url || p->package_email) { s << DIV(ID="package") << "Package:" << UL; - if (pv->package_url) - s << LI << DIV_URL (*pv->package_url) << ~LI; + if (p->package_url) + s << LI << DIV_URL (*p->package_url) << ~LI; - if (pv->package_email) - s << LI << DIV_EMAIL (*pv->package_email) << ~LI; + if (p->package_email) + s << LI << DIV_EMAIL (*p->package_email) << ~LI; s << ~UL << ~DIV; } - const auto& er (pv->external_repositories); + const auto& er (p->external_repositories); if (!er.empty ()) { @@ -293,7 +293,7 @@ namespace brep if (l.port () != 0) u += ":" + to_string (l.port ()); - u += "/go/" + mime_url_encode (p) + "/" + vs; + u += "/go/" + mime_url_encode (n) + "/" + vs; s << LI << DIV(CLASS="url") << A << HREF << u << ~HREF << u << ~A << ~DIV << ~LI; @@ -305,7 +305,7 @@ namespace brep t.commit (); - const string& ch (pv->changes); + const string& ch (p->changes); if (!ch.empty ()) s << DIV(ID="changes") << "Changes:" << PRE << ch << ~PRE << ~DIV; diff --git a/brep/package-version-search.cxx b/brep/package-version-search.cxx index 7b7ed63..8433b75 100644 --- a/brep/package-version-search.cxx +++ b/brep/package-version-search.cxx @@ -92,37 +92,37 @@ namespace brep transaction t (db_->begin ()); - shared_ptr pv; + shared_ptr p; { - using query = query; + using query = query; - latest_internal_package_version v; - if (!db_->query_one ( - query::package_version::id.data.package == name, v)) + latest_internal_package ip; + if (!db_->query_one ( + query::package::id.data.name == name, ip)) { throw invalid_request (404, "Package '" + name + "' not found"); } - pv = v; + p = ip; } - s << DIV(ID="summary") << pv->summary << ~DIV - << DIV_URL (pv->url) - << DIV_EMAIL (pv->email); + s << DIV(ID="summary") << p->summary << ~DIV + << DIV_URL (p->url) + << DIV_EMAIL (p->email); - if (pv->description) - s << DIV(ID="description") << *pv->description << ~DIV; + if (p->description) + s << DIV(ID="description") << *p->description << ~DIV; - s << DIV_TAGS (pv->tags); + s << DIV_TAGS (p->tags); size_t pvc; { - using query = query; + using query = query; // @@ Query will also include search criteria if specified. // - pvc = db_->query_value ( - query::id.data.package == name && + pvc = db_->query_value ( + query::id.data.name == name && query::internal_repository.is_not_null ()); } @@ -132,21 +132,21 @@ namespace brep // from this page totally. // /* - if (pv->package_url) - s << DIV_URL (*pv->package_url); + if (p->package_url) + s << DIV_URL (*p->package_url); - if (pv->package_email) - s << DIV_EMAIL (*pv->package_email); + if (p->package_email) + s << DIV_EMAIL (*p->package_email); */ - // @@ Use appropriate view when clarify which package version info to be - // displayed and search index structure get implemented. Query will also - // include search criteria if specified. + // @@ Use appropriate view when clarify which package info to be displayed + // and search index structure get implemented. Query will also include + // search criteria if specified. // - using query = query; + using query = query; auto r ( - db_->query ( - (query::id.data.package == name && + db_->query ( + (query::id.data.name == name && query::internal_repository.is_not_null ()) + order_by_version_desc (query::id.data.version) + "OFFSET" + to_string (pr.page () * rop) + diff --git a/brep/package.cxx b/brep/package.cxx index 3cf4063..be14034 100644 --- a/brep/package.cxx +++ b/brep/package.cxx @@ -16,25 +16,25 @@ using namespace odb::core; namespace brep { - // package_version + // package // - package_version:: - package_version (string nm, - version_type vr, - priority_type pr, - string sm, - license_alternatives_type la, - strings tg, - optional ds, - string ch, - url_type ur, - optional pu, - email_type em, - optional pe, - dependencies_type dp, - requirements_type rq, - optional lc, - shared_ptr rp) + package:: + package (string nm, + version_type vr, + priority_type pr, + string sm, + license_alternatives_type la, + strings tg, + optional ds, + string ch, + url_type ur, + optional pu, + email_type em, + optional pe, + dependencies_type dp, + requirements_type rq, + optional lc, + shared_ptr rp) : name (move (nm)), version (move (vr)), priority (move (pr)), @@ -55,10 +55,10 @@ namespace brep assert (internal_repository->internal); } - package_version:: - package_version (string nm, - version_type vr, - shared_ptr rp) + package:: + package (string nm, + version_type vr, + shared_ptr rp) : name (move (nm)), version (move (vr)) { @@ -66,7 +66,7 @@ namespace brep external_repositories.emplace_back (move (rp)); } - package_version::_id_type package_version:: + package::_id_type package:: _id () const { return _id_type { @@ -79,11 +79,11 @@ namespace brep version.upstream}; } - void package_version:: + void package:: _id (_id_type&& v, database&) { const auto& dv (v.data.version); - name = move (v.data.package); + name = move (v.data.name); version = version_type (dv.epoch, move (v.upstream), dv.revision); assert (version.canonical_upstream == dv.canonical_upstream); } -- cgit v1.1