<commit_before>var through = require('through2');
var gutil = require('gulp-util');
var path = require('path');

module.exports = function override() {
    var allowedPathRegExp = /\.(css|js)$/;

    function relPath(base, filePath) {
        if (filePath.indexOf(base) !== 0) {
            return filePath;
        }
        var newPath = filePath.substr(base.length);
        if (newPath[0] === path.sep) {
            return newPath.substr(1);
        } else {
            return newPath;
        }
    }

    var f = [];

    return through.obj(function (file, enc, cb) {
        var firstFile = null;

        if (file.path && file.revOrigPath) {
            firstFile = firstFile || file;
            var _relPath = relPath(path.resolve(firstFile.revOrigBase), file.revOrigPath);

            f.push({
                origPath: _relPath,
                hashedPath: relPath(path.resolve(firstFile.base), file.path),
                file: file
            });
        }
        cb();
    }, function (cb) {
        var self = this;
        f.forEach(function (_f) {
            if ((allowedPathRegExp.test(_f.file.revOrigPath) ) && _f.file.contents) {
                var contents = _f.file.contents.toString();
                f.forEach(function (__f) {
                    contents = contents.replace(
                        new RegExp(__f.origPath.replace('.', "\\."), 'g'),
                        __f.hashedPath);
                });
<commit_msg>Change \ to / in case we are running on windows.<commit_after>var through = require('through2');
var gutil = require('gulp-util');
var path = require('path');

module.exports = function override() {
    var allowedPathRegExp = /\.(css|js)$/;

    function relPath(base, filePath) {
        if (filePath.indexOf(base) !== 0) {
            return filePath;
        }
        var newPath = filePath.substr(base.length);
        if (newPath[0] === path.sep) {
            return newPath.substr(1);
        } else {
            return newPath;
        }
    }

    var f = [];

    return through.obj(function (file, enc, cb) {
        var firstFile = null;

        if (file.path && file.revOrigPath) {
            firstFile = firstFile || file;
            var _relPath = relPath(path.resolve(firstFile.revOrigBase), file.revOrigPath);

            f.push({
                origPath: _relPath,
                hashedPath: relPath(path.resolve(firstFile.base), file.path),
                file: file
            });
        }
        cb();
    }, function (cb) {
        var self = this;
        f.forEach(function (_f) {
            if ((allowedPathRegExp.test(_f.file.revOrigPath) ) && _f.file.contents) {
                var contents = _f.file.contents.toString();
                f.forEach(function (__f) {
                    var origPath = __f.origPath.replace(new RegExp('\\' + path.sep, 'g'), '/').replace(/\./g, "\\.");
                    var hashedPath = __f.hashedPath.replace(new RegExp('\\' + path.sep, 'g'), '/');
                    contents = contents.replace(
                        new RegExp(origPath, 'g'),
                        hashedPath);
                });

{'fraction_non_alphanumeric': 0.14080917489646383, 'fraction_numerical': 0.002548582351067219, 'mean_word_length': 1.654268808114962, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '150713', 'n_tokens_mistral': 934, 'n_tokens_neox': 897, 'n_words': 189}