<commit_before><?php

namespace Qafoo\ChangeTrack\Analyzer\Vcs;

class GitCheckout extends \Arbit\VCSWrapper\GitCli\Checkout
{
    /**
     * Returns the diff that was applied in the given $revision
     *
     * @param string $revision
     * @return array(\Arbit\VCSWrapper\Diff\Collection)
     */
    public function getRevisionDiff($revision)
    {
        $process = new \Arbit\VCSWrapper\GitCli\Process();
        $process->workingDirectory($this->root);
        $process->argument('show')->argument('--pretty="format:%b"')
            ->argument($revision)->execute();

        $parser = new \Arbit\VCSWrapper\Diff\Unified();
        return $parser->parseString($process->stdoutOutput);
    }

    /**
     * @param string $revision
     * @return bool
     */
    public function hasPredecessor($revision)
    {
        return strlen($this->getPredecessorCommitList($revision)) > 0;
    }

    /**
     * @param string $revision
     * @return string
     */
    private function getPredecessorCommitList($revision)<commit_msg>Implemented: Little performance boost by caching checked out revision.<commit_after><?php

namespace Qafoo\ChangeTrack\Analyzer\Vcs;

class GitCheckout extends \Arbit\VCSWrapper\GitCli\Checkout
{
    /**
     * @var string
     */
    private $currentRevision;

    public function update($version = null)
    {
        if ($this->currentRevision === null || $this->currentRevision !== $version) {
            $this->currentRevision = $version;
            return parent::update($version);
        }
        return false;
    }

    /**
     * Returns the diff that was applied in the given $revision
     *
     * @param string $revision
     * @return array(\Arbit\VCSWrapper\Diff\Collection)
     */
    public function getRevisionDiff($revision)
    {
        $process = new \Arbit\VCSWrapper\GitCli\Process();
        $process->workingDirectory($this->root);
        $process->argument('show')->argument('--pretty="format:%b"')
            ->argument($revision)->execute();

        $parser = new \Arbit\VCSWrapper\Diff\Unified();
        return $parser->parseString($process->stdoutOutput);
    }

    /**
     * @param string $revision
     * @return bool
     */
    public function hasPredecessor($revision)
    {
        return strlen($this->getPredecessorCommitList($revision)) > 0;
    }

    /**
     * @param string $revision
     * @return string
     */
    private function getPredecessorCommitList($revision)
{'fraction_non_alphanumeric': 0.13525588952071488, 'fraction_numerical': 0.0008123476848090983, 'mean_word_length': 2.6761194029850746, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 26, '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': '3431742', 'n_tokens_mistral': 726, 'n_tokens_neox': 703, 'n_words': 136}