navid/veins / 96f30f16c4319a85e8ccc3c97bc84950cf53e5f9cf7db59977076b5c1f3796cf / xveins/src/worktree/attributes.h

attributes.h

← xveins/src/worktree · 1149 bytes · raw · download

#pragma once

#include "core/common.h"

#include <cstdint>
#include <string>
#include <string_view>
#include <vector>

namespace vn {

enum class AttributeEol : std::uint8_t {
    None = 0,
    Lf = 1,
    Crlf = 2,
    Cr = 3,
};

enum class AttributeText : std::uint8_t {
    Auto = 0,
    Text = 1,
    Binary = 2,
};

struct PathAttributes {
    bool generated = false;
    AttributeText text = AttributeText::Auto;
    AttributeEol eol = AttributeEol::None;
};

class AttributeRules {
public:
    static AttributeRules load(const fs::path& root);

    PathAttributes lookup(std::string_view path) const;
    bool changed_since(std::int64_t cache_written_ms) const;

private:
    struct Rule {
        std::string pattern;
        bool has_slash = false;
        bool generated_set = false;
        bool generated = false;
        bool text_set = false;
        AttributeText text = AttributeText::Auto;
        bool eol_set = false;
        AttributeEol eol = AttributeEol::None;
    };

    std::vector<Rule> rules_;
    std::int64_t mtime_ns_ = 0;
};

std::vector<std::uint8_t> normalize_eol(Bytes data, AttributeEol eol);

} // namespace vn