Add file size in lines or bytes
Diffstat:
4 files changed, 22 insertions(+), 4 deletions(-)
@@ -4,7 +4,7 @@
include(cmake/prelude.cmake)
project(
startgit
VERSION 0.1.24
VERSION 0.1.25
DESCRIPTION "Static page generator for git repositories"
HOMEPAGE_URL "https://git.dimitrijedobrota.com/stargit.git"
LANGUAGES CXX
@@ -1,3 +1,6 @@
#include <algorithm>
#include <span>
#include "file.hpp"
#include <git2wrap/repository.hpp>
@@ -30,4 +33,14 @@
git2wrap::object_size_t file::get_size() const
return m_blob.get_rawsize();
}
int file::get_lines() const
{
if (m_lines != -1) {
return m_lines;
}
const auto span = std::span<const char>(get_content(), get_size());
return m_lines = static_cast<int>(std::count(span.begin(), span.end(), '\n'));
}
} // namespace startgit
@@ -20,11 +20,14 @@
public:
bool is_binary() const;
const char* get_content() const;
git2wrap::object_size_t get_size() const;
int get_lines() const;
private:
std::string m_filemode;
std::filesystem::path m_path;
git2wrap::blob m_blob;
mutable int m_lines = -1;
};
} // namespace startgit
@@ -231,17 +231,19 @@
void write_files_table(std::ostream& ost, const startgit::branch& branch)
ost << html::tr()
.add(html::td("Mode"))
.add(html::td("Name"))
.add(html::td("File"));
.add(html::td("Size"));
ost << html::thead();
ost << html::tbody();
for (const auto& file : branch.get_files()) {
const auto url = std::format("./file/{}.html", file.get_path().string());
const auto size = file.is_binary() ? std::format("{}B", file.get_size())
: std::format("{}L", file.get_lines());
ost << html::tr()
.add(html::td(file.get_filemode()))
.add(html::td().add(html::a(file.get_path()).set("href", url)))
.add(html::td("0"));
.add(html::td(size));
}
ost << html::tbody();
@@ -684,7 +686,7 @@
int parse_opt(int key, const char* arg, poafloc::Parser* parser)
auto* l_args = static_cast<arguments_t*>(parser->input());
switch (key) {
case 'o':
l_args->output_dir = arg;
l_args->output_dir = std::filesystem::canonical(arg).string();
break;
case 'b':
l_args->base_url = arg;