aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-06-06 11:34:47 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-06-06 17:14:23 +0100
commit850cd4d6491d4405c24b03309f15a96aa12b71b6 (patch)
treec5348d38ef764e556f57c3b71bed02cd33364656
parent163289879e4df006071f23447eb08f81d0053452 (diff)
downloadpaludis-850cd4d6491d4405c24b03309f15a96aa12b71b6.tar.gz
paludis-850cd4d6491d4405c24b03309f15a96aa12b71b6.tar.xz
vso_ignore_leading_v
-rw-r--r--paludis/version_spec.cc22
-rw-r--r--paludis/version_spec.se2
-rw-r--r--paludis/version_spec_TEST.cc16
3 files changed, 39 insertions, 1 deletions
diff --git a/paludis/version_spec.cc b/paludis/version_spec.cc
index 0b36829..e6b24f6 100644
--- a/paludis/version_spec.cc
+++ b/paludis/version_spec.cc
@@ -110,6 +110,14 @@ VersionSpec::VersionSpec(const std::string & text, const VersionSpecOptions & op
/* parse */
SimpleParser parser(text);
+ if (options[vso_ignore_leading_v] && parser.consume(
+ options[vso_ignore_case] ? simple_parser::exact_ignoring_case("v") : simple_parser::exact("v")))
+ _imp->parts.push_back(make_named_values<VersionSpecComponent>(
+ n::number_value() = "",
+ n::text() = "",
+ n::type() = vsct_ignore
+ ));
+
std::string scm_str;
if (parser.consume((options[vso_ignore_case] ? simple_parser::exact_ignoring_case("scm") : simple_parser::exact("scm")) >> scm_str))
{
@@ -338,6 +346,18 @@ namespace
const VersionSpecComponent * const p1(v1 == v1_end ? &end_part : &*v1);
const VersionSpecComponent * const p2(v2 == v2_end ? &end_part : &*v2);
+ if (p1->type() == vsct_ignore)
+ {
+ ++v1;
+ continue;
+ }
+
+ if (p2->type() == vsct_ignore)
+ {
+ ++v2;
+ continue;
+ }
+
if (&end_part == p1 && &end_part == p2)
{
std::pair<R_, bool> result(comparator(*p1, v1, v1_end, *p2, v2, v2_end, 0));
@@ -493,6 +513,8 @@ VersionSpec::hash() const
{
if ((*r).number_value() == "0" && (*r).type() == vsct_revision)
continue;
+ if ((*r).type() == vsct_ignore)
+ continue;
std::size_t hh(result & h_mask);
result <<= 5;
diff --git a/paludis/version_spec.se b/paludis/version_spec.se
index 89adbc4..7dc046d 100644
--- a/paludis/version_spec.se
+++ b/paludis/version_spec.se
@@ -5,6 +5,7 @@ make_enum_VersionSpecComponentType()
{
prefix vsct
+ key vsct_ignore "An ignorable part (e.g. v in v1.23)"
key vsct_alpha "An alpha part"
key vsct_beta "A beta part"
key vsct_pre "A pre part"
@@ -37,6 +38,7 @@ make_enum_VersionSpecOption()
key vso_ignore_case "Allow uppercase letters"
key vso_letters_anywhere "Allow 1a2.3 etc"
key vso_dotted_suffixes "Allow 1_alpha2.3"
+ key vso_ignore_leading_v "Allow v1 etc"
want_destringify
diff --git a/paludis/version_spec_TEST.cc b/paludis/version_spec_TEST.cc
index b4704f2..25f4601 100644
--- a/paludis/version_spec_TEST.cc
+++ b/paludis/version_spec_TEST.cc
@@ -1,7 +1,7 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
- * Copyright (c) 2005, 2006, 2007, 2008, 2009 Ciaran McCreesh
+ * Copyright (c) 2005, 2006, 2007, 2008, 2009, 2010 Ciaran McCreesh
*
* This file is part of the Paludis package manager. Paludis is free software;
* you can redistribute it and/or modify it under the terms of the GNU General
@@ -704,5 +704,19 @@ namespace test_cases
TEST_CHECK(v5.hash() == v6.hash());
}
} test_version_spec_flexible_dashes;
+
+ struct VersionSpecLeadingVTest : TestCase
+ {
+ VersionSpecLeadingVTest() : TestCase("leading v") { }
+
+ void run()
+ {
+ TEST_CHECK_THROWS(VersionSpec("v1.2.3", VersionSpecOptions()), BadVersionSpecError);
+ VersionSpec v1("v1.2.3", VersionSpecOptions() + vso_ignore_leading_v);
+ VersionSpec v2("1.2.3", VersionSpecOptions());
+ TEST_CHECK(v1 == v2);
+ TEST_CHECK(v1.hash() == v2.hash());
+ }
+ } test_version_spec_leading_v;
}