<commit_before>#include "fetchers.hh"
#include "store-api.hh"

namespace nix::fetchers {

struct PathInput : Input
{
    Path path;

    /* Allow the user to pass in "fake" tree info attributes. This is
       useful for making a pinned tree work the same as the repository
       from which is exported
       (e.g. path:/nix/store/...-source?lastModified=1585388205&rev=b0c285...). */
    std::optional<Hash> rev;
    std::optional<uint64_t> revCount;
    std::optional<time_t> lastModified;

    std::string type() const override { return "path"; }

    std::optional<Hash> getRev() const override { return rev; }

    bool operator ==(const Input & other) const override
    {
        auto other2 = dynamic_cast<const PathInput *>(&other);
        return
            other2
            && path == other2->path
            && rev == other2->rev
            && revCount == other2->revCount
            && lastModified == other2->lastModified;
    }

    bool isImmutable() const override
    {
        return (bool) narHash;
    }

    ParsedURL toURL() const override
    {
        auto query = attrsToQuery(toAttrsInternal());
        query.erase("path");
        return ParsedURL {
            .scheme = "path",
            .path = path,
            .query = query,
        };
    }

    Attrs toAttrsInternal() const override
    {
        Attrs attrs;
        attrs.emplace("path", path);
        if (rev)
            attrs.emplace("rev", rev->gitRev());
        if (revCount)
            attrs.emplace("revCount", *revCount);
        if (lastModified)
            attrs.emplace("lastModified", *lastModified);
        return attrs;
    }

    std::pair<Tree, std::shared_ptr<const Input>> fetchTreeInternal(nix::ref<Store> store) const override
    {
        auto input = std::make_shared<PathInput>(*this);

        auto storePath = store->maybeParseStorePath(path);

        if (storePath)
            store->addTempRoot(*storePath);

        if (!storePath || storePath->name() != "source" || !store->isValidPath(*storePath))
            // FIXME: try to substitute storePath.
            storePath = store->addToStore("name", path);

        return
            {
                Tree {
                    .actualPath = store->toRealPath(*storePath),
                    .storePath = std::move(*storePath),
                    .info = TreeInfo {
                        .revCount = revCount,
                        .lastModified = lastModified
                    }<commit_msg>Add FIXME<commit_after>#include "fetchers.hh"
#include "store-api.hh"

namespace nix::fetchers {

struct PathInput : Input
{
    Path path;

    /* Allow the user to pass in "fake" tree info attributes. This is
       useful for making a pinned tree work the same as the repository
       from which is exported
       (e.g. path:/nix/store/...-source?lastModified=1585388205&rev=b0c285...). */
    std::optional<Hash> rev;
    std::optional<uint64_t> revCount;
    std::optional<time_t> lastModified;

    std::string type() const override { return "path"; }

    std::optional<Hash> getRev() const override { return rev; }

    bool operator ==(const Input & other) const override
    {
        auto other2 = dynamic_cast<const PathInput *>(&other);
        return
            other2
            && path == other2->path
            && rev == other2->rev
            && revCount == other2->revCount
            && lastModified == other2->lastModified;
    }

    bool isImmutable() const override
    {
        return (bool) narHash;
    }

    ParsedURL toURL() const override
    {
        auto query = attrsToQuery(toAttrsInternal());
        query.erase("path");
        return ParsedURL {
            .scheme = "path",
            .path = path,
            .query = query,
        };
    }

    Attrs toAttrsInternal() const override
    {
        Attrs attrs;
        attrs.emplace("path", path);
        if (rev)
            attrs.emplace("rev", rev->gitRev());
        if (revCount)
            attrs.emplace("revCount", *revCount);
        if (lastModified)
            attrs.emplace("lastModified", *lastModified);
        return attrs;
    }

    std::pair<Tree, std::shared_ptr<const Input>> fetchTreeInternal(nix::ref<Store> store) const override
    {
        auto input = std::make_shared<PathInput>(*this);

        // FIXME: check whether access to 'path' is allowed.

        auto storePath = store->maybeParseStorePath(path);

        if (storePath)
            store->addTempRoot(*storePath);

        if (!storePath || storePath->name() != "source" || !store->isValidPath(*storePath))
            // FIXME: try to substitute storePath.
            storePath = store->addToStore("name", path);

        return
            {
                Tree {
                    .actualPath = store->toRealPath(*storePath),
                    .storePath = std::move(*storePath),
                    .info = TreeInfo {
                        .revCount = revCount,
                        .lastModified = lastModified
                    }
{'fraction_non_alphanumeric': 0.12068281063914252, 'fraction_numerical': 0.008733624454148471, 'mean_word_length': 1.9279488669378269, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 43, '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': '3479905', 'n_tokens_mistral': 1434, 'n_tokens_neox': 1377, 'n_words': 343}