Line data Source code
1 : /*! 2 : * \file esys/repo/sharing/policy_sharing.cpp 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 : #include "esys/repo/esysrepo_prec.h" 19 : #include "esys/repo/sharing/policy.h" 20 : 21 : namespace esys::repo::sharing 22 : { 23 : 24 4 : Config::Config(Policy policy, RevisionMismatch mismatch) 25 4 : : m_policy(policy) 26 4 : , m_revision_mismatch(mismatch) 27 : { 28 4 : } 29 : 30 0 : void Config::set_policy(Policy policy) 31 : { 32 0 : m_policy = policy; 33 0 : } 34 : 35 2 : Policy Config::get_policy() const 36 : { 37 2 : return m_policy; 38 : } 39 : 40 0 : void Config::set_revision_mismatch(RevisionMismatch mismatch) 41 : { 42 0 : m_revision_mismatch = mismatch; 43 0 : } 44 : 45 1 : RevisionMismatch Config::get_revision_mismatch() const 46 : { 47 1 : return m_revision_mismatch; 48 : } 49 : 50 0 : bool Config::operator==(const Config &other) const 51 : { 52 0 : return m_policy == other.m_policy && m_revision_mismatch == other.m_revision_mismatch; 53 : } 54 : 55 0 : bool Config::operator!=(const Config &other) const 56 : { 57 0 : return !operator==(other); 58 : } 59 : 60 2 : std::optional<Policy> Config::parse_policy(const std::string &text) 61 : { 62 2 : if (text == "worktree") return Policy::Worktree; 63 1 : return std::nullopt; 64 : } 65 : 66 1 : std::optional<RevisionMismatch> Config::parse_revision_mismatch(const std::string &text) 67 : { 68 1 : if (text == "warn") return RevisionMismatch::Warn; 69 0 : return std::nullopt; 70 : } 71 : 72 1 : const char *Config::to_string(Policy policy) 73 : { 74 1 : switch (policy) 75 : { 76 : case Policy::Worktree: return "worktree"; 77 : } 78 0 : return ""; 79 : } 80 : 81 1 : const char *Config::to_string(RevisionMismatch mismatch) 82 : { 83 1 : switch (mismatch) 84 : { 85 : case RevisionMismatch::Warn: return "warn"; 86 : } 87 0 : return ""; 88 : } 89 : 90 : } // namespace esys::repo::sharing