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 | |
commit | 563a09de5db327f6e08ae5cddb3d1df4a19332bb |
parent | aaea18699ba8c13e617c79051e1d3a9b57d5cb0a |
author | Dimitrije Dobrota <mail@dimitrijedobrota.com> |
date | Wed, 15 Jan 2025 23:37:59 +0100 |
Consistency improvements * Proper diff old and new order * File name and size * Don't print binary file content * Better add/delete indication handling * Fix tag author name display * Fix time all around: author > commit
Diffstat:M | CMakeLists.txt | | | +- |
M | source/commit.cpp | | | ++++++------- |
M | source/commit.hpp | | | +- |
M | source/diff.cpp | | | +- |
M | source/file.hpp | | | +++-- |
M | source/main.cpp | | | +++++++++++++++++++++++++++++++++++++++++--------------------- |
M | source/tag.cpp | | | +- |
M | source/utils.cpp | | | ++-- |
M | source/utils.hpp | | | ++-- |
9 files changed, 58 insertions(+), 38 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
@@ -4,7 +4,7 @@ include(cmake/prelude.cmake)
project(
startgit
VERSION 0.1.19
VERSION 0.1.20
DESCRIPTION "Static page generator for git repositories"
HOMEPAGE_URL "https://git.dimitrijedobrota.com/stargit.git"
LANGUAGES CXX
diff --git a/source/commit.cpp b/source/commit.cpp
@@ -12,7 +12,6 @@ commit::commit(git2wrap::commit cmmt)
: m_commit(std::move(cmmt))
, m_diff(m_commit)
{
}
std::string commit::get_id() const
@@ -47,22 +46,22 @@ std::string commit::get_summary() const
std::string commit::get_time() const
{
return long_to_string(m_commit.get_time());
return time_short(m_commit.get_author().get_time().time);
}
std::string commit::get_author_name() const
std::string commit::get_time_long() const
{
return m_commit.get_author().get_name();
return time_long(m_commit.get_author().get_time());
}
std::string commit::get_author_email() const
std::string commit::get_author_name() const
{
return m_commit.get_author().get_name();
}
std::string commit::get_author_time() const
std::string commit::get_author_email() const
{
return long_to_string(m_commit.get_author().get_time());
return m_commit.get_author().get_name();
}
git2wrap::tree commit::get_tree() const
diff --git a/source/commit.hpp b/source/commit.hpp
@@ -21,9 +21,9 @@ public:
size_t get_parentcount() const;
std::string get_summary() const;
std::string get_time() const;
std::string get_time_long() const;
std::string get_author_name() const;
std::string get_author_email() const;
std::string get_author_time() const;
git2wrap::tree get_tree() const;
std::string get_message() const;
diff --git a/source/diff.cpp b/source/diff.cpp
@@ -16,7 +16,7 @@ diff::diff(const git2wrap::commit& cmmt)
opts.flags = GIT_DIFF_DISABLE_PATHSPEC_MATCH | GIT_DIFF_IGNORE_SUBMODULES
| GIT_DIFF_INCLUDE_TYPECHANGE;
m_diff = git2wrap::diff::tree_to_tree(cmmt.get_tree(), ptree, &opts);
m_diff = git2wrap::diff::tree_to_tree(ptree, cmmt.get_tree(), &opts);
m_stats = m_diff.get_stats();
m_diff.foreach(file_cb, nullptr, hunk_cb, line_cb, this);
diff --git a/source/file.hpp b/source/file.hpp
@@ -1,5 +1,6 @@
#pragma once
#include <filesystem>
#include <string>
#include <git2wrap/blob.hpp>
@@ -14,7 +15,7 @@ public:
file(const git2wrap::tree_entry& entry, std::string path);
std::string get_filemode() const { return m_filemode; }
std::string get_path() const { return m_path; }
std::filesystem::path get_path() const { return m_path; }
bool is_binary() const;
const char* get_content() const;
@@ -22,7 +23,7 @@ public:
private:
std::string m_filemode;
std::string m_path;
std::filesystem::path m_path;
git2wrap::blob m_blob;
};
diff --git a/source/main.cpp b/source/main.cpp
@@ -57,6 +57,8 @@ void write_header(std::ostream& ost,
.set("class", "theme_switch");
ost << html::div().set("id", "content");
html::div().tgl_state();
ost << html::main();
ost << html::label(" ")
.set("for", "theme_switch")
@@ -179,7 +181,7 @@ void write_repo_table_entry(std::ostream& ost, const startgit::repository& repo)
.add(html::td().add(html::a(repo.get_name()).set("href", url)))
.add(html::td(repo.get_description()))
.add(html::td(repo.get_owner()))
.add(html::td(branch.get_commits()[0].get_author_time()));
.add(html::td(branch.get_commits()[0].get_time_long()));
break;
}
}
@@ -218,7 +220,7 @@ void write_files_table(std::ostream& ost, const startgit::branch& branch)
ost << html::tbody();
for (const auto& file : branch.get_files()) {
const auto url = std::format("./file/{}.html", file.get_path());
const auto url = std::format("./file/{}.html", file.get_path().string());
ost << html::tr()
.add(html::td(file.get_filemode()))
@@ -284,7 +286,7 @@ void write_tag_table(std::ostream& ost, const startgit::repository& repo)
.add(html::td(" "))
.add(html::td(tag.get_name()))
.add(html::td(tag.get_time()))
.add(html::td(tag.get_name()));
.add(html::td(tag.get_author()));
}
ost << html::tbody();
@@ -312,7 +314,7 @@ void write_file_changes(std::ostream& ost, const startgit::diff& diff)
}
ost << html::tbody() << html::table();
ost << html::span(
ost << html::p(
std::format("{} files changed, {} insertions(+), {} deletions(-)",
diff.get_files_changed(),
diff.get_insertions(),
@@ -338,28 +340,26 @@ void write_file_diffs(std::ostream& ost, const startgit::diff& diff)
ost << html::h4();
ost << std::format("@@ -{},{} +{},{} @@ ",
hunk->new_start,
hunk->new_lines,
hunk->old_start,
hunk->old_lines);
hunk->old_lines,
hunk->new_start,
hunk->new_lines);
startgit::xmlencode(ost, header.substr(header.rfind('@') + 2));
ost << html::h4();
ost << html::span().set("style", "white-space: pre");
for (const auto& line : hunk.get_lines()) {
if (line.get_origin() == '-') {
ost << html::span().set(
"style", "color: var(--theme_green); white-space: pre;");
} else if (line.get_origin() == '+') {
ost << html::span().set("style",
"color: var(--theme_red); white-space: pre;");
} else {
ost << html::span().set("style", "white-space: pre;");
}
ost << html::div().set(
"style",
line.get_origin() == '+' ? "color: var(--theme_green)"
: line.get_origin() == '-' ? "color: var(--theme_red)"
: "");
startgit::xmlencode(ost, line.get_content());
ost << html::span();
ost << html::div();
}
ost << html::span();
}
}
}
@@ -393,7 +393,7 @@ void write_commit_diff(std::ostream& ost, const startgit::commit& commit)
ost << html::tr()
.add(html::td().add(html::b("date")))
.add(html::td(commit.get_author_time()));
.add(html::td(commit.get_time_long()));
ost << html::tbody() << html::table();
ost << html::br() << html::p().set("style", "white-space: pre;");
@@ -405,10 +405,24 @@ void write_commit_diff(std::ostream& ost, const startgit::commit& commit)
write_file_diffs(ost, commit.get_diff());
}
void write_file_title(std::ostream& ost, const startgit::file& file)
{
using namespace hemplate; // NOLINT
ost << html::h3(std::format(
"{} ({}B)", file.get_path().filename().string(), file.get_size()));
ost << html::hr();
}
void write_file_content(std::ostream& ost, const startgit::file& file)
{
using namespace hemplate; // NOLINT
if (file.is_binary()) {
ost << html::h4("Binary file");
return;
}
const std::string str(file.get_content(), file.get_size());
std::stringstream sstr(str);
@@ -416,7 +430,8 @@ void write_file_content(std::ostream& ost, const startgit::file& file)
ost << html::span().set("style", "white-space: pre;");
for (int count = 1; std::getline(sstr, line, '\n'); count++) {
ost << std::format(R"(<a id="{}" href="#{}">{:5}</a>)", count, count, count);
ost << std::format(
R"(<a id="{}" href="#{}">{:5}</a>)", count, count, count);
ost << " ";
startgit::xmlencode(ost, line);
ost << '\n';
@@ -429,7 +444,10 @@ void write_footer(std::ostream& ost)
using namespace hemplate; // NOLINT
ost << html::main();
html::div().tgl_state();
ost << html::div();
ost << html::script(" ").set(
"src", "https://www.dimitrijedobrota.com/scripts/main.js");
ost << html::script(
@@ -520,12 +538,13 @@ void write_files(const std::filesystem::path& base,
const startgit::branch& branch)
{
for (const auto& file : branch.get_files()) {
const std::filesystem::path path = base / (file.get_path() + ".html");
const std::filesystem::path path =
base / (file.get_path().string() + ".html");
std::filesystem::create_directories(path.parent_path());
std::ofstream ofs(path);
std::string back = "../";
for (const char chr : file.get_path()) {
for (const char chr : file.get_path().string()) {
if (chr == '/') {
back += "../";
}
@@ -533,6 +552,7 @@ void write_files(const std::filesystem::path& base,
write_header(ofs, repo, branch, file.get_path());
write_title(ofs, repo, branch.get_name(), back);
write_file_title(ofs, file);
write_file_content(ofs, file);
write_footer(ofs);
}
diff --git a/source/tag.cpp b/source/tag.cpp
@@ -8,7 +8,7 @@ namespace startgit
tag::tag(const git2wrap::tag& tagg)
: m_name(tagg.get_name())
, m_author(tagg.get_tagger().get_name())
, m_time(long_to_string(tagg.get_tagger().get_time().time))
, m_time(time_short(tagg.get_tagger().get_time().time))
{
}
diff --git a/source/utils.cpp b/source/utils.cpp
@@ -9,14 +9,14 @@
namespace startgit
{
std::string long_to_string(int64_t date)
std::string time_short(int64_t date)
{
std::stringstream strs;
strs << std::put_time(std::gmtime(&date), "%Y-%m-%d %H:%M"); // NOLINT
return strs.str();
}
std::string long_to_string(const git2wrap::time& time)
std::string time_long(const git2wrap::time& time)
{
std::stringstream strs;
strs << std::put_time(std::gmtime(&time.time), // NOLINT
diff --git a/source/utils.hpp b/source/utils.hpp
@@ -8,8 +8,8 @@
namespace startgit
{
std::string long_to_string(int64_t date);
std::string long_to_string(const git2wrap::time& time);
std::string time_short(int64_t date);
std::string time_long(const git2wrap::time& time);
void xmlencode(std::ostream& ost, const std::string& str);
std::string filemode(git2wrap::filemode_t filemode);