startgitStatic page generator for git repositories | 
          
| git clone git://git.dimitrijedobrota.com/startgit.git | 
| Log | Files | Refs | README | LICENSE | HACKING | CONTRIBUTING | CODE_OF_CONDUCT | BUILDING | 
branch.cpp (1703B)
    0 #include <algorithm>
              1 #include <functional>
          
              3 #include "branch.hpp"
          
              5 #include <git2wrap/revwalk.hpp>
          
              7 #include "arguments.hpp"
              8 #include "repository.hpp"
          
             10 namespace startgit
             11 {
          
             13 branch::branch(git2wrap::branch brnch, repository& repo)
             14     : m_branch(std::move(brnch))
             15     , m_name(m_branch.get_name())
             16 {
             17   git2wrap::revwalk rwalk(repo.get());
          
             19   const git2wrap::object obj = repo.get().revparse(m_name.c_str());
             20   rwalk.push(obj.get_id());
          
             22   while (auto commit = rwalk.next()) {
             23     m_commits.emplace_back(std::move(commit));
             24   }
          
             26   if (m_commits.empty()) {
             27     return;
             28   }
          
             30   std::function<void(const git2wrap::tree&, const std::string& path)> traverse =
             31       [&](const auto& l_tree, const auto& path)
             32   {
             33     for (size_t i = 0; i < l_tree.get_entrycount(); i++) {
             34       const auto entry = l_tree.get_entry(i);
             35       const auto full_path =
             36           (!path.empty() ? path + "/" : "") + entry.get_name();
          
             38       using object_type = git2wrap::object::object_type;
             39       switch (entry.get_type()()) {
             40         case object_type::blob():
             41           break;
             42         case object_type::tree():
             43           traverse(entry.to_tree(), full_path);
             44           continue;
             45         case object_type::any():
             46         case object_type::invalid():
             47         case object_type::commit():
             48         case object_type::tag():
             49           continue;
             50       }
          
             52       m_files.emplace_back(entry, full_path);
          
             54       if (!path.empty()) {
             55         continue;
             56       }
          
             58       auto itr = args.special.find(entry.get_name());
             59       if (itr != args.special.end()) {
             60         m_special.emplace_back(entry, *itr);
             61       }
             62     }
             63   };
          
             65   traverse(get_last_commit().get_tree(), "");
             66   std::reverse(m_special.begin(), m_special.end());
             67 }
          
             69 }  // namespace startgit