<commit_before><?php
/**
 * For licensing information, please see the LICENSE file accompanied with this file.
 *
 * @author <NAME> <<EMAIL>>
 * @copyright 2012 <NAME> <http://melp.nl>
 */

namespace Zicht\Tool\Plugin\Svn;

use \Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;

use \Zicht\Tool\Container\Container;
use \Zicht\Tool\Plugin as BasePlugin;

/**
 * SVN plugin configuration
 */
class Plugin extends BasePlugin
{
    /**
     * Appends SVN configuration options
     *
     * @param \Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition $rootNode
     * @return mixed|void
     */
    public function appendConfiguration(ArrayNodeDefinition $rootNode)
    {
        $rootNode
            ->children()
                ->arrayNode('vcs')
                    ->children()
                        ->scalarNode('url')->isRequired()->end()
                        ->arrayNode('export')
                            ->children()
                                ->scalarNode('revfile')->isRequired()->end()
                            ->end()
                        ->end()
                    ->end()
                ->end()
            ->end()
        ;
    }

    public function setContainer(Container $container)
    {
        $container->method('vcs.versionid', function($container, $info) {
            if (
                trim($info)
                && preg_match('/^URL: (.*)/m', $info, $urlMatch)
                && preg_match('/^Revision: (.*)/m', $info, $revMatch)
            ) {
                $url = $urlMatch[1];
                $rev = $revMatch[1];
                return ltrim(str_replace($container->resolve('vcs.url'), '', $url), '/') . '@' . $rev;
            }
            return null;
        });
        $container->method('versionof', function($container, $dir) {
            if (is_file($revFile = ($dir . '/' . $container->resolve('vcs.export.revfile')))) {
                $info = file_get_contents($revFile);
            } elseif (is_dir($dir)) {
                $info = @shell_exec('svn info ' . $dir . ' 2>&1');
            } else {
                return null;
            }
            return $container->call('vcs.versionid', $info);
        });
        $container->decl('vcs.current', function($container) {
            return $container->call('versionof', $container->resolve('cwd'));
        });
    }
}<commit_msg>throw an exception if the project url does not match the current working version url.<commit_after><?php
/**
 * For licensing information, please see the LICENSE file accompanied with this file.
 *
 * @author <NAME> <<EMAIL>>
 * @copyright 2012 <NAME> <http://melp.nl>
 */

namespace Zicht\Tool\Plugin\Svn;

use \Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;

use \Zicht\Tool\Container\Container;
use \Zicht\Tool\Plugin as BasePlugin;

/**
 * SVN plugin configuration
 */
class Plugin extends BasePlugin
{
    /**
     * Appends SVN configuration options
     *
     * @param \Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition $rootNode
     * @return mixed|void
     */
    public function appendConfiguration(ArrayNodeDefinition $rootNode)
    {
        $rootNode
            ->children()
                ->arrayNode('vcs')
                    ->children()
                        ->scalarNode('url')->isRequired()->end()
                        ->arrayNode('export')
                            ->children()
                                ->scalarNode('revfile')->isRequired()->end()
                            ->end()
                        ->end()
                    ->end()
                ->end()
            ->end()
        ;
    }

    public function setContainer(Container $container)
    {
        $container->method('vcs.versionid', function($container, $info) {
            if (
                trim($info)
                && preg_match('/^URL: (.*)/m', $info, $urlMatch)
                && preg_match('/^Revision: (.*)/m', $info, $revMatch)
            ) {
                $url = $urlMatch[1];
                $rev = $revMatch[1];
                $projectUrl = $container->resolve('vcs.url');

                if (substr($url, 0, strlen($projectUrl)) != $projectUrl) {
                    throw new \UnexpectedValueException("The project url {$projectUrl} does not match the VCS url {$url}");
                }

                return ltrim(str_replace($container->resolve('vcs.url'), '', $url), '/') . '@' . $rev;
            }
            return null;
        });
        $container->method('versionof', function($container, $dir) {
            if (is_file($revFile = ($dir . '/' . $container->resolve('vcs.export.revfile')))) {
                $info = file_get_contents($revFile);
            } elseif (is_dir($dir)) {
                $info = @shell_exec('svn info ' . $dir . ' 2>&1');
            } else {
                return null;
            }
            return $container->call('vcs.versionid', $info);
        });
        $container->decl('vcs.current', function($container) {
            return $container->call('versionof', $container->resolve('cwd'));
        });
    }
}
{'fraction_non_alphanumeric': 0.1551825102479016, 'fraction_numerical': 0.003318368143665821, 'mean_word_length': 1.6841278156102673, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 64, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2882846', 'n_tokens_mistral': 1411, 'n_tokens_neox': 1350, 'n_words': 268}