From 410181ee2992139a218df7e5cd6c7452e4e3753f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Kerner?= Date: Thu, 16 Jan 2014 10:44:35 +0100 Subject: [PATCH 1/2] * added svn handling for tags, trunk, branches in root packages --- .../Package/Loader/RootPackageLoader.php | 50 ++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/src/Composer/Package/Loader/RootPackageLoader.php b/src/Composer/Package/Loader/RootPackageLoader.php index a067fa6a8..3ff018b5a 100644 --- a/src/Composer/Package/Loader/RootPackageLoader.php +++ b/src/Composer/Package/Loader/RootPackageLoader.php @@ -179,8 +179,15 @@ class RootPackageLoader extends ArrayLoader return $version; } - return $this->guessHgVersion($config); + $version = $this->guessHgVersion($config); + if (null !== $version) { + return $version; + } + + return $this->guessSvnVersion($config); } + + return null; } private function guessGitVersion(array $config) @@ -295,4 +302,45 @@ class RootPackageLoader extends ArrayLoader return $version; } + + private function guessSvnVersion(array $config) + { + // try to fetch current version from svn + if (0 === $this->process->execute('svn info --xml', $output)) { + + $regexDelimiter = '#'; + + $trunkPath = + isset($config['trunk-path']) + ? preg_quote($config['trunk-path'], $regexDelimiter) + : 'trunk'; + + $branchesPath = + isset($config['branches-path']) + ? preg_quote($config['branches-path'], $regexDelimiter) + : 'branches'; + + $tagsPath = + isset($config['tags-path']) + ? preg_quote($config['tags-path'], $regexDelimiter) + : 'tags'; + + $urlPattern = $regexDelimiter + . '.*/(' . $trunkPath . '|(' . $branchesPath . '|' . $tagsPath .')/(.*))' + . $regexDelimiter; + + if(preg_match($urlPattern, $output, $matches)) { + if(isset($matches[2]) && isset($matches[3]) && $branchesPath === $matches[2]) { + // we are in a branches path + $version = $this->versionParser->normalizeBranch($matches[3]); + if ('9999999-dev' === $version) { + $version = 'dev-' . $matches[3]; + } + return $version; + } + + return $this->versionParser->normalize(trim($matches[1])); + } + } + } } From f2c48788b8e7f8878be61a23ee8253177839b660 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Thu, 6 Feb 2014 23:06:48 +0100 Subject: [PATCH 2/2] Reformat code to follow coding style --- .../Package/Loader/RootPackageLoader.php | 32 ++++--------------- 1 file changed, 7 insertions(+), 25 deletions(-) diff --git a/src/Composer/Package/Loader/RootPackageLoader.php b/src/Composer/Package/Loader/RootPackageLoader.php index 3ff018b5a..8db725496 100644 --- a/src/Composer/Package/Loader/RootPackageLoader.php +++ b/src/Composer/Package/Loader/RootPackageLoader.php @@ -186,8 +186,6 @@ class RootPackageLoader extends ArrayLoader return $this->guessSvnVersion($config); } - - return null; } private function guessGitVersion(array $config) @@ -307,34 +305,18 @@ class RootPackageLoader extends ArrayLoader { // try to fetch current version from svn if (0 === $this->process->execute('svn info --xml', $output)) { + $trunkPath = isset($config['trunk-path']) ? preg_quote($config['trunk-path'], '#') : 'trunk'; + $branchesPath = isset($config['branches-path']) ? preg_quote($config['branches-path'], '#') : 'branches'; + $tagsPath = isset($config['tags-path']) ? preg_quote($config['tags-path'], '#') : 'tags'; - $regexDelimiter = '#'; - - $trunkPath = - isset($config['trunk-path']) - ? preg_quote($config['trunk-path'], $regexDelimiter) - : 'trunk'; + $urlPattern = '#.*/('.$trunkPath.'|('.$branchesPath.'|'. $tagsPath .')/(.*))#'; - $branchesPath = - isset($config['branches-path']) - ? preg_quote($config['branches-path'], $regexDelimiter) - : 'branches'; - - $tagsPath = - isset($config['tags-path']) - ? preg_quote($config['tags-path'], $regexDelimiter) - : 'tags'; - - $urlPattern = $regexDelimiter - . '.*/(' . $trunkPath . '|(' . $branchesPath . '|' . $tagsPath .')/(.*))' - . $regexDelimiter; - - if(preg_match($urlPattern, $output, $matches)) { - if(isset($matches[2]) && isset($matches[3]) && $branchesPath === $matches[2]) { + if (preg_match($urlPattern, $output, $matches)) { + if (isset($matches[2]) && $branchesPath === $matches[2]) { // we are in a branches path $version = $this->versionParser->normalizeBranch($matches[3]); if ('9999999-dev' === $version) { - $version = 'dev-' . $matches[3]; + $version = 'dev-'.$matches[3]; } return $version; }