aboutsummaryrefslogtreecommitdiff
path: root/bpkg/rep-add.cxx
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2018-02-24 18:21:39 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2018-02-26 17:50:24 +0300
commit4fcd32b536f3d29755b1fecc7e3f06be64f996ca (patch)
tree4aebf6eeb7ac4de316ddc91b92c264f252f86d44 /bpkg/rep-add.cxx
parent12a5375f25d6a7be5a5741c728a8f9b8168761a4 (diff)
Add support for rep-list and rep-remove, update rep-add
Diffstat (limited to 'bpkg/rep-add.cxx')
-rw-r--r--bpkg/rep-add.cxx62
1 files changed, 36 insertions, 26 deletions
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<repository_type> (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<repository> r (db.find<repository> (rl.canonical_name ()));
+ shared_ptr<repository> root (db.load<repository> (""));
- 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<repository_type> (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<repository> r (db.find<repository> (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<repository> (db, r)).second);
+
+ if (verb)
+ text << (added ? "added " : updated ? "updated " : "unchanged ") << rn;
}
- shared_ptr<repository> root (db.load<repository> (""));
-
- if (!root->complements.insert (lazy_shared_ptr<repository> (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;
}
}