<commit_before>const fs = require("fs");
const path = require("path");
const utils = require("./utils");
const _ = require("lodash");

var version = require("../package.json").libgit2.version;
var descriptor = require("./descriptor.json");
var libgit2 = require("./v" + version + ".json");

// Turn the types array into a hashmap of struct values
var structs = libgit2.types.reduce(function(hashMap, current) {
  var structName = current[0];
  var structDefOverrides = descriptor[structName] || {};
  var structDef = current[1];

  // currently skipping enums
  if (structDef.type === "enum") {
    return hashMap;
  }

  structDef.cType = structName;

  if (structDef.type === "enum") {
    structDef.isEnum = true;
  }
  else {
    structDef.isStruct = true;
  }

  structDef.isForwardDeclared = structDef.decl === structName;
  structDef.fields = structDef.fields || [];
  structDef.dependencies = [];

  if (!structDef.isForwardDeclared) {
    var dependencyLookup = {};

    structDef.fields.forEach(function (field) {
      var normalizedType = utils.normalizeCtype(field.type);

      field.cType = field.type;
      field.cppFunctionName = utils.titleCase(field.name);
      field.jsFunctionName = utils.camelCase(field.name);
      field.cppClassName = utils.cTypeToCppName(field.type);
      field.jsClassName = utils.cTypeToJsName(field.type);

      // We need to find all of the libgit2 types to build the dependency chain
      var libgitType;

      libgit2.types.some(function (type) {
        if (type[0] === normalizedType) {
          libgitType = type[1];
          return true;
        }
      });

      if (libgitType) {
        dependencyLookup[libgitType.file] = "";

        field.isEnum = libgitType.type === "enum";
        field.hasConstructor
          = libgitType.used
            && libgitType.used.needs
            && libgitType.used.needs[1]
            && utils.isConstructorFunction(
              normalizedType,
              libgitType.used.needs[1]);
      }
    });

    Object.keys(dependencyLookup).forEach(function (dependencyFilename) {
      structDef.dependencies.push("../include/" + dependencyFilename);
    });
  }

  _.merge(structDef, structDefOverrides);

  if (!structDef.ignore) {
    structDef.fields = structDef.fields.filter(function (field) {
      return !field.ignore;
    });

    hashMap[structName] = structDef;
  }

  return hashMap;
}, {});

var classes = libgit2.groups.reduce(function(hashMap, current) {
  var className = current[0];
  var classDefOverrides = descriptor[className] || {};
  var classDef = {
    isClass: true,
    cType: "git_" + className,
    filename: className + ".h",
    cppClassName: utils.cTypeToCppName("git_" + className),
    jsClassName: utils.cTypeToJsName("git_" + className),
    functions: current[1].reduce(function(fnHashMap, currentFn) {
      fnHashMap[currentFn] = libgit2.functions[currentFn];
      return fnHashMap;
    }, {}),
    dependencies: [],
    fields: []
  };

  var dependencyLookup = {};

  // Decorate functions and calculate dependencies
  Object.keys(classDef.functions).forEach(function(key) {
    var fnDef = classDef.functions[key];

    // if this is the free function for the class, make the ref on the class
    if (key == classDef.cType + "_free") {
      classDef.freeFunctionName = key;
    }

    fnDef.cppFunctionName = utils.cTypeToCppName(key);
    fnDef.jsFunctionName = utils.cTypeToJsName(key);
    fnDef.isAsync = false; // until proven otherwise

    fnDef.args.forEach(function(arg) {
      var normalizedType = utils.normalizeCtype(arg.type);

      // We need to find all of the libgit2 types to build the dependency chain
      if (structs[normalizedType]) {
        dependencyLookup[structs[normalizedType].file] = "";<commit_msg>Fixed some bugs in setup.js<commit_after>const fs = require("fs");
const path = require("path");
const utils = require("./utils");
const _ = require("lodash");

var version = require("../package.json").libgit2.version;
var descriptor = require("./descriptor.json");
var libgit2 = require("./v" + version + ".json");

// Turn the types array into a hashmap of struct values
var structs = libgit2.types.reduce(function(hashMap, current) {
  var structName = current[0];
  var structDefOverrides = descriptor[structName] || {};
  var structDef = current[1];

  // currently skipping enums
  if (structDef.type === "enum") {
    return hashMap;
  }

  structDef.cType = structName;

  if (structDef.type === "enum") {
    structDef.isEnum = true;
  }
  else {
    structDef.isStruct = true;
  }

  structDef.isForwardDeclared = structDef.decl === structName;
  structDef.fields = structDef.fields || [];
  structDef.functions = [];
  structDef.dependencies = [];
  structDef.filename = structDef.file;

  if (!structDef.isForwardDeclared) {
    var dependencyLookup = {};

    structDef.fields.forEach(function (field) {
      var normalizedType = utils.normalizeCtype(field.type);

      field.cType = field.type;
      field.cppFunctionName = utils.titleCase(field.name);
      field.jsFunctionName = utils.camelCase(field.name);
      field.cppClassName = utils.cTypeToCppName(field.type);
      field.jsClassName = utils.cTypeToJsName(field.type);

      // We need to find all of the libgit2 types to build the dependency chain
      var libgitType;

      libgit2.types.some(function (type) {
        if (type[0] === normalizedType) {
          libgitType = type[1];
          return true;
        }
      });

      if (libgitType) {
        if (!libgitType.file) debugger;
        dependencyLookup[libgitType.file] = "";

        field.isEnum = libgitType.type === "enum";
        field.hasConstructor
          = libgitType.used
            && libgitType.used.needs
            && libgitType.used.needs[1]
            && utils.isConstructorFunction(
              normalizedType,
              libgitType.used.needs[1]);
      }
    });

    Object.keys(dependencyLookup).forEach(function (dependencyFilename) {
      structDef.dependencies.push("../include/" + dependencyFilename);
    });
  }

  _.merge(structDef, structDefOverrides);

  if (!structDef.ignore) {
    structDef.fields = structDef.fields.filter(function (field) {
      return !field.ignore;
    });

    hashMap[structName] = structDef;
  }

  return hashMap;
}, {});

var classes = libgit2.groups.reduce(function(hashMap, current) {
  var className = current[0];
  var classDefOverrides = descriptor[className] || {};
  var classDef = {
    isClass: true,
    cType: "git_" + className,
    filename: className + ".h",
    cppClassName: utils.cTypeToCppName("git_" + className),
    jsClassName: utils.cTypeToJsName("git_" + className),
    functions: current[1].reduce(function(fnArray, currentFn) {
      var fnDef = libgit2.functions[currentFn];
      fnDef.cFunctionName = currentFn;
      fnArray.push(fnDef);
      return fnArray;
    }, []),
    dependencies: [],
    fields: []
  };

  var dependencyLookup = {};

  // Decorate functions and calculate dependencies
  classDef.functions.forEach(function(fnDef) {
    var key = fnDef.cFunctionName;

    // if this is the free function for the class, make the ref on the class
    if (key == classDef.cType + "_free") {
      classDef.freeFunctionName = key;
    }

    fnDef.cppFunctionName = utils.cTypeToCppName(key);
    fnDef.jsFunctionName = utils.cTypeToJsName(key);
    fnDef.isAsync = false; // until proven otherwise

    fnDef.args.forEach(function(arg) {
      var normalizedType = utils.normalizeCtype(arg.type);

      // We need to find all of the libgit2 types to build the dependency chain
      if (structs[normalizedType]) {
        dependencyLookup[structs[normalizedType].file] = "";
{'fraction_non_alphanumeric': 0.12974724562540504, 'fraction_numerical': 0.004147764095917045, 'mean_word_length': 3.0890302066772657, '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': '302727', 'n_tokens_mistral': 2355, 'n_tokens_neox': 2323, 'n_words': 494}