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)


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 switch (entry.get_type()) {
39 case GIT_OBJ_BLOB:
40 break;
41 case GIT_OBJ_TREE:
42 traverse(entry.to_tree(), full_path);
43 continue;
44 default:
45 continue;
46 }
48 m_files.emplace_back(entry, full_path);
50 if (!path.empty()) {
51 continue;
52 }
54 auto itr = args.special.find(entry.get_name());
55 if (itr != args.special.end()) {
56 m_special.emplace_back(entry, *itr);
57 }
58 }
59 };
61 traverse(get_last_commit().get_tree(), "");
62 std::reverse(m_special.begin(), m_special.end());
63 }
65 } // namespace startgit