<commit_before>"use strict";

var modes = require('../lib/modes');

module.exports = function (local, remote) {
  local.fetch = fetch;
  local.send = send;
  local.readRemoteRef = remote.readRef.bind(remote);
  local.updateRemoteRef = remote.updateRef.bind(remote);

  function fetch(ref, depth, callback) {
    if (!callback) return fetch.bind(local, ref, depth);
    sync(local, remote, ref, depth, callback);
  }

  function send(ref, callback) {
    if (!callback) return send.bind(local, ref);
    sync(remote, local, ref, Infinity, callback);
  }
};

// Download remote ref with depth
// Make sure to use Infinity for depth on github mounts or anything that
// doesn't allow shallow clones.
function sync(local, remote, ref, depth, callback) {
  if (typeof ref !== "string") throw new TypeError("ref must be string");
  if (typeof depth !== "number") throw new TypeError("depth must be number");

  var hasCache = {};

  remote.readRef(ref, function (err, hash) {
    if (!hash) return callback(err);
    importCommit(hash, depth, function (err) {
      if (err) return callback(err);
      callback(null, hash);
    });
  });

  // Caching has check.
  function check(type, hash, callback) {
    if (typeof type !== "string") throw new TypeError("type must be string");
    if (typeof hash !== "string") throw new TypeError("hash must be string");
    if (hasCache[hash]) return callback(null, true);
    local.hasHash(type, hash, function (err, has) {
      if (err) return callback(err);
      hasCache[hash] = has;
      callback(null, has);
    });
  }

  function importCommit(hash, depth, callback) {<commit_msg>hasHash no longer has type argument<commit_after>"use strict";

var modes = require('../lib/modes');

module.exports = function (local, remote) {
  local.fetch = fetch;
  local.send = send;
  local.readRemoteRef = remote.readRef.bind(remote);
  local.updateRemoteRef = remote.updateRef.bind(remote);

  function fetch(ref, depth, callback) {
    if (!callback) return fetch.bind(local, ref, depth);
    sync(local, remote, ref, depth, callback);
  }

  function send(ref, callback) {
    if (!callback) return send.bind(local, ref);
    sync(remote, local, ref, Infinity, callback);
  }
};

// Download remote ref with depth
// Make sure to use Infinity for depth on github mounts or anything that
// doesn't allow shallow clones.
function sync(local, remote, ref, depth, callback) {
  if (typeof ref !== "string") throw new TypeError("ref must be string");
  if (typeof depth !== "number") throw new TypeError("depth must be number");

  var hasCache = {};

  remote.readRef(ref, function (err, hash) {
    if (!hash) return callback(err);
    importCommit(hash, depth, function (err) {
      if (err) return callback(err);
      callback(null, hash);
    });
  });

  // Caching has check.
  function check(type, hash, callback) {
    if (typeof type !== "string") throw new TypeError("type must be string");
    if (typeof hash !== "string") throw new TypeError("hash must be string");
    if (hasCache[hash]) return callback(null, true);
    local.hasHash(hash, function (err, has) {
      if (err) return callback(err);
      hasCache[hash] = has;
      callback(null, has);
    });
  }

  function importCommit(hash, depth, callback) {
{'fraction_non_alphanumeric': 0.14237599510104104, 'fraction_numerical': 0.0, 'mean_word_length': 3.741654571843251, '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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3985137', 'n_tokens_mistral': 985, 'n_tokens_neox': 966, 'n_words': 328}