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 |
file.cpp (896B)
0 #include <algorithm>
1 #include <span>
3 #include "file.hpp"
5 #include <git2wrap/repository.hpp>
7 #include "utils.hpp"
9 namespace startgit
10 {
12 file::file(const git2wrap::tree_entry& entry, std::filesystem::path path)
13 : m_filemode(filemode(entry.get_filemode()))
14 , m_path(std::move(path))
15 , m_blob(
16 git2wrap::repository(entry.get_owner()).blob_lookup(entry.get_id()))
17 {
18 }
20 bool file::is_binary() const
21 {
22 return m_blob.is_binary();
23 }
25 const char* file::get_content() const
26 {
27 return static_cast<const char*>(m_blob.get_rawcontent());
28 }
30 git2wrap::object_size_t file::get_size() const
31 {
32 return m_blob.get_rawsize();
33 }
35 int file::get_lines() const
36 {
37 if (m_lines != -1) {
38 return m_lines;
39 }
41 const auto span = std::span<const char>(get_content(), get_size());
42 return m_lines = static_cast<int>(std::count(span.begin(), span.end(), '\n'));
43 }
45 } // namespace startgit