gitout

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

commit 4c532231cb5b7d3d96f260b061d24d4ab22c5d66
parent 9a1bf02a56b01af4f333d219e1229d15274aa7b1
Author: Chris Bracken <chris@bracken.jp>
Date:   Fri, 10 May 2024 23:47:53 -0700

Add HTML prefix to HTML writer identifiers

Diffstat:
Mwriter/html/commit.c | 10+++++-----
Mwriter/html/fileblob.c | 24++++++++++++------------
Mwriter/html/fileblob.h | 12++++++------
Mwriter/html/files.c | 24++++++++++++------------
Mwriter/html/files.h | 12++++++------
Mwriter/html/log.c | 30+++++++++++++++---------------
Mwriter/html/log.h | 18+++++++++---------
Mwriter/html/page.c | 18+++++++++---------
Mwriter/html/page.h | 16++++++++--------
Mwriter/html/refs.c | 88+++++++++++++++++++++++++++++++++++++++++--------------------------------------
Mwriter/html/refs.h | 12++++++------
Mwriter/html/repo_writer.c | 55++++++++++++++++++++++++++++---------------------------
12 files changed, 162 insertions(+), 157 deletions(-)

diff --git a/writer/html/commit.c b/writer/html/commit.c @@ -15,7 +15,7 @@ struct HtmlCommit { FILE* out; - Page* page; + HtmlPage* page; }; static void html_commit_write_summary(HtmlCommit* commit, @@ -45,7 +45,7 @@ HtmlCommit* html_commit_create(const GitRepo* repo, char path[PATH_MAX]; path_concat(path, sizeof(path), "commit", filename); commit->out = efopen(path, "w"); - commit->page = page_create(commit->out, repo, title, "../"); + commit->page = html_page_create(commit->out, repo, title, "../"); return commit; } @@ -55,13 +55,13 @@ void html_commit_free(HtmlCommit* commit) { } fclose(commit->out); commit->out = NULL; - page_free(commit->page); + html_page_free(commit->page); commit->page = NULL; free(commit); } void html_commit_begin(HtmlCommit* commit) { - page_begin(commit->page); + html_page_begin(commit->page); } void html_commit_add_commit(HtmlCommit* commit, const GitCommit* git_commit) { @@ -90,7 +90,7 @@ void html_commit_add_commit(HtmlCommit* commit, const GitCommit* git_commit) { } void html_commit_end(HtmlCommit* commit) { - page_end(commit->page); + html_page_end(commit->page); } void html_commit_write_summary(HtmlCommit* commit, diff --git a/writer/html/fileblob.c b/writer/html/fileblob.c @@ -12,14 +12,14 @@ #include "utils.h" #include "writer/html/page.h" -struct FileBlob { +struct HtmlFileBlob { const GitRepo* repo; FILE* out; - Page* page; + HtmlPage* page; }; -FileBlob* fileblob_create(const GitRepo* repo, const char* path) { - FileBlob* blob = ecalloc(1, sizeof(FileBlob)); +HtmlFileBlob* html_fileblob_create(const GitRepo* repo, const char* path) { + HtmlFileBlob* blob = ecalloc(1, sizeof(HtmlFileBlob)); blob->repo = repo; // Create directories. @@ -51,26 +51,26 @@ FileBlob* fileblob_create(const GitRepo* repo, const char* path) { if (!title) { err(1, "basename"); } - blob->page = page_create(blob->out, repo, title, relpath); + blob->page = html_page_create(blob->out, repo, title, relpath); return blob; } -void fileblob_free(FileBlob* blob) { +void html_fileblob_free(HtmlFileBlob* blob) { if (!blob) { return; } fclose(blob->out); blob->out = NULL; - page_free(blob->page); + html_page_free(blob->page); blob->page = NULL; free(blob); } -void fileblob_begin(FileBlob* blob) { - page_begin(blob->page); +void html_fileblob_begin(HtmlFileBlob* blob) { + html_page_begin(blob->page); } -void fileblob_add_file(FileBlob* blob, const GitFile* file) { +void html_fileblob_add_file(HtmlFileBlob* blob, const GitFile* file) { FILE* out = blob->out; fprintf(out, "<p> "); @@ -110,6 +110,6 @@ void fileblob_add_file(FileBlob* blob, const GitFile* file) { fprintf(out, "</pre>\n"); } -void fileblob_end(FileBlob* blob) { - page_end(blob->page); +void html_fileblob_end(HtmlFileBlob* blob) { + html_page_end(blob->page); } diff --git a/writer/html/fileblob.h b/writer/html/fileblob.h @@ -4,12 +4,12 @@ #include "git/file.h" #include "git/repo.h" -typedef struct FileBlob FileBlob; +typedef struct HtmlFileBlob HtmlFileBlob; -FileBlob* fileblob_create(const GitRepo* repo, const char* path); -void fileblob_free(FileBlob* blob); -void fileblob_begin(FileBlob* blob); -void fileblob_add_file(FileBlob* blob, const GitFile* file); -void fileblob_end(FileBlob* blob); +HtmlFileBlob* html_fileblob_create(const GitRepo* repo, const char* path); +void html_fileblob_free(HtmlFileBlob* blob); +void html_fileblob_begin(HtmlFileBlob* blob); +void html_fileblob_add_file(HtmlFileBlob* blob, const GitFile* file); +void html_fileblob_end(HtmlFileBlob* blob); #endif // GITOUT_WRITER_HTML_FILEBLOB_H_ diff --git a/writer/html/files.c b/writer/html/files.c @@ -8,33 +8,33 @@ #include "utils.h" #include "writer/html/page.h" -struct Files { +struct HtmlFiles { const GitRepo* repo; FILE* out; - Page* page; + HtmlPage* page; }; -Files* files_create(const GitRepo* repo) { - Files* files = ecalloc(1, sizeof(Files)); +HtmlFiles* html_files_create(const GitRepo* repo) { + HtmlFiles* files = ecalloc(1, sizeof(HtmlFiles)); files->repo = repo; files->out = efopen("files.html", "w"); - files->page = page_create(files->out, repo, "Files", ""); + files->page = html_page_create(files->out, repo, "Files", ""); return files; } -void files_free(Files* files) { +void html_files_free(HtmlFiles* files) { if (!files) { return; } fclose(files->out); files->out = NULL; - page_free(files->page); + html_page_free(files->page); files->page = NULL; free(files); } -void files_begin(Files* files) { - page_begin(files->page); +void html_files_begin(HtmlFiles* files) { + html_page_begin(files->page); fprintf(files->out, "<table id=\"files\"><thead>\n" "<tr>" @@ -45,7 +45,7 @@ void files_begin(Files* files) { "</thead><tbody>\n"); } -void files_add_file(Files* files, const GitFile* file) { +void html_files_add_file(HtmlFiles* files, const GitFile* file) { FILE* out = files->out; fprintf(out, "<tr><td>%s</td>", gitfile_mode(file)); @@ -70,7 +70,7 @@ void files_add_file(Files* files, const GitFile* file) { fprintf(out, "</td></tr>\n"); } -void files_end(Files* files) { +void html_files_end(HtmlFiles* files) { fprintf(files->out, "</tbody></table>"); - page_end(files->page); + html_page_end(files->page); } diff --git a/writer/html/files.h b/writer/html/files.h @@ -4,12 +4,12 @@ #include "git/file.h" #include "git/repo.h" -typedef struct Files Files; +typedef struct HtmlFiles HtmlFiles; -Files* files_create(const GitRepo* repo); -void files_free(Files* files); -void files_begin(Files* files); -void files_add_file(Files* files, const GitFile* file); -void files_end(Files* files); +HtmlFiles* html_files_create(const GitRepo* repo); +void html_files_free(HtmlFiles* files); +void html_files_begin(HtmlFiles* files); +void html_files_add_file(HtmlFiles* files, const GitFile* file); +void html_files_end(HtmlFiles* files); #endif // GITOUT_WRITER_HTML_FILES_H_ diff --git a/writer/html/log.c b/writer/html/log.c @@ -8,28 +8,28 @@ #include "writer/cache/cache.h" #include "writer/html/page.h" -struct Log { +struct HtmlLog { const GitRepo* repo; FILE* out; Cache* cache; - Page* page; + HtmlPage* page; size_t remaining_commits; size_t unlogged_commits; }; static void write_commit_row(FILE* out, const GitCommit* commit); -Log* log_create(const GitRepo* repo) { - Log* log = ecalloc(1, sizeof(Log)); +HtmlLog* html_log_create(const GitRepo* repo) { + HtmlLog* log = ecalloc(1, sizeof(HtmlLog)); log->repo = repo; log->out = efopen("log.html", "w"); - log->page = page_create(log->out, repo, "Log", ""); + log->page = html_page_create(log->out, repo, "Log", ""); log->remaining_commits = SIZE_MAX; log->unlogged_commits = 0; return log; } -void log_free(Log* log) { +void html_log_free(HtmlLog* log) { if (!log) { return; } @@ -37,25 +37,25 @@ void log_free(Log* log) { log->out = NULL; cache_free(log->cache); log->cache = NULL; - page_free(log->page); + html_page_free(log->page); log->page = NULL; free(log); } -void log_set_cachefile(Log* log, const char* cachefile) { +void html_log_set_cachefile(HtmlLog* log, const char* cachefile) { log->cache = cache_create(cachefile, write_commit_row); } -void log_set_commit_limit(Log* log, size_t count) { +void html_log_set_commit_limit(HtmlLog* log, size_t count) { log->remaining_commits = count; } -bool log_can_add_commits(const Log* log) { +bool html_log_can_add_commits(const HtmlLog* log) { return !log->cache || cache_can_add_commits(log->cache); } -void log_begin(Log* log) { - page_begin(log->page); +void html_log_begin(HtmlLog* log) { + html_page_begin(log->page); fprintf(log->out, "<table id=\"log\"><thead>\n" "<tr>" @@ -69,7 +69,7 @@ void log_begin(Log* log) { "</thead><tbody>\n"); } -void log_add_commit(Log* log, const GitCommit* commit) { +void html_log_add_commit(HtmlLog* log, const GitCommit* commit) { if (log->cache) { cache_add_commit_row(log->cache, commit); } else if (log->remaining_commits > 0) { @@ -80,7 +80,7 @@ void log_add_commit(Log* log, const GitCommit* commit) { } } -void log_end(Log* log) { +void html_log_end(HtmlLog* log) { FILE* out = log->out; if (log->cache) { cache_write(log->cache); @@ -92,7 +92,7 @@ void log_end(Log* log) { fprintf(out, "</td></tr>\n"); } fprintf(out, "</tbody></table>"); - page_end(log->page); + html_page_end(log->page); } void write_commit_row(FILE* out, const GitCommit* commit) { diff --git a/writer/html/log.h b/writer/html/log.h @@ -7,15 +7,15 @@ #include "git/commit.h" #include "git/repo.h" -typedef struct Log Log; +typedef struct HtmlLog HtmlLog; -Log* log_create(const GitRepo* repo); -void log_free(Log* log); -void log_set_cachefile(Log* log, const char* cachefile); -void log_set_commit_limit(Log* log, size_t count); -bool log_can_add_commits(const Log* log); -void log_begin(Log* log); -void log_add_commit(Log* log, const GitCommit* commit); -void log_end(Log* log); +HtmlLog* html_log_create(const GitRepo* repo); +void html_log_free(HtmlLog* log); +void html_log_set_cachefile(HtmlLog* log, const char* cachefile); +void html_log_set_commit_limit(HtmlLog* log, size_t count); +bool html_log_can_add_commits(const HtmlLog* log); +void html_log_begin(HtmlLog* log); +void html_log_add_commit(HtmlLog* log, const GitCommit* commit); +void html_log_end(HtmlLog* log); #endif // GITOUT_WRITER_HTML_LOG_H_ diff --git a/writer/html/page.c b/writer/html/page.c @@ -5,18 +5,18 @@ #include "format.h" #include "utils.h" -struct Page { +struct HtmlPage { FILE* out; const GitRepo* repo; char* title; char* relpath; }; -Page* page_create(FILE* out, - const GitRepo* repo, - const char* title, - const char* relpath) { - Page* page = ecalloc(1, sizeof(Page)); +HtmlPage* html_page_create(FILE* out, + const GitRepo* repo, + const char* title, + const char* relpath) { + HtmlPage* page = ecalloc(1, sizeof(HtmlPage)); page->out = out; page->repo = repo; page->title = estrdup(title); @@ -24,7 +24,7 @@ Page* page_create(FILE* out, return page; } -void page_free(Page* page) { +void html_page_free(HtmlPage* page) { if (!page) { return; } @@ -35,7 +35,7 @@ void page_free(Page* page) { free(page); } -void page_begin(Page* page) { +void html_page_begin(HtmlPage* page) { FILE* out = page->out; fprintf( out, @@ -120,6 +120,6 @@ void page_begin(Page* page) { fprintf(out, "</td></tr></table>\n<hr/>\n<div id=\"content\">\n"); } -void page_end(Page* page) { +void html_page_end(HtmlPage* page) { fprintf(page->out, "</div>\n</body>\n</html>\n"); } diff --git a/writer/html/page.h b/writer/html/page.h @@ -5,14 +5,14 @@ #include "git/repo.h" -typedef struct Page Page; +typedef struct HtmlPage HtmlPage; -Page* page_create(FILE* out, - const GitRepo* repo, - const char* title, - const char* relpath); -void page_free(Page* page); -void page_begin(Page* page); -void page_end(Page* page); +HtmlPage* html_page_create(FILE* out, + const GitRepo* repo, + const char* title, + const char* relpath); +void html_page_free(HtmlPage* page); +void html_page_begin(HtmlPage* page); +void html_page_end(HtmlPage* page); #endif // GITOUT_WRITER_HTML_PAGE_H_ diff --git a/writer/html/refs.c b/writer/html/refs.c @@ -12,33 +12,36 @@ typedef struct { char* title; char* id; FILE* out; -} RefsTable; +} HtmlRefsTable; -struct Refs { +struct HtmlRefs { const GitRepo* repo; FILE* out; - Page* page; - RefsTable* branches; - RefsTable* tags; + HtmlPage* page; + HtmlRefsTable* branches; + HtmlRefsTable* tags; }; -static RefsTable* refstable_create(const char* title, - const char* id, - FILE* out); -static void refstable_free(RefsTable* table); -static void refstable_begin(RefsTable* table); -static void refstable_add_ref(RefsTable* table, const GitReference* ref); -static void refstable_end(RefsTable* table); +static HtmlRefsTable* html_refstable_create(const char* title, + const char* id, + FILE* out); +static void html_refstable_free(HtmlRefsTable* table); +static void html_refstable_begin(HtmlRefsTable* table); +static void html_refstable_add_ref(HtmlRefsTable* table, + const GitReference* ref); +static void html_refstable_end(HtmlRefsTable* table); -RefsTable* refstable_create(const char* title, const char* id, FILE* out) { - RefsTable* table = ecalloc(1, sizeof(RefsTable)); +HtmlRefsTable* html_refstable_create(const char* title, + const char* id, + FILE* out) { + HtmlRefsTable* table = ecalloc(1, sizeof(HtmlRefsTable)); table->title = estrdup(title); table->id = estrdup(id); table->out = out; return table; } -void refstable_free(RefsTable* table) { +void html_refstable_free(HtmlRefsTable* table) { if (!table) { return; } @@ -49,7 +52,7 @@ void refstable_free(RefsTable* table) { free(table); } -void refstable_begin(RefsTable* table) { +void html_refstable_begin(HtmlRefsTable* table) { fprintf(table->out, "<h2>%s</h2>", table->title); fprintf(table->out, "<table id=\"%s\">", table->id); fprintf(table->out, @@ -62,7 +65,7 @@ void refstable_begin(RefsTable* table) { "</thead><tbody>\n"); } -void refstable_add_ref(RefsTable* table, const GitReference* ref) { +void html_refstable_add_ref(HtmlRefsTable* table, const GitReference* ref) { GitCommit* commit = gitreference_commit(ref); fprintf(table->out, "<tr><td>"); print_xml_encoded(table->out, gitreference_shorthand(ref)); @@ -73,71 +76,72 @@ void refstable_add_ref(RefsTable* table, const GitReference* ref) { fprintf(table->out, "</td></tr>\n"); } -void refstable_end(RefsTable* table) { +void html_refstable_end(HtmlRefsTable* table) { fprintf(table->out, "</tbody></table><br/>\n"); } -Refs* refs_create(const GitRepo* repo) { - Refs* refs = ecalloc(1, sizeof(Refs)); +HtmlRefs* html_refs_create(const GitRepo* repo) { + HtmlRefs* refs = ecalloc(1, sizeof(HtmlRefs)); refs->repo = repo; refs->out = efopen("refs.html", "w"); - refs->page = page_create(refs->out, repo, "Refs", ""); + refs->page = html_page_create(refs->out, repo, "Refs", ""); return refs; } -void refs_free(Refs* refs) { +void html_refs_free(HtmlRefs* refs) { if (!refs) { return; } fclose(refs->out); refs->out = NULL; - page_free(refs->page); + html_page_free(refs->page); refs->page = NULL; - refstable_free(refs->branches); + html_refstable_free(refs->branches); refs->branches = NULL; - refstable_free(refs->tags); + html_refstable_free(refs->tags); refs->tags = NULL; free(refs); } -void refs_begin(Refs* refs) { - page_begin(refs->page); +void html_refs_begin(HtmlRefs* refs) { + html_page_begin(refs->page); } -void refs_add_ref(Refs* refs, const GitReference* ref) { +void html_refs_add_ref(HtmlRefs* refs, const GitReference* ref) { switch (gitreference_type(ref)) { case kReftypeBranch: if (!refs->branches) { - refs->branches = refstable_create("Branches", "branches", refs->out); - refstable_begin(refs->branches); + refs->branches = + html_refstable_create("Branches", "branches", refs->out); + html_refstable_begin(refs->branches); } - refstable_add_ref(refs->branches, ref); + html_refstable_add_ref(refs->branches, ref); break; case kReftypeTag: if (refs->branches) { - refstable_end(refs->branches); - refstable_free(refs->branches); + html_refstable_end(refs->branches); + html_refstable_free(refs->branches); refs->branches = NULL; } if (!refs->tags) { - refs->tags = refstable_create("Tags", "tags", refs->out); - refstable_begin(refs->tags); + refs->tags = html_refstable_create("Tags", "tags", refs->out); + html_refstable_begin(refs->tags); } - refstable_add_ref(refs->tags, ref); + html_refstable_add_ref(refs->tags, ref); break; } } -void refs_end(Refs* refs) { +void html_refs_end(HtmlRefs* refs) { if (refs->branches) { - refstable_end(refs->branches); - refstable_free(refs->branches); + html_refstable_end(refs->branches); + html_refstable_free(refs->branches); refs->branches = NULL; } if (refs->tags) { - refstable_end(refs->tags); - refstable_free(refs->tags); + html_refstable_end(refs->tags); + html_refstable_free(refs->tags); refs->tags = NULL; } - page_end(refs->page); + html_page_end(refs->page); } diff --git a/writer/html/refs.h b/writer/html/refs.h @@ -4,12 +4,12 @@ #include "git/reference.h" #include "git/repo.h" -typedef struct Refs Refs; +typedef struct HtmlRefs HtmlRefs; -Refs* refs_create(const GitRepo* repo); -void refs_free(Refs* refs); -void refs_begin(Refs* refs); -void refs_add_ref(Refs* refs, const GitReference* ref); -void refs_end(Refs* refs); +HtmlRefs* html_refs_create(const GitRepo* repo); +void html_refs_free(HtmlRefs* refs); +void html_refs_begin(HtmlRefs* refs); +void html_refs_add_ref(HtmlRefs* refs, const GitReference* ref); +void html_refs_end(HtmlRefs* refs); #endif // GITOUT_WRITER_HTML_REFS_H_ diff --git a/writer/html/repo_writer.c b/writer/html/repo_writer.c @@ -20,21 +20,21 @@ struct HtmlRepoWriter { const GitRepo* repo; - Refs* refs; - Log* log; + HtmlRefs* refs; + HtmlLog* log; Atom* atom; Atom* tags; - Files* files; + HtmlFiles* files; }; HtmlRepoWriter* html_repowriter_create(const GitRepo* repo) { HtmlRepoWriter* writer = ecalloc(1, sizeof(HtmlRepoWriter)); writer->repo = repo; - writer->refs = refs_create(repo); - writer->log = log_create(repo); + writer->refs = html_refs_create(repo); + writer->log = html_log_create(repo); writer->atom = atom_create(repo, kAtomTypeAll); writer->tags = atom_create(repo, kAtomTypeTags); - writer->files = files_create(repo); + writer->files = html_files_create(repo); return writer; } @@ -42,27 +42,27 @@ void html_repowriter_free(HtmlRepoWriter* writer) { if (!writer) { return; } - refs_free(writer->refs); + html_refs_free(writer->refs); writer->refs = NULL; - log_free(writer->log); + html_log_free(writer->log); writer->log = NULL; atom_free(writer->atom); writer->atom = NULL; atom_free(writer->tags); writer->tags = NULL; - files_free(writer->files); + html_files_free(writer->files); writer->files = NULL; free(writer); } void html_repowriter_set_log_cachefile(void* writer, const char* cachefile) { HtmlRepoWriter* html_writer = (HtmlRepoWriter*)writer; - log_set_cachefile(html_writer->log, cachefile); + html_log_set_cachefile(html_writer->log, cachefile); } void html_repowriter_set_log_commit_limit(void* writer, size_t count) { HtmlRepoWriter* html_writer = (HtmlRepoWriter*)writer; - log_set_commit_limit(html_writer->log, count); + html_log_set_commit_limit(html_writer->log, count); } void html_repowriter_set_baseurl(void* writer, const char* baseurl) { @@ -76,11 +76,11 @@ void html_repowriter_begin(void* writer) { mkdir("commit", S_IRWXU | S_IRWXG | S_IRWXO); mkdir("file", S_IRWXU | S_IRWXG | S_IRWXO); - refs_begin(html_writer->refs); - log_begin(html_writer->log); + html_refs_begin(html_writer->refs); + html_log_begin(html_writer->log); atom_begin(html_writer->atom); atom_begin(html_writer->tags); - files_begin(html_writer->files); + html_files_begin(html_writer->files); } void html_repowriter_add_commit(void* writer, const GitCommit* git_commit) { @@ -94,8 +94,8 @@ void html_repowriter_add_commit(void* writer, const GitCommit* git_commit) { path_concat(path, sizeof(path), "commit", filename); atom_add_commit(html_writer->atom, git_commit, path, "text/html", ""); - if (log_can_add_commits(html_writer->log)) { - log_add_commit(html_writer->log, git_commit); + if (html_log_can_add_commits(html_writer->log)) { + html_log_add_commit(html_writer->log, git_commit); HtmlCommit* commit = html_commit_create(html_writer->repo, gitcommit_oid(git_commit), gitcommit_summary(git_commit)); @@ -108,7 +108,7 @@ void html_repowriter_add_commit(void* writer, const GitCommit* git_commit) { void html_repowriter_add_reference(void* writer, const GitReference* ref) { HtmlRepoWriter* html_writer = (HtmlRepoWriter*)writer; - refs_add_ref(html_writer->refs, ref); + html_refs_add_ref(html_writer->refs, ref); if (gitreference_type(ref) == kReftypeTag) { GitCommit* commit = gitreference_commit(ref); char filename[PATH_MAX]; @@ -125,20 +125,21 @@ void html_repowriter_add_reference(void* writer, const GitReference* ref) { void html_repowriter_add_file(void* writer, const GitFile* file) { HtmlRepoWriter* html_writer = (HtmlRepoWriter*)writer; - files_add_file(html_writer->files, file); - - FileBlob* blob = fileblob_create(html_writer->repo, gitfile_repo_path(file)); - fileblob_begin(blob); - fileblob_add_file(blob, file); - fileblob_end(blob); - fileblob_free(blob); + html_files_add_file(html_writer->files, file); + + HtmlFileBlob* blob = + html_fileblob_create(html_writer->repo, gitfile_repo_path(file)); + html_fileblob_begin(blob); + html_fileblob_add_file(blob, file); + html_fileblob_end(blob); + html_fileblob_free(blob); } void html_repowriter_end(void* writer) { HtmlRepoWriter* html_writer = (HtmlRepoWriter*)writer; - refs_end(html_writer->refs); - log_end(html_writer->log); + html_refs_end(html_writer->refs); + html_log_end(html_writer->log); atom_end(html_writer->atom); atom_end(html_writer->tags); - files_end(html_writer->files); + html_files_end(html_writer->files); }