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