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 |

commit80c86b7fc9f6316846cedad1f05f9d4afdaa7461
parent737b1d9858fa2c82ecd1cff6d9dfe14536a7e727
authorDimitrije Dobrota <mail@dimitrijedobrota.com>
dateWed, 8 Jan 2025 22:37:22 +0100

General readability improvements

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

4 files changed, 28 insertions(+), 24 deletions(-)


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

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

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

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

@@ -16,13 +16,6 @@

#include "repository.hpp"
struct arguments_t
{
std::filesystem::path output_dir = ".";
std::vector<std::filesystem::path> repos;
std::string url;
};
std::string long_to_string(int64_t date)
{
std::stringstream strs;

@@ -142,6 +135,13 @@ void write_footer(std::ostream& ost)

ost << html::html();
}
struct arguments_t
{
std::filesystem::path output_dir = ".";
std::vector<std::filesystem::path> repos;
std::string url;
};
int parse_opt(int key, const char* arg, poafloc::Parser* parser)
{
auto* args = static_cast<arguments_t*>(parser->input());

@@ -164,9 +164,11 @@ int parse_opt(int key, const char* arg, poafloc::Parser* parser)

// NOLINTBEGIN
// clang-format off
static const poafloc::option_t options[] = {
// {0, 0, 0, 0, "Output mode", 1},
{0, 0, 0, 0, "Output mode", 1},
{"output", 'o', "DIR", 0, "Output directory"},
{"url", 'u', "baseurl", 0, "Base URL to make links in the Atom feeds absolute"},
{0, 0, 0, 0, "General information", 2},
{"url", 'u', "BASEURL", 0, "Base URL to make links in the Atom feeds absolute"},
{0, 0, 0, 0, "Informational Options", -1},
{0},
};
// clang-format on

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

@@ -8,11 +8,11 @@ namespace startgit

repository::repository(const std::filesystem::path& path)
: m_repo(git2wrap::repository::open(
path.c_str(), GIT_REPOSITORY_OPEN_NO_SEARCH, nullptr))
, m_name(path.stem().string())
, m_url(read_file(path, "url"))
, m_owner(read_file(path, "owner"))
, m_description(read_file(path, "description"))
{
m_name = path.stem().string();
read_file(m_owner, path, "owner");
read_file(m_description, path, "description");
for (auto it = m_repo.branch_begin(GIT_BRANCH_LOCAL);
it != m_repo.branch_end();
++it)

@@ -21,9 +21,8 @@ repository::repository(const std::filesystem::path& path)

}
}
void repository::read_file(std::string& out,
const std::filesystem::path& base,
const char* file)
std::string repository::read_file(const std::filesystem::path& base,
const char* file)
{
std::ifstream ifs(base / file);

@@ -32,10 +31,12 @@ void repository::read_file(std::string& out,

}
if (ifs.is_open()) {
std::getline(ifs, out, '\n');
} else {
out = "Unknown";
std::string res;
std::getline(ifs, res, '\n');
return res;
}
return "Unknown";
}
} // namespace startgit

diff --git a/source/repository.hpp b/source/repository.hpp

@@ -25,14 +25,15 @@ public:

const auto& get_branches() const { return m_branches; }
private:
static void read_file(std::string& out,
const std::filesystem::path& base,
const char* file);
static std::string read_file(const std::filesystem::path& base,
const char* file);
git2wrap::repository m_repo;
std::string m_name;
std::string m_owner = "Unknown";
std::string m_url;
std::string m_owner;
std::string m_description;
std::vector<branch> m_branches;