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 |
repository.cpp (1254B)
0 #include <fstream>
2 #include "repository.hpp"
4 namespace startgit
5 {
7 repository::repository(const std::filesystem::path& path)
8 : m_path(path)
9 , m_repo(git2wrap::repository::open(
10 path.c_str(), GIT_REPOSITORY_OPEN_NO_SEARCH, nullptr))
11 , m_name(path.stem().string())
12 , m_url(read_file(path, "url"))
13 , m_owner(read_file(path, "owner"))
14 , m_description(read_file(path, "description"))
15 {
16 // Get branches
17 for (auto it = m_repo.branch_begin(GIT_BRANCH_LOCAL);
18 it != m_repo.branch_end();
19 ++it)
20 {
21 m_branches.emplace_back(it->dup(), *this);
22 }
24 // Get tags
25 auto callback = +[](const char*, git_oid* objid, void* payload_p)
26 {
27 auto& repo = *reinterpret_cast<repository*>(payload_p); // NOLINT
28 repo.m_tags.emplace_back(repo.m_repo.tag_lookup(git2wrap::oid(objid)));
29 return 0;
30 };
32 m_repo.tag_foreach(callback, this);
33 }
35 std::string repository::read_file(const std::filesystem::path& base,
36 const char* file)
37 {
38 std::ifstream ifs(base / file);
40 if (!ifs.is_open()) {
41 ifs = base / ".git" / file;
42 }
44 if (ifs.is_open()) {
45 std::string res;
46 std::getline(ifs, res, '\n');
47 return res;
48 }
50 return "Unknown";
51 }
53 } // namespace startgit