+ fputs("<table id=\"log\"><thead>\n<tr><td><b>Date</b></td>"
+ "<td><b>Commit</b></td>"
+ "<td><b>Author</b></td><td class=\"num\" align=\"right\"><b>Files</b></td>"
+ "<td class=\"num\" align=\"right\"><b>+</b></td>"
+ "<td class=\"num\" align=\"right\"><b>-</b></td></tr>\n</thead><tbody>\n", fp);
+
+ if (cachefile && head) {
+ /* read from cache file (does not need to exist) */
+ if ((rcachefp = fopen(cachefile, "r"))) {
+ if (!fgets(lastoidstr, sizeof(lastoidstr), rcachefp))
+ errx(1, "%s: no object id", cachefile);
+ if (git_oid_fromstr(&lastoid, lastoidstr))
+ errx(1, "%s: invalid object id", cachefile);
+ }
+
+ /* write log to (temporary) cache */
+ if ((fd = mkstemp(tmppath)) == -1)
+ err(1, "mkstemp");
+ if (!(wcachefp = fdopen(fd, "w")))
+ err(1, "fdopen: '%s'", tmppath);
+ /* write last commit id (HEAD) */
+ git_oid_tostr(buf, sizeof(buf), head);
+ fprintf(wcachefp, "%s\n", buf);
+
+ writelog(fp, head);
+
+ if (rcachefp) {
+ /* append previous log to log.html and the new cache */
+ while (!feof(rcachefp)) {
+ n = fread(buf, 1, sizeof(buf), rcachefp);
+ if (ferror(rcachefp))
+ err(1, "fread");
+ if (fwrite(buf, 1, n, fp) != n ||
+ fwrite(buf, 1, n, wcachefp) != n)
+ err(1, "fwrite");
+ }
+ fclose(rcachefp);
+ }
+ fclose(wcachefp);
+ } else {
+ if (head)
+ writelog(fp, head);
+ }
+
+ fputs("</tbody></table>", fp);