Line data Source code
1 : /*! 2 : * \file esys/repo/sharing/policy.h 3 : * \brief Sharing policy enums (ADR-0040) 4 : * 5 : * \cond 6 : * __legal_b__ 7 : * 8 : * Copyright (c) 2026 Michel Gillet 9 : * Distributed under the MIT License. 10 : * (See accompanying file LICENSE.txt or 11 : * copy at https://opensource.org/licenses/MIT) 12 : * 13 : * __legal_e__ 14 : * \endcond 15 : * 16 : */ 17 : 18 : #pragma once 19 : 20 : #include "esys/repo/esysrepo_defs.h" 21 : 22 : #include <optional> 23 : #include <string> 24 : 25 : namespace esys::repo::sharing 26 : { 27 : 28 : enum class Policy 29 : { 30 : Worktree = 0, 31 : }; 32 : 33 : enum class RevisionMismatch 34 : { 35 : Warn = 0, 36 : // Allow / Error reserved for follow-up (ADR-0040) 37 : }; 38 : 39 : /*! \class Config esys/repo/sharing/policy.h 40 : * \brief Parsed ``<sharing>`` attributes for one repository 41 : */ 42 : class ESYSREPO_API Config 43 : { 44 : public: 45 4 : Config() = default; 46 : Config(Policy policy, RevisionMismatch mismatch = RevisionMismatch::Warn); 47 : 48 : void set_policy(Policy policy); 49 : Policy get_policy() const; 50 : 51 : void set_revision_mismatch(RevisionMismatch mismatch); 52 : RevisionMismatch get_revision_mismatch() const; 53 : 54 : bool operator==(const Config &other) const; 55 : bool operator!=(const Config &other) const; 56 : 57 : static std::optional<Policy> parse_policy(const std::string &text); 58 : static std::optional<RevisionMismatch> parse_revision_mismatch(const std::string &text); 59 : static const char *to_string(Policy policy); 60 : static const char *to_string(RevisionMismatch mismatch); 61 : 62 : private: 63 : Policy m_policy = Policy::Worktree; 64 : RevisionMismatch m_revision_mismatch = RevisionMismatch::Warn; 65 : }; 66 : 67 : } // namespace esys::repo::sharing