<commit_before><?php
namespace VCS;

use DateTime;

class Base
{
    public $repositoryPath;

    public function __construct($repositoryPath)
    {
        $this->repositoryPath = realpath($repositoryPath);
    }

    protected function execute($command)
    {
        $cwd = getcwd();
        chdir($this->repositoryPath);
        exec($command, $output, $returnValue);
        chdir($cwd);

        if ($returnValue !== 0) {
            error_log("error");
        }

        return $output;
    }

    protected function parseLog($log)
    {
        for ($i = 0, $lines = count($log); $i < $lines; $i++) {
            $tmp = explode(': ', $log[$i]);

            if (trim($tmp[0]) == 'changeset') {
                $commit = trim($tmp[1]);
            }

            if (trim($tmp[0]) == 'user') {
                if (! strstr($tmp[1], '@')) {
                // No email in User field
                    $author = $tmp[1];
                    $email = 'Unknown email';
                } elseif (preg_match('~<([:alpha]*.+)>~', $tmp[1], $matches)) {
                // <NAME> <<EMAIL>>
                    $email = str_replace(['<', '>'], '', $matches[0]);
                    $author = explode('<', $tmp[1])[0];
                } elseif (preg_match('~([:alpha]*.+)~', $tmp[1], $matches)) {
                // <NAME> <EMAIL>
                    $email = $matches[0];
                    $author = str_replace($matches[0], '', $tmp[1]);

                // <EMAIL>
                    if ($author == '') {
                        $author = 'Unknown author';
                    }
                } else {
                // Fallback
                    $email  = 'Unknown email';
                    $author = 'Unknown author';
                }

                $email = trim($email);
                $author = trim($author);
            }

            if (trim($tmp[0]) == 'date') {
                $date = trim($tmp[1]);
            }

            if (trim($tmp[0]) == 'summary') {
                $summary = trim($tmp[1]);

                $commits[] = [
                    'commit'  => $commit,
                    'author'  => $author,
                    'email'   => $email,
                    'date'    => DateTime::createFromFormat('D M j H:i:s Y O', $date),
                    'summary' => $summary
                ];
            }
        }

        return $commits;
    }
}
<commit_msg>better error message + extract emails with parenthesis<commit_after><?php
namespace VCS;

use DateTime;

class Base
{
    public $repositoryPath;

    public function __construct($repositoryPath)
    {
        $this->repositoryPath = realpath($repositoryPath);
    }

    protected function execute($command)
    {
        $cwd = getcwd();
        chdir($this->repositoryPath);
        exec($command, $output, $returnCode);
        chdir($cwd);

        if ($returnCode !== 0) {
            error_log("Error with command {$command} launched in {$this->repositoryPath}");
        }

        return $output;
    }

    protected function parseLog($log)
    {
        for ($i = 0, $lines = count($log); $i < $lines; $i++) {
            $tmp = explode(': ', $log[$i]);

            if (trim($tmp[0]) == 'changeset') {
                $commit = trim($tmp[1]);
            }

            if (trim($tmp[0]) == 'user') {
                if (! strstr($tmp[1], '@')) {
                // No email in User field
                    $author = $tmp[1];
                    $email = 'Unknown email';
                } elseif (preg_match('~<([:alpha]*.+)>~', $tmp[1], $matches)) {
                // <NAME> <<EMAIL>>
                    $email = str_replace(['<', '>'], '', $matches[0]);
                    $author = explode('<', $tmp[1])[0];
                } elseif (preg_match('~\(([:alpha]*.+)\)~', $tmp[1], $matches)) {
                // <NAME> (<EMAIL>)
                    $email = str_replace(['(', ')'], '', $matches[0]);
                    $author = explode('(', $tmp[1])[0];
                } elseif (preg_match('~([:alpha]*.+)~', $tmp[1], $matches)) {
                // <NAME> j<EMAIL>
                    $email = $matches[0];
                    $author = str_replace($matches[0], '', $tmp[1]);

                // <EMAIL>
                    if ($author == '') {
                        $author = 'Unknown author';
                    }
                } else {
                // Fallback
                    $email  = 'Unknown email';
                    $author = 'Unknown author';
                }

                $email = trim($email);
                $author = trim($author);
            }

            if (trim($tmp[0]) == 'date') {
                $date = trim($tmp[1]);
            }

            if (trim($tmp[0]) == 'summary') {
                $summary = trim($tmp[1]);

                $commits[] = [
                    'commit'  => $commit,
                    'author'  => $author,
                    'email'   => $email,
                    'date'    => DateTime::createFromFormat('D M j H:i:s Y O', $date),
                    'summary' => $summary
                ];
            }
        }

        return $commits;
    }
}

{'fraction_non_alphanumeric': 0.17801047120418848, 'fraction_numerical': 0.008144269924374637, 'mean_word_length': 1.2494548626253816, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 36, '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': '6153273', 'n_tokens_mistral': 1511, 'n_tokens_neox': 1414, 'n_words': 292}