LCOV - code coverage report
Current view: top level - src/esys/repo/git - commit.cpp (source / functions) Hit Total Coverage
Test: esysrepo_coverage.info Lines: 60 101 59.4 %
Date: 2026-08-01 10:43:40 Functions: 19 30 63.3 %

          Line data    Source code
       1             : /*!
       2             :  * \file esys/repo/git/commit.cpp
       3             :  * \brief
       4             :  *
       5             :  * \cond
       6             :  * __legal_b__
       7             :  *
       8             :  * Copyright (c) 2022-2023 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/commit.h"
      20             : 
      21             : #include <date/date.h>
      22             : 
      23             : namespace esys::repo::git
      24             : {
      25             : 
      26          13 : Commit::Commit() = default;
      27             : 
      28          13 : Commit::~Commit() = default;
      29             : 
      30           8 : void Commit::clear()
      31             : {
      32           8 :     get_hash().set_hash("");
      33           8 :     set_message("");
      34           8 :     set_summary("");
      35           8 :     set_body("");
      36           8 :     set_author("");
      37           8 :     set_email("");
      38           8 :     m_all_notes.clear();
      39           8 :     m_map_ref_notes.clear();
      40           8 : }
      41             : 
      42           0 : void Commit::set_hash(const std::string &hash)
      43             : {
      44           0 :     get_hash().set_hash(hash);
      45           0 : }
      46             : 
      47           0 : const CommitHash &Commit::get_hash() const
      48             : {
      49           0 :     return m_hash;
      50             : }
      51             : 
      52          31 : CommitHash &Commit::get_hash()
      53             : {
      54          31 :     return m_hash;
      55             : }
      56             : 
      57          23 : void Commit::set_message(const std::string &message)
      58             : {
      59          23 :     m_message = message;
      60          23 : }
      61             : 
      62           0 : const std::string &Commit::get_message() const
      63             : {
      64           0 :     return m_message;
      65             : }
      66             : 
      67          15 : void Commit::set_summary(const std::string &summary)
      68             : {
      69          15 :     m_summary = summary;
      70          15 : }
      71             : 
      72           2 : const std::string &Commit::get_summary() const
      73             : {
      74           2 :     return m_summary;
      75             : }
      76             : 
      77          13 : void Commit::set_body(const std::string &body)
      78             : {
      79          13 :     m_body = body;
      80          13 : }
      81             : 
      82           2 : const std::string &Commit::get_body() const
      83             : {
      84           2 :     return m_body;
      85             : }
      86             : 
      87          16 : void Commit::set_author(const std::string &author)
      88             : {
      89          16 :     m_author_sign.set_name(author);
      90          16 : }
      91             : 
      92           1 : const std::string &Commit::get_author() const
      93             : {
      94           1 :     return m_author_sign.get_name();
      95             : }
      96             : 
      97          16 : void Commit::set_email(const std::string &email)
      98             : {
      99          16 :     m_author_sign.set_email(email);
     100          16 : }
     101             : 
     102           6 : const std::string &Commit::get_email() const
     103             : {
     104           6 :     return m_author_sign.get_email();
     105             : }
     106             : 
     107           8 : void Commit::set_date_time(const std::chrono::system_clock::time_point &date_time)
     108             : {
     109           8 :     m_author_sign.set_date_time(date_time);
     110           8 : }
     111             : 
     112           4 : const std::chrono::system_clock::time_point &Commit::get_date_time() const
     113             : {
     114           4 :     return m_author_sign.get_date_time();
     115             : }
     116             : 
     117           0 : std::vector<std::shared_ptr<Note>> &Commit::get_all_notes()
     118             : {
     119           0 :     return m_all_notes;
     120             : }
     121             : 
     122           0 : const std::vector<std::shared_ptr<Note>> &Commit::get_all_notes() const
     123             : {
     124           0 :     return m_all_notes;
     125             : }
     126             : 
     127           7 : int Commit::get_notes(const std::string &reference, std::vector<std::shared_ptr<Note>> &notes) const
     128             : {
     129           7 :     notes.clear();
     130             : 
     131           7 :     auto it = m_map_ref_notes.find(reference);
     132           7 :     if (it == m_map_ref_notes.end()) return 0;
     133             : 
     134           5 :     notes = it->second;
     135             :     return 0;
     136             : }
     137             : 
     138           5 : void Commit::add_note(std::shared_ptr<Note> note)
     139             : {
     140           5 :     m_all_notes.push_back(note);
     141           5 :     if (note->get_reference().empty()) return;
     142             : 
     143           5 :     auto it = m_map_ref_notes.find(note->get_reference());
     144           5 :     if (it != m_map_ref_notes.end())
     145             :     {
     146           0 :         it->second.push_back(note);
     147           0 :         return;
     148             :     }
     149             : 
     150           5 :     NoteVec vec;
     151           5 :     vec.push_back(note);
     152           5 :     m_map_ref_notes[note->get_reference()] = vec;
     153           5 : }
     154             : 
     155           7 : Signature &Commit::get_author_sign()
     156             : {
     157           7 :     return m_author_sign;
     158             : }
     159             : 
     160           0 : const Signature &Commit::get_author_sign() const
     161             : {
     162           0 :     return m_author_sign;
     163             : }
     164             : 
     165           7 : Signature &Commit::get_committer_sign()
     166             : {
     167           7 :     return m_committer_sign;
     168             : }
     169             : 
     170           0 : const Signature &Commit::get_committer_sign() const
     171             : {
     172           0 :     return m_committer_sign;
     173             : }
     174             : 
     175           0 : bool Commit::operator==(const Commit &other) const
     176             : {
     177           0 :     if (get_hash() != other.get_hash()) return false;
     178           0 :     if (get_message() != other.get_message()) return false;
     179           0 :     if (get_summary() != other.get_summary()) return false;
     180           0 :     if (get_body() != other.get_body()) return false;
     181           0 :     if (get_author() != other.get_author()) return false;
     182           0 :     if (get_email() != other.get_email()) return false;
     183           0 :     if (get_date_time() != other.get_date_time()) return false;
     184           0 :     if (get_all_notes().size() != other.get_all_notes().size()) return false;
     185             : 
     186           0 :     for (auto idx = 0; idx < get_all_notes().size(); ++idx)
     187             :     {
     188           0 :         if ((get_all_notes()[idx] == nullptr) && (other.get_all_notes()[idx] == nullptr))
     189           0 :             continue;
     190           0 :         else if ((get_all_notes()[idx] == nullptr) || (other.get_all_notes()[idx] == nullptr))
     191           0 :             return false;
     192           0 :         if (*get_all_notes()[idx] != *other.get_all_notes()[idx]) return false;
     193             :     }
     194             :     return true;
     195             : }
     196             : 
     197           0 : bool Commit::operator!=(const Commit &other) const
     198             : {
     199           0 :     return !operator==(other);
     200             : }
     201             : 
     202             : } // namespace esys::repo::git
     203             : 
     204             : namespace std
     205             : {
     206             : 
     207           0 : ESYSREPO_API ostream &operator<<(ostream &os, const esys::repo::git::Commit &commit)
     208             : {
     209           0 :     os << "hash   : " << commit.get_hash() << std::endl;
     210           0 :     os << "author : " << commit.get_author() << std::endl;
     211           0 :     os << "date   : " << date::format("%D %T %Z", commit.get_date_time()) << std::endl;
     212           0 :     os << "message: " << commit.get_message() << std::endl;
     213           0 :     os << "body   : " << commit.get_body();
     214           0 :     return os;
     215             : }
     216             : 
     217             : } // namespace std

Generated by: LCOV version 1.14