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

          Line data    Source code
       1             : /*!
       2             :  * \file esys/repo/git/clonerev.cpp
       3             :  * \brief Tip-at-clone revision planning (ADR-0030)
       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/git/clonerev.h"
      20             : 
      21             : #include <cctype>
      22             : 
      23             : namespace esys::repo::git
      24             : {
      25             : 
      26         109 : bool looks_like_full_commit_id(const std::string &rev)
      27             : {
      28         109 :     if (rev.size() != 40) return false;
      29         657 :     for (unsigned char c : rev)
      30             :     {
      31         641 :         if (!std::isxdigit(c)) return false;
      32             :     }
      33             :     return true;
      34             : }
      35             : 
      36          93 : std::string rev_name_for_clone(std::string rev)
      37             : {
      38          93 :     const std::string heads = "refs/heads/";
      39          93 :     const std::string tags = "refs/tags/";
      40          93 :     if (rev.compare(0, heads.size(), heads) == 0) return rev.substr(heads.size());
      41          43 :     if (rev.compare(0, tags.size(), tags) == 0) return rev.substr(tags.size());
      42         134 :     return rev;
      43          93 : }
      44             : 
      45         107 : CloneRevPlan plan_clone_rev(bool tip_enabled, const std::string &sync_branch, const std::string &manifest_rev)
      46             : {
      47         107 :     CloneRevPlan plan;
      48         107 :     if (!tip_enabled) return plan;
      49             : 
      50         106 :     std::string clone_rev;
      51         106 :     if (!sync_branch.empty())
      52             :     {
      53          14 :         if (!looks_like_full_commit_id(sync_branch)) clone_rev = rev_name_for_clone(sync_branch);
      54             :     }
      55          92 :     else if (!manifest_rev.empty() && !looks_like_full_commit_id(manifest_rev))
      56             :     {
      57          77 :         clone_rev = rev_name_for_clone(manifest_rev);
      58             :     }
      59             : 
      60         106 :     if (clone_rev.empty()) return plan;
      61             : 
      62          90 :     plan.use_tip = true;
      63          90 :     plan.clone_rev = std::move(clone_rev);
      64          90 :     return plan;
      65         107 : }
      66             : 
      67             : } // namespace esys::repo::git

Generated by: LCOV version 1.14