startgit

Static 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 (1508B)


1 #include <algorithm> 2 #include <functional> 3 4 #include "branch.hpp" 5 6 #include <git2wrap/revwalk.hpp> 7 8 #include "arguments.hpp" 9 #include "repository.hpp" 10 11 namespace startgit 12 { 13 14 branch::branch(git2wrap::branch brnch, repository& repo) 15 : m_branch(std::move(brnch)) 16 , m_name(m_branch.get_name()) 17 { 18 git2wrap::revwalk rwalk(repo.get()); 19 20 const git2wrap::object obj = repo.get().revparse(m_name.c_str()); 21 rwalk.push(obj.get_id()); 22 23 while (auto commit = rwalk.next()) { 24 m_commits.emplace_back(std::move(commit)); 25 } 26 27 if (m_commits.empty()) { 28 return; 29 } 30 31 std::function<void(const git2wrap::tree&, const std::string& path)> traverse = 32 [&](const auto& l_tree, const auto& path) 33 { 34 for (size_t i = 0; i < l_tree.get_entrycount(); i++) { 35 const auto entry = l_tree.get_entry(i); 36 const auto full_path = 37 (!path.empty() ? path + "/" : "") + entry.get_name(); 38 39 switch (entry.get_type()) { 40 case GIT_OBJ_BLOB: 41 break; 42 case GIT_OBJ_TREE: 43 traverse(entry.to_tree(), full_path); 44 continue; 45 default: 46 continue; 47 } 48 49 m_files.emplace_back(entry, full_path); 50 51 if (!path.empty()) { 52 continue; 53 } 54 55 auto itr = args.special.find(entry.get_name()); 56 if (itr != args.special.end()) { 57 m_special.emplace_back(entry, *itr); 58 } 59 } 60 }; 61 62 traverse(get_last_commit().get_tree(), ""); 63 std::reverse(m_special.begin(), m_special.end()); 64 } 65 66 } // namespace startgit