gout

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

commit d4ebfd7c3b98dbeaa6340ba14e1064d96134d537
parent d9c2243fc66e52616102044bff3b6ee98796cbb2
Author: Chris Bracken <chris@bracken.jp>
Date:   Fri, 20 Feb 2026 15:48:41 +0900

writer: add tests for Diff is too large output

Diffstat:
Msrc/writer/gopher/commit.c | 23++++++++++++++++++-----
Msrc/writer/gopher/commit.h | 6++++++
Msrc/writer/gopher/commit_tests.c | 28++++++++++++++++++++++++++++
Msrc/writer/html/commit.c | 23++++++++++++++++++-----
Msrc/writer/html/commit.h | 6++++++
Msrc/writer/html/commit_tests.c | 28++++++++++++++++++++++++++++
6 files changed, 104 insertions(+), 10 deletions(-)

diff --git a/src/writer/gopher/commit.c b/src/writer/gopher/commit.c @@ -17,6 +17,9 @@ struct GopherCommit { FILE* out; const FileSystem* fs; GopherPage* page; + uint64_t max_files; + uint64_t max_deltas; + uint64_t max_delta_lines; }; static void gopher_commit_write_summary(GopherCommit* commit, @@ -50,6 +53,9 @@ GopherCommit* gopher_commit_create(const GitRepo* repo, } free(path); commit->page = gopher_page_create(commit->out, repo, fs, title, ""); + commit->max_files = 1000; + commit->max_deltas = 1000; + commit->max_delta_lines = 100000; return commit; } @@ -70,9 +76,6 @@ void gopher_commit_begin(GopherCommit* commit) { 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, git_commit); @@ -84,8 +87,9 @@ void gopher_commit_add_commit(GopherCommit* commit, size_t addcount = git_commit->addcount; size_t delcount = git_commit->delcount; size_t filecount = git_commit->filecount; - if (filecount > kDiffMaxFiles || deltas_len > kDiffMaxDeltas || - addcount > kDiffMaxDeltaLines || delcount > kDiffMaxDeltaLines) { + if (filecount > commit->max_files || deltas_len > commit->max_deltas || + addcount > commit->max_delta_lines || + delcount > commit->max_delta_lines) { fprintf(out, "Diff is too large, output suppressed.\n"); return; } @@ -94,6 +98,15 @@ void gopher_commit_add_commit(GopherCommit* commit, gopher_commit_write_diff_content(commit, git_commit); } +void gopher_commit_set_diff_limits(GopherCommit* commit, + uint64_t max_files, + uint64_t max_deltas, + uint64_t max_delta_lines) { + commit->max_files = max_files; + commit->max_deltas = max_deltas; + commit->max_delta_lines = max_delta_lines; +} + void gopher_commit_end(GopherCommit* commit) { gopher_page_end(commit->page); } diff --git a/src/writer/gopher/commit.h b/src/writer/gopher/commit.h @@ -1,6 +1,8 @@ #ifndef GOUT_WRITER_GOPHER_COMMIT_H_ #define GOUT_WRITER_GOPHER_COMMIT_H_ +#include <stdint.h> + #include "git/commit.h" #include "git/repo.h" #include "utils.h" @@ -15,6 +17,10 @@ void gopher_commit_free(GopherCommit* commit); void gopher_commit_begin(GopherCommit* commit); void gopher_commit_add_commit(GopherCommit* commit, const GitCommit* git_commit); +void gopher_commit_set_diff_limits(GopherCommit* commit, + uint64_t max_files, + uint64_t max_deltas, + uint64_t max_delta_lines); void gopher_commit_end(GopherCommit* commit); #endif // GOUT_WRITER_GOPHER_COMMIT_H_ diff --git a/src/writer/gopher/commit_tests.c b/src/writer/gopher/commit_tests.c @@ -123,3 +123,31 @@ UTEST_F(gopher_commit, diff) { EXPECT_STR_SEQUENCE(buf, "[1|diff --git", "file.txt", "@@ -1,2 +1,2 @@", " unchanged", "+added line", "-removed line"); } + +UTEST_F(gopher_commit, too_large_diff) { + GitRepo repo = {.short_name = "test-repo"}; + GopherCommit* commit_writer = + gopher_commit_create(&repo, g_fs_inmemory, "sha123", "Commit Title"); + + /* Set limits small to trigger suppression. */ + gopher_commit_set_diff_limits(commit_writer, 0, 1000, 1000); + + GitCommit commit = { + .oid = "sha123", + .author_name = "User", + .author_email = "user@example.com", + .summary = "Summary", + .message = "Message", + .deltas_len = 1, + .filecount = 1, + }; + + gopher_commit_begin(commit_writer); + gopher_commit_add_commit(commit_writer, &commit); + gopher_commit_end(commit_writer); + gopher_commit_free(commit_writer); + + const char* buf = inmemory_fs_get_buffer("commit/sha123.gph"); + ASSERT_NE(NULL, buf); + EXPECT_NE(NULL, strstr(buf, "Diff is too large, output suppressed.")); +} diff --git a/src/writer/html/commit.c b/src/writer/html/commit.c @@ -17,6 +17,9 @@ struct HtmlCommit { FILE* out; const FileSystem* fs; HtmlPage* page; + uint64_t max_files; + uint64_t max_deltas; + uint64_t max_delta_lines; }; static void html_commit_write_summary(HtmlCommit* commit, @@ -53,6 +56,9 @@ HtmlCommit* html_commit_create(const GitRepo* repo, } free(path); commit->page = html_page_create(commit->out, repo, fs, title, "../"); + commit->max_files = 1000; + commit->max_deltas = 1000; + commit->max_delta_lines = 100000; return commit; } @@ -72,9 +78,6 @@ void html_commit_begin(HtmlCommit* commit) { } 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; html_commit_write_summary(commit, git_commit); @@ -86,8 +89,9 @@ void html_commit_add_commit(HtmlCommit* commit, const GitCommit* git_commit) { size_t addcount = git_commit->addcount; size_t delcount = git_commit->delcount; size_t filecount = git_commit->filecount; - if (filecount > kDiffMaxFiles || deltas_len > kDiffMaxDeltas || - addcount > kDiffMaxDeltaLines || delcount > kDiffMaxDeltaLines) { + if (filecount > commit->max_files || deltas_len > commit->max_deltas || + addcount > commit->max_delta_lines || + delcount > commit->max_delta_lines) { fprintf(out, "<pre>Diff is too large, output suppressed.</pre>\n"); return; } @@ -96,6 +100,15 @@ void html_commit_add_commit(HtmlCommit* commit, const GitCommit* git_commit) { html_commit_write_diff_content(commit, git_commit); } +void html_commit_set_diff_limits(HtmlCommit* commit, + uint64_t max_files, + uint64_t max_deltas, + uint64_t max_delta_lines) { + commit->max_files = max_files; + commit->max_deltas = max_deltas; + commit->max_delta_lines = max_delta_lines; +} + void html_commit_end(HtmlCommit* commit) { html_page_end(commit->page); } diff --git a/src/writer/html/commit.h b/src/writer/html/commit.h @@ -1,6 +1,8 @@ #ifndef GOUT_WRITER_HTML_COMMIT_H_ #define GOUT_WRITER_HTML_COMMIT_H_ +#include <stdint.h> + #include "git/commit.h" #include "git/repo.h" #include "utils.h" @@ -14,6 +16,10 @@ HtmlCommit* html_commit_create(const GitRepo* repo, 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_set_diff_limits(HtmlCommit* commit, + uint64_t max_files, + uint64_t max_deltas, + uint64_t max_delta_lines); void html_commit_end(HtmlCommit* commit); #endif // GOUT_WRITER_HTML_COMMIT_H_ diff --git a/src/writer/html/commit_tests.c b/src/writer/html/commit_tests.c @@ -123,3 +123,31 @@ UTEST_F(html_commit, diff) { EXPECT_STR_SEQUENCE(buf, "diff --git", "file.txt", "@@ -1,2 +1,2 @@", " unchanged", "+added line", "-removed line"); } + +UTEST_F(html_commit, too_large_diff) { + GitRepo repo = {.short_name = "test-repo"}; + HtmlCommit* commit_writer = + html_commit_create(&repo, g_fs_inmemory, "sha123", "Commit Title"); + + /* Set limits small to trigger suppression. */ + html_commit_set_diff_limits(commit_writer, 0, 1000, 1000); + + GitCommit commit = { + .oid = "sha123", + .author_name = "User", + .author_email = "user@example.com", + .summary = "Summary", + .message = "Message", + .deltas_len = 1, + .filecount = 1, + }; + + html_commit_begin(commit_writer); + html_commit_add_commit(commit_writer, &commit); + html_commit_end(commit_writer); + html_commit_free(commit_writer); + + const char* buf = inmemory_fs_get_buffer("commit/sha123.html"); + ASSERT_NE(NULL, buf); + EXPECT_NE(NULL, strstr(buf, "Diff is too large, output suppressed.")); +}