diff --git a/stagit.c b/stagit.c
@@ -598,29 +598,68 @@ size_t writeblobhtml(FILE *fp, const git_blob *blob)
void printcommit(FILE *fp, struct commitinfo *ci)
{
- fprintf(fp, "<b>commit</b> <a href=\"%scommit/%s.html\">%s</a>\n",
+ fprintf(fp,
+ "<article class=\"commit\">\n"
+ "<dl>\n"
+ "<dt>Commit</dt>\n"
+ "<dd><a href=\"%scommit/%s.html\">%s</a></dd>\n",
relpath, ci->oid, ci->oid);
if (ci->parentoid[0])
- fprintf(fp, "<b>parent</b> <a href=\"%scommit/%s.html\">%s</a>\n",
+ fprintf(fp,
+ "<dt>Parent</dt>\n"
+ "<dd><a href=\"%scommit/%s.html\">%s</a></dd>\n",
relpath, ci->parentoid, ci->parentoid);
if (ci->author) {
- fputs("<b>Author:</b> ", fp);
+ fputs("<dt>Author</dt>\n<dd>", fp);
xmlencode(fp, ci->author->name, strlen(ci->author->name));
fputs(" <<a href=\"mailto:", fp);
xmlencode(fp, ci->author->email, strlen(ci->author->email));
fputs("\">", fp);
xmlencode(fp, ci->author->email, strlen(ci->author->email));
- fputs("</a>>\n<b>Date:</b> ", fp);
+ fputs("</a>></dd>\n"
+ "<dt>Date</dt>\n"
+ "<dd><time datetime=\"",
+ fp);
+ printtimez(fp, &(ci->author->when));
+ fputs("\">", fp);
printtime(fp, &(ci->author->when));
- putc('\n', fp);
+ fputs("</time></dd>\n", fp);
}
+
+ fputs("</dl>\n", fp);
+
+ /* Split the message in paragraphs */
if (ci->msg) {
- putc('\n', fp);
- xmlencode(fp, ci->msg, strlen(ci->msg));
- putc('\n', fp);
+ size_t total_len = strlen(ci->msg);
+ size_t i = 0, len = 0;
+ char *s = ci->msg;
+
+ while (i < total_len) {
+ /* If we encounter the string "\n\n" */
+ if (ci->msg[i] == '\n' && i + 1 < total_len && ci->msg[i + 1] == '\n') {
+ fputs("<p>", fp);
+ xmlencode(fp, s, len);
+ fputs("</p>\n", fp);
+
+ while (ci->msg[i] == '\n') i++;
+ s = ci->msg + i;
+ len = 0;
+ } else {
+ i++;
+ len++;
+ }
+ }
+
+ if (len > 0) {
+ fputs("<p>", fp);
+ xmlencode(fp, s, len);
+ fputs("</p>\n", fp);
+ }
}
+
+ fputs("</article>\n", fp);
}
void printshowfile(FILE *fp, struct commitinfo *ci)
@@ -642,15 +681,35 @@ void printshowfile(FILE *fp, struct commitinfo *ci)
ci->ndeltas > 1000 ||
ci->addcount > 100000 ||
ci->delcount > 100000) {
- fputs("Diff is too large, output suppressed.\n", fp);
+ fputs("<p>Diff is too large, output suppressed.</p>\n", fp);
return;
}
/* diff stat */
- fputs("<b>Diffstat:</b>\n<table>", fp);
+ fprintf(fp,
+ "<h2>Diffstat</h2>\n"
+ "<p>%zu file%s changed, %zu insertion%s, %zu deletion%s\n</p>",
+ ci->filecount, ci->filecount == 1 ? "" : "s",
+ ci->addcount, ci->addcount == 1 ? "" : "s",
+ ci->delcount, ci->delcount == 1 ? "" : "s");
+
+ fputs("<table>\n"
+ "<thead>\n"
+ "<tr>\n"
+ "<td>Mode</td>\n"
+ "<td>File Name</td>\n"
+ "<td>N° Changes</td>\n"
+ "<td align=\"right\">Insertions/Deletions</td>\n"
+ "</tr>\n"
+ "</thead>\n"
+ "<tbody>\n",
+ fp);
+
for (i = 0; i < ci->ndeltas; i++) {
delta = git_patch_get_delta(ci->deltas[i]->patch);
+ fputs("<tr>\n", fp);
+
switch (delta->status) {
case GIT_DELTA_ADDED: c = 'A'; break;
case GIT_DELTA_COPIED: c = 'C'; break;
@@ -660,12 +719,9 @@ void printshowfile(FILE *fp, struct commitinfo *ci)
case GIT_DELTA_TYPECHANGE: c = 'T'; break;
default: c = ' '; break;
}
- if (c == ' ')
- fprintf(fp, "<tr><td>%c", c);
- else
- fprintf(fp, "<tr><td class=\"%c\">%c", c, c);
+ fprintf(fp, "<td>%c</td>\n", c);
- fprintf(fp, "</td><td><a href=\"#h%zu\">", i);
+ fprintf(fp, "<td><a href=\"#h%zu\">", i);
xmlencode(fp, delta->old_file.path, strlen(delta->old_file.path));
if (strcmp(delta->old_file.path, delta->new_file.path)) {
fputs(" -> ", fp);
@@ -685,21 +741,22 @@ void printshowfile(FILE *fp, struct commitinfo *ci)
memset(&linestr, '+', add);
memset(&linestr[add], '-', del);
- fprintf(fp, "</a></td><td> | </td><td>%zu</td><td><span class=\"i\">",
+ fprintf(fp,
+ "</a></td>\n"
+ "<td>%zu</td>\n"
+ "<td><span class=\"i\">",
ci->deltas[i]->addcount + ci->deltas[i]->delcount);
fwrite(&linestr, 1, add, fp);
fputs("</span><span class=\"d\">", fp);
fwrite(&linestr[add], 1, del, fp);
- fputs("</span></td></tr>\n", fp);
+ fputs("</span></td>\n</tr>\n", fp);
}
- fprintf(fp, "</table>\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");
- fputs("</pre>\n</div>\n<div class=\"codeblock\">\n<pre>", fp);
+ fputs("</tbody>\n</table>\n", fp);
+
for (i = 0; i < ci->ndeltas; i++) {
+ fputs("<div class=\"codeblock\">\n<pre>", fp);
patch = ci->deltas[i]->patch;
delta = git_patch_get_delta(patch);
fprintf(fp, "<b>diff --git a/<a id=\"h%zu\" href=\"%sfile/", i, relpath);
@@ -743,6 +800,8 @@ void printshowfile(FILE *fp, struct commitinfo *ci)
fputs("</a>", fp);
}
}
+
+ fputs("</pre>\n</div>\n", fp);
}
}
@@ -768,9 +827,9 @@ void writelogline(FILE *fp, struct commitinfo *ci)
fputs("</a>\n</p>\n", fp);
} else {
fprintf(
- fp,
- "<p>\n<a href=\"%scommit/%s.html\">Commit %s</a>\n</p>\n",
- relpath,
+ fp,
+ "<p>\n<a href=\"%scommit/%s.html\">Commit %s</a>\n</p>\n",
+ relpath,
ci->oid,
ci->oid
);
@@ -836,11 +895,8 @@ int writelog(FILE *fp, const git_oid *oid)
fpfile = efopen(path, "w");
writeheader(fpfile, ci->summary);
fputs("</ul>\n", fp);
- fputs("<div class=\"codeblock\">\n", fpfile);
- fputs("<pre>", fpfile);
+
printshowfile(fpfile, ci);
- fputs("</pre>\n", fpfile);
- fputs("</div>\n", fpfile);
writefooter(fpfile);
fclose(fpfile);
}