<commit_before>'use strict';

const events = require('events');
const spawn = require('child_process').spawn;
const split2 = require('split2');

function executeCommand(gitSource, path, extraArguments) {
  const args = ['ls-files'];
  const errorBuffers = [];

  if (extraArguments) {
    args.push(...extraArguments);
  }

  const ls = spawn('git', args, { cwd: path });
  ls.stdout
    .pipe(split2())
    .on('data', data => {
      gitSource._handleDataCallbacks(data);
    });


  ls.stderr.on('data', (data) => {
    errorBuffers.push(data);
  });

  ls.on('close', (code) => {
    if (errorBuffers.length > 0) {
      const errorString = Buffer.concat(errorBuffers).toString();
      gitSource._handleErrorCallbacks(errorString);
    }
    if (code !== 0) {
      // TODO: do something
      console.error(`Uh oh, bad exit code ${code}`);
      return;
    }

    gitSource._handleDoneCallbacks();
  });
}

class GitSource extends events.EventEmitter
{
  constructor() {
    super();
    this.numberOfCommandsToProcess = 2;
    this.isRepo = true;
  }

  readFiles(path) {

    this.numberOfCommandsProcessed = 0;
    executeCommand(this, path);
    executeCommand(this, path, ['--other', '--exclude-standard']);
  }

  _handleDataCallbacks(data) {
    this.emit('data', data);
  }

  _handleDoneCallbacks() {
    if (this.isRepo && 
        ++this.numberOfCommandsProcessed === 
          this.numberOfCommandsToProcess) {
      this.emit('done');
    }
  }

  _handleErrorCallbacks(error) {
    // if we're just not in a git repo, just emit done
    if (error.match(/Not a git repository/)) {
      this.isRepo = false;
      this.emit('notsupported');
    } else {
      this.emit('error', error);
    }
  }
}

module.exports = GitSource;<commit_msg>ensure that not a repo is only signalled once.<commit_after>'use strict';

const events = require('events');
const spawn = require('child_process').spawn;
const split2 = require('split2');

function executeCommand(gitSource, path, extraArguments) {
  const args = ['ls-files'];
  const errorBuffers = [];

  if (extraArguments) {
    args.push(...extraArguments);
  }

  const ls = spawn('git', args, { cwd: path });
  ls.stdout
    .pipe(split2())
    .on('data', data => {
      gitSource._handleDataCallbacks(data);
    });


  ls.stderr.on('data', (data) => {
    errorBuffers.push(data);
  });

  ls.on('close', (code) => {
    if (errorBuffers.length > 0) {
      const errorString = Buffer.concat(errorBuffers).toString();
      gitSource._handleErrorCallbacks(errorString);
    }
    if (code !== 0) {
      // TODO: do something
      console.error(`Uh oh, bad exit code ${code}`);
      return;
    }

    gitSource._handleDoneCallbacks();
  });
}

class GitSource extends events.EventEmitter
{
  constructor() {
    super();
    this.numberOfCommandsToProcess = 2;
    this.isRepo = true;
  }

  readFiles(path) {

    this.numberOfCommandsProcessed = 0;
    executeCommand(this, path);
    executeCommand(this, path, ['--other', '--exclude-standard']);
  }

  _handleDataCallbacks(data) {
    this.emit('data', data);
  }

  _handleDoneCallbacks() {
    if (this.isRepo && 
        ++this.numberOfCommandsProcessed === 
          this.numberOfCommandsToProcess) {
      this.emit('done');
    }
  }

  _handleErrorCallbacks(error) {
    // if we're just not in a git repo, just emit done
    if (error.match(/Not a git repository/)) {
      if (this.isRepo) {
        this.isRepo = false;
        this.emit('notsupported');
      }
    } else {
      this.emit('error', error);
    }
  }
}

module.exports = GitSource;
{'fraction_non_alphanumeric': 0.1554317548746518, 'fraction_numerical': 0.0038997214484679664, 'mean_word_length': 2.941822173435785, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '7272945', 'n_tokens_mistral': 1187, 'n_tokens_neox': 1156, 'n_words': 235}