From b83a9bbdb0407c198e615e61491e1f8492ae5dc9 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 5 Oct 2015 08:45:27 +0200 Subject: Add repository location to package, minor cleanups --- bpkg/package.cxx | 49 +++++++++++++++++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 14 deletions(-) (limited to 'bpkg/package.cxx') diff --git a/bpkg/package.cxx b/bpkg/package.cxx index 02cb49d..e764c3f 100644 --- a/bpkg/package.cxx +++ b/bpkg/package.cxx @@ -40,35 +40,54 @@ namespace bpkg // 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. + // Check if the package is available from the specified repository, + // its prerequisite repositories, or one of their complements, + // recursively. Return the first repository that contains the + // package or NULL if none are. // static shared_ptr find (const shared_ptr& r, - const shared_ptr& ap) + const shared_ptr& ap, + bool prereq = true) { + const auto& ps (r->prerequisites); const auto& cs (r->complements); for (const package_location& pl: ap->locations) { + const lazy_shared_ptr& lr (pl.repository); + // First check the repository itself. // - if (pl.repository.object_id () == r->name) + if (lr.object_id () == r->name) return r; - // Then check all the complements without loading them. + // Then check all the complements and prerequisites without + // loading them. // - if (cs.find (pl.repository) != cs.end ()) - return pl.repository.load (); + if (cs.find (lr) != cs.end () || (prereq && ps.find (lr) != ps.end ())) + return lr.load (); - // Finally, load the complements and check them recursively. + // Finally, load the complements and prerequisites and check them + // recursively. // for (const lazy_shared_ptr& cr: cs) { - if (shared_ptr r = find (cr.load (), ap)) + // Should we consider prerequisites of our complements as our + // prerequisites? I'd say not. + // + if (shared_ptr r = find (cr.load (), ap, false)) return r; } + + if (prereq) + { + for (const lazy_weak_ptr& pr: ps) + { + if (shared_ptr r = find (pr.load (), ap, false)) + return r; + } + } } return nullptr; @@ -88,16 +107,18 @@ namespace bpkg return aps; } - shared_ptr + pair, shared_ptr> filter_one (const shared_ptr& r, result&& apr) { + using result = pair, shared_ptr>; + for (shared_ptr ap: pointer_result (apr)) { - if (find (r, ap) != nullptr) - return ap; + if (shared_ptr pr = find (r, ap)) + return result (move (ap), move (pr)); } - return nullptr; + return result (); } // state -- cgit v1.1