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 |

commitcd4746a49db36e0055b9a54f570ed110ef41c3af
parent563a09de5db327f6e08ae5cddb3d1df4a19332bb
authorDimitrije Dobrota <mail@dimitrijedobrota.com>
dateThu, 16 Jan 2025 18:13:17 +0100

Proper exception handling

Diffstat:
MCMakeLists.txt|+-
Msource/branch.cpp|++++
Msource/main.cpp|++++++++++++++++++++++++++++++++++++++++------------------------------------------

3 files changed, 44 insertions(+), 43 deletions(-)


diff --git a/CMakeLists.txt b/CMakeLists.txt

@@ -4,7 +4,7 @@ include(cmake/prelude.cmake)

project(
startgit
VERSION 0.1.20
VERSION 0.1.21
DESCRIPTION "Static page generator for git repositories"
HOMEPAGE_URL "https://git.dimitrijedobrota.com/stargit.git"
LANGUAGES CXX

diff --git a/source/branch.cpp b/source/branch.cpp

@@ -22,6 +22,10 @@ branch::branch(git2wrap::branch brnch, repository& repo)

m_commits.emplace_back(std::move(commit));
}
if (m_commits.empty()) {
return;
}
std::function<void(const git2wrap::tree&, const std::string& path)> traverse =
[&](const auto& l_tree, const auto& path)
{

diff --git a/source/main.cpp b/source/main.cpp

@@ -182,8 +182,11 @@ void write_repo_table_entry(std::ostream& ost, const startgit::repository& repo)

.add(html::td(repo.get_description()))
.add(html::td(repo.get_owner()))
.add(html::td(branch.get_commits()[0].get_time_long()));
break;
return;
}
std::cerr << std::format("Warning: {} doesn't have master branch\n",
repo.get_path().string());
}
void write_repo_table(std::ostream& ost, const std::stringstream& index)

@@ -606,58 +609,52 @@ int main(int argc, char* argv[])

return 1;
}
const git2wrap::libgit2 libgit;
std::stringstream index;
try {
const git2wrap::libgit2 libgit;
std::stringstream index;
for (const auto& repo_path : args.repos) {
try {
const startgit::repository repo(repo_path);
const std::filesystem::path base = args.output_dir / repo.get_name();
std::filesystem::create_directory(base);
for (const auto& repo_path : args.repos) {
try {
const startgit::repository repo(repo_path);
const std::filesystem::path base = args.output_dir / repo.get_name();
std::filesystem::create_directory(base);
for (const auto& branch : repo.get_branches()) {
const std::filesystem::path base_branch = base / branch.get_name();
std::filesystem::create_directory(base_branch);
for (const auto& branch : repo.get_branches()) {
const std::filesystem::path base_branch = base / branch.get_name();
std::filesystem::create_directory(base_branch);
write_log(base_branch, repo, branch);
write_file(base_branch, repo, branch);
write_refs(base_branch, repo, branch);
write_log(base_branch, repo, branch);
write_file(base_branch, repo, branch);
write_refs(base_branch, repo, branch);
const std::filesystem::path commit = base_branch / "commit";
std::filesystem::create_directory(commit);
const std::filesystem::path commit = base_branch / "commit";
std::filesystem::create_directory(commit);
write_commits(commit, repo, branch);
write_commits(commit, repo, branch);
const std::filesystem::path file = base_branch / "file";
std::filesystem::create_directory(file);
const std::filesystem::path file = base_branch / "file";
std::filesystem::create_directory(file);
write_files(file, repo, branch);
}
write_files(file, repo, branch);
}
write_repo_table_entry(index, repo);
} catch (const git2wrap::error& err) {
std::cerr << std::format("Warning: {} is not a repository\n",
repo_path.string());
write_repo_table_entry(index, repo);
} catch (const git2wrap::error<git2wrap::error_code_t::ENOTFOUND>& err) {
std::cerr << std::format("Warning: {} is not a repository\n",
repo_path.string());
}
}
}
std::ofstream ofs(args.output_dir / "index.html");
write_header(ofs,
"Git repository",
"Collection of all public projects",
"Dimitrije Dobrota");
write_repo_table(ofs, index);
write_footer(ofs);
/*
catch (const git2wrap::error& err) {
std::cerr << std::format("({}:{}) Error {}/{}: {}\n",
err.get_file(),
err.get_line(),
err.get_error(),
err.get_klass(),
err.get_message());
std::ofstream ofs(args.output_dir / "index.html");
write_header(ofs,
"Git repository",
"Collection of all public projects",
"Dimitrije Dobrota");
write_repo_table(ofs, index);
write_footer(ofs);
} catch (const git2wrap::runtime_error& err) {
std::cerr << std::format("Error: {}\n", err.what());
}
*/
return 0;
}