<commit_before>#!/usr/bin/env node
var diff = require("diff");
var fs = require("fs");

function applyPatch(patchFile) {
  var patch = fs.readFileSync(patchFile, "utf8");

  var sourceFileMatch = /--- ([^ ]+).*/.exec(patch);
  var sourceFile;
  if (sourceFileMatch && sourceFileMatch[1]) {
    sourceFile = sourceFileMatch[1];
  } else {
    throw Error("Unable to find source file in '" + patchFile + "'");
  }
  var destinationFileMatch = /\+\+\+ ([^ ]+).*/.exec(patch);
  var destinationFile;
  if (destinationFileMatch && destinationFileMatch[1]) {
    destinationFile = destinationFileMatch[1];
  } else {
    throw Error("Unable to find destination file in '" + patchFile + "'");
  }

  var original = fs.readFileSync(sourceFile, "utf8");
  var patched = diff.applyPatch(original, patch);

  if (patched === false) {
    throw Error("Failed apply patch '" + patchFile + "' to '" + sourceFile + "'");
  } else if (sourceFile !== destinationFile) {
    console.log("Applied '" + patchFile + "' to '" + sourceFile + "' and stored it as '" +
      destinationFile + "'");
  } else {
    console.log("Applied '" + patchFile + "' to '" + sourceFile + "'");
  }

  fs.writeFileSync(destinationFile, patched);
}

module.exports.applyPatch = applyPatch;

if (require.main === module) {
  var argv = process.argv;
  for (var i = 2; i < argv.length; i++) {
    applyPatch(argv[i]);
  }
}
<commit_msg>Don't allow newline characters in file names<commit_after>#!/usr/bin/env node
var diff = require("diff");
var fs = require("fs");

function applyPatch(patchFile) {
  var patch = fs.readFileSync(patchFile, "utf8");

  var sourceFileMatch = /--- ([^ \n\r]+).*/.exec(patch);
  var sourceFile;
  if (sourceFileMatch && sourceFileMatch[1]) {
    sourceFile = sourceFileMatch[1];
  } else {
    throw Error("Unable to find source file in '" + patchFile + "'");
  }
  var destinationFileMatch = /\+\+\+ ([^ \n\r]+).*/.exec(patch);
  var destinationFile;
  if (destinationFileMatch && destinationFileMatch[1]) {
    destinationFile = destinationFileMatch[1];
  } else {
    throw Error("Unable to find destination file in '" + patchFile + "'");
  }

  var original = fs.readFileSync(sourceFile, "utf8");
  var patched = diff.applyPatch(original, patch);

  if (patched === false) {
    throw Error("Failed apply patch '" + patchFile + "' to '" + sourceFile + "'");
  } else if (sourceFile !== destinationFile) {
    console.log("Applied '" + patchFile + "' to '" + sourceFile + "' and stored it as '" +
      destinationFile + "'");
  } else {
    console.log("Applied '" + patchFile + "' to '" + sourceFile + "'");
  }

  fs.writeFileSync(destinationFile, patched);
}

module.exports.applyPatch = applyPatch;

if (require.main === module) {
  var argv = process.argv;
  for (var i = 2; i < argv.length; i++) {
    applyPatch(argv[i]);
  }
}

{'fraction_non_alphanumeric': 0.17709437963944857, 'fraction_numerical': 0.00494874513962531, 'mean_word_length': 3.6469622331691296, 'pattern_counts': {'":': 0, '<': 5, '<?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': '1899988', 'n_tokens_mistral': 918, 'n_tokens_neox': 894, 'n_words': 218}