aboutsummaryrefslogtreecommitdiff
path: root/libbpkg
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2018-06-12 22:00:33 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2018-06-15 15:40:08 +0300
commitbc45d34e6606ce31b2c11d3120b0eea20c547199 (patch)
treeb1d94d677672e448783957784d4a680b1a773a75 /libbpkg
parent8fe369a00e4c230f10611361942086709e2d4f1b (diff)
Default version epoch to one
Diffstat (limited to 'libbpkg')
-rw-r--r--libbpkg/manifest.cxx32
-rw-r--r--libbpkg/manifest.hxx2
2 files changed, 26 insertions, 8 deletions
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[+<revision>]' form (stubs) and one
+ // otherwise. Used for both version and version::data_type types.
+ //
+ template <typename T>
+ 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<uint16_t> 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);
diff --git a/libbpkg/manifest.hxx b/libbpkg/manifest.hxx
index 5e7a748..fc6c332 100644
--- a/libbpkg/manifest.hxx
+++ b/libbpkg/manifest.hxx
@@ -50,7 +50,7 @@ namespace bpkg
const std::string canonical_release;
// Create a special empty version. It is less than any other valid
- // version (and is conceptually equivalent to 0-).
+ // version (and is conceptually equivalent to +0-0-).
//
version (): epoch (0), release (""), revision (0), iteration (0) {}