<commit_before>function blamePR() {

    function collectMainDiffLines() {
        var out = {};
        var files = document.getElementsByClassName('file');
        for (var i = 0; i < files.length; i++) {
            var file = files[i];
            var filename = file.getElementsByClassName('user-select-contain')[0].textContent.trim();
            var lines = file.getElementsByClassName('blob-code-inner');
            var section = '';
            for (var j = 0; j < lines.length; j++) {
                var line = lines[j];
                var text = line.textContent;
                if (text[0] === '@' && text[1] === '@') {
                    section = text;
                    continue;
                }
                if (text[0] !== '-' && text[0] !== '+') {
                    continue;
                }
                out[filename + section + text] = line;
            }
        }
        return out;
    }

    function getPatchFile(cb) {
        var port = chrome.runtime.connect({name: 'blame-pr'})
        port.onMessage.addListener(function(msg) {
            if (msg.command !== 'get-patch-file') {
                return;
            }
            cb(msg.response);
        });
        port.postMessage({
          command: 'get-patch-file',
          url: document.location.href.replace(/\/files$/, '.patch')
        })
    }

    function collectPatchInfo(cb) {
        getPatchFile(function(data) {
            var out = {};
            var parts = data.split(/From [0-9a-f]{40} /);
            for (var i = 0; i < parts.length; i++) {
                var part = parts[i];
                var message = part.match(/Subject: \[[^\]]+\] (.*)/);
                if (!message || !message[1] || message[1].length < 1) {
                    continue;
                }
                message = message[1];

                var lines = part.split("\n");
                var filename = '';
                var section = '';
                for (var j = 0; j < lines.length; j++) {
                    var line = lines[j];
                    if (line.match(/^\+\+\+/)) {
                        continue;
                    }
                    var m;
                    if (m = line.match(/^--- (.*)$/)) {
                        if (!m[1]) {
                            continue;
                        }
                        // m[1] is something like a/frontend/src/myfile.js
                        filename = m[1].replace(/^a\//, '');
                        continue;
                    }
                    if (line.match(/^@@ /)) {
                        section = line;
                        continue;
                    }
                    if (line[0] === '-' || line[0] === '+') {
                        out[filename + section + line] = {
                            message: message 
                        };
                    }
                }
            }

            cb(out);
        });
    }

    // main

    var documentLines = collectMainDiffLines();
    collectPatchInfo(function(patchInfo) {
        for (var k in patchInfo) {
            var info = patchInfo[k];
            var line = documentLines[k];
            if (!line) {
                continue;
            }
            line.innerHTML += '<aside>' + info.message + '</aside>';
        }
    });
}
<commit_msg>add stupid heuristic so we always display some commit<commit_after>function blamePR() {

    var SEPERATOR = '||||||~~~~~~~~~~~~~||||||'

    function collectMainDiffLines() {
        var documentLines = {};
        var linesWithoutSection = {};
        var files = document.getElementsByClassName('file');
        for (var i = 0; i < files.length; i++) {
            var file = files[i];
            var filename = file.getElementsByClassName('user-select-contain')[0].textContent.trim();
            var lines = file.getElementsByClassName('blob-code-inner');
            var section = '';
            for (var j = 0; j < lines.length; j++) {
                var line = lines[j];
                var text = line.textContent;
                if (text[0] === '@' && text[1] === '@') {
                    section = text;
                    continue;
                }
                if (text[0] !== '-' && text[0] !== '+') {
                    continue;
                }
                documentLines[filename + section + text] = line;
                if (!linesWithoutSection[filename]) {
                    linesWithoutSection[filename] = [];
                }
                linesWithoutSection[filename].push({
                    text: text,
                    element: line
                });
            }
        }
        return [documentLines, linesWithoutSection];
    }

    function getPatchFile(cb) {
        var port = chrome.runtime.connect({name: 'blame-pr'})
        port.onMessage.addListener(function(msg) {
            if (msg.command !== 'get-patch-file') {
                return;
            }
            cb(msg.response);
        });
        port.postMessage({
          command: 'get-patch-file',
          url: document.location.href.replace(/\/files$/, '.patch')
        })
    }

    function collectPatchInfo(cb) {
        getPatchFile(function(data) {
            var patchInfo = {};
            var patchInfoWithoutSection = {};
            var parts = data.split(/From [0-9a-f]{40} /);
            for (var i = 0; i < parts.length; i++) {
                var part = parts[i];
                var message = part.match(/Subject: \[[^\]]+\] (.*)/);
                if (!message || !message[1] || message[1].length < 1) {
                    continue;
                }
                message = message[1];

                var lines = part.split("\n");
                var filename = '';
                var section = '';
                for (var j = 0; j < lines.length; j++) {
                    var line = lines[j];
                    if (line.match(/^---/)) {
                        continue;
                    }
                    var m;
                    if (m = line.match(/^\+\+\+ (.*)$/)) {
                        if (!m[1]) {
                            continue;
                        }
                        // m[1] is something like a/frontend/src/myfile.js
                        filename = m[1].replace(/^b\//, '');
                        continue;
                    }
                    if (line.match(/^@@ /)) {
                        section = line;
                        continue;
                    }
                    if (line[0] === '-' || line[0] === '+') {
                        var info = {
                            message: message,
                            filename: filename,
                            line: line
                        };
                        patchInfo[filename + section + line] = info;
                        if (!patchInfoWithoutSection[filename]) {
                            patchInfoWithoutSection[filename] = [];
                        }
                        patchInfoWithoutSection[filename].push(info);
                    }
                }
            }

            cb(patchInfo, patchInfoWithoutSection);
        });
    }

    // main

    var [documentLines, linesWithoutSection] = collectMainDiffLines();
    collectPatchInfo(function(patchInfo, patchInfoWithoutSection) {
        for (var k in patchInfo) {
            var info = patchInfo[k];
            var line = documentLines[k];
            if (!line) {
                // not found -> the displayed diff is probably a combination of multiple patches
                // Ignore the section, and just search the patch for matching lines in this file
                var matchingLines = linesWithoutSection[info.filename];
                if (!matchingLines) {
                    continue;
                }
                for (var i = 0; i < matchingLines.length; i++) {
                    var match = matchingLines[i];
                    if (match.text === info.line) {
                        line = match.element;
                        break;
                    }
                }
                if (!line) {
                    continue;
                }
            }
            line.innerHTML += '<aside>' + info.message + '</aside>';
        }
    });
}

{'fraction_non_alphanumeric': 0.13442347000120236, 'fraction_numerical': 0.0054106047853793434, 'mean_word_length': 1.0412269938650307, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 8, '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': '3897639', 'n_tokens_mistral': 2156, 'n_tokens_neox': 1996, 'n_words': 441}