LCOV - code coverage report
Current view: top level - src/esys/repo/gitstats - basic.cpp (source / functions) Hit Total Coverage
Test: esysrepo_coverage.info Lines: 29 40 72.5 %
Date: 2026-08-01 10:43:40 Functions: 6 11 54.5 %

          Line data    Source code
       1             : /*!
       2             :  * \file esys/repo/gitstats/basic.cpp
       3             :  * \brief
       4             :  *
       5             :  * \cond
       6             :  * __legal_b__
       7             :  *
       8             :  * Copyright (c) 2022 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/gitstats/basic.h"
      20             : #include "esys/repo/gitbase.h"
      21             : #include "esys/repo/git/diff.h"
      22             : 
      23             : #include <boost/date_time/gregorian/gregorian.hpp>
      24             : #include <boost/date_time/posix_time/posix_time.hpp>
      25             : 
      26             : namespace esys::repo::gitstats
      27             : {
      28             : 
      29           1 : Basic::Basic() = default;
      30             : 
      31           0 : Basic::Basic(std::shared_ptr<Data> data)
      32           0 :     : m_data(data)
      33             : {
      34           0 : }
      35             : 
      36           3 : Basic::~Basic() = default;
      37             : 
      38           0 : void Basic::set_data(std::shared_ptr<Data> data)
      39             : {
      40           0 :     m_data = data;
      41           0 : }
      42             : 
      43           2 : std::shared_ptr<Data> Basic::get_data()
      44             : {
      45           2 :     return m_data;
      46             : }
      47             : 
      48           4 : std::shared_ptr<Data> Basic::get_data_or_new()
      49             : {
      50           4 :     if (m_data == nullptr) m_data = std::make_shared<Data>();
      51             : 
      52           4 :     return m_data;
      53             : }
      54             : 
      55           0 : void Basic::set_author_mngr(std::shared_ptr<AuthorMngr> author_mngr)
      56             : {
      57           0 :     m_author_mngr = author_mngr;
      58           0 : }
      59             : 
      60           0 : std::shared_ptr<AuthorMngr> Basic::get_author_mngr()
      61             : {
      62           0 :     return m_author_mngr;
      63             : }
      64             : 
      65           4 : std::shared_ptr<AuthorMngr> Basic::get_author_mngr_or_new()
      66             : {
      67           4 :     if (m_author_mngr == nullptr) m_author_mngr = std::make_shared<AuthorMngr>();
      68             : 
      69           4 :     return m_author_mngr;
      70             : }
      71             : 
      72           4 : int Basic::new_commit(GitBase *git_base, std::shared_ptr<git::Commit> commit)
      73             : {
      74           4 :     auto date_time = commit->get_date_time();
      75             : 
      76           4 :     boost::gregorian::date date =
      77           4 :         boost::posix_time::from_time_t(std::chrono::system_clock::to_time_t(date_time)).date();
      78             : 
      79           4 :     auto data_year = get_data_or_new()->get_year_or_new(date.year());
      80           4 :     std::shared_ptr<DataPeriod> data_period;
      81           4 :     std::shared_ptr<DataPeriodAuthor> data_period_author;
      82             : 
      83          12 :     auto author = get_author_mngr_or_new()->get_author_or_new(commit);
      84             : 
      85           8 :     data_period = data_year->get_week_or_new(date.week_number() - 1);
      86             : 
      87          12 :     data_period_author = data_period->get_author_or_new(author);
      88           4 :     data_period_author->inc_commit_count();
      89             : 
      90           4 :     std::shared_ptr<git::Diff> diff = std::make_shared<git::Diff>();
      91           8 :     Result result = git_base->diff(commit->get_hash(), diff);
      92           4 :     if (result.error()) return result.get_result_code_int();
      93             : 
      94           4 :     data_period_author->inc_line_added(diff.get()->get_insertions());
      95           4 :     data_period_author->inc_line_removed(diff.get()->get_deletions());
      96           4 :     data_period_author->inc_renames(diff.get()->get_renames());
      97           4 :     data_period_author->inc_files_changed(diff.get()->get_files_changed());
      98             :     return 0;
      99          24 : }
     100             : 
     101             : } // namespace esys::repo::gitstats

Generated by: LCOV version 1.14