diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2015-10-01 09:13:37 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2015-10-01 09:13:37 +0200 |
commit | 098460199c35218979e207a1709111e477ab9567 (patch) | |
tree | 55765e91a517759bf28672abeda96102f2f511c4 /bpkg/package.cxx | |
parent | 42bbdd0e7f0d78b622697bf4d4543c1aead22ae8 (diff) |
build command genesis, some re-factoring
Diffstat (limited to 'bpkg/package.cxx')
-rw-r--r-- | bpkg/package.cxx | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/bpkg/package.cxx b/bpkg/package.cxx index ad54e51..c6f5dcf 100644 --- a/bpkg/package.cxx +++ b/bpkg/package.cxx @@ -3,9 +3,12 @@ // license : MIT; see accompanying LICENSE file #include <bpkg/package> +#include <bpkg/package-odb> #include <stdexcept> // invalid_argument +#include <bpkg/database> + using namespace std; namespace bpkg @@ -34,6 +37,69 @@ namespace bpkg return xv.revision < yv.revision; } + // available_package + // + + // Check if the package is available from the specified repository or + // one of its complements, recursively. Return the first repository + // that contains the package or NULL if none are. + // + static shared_ptr<repository> + find (const shared_ptr<repository>& r, + const shared_ptr<available_package>& ap) + { + const auto& cs (r->complements); + + for (const package_location& pl: ap->locations) + { + // First check the repository itself. + // + if (pl.repository.object_id () == r->name) + return r; + + // Then check all the complements without loading them. + // + if (cs.find (pl.repository) != cs.end ()) + return pl.repository.load (); + + // Finally, load the complements and check them recursively. + // + for (const lazy_shared_ptr<repository>& cr: cs) + { + if (shared_ptr<repository> r = find (cr.load (), ap)) + return r; + } + } + + return nullptr; + } + + vector<shared_ptr<available_package>> + filter (const shared_ptr<repository>& r, result<available_package>&& apr) + { + vector<shared_ptr<available_package>> aps; + + for (shared_ptr<available_package> ap: pointer_result (apr)) + { + if (find (r, ap) != nullptr) + aps.push_back (move (ap)); + } + + return aps; + } + + shared_ptr<available_package> + filter_one (const shared_ptr<repository>& r, result<available_package>&& apr) + { + for (shared_ptr<available_package> ap: pointer_result (apr)) + { + if (find (r, ap) != nullptr) + return ap; + } + + return nullptr; + } + // state // string |