From 4fcd32b536f3d29755b1fecc7e3f06be64f996ca Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Sat, 24 Feb 2018 18:21:39 +0300 Subject: Add support for rep-list and rep-remove, update rep-add --- bpkg/rep-add.cxx | 62 ++++++++++++++++++++++++++++++++------------------------ 1 file changed, 36 insertions(+), 26 deletions(-) (limited to 'bpkg/rep-add.cxx') diff --git a/bpkg/rep-add.cxx b/bpkg/rep-add.cxx index 7adb843..690b584 100644 --- a/bpkg/rep-add.cxx +++ b/bpkg/rep-add.cxx @@ -27,43 +27,53 @@ namespace bpkg fail << "repository location argument expected" << info << "run 'bpkg help rep-add' for more information"; - repository_location rl ( - parse_location (args.next (), - o.type_specified () - ? optional (o.type ()) - : nullopt)); - - const string& rn (rl.canonical_name ()); - - // Create the new repository and add is as a complement to the root. - // database db (open (c, trace)); transaction t (db.begin ()); session s; // Repository dependencies can have cycles. - // It is possible that this repository is already in the database. - // For example, it might be a prerequisite of one of the already - // added repository. - // - shared_ptr r (db.find (rl.canonical_name ())); + shared_ptr root (db.load ("")); - if (r == nullptr) + while (args.more ()) { - r.reset (new repository (rl)); - db.persist (r); + repository_location rl ( + parse_location (args.next (), + o.type_specified () + ? 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; } - shared_ptr root (db.load ("")); - - if (!root->complements.insert (lazy_shared_ptr (db, r)).second) - fail << rn << " is already a repository of this configuration"; - db.update (root); t.commit (); - if (verb) - text << "added repository " << rn; - return 0; } } -- cgit v1.1