commit 4116626b696c0a4ee918e9b221b5724bca3451c2
parent 5bc9a422994e6088c2baaf9c901c345acb11ce17
Author: Chris Bracken <chris@bracken.jp>
Date: Mon, 6 May 2024 18:34:21 +0900
Make output writer type configurable
For now, only HTML is supported, but other formats will be supported
later.
Diffstat:
2 files changed, 25 insertions(+), 5 deletions(-)
diff --git a/gitout.c b/gitout.c
@@ -18,6 +18,7 @@ struct GitoutOptions {
long long log_commit_limit; /* -1 indicates not used */
const char* cachefile_path;
const char* baseurl; /* base URL to make absolute RSS/Atom URI */
+ RepoWriterType writer_type;
};
static void commit_callback(const CommitInfo* ci, void* user_data);
@@ -30,6 +31,7 @@ GitoutOptions* gitout_options_create(int argc, const char* argv[]) {
.log_commit_limit = -1,
.cachefile_path = NULL,
.baseurl = "",
+ .writer_type = kRepoWriterTypeHtml,
};
for (int i = 1; i < argc; i++) {
if (argv[i][0] != '-') {
@@ -77,6 +79,8 @@ GitoutOptions* gitout_options_create(int argc, const char* argv[]) {
return NULL;
}
options.baseurl = argv[++i];
+ } else if (argv[i][1] == 'H') {
+ options.writer_type = kRepoWriterTypeHtml;
}
}
// Must specify at least one repo directory.
@@ -119,7 +123,7 @@ void gitout_init(const GitoutOptions* options) {
void gitout_run(const GitoutOptions* options) {
RepoInfo* repo = repoinfo_create(options->repodir);
- RepoWriter* writer = repowriter_create(kRepoWriterTypeHtml, repo);
+ RepoWriter* writer = repowriter_create(options->writer_type, repo);
if (options->log_commit_limit >= 0) {
repowriter_set_log_commit_limit(writer, options->log_commit_limit);
}
diff --git a/gitout_index.c b/gitout_index.c
@@ -1,27 +1,39 @@
#include "gitout_index.h"
+#include <err.h>
#include <stddef.h>
#include <stdlib.h>
#include "git/git.h"
#include "git/repo.h"
#include "security.h"
+#include "third_party/openbsd/reallocarray.h"
#include "utils.h"
#include "writer/index_writer.h"
struct GitoutIndexOptions {
const char** repo_dirs;
size_t repo_dir_count;
+ IndexWriterType writer_type;
};
GitoutIndexOptions* gitout_index_options_create(int argc, const char* argv[]) {
GitoutIndexOptions options = {
.repo_dirs = NULL,
.repo_dir_count = 0,
+ .writer_type = kIndexWriterTypeHtml,
};
- if (argc > 1) {
- options.repo_dirs = argv + 1;
- options.repo_dir_count = argc - 1;
+ for (int i = 1; i < argc; i++) {
+ if (argv[i][0] != '-') {
+ options.repo_dirs = reallocarray(
+ options.repo_dirs, options.repo_dir_count + 1, sizeof(char*));
+ if (!options.repo_dirs) {
+ err(1, "reallocarray");
+ }
+ options.repo_dirs[options.repo_dir_count++] = argv[i];
+ } else if (argv[i][1] == 'H') {
+ options.writer_type = kIndexWriterTypeHtml;
+ }
}
GitoutIndexOptions* options_out = ecalloc(1, sizeof(GitoutIndexOptions));
*options_out = options;
@@ -32,6 +44,10 @@ void gitout_index_options_free(GitoutIndexOptions* options) {
if (!options) {
return;
}
+ if (options->repo_dirs) {
+ free(options->repo_dirs);
+ options->repo_dirs = NULL;
+ }
free(options);
}
@@ -48,7 +64,7 @@ void gitout_index_init(const GitoutIndexOptions* options) {
}
void gitout_index_run(const GitoutIndexOptions* options) {
- IndexWriter* writer = indexwriter_create(kIndexWriterTypeHtml);
+ IndexWriter* writer = indexwriter_create(options->writer_type);
indexwriter_begin(writer);
for (size_t i = 0; i < options->repo_dir_count; i++) {
RepoInfo* ri = repoinfo_create(options->repo_dirs[i]);