static page generator for VCS repositories
git clone https://www.shemshak.org/~amin/repostead
diff --git a/repostead.c b/repostead.c
index a8181ab..6a22d88 100644
--- a/repostead.c
+++ b/repostead.c
@@ -932,6 +932,96 @@ process_tree(const struct repostead_config *conf,
page_end(index_file, index_file_path);
}
+static int
+print_diff_line(const git_diff_delta *delta,
+ const git_diff_hunk *hunk,
+ const git_diff_line *line,
+ void *f) /* FILE *f */
+{
+ if (line->origin == GIT_DIFF_LINE_CONTEXT
+ || line->origin == GIT_DIFF_LINE_ADDITION
+ || line->origin == GIT_DIFF_LINE_DELETION) {
+ fprintf((FILE *)f, "%c", line->origin);
+ }
+ html_escn((FILE *)f, line->content, line->content_len);
+ return 0;
+}
+
+static void
+process_commit(const struct repostead_config *conf,
+ const struct repostead_branch *br, git_commit *commit)
+{
+ char file_base_path[RS_PATH_MAX] = "";
+ char file_path[RS_PATH_MAX] = "";
+ FILE *file = NULL;
+ git_commit *parent = NULL;
+ git_tree *parent_tree = NULL;
+ git_tree *tree = NULL;
+ git_diff *diff = NULL;
+ const git_oid *oid = NULL;
+ const git_oid *parent_oid = NULL;
+ const char *oid_str;
+ const char *parent_oid_str;
+
+ if (git_commit_parentcount(commit) > 0) {
+ if (git_commit_parent(&parent, commit, 0) < 0) {
+ gitdie("git_commit_parent");
+ }
+ if (git_commit_tree(&parent_tree, parent) < 0) {
+ gitdie("git_commit_tree");
+ }
+ parent_oid = git_commit_id(parent);
+ if (!parent_oid) {
+ gitdie("git_commit_id");
+ }
+ parent_oid_str = git_oid_tostr_s(parent_oid);
+ if (!parent_oid_str) {
+ gitdie("git_oid_tostr_s");
+ }
+ }
+
+ oid = git_commit_id(commit);
+ if (!oid) {
+ gitdie("git_commit_id");
+ }
+
+ oid_str = git_oid_tostr_s(oid);
+ if (!oid_str) {
+ gitdie("git_oid_tostr_s");
+ }
+
+ if (git_commit_tree(&tree, commit) < 0) {
+ gitdie("git_commit_tree");
+ }
+
+ if (git_diff_tree_to_tree(&diff, conf->repo, parent_tree,
+ tree, NULL) < 0) {
+ gitdie("git_diff_tree_to_tree");
+ }
+
+ branch_path(file_base_path, sizeof(file_base_path), conf, br,
+ RS_LOG_ROOT, oid_str);
+ if (!path_ext(file_path, sizeof(file_path), file_base_path, "html")) {
+ die("file path too long %s.html", file_base_path);
+ }
+
+ file = page_begin(conf, file_path, oid_str, false);
+
+ fputs("<pre>", file);
+ if (git_diff_print(diff, GIT_DIFF_FORMAT_PATCH,
+ print_diff_line, file) < 0) {
+ gitdie("git_diff_print");
+ }
+ fputs("</pre>", file);
+
+ page_end(file, file_path);
+
+ git_diff_free(diff);
+ git_tree_free(tree);
+ git_tree_free(parent_tree);
+ git_commit_free(parent);
+}
+
static void
process_commits(const struct repostead_config *conf,
const struct repostead_branch *br, const git_oid *commit_oid)
@@ -964,7 +1054,11 @@ process_commits(const struct repostead_config *conf,
if (git_commit_lookup(&c, conf->repo, &oid) == 0) {
const char *summary = git_commit_summary(c);
const git_signature *author = git_commit_author(c);
+ const char *oid_str = git_oid_tostr_s(&oid);
+ if (!oid_str) {
+ gitdie("git_oid_tostr_s");
+ }
fputs("<tr class=\"commit\">", index_file);
if (author) {
struct tm tm;
@@ -978,15 +1072,18 @@ process_commits(const struct repostead_config *conf,
fputs(tbuf, index_file);
fputs("</td>", index_file);
}
- fputs("<td class=\"summary\">", index_file);
+ fputs("<td class=\"summary\"><a href=\"", index_file);
+ url_enc(index_file, oid_str);
+ fputs(".html\">", index_file);
html_esc(index_file, summary ? summary : "(no message)");
- fputs("</td>", index_file);
+ fputs("</a></td>", index_file);
if (author) {
fputs("<td class=\"author\">", index_file);
html_esc(index_file, author->name ? author->name : "");
fputs("</td>", index_file);
}
fputs("</tr>", index_file);
+ process_commit(conf, br, c);
git_commit_free(c);
} else {
gitdie("git_commit_lookup");
@@ -1162,9 +1259,7 @@ process_repo(struct repostead_config *conf)
page_end(index_file, index_file_path);
- if (head_tree) {
- git_tree_free(head_tree);
- }
+ git_tree_free(head_tree);
git_branch_iterator_free(brit);
git_repository_free(conf->repo);
conf->repo = NULL;