aboutsummaryrefslogtreecommitdiff
path: root/bpkg/rep-create.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2015-09-17 16:15:52 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2015-09-17 16:15:52 +0200
commitfaafff4814b4bfbbd043d13899c81115bd0f8604 (patch)
tree8d39839f49a4e88531c79b6ae411fd77b25f172b /bpkg/rep-create.cxx
parentd6be3b97cc3ce723ca3b2372c893b41aec16a9a4 (diff)
Detect packages that only differ in revision in rep-create
Diffstat (limited to 'bpkg/rep-create.cxx')
-rw-r--r--bpkg/rep-create.cxx44
1 files changed, 35 insertions, 9 deletions
diff --git a/bpkg/rep-create.cxx b/bpkg/rep-create.cxx
index 244ef03..4546224 100644
--- a/bpkg/rep-create.cxx
+++ b/bpkg/rep-create.cxx
@@ -28,8 +28,29 @@ using namespace butl;
namespace bpkg
{
- using package_key = pair<string, version>;
- using package_data = pair<path, package_manifest>;
+ struct package_key
+ {
+ string name;
+ bpkg::version version;
+
+ // There shouldn't be multiple revisions of the same package
+ // in a repository, thus we compare versions ignoring the
+ // revision.
+ //
+ bool
+ operator< (const package_key& y) const
+ {
+ int r (name.compare (y.name));
+ return r < 0 || (r == 0 && version.compare (y.version, true) < 0);
+ }
+ };
+
+ struct package_data
+ {
+ path archive;
+ package_manifest manifest;
+ };
+
using package_map = map<package_key, package_data>;
static void
@@ -83,17 +104,22 @@ namespace bpkg
//
m.location = a.leaf (root);
- package_key k (m.name, m.version); // Argument evaluation order.
- auto r (map.emplace (move (k), package_data (a, move (m))));
+ package_key k {m.name, m.version}; // Argument evaluation order.
+ auto r (map.emplace (move (k), package_data {a, move (m)}));
// Diagnose duplicates.
//
if (!r.second)
{
- const package_manifest& m (r.first->second.second);
-
- fail << "duplicate package " << m.name << " " << m.version <<
- info << "first package archive is " << r.first->second.first <<
+ const package_manifest& m (r.first->second.manifest);
+
+ // Strip the revision from the version we print in case the
+ // packages only differ in revisions and thus shouldn't be
+ // both in this repository.
+ //
+ fail << "duplicate package " << m.name << " "
+ << m.version.string (true) <<
+ info << "first package archive is " << r.first->second.archive <<
info << "second package archive is " << a;
}
}
@@ -164,7 +190,7 @@ namespace bpkg
for (const auto& p: pm)
{
- const package_manifest& m (p.second.second);
+ const package_manifest& m (p.second.manifest);
if (verb)
text << "adding " << m.name << " " << m.version;