gout

A static git page generator
git clone https://git.bracken.jp/gout.git
Log | Files | Refs | README | LICENSE

commit 30f7c260595185272ef2b841e985207d67db7aa6
parent dcd6abe6292f26d12b7947bae536ff581f74757c
Author: Chris Bracken <chris@bracken.jp>
Date:   Tue,  6 Jan 2026 16:57:46 +0900

Extract gitrepo_load_metadata static function

This separates the creation/opening of the repository object from the
code to logically populate it with repo metadata such as owner name,
description, clone URL, etc.

Diffstat:
Msrc/git/repo.c | 22+++++++++++++---------
1 file changed, 13 insertions(+), 9 deletions(-)

diff --git a/src/git/repo.c b/src/git/repo.c @@ -64,6 +64,7 @@ static bool gitrepo_has_blob(git_repository* repo, const char* file); static const char* gitrepo_first_matching_file(git_repository* repo, const char** files, size_t files_len); +static void gitrepo_load_metadata(GitRepo* repo, const char* path); static bool gitrepo_walk_tree_files(git_repository* repo, git_tree* tree, const char* path, @@ -236,15 +237,7 @@ const char* gitrepo_first_matching_file(git_repository* repo, return ""; } -GitRepo* gitrepo_create(const char* path) { - GitRepo* repo = ecalloc(1, sizeof(GitRepo)); - git_repository* git_repo = NULL; - git_repository_open_flag_t kRepoOpenFlags = GIT_REPOSITORY_OPEN_NO_SEARCH; - if (git_repository_open_ext(&git_repo, path, kRepoOpenFlags, NULL)) { - errx(1, "invalid git repository: %s", path); - } - repo->repo = git_repo; - +void gitrepo_load_metadata(GitRepo* repo, const char* path) { char* repo_path = realpath(path, NULL); if (!repo_path) { err(1, "realpath"); @@ -279,7 +272,18 @@ GitRepo* gitrepo_create(const char* path) { free(owner_path); free(desc_path); free(url_path); +} + +GitRepo* gitrepo_create(const char* path) { + GitRepo* repo = ecalloc(1, sizeof(GitRepo)); + git_repository* git_repo = NULL; + git_repository_open_flag_t kRepoOpenFlags = GIT_REPOSITORY_OPEN_NO_SEARCH; + if (git_repository_open_ext(&git_repo, path, kRepoOpenFlags, NULL)) { + errx(1, "invalid git repository: %s", path); + } + repo->repo = git_repo; + gitrepo_load_metadata(repo, path); return repo; }