<commit_before>var fs = require("fs");
var nodePath = require("path");
var index = require("./index");
var files = require("./files");
var objects = require("./objects");
var refs = require("./refs");
var diff = require("./diff");
var util = require("./util");

var checkout = module.exports = {
  writeWorkingCopy: function(fromHash, toHash) {
    var changes = diff.readDiff(fromHash, toHash);
    var checkoutIndex = objects.readCommitToc(toHash);
    Object.keys(changes).forEach(function(path) {
      if (changes[path] === diff.FILE_STATUS.ADD ||
          changes[path] === diff.FILE_STATUS.MODIFY) { // no line by line for now
          var content = objects.read(checkoutIndex[path]);
        files.writeFilesFromTree(util.assocIn({}, path.split(nodePath.sep).concat(content)),
                                 files.repoDir());
      } else if (changes[path] === diff.FILE_STATUS.DELETE) {
        fs.unlinkSync(path);
      }
    });

    fs.readdirSync(files.repoDir())
      .filter(function(dirChild) { return dirChild !== ".gitlet"; })
      .filter(function(dirChild) { return fs.statSync(dirChild).isDirectory(); })
      .forEach(files.deleteEmptyDirs);
  }
};
<commit_msg>Use new files.write()<commit_after>var fs = require("fs");
var nodePath = require("path");
var index = require("./index");
var files = require("./files");
var objects = require("./objects");
var refs = require("./refs");
var diff = require("./diff");
var util = require("./util");

var checkout = module.exports = {
  writeWorkingCopy: function(fromHash, toHash) {
    var changes = diff.readDiff(fromHash, toHash);
    var checkoutIndex = objects.readCommitToc(toHash);
    Object.keys(changes).forEach(function(path) {
      if (changes[path] === diff.FILE_STATUS.ADD ||
          changes[path] === diff.FILE_STATUS.MODIFY) { // no line by line for now
        files.write(nodePath.join(files.repoDir(), path), objects.read(checkoutIndex[path]));
      } else if (changes[path] === diff.FILE_STATUS.DELETE) {
        fs.unlinkSync(path);
      }
    });

    fs.readdirSync(files.repoDir())
      .filter(function(dirChild) { return dirChild !== ".gitlet"; })
      .filter(function(dirChild) { return fs.statSync(dirChild).isDirectory(); })
      .forEach(files.deleteEmptyDirs);
  }
};

{'fraction_non_alphanumeric': 0.17273125822007893, 'fraction_numerical': 0.0, 'mean_word_length': 3.5277777777777777, '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': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4069581', 'n_tokens_mistral': 702, 'n_tokens_neox': 693, 'n_words': 137}