<commit_before>var fs = require('fs');
var empty = {//return empty values to prevent 'undefined' in strings
  gitBranch: '',
  gitRev: '',
  gitShortRev: ''
};

function readInfo(dir) {
  var re, ref, head;
  var sha = '';
  var branch = 'HEAD'; //default if detached
  if (!fs.existsSync(dir +'/HEAD')) {
    return empty;
  }
  ref = fs.readFileSync(dir +'/HEAD', 'UTF-8');
  head = /(ref\: )?(.+)\s$/.exec(ref);
  if (head) {
    //if it's a branch, we read the rev from it's ref file
    if (head[1]) {
      ref = head[2];
      branch = ref.replace('refs/heads/', '');
      if (fs.existsSync(dir + '/' + ref)) {
        //read sha from file under refs folder if exists
        sha = fs.readFileSync(dir +'/' + ref, 'UTF-8');
      } else if (fs.existsSync(dir + '/' + 'packed-refs')) {
        //otherwise read it from "packed-refs" file
        re = new RegExp('^([^\\s]{40})\\s' + ref + '$');
        sha = re.exec(fs.readFileSync(dir + '/' + 'packed-refs'));
        sha = sha && sha[1] || '';
      }
    } else {
      // otherwise we return the rev found in the HEAD file
      sha = head[2];
    }
  }
  return {
    gitBranch: branch,
    gitRev: sha.trim(),
    gitShortRev: sha.substr(0, 7), //short rev
  };
}

module.exports = function (gitDir) {
  gitDir = gitDir || '.git';

  if (!fs.existsSync(gitDir)) {
    return empty;
  }

  if (fs.statSync(gitDir).isFile()) {
    //if .git is a file it means that it is a submodule, so we follow the path found in it
    gitDir = fs.readFileSync(gitDir, 'UTF-8').replace('gitdir: ', '');
  }
  return readInfo(gitDir);
};<commit_msg>fixed git path when submodule<commit_after>var fs = require('fs');
var empty = {//return empty values to prevent 'undefined' in strings
  gitBranch: '',
  gitRev: '',
  gitShortRev: ''
};

function readInfo(dir) {
  var re, ref, head;
  var sha = '';
  var branch = 'HEAD'; //default if detached
  if (!fs.existsSync(dir +'/HEAD')) {
    return empty;
  }
  ref = fs.readFileSync(dir +'/HEAD', 'UTF-8');
  head = /(ref\: )?(.+)\s$/.exec(ref);
  if (head) {
    //if it's a branch, we read the rev from it's ref file
    if (head[1]) {
      ref = head[2];
      branch = ref.replace('refs/heads/', '');
      if (fs.existsSync(dir + '/' + ref)) {
        //read sha from file under refs folder if exists
        sha = fs.readFileSync(dir +'/' + ref, 'UTF-8');
      } else if (fs.existsSync(dir + '/' + 'packed-refs')) {
        //otherwise read it from "packed-refs" file
        re = new RegExp('^([^\\s]{40})\\s' + ref + '$');
        sha = re.exec(fs.readFileSync(dir + '/' + 'packed-refs'));
        sha = sha && sha[1] || '';
      }
    } else {
      // otherwise we return the rev found in the HEAD file
      sha = head[2];
    }
  }
  return {
    gitBranch: branch,
    gitRev: sha.trim(),
    gitShortRev: sha.substr(0, 7), //short rev
  };
}

module.exports = function (gitDir) {
  gitDir = gitDir || '.git';

  if (!fs.existsSync(gitDir)) {
    return empty;
  }

  if (fs.statSync(gitDir).isFile()) {
    //if .git is a file it means that it is a submodule, so we follow the path found in it
    gitDir = fs.readFileSync(gitDir, 'UTF-8').replace('gitdir: ', '');
  }
  return readInfo(gitDir.trim());
};
{'fraction_non_alphanumeric': 0.18818040435458788, 'fraction_numerical': 0.006842923794712286, 'mean_word_length': 2.488069414316703, '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': '604129', 'n_tokens_mistral': 1158, 'n_tokens_neox': 1131, 'n_words': 320}