gitout

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

commit 9a1bf02a56b01af4f333d219e1229d15274aa7b1
parent 48d5bb36bf1cb0c2d9dee760272d99402362f4ba
Author: Chris Bracken <chris@bracken.jp>
Date:   Fri, 10 May 2024 14:54:57 -0700

Make git/*.h types opaque structures

Many of these contain private data pointers to libgit2 types such as
git_diff, git_patch, etc. Previously we were storing these as void* to
avoid including libgit2 headers; instead we move these into the
implementation files and provide accessor functions.

This also renames identifiers across the board for more consistency.

Diffstat:
Mgit/commit.c | 186+++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------
Mgit/commit.h | 70+++++++++++++++++++++++++++++++++++++++++++++++++---------------------
Mgit/delta.c | 225+++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------
Mgit/delta.h | 59++++++++++++++++++++++++++++-------------------------------
Mgit/file.c | 88+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------
Mgit/file.h | 22+++++++++++-----------
Mgit/internal.h | 32++++++++++++++++----------------
Mgit/reference.c | 85+++++++++++++++++++++++++++++++++++++++++++++++++------------------------------
Mgit/reference.h | 11++++-------
Mgit/repo.c | 259++++++++++++++++++++++++++++++++++++++++++++++---------------------------------
Mgit/repo.h | 65+++++++++++++++++++++++++++++------------------------------------
Mgitout.c | 26+++++++++++++-------------
Mgitout_index.c | 6+++---
Mwriter/atom/atom.c | 92+++++++++++++++++++++++++++++++++++++++++--------------------------------------
Mwriter/atom/atom.h | 4++--
Mwriter/cache/cache.c | 8++++----
Mwriter/cache/cache.h | 6+++---
Mwriter/gopher/commit.c | 161++++++++++++++++++++++++++++++++++++++++++++++---------------------------------
Mwriter/gopher/commit.h | 5+++--
Mwriter/gopher/fileblob.c | 14+++++++-------
Mwriter/gopher/fileblob.h | 4++--
Mwriter/gopher/files.c | 24++++++++++++++----------
Mwriter/gopher/files.h | 4++--
Mwriter/gopher/index_writer.c | 16++++++++--------
Mwriter/gopher/index_writer.h | 2+-
Mwriter/gopher/log.c | 25+++++++++++++------------
Mwriter/gopher/log.h | 4++--
Mwriter/gopher/page.c | 36+++++++++++++++++++++---------------
Mwriter/gopher/page.h | 2+-
Mwriter/gopher/refs.c | 24++++++++++++------------
Mwriter/gopher/refs.h | 4++--
Mwriter/gopher/repo_index.c | 14+++++++-------
Mwriter/gopher/repo_index.h | 2+-
Mwriter/gopher/repo_writer.c | 111+++++++++++++++++++++++++++++++++++++++++--------------------------------------
Mwriter/gopher/repo_writer.h | 8++++----
Mwriter/html/commit.c | 226++++++++++++++++++++++++++++++++++++++++++++++---------------------------------
Mwriter/html/commit.h | 14++++++++------
Mwriter/html/fileblob.c | 14+++++++-------
Mwriter/html/fileblob.h | 4++--
Mwriter/html/files.c | 41++++++++++++++++++++++++-----------------
Mwriter/html/files.h | 4++--
Mwriter/html/index_writer.c | 18+++++++++---------
Mwriter/html/index_writer.h | 2+-
Mwriter/html/log.c | 28+++++++++++++++-------------
Mwriter/html/log.h | 4++--
Mwriter/html/page.c | 44+++++++++++++++++++++++++-------------------
Mwriter/html/page.h | 2+-
Mwriter/html/refs.c | 24++++++++++++------------
Mwriter/html/refs.h | 4++--
Mwriter/html/repo_index.c | 16++++++++--------
Mwriter/html/repo_index.h | 2+-
Mwriter/html/repo_writer.c | 121+++++++++++++++++++++++++++++++++++++++++--------------------------------------
Mwriter/html/repo_writer.h | 8++++----
Mwriter/index_writer.c | 6+++---
Mwriter/index_writer.h | 2+-
Mwriter/repo_writer.c | 36++++++++++++++++++------------------
Mwriter/repo_writer.h | 10+++++-----
57 files changed, 1375 insertions(+), 959 deletions(-)

diff --git a/git/commit.c b/git/commit.c @@ -1,5 +1,6 @@ #include "git/commit.h" +#include <assert.h> #include <err.h> #include <git2/commit.h> #include <git2/diff.h> @@ -12,44 +13,66 @@ #include "git/internal.h" #include "utils.h" -CommitInfo* commitinfo_create(const git_oid* oid, git_repository* repo) { - CommitInfo* ci = ecalloc(1, sizeof(CommitInfo)); - if (git_commit_lookup((git_commit**)&ci->commit_, repo, oid)) { +struct GitCommit { + char* oid; + char* parentoid; + const char* summary; + const char* message; + time_t commit_time; + int commit_timezone_offset; + const char* author_name; + const 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; + + git_commit* commit; + git_diff* diff; +}; + +GitCommit* gitcommit_create(const git_oid* oid, git_repository* repo) { + GitCommit* commit = ecalloc(1, sizeof(GitCommit)); + if (git_commit_lookup(&commit->commit, repo, oid)) { errx(1, "git_commit_lookup"); } // Get OID, parent OID. - ci->oid = ecalloc(GIT_OID_SHA1_HEXSIZE + 1, sizeof(char)); - git_oid_tostr(ci->oid, GIT_OID_SHA1_HEXSIZE + 1, git_commit_id(ci->commit_)); - ci->parentoid = ecalloc(GIT_OID_SHA1_HEXSIZE + 1, sizeof(char)); - git_oid_tostr(ci->parentoid, GIT_OID_SHA1_HEXSIZE + 1, - git_commit_parent_id(ci->commit_, 0)); + commit->oid = ecalloc(GIT_OID_SHA1_HEXSIZE + 1, sizeof(char)); + git_oid_tostr(commit->oid, GIT_OID_SHA1_HEXSIZE + 1, + git_commit_id(commit->commit)); + commit->parentoid = ecalloc(GIT_OID_SHA1_HEXSIZE + 1, sizeof(char)); + git_oid_tostr(commit->parentoid, GIT_OID_SHA1_HEXSIZE + 1, + git_commit_parent_id(commit->commit, 0)); // Set commit summary, message. - ci->summary = git_commit_summary(ci->commit_); - ci->msg = git_commit_message(ci->commit_); + commit->summary = git_commit_summary(commit->commit); + commit->message = git_commit_message(commit->commit); // Get commit time, tz offset. - ci->commit_time = git_commit_time(ci->commit_); - ci->commit_timezone_offset = git_commit_time_offset(ci->commit_); + commit->commit_time = git_commit_time(commit->commit); + commit->commit_timezone_offset = git_commit_time_offset(commit->commit); // Get author info. - const git_signature* author = git_commit_author(ci->commit_); - ci->author_name = author->name; - ci->author_email = author->email; - ci->author_time = author->when.time; - ci->author_timezone_offset = author->when.offset; + const git_signature* author = git_commit_author(commit->commit); + commit->author_name = author->name; + commit->author_email = author->email; + commit->author_time = author->when.time; + commit->author_timezone_offset = author->when.offset; // Look up commit tree. git_tree* commit_tree = NULL; - if (git_tree_lookup(&commit_tree, repo, git_commit_tree_id(ci->commit_))) { + if (git_tree_lookup(&commit_tree, repo, git_commit_tree_id(commit->commit))) { errx(1, "git_tree_lookup"); } // Look up parent tree, if there is a parent commit. git_commit* parent = NULL; git_tree* parent_tree = NULL; - if (!git_commit_parent(&parent, ci->commit_, 0)) { + if (!git_commit_parent(&parent, commit->commit, 0)) { if (git_tree_lookup(&parent_tree, repo, git_commit_tree_id(parent))) { errx(1, "git_tree_lookup"); } @@ -69,8 +92,8 @@ CommitInfo* commitinfo_create(const git_oid* oid, git_repository* repo) { git_tree_free(commit_tree); git_tree_free(parent_tree); - git_diff_free(ci->diff_); - ci->diff_ = diff; + git_diff_free(commit->diff); + commit->diff = diff; git_diff_find_options fopts; if (git_diff_find_options_init(&fopts, GIT_DIFF_FIND_OPTIONS_VERSION)) { @@ -80,51 +103,112 @@ CommitInfo* commitinfo_create(const git_oid* oid, git_repository* repo) { /* find renames and copies, exact matches (no heuristic) for renames. */ fopts.flags |= GIT_DIFF_FIND_RENAMES | GIT_DIFF_FIND_COPIES | GIT_DIFF_FIND_EXACT_MATCH_ONLY; - if (git_diff_find_similar(ci->diff_, &fopts)) { + if (git_diff_find_similar(commit->diff, &fopts)) { errx(1, "git_diff_find_similar"); } // Add deltas. - ci->addcount = 0; - ci->delcount = 0; - size_t deltas_len = git_diff_num_deltas(ci->diff_); - ci->deltas = ecalloc(deltas_len, sizeof(DeltaInfo*)); + commit->addcount = 0; + commit->delcount = 0; + size_t deltas_len = git_diff_num_deltas(commit->diff); + commit->deltas = ecalloc(deltas_len, sizeof(GitDelta*)); size_t deltas_out_count = 0; for (size_t i = 0; i < deltas_len; i++) { git_patch* patch = NULL; - if (git_patch_from_diff(&patch, ci->diff_, i)) { + if (git_patch_from_diff(&patch, commit->diff, i)) { continue; } - // Hand ownership of patch to di. - DeltaInfo* di = deltainfo_create(patch); - if (di) { - ci->deltas[deltas_out_count++] = di; - ci->addcount += di->addcount; - ci->delcount += di->delcount; + // Hand ownership of patch to delta. + 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); } } - ci->deltas_len = deltas_out_count; - ci->filecount = deltas_len; - return ci; + commit->deltas_len = deltas_out_count; + commit->filecount = deltas_len; + return commit; } -void commitinfo_free(CommitInfo* ci) { - if (!ci) { +void gitcommit_free(GitCommit* commit) { + if (!commit) { return; } - free(ci->oid); - free(ci->parentoid); - for (size_t i = 0; i < ci->deltas_len; i++) { - deltainfo_free(ci->deltas[i]); - ci->deltas[i] = NULL; + free(commit->oid); + free(commit->parentoid); + for (size_t i = 0; i < commit->deltas_len; i++) { + gitdelta_free(commit->deltas[i]); + commit->deltas[i] = NULL; } - free(ci->deltas); - ci->deltas = NULL; - - git_diff_free(ci->diff_); - ci->diff_ = NULL; - git_commit_free(ci->commit_); - ci->commit_ = NULL; - free(ci); + free(commit->deltas); + commit->deltas = NULL; + + git_diff_free(commit->diff); + commit->diff = NULL; + git_commit_free(commit->commit); + commit->commit = NULL; + 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/git/commit.h b/git/commit.h @@ -5,26 +5,54 @@ #include "git/delta.h" -typedef struct { - char* oid; - char* parentoid; - const char* summary; - const char* msg; - time_t commit_time; - int commit_timezone_offset; - const char* author_name; - const char* author_email; - time_t author_time; - int author_timezone_offset; - DeltaInfo** deltas; - size_t deltas_len; - size_t addcount; - size_t delcount; - size_t filecount; - - /* private */ - void* commit_; - void* diff_; -} CommitInfo; +/* 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); #endif // GITOUT_GIT_COMMIT_H_ diff --git a/git/delta.c b/git/delta.c @@ -1,5 +1,6 @@ #include "git/delta.h" +#include <assert.h> #include <git2/diff.h> #include <git2/patch.h> #include <stdlib.h> @@ -8,30 +9,40 @@ #include "git/internal.h" #include "utils.h" +struct GitHunkLine { + size_t id; + int old_lineno; + int new_lineno; + const char* content; + size_t content_len; +}; + /* HunkLines */ -static HunkLine* hunkline_create(git_patch* patch, - size_t hunk_id, - size_t line_id); -static void hunkline_free(HunkLine* hunk_line); +static GitHunkLine* githunkline_create(git_patch* patch, + size_t hunk_id, + size_t line_id); +static void githunkline_free(GitHunkLine* hunk_line); /* Hunks */ -static Hunk* hunk_create(git_patch* patch, size_t id); -static void hunk_free(Hunk* hunk); +static GitHunk* githunk_create(git_patch* patch, size_t id); +static void githunk_free(GitHunk* hunk); /* Deltas */ static char status_for_delta(const git_diff_delta* delta); -static char* deltainfo_graph(const DeltaInfo* di, - size_t length, - char character, - size_t max_width); +static char* gitdelta_graph(const GitDelta* delta, + size_t length, + char character, + size_t max_width); -HunkLine* hunkline_create(git_patch* patch, size_t hunk_id, size_t line_id) { +GitHunkLine* githunkline_create(git_patch* patch, + size_t hunk_id, + size_t line_id) { const git_diff_line* line; if (git_patch_get_line_in_hunk(&line, patch, hunk_id, line_id)) { return NULL; } - HunkLine* line_out = ecalloc(1, sizeof(HunkLine)); + GitHunkLine* line_out = ecalloc(1, sizeof(GitHunkLine)); line_out->id = line_id; line_out->old_lineno = line->old_lineno; line_out->new_lineno = line->new_lineno; @@ -40,24 +51,51 @@ HunkLine* hunkline_create(git_patch* patch, size_t hunk_id, size_t line_id) { return line_out; } -void hunkline_free(HunkLine* hunk_line) { +void githunkline_free(GitHunkLine* hunk_line) { free(hunk_line); } -Hunk* hunk_create(git_patch* patch, size_t hunk_id) { +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; + const 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; if (git_patch_get_hunk(&hunk, &line_count, patch, hunk_id)) { return NULL; } - Hunk* hunk_out = ecalloc(1, sizeof(Hunk)); + GitHunk* hunk_out = ecalloc(1, sizeof(GitHunk)); hunk_out->id = hunk_id; hunk_out->header = hunk->header; - hunk_out->lines = ecalloc(line_count, sizeof(HunkLine*)); + hunk_out->lines = ecalloc(line_count, sizeof(GitHunkLine*)); size_t lines_out_count = 0; for (size_t i = 0; i < line_count; i++) { - HunkLine* hunk_line = hunkline_create(patch, hunk_id, i); + GitHunkLine* hunk_line = githunkline_create(patch, hunk_id, i); if (hunk_line) { hunk_out->lines[lines_out_count++] = hunk_line; } @@ -66,12 +104,12 @@ Hunk* hunk_create(git_patch* patch, size_t hunk_id) { return hunk_out; } -void hunk_free(Hunk* hunk) { +void githunk_free(GitHunk* hunk) { if (!hunk) { return; } for (size_t i = 0; i < hunk->lines_len; i++) { - hunkline_free(hunk->lines[i]); + githunkline_free(hunk->lines[i]); hunk->lines[i] = NULL; } free(hunk->lines); @@ -79,6 +117,23 @@ void hunk_free(Hunk* 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: @@ -103,76 +158,122 @@ char status_for_delta(const git_diff_delta* delta) { return ' '; } -DeltaInfo* deltainfo_create(git_patch* patch) { - DeltaInfo* di = ecalloc(1, sizeof(DeltaInfo)); +struct GitDelta { + bool is_binary; + char status; + const char* old_file_path; + const char* new_file_path; + size_t addcount; + size_t delcount; + GitHunk** hunks; + size_t hunks_len; + + git_patch* patch; +}; + +GitDelta* gitdelta_create(git_patch* patch) { + GitDelta* delta = ecalloc(1, sizeof(GitDelta)); /* Take ownership of patch. */ - di->patch_ = patch; + delta->patch = patch; - const git_diff_delta* delta = git_patch_get_delta(patch); - di->status = status_for_delta(delta); - di->is_binary = delta->flags & GIT_DIFF_FLAG_BINARY; - di->old_file_path = delta->old_file.path; - di->new_file_path = delta->new_file.path; - di->addcount = 0; - di->delcount = 0; + 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; + delta->new_file_path = git_delta->new_file.path; + delta->addcount = 0; + delta->delcount = 0; /* Skip stats for binary data. */ - if (di->is_binary) { - return di; + if (delta->is_binary) { + return delta; } /* Populate hunks array. */ size_t hunk_count = git_patch_num_hunks(patch); - di->hunks = ecalloc(hunk_count, sizeof(Hunk*)); + delta->hunks = ecalloc(hunk_count, sizeof(GitHunk*)); size_t hunks_out_count = 0; for (size_t i = 0; i < hunk_count; i++) { const git_diff_hunk* hunk; size_t line_count; if (!git_patch_get_hunk(&hunk, &line_count, patch, i)) { - Hunk* hunk = hunk_create(patch, i); + GitHunk* hunk = githunk_create(patch, i); if (hunk) { - di->hunks[hunks_out_count++] = hunk; + delta->hunks[hunks_out_count++] = hunk; } } } - di->hunks_len = hunks_out_count; + delta->hunks_len = hunks_out_count; /* Increment added/deleted line counts. */ - for (size_t i = 0; i < di->hunks_len; i++) { - Hunk* hunk = di->hunks[i]; + for (size_t i = 0; i < delta->hunks_len; i++) { + GitHunk* hunk = delta->hunks[i]; for (size_t j = 0; j < hunk->lines_len; j++) { - HunkLine* line = hunk->lines[j]; + GitHunkLine* line = hunk->lines[j]; if (line->old_lineno == -1) { - di->addcount++; + delta->addcount++; } else if (line->new_lineno == -1) { - di->delcount++; + delta->delcount++; } } } - return di; + return delta; } -void deltainfo_free(DeltaInfo* di) { - if (!di) { +void gitdelta_free(GitDelta* delta) { + if (!delta) { return; } - for (size_t i = 0; i < di->hunks_len; i++) { - hunk_free(di->hunks[i]); - di->hunks[i] = NULL; + for (size_t i = 0; i < delta->hunks_len; i++) { + githunk_free(delta->hunks[i]); + delta->hunks[i] = NULL; } - free(di->hunks); - di->hunks = NULL; - git_patch_free(di->patch_); - di->patch_ = NULL; - free(di); -} - -char* deltainfo_graph(const DeltaInfo* di, - size_t length, - char c, - size_t max_width) { - size_t changed = di->addcount + di->delcount; + free(delta->hunks); + delta->hunks = NULL; + git_patch_free(delta->patch); + delta->patch = NULL; + 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, + size_t max_width) { + size_t changed = delta->addcount + delta->delcount; if (changed > max_width && length > 0) { length = ((float)max_width / changed * length) + 1; } @@ -181,10 +282,10 @@ char* deltainfo_graph(const DeltaInfo* di, return graph; } -char* deltainfo_added_graph(const DeltaInfo* di, size_t max_width) { - return deltainfo_graph(di, di->addcount, '+', max_width); +char* gitdelta_added_graph(const GitDelta* delta, size_t max_width) { + return gitdelta_graph(delta, delta->addcount, '+', max_width); } -char* deltainfo_deleted_graph(const DeltaInfo* di, size_t max_width) { - return deltainfo_graph(di, di->delcount, '-', max_width); +char* gitdelta_deleted_graph(const GitDelta* delta, size_t max_width) { + return gitdelta_graph(delta, delta->delcount, '-', max_width); } diff --git a/git/delta.h b/git/delta.h @@ -4,36 +4,33 @@ #include <stdbool.h> #include <stddef.h> -typedef struct { - size_t id; - int old_lineno; - int new_lineno; - const char* content; - size_t content_len; -} HunkLine; - -typedef struct { - size_t id; - const char* header; - HunkLine** lines; - size_t lines_len; -} Hunk; - -typedef struct { - bool is_binary; - char status; - const char* old_file_path; - const char* new_file_path; - size_t addcount; - size_t delcount; - Hunk** hunks; - size_t hunks_len; - - /* private */ - void* patch_; -} DeltaInfo; - -char* deltainfo_added_graph(const DeltaInfo* di, size_t max_width); -char* deltainfo_deleted_graph(const DeltaInfo* di, size_t max_width); +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); + +char* gitdelta_added_graph(const GitDelta* delta, size_t max_width); +char* gitdelta_deleted_graph(const GitDelta* delta, size_t max_width); #endif // GITOUT_GIT_DELTA_H_ diff --git a/git/file.c b/git/file.c @@ -5,26 +5,70 @@ #include "git/internal.h" #include "utils.h" -FileInfo* fileinfo_create(FileType type, - const char* mode, - const char* display_path, - const char* repo_path, - const char* commit_oid, - ssize_t size_bytes, - ssize_t size_lines, - const char* content) { - FileInfo* fi = ecalloc(1, sizeof(FileInfo)); - fi->type = type; - fi->mode = mode; - fi->display_path = display_path; - fi->repo_path = repo_path; - fi->commit_oid = commit_oid; - fi->size_bytes = size_bytes; - fi->size_lines = size_lines; - fi->content = content; - return fi; -} - -void fileinfo_free(FileInfo* fi) { - free(fi); +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, + const char* repo_path, + const char* commit_oid, + ssize_t size_bytes, + ssize_t size_lines, + 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->size_bytes = size_bytes; + file->size_lines = size_lines; + file->content = content; + return file; +} + +void gitfile_free(GitFile* file) { + 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/git/file.h b/git/file.h @@ -8,16 +8,16 @@ typedef enum { kFileTypeSubmodule, } FileType; -typedef struct { - 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; -} FileInfo; +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); +ssize_t gitfile_size_lines(const GitFile* file); +const char* gitfile_content(const GitFile* file); #endif // GITOUT_GIT_FILE_H_ diff --git a/git/internal.h b/git/internal.h @@ -8,24 +8,24 @@ #include "git/file.h" #include "git/reference.h" -CommitInfo* commitinfo_create(const git_oid* oid, git_repository* repo); -void commitinfo_free(CommitInfo* ci); +GitCommit* gitcommit_create(const git_oid* oid, git_repository* repo); +void gitcommit_free(GitCommit* commit); -DeltaInfo* deltainfo_create(git_patch* patch); -void deltainfo_free(DeltaInfo* di); +GitDelta* gitdelta_create(git_patch* patch); +void gitdelta_free(GitDelta* delta); -FileInfo* fileinfo_create(FileType type, - const char* mode, - const char* display_path, - const char* repo_path, - const char* commit_oid, - ssize_t size_bytes, - ssize_t size_lines, - const char* content); -void fileinfo_free(FileInfo* fi); +GitFile* gitfile_create(FileType type, + const char* mode, + const char* display_path, + const char* repo_path, + const char* commit_oid, + ssize_t size_bytes, + ssize_t size_lines, + const char* content); +void gitfile_free(GitFile* file); -ReferenceInfo* referenceinfo_create(git_repository* repo, git_reference* ref); -void referenceinfo_free(ReferenceInfo* ri); -int referenceinfo_compare(const void* r1, const void* r2); +GitReference* gitreference_create(git_repository* repo, git_reference* ref); +void gitreference_free(GitReference* ref); +int gitreference_compare(const void* r1, const void* r2); #endif // GITOUT_GIT_INTERNAL_H_ diff --git a/git/reference.c b/git/reference.c @@ -12,72 +12,93 @@ #include "git/internal.h" #include "utils.h" -ReferenceInfo* referenceinfo_create(git_repository* repo, git_reference* ref) { - ReferenceInfo* ri = ecalloc(1, sizeof(ReferenceInfo)); +struct GitReference { + RefType type; + const char* shorthand; + GitCommit* commit; + + git_reference* ref; +}; + +GitReference* gitreference_create(git_repository* repo, + git_reference* git_ref) { + GitReference* ref = ecalloc(1, sizeof(GitReference)); // Set ref. - if (git_reference_type(ref) == GIT_REFERENCE_SYMBOLIC) { + if (git_reference_type(git_ref) == GIT_REFERENCE_SYMBOLIC) { git_reference* direct_ref = NULL; - git_reference_resolve(&direct_ref, ref); - git_reference_free(ref); - ref = direct_ref; + git_reference_resolve(&direct_ref, git_ref); + git_reference_free(git_ref); + git_ref = direct_ref; } - if (!git_reference_target(ref)) { + if (!git_reference_target(git_ref)) { errx(1, "git_reference_target"); } - ri->ref_ = ref; + ref->ref = git_ref; // Set type. - if (git_reference_is_branch(ri->ref_)) { - ri->type = kReftypeBranch; - } else if (git_reference_is_tag(ri->ref_)) { - ri->type = kReftypeTag; + if (git_reference_is_branch(ref->ref)) { + ref->type = kReftypeBranch; + } else if (git_reference_is_tag(ref->ref)) { + ref->type = kReftypeTag; } else { errx(1, "not a branch or tag"); } // Set shorthand. - ri->shorthand = git_reference_shorthand(ri->ref_); + ref->shorthand = git_reference_shorthand(ref->ref); - // Create a CommitInfo from the object. + // Create a GitCommit from the object. git_object* obj = NULL; - git_reference_peel(&obj, ref, GIT_OBJECT_ANY); + git_reference_peel(&obj, git_ref, GIT_OBJECT_ANY); const git_oid* id = git_object_id(obj); git_object_free(obj); if (!id) { errx(1, "git_object_id"); } - ri->ci = commitinfo_create(id, repo); - return ri; + ref->commit = gitcommit_create(id, repo); + return ref; } -void referenceinfo_free(ReferenceInfo* ri) { - if (!ri) { +void gitreference_free(GitReference* ref) { + if (!ref) { return; } - git_reference_free(ri->ref_); - ri->ref_ = NULL; - commitinfo_free(ri->ci); - ri->ci = NULL; - free(ri); + git_reference_free(ref->ref); + ref->ref = NULL; + gitcommit_free(ref->commit); + ref->commit = NULL; + 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 referenceinfo_compare(const void* a, const void* b) { - ReferenceInfo* r1 = *(ReferenceInfo**)a; - ReferenceInfo* r2 = *(ReferenceInfo**)b; - int r = git_reference_is_tag(r1->ref_) - git_reference_is_tag(r2->ref_); +int gitreference_compare(const void* a, const void* b) { + GitReference* r1 = *(GitReference**)a; + GitReference* r2 = *(GitReference**)b; + int r = git_reference_is_tag(r1->ref) - git_reference_is_tag(r2->ref); if (r != 0) { return r; } - time_t t1 = r1->ci->author_time; - time_t t2 = r2->ci->author_time; + time_t t1 = gitcommit_author_time(r1->commit); + time_t t2 = gitcommit_author_time(r2->commit); if (t1 > t2) { return -1; } if (t1 < t2) { return 1; } - return strcmp(git_reference_shorthand(r1->ref_), - git_reference_shorthand(r2->ref_)); + return strcmp(git_reference_shorthand(r1->ref), + git_reference_shorthand(r2->ref)); } diff --git a/git/reference.h b/git/reference.h @@ -9,13 +9,10 @@ typedef enum { } RefType; /* reference and associated data for sorting */ -typedef struct { - RefType type; - const char* shorthand; - CommitInfo* ci; +typedef struct GitReference GitReference; - /* private */ - void* ref_; -} ReferenceInfo; +RefType gitreference_type(const GitReference* ref); +const char* gitreference_shorthand(const GitReference* ref); +GitCommit* gitreference_commit(const GitReference* ref); #endif // GITOUT_GIT_REFERENCE_H_ diff --git a/git/repo.c b/git/repo.c @@ -26,6 +26,19 @@ #include "third_party/openbsd/reallocarray.h" #include "utils.h" +struct GitRepo { + char* name; + char* short_name; + char* owner; + char* description; + char* clone_url; + const char* submodules; + const char* readme; + const char* license; + + void* repo; +}; + /* Local const data */ static const char* kLicenses[] = {"HEAD:LICENSE", "HEAD:LICENSE.md", "HEAD:COPYING"}; @@ -40,18 +53,18 @@ static char* first_line_of_file(const char* path); static const git_oid* oid_for_spec(git_repository* repo, const char* spec); static char* format_filemode(git_filemode_t m); -/* RepoInfo utilities. */ -static char* repoinfo_name_from_path(const char* repo_path); -static char* repoinfo_shortname_from_name(const char* name); -static bool repoinfo_has_blob(git_repository* repo, const char* file); -static const char* repoinfo_first_matching_file(git_repository* repo, - const char** files, - size_t files_len); -static bool repoinfo_walk_tree_files(git_repository* repo, - git_tree* tree, - const char* path, - FileCallback cb, - void* user_data); +/* GitRepo utilities. */ +static char* gitrepo_name_from_path(const char* repo_path); +static char* gitrepo_shortname_from_name(const char* name); +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 bool gitrepo_walk_tree_files(git_repository* repo, + git_tree* tree, + const char* path, + FileCallback cb, + void* user_data); size_t string_count_lines(const char* str, ssize_t str_len) { if (str_len <= 0) { @@ -171,7 +184,7 @@ char* format_filemode(git_filemode_t m) { return mode; } -char* repoinfo_name_from_path(const char* repo_path) { +char* gitrepo_name_from_path(const char* repo_path) { char path[PATH_MAX]; estrlcpy(path, repo_path, sizeof(path)); const char* filename = basename(path); @@ -181,7 +194,7 @@ char* repoinfo_name_from_path(const char* repo_path) { return estrdup(filename); } -char* repoinfo_shortname_from_name(const char* name) { +char* gitrepo_shortname_from_name(const char* name) { char* short_name = estrdup(name); if (string_ends_with(short_name, ".git")) { size_t short_name_len = strlen(short_name); @@ -191,7 +204,7 @@ char* repoinfo_shortname_from_name(const char* name) { return short_name; } -bool repoinfo_has_blob(git_repository* repo, const char* file) { +bool gitrepo_has_blob(git_repository* repo, const char* file) { git_object* obj = NULL; if (git_revparse_single(&obj, repo, file)) { return false; @@ -201,26 +214,26 @@ bool repoinfo_has_blob(git_repository* repo, const char* file) { return has_blob; } -const char* repoinfo_first_matching_file(git_repository* repo, - const char** files, - size_t files_len) { +const char* gitrepo_first_matching_file(git_repository* repo, + const char** files, + size_t files_len) { for (size_t i = 0; i < files_len; i++) { const char* filename = files[i]; - if (repoinfo_has_blob(repo, filename)) { + if (gitrepo_has_blob(repo, filename)) { return filename + strlen("HEAD:"); } } return ""; } -RepoInfo* repoinfo_create(const char* path) { - RepoInfo* repo_info = ecalloc(1, sizeof(RepoInfo)); - git_repository* repo = NULL; +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(&repo, path, kRepoOpenFlags, NULL)) { + if (git_repository_open_ext(&git_repo, path, kRepoOpenFlags, NULL)) { errx(1, "git_repository_open_ext"); } - repo_info->repo_ = repo; + repo->repo = git_repo; char repo_path[PATH_MAX]; if (!realpath(path, repo_path)) { @@ -238,124 +251,156 @@ RepoInfo* repoinfo_create(const char* path) { char url_path[PATH_MAX]; path_concat(url_path, sizeof(url_path), git_path, "url"); - repo_info->name = repoinfo_name_from_path(repo_path); - repo_info->short_name = repoinfo_shortname_from_name(repo_info->name); - repo_info->owner = first_line_of_file(owner_path); - repo_info->description = first_line_of_file(desc_path); - repo_info->clone_url = first_line_of_file(url_path); - repo_info->submodules = - repoinfo_has_blob(repo_info->repo_, "HEAD:.gitmodules") ? ".gitmodules" - : ""; - repo_info->readme = - repoinfo_first_matching_file(repo_info->repo_, kReadmes, kReadmesLen); - repo_info->license = - repoinfo_first_matching_file(repo_info->repo_, kLicenses, kLicensesLen); - return repo_info; + repo->name = gitrepo_name_from_path(repo_path); + repo->short_name = gitrepo_shortname_from_name(repo->name); + 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 = gitrepo_has_blob(repo->repo, "HEAD:.gitmodules") + ? ".gitmodules" + : ""; + repo->readme = + gitrepo_first_matching_file(repo->repo, kReadmes, kReadmesLen); + repo->license = + gitrepo_first_matching_file(repo->repo, kLicenses, kLicensesLen); + return repo; } -void repoinfo_free(RepoInfo* repo_info) { - if (!repo_info) { +void gitrepo_free(GitRepo* repo) { + if (!repo) { return; } - free(repo_info->name); - repo_info->name = NULL; - free(repo_info->short_name); - repo_info->short_name = NULL; - free(repo_info->owner); - repo_info->owner = NULL; - free(repo_info->description); - repo_info->description = NULL; - free(repo_info->clone_url); - repo_info->clone_url = NULL; - git_repository_free(repo_info->repo_); - repo_info->repo_ = NULL; - free(repo_info); + free(repo->name); + repo->name = NULL; + free(repo->short_name); + repo->short_name = NULL; + free(repo->owner); + repo->owner = NULL; + free(repo->description); + repo->description = NULL; + free(repo->clone_url); + repo->clone_url = NULL; + git_repository_free(repo->repo); + repo->repo = NULL; + free(repo); +} + +const char* gitrepo_name(const GitRepo* repo) { + return repo->name; +} + +const char* gitrepo_short_name(const GitRepo* repo) { + return repo->short_name; +} + +const char* gitrepo_owner(const GitRepo* repo) { + return repo->owner; +} + +const char* gitrepo_description(const GitRepo* repo) { + return repo->description; +} + +const char* gitrepo_clone_url(const GitRepo* repo) { + return repo->clone_url; +} + +const char* gitrepo_submodules(const GitRepo* repo) { + return repo->submodules; +} + +const char* gitrepo_readme(const GitRepo* repo) { + return repo->readme; +} + +const char* gitrepo_license(const GitRepo* repo) { + return repo->license; } -void repoinfo_for_commit(RepoInfo* repo_info, - const char* spec, - CommitCallback cb, - void* user_data) { - const git_oid* start_oid = oid_for_spec(repo_info->repo_, spec); +void gitrepo_for_commit(GitRepo* repo, + const char* spec, + CommitCallback cb, + void* user_data) { + const git_oid* start_oid = oid_for_spec(repo->repo, spec); if (start_oid == NULL) { return; } git_revwalk* revwalk = NULL; - if (git_revwalk_new(&revwalk, repo_info->repo_) != 0) { + if (git_revwalk_new(&revwalk, repo->repo) != 0) { errx(1, "git_revwalk_new"); } git_revwalk_push(revwalk, start_oid); git_oid current; if (!git_revwalk_next(&current, revwalk)) { - CommitInfo* ci = commitinfo_create(&current, repo_info->repo_); - cb(ci, user_data); - commitinfo_free(ci); + GitCommit* commit = gitcommit_create(&current, repo->repo); + cb(commit, user_data); + gitcommit_free(commit); } git_revwalk_free(revwalk); } -void repoinfo_for_each_commit(RepoInfo* repo_info, - CommitCallback cb, - void* user_data) { - const git_oid* start_oid = oid_for_spec(repo_info->repo_, "HEAD"); +void gitrepo_for_each_commit(GitRepo* repo, + CommitCallback cb, + void* user_data) { + const git_oid* start_oid = oid_for_spec(repo->repo, "HEAD"); git_revwalk* revwalk = NULL; - if (git_revwalk_new(&revwalk, repo_info->repo_) != 0) { + if (git_revwalk_new(&revwalk, repo->repo) != 0) { errx(1, "git_revwalk_new"); } git_revwalk_push(revwalk, start_oid); git_oid current; while (!git_revwalk_next(&current, revwalk)) { - CommitInfo* ci = commitinfo_create(&current, repo_info->repo_); - cb(ci, user_data); - commitinfo_free(ci); + GitCommit* commit = gitcommit_create(&current, repo->repo); + cb(commit, user_data); + gitcommit_free(commit); } git_revwalk_free(revwalk); } -void repoinfo_for_each_reference(RepoInfo* repo_info, - ReferenceCallback cb, - void* user_data) { +void gitrepo_for_each_reference(GitRepo* repo, + ReferenceCallback cb, + void* user_data) { git_reference_iterator* it = NULL; - if (git_reference_iterator_new(&it, repo_info->repo_) != 0) { + if (git_reference_iterator_new(&it, repo->repo) != 0) { errx(1, "git_reference_iterator_new"); } - ReferenceInfo** ris = NULL; - size_t ris_len = 0; + GitReference** repos = NULL; + size_t repos_len = 0; git_reference* current = NULL; while (!git_reference_next(&current, it)) { if (!git_reference_is_branch(current) && !git_reference_is_tag(current)) { git_reference_free(current); continue; } - // Hand ownership of current to ReferenceInfo. - ReferenceInfo* ri = referenceinfo_create(repo_info->repo_, current); - ris = reallocarray(ris, ris_len + 1, sizeof(ReferenceInfo*)); - if (!ris) { + // Hand ownership of current to GitReference. + GitReference* ref = gitreference_create(repo->repo, current); + repos = reallocarray(repos, repos_len + 1, sizeof(GitReference*)); + if (!repos) { err(1, "reallocarray"); } - ris[ris_len++] = ri; + repos[repos_len++] = ref; } git_reference_iterator_free(it); - qsort(ris, ris_len, sizeof(ReferenceInfo*), referenceinfo_compare); + qsort(repos, repos_len, sizeof(GitReference*), gitreference_compare); - for (size_t i = 0; i < ris_len; i++) { - cb(ris[i], user_data); - referenceinfo_free(ris[i]); - ris[i] = NULL; + for (size_t i = 0; i < repos_len; i++) { + cb(repos[i], user_data); + gitreference_free(repos[i]); + repos[i] = NULL; } - free(ris); + free(repos); } -bool repoinfo_walk_tree_files(git_repository* repo, - git_tree* tree, - const char* path, - FileCallback cb, - void* user_data) { +bool gitrepo_walk_tree_files(git_repository* repo, + git_tree* tree, + const char* path, + FileCallback cb, + void* user_data) { for (size_t i = 0; i < git_tree_entrycount(tree); i++) { const git_tree_entry* entry = git_tree_entry_byindex(tree, i); if (!entry) { @@ -380,19 +425,19 @@ bool repoinfo_walk_tree_files(git_repository* repo, if (git_tree_entry_to_object(&obj, repo, entry) != 0) { char oid_str[GIT_OID_SHA1_HEXSIZE + 1]; git_oid_tostr(oid_str, sizeof(oid_str), git_tree_entry_id(entry)); - FileInfo* fileinfo = - fileinfo_create(kFileTypeSubmodule, "m---------", entrypath, - ".gitmodules", oid_str, -1, -1, ""); + GitFile* fileinfo = + gitfile_create(kFileTypeSubmodule, "m---------", entrypath, + ".gitmodules", oid_str, -1, -1, ""); cb(fileinfo, user_data); - fileinfo_free(fileinfo); + gitfile_free(fileinfo); } else { switch (git_object_type(obj)) { case GIT_OBJECT_BLOB: break; case GIT_OBJECT_TREE: { /* NOTE: recurses */ - if (!repoinfo_walk_tree_files(repo, (git_tree*)obj, entrypath, cb, - user_data)) { + if (!gitrepo_walk_tree_files(repo, (git_tree*)obj, entrypath, cb, + user_data)) { git_object_free(obj); return false; } @@ -413,11 +458,11 @@ bool repoinfo_walk_tree_files(git_repository* repo, size_lines = string_count_lines(content, size_bytes); } char* filemode = format_filemode(git_tree_entry_filemode(entry)); - FileInfo* fileinfo = - fileinfo_create(kFileTypeFile, filemode, entrypath, entrypath, "", - size_bytes, size_lines, content); + GitFile* fileinfo = + gitfile_create(kFileTypeFile, filemode, entrypath, entrypath, "", + size_bytes, size_lines, content); cb(fileinfo, user_data); - fileinfo_free(fileinfo); + gitfile_free(fileinfo); git_object_free(obj); free(filemode); } @@ -425,12 +470,12 @@ bool repoinfo_walk_tree_files(git_repository* repo, return true; } -void repoinfo_for_each_file(RepoInfo* repo_info, - FileCallback cb, - void* user_data) { +void gitrepo_for_each_file(GitRepo* repo, + FileCallback cb, + void* user_data) { git_commit* commit = NULL; - const git_oid* id = oid_for_spec(repo_info->repo_, "HEAD"); - if (git_commit_lookup(&commit, repo_info->repo_, id) != 0) { + const git_oid* id = oid_for_spec(repo->repo, "HEAD"); + if (git_commit_lookup(&commit, repo->repo, id) != 0) { return; } git_tree* tree = NULL; @@ -440,7 +485,7 @@ void repoinfo_for_each_file(RepoInfo* repo_info, } git_commit_free(commit); - if (!repoinfo_walk_tree_files(repo_info->repo_, tree, "", cb, user_data)) { + if (!gitrepo_walk_tree_files(repo->repo, tree, "", cb, user_data)) { git_tree_free(tree); return; } diff --git a/git/repo.h b/git/repo.h @@ -5,41 +5,34 @@ #include "git/file.h" #include "git/reference.h" -typedef struct { - char* name; - char* short_name; - char* owner; - char* description; - char* clone_url; - const char* submodules; - const char* readme; - const char* license; - - /* private */ - void* repo_; -} RepoInfo; - -RepoInfo* repoinfo_create(const char* path); -void repoinfo_free(RepoInfo* repo_info); - -typedef void (*CommitCallback)(const CommitInfo* ci, void* user_data); -void repoinfo_for_commit(RepoInfo* repo_info, - const char* spec, - CommitCallback cb, - void* user_data); - -void repoinfo_for_each_commit(RepoInfo* repo_info, - CommitCallback cb, - void* user_data); - -typedef void (*ReferenceCallback)(const ReferenceInfo* ri, void* user_data); -void repoinfo_for_each_reference(RepoInfo* repo_info, - ReferenceCallback cb, - void* user_data); - -typedef void (*FileCallback)(const FileInfo* ri, void* user_data); -void repoinfo_for_each_file(RepoInfo* repo_info, - FileCallback cb, - void* user_data); +typedef struct GitRepo GitRepo; + +GitRepo* gitrepo_create(const char* path); +void gitrepo_free(GitRepo* repo); + +const char* gitrepo_name(const GitRepo* repo); +const char* gitrepo_short_name(const GitRepo* repo); +const char* gitrepo_owner(const GitRepo* repo); +const char* gitrepo_description(const GitRepo* repo); +const char* gitrepo_clone_url(const GitRepo* repo); +const char* gitrepo_submodules(const GitRepo* repo); +const char* gitrepo_readme(const GitRepo* repo); +const char* gitrepo_license(const GitRepo* repo); + +typedef void (*CommitCallback)(const GitCommit* ci, void* user_data); +void gitrepo_for_commit(GitRepo* repo, + const char* spec, + CommitCallback cb, + void* user_data); + +void gitrepo_for_each_commit(GitRepo* repo, CommitCallback cb, void* user_data); + +typedef void (*ReferenceCallback)(const GitReference* ref, void* user_data); +void gitrepo_for_each_reference(GitRepo* repo, + ReferenceCallback cb, + void* user_data); + +typedef void (*FileCallback)(const GitFile* file, void* user_data); +void gitrepo_for_each_file(GitRepo* repo, FileCallback cb, void* user_data); #endif // GITOUT_GIT_REPO_H_ diff --git a/gitout.c b/gitout.c @@ -21,9 +21,9 @@ struct GitoutOptions { RepoWriterType writer_type; }; -static void commit_callback(const CommitInfo* ci, void* user_data); -static void reference_callback(const ReferenceInfo* ri, void* user_data); -static void file_callback(const FileInfo* fi, void* user_data); +static void commit_callback(const GitCommit* commit, void* user_data); +static void reference_callback(const GitReference* ref, void* user_data); +static void file_callback(const GitFile* file, void* user_data); GitoutOptions* gitout_options_create(int argc, const char* argv[]) { GitoutOptions options = { @@ -124,7 +124,7 @@ void gitout_init(const GitoutOptions* options) { } void gitout_run(const GitoutOptions* options) { - RepoInfo* repo = repoinfo_create(options->repodir); + GitRepo* repo = gitrepo_create(options->repodir); RepoWriter* writer = repowriter_create(options->writer_type, repo); if (options->log_commit_limit >= 0) { repowriter_set_log_commit_limit(writer, options->log_commit_limit); @@ -137,30 +137,30 @@ void gitout_run(const GitoutOptions* options) { } repowriter_begin(writer); - repoinfo_for_each_commit(repo, commit_callback, writer); - repoinfo_for_each_reference(repo, reference_callback, writer); - repoinfo_for_each_file(repo, file_callback, writer); + gitrepo_for_each_commit(repo, commit_callback, writer); + gitrepo_for_each_reference(repo, reference_callback, writer); + gitrepo_for_each_file(repo, file_callback, writer); repowriter_end(writer); repowriter_free(writer); - repoinfo_free(repo); + gitrepo_free(repo); } void gitout_shutdown(void) { gitout_git_shutdown(); } -void commit_callback(const CommitInfo* ci, void* user_data) { +void commit_callback(const GitCommit* ci, void* user_data) { RepoWriter* writer = (RepoWriter*)user_data; repowriter_add_commit(writer, ci); } -void reference_callback(const ReferenceInfo* ri, void* user_data) { +void reference_callback(const GitReference* ref, void* user_data) { RepoWriter* writer = (RepoWriter*)user_data; - repowriter_add_reference(writer, ri); + repowriter_add_reference(writer, ref); } -void file_callback(const FileInfo* fi, void* user_data) { +void file_callback(const GitFile* file, void* user_data) { RepoWriter* writer = (RepoWriter*)user_data; - repowriter_add_file(writer, fi); + repowriter_add_file(writer, file); } diff --git a/gitout_index.c b/gitout_index.c @@ -80,9 +80,9 @@ void gitout_index_run(const GitoutIndexOptions* options) { } indexwriter_begin(writer); for (size_t i = 0; i < options->repo_dir_count; i++) { - RepoInfo* ri = repoinfo_create(options->repo_dirs[i]); - indexwriter_add_repo(writer, ri); - repoinfo_free(ri); + GitRepo* repo = gitrepo_create(options->repo_dirs[i]); + indexwriter_add_repo(writer, repo); + gitrepo_free(repo); } indexwriter_end(writer); indexwriter_free(writer); diff --git a/writer/atom/atom.c b/writer/atom/atom.c @@ -8,13 +8,13 @@ #include "utils.h" struct Atom { - const RepoInfo* repo; + const GitRepo* repo; const char* baseurl; FILE* out; size_t remaining_commits; }; -Atom* atom_create(const RepoInfo* repo, AtomType type) { +Atom* atom_create(const GitRepo* repo, AtomType type) { Atom* atom = ecalloc(1, sizeof(Atom)); atom->repo = repo; atom->baseurl = ""; @@ -38,74 +38,78 @@ void atom_begin(Atom* atom) { fprintf(atom->out, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); fprintf(atom->out, "<feed xmlns=\"http://www.w3.org/2005/Atom\">\n"); fprintf(atom->out, "<title>"); - print_xml_encoded(atom->out, atom->repo->short_name); + print_xml_encoded(atom->out, gitrepo_short_name(atom->repo)); fprintf(atom->out, ", branch HEAD</title>\n"); fprintf(atom->out, "<subtitle>"); - print_xml_encoded(atom->out, atom->repo->description); + print_xml_encoded(atom->out, gitrepo_description(atom->repo)); fprintf(atom->out, "</subtitle>\n"); } void atom_add_commit(Atom* atom, - const CommitInfo* ci, + const GitCommit* commit, const char* path, const char* content_type, const char* tag) { + FILE* out = atom->out; if (atom->remaining_commits == 0) { return; } atom->remaining_commits--; - fprintf(atom->out, "<entry>\n"); - fprintf(atom->out, "<id>%s</id>\n", ci->oid); + fprintf(out, "<entry>\n"); + fprintf(out, "<id>%s</id>\n", gitcommit_oid(commit)); - fprintf(atom->out, "<published>"); - print_time_z(atom->out, ci->author_time); - fprintf(atom->out, "</published>\n"); + fprintf(out, "<published>"); + print_time_z(out, gitcommit_author_time(commit)); + fprintf(out, "</published>\n"); - fprintf(atom->out, "<updated>"); - print_time_z(atom->out, ci->commit_time); - fprintf(atom->out, "</updated>\n"); + fprintf(out, "<updated>"); + print_time_z(out, gitcommit_commit_time(commit)); + fprintf(out, "</updated>\n"); - if (ci->summary) { - fprintf(atom->out, "<title>"); + if (gitcommit_summary(commit)) { + fprintf(out, "<title>"); if (tag && tag[0] != '\0') { - fputc('[', atom->out); - print_xml_encoded(atom->out, tag); - fputc(']', atom->out); + fputc('[', out); + print_xml_encoded(out, tag); + fputc(']', out); } - print_xml_encoded(atom->out, ci->summary); - fprintf(atom->out, "</title>\n"); + print_xml_encoded(out, gitcommit_summary(commit)); + fprintf(out, "</title>\n"); } - fprintf(atom->out, "<link rel=\"alternate\" "); + fprintf(out, "<link rel=\"alternate\" "); if (strlen(content_type) > 0) { - fprintf(atom->out, "type=\"%s\" ", content_type); + fprintf(out, "type=\"%s\" ", content_type); } - fprintf(atom->out, "href=\"%s%s\" />\n", atom->baseurl, path); + fprintf(out, "href=\"%s%s\" />\n", atom->baseurl, path); - fprintf(atom->out, "<author>\n<name>"); - print_xml_encoded(atom->out, ci->author_name); - fprintf(atom->out, "</name>\n<email>"); - print_xml_encoded(atom->out, ci->author_email); - fprintf(atom->out, "</email>\n</author>\n"); + fprintf(out, "<author>\n<name>"); + print_xml_encoded(out, gitcommit_author_name(commit)); + fprintf(out, "</name>\n<email>"); + print_xml_encoded(out, gitcommit_author_email(commit)); + fprintf(out, "</email>\n</author>\n"); - fprintf(atom->out, "<content>"); - fprintf(atom->out, "commit %s\n", ci->oid); - if (ci->parentoid[0]) { - fprintf(atom->out, "parent %s\n", ci->parentoid); + fprintf(out, "<content>"); + fprintf(out, "commit %s\n", gitcommit_oid(commit)); + const char* parentoid = gitcommit_parentoid(commit); + if (parentoid[0]) { + fprintf(out, "parent %s\n", parentoid); } - fprintf(atom->out, "Author: "); - print_xml_encoded(atom->out, ci->author_name); - fprintf(atom->out, " &lt;"); - print_xml_encoded(atom->out, ci->author_email); - fprintf(atom->out, "&gt;\n"); - fprintf(atom->out, "Date: "); - print_time(atom->out, ci->author_time, ci->author_timezone_offset); - fprintf(atom->out, "\n"); - if (ci->msg) { - fputc('\n', atom->out); - print_xml_encoded(atom->out, ci->msg); + fprintf(out, "Author: "); + print_xml_encoded(out, gitcommit_author_name(commit)); + fprintf(out, " &lt;"); + print_xml_encoded(out, gitcommit_author_email(commit)); + fprintf(out, "&gt;\n"); + fprintf(out, "Date: "); + print_time(out, gitcommit_author_time(commit), + gitcommit_author_timezone_offset(commit)); + fprintf(out, "\n"); + const char* message = gitcommit_message(commit); + if (message) { + fputc('\n', out); + print_xml_encoded(out, message); } - fprintf(atom->out, "\n</content>\n</entry>\n"); + fprintf(out, "\n</content>\n</entry>\n"); } void atom_end(Atom* atom) { diff --git a/writer/atom/atom.h b/writer/atom/atom.h @@ -16,7 +16,7 @@ typedef enum { } AtomType; /* Allocate a new Atom RSS output file. */ -Atom* atom_create(const RepoInfo* repo, AtomType type); +Atom* atom_create(const GitRepo* repo, AtomType type); /* Frees the specified Atom RSS output file. */ void atom_free(Atom* atom); @@ -29,7 +29,7 @@ void atom_begin(Atom* atom); /* Writes an RSS <entry> for the commit. */ void atom_add_commit(Atom* atom, - const CommitInfo* ci, + const GitCommit* commit, const char* path, const char* content_type, const char* tag); diff --git a/writer/cache/cache.c b/writer/cache/cache.c @@ -84,20 +84,20 @@ bool cache_can_add_commits(const Cache* cache) { return cache->can_add_commits; } -void cache_add_commit_row(Cache* cache, const CommitInfo* ci) { +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", ci->oid); + fprintf(cache->cache_out, "%s\n", gitcommit_oid(commit)); cache->wrote_lastoid_out = true; } // If all commits are already written; do nothing. if (!cache->can_add_commits || - strncmp(ci->oid, cache->lastoid_in, kOidLen - 1) == 0) { + strncmp(gitcommit_oid(commit), cache->lastoid_in, kOidLen - 1) == 0) { cache->can_add_commits = false; return; } // The rest of the file is the log contents up to and including that commit. - cache->write_commit_row(cache->cache_out, ci); + cache->write_commit_row(cache->cache_out, commit); } void cache_write(Cache* cache) { diff --git a/writer/cache/cache.h b/writer/cache/cache.h @@ -33,7 +33,7 @@ typedef struct Cache Cache; /* Callback used to write a commit to out. */ -typedef void (*WriteCommitRow)(FILE* out, const CommitInfo* ci); +typedef void (*WriteCommitRow)(FILE* out, const GitCommit* commit); /* Allocates a cache. * @@ -44,7 +44,7 @@ typedef void (*WriteCommitRow)(FILE* out, const CommitInfo* ci); * the file at cache_path (if any), when cache_write is invoked. * * The WriteCommitRow parameter is a callback that is passed the output - * stream of the cache and a CommitInfo struct, and writes formatted output to + * stream of the cache and a GitCommit struct, and writes formatted output to * the stream. This callback function should emit the same content emitted as * is used to generating the commit log itself since the contents of this cache * will be inserted into the commit log for all commits after the cached OID. @@ -67,7 +67,7 @@ bool cache_can_add_commits(const Cache* cache); * If this is the first commit to be written, the OID will be written to the * first line of the cache before the commit content is written. */ -void cache_add_commit_row(Cache* cache, const CommitInfo* ci); +void cache_add_commit_row(Cache* cache, const GitCommit* commit); /* Writes the cache to cache_path, overwriting any existing file. */ diff --git a/writer/gopher/commit.c b/writer/gopher/commit.c @@ -19,19 +19,19 @@ struct GopherCommit { }; static void gopher_commit_write_summary(GopherCommit* commit, - const CommitInfo* ci); + const GitCommit* git_commit); static void gopher_commit_write_diffstat(GopherCommit* commit, - const CommitInfo* ci); + const GitCommit* git_commit); static void gopher_commit_write_diffstat_row(GopherCommit* commit, - const DeltaInfo* delta); + const GitDelta* delta); static void gopher_commit_write_diff_content(GopherCommit* commit, - const CommitInfo* ci); + const GitCommit* git_commit); static void gopher_commit_write_diff_delta(GopherCommit* commit, - const DeltaInfo* delta); + const GitDelta* delta); static void gopher_commit_write_diff_hunk(GopherCommit* commit, - const Hunk* hunk); + const GitHunk* hunk); -GopherCommit* gopher_commit_create(const RepoInfo* repo, +GopherCommit* gopher_commit_create(const GitRepo* repo, const char* oid, const char* title) { GopherCommit* commit = ecalloc(1, sizeof(GopherCommit)); @@ -61,149 +61,176 @@ void gopher_commit_begin(GopherCommit* commit) { gopher_page_begin(commit->page); } -void gopher_commit_add_commit(GopherCommit* commit, const CommitInfo* ci) { +void gopher_commit_add_commit(GopherCommit* commit, + const GitCommit* git_commit) { static const uint64_t kDiffMaxFiles = 1000; static const uint64_t kDiffMaxDeltas = 1000; static const uint64_t kDiffMaxDeltaLines = 100000; + FILE* out = commit->out; - gopher_commit_write_summary(commit, ci); + gopher_commit_write_summary(commit, git_commit); - if (ci->deltas_len == 0) { + size_t deltas_len = gitcommit_delta_count(git_commit); + if (deltas_len == 0) { return; } - if (ci->filecount > kDiffMaxFiles || ci->deltas_len > kDiffMaxDeltas || - ci->addcount > kDiffMaxDeltaLines || ci->delcount > kDiffMaxDeltaLines) { - fprintf(commit->out, "Diff is too large, output suppressed.</pre>\n"); + size_t addcount = gitcommit_addcount(git_commit); + size_t delcount = gitcommit_delcount(git_commit); + size_t filecount = gitcommit_filecount(git_commit); + if (filecount > kDiffMaxFiles || deltas_len > kDiffMaxDeltas || + addcount > kDiffMaxDeltaLines || delcount > kDiffMaxDeltaLines) { + fprintf(out, "Diff is too large, output suppressed.</pre>\n"); return; } - gopher_commit_write_diffstat(commit, ci); - gopher_commit_write_diff_content(commit, ci); + gopher_commit_write_diffstat(commit, git_commit); + gopher_commit_write_diff_content(commit, git_commit); } void gopher_commit_end(GopherCommit* commit) { gopher_page_end(commit->page); } -void gopher_commit_write_summary(GopherCommit* commit, const CommitInfo* ci) { +void gopher_commit_write_summary(GopherCommit* commit, + const GitCommit* git_commit) { FILE* out = commit->out; - fprintf(out, "[1|commit %s|../commit/%s.gph|server|port]\n", ci->oid, - ci->oid); + const char* oid = gitcommit_oid(git_commit); + fprintf(out, "[1|commit %s|../commit/%s.gph|server|port]\n", oid, oid); - if (ci->parentoid[0] != '\0') { - const char* oid = ci->parentoid; - fprintf(out, "[1|parent %s|../commit/%s.gph|server|port]\n", oid, oid); + const char* parentoid = gitcommit_parentoid(git_commit); + 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, ci->author_name); + print_gopher_link(commit->out, gitcommit_author_name(git_commit)); fprintf(out, " <"); - print_gopher_link(commit->out, ci->author_email); + print_gopher_link(commit->out, gitcommit_author_email(git_commit)); fprintf(out, ">|URL:mailto:"); - print_gopher_link(commit->out, ci->author_email); + print_gopher_link(commit->out, gitcommit_author_email(git_commit)); fprintf(out, "|server|port]\n"); fprintf(out, "Date: "); - print_time(out, ci->author_time, ci->author_timezone_offset); + print_time(out, gitcommit_author_time(git_commit), + gitcommit_author_timezone_offset(git_commit)); fprintf(out, "\n"); - if (ci->msg) { + const char* message = gitcommit_message(git_commit); + if (message) { fprintf(out, "\n"); - print_gopher_text(commit->out, ci->msg, true); + print_gopher_text(out, message, true); fprintf(out, "\n"); } } -void gopher_commit_write_diffstat(GopherCommit* commit, const CommitInfo* ci) { +void gopher_commit_write_diffstat(GopherCommit* commit, + const GitCommit* git_commit) { fprintf(commit->out, "Diffstat:\n"); - for (size_t i = 0; i < ci->deltas_len; i++) { - gopher_commit_write_diffstat_row(commit, ci->deltas[i]); + size_t delta_count = gitcommit_delta_count(git_commit); + for (size_t i = 0; i < delta_count; i++) { + gopher_commit_write_diffstat_row(commit, gitcommit_delta(git_commit, i)); } } void gopher_commit_write_diffstat_row(GopherCommit* commit, - const DeltaInfo* delta) { + const GitDelta* delta) { static const size_t kGraphWidth = 30; + FILE* out = commit->out; - fprintf(commit->out, " %c ", delta->status); + fprintf(out, " %c ", gitdelta_status(delta)); char filename[PATH_MAX]; - if (strcmp(delta->old_file_path, delta->new_file_path) == 0) { - snprintf(filename, sizeof(filename), "%s", delta->old_file_path); + const char* old_file_path = gitdelta_old_file_path(delta); + const char* new_file_path = gitdelta_new_file_path(delta); + if (strcmp(old_file_path, new_file_path) == 0) { + snprintf(filename, sizeof(filename), "%s", old_file_path); } else { - snprintf(filename, sizeof(filename), "%s -> %s", delta->old_file_path, - delta->new_file_path); + snprintf(filename, sizeof(filename), "%s -> %s", old_file_path, + new_file_path); } - print_gopher_link_padded(commit->out, filename, 35, ' '); + print_gopher_link_padded(out, filename, 35, ' '); - size_t changed = delta->addcount + delta->delcount; - fprintf(commit->out, " | "); - fprintf(commit->out, "%7zu ", changed); - char* added_graph = deltainfo_added_graph(delta, kGraphWidth); - fprintf(commit->out, "%s", added_graph); + size_t changed = gitdelta_lines_added(delta) + gitdelta_lines_deleted(delta); + fprintf(out, " | "); + fprintf(out, "%7zu ", changed); + char* added_graph = gitdelta_added_graph(delta, kGraphWidth); + fprintf(out, "%s", added_graph); free(added_graph); - char* deleted_graph = deltainfo_deleted_graph(delta, kGraphWidth); - fprintf(commit->out, "%s", deleted_graph); + char* deleted_graph = gitdelta_deleted_graph(delta, kGraphWidth); + fprintf(out, "%s", deleted_graph); free(deleted_graph); - fprintf(commit->out, "\n"); + fprintf(out, "\n"); } void gopher_commit_write_diff_content(GopherCommit* commit, - const CommitInfo* ci) { + 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); fprintf(out, "\n%zu file%s changed, %zu insertion%s(+), %zu deletion%s(-)\n", - ci->filecount, ci->filecount == 1 ? "" : "s", // - ci->addcount, ci->addcount == 1 ? "" : "s", // - ci->delcount, ci->delcount == 1 ? "" : "s"); + filecount, filecount == 1 ? "" : "s", // + addcount, addcount == 1 ? "" : "s", // + delcount, delcount == 1 ? "" : "s"); fprintf(commit->out, "---\n"); - for (size_t i = 0; i < ci->deltas_len; i++) { - gopher_commit_write_diff_delta(commit, ci->deltas[i]); + size_t delta_count = gitcommit_delta_count(git_commit); + for (size_t i = 0; i < delta_count; i++) { + gopher_commit_write_diff_delta(commit, gitcommit_delta(git_commit, i)); } } void gopher_commit_write_diff_delta(GopherCommit* commit, - const DeltaInfo* delta) { + const GitDelta* delta) { FILE* out = commit->out; fprintf(out, "[1|diff --git a/"); - print_gopher_link(out, delta->old_file_path); + print_gopher_link(out, gitdelta_old_file_path(delta)); fprintf(out, " b/"); - print_gopher_link(out, delta->new_file_path); + print_gopher_link(out, gitdelta_new_file_path(delta)); fprintf(out, "|../file/"); - print_gopher_link(out, delta->new_file_path); + print_gopher_link(out, gitdelta_new_file_path(delta)); fprintf(out, ".gph|server|port]\n"); - if (delta->is_binary) { + if (gitdelta_is_binary(delta)) { fprintf(out, "Binary files differ.\n"); } else { - for (size_t i = 0; i < delta->hunks_len; i++) { - gopher_commit_write_diff_hunk(commit, delta->hunks[i]); + size_t hunk_count = gitdelta_hunk_count(delta); + for (size_t i = 0; i < hunk_count; i++) { + gopher_commit_write_diff_hunk(commit, gitdelta_hunk(delta, i)); } } } -void gopher_commit_write_diff_hunk(GopherCommit* commit, const Hunk* hunk) { +void gopher_commit_write_diff_hunk(GopherCommit* commit, const GitHunk* hunk) { FILE* out = commit->out; // Output header. e.g. @@ -0,0 +1,3 @@ - print_gopher_text(out, hunk->header, false); + const char* header = githunk_header(hunk); + print_gopher_text(out, header, false); fprintf(out, "\n"); // Iterate over lines in hunk. - for (size_t i = 0; i < hunk->lines_len; i++) { - const HunkLine* line = hunk->lines[i]; - if (line->old_lineno == -1) { + size_t line_count = githunk_line_count(hunk); + for (size_t i = 0; i < line_count; i++) { + const GitHunkLine* line = githunk_line(hunk, 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); + if (old_lineno == -1) { // Added line. Prefix with +. fprintf(out, "+"); - print_gopher_text_len(out, line->content, line->content_len, false); + print_gopher_text_len(out, content, content_len, false); fprintf(out, "\n"); - } else if (line->new_lineno == -1) { + } else if (new_lineno == -1) { // Removed line. Prefix with -. fprintf(out, "-"); - print_gopher_text_len(out, line->content, line->content_len, false); + print_gopher_text_len(out, content, content_len, false); fprintf(out, "\n"); } else { // Unchanged line. Prefix with ' '. No link. fprintf(out, " "); - print_gopher_text_len(out, line->content, line->content_len, false); + print_gopher_text_len(out, content, content_len, false); fprintf(out, "\n"); } } diff --git a/writer/gopher/commit.h b/writer/gopher/commit.h @@ -6,12 +6,13 @@ typedef struct GopherCommit GopherCommit; -GopherCommit* gopher_commit_create(const RepoInfo* repo, +GopherCommit* gopher_commit_create(const GitRepo* repo, const char* oid, const char* title); void gopher_commit_free(GopherCommit* commit); void gopher_commit_begin(GopherCommit* commit); -void gopher_commit_add_commit(GopherCommit* commit, const CommitInfo* ci); +void gopher_commit_add_commit(GopherCommit* commit, + const GitCommit* git_commit); void gopher_commit_end(GopherCommit* commit); #endif // GITOUT_WRITER_GOPHER_COMMIT_H_ diff --git a/writer/gopher/fileblob.c b/writer/gopher/fileblob.c @@ -13,12 +13,12 @@ #include "writer/gopher/page.h" struct GopherFileBlob { - const RepoInfo* repo; + const GitRepo* repo; FILE* out; GopherPage* page; }; -GopherFileBlob* gopher_fileblob_create(const RepoInfo* repo, const char* path) { +GopherFileBlob* gopher_fileblob_create(const GitRepo* repo, const char* path) { GopherFileBlob* blob = ecalloc(1, sizeof(GopherFileBlob)); blob->repo = repo; @@ -70,26 +70,26 @@ void gopher_fileblob_begin(GopherFileBlob* blob) { gopher_page_begin(blob->page); } -void gopher_fileblob_add_file(GopherFileBlob* blob, const FileInfo* fi) { +void gopher_fileblob_add_file(GopherFileBlob* blob, const GitFile* file) { FILE* out = blob->out; char path[PATH_MAX]; - estrlcpy(path, fi->repo_path, sizeof(path)); + estrlcpy(path, gitfile_repo_path(file), sizeof(path)); const char* filename = basename(path); if (!filename) { err(1, "basename"); } print_gopher_text(out, filename, false); - fprintf(out, " (%zdB)\n", fi->size_bytes); + fprintf(out, " (%zdB)\n", gitfile_size_bytes(file)); fprintf(out, "---\n"); - if (fi->size_lines < 0) { + if (gitfile_size_lines(file) < 0) { fprintf(out, "Binary file.\n"); return; } size_t i = 0; - const char* content = fi->content; + const char* content = gitfile_content(file); const char* end = content + strlen(content); const char* cur_line = content; while (cur_line) { diff --git a/writer/gopher/fileblob.h b/writer/gopher/fileblob.h @@ -6,10 +6,10 @@ typedef struct GopherFileBlob GopherFileBlob; -GopherFileBlob* gopher_fileblob_create(const RepoInfo* repo, const char* path); +GopherFileBlob* gopher_fileblob_create(const GitRepo* repo, const char* path); void gopher_fileblob_free(GopherFileBlob* blob); void gopher_fileblob_begin(GopherFileBlob* blob); -void gopher_fileblob_add_file(GopherFileBlob* blob, const FileInfo* fi); +void gopher_fileblob_add_file(GopherFileBlob* blob, const GitFile* file); void gopher_fileblob_end(GopherFileBlob* blob); #endif // GITOUT_WRITER_GOPHER_FILEBLOB_H_ diff --git a/writer/gopher/files.c b/writer/gopher/files.c @@ -2,18 +2,19 @@ #include <stdio.h> #include <stdlib.h> +#include <sys/types.h> #include "format.h" #include "utils.h" #include "writer/gopher/page.h" struct GopherFiles { - const RepoInfo* repo; + const GitRepo* repo; FILE* out; GopherPage* page; }; -GopherFiles* gopher_files_create(const RepoInfo* repo) { +GopherFiles* gopher_files_create(const GitRepo* repo) { GopherFiles* files = ecalloc(1, sizeof(GopherFiles)); files->repo = repo; files->out = efopen("files.gph", "w"); @@ -40,19 +41,22 @@ void gopher_files_begin(GopherFiles* files) { fprintf(out, "%8.8s\n", "Size"); } -void gopher_files_add_file(GopherFiles* files, const FileInfo* fi) { +void gopher_files_add_file(GopherFiles* files, const GitFile* file) { FILE* out = files->out; - fprintf(out, "[1|%s", fi->mode); + fprintf(out, "[1|%s", gitfile_mode(file)); fprintf(out, " "); - print_gopher_link_padded(out, fi->display_path, 50, ' '); + print_gopher_link_padded(out, gitfile_display_path(file), 50, ' '); fprintf(out, " "); - if (fi->size_lines >= 0) { - fprintf(files->out, "%7zdL", fi->size_lines); - } else if (fi->size_bytes >= 0) { - fprintf(files->out, "%7zdB", fi->size_bytes); + + ssize_t size_lines = gitfile_size_lines(file); + ssize_t size_bytes = gitfile_size_lines(file); + 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, fi->repo_path); + print_gopher_link(out, gitfile_repo_path(file)); fprintf(out, ".gph|server|port]\n"); } diff --git a/writer/gopher/files.h b/writer/gopher/files.h @@ -6,10 +6,10 @@ typedef struct GopherFiles GopherFiles; -GopherFiles* gopher_files_create(const RepoInfo* repo); +GopherFiles* gopher_files_create(const GitRepo* repo); void gopher_files_free(GopherFiles* files); void gopher_files_begin(GopherFiles* files); -void gopher_files_add_file(GopherFiles* files, const FileInfo* fi); +void gopher_files_add_file(GopherFiles* files, const GitFile* file); void gopher_files_end(GopherFiles* files); #endif // GITOUT_WRITER_GOPHER_FILES_H_ diff --git a/writer/gopher/index_writer.c b/writer/gopher/index_writer.c @@ -8,13 +8,13 @@ #include "writer/gopher/repo_index.h" struct GopherIndexWriter { - GopherRepoIndex* index_; + GopherRepoIndex* index; }; GopherIndexWriter* gopher_indexwriter_create() { GopherIndexWriter* writer = ecalloc(1, sizeof(GopherIndexWriter)); FILE* out = stdout; - writer->index_ = gopher_repoindex_create(out); + writer->index = gopher_repoindex_create(out); return writer; } @@ -22,22 +22,22 @@ void gopher_indexwriter_free(GopherIndexWriter* writer) { if (!writer) { return; } - gopher_repoindex_free(writer->index_); - writer->index_ = NULL; + gopher_repoindex_free(writer->index); + writer->index = NULL; free(writer); } void gopher_indexwriter_begin(void* writer) { GopherIndexWriter* gopher_writer = (GopherIndexWriter*)writer; - gopher_repoindex_begin(gopher_writer->index_); + gopher_repoindex_begin(gopher_writer->index); } -void gopher_indexwriter_add_repo(void* writer, RepoInfo* ri) { +void gopher_indexwriter_add_repo(void* writer, GitRepo* repo) { GopherIndexWriter* gopher_writer = (GopherIndexWriter*)writer; - gopher_repoindex_add_repo(gopher_writer->index_, ri); + gopher_repoindex_add_repo(gopher_writer->index, repo); } void gopher_indexwriter_end(void* writer) { GopherIndexWriter* gopher_writer = (GopherIndexWriter*)writer; - gopher_repoindex_end(gopher_writer->index_); + gopher_repoindex_end(gopher_writer->index); } diff --git a/writer/gopher/index_writer.h b/writer/gopher/index_writer.h @@ -8,7 +8,7 @@ typedef struct GopherIndexWriter GopherIndexWriter; GopherIndexWriter* gopher_indexwriter_create(); void gopher_indexwriter_free(GopherIndexWriter* writer); void gopher_indexwriter_begin(void* writer); -void gopher_indexwriter_add_repo(void* writer, RepoInfo* ri); +void gopher_indexwriter_add_repo(void* writer, GitRepo* repo); void gopher_indexwriter_end(void* writer); #endif // GITOUT_WRITER_GOPHER_INDEX_WRITER_H_ diff --git a/writer/gopher/log.c b/writer/gopher/log.c @@ -9,7 +9,7 @@ #include "writer/gopher/page.h" struct GopherLog { - const RepoInfo* repo; + const GitRepo* repo; FILE* out; Cache* cache; GopherPage* page; @@ -17,9 +17,9 @@ struct GopherLog { size_t unlogged_commits; }; -static void write_commit_row(FILE* out, const CommitInfo* ci); +static void write_commit_row(FILE* out, const GitCommit* commit); -GopherLog* gopher_log_create(const RepoInfo* repo) { +GopherLog* gopher_log_create(const GitRepo* repo) { GopherLog* log = ecalloc(1, sizeof(GopherLog)); log->repo = repo; log->out = efopen("log.gph", "w"); @@ -62,11 +62,11 @@ void gopher_log_begin(GopherLog* log) { fprintf(out, "%s\n", "Author"); } -void gopher_log_add_commit(GopherLog* log, const CommitInfo* ci) { +void gopher_log_add_commit(GopherLog* log, const GitCommit* commit) { if (log->cache) { - cache_add_commit_row(log->cache, ci); + cache_add_commit_row(log->cache, commit); } else if (log->remaining_commits > 0) { - write_commit_row(log->out, ci); + write_commit_row(log->out, commit); log->remaining_commits--; } else { log->unlogged_commits++; @@ -88,14 +88,15 @@ void gopher_log_end(GopherLog* log) { gopher_page_end(log->page); } -void write_commit_row(FILE* out, const CommitInfo* ci) { +void write_commit_row(FILE* out, const GitCommit* commit) { fprintf(out, "[1|"); - print_time_short(out, ci->author_time); + print_time_short(out, gitcommit_author_time(commit)); fprintf(out, " "); - if (ci->summary) { - print_gopher_link_padded(out, ci->summary, 40, ' '); + const char* summary = gitcommit_summary(commit); + if (summary) { + print_gopher_link_padded(out, summary, 40, ' '); fprintf(out, " "); } - print_gopher_link(out, ci->author_name); - fprintf(out, "|commit/%s.gph|server|port]\n", ci->oid); + print_gopher_link(out, gitcommit_author_name(commit)); + fprintf(out, "|commit/%s.gph|server|port]\n", gitcommit_oid(commit)); } diff --git a/writer/gopher/log.h b/writer/gopher/log.h @@ -9,13 +9,13 @@ typedef struct GopherLog GopherLog; -GopherLog* gopher_log_create(const RepoInfo* repo); +GopherLog* gopher_log_create(const GitRepo* repo); void gopher_log_free(GopherLog* log); void gopher_log_set_cachefile(GopherLog* log, const char* cachefile); void gopher_log_set_commit_limit(GopherLog* log, size_t count); bool gopher_log_can_add_commits(const GopherLog* log); void gopher_log_begin(GopherLog* log); -void gopher_log_add_commit(GopherLog* log, const CommitInfo* commit); +void gopher_log_add_commit(GopherLog* log, const GitCommit* commit); void gopher_log_end(GopherLog* log); #endif // GITOUT_WRITER_GOPHER_LOG_H_ diff --git a/writer/gopher/page.c b/writer/gopher/page.c @@ -8,13 +8,13 @@ struct GopherPage { FILE* out; - const RepoInfo* repo; + const GitRepo* repo; char* title; char* relpath; }; GopherPage* gopher_page_create(FILE* out, - const RepoInfo* repo, + const GitRepo* repo, const char* title, const char* relpath) { GopherPage* page = ecalloc(1, sizeof(GopherPage)); @@ -39,37 +39,43 @@ void gopher_page_free(GopherPage* page) { void gopher_page_begin(GopherPage* page) { FILE* out = page->out; print_gopher_text(out, page->title, false); - if (page->title[0] != '\0' && page->repo->short_name[0] != '\0') { + const char* short_name = gitrepo_short_name(page->repo); + if (page->title[0] != '\0' && short_name[0] != '\0') { fprintf(out, " - "); - print_gopher_text(out, page->repo->short_name, false); + print_gopher_text(out, short_name, false); } - if (page->title[0] != '\0' && page->repo->description[0] != '\0') { + const char* description = gitrepo_description(page->repo); + if (page->title[0] != '\0' && description[0] != '\0') { fprintf(out, " - "); - print_gopher_text(out, page->repo->description, false); + print_gopher_text(out, description, false); fprintf(out, "\n"); } - if (page->repo->clone_url[0] != '\0') { + const char* clone_url = gitrepo_clone_url(page->repo); + if (clone_url[0] != '\0') { fprintf(out, "[h|git clone "); - print_gopher_link(out, page->repo->clone_url); + print_gopher_link(out, clone_url); fprintf(out, "|URL:"); - print_gopher_link(out, page->repo->clone_url); + print_gopher_link(out, clone_url); fprintf(out, "|server|port]\n"); } fprintf(out, "[1|Log|%slog.gph|server|port]\n", page->relpath); fprintf(out, "[1|Files|%sfiles.gph|server|port]\n", page->relpath); fprintf(out, "[1|Refs|%srefs.gph|server|port]\n", page->relpath); - if (page->repo->submodules[0] != '\0') { + const char* submodules = gitrepo_submodules(page->repo); + if (submodules[0] != '\0') { fprintf(out, "[1|Submodules|%sfile/%s.gph|server|port]\n", page->relpath, - page->repo->submodules); + submodules); } - if (page->repo->readme[0] != '\0') { + const char* readme = gitrepo_readme(page->repo); + if (readme[0] != '\0') { fprintf(out, "[1|README|%sfile/%s.gph|server|port]\n", page->relpath, - page->repo->readme); + readme); } - if (page->repo->license[0] != '\0') { + const char* license = gitrepo_license(page->repo); + if (license[0] != '\0') { fprintf(out, "[1|LICENSE|%sfile/%s.gph|server|port]\n", page->relpath, - page->repo->license); + license); } fprintf(out, "---\n"); } diff --git a/writer/gopher/page.h b/writer/gopher/page.h @@ -8,7 +8,7 @@ typedef struct GopherPage GopherPage; GopherPage* gopher_page_create(FILE* out, - const RepoInfo* repo, + const GitRepo* repo, const char* title, const char* relpath); void gopher_page_free(GopherPage* page); diff --git a/writer/gopher/refs.c b/writer/gopher/refs.c @@ -15,7 +15,7 @@ typedef struct { } GopherRefsTable; struct GopherRefs { - const RepoInfo* repo; + const GitRepo* repo; FILE* out; GopherPage* page; GopherRefsTable* branches; @@ -28,7 +28,7 @@ static GopherRefsTable* gopher_refstable_create(const char* title, static void gopher_refstable_free(GopherRefsTable* table); static void gopher_refstable_begin(GopherRefsTable* table); static void gopher_refstable_add_ref(GopherRefsTable* table, - const ReferenceInfo* ri); + const GitReference* ref); static void gopher_refstable_end(GopherRefsTable* table); GopherRefsTable* gopher_refstable_create(const char* title, @@ -60,16 +60,16 @@ void gopher_refstable_begin(GopherRefsTable* table) { fprintf(out, " %s\n", "Author"); } -void gopher_refstable_add_ref(GopherRefsTable* table, const ReferenceInfo* ri) { - CommitInfo* ci = ri->ci; +void gopher_refstable_add_ref(GopherRefsTable* table, const GitReference* ref) { + GitCommit* commit = gitreference_commit(ref); FILE* out = table->out; fprintf(out, " "); - print_gopher_link_padded(out, ri->shorthand, 32, ' '); + print_gopher_link_padded(out, gitreference_shorthand(ref), 32, ' '); fprintf(out, " "); - print_time_short(out, ci->author_time); + print_time_short(out, gitcommit_author_time(commit)); fprintf(out, " "); - print_gopher_link_padded(out, ci->author_name, 25, '\0'); + print_gopher_link_padded(out, gitcommit_author_name(commit), 25, '\0'); fprintf(out, "\n"); } @@ -78,7 +78,7 @@ void gopher_refstable_end(GopherRefsTable* table) { fprintf(out, "\n"); } -GopherRefs* gopher_refs_create(const RepoInfo* repo) { +GopherRefs* gopher_refs_create(const GitRepo* repo) { GopherRefs* refs = ecalloc(1, sizeof(GopherRefs)); refs->repo = repo; refs->out = efopen("refs.gph", "w"); @@ -105,15 +105,15 @@ void gopher_refs_begin(GopherRefs* refs) { gopher_page_begin(refs->page); } -void gopher_refs_add_ref(GopherRefs* refs, const ReferenceInfo* ri) { - switch (ri->type) { +void gopher_refs_add_ref(GopherRefs* refs, const GitReference* ref) { + switch (gitreference_type(ref)) { case kReftypeBranch: if (!refs->branches) { refs->branches = gopher_refstable_create("Branches", "branches", refs->out); gopher_refstable_begin(refs->branches); } - gopher_refstable_add_ref(refs->branches, ri); + gopher_refstable_add_ref(refs->branches, ref); break; case kReftypeTag: if (refs->branches) { @@ -125,7 +125,7 @@ void gopher_refs_add_ref(GopherRefs* refs, const ReferenceInfo* ri) { refs->tags = gopher_refstable_create("Tags", "tags", refs->out); gopher_refstable_begin(refs->tags); } - gopher_refstable_add_ref(refs->tags, ri); + gopher_refstable_add_ref(refs->tags, ref); break; } } diff --git a/writer/gopher/refs.h b/writer/gopher/refs.h @@ -6,10 +6,10 @@ typedef struct GopherRefs GopherRefs; -GopherRefs* gopher_refs_create(const RepoInfo* repo); +GopherRefs* gopher_refs_create(const GitRepo* repo); void gopher_refs_free(GopherRefs* refs); void gopher_refs_begin(GopherRefs* refs); -void gopher_refs_add_ref(GopherRefs* refs, const ReferenceInfo* ri); +void gopher_refs_add_ref(GopherRefs* refs, const GitReference* ref); void gopher_refs_end(GopherRefs* refs); #endif // GITOUT_WRITER_GOPHER_REFS_H_ diff --git a/writer/gopher/repo_index.c b/writer/gopher/repo_index.c @@ -33,20 +33,20 @@ void gopher_repoindex_begin(GopherRepoIndex* index) { fprintf(out, "%s\n", "Last commit"); } -static void print_author_time(const CommitInfo* ci, void* user_data) { +static void print_author_time(const GitCommit* commit, void* user_data) { FILE* out = (FILE*)user_data; - print_time_short(out, ci->author_time); + print_time_short(out, gitcommit_author_time(commit)); } -void gopher_repoindex_add_repo(GopherRepoIndex* index, RepoInfo* ri) { +void gopher_repoindex_add_repo(GopherRepoIndex* index, GitRepo* repo) { FILE* out = index->out; fprintf(out, "[1|"); - print_gopher_link_padded(out, ri->short_name, 20, ' '); + print_gopher_link_padded(out, gitrepo_short_name(repo), 20, ' '); fprintf(out, " "); - print_gopher_link_padded(out, ri->description, 39, ' '); + print_gopher_link_padded(out, gitrepo_description(repo), 39, ' '); fprintf(out, " "); - repoinfo_for_commit(ri, "HEAD", print_author_time, out); - fprintf(out, "|%s/log.gph|server|port]\n", ri->short_name); + gitrepo_for_commit(repo, "HEAD", print_author_time, out); + fprintf(out, "|%s/log.gph|server|port]\n", gitrepo_short_name(repo)); } void gopher_repoindex_end(GopherRepoIndex* index) { diff --git a/writer/gopher/repo_index.h b/writer/gopher/repo_index.h @@ -10,7 +10,7 @@ typedef struct GopherRepoIndex GopherRepoIndex; GopherRepoIndex* gopher_repoindex_create(FILE* out); void gopher_repoindex_free(GopherRepoIndex* index); void gopher_repoindex_begin(GopherRepoIndex* index); -void gopher_repoindex_add_repo(GopherRepoIndex* index, RepoInfo* ri); +void gopher_repoindex_add_repo(GopherRepoIndex* index, GitRepo* repo); void gopher_repoindex_end(GopherRepoIndex* index); #endif // GITOUT_WRITER_GOPHER_REPOINDEX_H_ diff --git a/writer/gopher/repo_writer.c b/writer/gopher/repo_writer.c @@ -19,22 +19,22 @@ #include "writer/gopher/refs.h" struct GopherRepoWriter { - const RepoInfo* repo_; - GopherRefs* refs_; - GopherLog* log_; - Atom* atom_; - Atom* tags_; - GopherFiles* files_; + const GitRepo* repo; + GopherRefs* refs; + GopherLog* log; + Atom* atom; + Atom* tags; + GopherFiles* files; }; -GopherRepoWriter* gopher_repowriter_create(const RepoInfo* repo) { +GopherRepoWriter* gopher_repowriter_create(const GitRepo* repo) { GopherRepoWriter* writer = ecalloc(1, sizeof(GopherRepoWriter)); - writer->repo_ = repo; - writer->refs_ = gopher_refs_create(repo); - writer->log_ = gopher_log_create(repo); - writer->atom_ = atom_create(repo, kAtomTypeAll); - writer->tags_ = atom_create(repo, kAtomTypeTags); - writer->files_ = gopher_files_create(repo); + writer->repo = repo; + writer->refs = gopher_refs_create(repo); + writer->log = gopher_log_create(repo); + writer->atom = atom_create(repo, kAtomTypeAll); + writer->tags = atom_create(repo, kAtomTypeTags); + writer->files = gopher_files_create(repo); return writer; } @@ -42,33 +42,33 @@ void gopher_repowriter_free(GopherRepoWriter* writer) { if (!writer) { return; } - gopher_refs_free(writer->refs_); - writer->refs_ = NULL; - gopher_log_free(writer->log_); - writer->log_ = NULL; - atom_free(writer->atom_); - writer->atom_ = NULL; - atom_free(writer->tags_); - writer->tags_ = NULL; - gopher_files_free(writer->files_); - writer->files_ = NULL; + gopher_refs_free(writer->refs); + writer->refs = NULL; + gopher_log_free(writer->log); + writer->log = NULL; + atom_free(writer->atom); + writer->atom = NULL; + atom_free(writer->tags); + writer->tags = NULL; + gopher_files_free(writer->files); + writer->files = NULL; free(writer); } void gopher_repowriter_set_log_cachefile(void* writer, const char* cachefile) { GopherRepoWriter* gopher_writer = (GopherRepoWriter*)writer; - gopher_log_set_cachefile(gopher_writer->log_, cachefile); + gopher_log_set_cachefile(gopher_writer->log, cachefile); } void gopher_repowriter_set_log_commit_limit(void* writer, size_t count) { GopherRepoWriter* gopher_writer = (GopherRepoWriter*)writer; - gopher_log_set_commit_limit(gopher_writer->log_, count); + gopher_log_set_commit_limit(gopher_writer->log, count); } void gopher_repowriter_set_baseurl(void* writer, const char* baseurl) { GopherRepoWriter* gopher_writer = (GopherRepoWriter*)writer; - atom_set_baseurl(gopher_writer->atom_, baseurl); - atom_set_baseurl(gopher_writer->tags_, baseurl); + atom_set_baseurl(gopher_writer->atom, baseurl); + atom_set_baseurl(gopher_writer->tags, baseurl); } void gopher_repowriter_begin(void* writer) { @@ -76,65 +76,70 @@ void gopher_repowriter_begin(void* writer) { mkdir("commit", S_IRWXU | S_IRWXG | S_IRWXO); mkdir("file", S_IRWXU | S_IRWXG | S_IRWXO); - gopher_refs_begin(gopher_writer->refs_); - gopher_log_begin(gopher_writer->log_); - atom_begin(gopher_writer->atom_); - atom_begin(gopher_writer->tags_); - gopher_files_begin(gopher_writer->files_); + gopher_refs_begin(gopher_writer->refs); + gopher_log_begin(gopher_writer->log); + atom_begin(gopher_writer->atom); + atom_begin(gopher_writer->tags); + gopher_files_begin(gopher_writer->files); } -void gopher_repowriter_add_commit(void* writer, const CommitInfo* ci) { +void gopher_repowriter_add_commit(void* writer, const GitCommit* git_commit) { GopherRepoWriter* gopher_writer = (GopherRepoWriter*)writer; char filename[PATH_MAX]; - if (snprintf(filename, sizeof(filename), "%s.gph", ci->oid) < 0) { + if (snprintf(filename, sizeof(filename), "%s.gph", + gitcommit_oid(git_commit)) < 0) { err(1, "snprintf"); } char path[PATH_MAX]; path_concat(path, sizeof(path), "commit", filename); - atom_add_commit(gopher_writer->atom_, ci, path, "", ""); + atom_add_commit(gopher_writer->atom, git_commit, path, "", ""); - if (gopher_log_can_add_commits(gopher_writer->log_)) { - gopher_log_add_commit(gopher_writer->log_, ci); + if (gopher_log_can_add_commits(gopher_writer->log)) { + gopher_log_add_commit(gopher_writer->log, git_commit); GopherCommit* commit = - gopher_commit_create(gopher_writer->repo_, ci->oid, ci->summary); + gopher_commit_create(gopher_writer->repo, gitcommit_oid(git_commit), + gitcommit_summary(git_commit)); gopher_commit_begin(commit); - gopher_commit_add_commit(commit, ci); + gopher_commit_add_commit(commit, git_commit); gopher_commit_end(commit); gopher_commit_free(commit); } } -void gopher_repowriter_add_reference(void* writer, const ReferenceInfo* ri) { +void gopher_repowriter_add_reference(void* writer, const GitReference* ref) { GopherRepoWriter* gopher_writer = (GopherRepoWriter*)writer; - gopher_refs_add_ref(gopher_writer->refs_, ri); - if (ri->type == kReftypeTag) { + gopher_refs_add_ref(gopher_writer->refs, ref); + if (gitreference_type(ref) == kReftypeTag) { + GitCommit* commit = gitreference_commit(ref); char filename[PATH_MAX]; - if (snprintf(filename, sizeof(filename), "%s.gph", ri->ci->oid) < 0) { + if (snprintf(filename, sizeof(filename), "%s.gph", gitcommit_oid(commit)) < + 0) { err(1, "snprintf"); } char path[PATH_MAX]; path_concat(path, sizeof(path), "commit", filename); - atom_add_commit(gopher_writer->tags_, ri->ci, path, "", ri->shorthand); + atom_add_commit(gopher_writer->tags, commit, path, "", + gitreference_shorthand(ref)); } } -void gopher_repowriter_add_file(void* writer, const FileInfo* fi) { +void gopher_repowriter_add_file(void* writer, const GitFile* file) { GopherRepoWriter* gopher_writer = (GopherRepoWriter*)writer; - gopher_files_add_file(gopher_writer->files_, fi); + gopher_files_add_file(gopher_writer->files, file); GopherFileBlob* blob = - gopher_fileblob_create(gopher_writer->repo_, fi->repo_path); + gopher_fileblob_create(gopher_writer->repo, gitfile_repo_path(file)); gopher_fileblob_begin(blob); - gopher_fileblob_add_file(blob, fi); + gopher_fileblob_add_file(blob, file); gopher_fileblob_end(blob); gopher_fileblob_free(blob); } void gopher_repowriter_end(void* writer) { GopherRepoWriter* gopher_writer = (GopherRepoWriter*)writer; - gopher_refs_end(gopher_writer->refs_); - gopher_log_end(gopher_writer->log_); - atom_end(gopher_writer->atom_); - atom_end(gopher_writer->tags_); - gopher_files_end(gopher_writer->files_); + gopher_refs_end(gopher_writer->refs); + gopher_log_end(gopher_writer->log); + atom_end(gopher_writer->atom); + atom_end(gopher_writer->tags); + gopher_files_end(gopher_writer->files); } diff --git a/writer/gopher/repo_writer.h b/writer/gopher/repo_writer.h @@ -10,15 +10,15 @@ typedef struct GopherRepoWriter GopherRepoWriter; -GopherRepoWriter* gopher_repowriter_create(const RepoInfo* repo); +GopherRepoWriter* gopher_repowriter_create(const GitRepo* repo); void gopher_repowriter_free(GopherRepoWriter* writer); void gopher_repowriter_set_log_cachefile(void* writer, const char* cachefile); void gopher_repowriter_set_log_commit_limit(void* writer, size_t count); void gopher_repowriter_set_baseurl(void* writer, const char* baseurl); void gopher_repowriter_begin(void* writer); -void gopher_repowriter_add_commit(void* writer, const CommitInfo* ci); -void gopher_repowriter_add_reference(void* writer, const ReferenceInfo* ri); -void gopher_repowriter_add_file(void* writer, const FileInfo* fi); +void gopher_repowriter_add_commit(void* writer, const GitCommit* commit); +void gopher_repowriter_add_reference(void* writer, const GitReference* ref); +void gopher_repowriter_add_file(void* writer, const GitFile* file); void gopher_repowriter_end(void* writer); #endif // GITOUT_WRITER_GOPHER_REPO_WRITER_H_ diff --git a/writer/html/commit.c b/writer/html/commit.c @@ -13,28 +13,31 @@ #include "utils.h" #include "writer/html/page.h" -struct Commit { +struct HtmlCommit { FILE* out; Page* page; }; -static void commit_write_summary(Commit* commit, const CommitInfo* ci); -static void commit_write_diffstat(Commit* commit, const CommitInfo* ci); -static void commit_write_diffstat_row(Commit* commit, - size_t row, - const DeltaInfo* delta); -static void commit_write_diff_content(Commit* commit, const CommitInfo* ci); -static void commit_write_diff_delta(Commit* commit, - size_t file_num, - const DeltaInfo* delta); -static void commit_write_diff_hunk(Commit* commit, - size_t file_num, - const Hunk* hunk); - -Commit* commit_create(const RepoInfo* repo, - const char* oid, - const char* title) { - Commit* commit = ecalloc(1, sizeof(Commit)); +static void html_commit_write_summary(HtmlCommit* commit, + const GitCommit* git_commit); +static void html_commit_write_diffstat(HtmlCommit* commit, + const GitCommit* git_commit); +static void html_commit_write_diffstat_row(HtmlCommit* commit, + size_t row, + const GitDelta* delta); +static void html_commit_write_diff_content(HtmlCommit* commit, + const GitCommit* git_commit); +static void html_commit_write_diff_delta(HtmlCommit* commit, + size_t file_num, + const GitDelta* delta); +static void html_commit_write_diff_hunk(HtmlCommit* commit, + size_t file_num, + const GitHunk* hunk); + +HtmlCommit* html_commit_create(const GitRepo* repo, + const char* oid, + const char* title) { + HtmlCommit* commit = ecalloc(1, sizeof(HtmlCommit)); char filename[PATH_MAX]; if (snprintf(filename, sizeof(filename), "%s.html", oid) < 0) { err(1, "snprintf"); @@ -46,7 +49,7 @@ Commit* commit_create(const RepoInfo* repo, return commit; } -void commit_free(Commit* commit) { +void html_commit_free(HtmlCommit* commit) { if (!commit) { return; } @@ -57,175 +60,208 @@ void commit_free(Commit* commit) { free(commit); } -void commit_begin(Commit* commit) { +void html_commit_begin(HtmlCommit* commit) { page_begin(commit->page); } -void commit_add_commit(Commit* commit, const CommitInfo* ci) { +void html_commit_add_commit(HtmlCommit* commit, const GitCommit* git_commit) { static const uint64_t kDiffMaxFiles = 1000; static const uint64_t kDiffMaxDeltas = 1000; static const uint64_t kDiffMaxDeltaLines = 100000; + FILE* out = commit->out; - commit_write_summary(commit, ci); + html_commit_write_summary(commit, git_commit); - if (ci->deltas_len == 0) { + size_t deltas_len = gitcommit_delta_count(git_commit); + if (deltas_len == 0) { return; } - if (ci->filecount > kDiffMaxFiles || ci->deltas_len > kDiffMaxDeltas || - ci->addcount > kDiffMaxDeltaLines || ci->delcount > kDiffMaxDeltaLines) { - fprintf(commit->out, "<pre>Diff is too large, output suppressed.</pre>\n"); + size_t addcount = gitcommit_addcount(git_commit); + size_t delcount = gitcommit_delcount(git_commit); + size_t filecount = gitcommit_filecount(git_commit); + if (filecount > kDiffMaxFiles || deltas_len > kDiffMaxDeltas || + addcount > kDiffMaxDeltaLines || delcount > kDiffMaxDeltaLines) { + fprintf(out, "<pre>Diff is too large, output suppressed.</pre>\n"); return; } - commit_write_diffstat(commit, ci); - commit_write_diff_content(commit, ci); + html_commit_write_diffstat(commit, git_commit); + html_commit_write_diff_content(commit, git_commit); } -void commit_end(Commit* commit) { +void html_commit_end(HtmlCommit* commit) { page_end(commit->page); } -void commit_write_summary(Commit* commit, const CommitInfo* ci) { +void html_commit_write_summary(HtmlCommit* commit, + const GitCommit* git_commit) { FILE* out = commit->out; + const char* oid = gitcommit_oid(git_commit); fprintf(out, "<pre><b>commit</b> "); - fprintf(out, "<a href=\"../commit/%s.html\">%s</a>\n", ci->oid, ci->oid); + fprintf(out, "<a href=\"../commit/%s.html\">%s</a>\n", oid, oid); - if (ci->parentoid[0] != '\0') { - const char* oid = ci->parentoid; + const char* parentoid = gitcommit_parentoid(git_commit); + if (parentoid[0] != '\0') { fprintf(out, "<b>parent</b> "); - fprintf(out, "<a href=\"../commit/%s.html\">%s</a>\n", oid, oid); + fprintf(out, "<a href=\"../commit/%s.html\">%s</a>\n", parentoid, + parentoid); } fprintf(out, "<b>Author:</b> "); - print_xml_encoded(commit->out, ci->author_name); + print_xml_encoded(out, gitcommit_author_name(git_commit)); fprintf(out, " &lt;<a href=\"mailto:"); - print_xml_encoded(commit->out, ci->author_email); + print_xml_encoded(out, gitcommit_author_email(git_commit)); fprintf(out, "\">"); - print_xml_encoded(commit->out, ci->author_email); + print_xml_encoded(out, gitcommit_author_email(git_commit)); fprintf(out, "</a>&gt;\n"); fprintf(out, "<b>Date:</b> "); - print_time(out, ci->author_time, ci->author_timezone_offset); + print_time(out, gitcommit_author_time(git_commit), + gitcommit_author_timezone_offset(git_commit)); fprintf(out, "\n"); - if (ci->msg) { + const char* message = gitcommit_message(git_commit); + if (message) { fprintf(out, "\n"); - print_xml_encoded(commit->out, ci->msg); + print_xml_encoded(out, message); fprintf(out, "\n"); } } -void commit_write_diffstat(Commit* commit, const CommitInfo* ci) { +void html_commit_write_diffstat(HtmlCommit* commit, + const GitCommit* git_commit) { fprintf(commit->out, "<b>Diffstat:</b>\n<table>"); - for (size_t i = 0; i < ci->deltas_len; i++) { - commit_write_diffstat_row(commit, i, ci->deltas[i]); + size_t delta_count = gitcommit_delta_count(git_commit); + for (size_t i = 0; i < delta_count; i++) { + html_commit_write_diffstat_row(commit, i, gitcommit_delta(git_commit, i)); } fprintf(commit->out, "</table></pre>"); } -void commit_write_diffstat_row(Commit* commit, - size_t row, - const DeltaInfo* delta) { +void html_commit_write_diffstat_row(HtmlCommit* commit, + size_t row, + const GitDelta* delta) { static const size_t kGraphWidth = 78; + FILE* out = commit->out; - if (delta->status == ' ') { - fprintf(commit->out, "<tr><td>"); + char status = gitdelta_status(delta); + if (status == ' ') { + fprintf(out, "<tr><td>"); } else { - char c = delta->status; - fprintf(commit->out, "<tr><td class=\"%c\">%c", c, c); + fprintf(out, "<tr><td class=\"%c\">%c", status, status); } - fprintf(commit->out, "</td>"); - fprintf(commit->out, "<td>"); - fprintf(commit->out, "<a href=\"#h%zu\">", row); - print_xml_encoded(commit->out, delta->old_file_path); - if (strcmp(delta->old_file_path, delta->new_file_path) != 0) { - fprintf(commit->out, " -&gt; "); - print_xml_encoded(commit->out, delta->new_file_path); + 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); + print_xml_encoded(out, old_file_path); + if (strcmp(old_file_path, new_file_path) != 0) { + fprintf(out, " -&gt; "); + print_xml_encoded(out, new_file_path); } - fprintf(commit->out, "</a></td>"); + fprintf(out, "</a></td>"); - size_t changed = delta->addcount + delta->delcount; - fprintf(commit->out, "<td> | </td>"); - fprintf(commit->out, "<td class=\"num\">%zu</td>", changed); - char* added_graph = deltainfo_added_graph(delta, kGraphWidth); - fprintf(commit->out, "<td><span class=\"i\">%s</span>", added_graph); + size_t changed = gitdelta_lines_added(delta) + gitdelta_lines_deleted(delta); + fprintf(out, "<td> | </td>"); + fprintf(out, "<td class=\"num\">%zu</td>", changed); + char* added_graph = gitdelta_added_graph(delta, kGraphWidth); + fprintf(out, "<td><span class=\"i\">%s</span>", added_graph); free(added_graph); - char* deleted_graph = deltainfo_deleted_graph(delta, kGraphWidth); - fprintf(commit->out, "<span class=\"d\">%s</span>", deleted_graph); + char* deleted_graph = gitdelta_deleted_graph(delta, kGraphWidth); + fprintf(out, "<span class=\"d\">%s</span>", deleted_graph); free(deleted_graph); - fprintf(commit->out, "</td></tr>\n"); + fprintf(out, "</td></tr>\n"); } -void commit_write_diff_content(Commit* commit, const CommitInfo* ci) { +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); fprintf(out, "<pre>"); fprintf(out, "%zu file%s changed, %zu insertion%s(+), %zu deletion%s(-)\n", - ci->filecount, ci->filecount == 1 ? "" : "s", // - ci->addcount, ci->addcount == 1 ? "" : "s", // - ci->delcount, ci->delcount == 1 ? "" : "s"); - fprintf(commit->out, "<hr/>"); + filecount, filecount == 1 ? "" : "s", // + addcount, addcount == 1 ? "" : "s", // + delcount, delcount == 1 ? "" : "s"); + fprintf(out, "<hr/>"); - for (size_t i = 0; i < ci->deltas_len; i++) { - commit_write_diff_delta(commit, i, ci->deltas[i]); + size_t delta_count = gitcommit_delta_count(git_commit); + for (size_t i = 0; i < delta_count; i++) { + html_commit_write_diff_delta(commit, i, gitcommit_delta(git_commit, i)); } - fprintf(commit->out, "</pre>\n"); + fprintf(out, "</pre>\n"); } -void commit_write_diff_delta(Commit* commit, - size_t file_num, - const DeltaInfo* delta) { +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); fprintf(commit->out, "<b>diff --git "); fprintf(commit->out, "a/<a id=\"h%zu\" href=\"../file/", file_num); - print_percent_encoded(commit->out, delta->old_file_path); + print_percent_encoded(commit->out, old_file_path); fprintf(commit->out, ".html\">"); - print_xml_encoded(commit->out, delta->old_file_path); + print_xml_encoded(commit->out, old_file_path); fprintf(commit->out, "</a> b/<a href=\"../file/"); - print_percent_encoded(commit->out, delta->new_file_path); + print_percent_encoded(commit->out, new_file_path); fprintf(commit->out, ".html\">"); - print_xml_encoded(commit->out, delta->new_file_path); + print_xml_encoded(commit->out, new_file_path); fprintf(commit->out, "</a></b>\n"); - if (delta->is_binary) { + if (gitdelta_is_binary(delta)) { fprintf(commit->out, "Binary files differ.\n"); } else { - for (size_t i = 0; i < delta->hunks_len; i++) { - commit_write_diff_hunk(commit, file_num, delta->hunks[i]); + size_t hunk_count = gitdelta_hunk_count(delta); + for (size_t i = 0; i < hunk_count; i++) { + html_commit_write_diff_hunk(commit, file_num, gitdelta_hunk(delta, i)); } } } -void commit_write_diff_hunk(Commit* commit, size_t file_num, const Hunk* hunk) { +void html_commit_write_diff_hunk(HtmlCommit* commit, + size_t file_num, + const GitHunk* hunk) { FILE* out = commit->out; // Output header. e.g. @@ -0,0 +1,3 @@ char hdr_id[32]; - if (snprintf(hdr_id, sizeof(hdr_id), "h%zu-%zu", file_num, hunk->id) < 0) { + size_t hunkid = githunk_id(hunk); + 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); - print_xml_encoded(out, hunk->header); + const char* header = githunk_header(hunk); + print_xml_encoded(out, header); fprintf(out, "</a>"); // Iterate over lines in hunk. - for (size_t i = 0; i < hunk->lines_len; i++) { - const HunkLine* line = hunk->lines[i]; + size_t line_count = githunk_line_count(hunk); + for (size_t i = 0; i < line_count; i++) { + const GitHunkLine* line = githunk_line(hunk, i); + size_t hunklineid = githunkline_id(line); char line_id[64]; - if (snprintf(line_id, sizeof(line_id), "%s-%zu", hdr_id, line->id) < 0) { + if (snprintf(line_id, sizeof(line_id), "%s-%zu", hdr_id, hunklineid) < 0) { err(1, "snprintf"); } - if (line->old_lineno == -1) { + 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); + if (old_lineno == -1) { // Added line. Prefix with +. fprintf(out, "<a href=\"#%s\" id=\"%s\" class=\"i\">+", line_id, line_id); - print_xml_encoded_len(out, line->content, line->content_len, false); + print_xml_encoded_len(out, content, content_len, false); fprintf(out, "\n</a>"); - } else if (line->new_lineno == -1) { + } else if (new_lineno == -1) { // Removed line. Prefix with -. fprintf(out, "<a href=\"#%s\" id=\"%s\" class=\"d\">-", line_id, line_id); - print_xml_encoded_len(out, line->content, line->content_len, false); + print_xml_encoded_len(out, content, content_len, false); fprintf(out, "\n</a>"); } else { // Unchanged line. Prefix with ' '. No link. fprintf(out, " "); - print_xml_encoded_len(out, line->content, line->content_len, false); + print_xml_encoded_len(out, content, content_len, false); fprintf(out, "\n"); } } diff --git a/writer/html/commit.h b/writer/html/commit.h @@ -4,12 +4,14 @@ #include "git/commit.h" #include "git/repo.h" -typedef struct Commit Commit; +typedef struct HtmlCommit HtmlCommit; -Commit* commit_create(const RepoInfo* repo, const char* oid, const char* title); -void commit_free(Commit* commit); -void commit_begin(Commit* commit); -void commit_add_commit(Commit* commit, const CommitInfo* ci); -void commit_end(Commit* commit); +HtmlCommit* html_commit_create(const GitRepo* repo, + const char* oid, + const char* title); +void html_commit_free(HtmlCommit* commit); +void html_commit_begin(HtmlCommit* commit); +void html_commit_add_commit(HtmlCommit* commit, const GitCommit* git_commit); +void html_commit_end(HtmlCommit* commit); #endif // GITOUT_WRITER_HTML_COMMIT_H_ diff --git a/writer/html/fileblob.c b/writer/html/fileblob.c @@ -13,12 +13,12 @@ #include "writer/html/page.h" struct FileBlob { - const RepoInfo* repo; + const GitRepo* repo; FILE* out; Page* page; }; -FileBlob* fileblob_create(const RepoInfo* repo, const char* path) { +FileBlob* fileblob_create(const GitRepo* repo, const char* path) { FileBlob* blob = ecalloc(1, sizeof(FileBlob)); blob->repo = repo; @@ -70,21 +70,21 @@ void fileblob_begin(FileBlob* blob) { page_begin(blob->page); } -void fileblob_add_file(FileBlob* blob, const FileInfo* fi) { +void fileblob_add_file(FileBlob* blob, const GitFile* file) { FILE* out = blob->out; fprintf(out, "<p> "); char path[PATH_MAX]; - estrlcpy(path, fi->repo_path, sizeof(path)); + estrlcpy(path, gitfile_repo_path(file), sizeof(path)); const char* filename = basename(path); if (!filename) { err(1, "basename"); } print_xml_encoded(out, filename); - fprintf(out, " (%zdB)", fi->size_bytes); + fprintf(out, " (%zdB)", gitfile_size_bytes(file)); fprintf(out, "</p><hr/>"); - if (fi->size_lines < 0) { + if (gitfile_size_lines(file) < 0) { fprintf(out, "<p>Binary file.</p>\n"); return; } @@ -92,7 +92,7 @@ void fileblob_add_file(FileBlob* blob, const FileInfo* fi) { fprintf(out, "<pre id=\"blob\">\n"); size_t i = 0; - const char* content = fi->content; + const char* content = gitfile_content(file); const char* end = content + strlen(content); const char* cur_line = content; while (cur_line) { diff --git a/writer/html/fileblob.h b/writer/html/fileblob.h @@ -6,10 +6,10 @@ typedef struct FileBlob FileBlob; -FileBlob* fileblob_create(const RepoInfo* repo, const char* path); +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 FileInfo* fi); +void fileblob_add_file(FileBlob* blob, const GitFile* file); void fileblob_end(FileBlob* blob); #endif // GITOUT_WRITER_HTML_FILEBLOB_H_ diff --git a/writer/html/files.c b/writer/html/files.c @@ -2,18 +2,19 @@ #include <stdio.h> #include <stdlib.h> +#include <sys/types.h> #include "format.h" #include "utils.h" #include "writer/html/page.h" struct Files { - const RepoInfo* repo; + const GitRepo* repo; FILE* out; Page* page; }; -Files* files_create(const RepoInfo* repo) { +Files* files_create(const GitRepo* repo) { Files* files = ecalloc(1, sizeof(Files)); files->repo = repo; files->out = efopen("files.html", "w"); @@ -44,23 +45,29 @@ void files_begin(Files* files) { "</thead><tbody>\n"); } -void files_add_file(Files* files, const FileInfo* fi) { - fprintf(files->out, "<tr><td>%s</td>", fi->mode); - fprintf(files->out, "<td><a href=\"file/"); - print_percent_encoded(files->out, fi->repo_path); - fprintf(files->out, ".html\">"); - print_xml_encoded(files->out, fi->display_path); - fprintf(files->out, "</a>"); - if (fi->commit_oid[0] != '\0') { - fprintf(files->out, " @ %s", fi->commit_oid); +void files_add_file(Files* files, const GitFile* file) { + FILE* out = files->out; + + fprintf(out, "<tr><td>%s</td>", gitfile_mode(file)); + fprintf(out, "<td><a href=\"file/"); + print_percent_encoded(out, gitfile_repo_path(file)); + fprintf(out, ".html\">"); + print_xml_encoded(out, gitfile_display_path(file)); + fprintf(out, "</a>"); + const char* oid = gitfile_commit_oid(file); + if (oid[0] != '\0') { + fprintf(out, " @ %s", oid); } - fprintf(files->out, "</td><td class=\"num\" align=\"right\">"); - if (fi->size_lines >= 0) { - fprintf(files->out, "%zdL", fi->size_lines); - } else if (fi->size_bytes >= 0) { - fprintf(files->out, "%zdB", fi->size_bytes); + fprintf(out, "</td><td class=\"num\" align=\"right\">"); + + ssize_t size_lines = gitfile_size_lines(file); + ssize_t size_bytes = gitfile_size_lines(file); + if (size_lines >= 0) { + fprintf(out, "%zdL", size_lines); + } else if (size_bytes >= 0) { + fprintf(out, "%zdB", size_bytes); } - fprintf(files->out, "</td></tr>\n"); + fprintf(out, "</td></tr>\n"); } void files_end(Files* files) { diff --git a/writer/html/files.h b/writer/html/files.h @@ -6,10 +6,10 @@ typedef struct Files Files; -Files* files_create(const RepoInfo* repo); +Files* files_create(const GitRepo* repo); void files_free(Files* files); void files_begin(Files* files); -void files_add_file(Files* files, const FileInfo* fi); +void files_add_file(Files* files, const GitFile* file); void files_end(Files* files); #endif // GITOUT_WRITER_HTML_FILES_H_ diff --git a/writer/html/index_writer.c b/writer/html/index_writer.c @@ -8,13 +8,13 @@ #include "writer/html/repo_index.h" struct HtmlIndexWriter { - HtmlRepoIndex* index_; + HtmlRepoIndex* index; }; HtmlIndexWriter* html_indexwriter_create() { HtmlIndexWriter* writer = ecalloc(1, sizeof(HtmlIndexWriter)); FILE* out = stdout; - writer->index_ = html_repoindex_create(out); + writer->index = html_repoindex_create(out); return writer; } @@ -22,27 +22,27 @@ void html_indexwriter_free(HtmlIndexWriter* writer) { if (!writer) { return; } - html_repoindex_free(writer->index_); - writer->index_ = NULL; + html_repoindex_free(writer->index); + writer->index = NULL; free(writer); } void html_indexwriter_set_me_url(void* writer, const char* url) { HtmlIndexWriter* html_writer = (HtmlIndexWriter*)writer; - html_repoindex_set_me_url(html_writer->index_, url); + html_repoindex_set_me_url(html_writer->index, url); } void html_indexwriter_begin(void* writer) { HtmlIndexWriter* html_writer = (HtmlIndexWriter*)writer; - html_repoindex_begin(html_writer->index_); + html_repoindex_begin(html_writer->index); } -void html_indexwriter_add_repo(void* writer, RepoInfo* ri) { +void html_indexwriter_add_repo(void* writer, GitRepo* repo) { HtmlIndexWriter* html_writer = (HtmlIndexWriter*)writer; - html_repoindex_add_repo(html_writer->index_, ri); + html_repoindex_add_repo(html_writer->index, repo); } void html_indexwriter_end(void* writer) { HtmlIndexWriter* html_writer = (HtmlIndexWriter*)writer; - html_repoindex_end(html_writer->index_); + html_repoindex_end(html_writer->index); } diff --git a/writer/html/index_writer.h b/writer/html/index_writer.h @@ -9,7 +9,7 @@ HtmlIndexWriter* html_indexwriter_create(); void html_indexwriter_free(HtmlIndexWriter* writer); void html_indexwriter_set_me_url(void* writer, const char* url); void html_indexwriter_begin(void* writer); -void html_indexwriter_add_repo(void* writer, RepoInfo* ri); +void html_indexwriter_add_repo(void* writer, GitRepo* repo); void html_indexwriter_end(void* writer); #endif // GITOUT_WRITER_HTML_INDEX_WRITER_H_ diff --git a/writer/html/log.c b/writer/html/log.c @@ -9,7 +9,7 @@ #include "writer/html/page.h" struct Log { - const RepoInfo* repo; + const GitRepo* repo; FILE* out; Cache* cache; Page* page; @@ -17,9 +17,9 @@ struct Log { size_t unlogged_commits; }; -static void write_commit_row(FILE* out, const CommitInfo* ci); +static void write_commit_row(FILE* out, const GitCommit* commit); -Log* log_create(const RepoInfo* repo) { +Log* log_create(const GitRepo* repo) { Log* log = ecalloc(1, sizeof(Log)); log->repo = repo; log->out = efopen("log.html", "w"); @@ -69,11 +69,11 @@ void log_begin(Log* log) { "</thead><tbody>\n"); } -void log_add_commit(Log* log, const CommitInfo* ci) { +void log_add_commit(Log* log, const GitCommit* commit) { if (log->cache) { - cache_add_commit_row(log->cache, ci); + cache_add_commit_row(log->cache, commit); } else if (log->remaining_commits > 0) { - write_commit_row(log->out, ci); + write_commit_row(log->out, commit); log->remaining_commits--; } else { log->unlogged_commits++; @@ -95,21 +95,23 @@ void log_end(Log* log) { page_end(log->page); } -void write_commit_row(FILE* out, const CommitInfo* ci) { +void write_commit_row(FILE* out, const GitCommit* commit) { fprintf(out, "<tr><td>"); - print_time_short(out, ci->author_time); + print_time_short(out, gitcommit_author_time(commit)); fprintf(out, "</td><td>"); - if (ci->summary) { - fprintf(out, "<a href=\"commit/%s.html\">", ci->oid); - print_xml_encoded(out, ci->summary); + const char* summary = gitcommit_summary(commit); + if (summary) { + fprintf(out, "<a href=\"commit/%s.html\">", gitcommit_oid(commit)); + print_xml_encoded(out, summary); fprintf(out, "</a>"); } fprintf(out, "</td><td>"); - print_xml_encoded(out, ci->author_name); + print_xml_encoded(out, gitcommit_author_name(commit)); 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", - ci->filecount, ci->addcount, ci->delcount); + gitcommit_filecount(commit), gitcommit_addcount(commit), + gitcommit_delcount(commit)); } diff --git a/writer/html/log.h b/writer/html/log.h @@ -9,13 +9,13 @@ typedef struct Log Log; -Log* log_create(const RepoInfo* repo); +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 CommitInfo* commit); +void log_add_commit(Log* log, const GitCommit* commit); void log_end(Log* log); #endif // GITOUT_WRITER_HTML_LOG_H_ diff --git a/writer/html/page.c b/writer/html/page.c @@ -7,13 +7,13 @@ struct Page { FILE* out; - const RepoInfo* repo; + const GitRepo* repo; char* title; char* relpath; }; Page* page_create(FILE* out, - const RepoInfo* repo, + const GitRepo* repo, const char* title, const char* relpath) { Page* page = ecalloc(1, sizeof(Page)); @@ -49,13 +49,15 @@ void page_begin(Page* page) { fprintf(out, "<title>"); print_xml_encoded(out, page->title); - if (page->title[0] != '\0' && page->repo->short_name[0] != '\0') { + const char* short_name = gitrepo_short_name(page->repo); + if (page->title[0] != '\0' && short_name[0] != '\0') { fprintf(out, " - "); - print_xml_encoded(out, page->repo->short_name); + print_xml_encoded(out, short_name); } - if (page->title[0] != '\0' && page->repo->description[0] != '\0') { + const char* description = gitrepo_description(page->repo); + if (page->title[0] != '\0' && description[0] != '\0') { fprintf(out, " - "); - print_xml_encoded(out, page->repo->description); + print_xml_encoded(out, description); } const char* relpath = page->relpath; @@ -65,11 +67,11 @@ void page_begin(Page* page) { relpath); fprintf(out, "<link rel=\"alternate\" type=\"application/atom+xml\" title=\""); - print_xml_encoded(out, page->repo->name); + print_xml_encoded(out, gitrepo_name(page->repo)); fprintf(out, " Atom Feed\" href=\"%satom.xml\" />\n", relpath); fprintf(out, "<link rel=\"alternate\" type=\"application/atom+xml\" title=\""); - print_xml_encoded(out, page->repo->name); + print_xml_encoded(out, gitrepo_name(page->repo)); fprintf(out, " Atom Feed (tags)\" href=\"%stags.xml\" />\n", relpath); fprintf(out, "<link rel=\"stylesheet\" type=\"text/css\" href=\"%sstyle.css\" />", @@ -79,16 +81,17 @@ void page_begin(Page* page) { fprintf(out, "<img src=\"%slogo.png\" alt=\"\" width=\"32\" height=\"32\" />", relpath); fprintf(out, "</a></td><td><h1>"); - print_xml_encoded(out, page->repo->short_name); + print_xml_encoded(out, gitrepo_short_name(page->repo)); fprintf(out, "</h1><span class=\"desc\">"); - print_xml_encoded(out, page->repo->description); + print_xml_encoded(out, gitrepo_description(page->repo)); fprintf(out, "</span></td></tr>"); - if (page->repo->clone_url[0] != '\0') { + const char* clone_url = gitrepo_clone_url(page->repo); + if (clone_url[0] != '\0') { fprintf(out, "<tr class=\"url\"><td></td><td>git clone <a href=\""); - print_xml_encoded(out, page->repo->clone_url); + print_xml_encoded(out, clone_url); fprintf(out, "\">"); - print_xml_encoded(out, page->repo->clone_url); + print_xml_encoded(out, clone_url); fprintf(out, "</a></td></tr>"); } fprintf(out, "<tr><td></td><td>\n"); @@ -96,19 +99,22 @@ void page_begin(Page* page) { fprintf(out, "<a href=\"%sfiles.html\">Files</a> | ", relpath); fprintf(out, "<a href=\"%srefs.html\">Refs</a>", relpath); - if (page->repo->submodules[0] != '\0') { + const char* submodules = gitrepo_submodules(page->repo); + if (submodules[0] != '\0') { fprintf(out, " | <a href=\"%sfile/", relpath); - print_xml_encoded(out, page->repo->submodules); + print_xml_encoded(out, submodules); fprintf(out, ".html\">Submodules</a>"); } - if (page->repo->readme[0] != '\0') { + const char* readme = gitrepo_readme(page->repo); + if (readme[0] != '\0') { fprintf(out, " | <a href=\"%sfile/", relpath); - print_xml_encoded(out, page->repo->readme); + print_xml_encoded(out, readme); fprintf(out, ".html\">README</a>"); } - if (page->repo->license[0] != '\0') { + const char* license = gitrepo_license(page->repo); + if (license[0] != '\0') { fprintf(out, " | <a href=\"%sfile/", relpath); - print_xml_encoded(out, page->repo->license); + print_xml_encoded(out, license); fprintf(out, ".html\">LICENSE</a>"); } fprintf(out, "</td></tr></table>\n<hr/>\n<div id=\"content\">\n"); diff --git a/writer/html/page.h b/writer/html/page.h @@ -8,7 +8,7 @@ typedef struct Page Page; Page* page_create(FILE* out, - const RepoInfo* repo, + const GitRepo* repo, const char* title, const char* relpath); void page_free(Page* page); diff --git a/writer/html/refs.c b/writer/html/refs.c @@ -15,7 +15,7 @@ typedef struct { } RefsTable; struct Refs { - const RepoInfo* repo; + const GitRepo* repo; FILE* out; Page* page; RefsTable* branches; @@ -27,7 +27,7 @@ static RefsTable* refstable_create(const char* title, FILE* out); static void refstable_free(RefsTable* table); static void refstable_begin(RefsTable* table); -static void refstable_add_ref(RefsTable* table, const ReferenceInfo* ri); +static void refstable_add_ref(RefsTable* table, const GitReference* ref); static void refstable_end(RefsTable* table); RefsTable* refstable_create(const char* title, const char* id, FILE* out) { @@ -62,14 +62,14 @@ void refstable_begin(RefsTable* table) { "</thead><tbody>\n"); } -void refstable_add_ref(RefsTable* table, const ReferenceInfo* ri) { - CommitInfo* ci = ri->ci; +void refstable_add_ref(RefsTable* table, const GitReference* ref) { + GitCommit* commit = gitreference_commit(ref); fprintf(table->out, "<tr><td>"); - print_xml_encoded(table->out, ri->shorthand); + print_xml_encoded(table->out, gitreference_shorthand(ref)); fprintf(table->out, "</td><td>"); - print_time_short(table->out, ci->author_time); + print_time_short(table->out, gitcommit_author_time(commit)); fprintf(table->out, "</td><td>"); - print_xml_encoded(table->out, ci->author_name); + print_xml_encoded(table->out, gitcommit_author_name(commit)); fprintf(table->out, "</td></tr>\n"); } @@ -77,7 +77,7 @@ void refstable_end(RefsTable* table) { fprintf(table->out, "</tbody></table><br/>\n"); } -Refs* refs_create(const RepoInfo* repo) { +Refs* refs_create(const GitRepo* repo) { Refs* refs = ecalloc(1, sizeof(Refs)); refs->repo = repo; refs->out = efopen("refs.html", "w"); @@ -104,14 +104,14 @@ void refs_begin(Refs* refs) { page_begin(refs->page); } -void refs_add_ref(Refs* refs, const ReferenceInfo* ri) { - switch (ri->type) { +void refs_add_ref(Refs* 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); } - refstable_add_ref(refs->branches, ri); + refstable_add_ref(refs->branches, ref); break; case kReftypeTag: if (refs->branches) { @@ -123,7 +123,7 @@ void refs_add_ref(Refs* refs, const ReferenceInfo* ri) { refs->tags = refstable_create("Tags", "tags", refs->out); refstable_begin(refs->tags); } - refstable_add_ref(refs->tags, ri); + refstable_add_ref(refs->tags, ref); break; } } diff --git a/writer/html/refs.h b/writer/html/refs.h @@ -6,10 +6,10 @@ typedef struct Refs Refs; -Refs* refs_create(const RepoInfo* repo); +Refs* refs_create(const GitRepo* repo); void refs_free(Refs* refs); void refs_begin(Refs* refs); -void refs_add_ref(Refs* refs, const ReferenceInfo* ri); +void refs_add_ref(Refs* refs, const GitReference* ref); void refs_end(Refs* refs); #endif // GITOUT_WRITER_HTML_REFS_H_ diff --git a/writer/html/repo_index.c b/writer/html/repo_index.c @@ -64,23 +64,23 @@ void html_repoindex_begin(HtmlRepoIndex* index) { "</thead><tbody>\n"); } -static void print_author_time(const CommitInfo* ci, void* user_data) { +static void print_author_time(const GitCommit* commit, void* user_data) { FILE* out = (FILE*)user_data; - print_time_short(out, ci->author_time); + print_time_short(out, gitcommit_author_time(commit)); } -void html_repoindex_add_repo(HtmlRepoIndex* index, RepoInfo* ri) { +void html_repoindex_add_repo(HtmlRepoIndex* index, GitRepo* repo) { FILE* out = index->out; fprintf(out, "<tr><td><a href=\""); - print_percent_encoded(out, ri->short_name); + print_percent_encoded(out, gitrepo_short_name(repo)); fprintf(out, "/log.html\">"); - print_xml_encoded(out, ri->short_name); + print_xml_encoded(out, gitrepo_short_name(repo)); fprintf(out, "</a></td><td>"); - print_xml_encoded(out, ri->description); + print_xml_encoded(out, gitrepo_description(repo)); fprintf(out, "</td><td>"); - print_xml_encoded(out, ri->owner); + print_xml_encoded(out, gitrepo_owner(repo)); fprintf(out, "</td><td>"); - repoinfo_for_commit(ri, "HEAD", print_author_time, out); + gitrepo_for_commit(repo, "HEAD", print_author_time, out); fprintf(out, "</td></tr>"); } diff --git a/writer/html/repo_index.h b/writer/html/repo_index.h @@ -11,7 +11,7 @@ HtmlRepoIndex* html_repoindex_create(FILE* out); void html_repoindex_free(HtmlRepoIndex* index); void html_repoindex_set_me_url(HtmlRepoIndex* index, const char* url); void html_repoindex_begin(HtmlRepoIndex* index); -void html_repoindex_add_repo(HtmlRepoIndex* index, RepoInfo* ri); +void html_repoindex_add_repo(HtmlRepoIndex* index, GitRepo* repo); void html_repoindex_end(HtmlRepoIndex* index); #endif // GITOUT_WRITER_HTML_REPOINDEX_H_ diff --git a/writer/html/repo_writer.c b/writer/html/repo_writer.c @@ -19,22 +19,22 @@ #include "writer/html/refs.h" struct HtmlRepoWriter { - const RepoInfo* repo_; - Refs* refs_; - Log* log_; - Atom* atom_; - Atom* tags_; - Files* files_; + const GitRepo* repo; + Refs* refs; + Log* log; + Atom* atom; + Atom* tags; + Files* files; }; -HtmlRepoWriter* html_repowriter_create(const RepoInfo* repo) { +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->atom_ = atom_create(repo, kAtomTypeAll); - writer->tags_ = atom_create(repo, kAtomTypeTags); - writer->files_ = files_create(repo); + writer->repo = repo; + writer->refs = refs_create(repo); + writer->log = log_create(repo); + writer->atom = atom_create(repo, kAtomTypeAll); + writer->tags = atom_create(repo, kAtomTypeTags); + writer->files = files_create(repo); return writer; } @@ -42,33 +42,33 @@ void html_repowriter_free(HtmlRepoWriter* writer) { if (!writer) { return; } - refs_free(writer->refs_); - writer->refs_ = NULL; - 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_); - writer->files_ = NULL; + refs_free(writer->refs); + writer->refs = NULL; + 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); + 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); + 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); + log_set_commit_limit(html_writer->log, count); } void html_repowriter_set_baseurl(void* writer, const char* baseurl) { HtmlRepoWriter* html_writer = (HtmlRepoWriter*)writer; - atom_set_baseurl(html_writer->atom_, baseurl); - atom_set_baseurl(html_writer->tags_, baseurl); + atom_set_baseurl(html_writer->atom, baseurl); + atom_set_baseurl(html_writer->tags, baseurl); } void html_repowriter_begin(void* writer) { @@ -76,64 +76,69 @@ 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_); - atom_begin(html_writer->atom_); - atom_begin(html_writer->tags_); - files_begin(html_writer->files_); + refs_begin(html_writer->refs); + log_begin(html_writer->log); + atom_begin(html_writer->atom); + atom_begin(html_writer->tags); + files_begin(html_writer->files); } -void html_repowriter_add_commit(void* writer, const CommitInfo* ci) { +void html_repowriter_add_commit(void* writer, const GitCommit* git_commit) { HtmlRepoWriter* html_writer = (HtmlRepoWriter*)writer; char filename[PATH_MAX]; - if (snprintf(filename, sizeof(filename), "%s.html", ci->oid) < 0) { + if (snprintf(filename, sizeof(filename), "%s.html", + gitcommit_oid(git_commit)) < 0) { err(1, "snprintf"); } char path[PATH_MAX]; path_concat(path, sizeof(path), "commit", filename); - atom_add_commit(html_writer->atom_, ci, path, "text/html", ""); - - if (log_can_add_commits(html_writer->log_)) { - log_add_commit(html_writer->log_, ci); - Commit* commit = commit_create(html_writer->repo_, ci->oid, ci->summary); - commit_begin(commit); - commit_add_commit(commit, ci); - commit_end(commit); - commit_free(commit); + 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); + HtmlCommit* commit = + html_commit_create(html_writer->repo, gitcommit_oid(git_commit), + gitcommit_summary(git_commit)); + html_commit_begin(commit); + html_commit_add_commit(commit, git_commit); + html_commit_end(commit); + html_commit_free(commit); } } -void html_repowriter_add_reference(void* writer, const ReferenceInfo* ri) { +void html_repowriter_add_reference(void* writer, const GitReference* ref) { HtmlRepoWriter* html_writer = (HtmlRepoWriter*)writer; - refs_add_ref(html_writer->refs_, ri); - if (ri->type == kReftypeTag) { + refs_add_ref(html_writer->refs, ref); + if (gitreference_type(ref) == kReftypeTag) { + GitCommit* commit = gitreference_commit(ref); char filename[PATH_MAX]; - if (snprintf(filename, sizeof(filename), "%s.html", ri->ci->oid) < 0) { + if (snprintf(filename, sizeof(filename), "%s.html", gitcommit_oid(commit)) < + 0) { err(1, "snprintf"); } char path[PATH_MAX]; path_concat(path, sizeof(path), "commit", filename); - atom_add_commit(html_writer->tags_, ri->ci, path, "text/html", - ri->shorthand); + atom_add_commit(html_writer->tags, commit, path, "text/html", + gitreference_shorthand(ref)); } } -void html_repowriter_add_file(void* writer, const FileInfo* fi) { +void html_repowriter_add_file(void* writer, const GitFile* file) { HtmlRepoWriter* html_writer = (HtmlRepoWriter*)writer; - files_add_file(html_writer->files_, fi); + files_add_file(html_writer->files, file); - FileBlob* blob = fileblob_create(html_writer->repo_, fi->repo_path); + FileBlob* blob = fileblob_create(html_writer->repo, gitfile_repo_path(file)); fileblob_begin(blob); - fileblob_add_file(blob, fi); + fileblob_add_file(blob, file); fileblob_end(blob); fileblob_free(blob); } void html_repowriter_end(void* writer) { HtmlRepoWriter* html_writer = (HtmlRepoWriter*)writer; - refs_end(html_writer->refs_); - log_end(html_writer->log_); - atom_end(html_writer->atom_); - atom_end(html_writer->tags_); - files_end(html_writer->files_); + refs_end(html_writer->refs); + log_end(html_writer->log); + atom_end(html_writer->atom); + atom_end(html_writer->tags); + files_end(html_writer->files); } diff --git a/writer/html/repo_writer.h b/writer/html/repo_writer.h @@ -10,15 +10,15 @@ typedef struct HtmlRepoWriter HtmlRepoWriter; -HtmlRepoWriter* html_repowriter_create(const RepoInfo* repo); +HtmlRepoWriter* html_repowriter_create(const GitRepo* repo); void html_repowriter_free(HtmlRepoWriter* writer); void html_repowriter_set_log_cachefile(void* writer, const char* cachefile); void html_repowriter_set_log_commit_limit(void* writer, size_t count); void html_repowriter_set_baseurl(void* writer, const char* baseurl); void html_repowriter_begin(void* writer); -void html_repowriter_add_commit(void* writer, const CommitInfo* ci); -void html_repowriter_add_reference(void* writer, const ReferenceInfo* ri); -void html_repowriter_add_file(void* writer, const FileInfo* fi); +void html_repowriter_add_commit(void* writer, const GitCommit* commit); +void html_repowriter_add_reference(void* writer, const GitReference* ref); +void html_repowriter_add_file(void* writer, const GitFile* file); void html_repowriter_end(void* writer); #endif // GITOUT_WRITER_HTML_REPO_WRITER_H_ diff --git a/writer/index_writer.c b/writer/index_writer.c @@ -9,7 +9,7 @@ typedef void (*IndexWriterVoidFunc)(void* impl); typedef void (*IndexWriterStringFunc)(void* impl, const char* url); -typedef void (*IndexWriterRepoInfoFunc)(void* impl, RepoInfo* ri); +typedef void (*IndexWriterRepoInfoFunc)(void* impl, GitRepo* repo); struct IndexWriter { /* Writer implementation. */ @@ -62,8 +62,8 @@ void indexwriter_begin(IndexWriter* writer) { writer->begin(writer->impl); } -void indexwriter_add_repo(IndexWriter* writer, RepoInfo* ri) { - writer->add_repo(writer->impl, ri); +void indexwriter_add_repo(IndexWriter* writer, GitRepo* repo) { + writer->add_repo(writer->impl, repo); } void indexwriter_end(IndexWriter* writer) { diff --git a/writer/index_writer.h b/writer/index_writer.h @@ -14,7 +14,7 @@ IndexWriter* indexwriter_create(IndexWriterType type); void indexwriter_free(IndexWriter* writer); void indexwriter_set_me_url(IndexWriter* writer, const char* url); void indexwriter_begin(IndexWriter* writer); -void indexwriter_add_repo(IndexWriter* writer, RepoInfo* ri); +void indexwriter_add_repo(IndexWriter* writer, GitRepo* repo); void indexwriter_end(IndexWriter* writer); #endif // GITOUT_WRITER_INDEX_WRITER_H_ diff --git a/writer/repo_writer.c b/writer/repo_writer.c @@ -11,9 +11,9 @@ typedef void (*RepoWriterSetLogCachefile)(void* writer, const char* cachefile); typedef void (*RepoWriterSetLogCommitLimit)(void* writer, size_t count); typedef void (*RepoWriterSetBaseurl)(void* writer, const char* baseurl); typedef void (*RepoWriterBegin)(void* writer); -typedef void (*RepoWriterAddCommit)(void* writer, const CommitInfo* ci); -typedef void (*RepoWriterAddReference)(void* writer, const ReferenceInfo* ri); -typedef void (*RepoWriterAddFile)(void* writer, const FileInfo* fi); +typedef void (*RepoWriterAddCommit)(void* writer, const GitCommit* commit); +typedef void (*RepoWriterAddReference)(void* writer, const GitReference* ref); +typedef void (*RepoWriterAddFile)(void* writer, const GitFile* file); typedef void (*RepoWriterEnd)(void* writer); struct RepoWriter { @@ -34,18 +34,18 @@ struct RepoWriter { RepoWriterEnd end; }; -static RepoWriter* htmlrepowriter_create(RepoInfo* ri); +static RepoWriter* htmlrepowriter_create(GitRepo* repo); static void htmlrepowriter_free(RepoWriter* writer); -static RepoWriter* gopherrepowriter_create(RepoInfo* ri); +static RepoWriter* gopherrepowriter_create(GitRepo* repo); static void gopherrepowriter_free(RepoWriter* writer); -RepoWriter* repowriter_create(RepoWriterType type, RepoInfo* ri) { +RepoWriter* repowriter_create(RepoWriterType type, GitRepo* repo) { switch (type) { case kRepoWriterTypeHtml: - return htmlrepowriter_create(ri); + return htmlrepowriter_create(repo); case kRepoWriterTypeGopher: - return gopherrepowriter_create(ri); + return gopherrepowriter_create(repo); } errx(1, "unknown RepoWriterType %d", type); } @@ -81,16 +81,16 @@ void repowriter_begin(RepoWriter* writer) { writer->begin(writer->impl); } -void repowriter_add_commit(RepoWriter* writer, const CommitInfo* ci) { - writer->add_commit(writer->impl, ci); +void repowriter_add_commit(RepoWriter* writer, const GitCommit* commit) { + writer->add_commit(writer->impl, commit); } -void repowriter_add_reference(RepoWriter* writer, const ReferenceInfo* ri) { - writer->add_reference(writer->impl, ri); +void repowriter_add_reference(RepoWriter* writer, const GitReference* ref) { + writer->add_reference(writer->impl, ref); } -void repowriter_add_file(RepoWriter* writer, const FileInfo* fi) { - writer->add_file(writer->impl, fi); +void repowriter_add_file(RepoWriter* writer, const GitFile* file) { + writer->add_file(writer->impl, file); } void repowriter_end(RepoWriter* writer) { @@ -99,9 +99,9 @@ void repowriter_end(RepoWriter* writer) { /* HtmlRepoWriter setup/teardown. */ -RepoWriter* htmlrepowriter_create(RepoInfo* ri) { +RepoWriter* htmlrepowriter_create(GitRepo* repo) { RepoWriter* writer = ecalloc(1, sizeof(RepoWriter)); - HtmlRepoWriter* html_writer = html_repowriter_create(ri); + HtmlRepoWriter* html_writer = html_repowriter_create(repo); writer->type = kRepoWriterTypeHtml; writer->impl = html_writer; writer->set_log_cachefile = html_repowriter_set_log_cachefile; @@ -126,9 +126,9 @@ void htmlrepowriter_free(RepoWriter* writer) { /* GopherRepoWriter setup/teardown. */ -RepoWriter* gopherrepowriter_create(RepoInfo* ri) { +RepoWriter* gopherrepowriter_create(GitRepo* repo) { RepoWriter* writer = ecalloc(1, sizeof(RepoWriter)); - GopherRepoWriter* gopher_writer = gopher_repowriter_create(ri); + GopherRepoWriter* gopher_writer = gopher_repowriter_create(repo); writer->type = kRepoWriterTypeGopher; writer->impl = gopher_writer; writer->set_log_cachefile = gopher_repowriter_set_log_cachefile; diff --git a/writer/repo_writer.h b/writer/repo_writer.h @@ -15,17 +15,17 @@ typedef enum { typedef struct RepoWriter RepoWriter; -RepoWriter* repowriter_create(RepoWriterType type, RepoInfo* ri); -void repowriter_free(RepoWriter* ri); +RepoWriter* repowriter_create(RepoWriterType type, GitRepo* repo); +void repowriter_free(RepoWriter* repo); void repowriter_set_log_cachefile(RepoWriter* writer, const char* cachefile); void repowriter_set_log_commit_limit(RepoWriter* writer, size_t count); void repowriter_set_baseurl(RepoWriter* writer, const char* baseurl); void repowriter_begin(RepoWriter* writer); -void repowriter_add_commit(RepoWriter* writer, const CommitInfo* ci); -void repowriter_add_reference(RepoWriter* writer, const ReferenceInfo* ri); -void repowriter_add_file(RepoWriter* writer, const FileInfo* fi); +void repowriter_add_commit(RepoWriter* writer, const GitCommit* commit); +void repowriter_add_reference(RepoWriter* writer, const GitReference* ref); +void repowriter_add_file(RepoWriter* writer, const GitFile* file); void repowriter_end(RepoWriter* writer); #endif // GITOUT_WRITER_REPO_WRITER_H_