aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-04-27 18:31:01 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-04-27 18:31:01 +0000
commit74e6eacacc89b3f62e3953cd74092b51d5d40cd1 (patch)
treebd6ad862c2fe949ce7e71c259989bf3a10e6d478
parent38cf3f33e7fdf933b0ef8944114ec00fcc8ad2d3 (diff)
downloadpaludis-74e6eacacc89b3f62e3953cd74092b51d5d40cd1.tar.gz
paludis-74e6eacacc89b3f62e3953cd74092b51d5d40cd1.tar.xz
Allow scm-rX on unversioned packages
-rw-r--r--paludis/version_spec.cc183
-rw-r--r--paludis/version_spec_TEST.cc1
2 files changed, 93 insertions, 91 deletions
diff --git a/paludis/version_spec.cc b/paludis/version_spec.cc
index 08b45e8..ee33645 100644
--- a/paludis/version_spec.cc
+++ b/paludis/version_spec.cc
@@ -120,80 +120,98 @@ VersionSpec::VersionSpec(const std::string & text) :
/* parse */
std::string::size_type p(0);
- if (text == "scm")
+ if (0 == text.compare(p, 3, "scm"))
{
_imp->parts.push_back(Part(scm, 0));
- return;
+ p += 3;
}
-
- /* numbers... */
- unsigned long x(0);
- while (p < text.length())
+ else
{
- if (text.at(p) < '0' || text.at(p) > '9')
- throw BadVersionSpecError(text);
-
- x *= 10;
- x += text.at(p) - '0';
-
- if (++p >= text.length())
- break;
-
- if ('.' == text.at(p))
+ /* numbers... */
+ unsigned long x(0);
+ while (p < text.length())
{
- ++p;
- _imp->parts.push_back(Part(number, x));
- x = 0;
- }
-
- if (text.at(p) < '0' || text.at(p) > '9')
- break;
- }
- _imp->parts.push_back(Part(number, x));
+ if (text.at(p) < '0' || text.at(p) > '9')
+ throw BadVersionSpecError(text);
- while (_imp->parts.size() > 1)
- {
- if (0 == _imp->parts[_imp->parts.size() - 1].get<part_value>())
- _imp->parts.pop_back();
- else
- break;
- }
+ x *= 10;
+ x += text.at(p) - '0';
- /* letter */
- if (p < text.length())
- if (text.at(p) >= 'a' && text.at(p) <= 'z')
- _imp->parts.push_back(Part(letter, text.at(p++)));
+ if (++p >= text.length())
+ break;
- /* suffix */
- if (p < text.length())
- do
- {
- PartKind k(empty);
- if (0 == text.compare(p, 6, "_alpha"))
- {
- k = alpha;
- p += 6;
- }
- else if (0 == text.compare(p, 5, "_beta"))
+ if ('.' == text.at(p))
{
- k = beta;
- p += 5;
- }
- else if (0 == text.compare(p, 4, "_pre"))
- {
- k = pre;
- p += 4;
- }
- else if (0 == text.compare(p, 3, "_rc"))
- {
- k = rc;
- p += 3;
+ ++p;
+ _imp->parts.push_back(Part(number, x));
+ x = 0;
}
+
+ if (text.at(p) < '0' || text.at(p) > '9')
+ break;
+ }
+ _imp->parts.push_back(Part(number, x));
+
+ while (_imp->parts.size() > 1)
+ {
+ if (0 == _imp->parts[_imp->parts.size() - 1].get<part_value>())
+ _imp->parts.pop_back();
else
break;
+ }
+ /* letter */
+ if (p < text.length())
+ if (text.at(p) >= 'a' && text.at(p) <= 'z')
+ _imp->parts.push_back(Part(letter, text.at(p++)));
+
+ /* suffix */
+ if (p < text.length())
+ do
+ {
+ PartKind k(empty);
+ if (0 == text.compare(p, 6, "_alpha"))
+ {
+ k = alpha;
+ p += 6;
+ }
+ else if (0 == text.compare(p, 5, "_beta"))
+ {
+ k = beta;
+ p += 5;
+ }
+ else if (0 == text.compare(p, 4, "_pre"))
+ {
+ k = pre;
+ p += 4;
+ }
+ else if (0 == text.compare(p, 3, "_rc"))
+ {
+ k = rc;
+ p += 3;
+ }
+ else
+ break;
+
+ x = std::numeric_limits<unsigned long>::max();
+ for ( ; p < text.length() ; ++p)
+ {
+ if (text.at(p) < '0' || text.at(p) > '9')
+ break;
+ if (x == std::numeric_limits<unsigned long>::max())
+ x = 0;
+ x *= 10;
+ x += text.at(p) - '0';
+ }
+
+ _imp->parts.push_back(Part(k, x));
+ } while (false);
+
+ /* patch level */
+ if (p < text.length() && 0 == text.compare(p, 2, "_p"))
+ {
x = std::numeric_limits<unsigned long>::max();
- for ( ; p < text.length() ; ++p)
+ for (p += 2 ; p < text.length() ; ++p)
{
if (text.at(p) < '0' || text.at(p) > '9')
break;
@@ -202,38 +220,22 @@ VersionSpec::VersionSpec(const std::string & text) :
x *= 10;
x += text.at(p) - '0';
}
+ _imp->parts.push_back(Part(patch, x));
+ }
- _imp->parts.push_back(Part(k, x));
- } while (false);
-
- /* patch level */
- if (p < text.length() && 0 == text.compare(p, 2, "_p"))
- {
- x = std::numeric_limits<unsigned long>::max();
- for (p += 2 ; p < text.length() ; ++p)
+ /* scm */
+ if ((p < text.length()) && (0 == text.compare(p, 4, "-scm")))
{
- if (text.at(p) < '0' || text.at(p) > '9')
- break;
- if (x == std::numeric_limits<unsigned long>::max())
- x = 0;
- x *= 10;
- x += text.at(p) - '0';
+ p += 4;
+ _imp->parts.push_back(Part(scm, 0));
+ }
+ else
+ {
+ for (std::vector<Part>::iterator i(_imp->parts.begin()),
+ i_end(_imp->parts.end()) ; i != i_end ; ++i)
+ if (std::numeric_limits<unsigned long>::max() == i->get<part_value>())
+ i->set<part_value>(0);
}
- _imp->parts.push_back(Part(patch, x));
- }
-
- /* scm */
- if ((p < text.length()) && (0 == text.compare(p, 4, "-scm")))
- {
- p += 4;
- _imp->parts.push_back(Part(scm, 0));
- }
- else
- {
- for (std::vector<Part>::iterator i(_imp->parts.begin()),
- i_end(_imp->parts.end()) ; i != i_end ; ++i)
- if (std::numeric_limits<unsigned long>::max() == i->get<part_value>())
- i->set<part_value>(0);
}
/* revision */
@@ -241,7 +243,7 @@ VersionSpec::VersionSpec(const std::string & text) :
if (0 == text.compare(p, 2, "-r"))
{
p += 2;
- x = 0;
+ unsigned long x = 0;
while (p < text.length())
{
if (text.at(p) < '0' || text.at(p) > '9')
@@ -253,7 +255,6 @@ VersionSpec::VersionSpec(const std::string & text) :
_imp->parts.push_back(Part(revision, x));
}
-
/* trailing stuff? */
if (p < text.length())
throw BadVersionSpecError(text);
diff --git a/paludis/version_spec_TEST.cc b/paludis/version_spec_TEST.cc
index 2ce9f8c..da974df 100644
--- a/paludis/version_spec_TEST.cc
+++ b/paludis/version_spec_TEST.cc
@@ -257,6 +257,7 @@ namespace test_cases
v.push_back(VersionSpec("1-scm"));
v.push_back(VersionSpec("2_alpha"));
v.push_back(VersionSpec("scm"));
+ v.push_back(VersionSpec("scm-r3"));
std::vector<VersionSpec>::iterator v1(v.begin()), v_end(v.end());
for ( ; v1 != v_end ; ++v1)