Skip to content

Instantly share code, notes, and snippets.

@hoffigk
Created June 5, 2013 08:32
Show Gist options
  • Save hoffigk/5712474 to your computer and use it in GitHub Desktop.
Save hoffigk/5712474 to your computer and use it in GitHub Desktop.
<?php
/**
* folder relative-folder
* folder revision url
* folder url
* url folder
* url revision folder
* revision url folder
* url@revision folder
*/
$s
= "
third-party/sounds http://svn.example.com/repos/sounds
third-party/skins -r148 http://svn.example.com/skinproj
third-party/skins/toolkit -r21 http://svn.example.com/skin-maker
http://svn.example.com/repos/sounds third-party/sounds
-r148 http://svn.example.com/skinproj third-party/skins
-r21 http://svn.example.com/skin-maker third-party/skins/toolkit
http://svn.example.com/repos/sounds third-party/sounds
http://svn.example.com/skinproj@148 third-party/skins
http://svn.example.com/skin-maker@21 third-party/skins/toolkit # fff
third-party/sounds ../foo/sounds
../foo/sounds third-party/sounds
";
$lines = preg_split("~\n~", $s, -1, PREG_SPLIT_NO_EMPTY);
$matches = array();
$externals = array();
foreach ($lines as $line) {
$parts = preg_split("~[\s\t]+~", $line, -1, PREG_SPLIT_NO_EMPTY);
$parts = array_map('trim', $parts);
$external = array(
'url' => null,
'folder' => null,
'revision' => null
);
foreach ($parts as $part) {
if (strpos($part, '#') !== false) {
break;
}
if (preg_match('~-r(\d+)~', $part, $matches)) {
$external['revision'] = $matches[1];
continue;
}
if (preg_match('~(.+)@(\d+)$~', $part, $matches)) {
$external['url'] = $matches[1];
$external['revision'] = $matches[2];
continue;
}
if (preg_match('~^\.|://~', $part, $matches)) {
$external['url'] = $part;
continue;
}
$external['folder'] = $part;
}
$externals[] = $external;
}
print_r($externals);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment