From f82ed52a4959cecae176600180f967328d924ce6 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 6 Oct 2015 10:12:14 +0200 Subject: Rename package to selected_package, state to package_state --- bpkg/build.cxx | 12 ++++++------ bpkg/forward | 2 +- bpkg/package | 41 ++++++++++++++++++++--------------------- bpkg/package.cxx | 22 +++++++++++----------- bpkg/package.xml | 10 +++++----- bpkg/pkg-command.cxx | 4 ++-- bpkg/pkg-configure.cxx | 18 ++++++++++-------- bpkg/pkg-disfigure | 4 ++-- bpkg/pkg-disfigure.cxx | 23 ++++++++++++----------- bpkg/pkg-fetch.cxx | 6 +++--- bpkg/pkg-purge.cxx | 24 +++++++++++++----------- bpkg/pkg-status.cxx | 6 +++--- bpkg/pkg-unpack.cxx | 18 +++++++++--------- 13 files changed, 97 insertions(+), 93 deletions(-) (limited to 'bpkg') diff --git a/bpkg/build.cxx b/bpkg/build.cxx index e9377ec..d2ec9e8 100644 --- a/bpkg/build.cxx +++ b/bpkg/build.cxx @@ -21,7 +21,7 @@ using namespace butl; namespace bpkg { - struct selected_package // @@ Swap names. + struct satisfied_package { shared_ptr ap; // Note: might be transient. @@ -29,7 +29,7 @@ namespace bpkg optional directory; }; - using packages = vector; + using packages = vector; void build (const build_options& o, cli::scanner& args) @@ -58,7 +58,7 @@ namespace bpkg { const char* s (args.next ()); - selected_package pkg; + satisfied_package pkg; // Reduce all the potential variations (archive, directory, // package, package version) to the single available_package @@ -158,9 +158,9 @@ namespace bpkg // package that we will be building (which may or may not be // the same as the selected package). // - shared_ptr p (db.find (n)); + shared_ptr p (db.find (n)); - if (p != nullptr && p->state == state::broken) + if (p != nullptr && p->state == package_state::broken) fail << "unable to build broken package " << n << info << "use 'pkg-purge --force' to remove"; @@ -215,7 +215,7 @@ namespace bpkg // can get its manifest. // ap = make_shared ( - p->state == state::fetched + p->state == package_state::fetched ? pkg_verify (o, *p->archive) : pkg_verify (*p->src_root)); } diff --git a/bpkg/forward b/bpkg/forward index cddc89f..9ca44b6 100644 --- a/bpkg/forward +++ b/bpkg/forward @@ -14,7 +14,7 @@ namespace bpkg // // - class package; + class selected_package; } #endif // BPKG_FORWARD diff --git a/bpkg/package b/bpkg/package index 04cb821..ac0ac0f 100644 --- a/bpkg/package +++ b/bpkg/package @@ -312,9 +312,9 @@ namespace bpkg std::pair, shared_ptr> filter_one (const shared_ptr&, odb::result&&); - // state + // package_state // - enum class state + enum class package_state { broken, fetched, @@ -323,31 +323,30 @@ namespace bpkg }; string - to_string (state); + to_string (package_state); - state - to_state (const string&); // May throw invalid_argument. + package_state + to_package_state (const string&); // May throw invalid_argument. inline std::ostream& - operator<< (std::ostream& os, state s) {return os << to_string (s);} + operator<< (std::ostream& os, package_state s) {return os << to_string (s);} - #pragma db map type(state) as(string) \ - to(to_string (?)) \ - from(bpkg::to_state (?)) + #pragma db map type(package_state) as(string) \ + to(to_string (?)) \ + from(bpkg::to_package_state (?)) // package // #pragma db object pointer(shared_ptr) session - class package + class selected_package { public: using version_type = bpkg::version; - using state_type = bpkg::state; string name; // Object id. version_type version; - state_type state; + package_state state; // Repository from which this package came. Note that it is not // a pointer to the repository object because it could be wiped @@ -390,7 +389,7 @@ namespace bpkg // A map of "effective" prerequisites (i.e., pointers to other // selected packages) to optional dependency constraint. // - using prerequisites_type = std::map, + using prerequisites_type = std::map, optional, compare_lazy_ptr>; prerequisites_type prerequisites; @@ -404,16 +403,16 @@ namespace bpkg private: friend class odb::access; - package () = default; + selected_package () = default; }; // Return a list of packages that depend on this package along with // their constraints. // /* - #pragma db view object(package) \ - container(package::prerequisites = pp inner: pp.key) - struct package_dependents + #pragma db view object(selected_package) \ + container(selected_package::prerequisites = pp inner: pp.key) + struct package_dependent { #pragma db column(pp.id) string name; @@ -426,10 +425,10 @@ namespace bpkg // @@ Using raw container table since ODB doesn't support containers // in views yet. // - #pragma db view object(package) \ - table("package_prerequisites" = "pp" inner: \ - "pp.prerequisite = " + package::name) - struct package_dependents + #pragma db view object(selected_package) \ + table("selected_package_prerequisites" = "pp" inner: \ + "pp.prerequisite = " + selected_package::name) + struct package_dependent { #pragma db column("pp.package") string name; diff --git a/bpkg/package.cxx b/bpkg/package.cxx index e764c3f..2612cbe 100644 --- a/bpkg/package.cxx +++ b/bpkg/package.cxx @@ -124,26 +124,26 @@ namespace bpkg // state // string - to_string (state s) + to_string (package_state s) { switch (s) { - case state::broken: return "broken"; - case state::fetched: return "fetched"; - case state::unpacked: return "unpacked"; - case state::configured: return "configured"; + case package_state::broken: return "broken"; + case package_state::fetched: return "fetched"; + case package_state::unpacked: return "unpacked"; + case package_state::configured: return "configured"; } return string (); // Should never reach. } - state - to_state (const string& s) + package_state + to_package_state (const string& s) { - if (s == "broken") return state::broken; - else if (s == "fetched") return state::fetched; - else if (s == "unpacked") return state::unpacked; - else if (s == "configured") return state::configured; + if (s == "broken") return package_state::broken; + else if (s == "fetched") return package_state::fetched; + else if (s == "unpacked") return package_state::unpacked; + else if (s == "configured") return package_state::configured; else throw invalid_argument ("invalid package state '" + s + "'"); } } diff --git a/bpkg/package.xml b/bpkg/package.xml index 9935e06..79d7ac7 100644 --- a/bpkg/package.xml +++ b/bpkg/package.xml @@ -152,7 +152,7 @@ - +
@@ -169,7 +169,7 @@
- +
@@ -179,16 +179,16 @@ - + - + - + diff --git a/bpkg/pkg-command.cxx b/bpkg/pkg-command.cxx index fc8deb9..39caa8e 100644 --- a/bpkg/pkg-command.cxx +++ b/bpkg/pkg-command.cxx @@ -36,13 +36,13 @@ namespace bpkg database db (open (c, trace)); transaction t (db.begin ()); - shared_ptr p (db.find (n)); + shared_ptr p (db.find (n)); t.commit (); if (p == nullptr) fail << "package " << n << " does not exist in configuration " << c; - if (p->state != state::configured) + if (p->state != package_state::configured) fail << "package " << n << " is " << p->state << info << "expected it to be configured"; diff --git a/bpkg/pkg-configure.cxx b/bpkg/pkg-configure.cxx index 208fad4..c76fae9 100644 --- a/bpkg/pkg-configure.cxx +++ b/bpkg/pkg-configure.cxx @@ -53,12 +53,12 @@ namespace bpkg transaction t (db.begin ()); session s; - shared_ptr p (db.find (n)); + shared_ptr p (db.find (n)); if (p == nullptr) fail << "package " << n << " does not exist in configuration " << c; - if (p->state != state::unpacked) + if (p->state != package_state::unpacked) fail << "package " << n << " is " << p->state << info << "expected it to be unpacked"; @@ -91,9 +91,11 @@ namespace bpkg bool satisfied (false); for (const dependency& d: da) { - if (shared_ptr dp = db.find (d.name)) + const string& n (d.name); + + if (shared_ptr dp = db.find (n)) { - if (dp->state != state::configured) + if (dp->state != package_state::configured) continue; if (!satisfies (dp->version, d.constraint)) @@ -113,8 +115,8 @@ namespace bpkg if (!s1 && !s2) fail << "incompatible constraints " - << "(" << d.name << " " << *c << ") and " - << "(" << d.name << " " << *d.constraint << ")"; + << "(" << n << " " << *c << ") and " + << "(" << n << " " << *d.constraint << ")"; if (s2 && !s1) c = d.constraint; @@ -161,14 +163,14 @@ namespace bpkg // Indicate to pkg_disfigure() we are partially configured. // p->out_root = out_root.leaf (); - p->state = state::broken; + p->state = package_state::broken; pkg_disfigure (c, t, p); // Commits the transaction. throw; } p->out_root = out_root.leaf (); - p->state = state::configured; + p->state = package_state::configured; db.update (p); t.commit (); diff --git a/bpkg/pkg-disfigure b/bpkg/pkg-disfigure index 2df892b..ef78d05 100644 --- a/bpkg/pkg-disfigure +++ b/bpkg/pkg-disfigure @@ -6,7 +6,7 @@ #define BPKG_PKG_DISFIGURE #include -#include // transaction, package +#include // transaction, selected_package #include namespace bpkg @@ -23,7 +23,7 @@ namespace bpkg void pkg_disfigure (const dir_path& configuration, transaction&, - const shared_ptr&); + const shared_ptr&); } #endif // BPKG_PKG_DISFIGURE diff --git a/bpkg/pkg-disfigure.cxx b/bpkg/pkg-disfigure.cxx index a3d0336..d9e5552 100644 --- a/bpkg/pkg-disfigure.cxx +++ b/bpkg/pkg-disfigure.cxx @@ -19,9 +19,10 @@ namespace bpkg void pkg_disfigure (const dir_path& c, transaction& t, - const shared_ptr& p) + const shared_ptr& p) { - assert (p->state == state::configured || p->state == state::broken); + assert (p->state == package_state::configured || + p->state == package_state::broken); tracer trace ("pkg_disfigure"); @@ -30,18 +31,18 @@ namespace bpkg // Check that we have no dependents. // - if (p->state == state::configured) + if (p->state == package_state::configured) { - using query = query; + using query = query; - auto r (db.query (query::name == p->name)); + auto r (db.query (query::name == p->name)); if (!r.empty ()) { diag_record dr; dr << fail << "package " << p->name << " still has dependencies:"; - for (const package_dependents& pd: r) + for (const package_dependent& pd: r) { dr << info << "package " << pd.name; @@ -72,7 +73,7 @@ namespace bpkg // string bspec; - if (p->state == state::configured) + if (p->state == package_state::configured) { bspec = "clean(" + out_root.string () + "/) " "disfigure(" + out_root.string () + "/)"; @@ -110,7 +111,7 @@ namespace bpkg // If we failed to disfigure the package, set it to the broken // state. The user can then try to clean things up with pkg-purge. // - p->state = state::broken; + p->state = package_state::broken; db.update (p); t.commit (); @@ -120,7 +121,7 @@ namespace bpkg } p->out_root = nullopt; - p->state = state::unpacked; + p->state = package_state::unpacked; db.update (p); t.commit (); @@ -143,12 +144,12 @@ namespace bpkg database db (open (c, trace)); transaction t (db.begin ()); - shared_ptr p (db.find (n)); + shared_ptr p (db.find (n)); if (p == nullptr) fail << "package " << n << " does not exist in configuration " << c; - if (p->state != state::configured) + if (p->state != package_state::configured) fail << "package " << n << " is " << p->state << info << "expected it to be configured"; diff --git a/bpkg/pkg-fetch.cxx b/bpkg/pkg-fetch.cxx index 4a2a9ea..14022e8 100644 --- a/bpkg/pkg-fetch.cxx +++ b/bpkg/pkg-fetch.cxx @@ -120,7 +120,7 @@ namespace bpkg // See if this package already exists in this configuration. // - if (shared_ptr p = db.find (n)) + if (shared_ptr p = db.find (n)) fail << "package " << n << " already exists in configuration " << c << info << "version: " << p->version << ", state: " << p->state; @@ -136,10 +136,10 @@ namespace bpkg // Add the package to the configuration. // - shared_ptr p (new package { + shared_ptr p (new selected_package { move (m.name), move (m.version), - state::fetched, + package_state::fetched, move (rl), move (a), purge, diff --git a/bpkg/pkg-purge.cxx b/bpkg/pkg-purge.cxx index 76101ef..5e14a2b 100644 --- a/bpkg/pkg-purge.cxx +++ b/bpkg/pkg-purge.cxx @@ -33,7 +33,7 @@ namespace bpkg database db (open (c, trace)); transaction t (db.begin ()); - shared_ptr p (db.find (n)); + shared_ptr p (db.find (n)); if (p == nullptr) fail << "package " << n << " does not exist in configuration " << c; @@ -42,7 +42,7 @@ namespace bpkg // switch (p->state) { - case state::fetched: + case package_state::fetched: { // If we have --keep, then this is a no-op. We could have // detected this and returned but we still want the normal @@ -51,14 +51,14 @@ namespace bpkg // break; } - case state::unpacked: + case package_state::unpacked: { if (o.keep () && !p->archive) fail << "package " << n << " has no archive to keep"; break; } - case state::broken: + case package_state::broken: { if (!o.force ()) fail << "broken package " << n << " can only be purged with --force"; @@ -80,7 +80,7 @@ namespace bpkg { dir_path d (p->src_root->absolute () ? *p->src_root : c / *p->src_root); - if (p->state != state::broken) + if (p->state != package_state::broken) { try { @@ -92,7 +92,7 @@ namespace bpkg } catch (const failed&) { - p->state = state::broken; + p->state = package_state::broken; db.update (p); t.commit (); @@ -116,7 +116,9 @@ namespace bpkg // if (p->out_root) { - assert (p->state == state::broken); // Can only be present if broken. + // Can only be present if broken. + // + assert (p->state == package_state::broken); dir_path d (c / *p->out_root); // Always relative. @@ -131,7 +133,7 @@ namespace bpkg { path a (p->archive->absolute () ? *p->archive : c / *p->archive); - if (p->state != state::broken) + if (p->state != package_state::broken) { try { @@ -143,7 +145,7 @@ namespace bpkg } catch (const failed&) { - p->state = state::broken; + p->state = package_state::broken; db.update (p); t.commit (); @@ -162,9 +164,9 @@ namespace bpkg if (o.keep ()) { - if (p->state != state::fetched) // That no-op we were talking about. + if (p->state != package_state::fetched) // No-op we were talking about. { - p->state = state::fetched; + p->state = package_state::fetched; db.update (p); } } diff --git a/bpkg/pkg-status.cxx b/bpkg/pkg-status.cxx index 196106a..c1cd12f 100644 --- a/bpkg/pkg-status.cxx +++ b/bpkg/pkg-status.cxx @@ -46,15 +46,15 @@ namespace bpkg // First search in the packages that already exist in this configuration. // - shared_ptr p; + shared_ptr p; { - using query = query; + using query = query; query q (query::name == n); if (!v.empty ()) q = q && query::version == v; - p = db.query_one (q); + p = db.query_one (q); } // Now look for available packages. If the user specified the version diff --git a/bpkg/pkg-unpack.cxx b/bpkg/pkg-unpack.cxx index 32d2af3..a7c53b6 100644 --- a/bpkg/pkg-unpack.cxx +++ b/bpkg/pkg-unpack.cxx @@ -22,7 +22,7 @@ using namespace butl; namespace bpkg { - static shared_ptr + static shared_ptr pkg_unpack (database& db, const dir_path& c, const dir_path& d, bool purge) { tracer trace ("pkg_unpack(dir)"); @@ -42,7 +42,7 @@ namespace bpkg // See if this package already exists in this configuration. // - if (shared_ptr p = db.find (n)) + if (shared_ptr p = db.find (n)) fail << "package " << n << " already exists in configuration " << c << info << "version: " << p->version << ", state: " << p->state; @@ -60,10 +60,10 @@ namespace bpkg // Add the package to the configuration. Use the special root // repository as the repository of this package. // - shared_ptr p (new package { + shared_ptr p (new selected_package { move (m.name), move (m.version), - state::unpacked, + package_state::unpacked, repository_location (), nullopt, // No archive false, // Don't purge archive. @@ -79,7 +79,7 @@ namespace bpkg return p; } - static shared_ptr + static shared_ptr pkg_unpack (const common_options& co, database& db, const dir_path& c, @@ -89,12 +89,12 @@ namespace bpkg tracer_guard tg (db, trace); transaction t (db.begin ()); - shared_ptr p (db.find (name)); + shared_ptr p (db.find (name)); if (p == nullptr) fail << "package " << name << " does not exist in configuration " << c; - if (p->state != state::fetched) + if (p->state != package_state::fetched) fail << "package " << name << " is " << p->state << info << "expected it to be fetched"; @@ -169,7 +169,7 @@ namespace bpkg p->src_root = d.leaf (); // For now assuming to be in configuration. p->purge_src = true; - p->state = state::unpacked; + p->state = package_state::unpacked; db.update (p); t.commit (); @@ -189,7 +189,7 @@ namespace bpkg database db (open (c, trace)); - shared_ptr p; + shared_ptr p; if (o.existing ()) { -- cgit v1.1