#pragma once #include "common.h" #include #include #include namespace vn { class Store; constexpr std::uint8_t TYPE_CHUNK = 1; constexpr std::uint8_t TYPE_BLOB = 2; constexpr std::uint8_t TYPE_TREE = 3; constexpr std::uint8_t TYPE_COMMIT = 4; constexpr std::uint8_t TYPE_CONFLICT = 5; constexpr std::uint8_t TYPE_OPERATION = 6; constexpr std::uint8_t TYPE_VIEW = 7; std::string_view type_name(std::uint8_t type); bool type_valid(std::uint8_t type); struct RawObject { std::uint8_t type = 0; std::vector body; std::optional id; }; struct KeyValue { std::string key; std::string value; }; // --------------------------------------------------------------------------- // Names // --------------------------------------------------------------------------- bool valid_name(std::string_view name); bool valid_path(std::string_view path); // --------------------------------------------------------------------------- // Blobs // --------------------------------------------------------------------------- enum class BlobForm : std::uint8_t { Inline = 0, Leaf = 1, Interior = 2 }; struct BlobEntry { Id id{}; std::uint64_t length = 0; }; struct Blob { BlobForm form = BlobForm::Inline; std::vector data; std::vector entries; }; Result decode_blob(Bytes body); Result> encode_inline_blob(Bytes data); std::size_t fastcdc_next(Bytes data); const std::array &fastcdc_gear(); struct BlobBuild { Id root{}; std::vector objects; }; BlobBuild build_blob(Bytes data); // --------------------------------------------------------------------------- // Trees // --------------------------------------------------------------------------- constexpr std::uint8_t KIND_FILE = 1; constexpr std::uint8_t KIND_EXECUTABLE = 2; constexpr std::uint8_t KIND_SYMLINK = 3; constexpr std::uint8_t KIND_SUBTREE = 4; constexpr std::uint8_t KIND_SUBMODULE = 5; constexpr std::uint8_t KIND_CONFLICT = 6; constexpr std::uint8_t KIND_MISSING = 0; struct TreeEntry { std::string name; std::uint8_t kind = 0; Id target{}; }; struct Tree { std::vector entries; std::vector body; }; Result decode_tree(Bytes body); Result> encode_tree(const std::vector &entries); // --------------------------------------------------------------------------- // Commits // --------------------------------------------------------------------------- constexpr std::uint8_t RENAMES_UNKNOWN = 0; constexpr std::uint8_t RENAMES_RECORDED = 1; struct Rename { std::uint64_t parent_index = 0; std::uint8_t kind = 0; std::string from_path; std::string to_path; }; struct Commit { std::uint8_t version = 1; std::vector parents; Id root_tree{}; ChangeId change_id{}; Sig author; Sig committer; std::string message; std::uint8_t renames_state = RENAMES_RECORDED; std::vector renames; std::vector extra; }; Result decode_commit(Bytes body); std::vector encode_commit(const Commit &commit); // --------------------------------------------------------------------------- // Conflicts // --------------------------------------------------------------------------- struct ConflictValue { std::uint8_t kind = 0; std::optional target; }; struct Conflict { std::vector adds; std::vector removes; }; Result decode_conflict(Bytes body); std::vector encode_conflict(const Conflict &conflict); // --------------------------------------------------------------------------- // Operations and views // --------------------------------------------------------------------------- struct TargetSet { std::vector> adds; std::vector> removes; }; struct Bookmark { std::string name; TargetSet targets; }; struct TagRef { std::string name; Id target{}; }; struct RemoteRef { std::string remote; std::string name; Id target{}; }; struct WorkspaceRef { std::string workspace; Id target{}; }; struct View { std::vector heads; std::vector bookmarks; std::vector tags; std::vector remote_refs; std::vector working_copies; }; struct Operation { std::vector parents; Id view{}; Reader::TimeMs start; Reader::TimeMs end; std::string hostname; std::string username; std::string description; std::vector tags; }; Result decode_view(Bytes body); std::vector encode_view(const View &view); Result decode_operation(Bytes body); std::vector encode_operation(const Operation &op); // --------------------------------------------------------------------------- // Graph, tree walking, and content // --------------------------------------------------------------------------- struct LoadedCommit { Commit commit; std::vector body; }; std::optional load_commit(Store &store, const Id &id); bool has_changes(Store &store, const LoadedCommit &loaded); std::vector collect_commits(Store &store, std::span start); std::vector all_commits(Store &store, const View &view); std::vector view_roots(const View &view); std::optional resolve_revision(Store &store, const View &view, std::string_view rev); std::optional working_copy_id(const View &view); bool contains_id(const std::vector &ids, const Id &id); bool target_contains(const std::vector> &ids, const Id &id); struct FlatEntry { std::string path; std::uint8_t kind = 0; Id target{}; }; std::vector flatten_tree(Store &store, const Id &tree_id); Result> flatten_tree_checked(Store &store, const Id &tree_id); std::vector flatten_or_empty(Store &store, std::optional tree_id); const FlatEntry *find_flat(const std::vector &entries, std::string_view path); int find_tree_name(const Tree &tree, std::string_view name); bool tree_conflicted(Store &store, const Id &tree_id); struct TreeChange { std::string path; std::uint8_t old_kind = KIND_MISSING; std::uint8_t new_kind = KIND_MISSING; std::optional old_id; std::optional new_id; }; std::vector compare_trees(Store &store, std::optional old_tree, std::optional new_tree); std::optional> read_blob(Store &store, const Id &id); bool is_lazy_blob(const Id &id); } // namespace vn