gout

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

commit b95e5ade712319ab5fa247eee1958bc3cfe24d3e
parent a5aa70a985c9856e7be9cd0efa2acf4ab66ad5b9
Author: Chris Bracken <chris@bracken.jp>
Date:   Tue, 17 Feb 2026 18:33:34 +0900

git: make structs public

These no longer expose any libgit2 type information and so can be safely
make public without dragging libgit2 headers into gout main and writer code.

Diffstat:
Msrc/git/commit.c | 86+++----------------------------------------------------------------------------
Msrc/git/commit.h | 67+++++++++++++++++--------------------------------------------------
Msrc/git/delta.c | 102++++---------------------------------------------------------------------------
Msrc/git/delta.h | 50+++++++++++++++++++++++++-------------------------
Msrc/git/file.c | 68+++++++++++++++++++-------------------------------------------------
Msrc/git/file.h | 24+++++++++++-------------
Msrc/git/reference.c | 22++--------------------
Msrc/git/reference.h | 10+++++-----
Msrc/git/repo.c | 7++++---
Msrc/gout_tests_main.c | 4++--
Msrc/utils_tests.c | 30+++++++++++++++---------------
Msrc/writer/atom/atom.c | 27+++++++++++++--------------
Msrc/writer/cache/cache.c | 4++--
Msrc/writer/gopher/commit.c | 71+++++++++++++++++++++++++++++++++++------------------------------------
Msrc/writer/gopher/fileblob.c | 10+++++-----
Msrc/writer/gopher/files.c | 10+++++-----
Msrc/writer/gopher/log.c | 8++++----
Msrc/writer/gopher/refs.c | 10+++++-----
Msrc/writer/gopher/repo_index.c | 2+-
Msrc/writer/gopher/repo_writer.c | 23+++++++++--------------
Msrc/writer/html/commit.c | 71+++++++++++++++++++++++++++++++++++------------------------------------
Msrc/writer/html/fileblob.c | 10+++++-----
Msrc/writer/html/files.c | 12++++++------
Msrc/writer/html/log.c | 11+++++------
Msrc/writer/html/refs.c | 10+++++-----
Msrc/writer/html/repo_index.c | 2+-
Msrc/writer/html/repo_writer.c | 21++++++++-------------
Msrc/writer/repo_writer.c | 3+--
28 files changed, 252 insertions(+), 523 deletions(-)

diff --git a/src/git/commit.c b/src/git/commit.c @@ -13,24 +13,6 @@ #include "git/internal.h" #include "utils.h" -struct GitCommit { - char* oid; - char* parentoid; - char* summary; - char* message; - time_t commit_time; - int commit_timezone_offset; - char* author_name; - char* author_email; - time_t author_time; - int author_timezone_offset; - GitDelta** deltas; - size_t deltas_len; - size_t addcount; - size_t delcount; - size_t filecount; -}; - GitCommit* gitcommit_create(const git_oid* oid, git_repository* repo) { GitCommit* commit = ecalloc(1, sizeof(GitCommit)); git_commit* gcommit = NULL; @@ -40,8 +22,7 @@ GitCommit* gitcommit_create(const git_oid* oid, git_repository* repo) { // Get OID, parent OID. commit->oid = ecalloc(GIT_OID_SHA1_HEXSIZE + 1, sizeof(char)); - git_oid_tostr(commit->oid, GIT_OID_SHA1_HEXSIZE + 1, - git_commit_id(gcommit)); + git_oid_tostr(commit->oid, GIT_OID_SHA1_HEXSIZE + 1, git_commit_id(gcommit)); commit->parentoid = ecalloc(GIT_OID_SHA1_HEXSIZE + 1, sizeof(char)); git_oid_tostr(commit->parentoid, GIT_OID_SHA1_HEXSIZE + 1, git_commit_parent_id(gcommit, 0)); @@ -120,8 +101,8 @@ GitCommit* gitcommit_create(const git_oid* oid, git_repository* repo) { GitDelta* delta = gitdelta_create(patch); if (delta) { commit->deltas[deltas_out_count++] = delta; - commit->addcount += gitdelta_lines_added(delta); - commit->delcount += gitdelta_lines_deleted(delta); + commit->addcount += delta->addcount; + commit->delcount += delta->delcount; } } commit->deltas_len = deltas_out_count; @@ -151,64 +132,3 @@ void gitcommit_free(GitCommit* commit) { free(commit); } - -const char* gitcommit_oid(const GitCommit* commit) { - return commit->oid; -} - -const char* gitcommit_parentoid(const GitCommit* commit) { - return commit->parentoid; -} - -const char* gitcommit_summary(const GitCommit* commit) { - return commit->summary; -} - -const char* gitcommit_message(const GitCommit* commit) { - return commit->message; -} - -time_t gitcommit_commit_time(const GitCommit* commit) { - return commit->commit_time; -} - -int gitcommit_commit_timezone_offset(const GitCommit* commit) { - return commit->commit_timezone_offset; -} - -const char* gitcommit_author_name(const GitCommit* commit) { - return commit->author_name; -} - -const char* gitcommit_author_email(const GitCommit* commit) { - return commit->author_email; -} - -time_t gitcommit_author_time(const GitCommit* commit) { - return commit->author_time; -} - -int gitcommit_author_timezone_offset(const GitCommit* commit) { - return commit->author_timezone_offset; -} - -GitDelta* gitcommit_delta(const GitCommit* commit, size_t index) { - assert(index < commit->deltas_len); - return commit->deltas[index]; -} - -size_t gitcommit_delta_count(const GitCommit* commit) { - return commit->deltas_len; -} - -size_t gitcommit_addcount(const GitCommit* commit) { - return commit->addcount; -} - -size_t gitcommit_delcount(const GitCommit* commit) { - return commit->delcount; -} - -size_t gitcommit_filecount(const GitCommit* commit) { - return commit->filecount; -} diff --git a/src/git/commit.h b/src/git/commit.h @@ -3,56 +3,23 @@ #include <time.h> -#include "git/delta.h" - /* A git commit. */ -typedef struct GitCommit GitCommit; - -/* Returns the commit OID as a SHA1 hash. */ -const char* gitcommit_oid(const GitCommit* commit); - -/* Returns the parent commit OID as a SHA1 hash, or NULL if there is no parent - * commit. */ -const char* gitcommit_parentoid(const GitCommit* commit); - -/* Returns the commit summary. This is the first line of the commit message. */ -const char* gitcommit_summary(const GitCommit* commit); - -/* Returns the commit message, excluding the summary. */ -const char* gitcommit_message(const GitCommit* commit); - -/* Returns the commit author name. */ -const char* gitcommit_author_name(const GitCommit* commit); - -/* Returns the commit author email. */ -const char* gitcommit_author_email(const GitCommit* commit); - -/* Returns the author time. */ -time_t gitcommit_author_time(const GitCommit* commit); - -/* Returns the timezone for the time returned by gitcommit_author_time. */ -int gitcommit_author_timezone_offset(const GitCommit* commit); - -/* Returns the commit time. */ -time_t gitcommit_commit_time(const GitCommit* commit); - -/* Returns the timezone for the time returned by gitcommit_commit_time. */ -int gitcommit_commit_timezone_offset(const GitCommit* commit); - -/* Returns the delta at the specified index. The index must be less than the - * value returned by gitcommit_delta_count. */ -GitDelta* gitcommit_delta(const GitCommit* commit, size_t index); - -/* Returns the total number of deltas in this commit. */ -size_t gitcommit_delta_count(const GitCommit* commit); - -/* Returns the sum of lines added across all deltas in this commit. */ -size_t gitcommit_addcount(const GitCommit* commit); - -/* Returns the sum of lines deleted across all deltas in this commit. */ -size_t gitcommit_delcount(const GitCommit* commit); - -/* Returns the sum of files modified across all deltas in this commit. */ -size_t gitcommit_filecount(const GitCommit* commit); +typedef struct GitCommit { + char* oid; + char* parentoid; + char* summary; + char* message; + time_t commit_time; + int commit_timezone_offset; + char* author_name; + char* author_email; + time_t author_time; + int author_timezone_offset; + struct GitDelta** deltas; + size_t deltas_len; + size_t addcount; + size_t delcount; + size_t filecount; +} GitCommit; #endif // GOUT_GIT_COMMIT_H_ diff --git a/src/git/delta.c b/src/git/delta.c @@ -9,14 +9,6 @@ #include "git/internal.h" #include "utils.h" -struct GitHunkLine { - size_t id; - int old_lineno; - int new_lineno; - char* content; - size_t content_len; -}; - /* HunkLines */ static GitHunkLine* githunkline_create(git_patch* patch, size_t hunk_id, @@ -60,33 +52,6 @@ void githunkline_free(GitHunkLine* hunk_line) { free(hunk_line); } -size_t githunkline_id(const GitHunkLine* line) { - return line->id; -} - -int githunkline_old_lineno(const GitHunkLine* line) { - return line->old_lineno; -} - -int githunkline_new_lineno(const GitHunkLine* line) { - return line->new_lineno; -} - -const char* githunkline_content(const GitHunkLine* line) { - return line->content; -} - -size_t githunkline_content_len(const GitHunkLine* line) { - return line->content_len; -} - -struct GitHunk { - size_t id; - char* header; - GitHunkLine** lines; - size_t lines_len; -}; - GitHunk* githunk_create(git_patch* patch, size_t hunk_id) { const git_diff_hunk* hunk; size_t line_count; @@ -123,23 +88,6 @@ void githunk_free(GitHunk* hunk) { free(hunk); } -size_t githunk_id(const GitHunk* hunk) { - return hunk->id; -} - -const char* githunk_header(const GitHunk* hunk) { - return hunk->header; -} - -GitHunkLine* githunk_line(const GitHunk* hunk, size_t line) { - assert(line < hunk->lines_len); - return hunk->lines[line]; -} - -size_t githunk_line_count(const GitHunk* hunk) { - return hunk->lines_len; -} - char status_for_delta(const git_diff_delta* delta) { switch (delta->status) { case GIT_DELTA_ADDED: @@ -164,25 +112,16 @@ char status_for_delta(const git_diff_delta* delta) { return ' '; } -struct GitDelta { - bool is_binary; - char status; - char* old_file_path; - char* new_file_path; - size_t addcount; - size_t delcount; - GitHunk** hunks; - size_t hunks_len; -}; - GitDelta* gitdelta_create(git_patch* patch) { GitDelta* delta = ecalloc(1, sizeof(GitDelta)); const git_diff_delta* git_delta = git_patch_get_delta(patch); delta->status = status_for_delta(git_delta); delta->is_binary = git_delta->flags & GIT_DIFF_FLAG_BINARY; - delta->old_file_path = git_delta->old_file.path ? estrdup(git_delta->old_file.path) : NULL; - delta->new_file_path = git_delta->new_file.path ? estrdup(git_delta->new_file.path) : NULL; + delta->old_file_path = + git_delta->old_file.path ? estrdup(git_delta->old_file.path) : NULL; + delta->new_file_path = + git_delta->new_file.path ? estrdup(git_delta->new_file.path) : NULL; delta->addcount = 0; delta->delcount = 0; @@ -239,39 +178,6 @@ void gitdelta_free(GitDelta* delta) { free(delta); } -bool gitdelta_is_binary(const GitDelta* delta) { - return delta->is_binary; -} - -char gitdelta_status(const GitDelta* delta) { - return delta->status; -} - -const char* gitdelta_old_file_path(const GitDelta* delta) { - return delta->old_file_path; -} - -const char* gitdelta_new_file_path(const GitDelta* delta) { - return delta->new_file_path; -} - -size_t gitdelta_lines_added(const GitDelta* delta) { - return delta->addcount; -} - -size_t gitdelta_lines_deleted(const GitDelta* delta) { - return delta->delcount; -} - -GitHunk* gitdelta_hunk(const GitDelta* delta, size_t id) { - assert(id < delta->hunks_len); - return delta->hunks[id]; -} - -size_t gitdelta_hunk_count(const GitDelta* delta) { - return delta->hunks_len; -} - char* gitdelta_graph(const GitDelta* delta, size_t length, char c, diff --git a/src/git/delta.h b/src/git/delta.h @@ -4,31 +4,31 @@ #include <stdbool.h> #include <stddef.h> -typedef struct GitHunkLine GitHunkLine; - -size_t githunkline_id(const GitHunkLine* line); -int githunkline_old_lineno(const GitHunkLine* line); -int githunkline_new_lineno(const GitHunkLine* line); -const char* githunkline_content(const GitHunkLine* line); -size_t githunkline_content_len(const GitHunkLine* line); - -typedef struct GitHunk GitHunk; - -size_t githunk_id(const GitHunk* hunk); -const char* githunk_header(const GitHunk* hunk); -GitHunkLine* githunk_line(const GitHunk* hunk, size_t line); -size_t githunk_line_count(const GitHunk* hunk); - -typedef struct GitDelta GitDelta; - -bool gitdelta_is_binary(const GitDelta* delta); -char gitdelta_status(const GitDelta* delta); -const char* gitdelta_old_file_path(const GitDelta* delta); -const char* gitdelta_new_file_path(const GitDelta* delta); -size_t gitdelta_lines_added(const GitDelta* delta); -size_t gitdelta_lines_deleted(const GitDelta* delta); -GitHunk* gitdelta_hunk(const GitDelta* delta, size_t id); -size_t gitdelta_hunk_count(const GitDelta* delta); +typedef struct GitHunkLine { + size_t id; + int old_lineno; + int new_lineno; + char* content; + size_t content_len; +} GitHunkLine; + +typedef struct GitHunk { + size_t id; + char* header; + GitHunkLine** lines; + size_t lines_len; +} GitHunk; + +typedef struct GitDelta { + bool is_binary; + char status; + char* old_file_path; + char* new_file_path; + size_t addcount; + size_t delcount; + GitHunk** hunks; + size_t hunks_len; +} GitDelta; char* gitdelta_added_graph(const GitDelta* delta, size_t max_width); char* gitdelta_deleted_graph(const GitDelta* delta, size_t max_width); diff --git a/src/git/file.c b/src/git/file.c @@ -1,22 +1,11 @@ #include "git/file.h" #include <stdlib.h> +#include <string.h> #include "git/internal.h" #include "utils.h" -struct GitFile { - FileType type; - const char* mode; - const char* display_path; - const char* repo_path; - // Submodule commit OID. Empty string for files. - const char* commit_oid; - ssize_t size_bytes; - ssize_t size_lines; - const char* content; -}; - GitFile* gitfile_create(FileType type, const char* mode, const char* display_path, @@ -27,48 +16,29 @@ GitFile* gitfile_create(FileType type, const char* content) { GitFile* file = ecalloc(1, sizeof(GitFile)); file->type = type; - file->mode = mode; - file->display_path = display_path; - file->repo_path = repo_path; - file->commit_oid = commit_oid; + file->mode = mode ? estrdup(mode) : NULL; + file->display_path = display_path ? estrdup(display_path) : NULL; + file->repo_path = repo_path ? estrdup(repo_path) : NULL; + file->commit_oid = commit_oid ? estrdup(commit_oid) : NULL; file->size_bytes = size_bytes; file->size_lines = size_lines; - file->content = content; + if (content && size_bytes >= 0) { + file->content = ecalloc(size_bytes + 1, sizeof(char)); + memcpy(file->content, content, size_bytes); + } else { + file->content = NULL; + } return file; } void gitfile_free(GitFile* file) { + if (!file) { + return; + } + free(file->mode); + free(file->display_path); + free(file->repo_path); + free(file->commit_oid); + free(file->content); free(file); } - -FileType gitfile_type(const GitFile* file) { - return file->type; -} - -const char* gitfile_mode(const GitFile* file) { - return file->mode; -} - -const char* gitfile_display_path(const GitFile* file) { - return file->display_path; -} - -const char* gitfile_repo_path(const GitFile* file) { - return file->repo_path; -} - -const char* gitfile_commit_oid(const GitFile* file) { - return file->commit_oid; -} - -ssize_t gitfile_size_bytes(const GitFile* file) { - return file->size_bytes; -} - -ssize_t gitfile_size_lines(const GitFile* file) { - return file->size_lines; -} - -const char* gitfile_content(const GitFile* file) { - return file->content; -} diff --git a/src/git/file.h b/src/git/file.h @@ -8,18 +8,16 @@ typedef enum { kFileTypeSubmodule, } FileType; -typedef struct GitFile GitFile; - -FileType gitfile_type(const GitFile* file); -const char* gitfile_mode(const GitFile* file); -const char* gitfile_display_path(const GitFile* file); -const char* gitfile_repo_path(const GitFile* file); -// Submodule commit OID. Empty string for files. -const char* gitfile_commit_oid(const GitFile* file); -ssize_t gitfile_size_bytes(const GitFile* file); - -// Returns file size in lines, or -1 if binary file, -2 if file too large. -ssize_t gitfile_size_lines(const GitFile* file); -const char* gitfile_content(const GitFile* file); +typedef struct GitFile { + FileType type; + char* mode; + char* display_path; + char* repo_path; + // Submodule commit OID. Empty string for files. + char* commit_oid; + ssize_t size_bytes; + ssize_t size_lines; + char* content; +} GitFile; #endif // GOUT_GIT_FILE_H_ diff --git a/src/git/reference.c b/src/git/reference.c @@ -12,12 +12,6 @@ #include "git/internal.h" #include "utils.h" -struct GitReference { - RefType type; - char* shorthand; - GitCommit* commit; -}; - GitReference* gitreference_create(git_repository* repo, git_reference* git_ref) { GitReference* ref = ecalloc(1, sizeof(GitReference)); @@ -71,18 +65,6 @@ void gitreference_free(GitReference* ref) { free(ref); } -RefType gitreference_type(const GitReference* r) { - return r->type; -} - -const char* gitreference_shorthand(const GitReference* r) { - return r->shorthand; -} - -GitCommit* gitreference_commit(const GitReference* r) { - return r->commit; -} - int gitreference_compare(const void* a, const void* b) { GitReference* r1 = *(GitReference**)a; GitReference* r2 = *(GitReference**)b; @@ -91,8 +73,8 @@ int gitreference_compare(const void* a, const void* b) { return r; } - time_t t1 = gitcommit_author_time(r1->commit); - time_t t2 = gitcommit_author_time(r2->commit); + time_t t1 = r1->commit->author_time; + time_t t2 = r2->commit->author_time; if (t1 > t2) { return -1; } diff --git a/src/git/reference.h b/src/git/reference.h @@ -9,10 +9,10 @@ typedef enum { } RefType; /* reference and associated data for sorting */ -typedef struct GitReference GitReference; - -RefType gitreference_type(const GitReference* ref); -const char* gitreference_shorthand(const GitReference* ref); -GitCommit* gitreference_commit(const GitReference* ref); +typedef struct GitReference { + RefType type; + char* shorthand; + GitCommit* commit; +} GitReference; #endif // GOUT_GIT_REFERENCE_H_ diff --git a/src/git/repo.c b/src/git/repo.c @@ -261,9 +261,10 @@ void gitrepo_load_metadata(GitRepo* repo, const char* path) { repo->owner = first_line_of_file(owner_path); repo->description = first_line_of_file(desc_path); repo->clone_url = first_line_of_file(url_path); - repo->submodules = - estrdup(gitrepo_has_blob(repo->repo, "HEAD:.gitmodules") ? ".gitmodules" : ""); - repo->readme = estrdup(gitrepo_first_matching_file(repo->repo, kReadmes, kReadmesLen)); + repo->submodules = estrdup( + gitrepo_has_blob(repo->repo, "HEAD:.gitmodules") ? ".gitmodules" : ""); + repo->readme = + estrdup(gitrepo_first_matching_file(repo->repo, kReadmes, kReadmesLen)); repo->license = estrdup(gitrepo_first_matching_file(repo->repo, kLicenses, kLicensesLen)); diff --git a/src/gout_tests_main.c b/src/gout_tests_main.c @@ -3,7 +3,7 @@ UTEST_STATE(); -int main(int argc, const char *const argv[]) { - setlocale(LC_ALL, "en_US.UTF-8"); +int main(int argc, const char* const argv[]) { + setlocale(LC_ALL, "en_US.UTF-8"); return utest_main(argc, argv); } diff --git a/src/utils_tests.c b/src/utils_tests.c @@ -71,31 +71,31 @@ UTEST(is_safe_mailto, RejectsInvalidCharacters) { } UTEST(relpath_from_dir, SingleDirectory) { - char* result = relpath_from_dir("folder"); - ASSERT_STREQ("../", result); - free(result); + char* result = relpath_from_dir("folder"); + ASSERT_STREQ("../", result); + free(result); } UTEST(relpath_from_dir, MultipleDirectories) { - char* result = relpath_from_dir("path/to/somewhere"); - ASSERT_STREQ("../../../", result); - free(result); + char* result = relpath_from_dir("path/to/somewhere"); + ASSERT_STREQ("../../../", result); + free(result); } UTEST(relpath_from_dir, CurrentDirectoryLiteral) { - char* result = relpath_from_dir("."); - ASSERT_STREQ("../", result); - free(result); + char* result = relpath_from_dir("."); + ASSERT_STREQ("../", result); + free(result); } UTEST(relpath_from_dir, TrailingSlash) { - char* result = relpath_from_dir("folder/"); - ASSERT_STREQ("../../", result); - free(result); + char* result = relpath_from_dir("folder/"); + ASSERT_STREQ("../../", result); + free(result); } UTEST(relpath_from_dir, RootPath) { - char* result = relpath_from_dir("/"); - ASSERT_STREQ("../../", result); - free(result); + char* result = relpath_from_dir("/"); + ASSERT_STREQ("../../", result); + free(result); } diff --git a/src/writer/atom/atom.c b/src/writer/atom/atom.c @@ -57,24 +57,24 @@ void atom_add_commit(Atom* atom, atom->remaining_commits--; fprintf(out, "<entry>\n"); - fprintf(out, "<id>%s</id>\n", gitcommit_oid(commit)); + fprintf(out, "<id>%s</id>\n", commit->oid); fprintf(out, "<published>"); - print_time_z(out, gitcommit_author_time(commit)); + print_time_z(out, commit->author_time); fprintf(out, "</published>\n"); fprintf(out, "<updated>"); - print_time_z(out, gitcommit_commit_time(commit)); + print_time_z(out, commit->commit_time); fprintf(out, "</updated>\n"); - if (gitcommit_summary(commit)) { + if (commit->summary) { fprintf(out, "<title>"); if (tag && tag[0] != '\0') { fputc('[', out); print_xml_encoded(out, tag); fputc(']', out); } - print_xml_encoded(out, gitcommit_summary(commit)); + print_xml_encoded(out, commit->summary); fprintf(out, "</title>\n"); } fprintf(out, "<link rel=\"alternate\" "); @@ -84,27 +84,26 @@ void atom_add_commit(Atom* atom, fprintf(out, "href=\"%s%s\" />\n", atom->baseurl, path); fprintf(out, "<author>\n<name>"); - print_xml_encoded(out, gitcommit_author_name(commit)); + print_xml_encoded(out, commit->author_name); fprintf(out, "</name>\n<email>"); - print_xml_encoded(out, gitcommit_author_email(commit)); + print_xml_encoded(out, commit->author_email); fprintf(out, "</email>\n</author>\n"); fprintf(out, "<content>"); - fprintf(out, "commit %s\n", gitcommit_oid(commit)); - const char* parentoid = gitcommit_parentoid(commit); + fprintf(out, "commit %s\n", commit->oid); + const char* parentoid = commit->parentoid; if (parentoid[0]) { fprintf(out, "parent %s\n", parentoid); } fprintf(out, "Author: "); - print_xml_encoded(out, gitcommit_author_name(commit)); + print_xml_encoded(out, commit->author_name); fprintf(out, " &lt;"); - print_xml_encoded(out, gitcommit_author_email(commit)); + print_xml_encoded(out, commit->author_email); fprintf(out, "&gt;\n"); fprintf(out, "Date: "); - print_time(out, gitcommit_author_time(commit), - gitcommit_author_timezone_offset(commit)); + print_time(out, commit->author_time, commit->author_timezone_offset); fprintf(out, "\n"); - const char* message = gitcommit_message(commit); + const char* message = commit->message; if (message) { fputc('\n', out); print_xml_encoded(out, message); diff --git a/src/writer/cache/cache.c b/src/writer/cache/cache.c @@ -87,12 +87,12 @@ bool cache_can_add_commits(const Cache* cache) { void cache_add_commit_row(Cache* cache, const GitCommit* commit) { // The first row of the file is the last OID. if (!cache->wrote_lastoid_out) { - fprintf(cache->cache_out, "%s\n", gitcommit_oid(commit)); + fprintf(cache->cache_out, "%s\n", commit->oid); cache->wrote_lastoid_out = true; } // If all commits are already written; do nothing. if (!cache->can_add_commits || - strncmp(gitcommit_oid(commit), cache->lastoid_in, kOidLen - 1) == 0) { + strncmp(commit->oid, cache->lastoid_in, kOidLen - 1) == 0) { cache->can_add_commits = false; return; } diff --git a/src/writer/gopher/commit.c b/src/writer/gopher/commit.c @@ -70,13 +70,13 @@ void gopher_commit_add_commit(GopherCommit* commit, gopher_commit_write_summary(commit, git_commit); - size_t deltas_len = gitcommit_delta_count(git_commit); + size_t deltas_len = git_commit->deltas_len; if (deltas_len == 0) { return; } - size_t addcount = gitcommit_addcount(git_commit); - size_t delcount = gitcommit_delcount(git_commit); - size_t filecount = gitcommit_filecount(git_commit); + size_t addcount = git_commit->addcount; + size_t delcount = git_commit->delcount; + size_t filecount = git_commit->filecount; if (filecount > kDiffMaxFiles || deltas_len > kDiffMaxDeltas || addcount > kDiffMaxDeltaLines || delcount > kDiffMaxDeltaLines) { fprintf(out, "Diff is too large, output suppressed.</pre>\n"); @@ -94,28 +94,27 @@ void gopher_commit_end(GopherCommit* commit) { void gopher_commit_write_summary(GopherCommit* commit, const GitCommit* git_commit) { FILE* out = commit->out; - const char* oid = gitcommit_oid(git_commit); + const char* oid = git_commit->oid; fprintf(out, "[1|commit %s|../commit/%s.gph|server|port]\n", oid, oid); - const char* parentoid = gitcommit_parentoid(git_commit); + const char* parentoid = git_commit->parentoid; if (parentoid[0] != '\0') { fprintf(out, "[1|parent %s|../commit/%s.gph|server|port]\n", parentoid, parentoid); } fprintf(out, "[h|Author: "); - print_gopher_link(commit->out, gitcommit_author_name(git_commit)); + print_gopher_link(commit->out, git_commit->author_name); fprintf(out, " <"); - print_gopher_link(commit->out, gitcommit_author_email(git_commit)); + print_gopher_link(commit->out, git_commit->author_email); fprintf(out, ">|URL:mailto:"); - print_gopher_link(commit->out, gitcommit_author_email(git_commit)); + print_gopher_link(commit->out, git_commit->author_email); fprintf(out, "|server|port]\n"); fprintf(out, "Date: "); - print_time(out, gitcommit_author_time(git_commit), - gitcommit_author_timezone_offset(git_commit)); + print_time(out, git_commit->author_time, git_commit->author_timezone_offset); fprintf(out, "\n"); - const char* message = gitcommit_message(git_commit); + const char* message = git_commit->message; if (message) { fprintf(out, "\n"); print_gopher_text(out, message, true); @@ -126,9 +125,9 @@ void gopher_commit_write_summary(GopherCommit* commit, void gopher_commit_write_diffstat(GopherCommit* commit, const GitCommit* git_commit) { fprintf(commit->out, "Diffstat:\n"); - size_t delta_count = gitcommit_delta_count(git_commit); + size_t delta_count = git_commit->deltas_len; for (size_t i = 0; i < delta_count; i++) { - gopher_commit_write_diffstat_row(commit, gitcommit_delta(git_commit, i)); + gopher_commit_write_diffstat_row(commit, git_commit->deltas[i]); } } @@ -137,10 +136,10 @@ void gopher_commit_write_diffstat_row(GopherCommit* commit, static const size_t kGraphWidth = 30; FILE* out = commit->out; - fprintf(out, " %c ", gitdelta_status(delta)); + fprintf(out, " %c ", delta->status); char filename[PATH_MAX]; - const char* old_file_path = gitdelta_old_file_path(delta); - const char* new_file_path = gitdelta_new_file_path(delta); + const char* old_file_path = delta->old_file_path; + const char* new_file_path = delta->new_file_path; if (strcmp(old_file_path, new_file_path) == 0) { snprintf(filename, sizeof(filename), "%s", old_file_path); } else { @@ -149,7 +148,7 @@ void gopher_commit_write_diffstat_row(GopherCommit* commit, } print_gopher_link_padded(out, filename, 35, ' '); - size_t changed = gitdelta_lines_added(delta) + gitdelta_lines_deleted(delta); + size_t changed = delta->addcount + delta->delcount; fprintf(out, " | "); fprintf(out, "%7zu ", changed); char* added_graph = gitdelta_added_graph(delta, kGraphWidth); @@ -164,18 +163,18 @@ void gopher_commit_write_diffstat_row(GopherCommit* commit, void gopher_commit_write_diff_content(GopherCommit* commit, const GitCommit* git_commit) { FILE* out = commit->out; - size_t addcount = gitcommit_addcount(git_commit); - size_t delcount = gitcommit_delcount(git_commit); - size_t filecount = gitcommit_filecount(git_commit); + size_t addcount = git_commit->addcount; + size_t delcount = git_commit->delcount; + size_t filecount = git_commit->filecount; fprintf(out, "\n%zu file%s changed, %zu insertion%s(+), %zu deletion%s(-)\n", filecount, filecount == 1 ? "" : "s", // addcount, addcount == 1 ? "" : "s", // delcount, delcount == 1 ? "" : "s"); fprintf(commit->out, "---\n"); - size_t delta_count = gitcommit_delta_count(git_commit); + size_t delta_count = git_commit->deltas_len; for (size_t i = 0; i < delta_count; i++) { - gopher_commit_write_diff_delta(commit, gitcommit_delta(git_commit, i)); + gopher_commit_write_diff_delta(commit, git_commit->deltas[i]); } } @@ -183,19 +182,19 @@ void gopher_commit_write_diff_delta(GopherCommit* commit, const GitDelta* delta) { FILE* out = commit->out; fprintf(out, "[1|diff --git a/"); - print_gopher_link(out, gitdelta_old_file_path(delta)); + print_gopher_link(out, delta->old_file_path); fprintf(out, " b/"); - print_gopher_link(out, gitdelta_new_file_path(delta)); + print_gopher_link(out, delta->new_file_path); fprintf(out, "|../file/"); - print_gopher_link(out, gitdelta_new_file_path(delta)); + print_gopher_link(out, delta->new_file_path); fprintf(out, ".gph|server|port]\n"); - if (gitdelta_is_binary(delta)) { + if (delta->is_binary) { fprintf(out, "Binary files differ.\n"); } else { - size_t hunk_count = gitdelta_hunk_count(delta); + size_t hunk_count = delta->hunks_len; for (size_t i = 0; i < hunk_count; i++) { - gopher_commit_write_diff_hunk(commit, gitdelta_hunk(delta, i)); + gopher_commit_write_diff_hunk(commit, delta->hunks[i]); } } } @@ -204,19 +203,19 @@ void gopher_commit_write_diff_hunk(GopherCommit* commit, const GitHunk* hunk) { FILE* out = commit->out; // Output header. e.g. @@ -0,0 +1,3 @@ - const char* header = githunk_header(hunk); + const char* header = hunk->header; print_gopher_text(out, header, false); fprintf(out, "\n"); // Iterate over lines in hunk. - size_t line_count = githunk_line_count(hunk); + size_t line_count = hunk->lines_len; for (size_t i = 0; i < line_count; i++) { - const GitHunkLine* line = githunk_line(hunk, i); + const GitHunkLine* line = hunk->lines[i]; - const char* content = githunkline_content(line); - size_t content_len = githunkline_content_len(line); - int old_lineno = githunkline_old_lineno(line); - int new_lineno = githunkline_new_lineno(line); + const char* content = line->content; + size_t content_len = line->content_len; + int old_lineno = line->old_lineno; + int new_lineno = line->new_lineno; if (old_lineno == -1) { // Added line. Prefix with +. fprintf(out, "+"); diff --git a/src/writer/gopher/fileblob.c b/src/writer/gopher/fileblob.c @@ -77,16 +77,16 @@ void gopher_fileblob_add_file(GopherFileBlob* blob, const GitFile* file) { FILE* out = blob->out; char path[PATH_MAX]; - estrlcpy(path, gitfile_repo_path(file), sizeof(path)); + estrlcpy(path, file->repo_path, sizeof(path)); const char* filename = basename(path); if (!filename) { err(1, "basename"); } print_gopher_text(out, filename, false); - fprintf(out, " (%zdB)\n", gitfile_size_bytes(file)); + fprintf(out, " (%zdB)\n", file->size_bytes); fprintf(out, "---\n"); - ssize_t size_lines = gitfile_size_lines(file); + ssize_t size_lines = file->size_lines; if (size_lines == -1) { fprintf(out, "Binary file.\n"); return; @@ -97,8 +97,8 @@ void gopher_fileblob_add_file(GopherFileBlob* blob, const GitFile* file) { } size_t i = 0; - const char* content = gitfile_content(file); - const char* end = content + gitfile_size_bytes(file); + const char* content = file->content; + const char* end = content + file->size_bytes; const char* cur_line = content; while (cur_line < end) { const char* next_line = memchr(cur_line, '\n', end - cur_line); diff --git a/src/writer/gopher/files.c b/src/writer/gopher/files.c @@ -43,20 +43,20 @@ void gopher_files_begin(GopherFiles* files) { void gopher_files_add_file(GopherFiles* files, const GitFile* file) { FILE* out = files->out; - fprintf(out, "[1|%s", gitfile_mode(file)); + fprintf(out, "[1|%s", file->mode); fprintf(out, " "); - print_gopher_link_padded(out, gitfile_display_path(file), 50, ' '); + print_gopher_link_padded(out, file->display_path, 50, ' '); fprintf(out, " "); - ssize_t size_lines = gitfile_size_lines(file); - ssize_t size_bytes = gitfile_size_lines(file); + ssize_t size_lines = file->size_lines; + ssize_t size_bytes = file->size_bytes; if (size_lines >= 0) { fprintf(out, "%7zdL", size_lines); } else if (size_bytes >= 0) { fprintf(out, "%7zdB", size_bytes); } fprintf(out, "|file/"); - print_gopher_link(out, gitfile_repo_path(file)); + print_gopher_link(out, file->repo_path); fprintf(out, ".gph|server|port]\n"); } diff --git a/src/writer/gopher/log.c b/src/writer/gopher/log.c @@ -90,13 +90,13 @@ void gopher_log_end(GopherLog* log) { void write_commit_row(FILE* out, const GitCommit* commit) { fprintf(out, "[1|"); - print_time_short(out, gitcommit_author_time(commit)); + print_time_short(out, commit->author_time); fprintf(out, " "); - const char* summary = gitcommit_summary(commit); + const char* summary = commit->summary; if (summary) { print_gopher_link_padded(out, summary, 40, ' '); fprintf(out, " "); } - print_gopher_link(out, gitcommit_author_name(commit)); - fprintf(out, "|commit/%s.gph|server|port]\n", gitcommit_oid(commit)); + print_gopher_link(out, commit->author_name); + fprintf(out, "|commit/%s.gph|server|port]\n", commit->oid); } diff --git a/src/writer/gopher/refs.c b/src/writer/gopher/refs.c @@ -61,15 +61,15 @@ void gopher_refstable_begin(GopherRefsTable* table) { } void gopher_refstable_add_ref(GopherRefsTable* table, const GitReference* ref) { - GitCommit* commit = gitreference_commit(ref); + GitCommit* commit = ref->commit; FILE* out = table->out; fprintf(out, " "); - print_gopher_link_padded(out, gitreference_shorthand(ref), 32, ' '); + print_gopher_link_padded(out, ref->shorthand, 32, ' '); fprintf(out, " "); - print_time_short(out, gitcommit_author_time(commit)); + print_time_short(out, commit->author_time); fprintf(out, " "); - print_gopher_link_padded(out, gitcommit_author_name(commit), 25, '\0'); + print_gopher_link_padded(out, commit->author_name, 25, '\0'); fprintf(out, "\n"); } @@ -106,7 +106,7 @@ void gopher_refs_begin(GopherRefs* refs) { } void gopher_refs_add_ref(GopherRefs* refs, const GitReference* ref) { - switch (gitreference_type(ref)) { + switch (ref->type) { case kReftypeBranch: if (!refs->branches) { refs->branches = diff --git a/src/writer/gopher/repo_index.c b/src/writer/gopher/repo_index.c @@ -35,7 +35,7 @@ void gopher_repoindex_begin(GopherRepoIndex* index) { static void print_author_time(const GitCommit* commit, void* user_data) { FILE* out = (FILE*)user_data; - print_time_short(out, gitcommit_author_time(commit)); + print_time_short(out, commit->author_time); } void gopher_repoindex_add_repo(GopherRepoIndex* index, GitRepo* repo) { diff --git a/src/writer/gopher/repo_writer.c b/src/writer/gopher/repo_writer.c @@ -56,7 +56,7 @@ void gopher_repowriter_free(GopherRepoWriter* writer) { } void gopher_repowriter_set_log_cachefile(GopherRepoWriter* writer, - const char* cachefile) { + const char* cachefile) { gopher_log_set_cachefile(writer->log, cachefile); } @@ -85,8 +85,7 @@ void gopher_repowriter_begin(GopherRepoWriter* writer) { void gopher_repowriter_add_commit(GopherRepoWriter* writer, const GitCommit* git_commit) { char filename[PATH_MAX]; - if (snprintf(filename, sizeof(filename), "%s.gph", - gitcommit_oid(git_commit)) < 0) { + if (snprintf(filename, sizeof(filename), "%s.gph", git_commit->oid) < 0) { err(1, "snprintf"); } char* path = path_concat("commit", filename); @@ -95,9 +94,8 @@ void gopher_repowriter_add_commit(GopherRepoWriter* writer, if (gopher_log_can_add_commits(writer->log)) { gopher_log_add_commit(writer->log, git_commit); - GopherCommit* commit = - gopher_commit_create(writer->repo, gitcommit_oid(git_commit), - gitcommit_summary(git_commit)); + GopherCommit* commit = gopher_commit_create(writer->repo, git_commit->oid, + git_commit->summary); gopher_commit_begin(commit); gopher_commit_add_commit(commit, git_commit); gopher_commit_end(commit); @@ -108,16 +106,14 @@ void gopher_repowriter_add_commit(GopherRepoWriter* writer, void gopher_repowriter_add_reference(GopherRepoWriter* writer, const GitReference* ref) { gopher_refs_add_ref(writer->refs, ref); - if (gitreference_type(ref) == kReftypeTag) { - GitCommit* commit = gitreference_commit(ref); + if (ref->type == kReftypeTag) { + GitCommit* commit = ref->commit; char filename[PATH_MAX]; - if (snprintf(filename, sizeof(filename), "%s.gph", gitcommit_oid(commit)) < - 0) { + if (snprintf(filename, sizeof(filename), "%s.gph", commit->oid) < 0) { err(1, "snprintf"); } char* path = path_concat("commit", filename); - atom_add_commit(writer->tags, commit, path, "", - gitreference_shorthand(ref)); + atom_add_commit(writer->tags, commit, path, "", ref->shorthand); free(path); } } @@ -125,8 +121,7 @@ void gopher_repowriter_add_reference(GopherRepoWriter* writer, void gopher_repowriter_add_file(GopherRepoWriter* writer, const GitFile* file) { gopher_files_add_file(writer->files, file); - GopherFileBlob* blob = - gopher_fileblob_create(writer->repo, gitfile_repo_path(file)); + GopherFileBlob* blob = gopher_fileblob_create(writer->repo, file->repo_path); gopher_fileblob_begin(blob); gopher_fileblob_add_file(blob, file); gopher_fileblob_end(blob); diff --git a/src/writer/html/commit.c b/src/writer/html/commit.c @@ -72,13 +72,13 @@ void html_commit_add_commit(HtmlCommit* commit, const GitCommit* git_commit) { html_commit_write_summary(commit, git_commit); - size_t deltas_len = gitcommit_delta_count(git_commit); + size_t deltas_len = git_commit->deltas_len; if (deltas_len == 0) { return; } - size_t addcount = gitcommit_addcount(git_commit); - size_t delcount = gitcommit_delcount(git_commit); - size_t filecount = gitcommit_filecount(git_commit); + size_t addcount = git_commit->addcount; + size_t delcount = git_commit->delcount; + size_t filecount = git_commit->filecount; if (filecount > kDiffMaxFiles || deltas_len > kDiffMaxDeltas || addcount > kDiffMaxDeltaLines || delcount > kDiffMaxDeltaLines) { fprintf(out, "<pre>Diff is too large, output suppressed.</pre>\n"); @@ -96,11 +96,11 @@ void html_commit_end(HtmlCommit* commit) { void html_commit_write_summary(HtmlCommit* commit, const GitCommit* git_commit) { FILE* out = commit->out; - const char* oid = gitcommit_oid(git_commit); + const char* oid = git_commit->oid; fprintf(out, "<pre><b>commit</b> "); fprintf(out, "<a href=\"../commit/%s.html\">%s</a>\n", oid, oid); - const char* parentoid = gitcommit_parentoid(git_commit); + const char* parentoid = git_commit->parentoid; if (parentoid[0] != '\0') { fprintf(out, "<b>parent</b> "); fprintf(out, "<a href=\"../commit/%s.html\">%s</a>\n", parentoid, @@ -108,8 +108,8 @@ void html_commit_write_summary(HtmlCommit* commit, } fprintf(out, "<b>Author:</b> "); - print_xml_encoded(out, gitcommit_author_name(git_commit)); - const char* email = gitcommit_author_email(git_commit); + print_xml_encoded(out, git_commit->author_name); + const char* email = git_commit->author_email; if (is_safe_mailto(email)) { fprintf(out, " &lt;<a href=\"mailto:"); print_xml_encoded(out, email); @@ -122,11 +122,10 @@ void html_commit_write_summary(HtmlCommit* commit, fprintf(out, "&gt;\n"); } fprintf(out, "<b>Date:</b> "); - print_time(out, gitcommit_author_time(git_commit), - gitcommit_author_timezone_offset(git_commit)); + print_time(out, git_commit->author_time, git_commit->author_timezone_offset); fprintf(out, "\n"); - const char* message = gitcommit_message(git_commit); + const char* message = git_commit->message; if (message) { fprintf(out, "\n"); print_xml_encoded(out, message); @@ -137,9 +136,9 @@ void html_commit_write_summary(HtmlCommit* commit, void html_commit_write_diffstat(HtmlCommit* commit, const GitCommit* git_commit) { fprintf(commit->out, "<b>Diffstat:</b>\n<table>"); - size_t delta_count = gitcommit_delta_count(git_commit); + size_t delta_count = git_commit->deltas_len; for (size_t i = 0; i < delta_count; i++) { - html_commit_write_diffstat_row(commit, i, gitcommit_delta(git_commit, i)); + html_commit_write_diffstat_row(commit, i, git_commit->deltas[i]); } fprintf(commit->out, "</table></pre>"); } @@ -150,7 +149,7 @@ void html_commit_write_diffstat_row(HtmlCommit* commit, static const size_t kGraphWidth = 78; FILE* out = commit->out; - char status = gitdelta_status(delta); + char status = delta->status; if (status == ' ') { fprintf(out, "<tr><td>"); } else { @@ -159,8 +158,8 @@ void html_commit_write_diffstat_row(HtmlCommit* commit, fprintf(out, "</td>"); fprintf(out, "<td>"); fprintf(out, "<a href=\"#h%zu\">", row); - const char* old_file_path = gitdelta_old_file_path(delta); - const char* new_file_path = gitdelta_new_file_path(delta); + const char* old_file_path = delta->old_file_path; + const char* new_file_path = delta->new_file_path; print_xml_encoded(out, old_file_path); if (strcmp(old_file_path, new_file_path) != 0) { fprintf(out, " -&gt; "); @@ -168,7 +167,7 @@ void html_commit_write_diffstat_row(HtmlCommit* commit, } fprintf(out, "</a></td>"); - size_t changed = gitdelta_lines_added(delta) + gitdelta_lines_deleted(delta); + size_t changed = delta->addcount + delta->delcount; fprintf(out, "<td> | </td>"); fprintf(out, "<td class=\"num\">%zu</td>", changed); char* added_graph = gitdelta_added_graph(delta, kGraphWidth); @@ -183,9 +182,9 @@ void html_commit_write_diffstat_row(HtmlCommit* commit, void html_commit_write_diff_content(HtmlCommit* commit, const GitCommit* git_commit) { FILE* out = commit->out; - size_t filecount = gitcommit_filecount(git_commit); - size_t addcount = gitcommit_addcount(git_commit); - size_t delcount = gitcommit_delcount(git_commit); + size_t filecount = git_commit->filecount; + size_t addcount = git_commit->addcount; + size_t delcount = git_commit->delcount; fprintf(out, "<pre>"); fprintf(out, "%zu file%s changed, %zu insertion%s(+), %zu deletion%s(-)\n", filecount, filecount == 1 ? "" : "s", // @@ -193,9 +192,9 @@ void html_commit_write_diff_content(HtmlCommit* commit, delcount, delcount == 1 ? "" : "s"); fprintf(out, "<hr/>"); - size_t delta_count = gitcommit_delta_count(git_commit); + size_t delta_count = git_commit->deltas_len; for (size_t i = 0; i < delta_count; i++) { - html_commit_write_diff_delta(commit, i, gitcommit_delta(git_commit, i)); + html_commit_write_diff_delta(commit, i, git_commit->deltas[i]); } fprintf(out, "</pre>\n"); } @@ -203,8 +202,8 @@ void html_commit_write_diff_content(HtmlCommit* commit, void html_commit_write_diff_delta(HtmlCommit* commit, size_t file_num, const GitDelta* delta) { - const char* old_file_path = gitdelta_old_file_path(delta); - const char* new_file_path = gitdelta_new_file_path(delta); + const char* old_file_path = delta->old_file_path; + const char* new_file_path = delta->new_file_path; fprintf(commit->out, "<b>diff --git "); fprintf(commit->out, "a/<a id=\"h%zu\" href=\"../file/", file_num); print_percent_encoded(commit->out, old_file_path); @@ -216,12 +215,12 @@ void html_commit_write_diff_delta(HtmlCommit* commit, print_xml_encoded(commit->out, new_file_path); fprintf(commit->out, "</a></b>\n"); - if (gitdelta_is_binary(delta)) { + if (delta->is_binary) { fprintf(commit->out, "Binary files differ.\n"); } else { - size_t hunk_count = gitdelta_hunk_count(delta); + size_t hunk_count = delta->hunks_len; for (size_t i = 0; i < hunk_count; i++) { - html_commit_write_diff_hunk(commit, file_num, gitdelta_hunk(delta, i)); + html_commit_write_diff_hunk(commit, file_num, delta->hunks[i]); } } } @@ -233,28 +232,28 @@ void html_commit_write_diff_hunk(HtmlCommit* commit, // Output header. e.g. @@ -0,0 +1,3 @@ char hdr_id[32]; - size_t hunkid = githunk_id(hunk); + size_t hunkid = hunk->id; if (snprintf(hdr_id, sizeof(hdr_id), "h%zu-%zu", file_num, hunkid) < 0) { err(1, "snprintf"); } fprintf(out, "<a href=\"#%s\" id=\"%s\" class=\"h\">", hdr_id, hdr_id); - const char* header = githunk_header(hunk); + const char* header = hunk->header; print_xml_encoded(out, header); fprintf(out, "</a>"); // Iterate over lines in hunk. - size_t line_count = githunk_line_count(hunk); + size_t line_count = hunk->lines_len; for (size_t i = 0; i < line_count; i++) { - const GitHunkLine* line = githunk_line(hunk, i); - size_t hunklineid = githunkline_id(line); + const GitHunkLine* line = hunk->lines[i]; + size_t hunklineid = line->id; char line_id[64]; if (snprintf(line_id, sizeof(line_id), "%s-%zu", hdr_id, hunklineid) < 0) { err(1, "snprintf"); } - const char* content = githunkline_content(line); - size_t content_len = githunkline_content_len(line); - int old_lineno = githunkline_old_lineno(line); - int new_lineno = githunkline_new_lineno(line); + const char* content = line->content; + size_t content_len = line->content_len; + int old_lineno = line->old_lineno; + int new_lineno = line->new_lineno; if (old_lineno == -1) { // Added line. Prefix with +. fprintf(out, "<a href=\"#%s\" id=\"%s\" class=\"i\">+", line_id, line_id); diff --git a/src/writer/html/fileblob.c b/src/writer/html/fileblob.c @@ -78,16 +78,16 @@ void html_fileblob_add_file(HtmlFileBlob* blob, const GitFile* file) { fprintf(out, "<p> "); char path[PATH_MAX]; - estrlcpy(path, gitfile_repo_path(file), sizeof(path)); + estrlcpy(path, file->repo_path, sizeof(path)); const char* filename = basename(path); if (!filename) { err(1, "basename"); } print_xml_encoded(out, filename); - fprintf(out, " (%zdB)", gitfile_size_bytes(file)); + fprintf(out, " (%zdB)", file->size_bytes); fprintf(out, "</p><hr/>"); - ssize_t size_lines = gitfile_size_lines(file); + ssize_t size_lines = file->size_lines; if (size_lines == -1) { fprintf(out, "<p>Binary file.</p>\n"); return; @@ -100,8 +100,8 @@ void html_fileblob_add_file(HtmlFileBlob* blob, const GitFile* file) { fprintf(out, "<pre id=\"blob\">\n"); size_t i = 0; - const char* content = gitfile_content(file); - const char* end = content + gitfile_size_bytes(file); + const char* content = file->content; + const char* end = content + file->size_bytes; const char* cur_line = content; while (cur_line < end) { const char* next_line = memchr(cur_line, '\n', end - cur_line); diff --git a/src/writer/html/files.c b/src/writer/html/files.c @@ -48,20 +48,20 @@ void html_files_begin(HtmlFiles* files) { void html_files_add_file(HtmlFiles* files, const GitFile* file) { FILE* out = files->out; - fprintf(out, "<tr><td>%s</td>", gitfile_mode(file)); + fprintf(out, "<tr><td>%s</td>", file->mode); fprintf(out, "<td><a href=\"file/"); - print_percent_encoded(out, gitfile_repo_path(file)); + print_percent_encoded(out, file->repo_path); fprintf(out, ".html\">"); - print_xml_encoded(out, gitfile_display_path(file)); + print_xml_encoded(out, file->display_path); fprintf(out, "</a>"); - const char* oid = gitfile_commit_oid(file); + const char* oid = file->commit_oid; if (oid[0] != '\0') { fprintf(out, " @ %s", oid); } fprintf(out, "</td><td class=\"num\" align=\"right\">"); - ssize_t size_lines = gitfile_size_lines(file); - ssize_t size_bytes = gitfile_size_lines(file); + ssize_t size_lines = file->size_lines; + ssize_t size_bytes = file->size_bytes; if (size_lines >= 0) { fprintf(out, "%zdL", size_lines); } else if (size_bytes >= 0) { diff --git a/src/writer/html/log.c b/src/writer/html/log.c @@ -97,21 +97,20 @@ void html_log_end(HtmlLog* log) { void write_commit_row(FILE* out, const GitCommit* commit) { fprintf(out, "<tr><td>"); - print_time_short(out, gitcommit_author_time(commit)); + print_time_short(out, commit->author_time); fprintf(out, "</td><td>"); - const char* summary = gitcommit_summary(commit); + const char* summary = commit->summary; if (summary) { - fprintf(out, "<a href=\"commit/%s.html\">", gitcommit_oid(commit)); + fprintf(out, "<a href=\"commit/%s.html\">", commit->oid); print_xml_encoded(out, summary); fprintf(out, "</a>"); } fprintf(out, "</td><td>"); - print_xml_encoded(out, gitcommit_author_name(commit)); + print_xml_encoded(out, commit->author_name); fprintf(out, "</td>" "<td class=\"num\" align=\"right\">%zu</td>" "<td class=\"num\" align=\"right\">+%zu</td>" "<td class=\"num\" align=\"right\">-%zu</td></tr>\n", - gitcommit_filecount(commit), gitcommit_addcount(commit), - gitcommit_delcount(commit)); + commit->filecount, commit->addcount, commit->delcount); } diff --git a/src/writer/html/refs.c b/src/writer/html/refs.c @@ -66,13 +66,13 @@ void html_refstable_begin(HtmlRefsTable* table) { } void html_refstable_add_ref(HtmlRefsTable* table, const GitReference* ref) { - GitCommit* commit = gitreference_commit(ref); + GitCommit* commit = ref->commit; fprintf(table->out, "<tr><td>"); - print_xml_encoded(table->out, gitreference_shorthand(ref)); + print_xml_encoded(table->out, ref->shorthand); fprintf(table->out, "</td><td>"); - print_time_short(table->out, gitcommit_author_time(commit)); + print_time_short(table->out, commit->author_time); fprintf(table->out, "</td><td>"); - print_xml_encoded(table->out, gitcommit_author_name(commit)); + print_xml_encoded(table->out, commit->author_name); fprintf(table->out, "</td></tr>\n"); } @@ -108,7 +108,7 @@ void html_refs_begin(HtmlRefs* refs) { } void html_refs_add_ref(HtmlRefs* refs, const GitReference* ref) { - switch (gitreference_type(ref)) { + switch (ref->type) { case kReftypeBranch: if (!refs->branches) { refs->branches = diff --git a/src/writer/html/repo_index.c b/src/writer/html/repo_index.c @@ -66,7 +66,7 @@ void html_repoindex_begin(HtmlRepoIndex* index) { static void print_author_time(const GitCommit* commit, void* user_data) { FILE* out = (FILE*)user_data; - print_time_short(out, gitcommit_author_time(commit)); + print_time_short(out, commit->author_time); } void html_repoindex_add_repo(HtmlRepoIndex* index, GitRepo* repo) { diff --git a/src/writer/html/repo_writer.c b/src/writer/html/repo_writer.c @@ -56,7 +56,7 @@ void html_repowriter_free(HtmlRepoWriter* writer) { } void html_repowriter_set_log_cachefile(HtmlRepoWriter* writer, - const char* cachefile) { + const char* cachefile) { html_log_set_cachefile(writer->log, cachefile); } @@ -84,8 +84,7 @@ void html_repowriter_begin(HtmlRepoWriter* writer) { void html_repowriter_add_commit(HtmlRepoWriter* writer, const GitCommit* git_commit) { char filename[PATH_MAX]; - if (snprintf(filename, sizeof(filename), "%s.html", - gitcommit_oid(git_commit)) < 0) { + if (snprintf(filename, sizeof(filename), "%s.html", git_commit->oid) < 0) { err(1, "snprintf"); } char* path = path_concat("commit", filename); @@ -95,8 +94,7 @@ void html_repowriter_add_commit(HtmlRepoWriter* writer, if (html_log_can_add_commits(writer->log)) { html_log_add_commit(writer->log, git_commit); HtmlCommit* commit = - html_commit_create(writer->repo, gitcommit_oid(git_commit), - gitcommit_summary(git_commit)); + html_commit_create(writer->repo, git_commit->oid, git_commit->summary); html_commit_begin(commit); html_commit_add_commit(commit, git_commit); html_commit_end(commit); @@ -107,16 +105,14 @@ void html_repowriter_add_commit(HtmlRepoWriter* writer, void html_repowriter_add_reference(HtmlRepoWriter* writer, const GitReference* ref) { html_refs_add_ref(writer->refs, ref); - if (gitreference_type(ref) == kReftypeTag) { - GitCommit* commit = gitreference_commit(ref); + if (ref->type == kReftypeTag) { + GitCommit* commit = ref->commit; char filename[PATH_MAX]; - if (snprintf(filename, sizeof(filename), "%s.html", gitcommit_oid(commit)) < - 0) { + if (snprintf(filename, sizeof(filename), "%s.html", commit->oid) < 0) { err(1, "snprintf"); } char* path = path_concat("commit", filename); - atom_add_commit(writer->tags, commit, path, "text/html", - gitreference_shorthand(ref)); + atom_add_commit(writer->tags, commit, path, "text/html", ref->shorthand); free(path); } } @@ -124,8 +120,7 @@ void html_repowriter_add_reference(HtmlRepoWriter* writer, void html_repowriter_add_file(HtmlRepoWriter* writer, const GitFile* file) { html_files_add_file(writer->files, file); - HtmlFileBlob* blob = - html_fileblob_create(writer->repo, gitfile_repo_path(file)); + HtmlFileBlob* blob = html_fileblob_create(writer->repo, file->repo_path); html_fileblob_begin(blob); html_fileblob_add_file(blob, file); html_fileblob_end(blob); diff --git a/src/writer/repo_writer.c b/src/writer/repo_writer.c @@ -111,8 +111,7 @@ RepoWriter* htmlrepowriter_create(GitRepo* repo) { writer->set_baseurl = (RepoWriterSetBaseurl)html_repowriter_set_baseurl; writer->begin = (RepoWriterBegin)html_repowriter_begin; writer->add_commit = (RepoWriterAddCommit)html_repowriter_add_commit; - writer->add_reference = - (RepoWriterAddReference)html_repowriter_add_reference; + writer->add_reference = (RepoWriterAddReference)html_repowriter_add_reference; writer->add_file = (RepoWriterAddFile)html_repowriter_add_file; writer->end = (RepoWriterEnd)html_repowriter_end; return writer;