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

file.cpp (896B)


0 #include <algorithm> 1 #include <span> 2 3 #include "file.hpp" 4 5 #include <git2wrap/repository.hpp> 6 7 #include "utils.hpp" 8 9 namespace startgit 10 { 11 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 } 19 20 bool file::is_binary() const 21 { 22 return m_blob.is_binary(); 23 } 24 25 const char* file::get_content() const 26 { 27 return static_cast<const char*>(m_blob.get_rawcontent()); 28 } 29 30 git2wrap::object_size_t file::get_size() const 31 { 32 return m_blob.get_rawsize(); 33 } 34 35 int file::get_lines() const 36 { 37 if (m_lines != -1) { 38 return m_lines; 39 } 40 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 } 44 45 } // namespace startgit