<commit_before><?php
namespace phorkie;


class Repository
{
    /**
     * Repository ID (number in repositories directory)
     *
     * @var integer
     */
    public $id;

    /**
     * Full path to the .git repository
     *
     * @var string
     */
    public $gitDir;

    /**
     * Full path to the work tree directory
     *
     * @var string
     */
    public $workDir;

    /**
     * Revision of the repository that shall be shown
     *
     * @var string
     */
    public $hash;

    /**
     * Commit message of the last (or current) revision
     *
     * @var string
     */
    public $message;


    /**
     * Load Repository data from GET-Request
     *
     * @return void
     *
     * @throws Exception When something is wrong
     */
    public function loadFromRequest()
    {
        if (!isset($_GET['id'])) {
            throw new Exception_Input('Paste ID missing');
        }
        if (!is_numeric($_GET['id'])) {
            throw new Exception_Input('Paste ID not numeric');
        }
        if (isset($_GET['rev'])) {
            $this->hash = $_GET['rev'];
        }

        $this->id = (int)$_GET['id'];
        $this->loadDirs();
        $this->loadHash();
        $this->loadMessage();
    }

    protected function loadDirs()
    {
        $gitDir = $GLOBALS['phorkie']['cfg']['gitdir'] . '/' . $this->id . '.git';
        if (!is_dir($gitDir)) {
            throw new Exception_NotFound(
                sprintf('Paste %d .git dir not found', $this->id)
            );
        }
        $this->gitDir = $gitDir;

        $workDir = $GLOBALS['phorkie']['cfg']['workdir'] . '/' . $this->id;
        if (!is_dir($workDir)) {
            throw new Exception_NotFound(
                sprintf('Paste %d work dir not found', $this->id)
            );
        }
        $this->workDir = $workDir;
    }

    public function loadHash()
    {
        return;
        if ($this->hash !== null) {
            return;
        }

        $output = $this->getVc()->getCommand('log')
            ->setOption('pretty', 'format:%H')
            ->setOption('max-count', 1)
            ->execute();
        $output = trim($output);
        if (strlen($output) !== 40) {
            throw new Exception(
                'Loading commit hash failed: ' . $output
            );
        }
        $this->hash = $output;
    }

	/**
     * Populates $this->message
     *
     * @return void
     */
    public function loadMessage()
    {
        $rev = (isset($this->hash)) ? $this->hash : 'HEAD';
        $output = $this->getVc()->getCommand('log')
            ->setOption('oneline')
            ->addArgument('-1')
            ->addArgument($rev)
            ->execute();
        $output = trim($output);
        if (strpos($output, ' ') > 0) {
            $output = substr($output, strpos($output, ' '), strlen($output));
            $this->message = trim($output);
        } else {
            $this->message = "This commit message intentionally left blank.";
        }
    }
<commit_msg>corrected spacing to PEAR standards<commit_after><?php
namespace phorkie;


class Repository
{
    /**
     * Repository ID (number in repositories directory)
     *
     * @var integer
     */
    public $id;

    /**
     * Full path to the .git repository
     *
     * @var string
     */
    public $gitDir;

    /**
     * Full path to the work tree directory
     *
     * @var string
     */
    public $workDir;

    /**
     * Revision of the repository that shall be shown
     *
     * @var string
     */
    public $hash;

    /**
     * Commit message of the last (or current) revision
     *
     * @var string
     */
    public $message;


    /**
     * Load Repository data from GET-Request
     *
     * @return void
     *
     * @throws Exception When something is wrong
     */
    public function loadFromRequest()
    {
        if (!isset($_GET['id'])) {
            throw new Exception_Input('Paste ID missing');
        }
        if (!is_numeric($_GET['id'])) {
            throw new Exception_Input('Paste ID not numeric');
        }
        if (isset($_GET['rev'])) {
            $this->hash = $_GET['rev'];
        }

        $this->id = (int)$_GET['id'];
        $this->loadDirs();
        $this->loadHash();
        $this->loadMessage();
    }

    protected function loadDirs()
    {
        $gitDir = $GLOBALS['phorkie']['cfg']['gitdir'] . '/' . $this->id . '.git';
        if (!is_dir($gitDir)) {
            throw new Exception_NotFound(
                sprintf('Paste %d .git dir not found', $this->id)
            );
        }
        $this->gitDir = $gitDir;

        $workDir = $GLOBALS['phorkie']['cfg']['workdir'] . '/' . $this->id;
        if (!is_dir($workDir)) {
            throw new Exception_NotFound(
                sprintf('Paste %d work dir not found', $this->id)
            );
        }
        $this->workDir = $workDir;
    }

    public function loadHash()
    {
        return;
        if ($this->hash !== null) {
            return;
        }

        $output = $this->getVc()->getCommand('log')
            ->setOption('pretty', 'format:%H')
            ->setOption('max-count', 1)
            ->execute();
        $output = trim($output);
        if (strlen($output) !== 40) {
            throw new Exception(
                'Loading commit hash failed: ' . $output
            );
        }
        $this->hash = $output;
    }

    /**
     * Populates $this->message
     *
     * @return void
     */
    public function loadMessage()
    {
        $rev = (isset($this->hash)) ? $this->hash : 'HEAD';
        $output = $this->getVc()->getCommand('log')
            ->setOption('oneline')
            ->addArgument('-1')
            ->addArgument($rev)
            ->execute();
        $output = trim($output);
        if (strpos($output, ' ') > 0) {
            $output = substr($output, strpos($output, ' '), strlen($output));
            $this->message = trim($output);
        } else {
            $this->message = "This commit message intentionally left blank.";
        }
    }

{'fraction_non_alphanumeric': 0.1587353861353532, 'fraction_numerical': 0.0016466326362588506, 'mean_word_length': 1.6023993144815767, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 63, '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': '5599984', 'n_tokens_mistral': 1801, 'n_tokens_neox': 1755, 'n_words': 412}