<commit_before><?php

/*
 * core42
 *
 * @package core42
 * @link https://github.com/raum42/core42
 * @copyright Copyright (c) 2010 - 2016 raum42 (https://www.raum42.at)
 * @license MIT License
 * @author raum42 <<EMAIL>>
 */

namespace Core42\Command\Revision;

use Core42\Command\AbstractCommand;
use Core42\Command\ConsoleAwareTrait;
use Ramsey\Uuid\Uuid;
use Zend\Json\Json;
use ZF\Console\Route;

class CreateFileCommand extends AbstractCommand
{
    use ConsoleAwareTrait;

    /**
     * @var bool
     */
    protected $transaction = false;

    /**
     *
     */
    protected function execute()
    {
        $result = [];

        $result['revision_type'] = 'none';
        $result['revision_hash'] = md5(Uuid::uuid4()->toString()) . substr(md5(Uuid::uuid4()->toString()), 0, 8);
        $rev = $this->getGitRevision();
        if ($rev !== false) {
            $result['revision_type'] = 'git';
            $result['revision_hash'] = $rev;
        }

        $result['revision_hash_short'] = substr($result['revision_hash'], 0, 7);

        if (!is_dir('resources/version')) {
            @mkdir('resources/version', 0777, true);
        }

        file_put_contents('resources/version/revision.json', Json::encode($result, false, ['prettyPrint' => true]));

        return $result;
    }

    protected function getGitRevision()
    {
        if (!is_dir(getcwd() . '/.git/')) {
            return false;
        }

        if (!file_exists(getcwd() . '/.git/HEAD')) {
            return false;
        }

        $ref = trim(file_get_contents(getcwd() . '/.git/HEAD'));
        if (substr($ref, 0 , 5) != 'ref: ') {
            return false;
        }
        $ref = trim(substr($ref, 5));

        if (!file_exists(getcwd() . '/.git/' . $ref)) {
            return false;
        }
<commit_msg>support of detached head in git revision<commit_after><?php

/*
 * core42
 *
 * @package core42
 * @link https://github.com/raum42/core42
 * @copyright Copyright (c) 2010 - 2016 raum42 (https://www.raum42.at)
 * @license MIT License
 * @author raum42 <<EMAIL>>
 */

namespace Core42\Command\Revision;

use Core42\Command\AbstractCommand;
use Core42\Command\ConsoleAwareTrait;
use Ramsey\Uuid\Uuid;
use Zend\Json\Json;
use ZF\Console\Route;

class CreateFileCommand extends AbstractCommand
{
    use ConsoleAwareTrait;

    /**
     * @var bool
     */
    protected $transaction = false;

    /**
     *
     */
    protected function execute()
    {
        $result = [];

        $result['revision_type'] = 'none';
        $result['revision_hash'] = md5(Uuid::uuid4()->toString()) . substr(md5(Uuid::uuid4()->toString()), 0, 8);
        $rev = $this->getGitRevision();
        if ($rev !== false) {
            $result['revision_type'] = 'git';
            $result['revision_hash'] = $rev;
        }

        $result['revision_hash_short'] = substr($result['revision_hash'], 0, 7);

        if (!is_dir('resources/version')) {
            @mkdir('resources/version', 0777, true);
        }

        file_put_contents('resources/version/revision.json', Json::encode($result, false, ['prettyPrint' => true]));

        return $result;
    }

    protected function getGitRevision()
    {
        if (!is_dir(getcwd() . '/.git/')) {
            return false;
        }

        if (!file_exists(getcwd() . '/.git/HEAD')) {
            return false;
        }

        $ref = trim(file_get_contents(getcwd() . '/.git/HEAD'));

        if (strlen($ref) === 40) {
            return $ref;
        }elseif (substr($ref, 0 , 5) == 'ref: ') {
            $ref = trim(substr($ref, 5));
        } else {
            return false;
        }

        if (!file_exists(getcwd() . '/.git/' . $ref)) {
            return false;
        }

{'fraction_non_alphanumeric': 0.17032672737011248, 'fraction_numerical': 0.023567220139260846, 'mean_word_length': 2.2534843205574915, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 15, 'https://': 4, 'lorem ipsum': 0, 'www.': 2, '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': '965822', 'n_tokens_mistral': 1275, 'n_tokens_neox': 1178, 'n_words': 232}