LCOV - code coverage report
Current view: top level - src/esys/repo/git - filestatus_git.cpp (source / functions) Hit Total Coverage
Test: esysrepo_coverage.info Lines: 19 48 39.6 %
Date: 2026-08-01 10:43:40 Functions: 7 14 50.0 %

          Line data    Source code
       1             : /*!
       2             :  * \file esys/repo/git/filestatus_git.cpp
       3             :  * \brief
       4             :  *
       5             :  * \cond
       6             :  * __legal_b__
       7             :  *
       8             :  * Copyright (c) 2020 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/git/filestatus.h"
      20             : 
      21             : namespace esys::repo::git
      22             : {
      23             : 
      24           6 : FileStatus::FileStatus(const std::string &old_name)
      25           6 :     : m_old_name(old_name)
      26             : {
      27           6 : }
      28             : 
      29          12 : FileStatus::~FileStatus() = default;
      30             : 
      31           0 : void FileStatus::set_old_name(const std::string &old_name)
      32             : {
      33           0 :     m_old_name = old_name;
      34           0 : }
      35             : 
      36           8 : const std::string &FileStatus::get_old_name() const
      37             : {
      38           8 :     return m_old_name;
      39             : }
      40             : 
      41           6 : void FileStatus::add(std::shared_ptr<Status> status)
      42             : {
      43           6 :     m_status.push_back(status);
      44             : 
      45           6 :     if (status->get_type() == StatusType::INDEX)
      46           0 :         set_head_to_index(status);
      47           6 :     else if (status->get_type() == StatusType::WORKING_DIR)
      48          18 :         set_index_to_work_dir(status);
      49           6 : }
      50             : 
      51           0 : void FileStatus::set_head_to_index(std::shared_ptr<Status> head_to_index)
      52             : {
      53           0 :     m_head_to_index = head_to_index;
      54           0 : }
      55             : 
      56           0 : std::shared_ptr<Status> FileStatus::get_head_to_index() const
      57             : {
      58           0 :     return m_head_to_index;
      59             : }
      60             : 
      61           6 : void FileStatus::set_index_to_work_dir(std::shared_ptr<Status> index_to_work_dir)
      62             : {
      63           6 :     m_index_to_work_dir = index_to_work_dir;
      64           6 : }
      65             : 
      66           8 : std::shared_ptr<Status> FileStatus::get_index_to_work_dir() const
      67             : {
      68           8 :     return m_index_to_work_dir;
      69             : }
      70             : 
      71           4 : std::vector<std::shared_ptr<Status>> &FileStatus::get_status()
      72             : {
      73           4 :     return m_status;
      74             : }
      75             : 
      76           0 : const std::vector<std::shared_ptr<Status>> &FileStatus::get_status() const
      77             : {
      78           0 :     return m_status;
      79             : }
      80             : 
      81           0 : bool FileStatus::operator==(const FileStatus &other) const
      82             : {
      83           0 :     if (get_old_name() != other.get_old_name()) return false;
      84           0 :     if ((get_head_to_index() != nullptr) && (other.get_head_to_index() != nullptr))
      85             :     {
      86           0 :         if (*get_head_to_index() != *other.get_head_to_index()) return false;
      87             :     }
      88           0 :     else if ((get_head_to_index() != nullptr) || (other.get_head_to_index() != nullptr))
      89             :         return false;
      90             : 
      91           0 :     if ((get_index_to_work_dir() != nullptr) && (other.get_index_to_work_dir() != nullptr))
      92             :     {
      93           0 :         if (*get_index_to_work_dir() != *other.get_index_to_work_dir()) return false;
      94             :     }
      95           0 :     else if ((get_index_to_work_dir() != nullptr) || (other.get_index_to_work_dir() != nullptr))
      96             :         return false;
      97             : 
      98           0 :     bool equal = is_equal(get_status(), other.get_status());
      99           0 :     if (!equal) return false;
     100             :     return true;
     101             : }
     102             : 
     103           0 : bool FileStatus::is_equal(const std::vector<std::shared_ptr<Status>> &left,
     104             :                           const std::vector<std::shared_ptr<Status>> &right) const
     105             : {
     106           0 :     if (left.size() != right.size()) return false;
     107             : 
     108           0 :     for (auto idx = 0; idx < left.size(); ++idx)
     109             :     {
     110           0 :         if ((left[idx] == nullptr) && (right[idx] == nullptr)) return true;
     111           0 :         if ((left[idx] == nullptr) || (right[idx] == nullptr)) return false;
     112           0 :         if (*left[idx] != *right[idx]) return false;
     113             :     }
     114             :     return true;
     115             : }
     116             : 
     117           0 : bool FileStatus::operator!=(const FileStatus &other) const
     118             : {
     119           0 :     return !operator==(other);
     120             : }
     121             : 
     122             : } // namespace esys::repo::git

Generated by: LCOV version 1.14