LCOV - code coverage report
Current view: top level - src/esys/repo/manifest - syncs_manifest.cpp (source / functions) Hit Total Coverage
Test: esysrepo_coverage.info Lines: 22 22 100.0 %
Date: 2026-08-12 14:26:50 Functions: 4 4 100.0 %

          Line data    Source code
       1             : /*!
       2             :  * \file esys/repo/manifest/syncs_manifest.cpp
       3             :  * \brief sync-s / recurse-submodules policy (ADR-0032)
       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/manifest/syncs.h"
      20             : #include "esys/repo/manifest.h"
      21             : #include "esys/repo/manifest/repository.h"
      22             : 
      23             : #include <algorithm>
      24             : #include <cctype>
      25             : 
      26             : namespace esys::repo::manifest
      27             : {
      28             : 
      29             : namespace
      30             : {
      31             : 
      32           6 : std::string lower_copy(std::string s)
      33             : {
      34          28 :     std::transform(s.begin(), s.end(), s.begin(), [](unsigned char c) { return static_cast<char>(std::tolower(c)); });
      35           6 :     return s;
      36             : }
      37             : 
      38             : } // namespace
      39             : 
      40           6 : bool parse_sync_s_value(const std::string &value, bool &out)
      41             : {
      42           6 :     const std::string v = lower_copy(value);
      43          13 :     if (v == "true" || v == "yes" || v == "1")
      44             :     {
      45           3 :         out = true;
      46           3 :         return true;
      47             :     }
      48           7 :     if (v == "false" || v == "no" || v == "0")
      49             :     {
      50           2 :         out = false;
      51           2 :         return true;
      52             :     }
      53             :     return false;
      54           6 : }
      55             : 
      56         126 : bool effective_sync_s(const Manifest &manifest, const Repository *repo)
      57             : {
      58         126 :     if (repo != nullptr)
      59             :     {
      60         126 :         const auto &repo_s = repo->get_sync_s();
      61         126 :         if (repo_s.has_value()) return *repo_s;
      62             :     }
      63         124 :     const auto &def = manifest.get_default_sync_s();
      64         124 :     if (def.has_value()) return *def;
      65             :     return false;
      66             : }
      67             : 
      68         125 : bool should_update_submodules(RecurseSubmodules cli, const Manifest &manifest, const Repository *repo)
      69             : {
      70         125 :     if (cli == RecurseSubmodules::Yes) return true;
      71         123 :     if (cli == RecurseSubmodules::No) return false;
      72         122 :     return effective_sync_s(manifest, repo);
      73             : }
      74             : 
      75             : } // namespace esys::repo::manifest

Generated by: LCOV version 1.14