LCOV - code coverage report
Current view: top level - src/esys/repo - revisionpins.cpp (source / functions) Hit Total Coverage
Test: esysrepo_coverage.info Lines: 24 38 63.2 %
Date: 2026-08-12 14:26:50 Functions: 7 11 63.6 %

          Line data    Source code
       1             : /*!
       2             :  * \file esys/repo/revisionpins.cpp
       3             :  * \brief
       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/revisionpins.h"
      20             : 
      21             : namespace esys::repo
      22             : {
      23             : 
      24          60 : RevisionPins::RevisionPins() = default;
      25             : 
      26          60 : RevisionPins::~RevisionPins() = default;
      27             : 
      28          58 : void RevisionPins::clear()
      29             : {
      30          58 :     m_pins.clear();
      31          58 :     m_by_path.clear();
      32          58 : }
      33             : 
      34           3 : void RevisionPins::add(std::shared_ptr<RevisionPin> pin)
      35             : {
      36           3 :     if (pin == nullptr) return;
      37             : 
      38           3 :     auto existing = find_by_path(pin->get_path());
      39           3 :     if (existing != nullptr) remove_by_path(pin->get_path());
      40             : 
      41           3 :     m_pins.push_back(pin);
      42           6 :     if (!pin->get_path().empty()) m_by_path[pin->get_path()] = pin;
      43           3 : }
      44             : 
      45           0 : void RevisionPins::remove_by_path(const std::string &path)
      46             : {
      47           0 :     m_by_path.erase(path);
      48           0 :     for (auto it = m_pins.begin(); it != m_pins.end();)
      49             :     {
      50           0 :         if ((*it) != nullptr && (*it)->get_path() == path)
      51           0 :             it = m_pins.erase(it);
      52             :         else
      53           0 :             ++it;
      54             :     }
      55           0 : }
      56             : 
      57         167 : std::shared_ptr<RevisionPin> RevisionPins::find_by_path(const std::string &path) const
      58             : {
      59         167 :     auto it = m_by_path.find(path);
      60         167 :     if (it == m_by_path.end()) return nullptr;
      61           5 :     return it->second;
      62             : }
      63             : 
      64           0 : std::shared_ptr<RevisionPin> RevisionPins::find_by_selector(PinSelector selector, const std::string &value) const
      65             : {
      66           0 :     for (auto &pin : m_pins)
      67             :     {
      68           0 :         if (pin == nullptr) continue;
      69           0 :         if (pin->get_selector() == selector && pin->get_value() == value) return pin;
      70             :     }
      71           0 :     return nullptr;
      72             : }
      73             : 
      74         163 : std::string RevisionPins::get_rev_for_path(const std::string &path) const
      75             : {
      76         163 :     auto pin = find_by_path(path);
      77         163 :     if (pin == nullptr) return "";
      78           4 :     return pin->get_rev();
      79         163 : }
      80             : 
      81           3 : std::vector<std::shared_ptr<RevisionPin>> &RevisionPins::get_pins()
      82             : {
      83           3 :     return m_pins;
      84             : }
      85             : 
      86           0 : const std::vector<std::shared_ptr<RevisionPin>> &RevisionPins::get_pins() const
      87             : {
      88           0 :     return m_pins;
      89             : }
      90             : 
      91             : } // namespace esys::repo

Generated by: LCOV version 1.14