Skip to content

Semantic Version Parsing: ~version #1160

Merged
merged 1 commit into from Oct 19, 2012

3 participants

@simensen

Implemented according to #643 and used the following versions as a test case as defined by @Seldaek:

  • "~1.2.3.4" = ">=1.2.3.4 <1.2.4.0-dev"
  • "~1.2.3" = ">=1.2.3 <1.3.0-dev"
  • "~1.2" = ">=1.2.0 <2.0.0-dev"
  • "~1" = ">=1.0.0 <2.0.0-dev"

This was by no means done simply because I want to ask Composer to update to depend on Symfony ~2.1 components. Honest. :)

@simensen

Hm, maybe it doesn't close #643 entirely? :) I might have been too excited about that. :) But I added the ~ part. I am going to amend my commit to take the closes part out.

@stof
stof commented Sep 30, 2012

~1.2.3.4 should also be supported as Composer supports 4 level in the version number

@stof stof commented on an outdated diff Sep 30, 2012
src/Composer/Package/Version/VersionParser.php
@@ -238,6 +238,25 @@ private function parseConstraint($constraint)
return array();
}
+ if (preg_match('{^~(\d+)(?:\.(\d+))?(?:\.(\d+))?$}', $constraint, $matches)) {
+ if (isset($matches[3])) {
+ $highVersion = $matches[1] . '.' . ($matches[2] + 1) . '.0000000.0000000';
+ $lowVersion = $matches[1] . '.' . $matches[2] . '.' . $matches[3]. '.0000000';
+ } else {
+ $highVersion = ($matches[1] + 1) . '.0000000.0000000.0000000';
+ if (isset($matches[2])) {
+ $lowVersion = $matches[1] . '.' . $matches[2] . '.0000000.0000000';
+ } else {
+ $lowVersion = $matches[1] . '.0000000.0000000.0000000';
@stof
stof added a note Sep 30, 2012

use .0, not .000000

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@simensen

What would the constraints look like for ~1.2.3.4?

@simensen
simensen commented Oct 1, 2012

I took a guess on what I figured ~1.2.3.4 would mean.

  • "~1.2.3.4" = ">=1.2.3.4 <1.2.4.0"

I also fixed the 0000000 bit. :-/

Thanks for catching these @stof!

@Seldaek Seldaek and 2 others commented on an outdated diff Oct 2, 2012
...s/Composer/Test/Package/Version/VersionParserTest.php
+ if ($min) {
+ $expected = new MultiConstraint(array($min, $max));
+ } else {
+ $expected = $max;
+ }
+
+ $this->assertSame((string) $expected, (string) $parser->parseConstraints($input));
+ }
+
+ public function tildeConstraints()
+ {
+ return array(
+ array('~1', new VersionConstraint('>=', '1.0.0.0'), new VersionConstraint('<', '2.0.0.0')),
+ array('~1.2', new VersionConstraint('>=', '1.2.0.0'), new VersionConstraint('<', '2.0.0.0')),
+ array('~1.2.3', new VersionConstraint('>=', '1.2.3.0'), new VersionConstraint('<', '1.3.0.0')),
+ array('~1.2.3.4', new VersionConstraint('>=', '1.2.3.4'), new VersionConstraint('<', '1.2.4.0')),
@Seldaek
Composer member
Seldaek added a note Oct 2, 2012

Actually the < should be <anything-dev because 2.0.0.0-dev is smaller than 2.0.0.0 for example.

@simensen
simensen added a note Oct 2, 2012

So how would the version constraint look?

@stof
stof added a note Oct 2, 2012

new VersionConstraint('<', '1.2.4.0-dev'))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@simensen
simensen commented Oct 2, 2012

Updated to have the high number to include -dev.

@simensen simensen Semantic Version Parsing: ~version
Implemented `~` according to #643 and used the following versions
as a test case as defined by @Seldaek:

 * "~1.2.3.4" = ">=1.2.3.4 <1.2.4.0-dev"
 * "~1.2.3" = ">=1.2.3 <1.3.0-dev"
 * "~1.2" = ">=1.2.0 <2.0.0-dev"
 * "~1" = ">=1.0.0 <2.0.0-dev"

Refs #643
96a76ee
@simensen
simensen commented Oct 8, 2012

Is this good to go now or does it still need some tweaking? I rebased a few days ago because I saw some other version parsing stuff going on and it looked like it was still clean at the time.

@Seldaek
Composer member
Seldaek commented Oct 8, 2012

It looks good yes thank you, but I'm putting it on hold for now because I need to do some work in packagist so that this stuff doesn't blow up every composer.phar out there at the first package that's using it.

@Seldaek Seldaek merged commit 96a76ee into composer:master Oct 19, 2012
@Seldaek
Composer member
Seldaek commented Oct 19, 2012

Merged, thanks!

@simensen simensen deleted the simensen:sem-version-support branch May 3, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.