From acf830d519ba2b467f5eb0968b44a514b1b0e2b3 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 14 Mar 2018 10:27:26 +0200 Subject: Don't print pointless "fetching ..." line if fetching single repository --- bpkg/pkg-build.cxx | 7 ++++++- bpkg/rep-fetch.cxx | 39 ++++++++++++++++++++++++++++----------- bpkg/rep-fetch.hxx | 5 ++++- 3 files changed, 38 insertions(+), 13 deletions(-) diff --git a/bpkg/pkg-build.cxx b/bpkg/pkg-build.cxx index a8e90aa..28105d4 100644 --- a/bpkg/pkg-build.cxx +++ b/bpkg/pkg-build.cxx @@ -1196,7 +1196,12 @@ namespace bpkg } if (!locations.empty ()) - rep_fetch (o, c, db, locations, o.fetch_shallow ()); + rep_fetch (o, + c, + db, + locations, + o.fetch_shallow (), + string () /* reason for "fetching ..." */); // Expand @ arguments. // diff --git a/bpkg/rep-fetch.cxx b/bpkg/rep-fetch.cxx index 1f0f893..b443118 100644 --- a/bpkg/rep-fetch.cxx +++ b/bpkg/rep-fetch.cxx @@ -425,6 +425,8 @@ namespace bpkg using repositories = set>; + // If reason is absent, then don't print the "fetching ..." progress line. + // static void rep_fetch (const common_options& co, const dir_path& conf, @@ -433,7 +435,7 @@ namespace bpkg repositories& fetched, repositories& removed, bool shallow, - const string& reason = string ()) + const optional& reason) { tracer trace ("rep_fetch(rep)"); @@ -460,17 +462,17 @@ namespace bpkg // removed.erase (r); - // The fetch_*() functions below will be quiet at level 1, which - // can be quite confusing if the download hangs. + // The fetch_*() functions below will be quiet at level 1, which can be + // quite confusing if the download hangs. // - if (verb) + if (verb && reason) { diag_record dr (text); dr << "fetching " << r->name; - if (!reason.empty ()) - dr << " (" << reason << ")"; + if (!reason->empty ()) + dr << " (" << *reason << ")"; } // Load the repository and package manifests and use them to populate the @@ -752,7 +754,8 @@ namespace bpkg const dir_path& conf, transaction& t, const vector>& repos, - bool shallow) + bool shallow, + const optional& reason) { // As a fist step we fetch repositories recursively building the list of // the former prerequisites and complements to be considered for removal. @@ -772,7 +775,7 @@ namespace bpkg repositories removed; for (const lazy_shared_ptr& r: repos) - rep_fetch (o, conf, t, r.load (), fetched, removed, shallow); + rep_fetch (o, conf, t, r.load (), fetched, removed, shallow, reason); // Finally, remove dangling repositories. // @@ -803,7 +806,8 @@ namespace bpkg const dir_path& conf, database& db, const vector& rls, - bool shallow) + bool shallow, + const optional& reason) { assert (session::has_current ()); @@ -828,7 +832,7 @@ namespace bpkg repos.emplace_back (r); } - rep_fetch (o, conf, t, repos, shallow); + rep_fetch (o, conf, t, repos, shallow, reason); t.commit (); } @@ -852,12 +856,19 @@ namespace bpkg shared_ptr root (db.load ("")); repository::complements_type& ua (root->complements); // User-added repos. + optional reason; + if (!args.more ()) { if (ua.empty ()) fail << "configuration " << c << " has no repositories" << info << "use 'bpkg rep-add' to add a repository"; + // Always print "fetching ..." for complements of the root, even if + // there is only one. + // + reason = ""; + for (const lazy_shared_ptr& r: ua) repos.push_back (r); } @@ -897,9 +908,15 @@ namespace bpkg repos.emplace_back (move (r)); } + + // If the user specified a single repository, then don't insult them + // with a pointless "fetching ..." line for this repository. + // + if (repos.size () > 1) + reason = ""; } - rep_fetch (o, c, t, repos, o.shallow ()); + rep_fetch (o, c, t, repos, o.shallow (), reason); size_t rcount (0), pcount (0); if (verb) diff --git a/bpkg/rep-fetch.hxx b/bpkg/rep-fetch.hxx index 18a50e9..89f4f2a 100644 --- a/bpkg/rep-fetch.hxx +++ b/bpkg/rep-fetch.hxx @@ -56,12 +56,15 @@ namespace bpkg // the configuration (see rep_remove_clean() for details). Note that it // should be called in session. // + // If reason is absent, then don't print the "fetching ..." progress line. + // void rep_fetch (const common_options&, const dir_path& conf, database&, const vector&, - bool shallow); + bool shallow, + const optional& reason); } #endif // BPKG_REP_FETCH_HXX -- cgit v1.1