<commit_before>var Q = require('q');
var bufferUtils = require('./arraybuffer');

var FILETYPE = require('../constants/filetype');
var Change = require('../models/change');
var File = require('../models/file');

var error = require('./error');
var ChangeUtils = require('./change');
var WorkingUtils = require('./working');
var RepoUtils = require('./repo');
var CacheUtils = require('./cache');

/**
 * Fetch a file blob. Required for content access with
 * stat/read. No-op if there are pending changes for the file.
 * @param {RepositoryState} repoState
 * @param {Driver} driver
 * @param {Path} filepath
 * @return {Promise<RepositoryState>}
 */
function fetch(repoState, driver, filepath) {
    var workingState = repoState.getCurrentState();

    if (isFetched(repoState, filepath)) {
        // No op if already fetched
        return Q(repoState);
    }

    var blobSha = WorkingUtils.findSha(workingState, filepath);
    var cache = workingState.getCache();

    // Fetch the blob
    return driver.fetchBlob(blobSha)
    // Then store it in the cache
    .then(function(blob) {
        var newCache = CacheUtils.addBlob(cache, blob);
        return RepoUtils.updateCurrentWorkingState(
            repoState,
            workingState.set('cache', newCache));
    });
}

/**
 * @param {RepositoryState} repoState
 * @param {Path} filepath
 * @return {Boolean} True if the file does not need to be fetched
 */
function isFetched(repoState, filepath) {
    var workingState = repoState.getCurrentState();
    if (WorkingUtils.hasPendingChanges(workingState, filepath)) {
        return true;
    } else {
        var blobSha = WorkingUtils.findSha(workingState, filepath);
        return workingState.getCache().getBlobs().has(blobSha);
    }
}<commit_msg>Fix FileUtils.isFetched<commit_after>var Q = require('q');
var bufferUtils = require('./arraybuffer');

var FILETYPE = require('../constants/filetype');
var Change = require('../models/change');
var File = require('../models/file');

var error = require('./error');
var ChangeUtils = require('./change');
var WorkingUtils = require('./working');
var RepoUtils = require('./repo');
var CacheUtils = require('./cache');

/**
 * Fetch a file blob. Required for content access with
 * stat/read. No-op if there are pending changes for the file.
 * @param {RepositoryState} repoState
 * @param {Driver} driver
 * @param {Path} filepath
 * @return {Promise<RepositoryState>}
 */
function fetch(repoState, driver, filepath) {
    var workingState = repoState.getCurrentState();

    if (isFetched(repoState, filepath)) {
        // No op if already fetched
        return Q(repoState);
    }

    var blobSha = WorkingUtils.findSha(workingState, filepath);
    var cache = workingState.getCache();

    // Fetch the blob
    return driver.fetchBlob(blobSha)
    // Then store it in the cache
    .then(function(blob) {
        var newCache = CacheUtils.addBlob(cache, blob);
        return RepoUtils.updateCurrentWorkingState(
            repoState,
            workingState.set('cache', newCache));
    });
}

/**
 * @param {RepositoryState} repoState
 * @param {Path} filepath
 * @return {Boolean} True if the file's content can be accessed
 * without fetching it
 */
function isFetched(repoState, filepath) {
    var workingState = repoState.getCurrentState();
    var blobSha = WorkingUtils.findSha(workingState, filepath);
    // If sha is null then there are changes (those which are stored
    // and need not be fetched)
    return (blobSha === null) || (workingState.getCache().getBlobs().has(blobSha));
}
{'fraction_non_alphanumeric': 0.13465845464725643, 'fraction_numerical': 0.0, 'mean_word_length': 3.5573979591836733, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1154322', 'n_tokens_mistral': 1029, 'n_tokens_neox': 1023, 'n_words': 297}