From bc45d34e6606ce31b2c11d3120b0eea20c547199 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Tue, 12 Jun 2018 22:00:33 +0300 Subject: Default version epoch to one --- libbpkg/manifest.cxx | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) (limited to 'libbpkg/manifest.cxx') diff --git a/libbpkg/manifest.cxx b/libbpkg/manifest.cxx index f155c5a..0fa2a4c 100644 --- a/libbpkg/manifest.cxx +++ b/libbpkg/manifest.cxx @@ -238,8 +238,18 @@ namespace bpkg size_t len_ = 0; // Length without the trailing digit-only zero components. }; + // Return zero for versions having the '0[+]' form (stubs) and one + // otherwise. Used for both version and version::data_type types. + // + template + inline static uint16_t + default_epoch (const T& v) + { + return v.canonical_upstream.empty () && !v.release ? 0 : 1; + } + version::data_type:: - data_type (const char* v, parse pr): epoch (0), revision (0) + data_type (const char* v, parse pr): revision (0) { // Otherwise compiler gets confused with string() member. // @@ -255,6 +265,8 @@ namespace bpkg assert (v != nullptr); + optional ep; + auto bad_arg = [](const string& d) {throw invalid_argument (d);}; auto uint16 = [&bad_arg](const string& s, const char* what) -> uint16_t @@ -331,7 +343,7 @@ namespace bpkg if (lnn >= cb) // Contains non-digits. bad_arg ("epoch should be 2-byte unsigned integer"); - epoch = uint16 (string (cb, p), "epoch"); + ep = uint16 (string (cb, p), "epoch"); } else canon_part->add (cb, p, lnn < cb); @@ -467,11 +479,17 @@ namespace bpkg } } - if (pr == parse::full && epoch == 0 && canonical_upstream.empty () && - canonical_release.empty ()) + if (pr == parse::full) { - assert (revision == 0); // Can't happen if through all previous checks. - bad_arg ("empty version"); + epoch = ep ? *ep : default_epoch (*this); + + if (epoch == 0 && + canonical_upstream.empty () && + canonical_release.empty ()) + { + assert (revision == 0); // Can't happen if through all previous checks. + bad_arg ("empty version"); + } } } @@ -502,7 +520,7 @@ namespace bpkg if (empty ()) throw logic_error ("empty version"); - std::string v (epoch != 0 + std::string v (epoch != default_epoch (*this) ? '+' + to_string (epoch) + '-' + upstream : upstream); -- cgit v1.1