diff options
Diffstat (limited to 'bpkg')
-rw-r--r-- | bpkg/manifest | 49 | ||||
-rw-r--r-- | bpkg/manifest.cxx | 31 |
2 files changed, 61 insertions, 19 deletions
diff --git a/bpkg/manifest b/bpkg/manifest index 6f3dc13..a4bf6f2 100644 --- a/bpkg/manifest +++ b/bpkg/manifest @@ -27,10 +27,26 @@ namespace bpkg version (): epoch_ (0), revision_ (0) {} explicit - version (const char*); + version (const std::string& v): version (v.c_str ()) /* Delegate */ {} explicit - version (const std::string& v): version (v.c_str ()) /* Delegate */ {} + version (const char* v): version (v, false) /* Delegate */ {} + + // Create the version object from separate epoch, upstream, and + // revision parts. + // + version (std::uint16_t epoch, + std::string upstream, + std::uint16_t revision) + : version (upstream.c_str (), true) // Delegate + + { + // Can't initialize in member initializer list due to construction + // delegation. + // + epoch_ = epoch; + revision_ = revision; + } std::uint16_t epoch () const noexcept {return epoch_;} @@ -42,7 +58,7 @@ namespace bpkg upstream () const noexcept {return upstream_;} const std::string& - canonical_upstream () const noexcept {return canonical_;} + canonical_upstream () const noexcept {return canonical_upstream_;} std::string string () const @@ -77,7 +93,7 @@ namespace bpkg if (epoch_ != v.epoch_) return epoch_ < v.epoch_ ? -1 : 1; - if (int c = canonical_.compare (v.canonical_)) + if (int c = canonical_upstream_.compare (v.canonical_upstream_)) return c; if (!ignore_revision && revision_ != v.revision_) @@ -89,8 +105,8 @@ namespace bpkg bool empty () const noexcept { - // No sense to test epoch_ and revision_ for 0 as properly constructed - // version object can not have them different from 0 if upstream_ is + // No sense to test epoch and revision for 0 as properly constructed + // version object can not have them different from 0 if upstream is // empty. Returns true only for objects constructed with the default // constructor. // @@ -98,10 +114,16 @@ namespace bpkg } private: + version (const char*, bool upstream_only); + + private: + // Let's keep the members in the order they appear in the string + // representation. + // std::uint16_t epoch_; - std::uint16_t revision_; std::string upstream_; - std::string canonical_; // Upstream part canonical representation. + std::uint16_t revision_; + std::string canonical_upstream_; // Upstream part canonical representation. }; // priority @@ -205,7 +227,7 @@ namespace bpkg struct dependency { - std::string name; + std::string package; butl::optional<version_comparison> version; }; @@ -263,6 +285,15 @@ namespace bpkg serialize (manifest_serializer&) const; }; + class repository_location + { + // @@ Move all the location verification/canonical name calculation + // here. + // + + // ... + }; + class repository_manifest { public: diff --git a/bpkg/manifest.cxx b/bpkg/manifest.cxx index 149c743..2576bea 100644 --- a/bpkg/manifest.cxx +++ b/bpkg/manifest.cxx @@ -52,7 +52,7 @@ namespace bpkg static ostream& operator<< (ostream& o, const dependency& d) { - o << d.name; + o << d.package; if (d.version) { @@ -173,7 +173,7 @@ namespace bpkg // version // version:: - version (const char* v): version () // Delegate + version (const char* v, bool upstream_only): version () // Delegate { using std::string; // Otherwise compiler get confused with string() member. @@ -195,18 +195,18 @@ namespace bpkg auto add_canonical_component ( [this, &bad_arg](const char* b, const char* e, bool numeric) -> bool { - if (!canonical_.empty ()) - canonical_.append (1, '.'); + if (!canonical_upstream_.empty ()) + canonical_upstream_.append (1, '.'); if (numeric) { if (e - b > 8) bad_arg ("8 digits maximum allowed in a component"); - canonical_.append (8 - (e - b), '0'); // Add padding spaces. + canonical_upstream_.append (8 - (e - b), '0'); // Add padding spaces. string c (b, e); - canonical_.append (c); + canonical_upstream_.append (c); return stoul (c) != 0; } else @@ -218,7 +218,8 @@ namespace bpkg for (const char* i (b); i != e; ++i) { char c (*i); - canonical_.append (1, c >= 'A' && c <='Z' ? c + shift : c); + canonical_upstream_.append ( + 1, c >= 'A' && c <='Z' ? c + shift : c); } return true; @@ -244,6 +245,9 @@ namespace bpkg { case '+': { + if (upstream_only) + bad_arg ("unexpected '+' character"); + if (mode != epoch || p == v) bad_arg ("unexpected '+' character position"); @@ -258,13 +262,20 @@ namespace bpkg } case '-': + { + if (upstream_only) + bad_arg ("unexpected '-' character"); + + // No break, go to the next case. + } + case '.': { if (mode != epoch && mode != upstream || p == cb) bad_arg (string ("unexpected '") + c + "' character position"); if (add_canonical_component (cb, p, lnn < cb)) - cl = canonical_.size (); + cl = canonical_upstream_.size (); ue = p; mode = c == '-' ? revision : upstream; @@ -295,14 +306,14 @@ namespace bpkg else { if (add_canonical_component (cb, p, lnn < cb)) - cl = canonical_.size (); + cl = canonical_upstream_.size (); ue = p; } assert (ub != ue); // Can't happen if through all previous checks. upstream_.assign (ub, ue); - canonical_.resize (cl); + canonical_upstream_.resize (cl); } // package_manifest |