From 780290277a51853b2e515b16898ca0fcfa1e9e71 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Mon, 26 Feb 2018 22:00:22 +0300 Subject: Update rep-fetch --- bpkg/rep-add.cxx | 68 ++++++++++++++++++++++++++++++-------------------------- 1 file changed, 37 insertions(+), 31 deletions(-) (limited to 'bpkg/rep-add.cxx') diff --git a/bpkg/rep-add.cxx b/bpkg/rep-add.cxx index 690b584..2dcce9a 100644 --- a/bpkg/rep-add.cxx +++ b/bpkg/rep-add.cxx @@ -15,6 +15,42 @@ using namespace butl; namespace bpkg { + shared_ptr + rep_add (database& db, const repository_location& rl) + { + const string& rn (rl.canonical_name ()); + + shared_ptr r (db.find (rn)); + + bool updated (false); + + if (r == nullptr) + { + r.reset (new repository (rl)); + db.persist (r); + } + else if (r->location.url () != rl.url ()) + { + r->location = rl; + db.update (r); + + updated = true; + } + + shared_ptr root (db.load ("")); + + bool added ( + root->complements.insert (lazy_shared_ptr (db, r)).second); + + if (added) + db.update (root); + + if (verb) + text << (added ? "added " : updated ? "updated " : "unchanged ") << rn; + + return r; + } + int rep_add (const rep_add_options& o, cli::scanner& args) { @@ -31,8 +67,6 @@ namespace bpkg transaction t (db.begin ()); session s; // Repository dependencies can have cycles. - shared_ptr root (db.load ("")); - while (args.more ()) { repository_location rl ( @@ -41,37 +75,9 @@ namespace bpkg ? optional (o.type ()) : nullopt)); - const string& rn (rl.canonical_name ()); - - // Create the new repository if it is not in the database yet. Otherwise - // update its location. Add it as a complement to the root repository (if - // it is not there yet). - // - shared_ptr r (db.find (rn)); - - bool updated (false); - - if (r == nullptr) - { - r.reset (new repository (rl)); - db.persist (r); - } - else if (r->location.url () != rl.url ()) - { - r->location = rl; - db.update (r); - - updated = true; - } - - bool added ( - root->complements.insert (lazy_shared_ptr (db, r)).second); - - if (verb) - text << (added ? "added " : updated ? "updated " : "unchanged ") << rn; + rep_add (db, rl); } - db.update (root); t.commit (); return 0; -- cgit v1.1