aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-01-30 16:30:55 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-01-30 16:30:55 +0000
commit91a72e05f165e8230d510df90e896c4a25b681e3 (patch)
tree14e0920a689553947ff203f70862a32cecc60955
parent4f3c3dbc12a6cdd57136f7a377f81ea8521ac594 (diff)
downloadpaludis-91a72e05f165e8230d510df90e896c4a25b681e3.tar.gz
paludis-91a72e05f165e8230d510df90e896c4a25b681e3.tar.xz
Add remove_revision to VersionSpec. Use it.
-rw-r--r--paludis/portage_repository.cc3
-rw-r--r--paludis/version_spec.cc14
-rw-r--r--paludis/version_spec.hh5
-rw-r--r--paludis/version_spec_TEST.cc17
4 files changed, 37 insertions, 2 deletions
diff --git a/paludis/portage_repository.cc b/paludis/portage_repository.cc
index 056c580..9bc99e0 100644
--- a/paludis/portage_repository.cc
+++ b/paludis/portage_repository.cc
@@ -668,8 +668,7 @@ PortageRepository::do_version_metadata(
else
{
std::string cmd(
- "env PV='" + stringify(p) + "-" + strip_trailing_string(
- strip_trailing(stringify(v), "0123456789"), "-r") + "' " +
+ "env PV='" + stringify(p) + "-" + stringify(v.remove_revision()) + "' " +
"PN='" + stringify(p) + "' "
"PVR='" + stringify(p) + "-" + stringify(v) + "' " +
"CATEGORY='" + stringify(c) + "' " +
diff --git a/paludis/version_spec.cc b/paludis/version_spec.cc
index 375eea3..16cfe61 100644
--- a/paludis/version_spec.cc
+++ b/paludis/version_spec.cc
@@ -307,6 +307,20 @@ VersionSpec::hash_value() const
return _implementation->version_parts[0];
}
+VersionSpec
+VersionSpec::remove_revision() const
+{
+ VersionSpec result(*this);
+ result._implementation->revision_part = 0;
+
+ std::string::size_type p;
+ if (std::string::npos != ((p = result._implementation->text.rfind("-r"))))
+ if (std::string::npos == result._implementation->text.find_first_not_of("0123456789", p + 2))
+ result._implementation->text.erase(p);
+
+ return result;
+}
+
std::ostream &
paludis::operator<< (std::ostream & s, const VersionSpec & v)
{
diff --git a/paludis/version_spec.hh b/paludis/version_spec.hh
index 50ff83e..02876ad 100644
--- a/paludis/version_spec.hh
+++ b/paludis/version_spec.hh
@@ -102,6 +102,11 @@ namespace paludis
*/
std::size_t hash_value() const;
+ /**
+ * Remove the revision part.
+ */
+ VersionSpec remove_revision() const;
+
};
/**
diff --git a/paludis/version_spec_TEST.cc b/paludis/version_spec_TEST.cc
index be9cffc..02dd0c9 100644
--- a/paludis/version_spec_TEST.cc
+++ b/paludis/version_spec_TEST.cc
@@ -166,5 +166,22 @@ namespace test_cases
}
} test_version_spec_star_compare;
+
+ /**
+ * \test VersionSpec remove revision
+ *
+ * \ingroup Test
+ */
+ struct VersionRemoveRevisionTest : TestCase
+ {
+ VersionRemoveRevisionTest() : TestCase("version spec remove revision") {}
+
+ void run()
+ {
+ TEST_CHECK_STRINGIFY_EQUAL(VersionSpec("1.2").remove_revision(), "1.2");
+ TEST_CHECK_STRINGIFY_EQUAL(VersionSpec("1.2-r").remove_revision(), "1.2");
+ TEST_CHECK_STRINGIFY_EQUAL(VersionSpec("1.2-r99").remove_revision(), "1.2");
+ }
+ } test_version_remove_revision;
}