]> git.armaanb.net Git - stagit.git/blob - urmoms.c
writelog: remove return value, it was unused
[stagit.git] / urmoms.c
1 #include <sys/stat.h>
2
3 #include <err.h>
4 #include <errno.h>
5 #include <inttypes.h>
6 #include <libgen.h>
7 #include <limits.h>
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <string.h>
11 #include <unistd.h>
12
13 #include "config.h"
14 #include "git2.h"
15
16 struct commitinfo {
17         const git_oid *id;
18
19         char oid[GIT_OID_HEXSZ + 1];
20         char parentoid[GIT_OID_HEXSZ + 1];
21
22         const git_signature *author;
23         const char *summary;
24         const char *msg;
25
26         git_diff_stats *stats;
27         git_diff       *diff;
28         git_commit     *commit;
29         git_commit     *parent;
30         git_tree       *commit_tree;
31         git_tree       *parent_tree;
32
33         size_t addcount;
34         size_t delcount;
35         size_t filecount;
36 };
37
38 static git_repository *repo;
39
40 static const char *relpath = "";
41 static const char *repodir;
42
43 static char name[255];
44 static char description[255];
45 static int hasreadme, haslicense;
46
47 void
48 commitinfo_free(struct commitinfo *ci)
49 {
50         if (!ci)
51                 return;
52
53         git_diff_stats_free(ci->stats);
54         git_diff_free(ci->diff);
55         git_tree_free(ci->commit_tree);
56         git_tree_free(ci->parent_tree);
57         git_commit_free(ci->commit);
58 }
59
60 struct commitinfo *
61 commitinfo_getbyoid(const git_oid *id)
62 {
63         struct commitinfo *ci;
64         git_diff_options opts;
65         int error;
66
67         if (!(ci = calloc(1, sizeof(struct commitinfo))))
68                 err(1, "calloc");
69
70         ci->id = id;
71         if (git_commit_lookup(&(ci->commit), repo, id))
72                 goto err;
73
74         /* TODO: show tags when commit has it */
75         git_oid_tostr(ci->oid, sizeof(ci->oid), git_commit_id(ci->commit));
76         git_oid_tostr(ci->parentoid, sizeof(ci->parentoid), git_commit_parent_id(ci->commit, 0));
77
78         ci->author = git_commit_author(ci->commit);
79         ci->summary = git_commit_summary(ci->commit);
80         ci->msg = git_commit_message(ci->commit);
81
82         if ((error = git_commit_tree(&(ci->commit_tree), ci->commit)))
83                 goto err; /* TODO: handle error */
84         if (!(error = git_commit_parent(&(ci->parent), ci->commit, 0))) {
85                 if ((error = git_commit_tree(&(ci->parent_tree), ci->parent)))
86                         goto err;
87         } else {
88                 ci->parent = NULL;
89                 ci->parent_tree = NULL;
90         }
91
92         git_diff_init_options(&opts, GIT_DIFF_OPTIONS_VERSION);
93         opts.flags |= GIT_DIFF_DISABLE_PATHSPEC_MATCH;
94         if ((error = git_diff_tree_to_tree(&(ci->diff), repo, ci->parent_tree, ci->commit_tree, &opts)))
95                 goto err;
96         if (git_diff_get_stats(&(ci->stats), ci->diff))
97                 goto err;
98
99         ci->addcount = git_diff_stats_insertions(ci->stats);
100         ci->delcount = git_diff_stats_deletions(ci->stats);
101         ci->filecount = git_diff_stats_files_changed(ci->stats);
102
103         /* TODO: show tag when commit has it */
104
105         return ci;
106
107 err:
108         commitinfo_free(ci);
109         free(ci);
110
111         return NULL;
112 }
113
114 FILE *
115 efopen(const char *name, const char *flags)
116 {
117         FILE *fp;
118
119         if (!(fp = fopen(name, flags)))
120                 err(1, "fopen");
121
122         return fp;
123 }
124
125 /* Escape characters below as HTML 2.0 / XML 1.0. */
126 void
127 xmlencode(FILE *fp, const char *s, size_t len)
128 {
129         size_t i;
130
131         for (i = 0; *s && i < len; s++, i++) {
132                 switch(*s) {
133                 case '<':  fputs("&lt;",   fp); break;
134                 case '>':  fputs("&gt;",   fp); break;
135                 case '\'': fputs("&apos;", fp); break;
136                 case '&':  fputs("&amp;",  fp); break;
137                 case '"':  fputs("&quot;", fp); break;
138                 default:   fputc(*s, fp);
139                 }
140         }
141 }
142
143 /* Some implementations of basename(3) return a pointer to a static
144  * internal buffer (OpenBSD). Others modify the contents of `path` (POSIX).
145  * This is a wrapper function that is compatible with both versions.
146  * The program will error out if basename(3) failed, this can only happen
147  * with the OpenBSD version. */
148 char *
149 xbasename(const char *path)
150 {
151         char *p, *b;
152
153         if (!(p = strdup(path)))
154                 err(1, "strdup");
155         if (!(b = basename(p)))
156                 err(1, "basename");
157         if (!(b = strdup(b)))
158                 err(1, "strdup");
159         free(p);
160
161         return b;
162 }
163
164 int
165 mkdirp(const char *path)
166 {
167         char tmp[PATH_MAX], *p;
168
169         strlcpy(tmp, path, sizeof(tmp)); /* TODO: bring in libutil? */
170         for (p = tmp + (tmp[0] == '/'); *p; p++) {
171                 if (*p != '/')
172                         continue;
173                 *p = '\0';
174                 if (mkdir(tmp, S_IRWXU | S_IRWXG | S_IRWXO) < 0 && errno != EEXIST)
175                         return -1;
176                 *p = '/';
177         }
178         if (mkdir(tmp, S_IRWXU | S_IRWXG | S_IRWXO) < 0 && errno != EEXIST)
179                 return -1;
180         return 0;
181 }
182
183 void
184 printtimeformat(FILE *fp, const git_time *intime, const char *fmt)
185 {
186         struct tm *intm;
187         time_t t;
188         char out[32];
189
190         t = (time_t) intime->time + (intime->offset * 60);
191         intm = gmtime(&t);
192         strftime(out, sizeof(out), fmt, intm);
193         fputs(out, fp);
194 }
195
196 void
197 printtimez(FILE *fp, const git_time *intime)
198 {
199         printtimeformat(fp, intime, "%Y-%m-%dT%H:%M:%SZ");
200 }
201
202 void
203 printtime(FILE *fp, const git_time *intime)
204 {
205         printtimeformat(fp, intime, "%a %b %e %T %Y");
206 }
207
208 void
209 printtimeshort(FILE *fp, const git_time *intime)
210 {
211         printtimeformat(fp, intime, "%Y-%m-%d %H:%M");
212 }
213
214 int
215 writeheader(FILE *fp)
216 {
217         fputs("<!DOCTYPE HTML>"
218                 "<html dir=\"ltr\" lang=\"en\">\n<head>\n"
219                 "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />\n"
220                 "<meta http-equiv=\"Content-Language\" content=\"en\" />\n<title>", fp);
221         xmlencode(fp, name, strlen(name));
222         if (description[0])
223                 fputs(" - ", fp);
224         xmlencode(fp, description, strlen(description));
225         fprintf(fp, "</title>\n<link rel=\"icon\" type=\"image/png\" href=\"%sfavicon.png\" />\n", relpath);
226         fprintf(fp, "<link rel=\"alternate\" type=\"application/atom+xml\" title=\"%s Atom Feed\" href=\"%satom.xml\" />\n",
227                 name, relpath);
228         fprintf(fp, "<link rel=\"stylesheet\" type=\"text/css\" href=\"%sstyle.css\" />\n", relpath);
229         fputs("</head>\n<body>\n\n<table><tr><td>", fp);
230         fprintf(fp, "<a href=\"../%s\"><img src=\"%slogo.png\" alt=\"\" width=\"32\" height=\"32\" /></a>",
231                 relpath, relpath);
232         fputs("</td><td><h1>", fp);
233         xmlencode(fp, name, strlen(name));
234         fputs("</h1><span class=\"desc\">", fp);
235         xmlencode(fp, description, strlen(description));
236         fputs("</span></td></tr><tr><td></td><td>\n", fp);
237         fprintf(fp, "<a href=\"%slog.html\">Log</a> | ", relpath);
238         fprintf(fp, "<a href=\"%sfiles.html\">Files</a>", relpath);
239         if (hasreadme)
240                 fprintf(fp, " | <a href=\"%sfile/README.html\">README</a>", relpath);
241         if (haslicense)
242                 fprintf(fp, " | <a href=\"%sfile/LICENSE.html\">LICENSE</a>", relpath);
243         fputs("</td></tr></table>\n<hr/><div id=\"content\">\n", fp);
244
245         return 0;
246 }
247
248 int
249 writefooter(FILE *fp)
250 {
251         return !fputs("</div></body>\n</html>", fp);
252 }
253
254 void
255 writeblobhtml(FILE *fp, const git_blob *blob)
256 {
257         off_t i = 0;
258         size_t n = 1;
259         char *nfmt = "<a href=\"#l%d\" id=\"l%d\">%d</a>\n";
260         const char *s = git_blob_rawcontent(blob);
261         git_off_t len = git_blob_rawsize(blob);
262
263         fputs("<table id=\"blob\"><tr><td class=\"num\"><pre>\n", fp);
264
265         if (len) {
266                 fprintf(fp, nfmt, n, n, n);
267                 while (i < len - 1) {
268                         if (s[i] == '\n') {
269                                 n++;
270                                 fprintf(fp, nfmt, n, n, n);
271                         }
272                         i++;
273                 }
274         }
275
276         fputs("</pre></td><td><pre>\n", fp);
277         xmlencode(fp, s, (size_t)len);
278         fputs("</pre></td></tr></table>\n", fp);
279 }
280
281 void
282 printcommit(FILE *fp, struct commitinfo *ci)
283 {
284         /* TODO: show tag when commit has it */
285         fprintf(fp, "<b>commit</b> <a href=\"%scommit/%s.html\">%s</a>\n",
286                 relpath, ci->oid, ci->oid);
287
288         if (ci->parentoid[0])
289                 fprintf(fp, "<b>parent</b> <a href=\"%scommit/%s.html\">%s</a>\n",
290                         relpath, ci->parentoid, ci->parentoid);
291
292 #if 0
293         if ((count = (int)git_commit_parentcount(commit)) > 1) {
294                 fprintf(fp, "<b>Merge:</b>");
295                 for (i = 0; i < count; i++) {
296                         git_oid_tostr(buf, 8, git_commit_parent_id(commit, i));
297                         fprintf(fp, " <a href=\"%scommit/%s.html\">%s</a>",
298                                 relpath, buf, buf);
299                 }
300                 fputc('\n', fp);
301         }
302 #endif
303         if (ci->author) {
304                 fprintf(fp, "<b>Author:</b> ");
305                 xmlencode(fp, ci->author->name, strlen(ci->author->name));
306                 fprintf(fp, " &lt;<a href=\"mailto:");
307                 xmlencode(fp, ci->author->email, strlen(ci->author->email));
308                 fputs("\">", fp);
309                 xmlencode(fp, ci->author->email, strlen(ci->author->email));
310                 fputs("</a>&gt;\n<b>Date:</b>   ", fp);
311                 printtime(fp, &(ci->author->when));
312                 fputc('\n', fp);
313         }
314         fputc('\n', fp);
315
316         if (ci->msg)
317                 xmlencode(fp, ci->msg, strlen(ci->msg));
318
319         fputc('\n', fp);
320 }
321
322 void
323 printshowfile(struct commitinfo *ci)
324 {
325         const git_diff_delta *delta;
326         const git_diff_hunk *hunk;
327         const git_diff_line *line;
328         git_patch *patch;
329         git_buf statsbuf;
330         size_t ndeltas, nhunks, nhunklines;
331         FILE *fp;
332         size_t i, j, k;
333         char path[PATH_MAX];
334
335         snprintf(path, sizeof(path), "commit/%s.html", ci->oid);
336         /* check if file exists if so skip it */
337         if (!access(path, F_OK))
338                 return;
339
340         fp = efopen(path, "w");
341         writeheader(fp);
342         fputs("<pre>\n", fp);
343         printcommit(fp, ci);
344
345         memset(&statsbuf, 0, sizeof(statsbuf));
346
347         /* diff stat */
348         if (ci->stats) {
349                 if (!git_diff_stats_to_buf(&statsbuf, ci->stats,
350                     GIT_DIFF_STATS_FULL | GIT_DIFF_STATS_SHORT, 80)) {
351                         if (statsbuf.ptr && statsbuf.ptr[0]) {
352                                 fprintf(fp, "<b>Diffstat:</b>\n");
353                                 fputs(statsbuf.ptr, fp);
354                         }
355                 }
356         }
357
358         fputs("<hr/>", fp);
359
360         ndeltas = git_diff_num_deltas(ci->diff);
361         for (i = 0; i < ndeltas; i++) {
362                 if (git_patch_from_diff(&patch, ci->diff, i)) {
363                         git_patch_free(patch);
364                         break; /* TODO: handle error */
365                 }
366
367                 delta = git_patch_get_delta(patch);
368                 fprintf(fp, "<b>diff --git a/<a href=\"%sfile/%s.html\">%s</a> b/<a href=\"%sfile/%s.html\">%s</a></b>\n",
369                         relpath, delta->old_file.path, delta->old_file.path,
370                         relpath, delta->new_file.path, delta->new_file.path);
371
372                 /* check binary data */
373                 if (delta->flags & GIT_DIFF_FLAG_BINARY) {
374                         fputs("Binary files differ\n", fp);
375                         git_patch_free(patch);
376                         continue;
377                 }
378
379                 nhunks = git_patch_num_hunks(patch);
380                 for (j = 0; j < nhunks; j++) {
381                         if (git_patch_get_hunk(&hunk, &nhunklines, patch, j))
382                                 break; /* TODO: handle error ? */
383
384                         fprintf(fp, "<span class=\"h\">%s</span>\n", hunk->header);
385
386                         for (k = 0; ; k++) {
387                                 if (git_patch_get_line_in_hunk(&line, patch, j, k))
388                                         break;
389                                 if (line->old_lineno == -1)
390                                         fprintf(fp, "<a href=\"#h%zu-%zu\" id=\"h%zu-%zu\" class=\"i\">+",
391                                                 j, k, j, k);
392                                 else if (line->new_lineno == -1)
393                                         fprintf(fp, "<a href=\"#h%zu-%zu\" id=\"h%zu-%zu\" class=\"d\">-",
394                                                 j, k, j, k);
395                                 else
396                                         fputc(' ', fp);
397                                 xmlencode(fp, line->content, line->content_len);
398                                 if (line->old_lineno == -1 || line->new_lineno == -1)
399                                         fputs("</a>", fp);
400                         }
401                 }
402                 git_patch_free(patch);
403         }
404         git_buf_free(&statsbuf);
405
406         fputs( "</pre>\n", fp);
407         writefooter(fp);
408         fclose(fp);
409         return;
410 }
411
412 void
413 writelog(FILE *fp)
414 {
415         struct commitinfo *ci;
416         git_revwalk *w = NULL;
417         git_oid id;
418         size_t len;
419
420         mkdir("commit", 0755);
421
422         git_revwalk_new(&w, repo);
423         git_revwalk_push_head(w);
424         git_revwalk_sorting(w, GIT_SORT_TIME);
425         git_revwalk_simplify_first_parent(w);
426
427         /* TODO: also make "expanded" log ? (with message body) */
428         fputs("<table id=\"log\"><thead>\n<tr><td>Age</td><td>Commit message</td>"
429                   "<td>Author</td><td>Files</td><td class=\"num\">+</td>"
430                   "<td class=\"num\">-</td></tr>\n</thead><tbody>\n", fp);
431         while (!git_revwalk_next(&id, w)) {
432                 relpath = "";
433
434                 if (!(ci = commitinfo_getbyoid(&id)))
435                         break;
436
437                 fputs("<tr><td>", fp);
438                 if (ci->author)
439                         printtimeshort(fp, &(ci->author->when));
440                 fputs("</td><td>", fp);
441                 if (ci->summary) {
442                         fprintf(fp, "<a href=\"%scommit/%s.html\">", relpath, ci->oid);
443                         if ((len = strlen(ci->summary)) > summarylen) {
444                                 xmlencode(fp, ci->summary, summarylen - 1);
445                                 fputs("…", fp);
446                         } else {
447                                 xmlencode(fp, ci->summary, len);
448                         }
449                         fputs("</a>", fp);
450                 }
451                 fputs("</td><td>", fp);
452                 if (ci->author)
453                         xmlencode(fp, ci->author->name, strlen(ci->author->name));
454                 fputs("</td><td class=\"num\">", fp);
455                 fprintf(fp, "%zu", ci->filecount);
456                 fputs("</td><td class=\"num\">", fp);
457                 fprintf(fp, "+%zu", ci->addcount);
458                 fputs("</td><td class=\"num\">", fp);
459                 fprintf(fp, "-%zu", ci->delcount);
460                 fputs("</td></tr>\n", fp);
461
462                 relpath = "../";
463                 printshowfile(ci);
464
465                 commitinfo_free(ci);
466         }
467         fprintf(fp, "</tbody></table>");
468
469         git_revwalk_free(w);
470         relpath = "";
471 }
472
473 void
474 printcommitatom(FILE *fp, struct commitinfo *ci)
475 {
476         fputs("<entry>\n", fp);
477
478         fprintf(fp, "<id>%s</id>\n", ci->oid);
479         if (ci->author) {
480                 fputs("<updated>", fp);
481                 printtimez(fp, &(ci->author->when));
482                 fputs("</updated>\n", fp);
483         }
484         if (ci->summary) {
485                 fputs("<title type=\"text\">", fp);
486                 xmlencode(fp, ci->summary, strlen(ci->summary));
487                 fputs("</title>\n", fp);
488         }
489
490         fputs("<content type=\"text\">", fp);
491         fprintf(fp, "commit %s\n", ci->oid);
492         if (ci->parentoid[0])
493                 fprintf(fp, "parent %s\n", ci->parentoid);
494
495 #if 0
496         if ((count = (int)git_commit_parentcount(commit)) > 1) {
497                 fprintf(fp, "Merge:");
498                 for (i = 0; i < count; i++) {
499                         git_oid_tostr(buf, 8, git_commit_parent_id(commit, i));
500                         fprintf(fp, " %s", buf);
501                 }
502                 fputc('\n', fp);
503         }
504 #endif
505
506         if (ci->author) {
507                 fprintf(fp, "Author: ");
508                 xmlencode(fp, ci->author->name, strlen(ci->author->name));
509                 fprintf(fp, " &lt;");
510                 xmlencode(fp, ci->author->email, strlen(ci->author->email));
511                 fprintf(fp, "&gt;\nDate:   ");
512                 printtime(fp, &(ci->author->when));
513         }
514         fputc('\n', fp);
515
516         if (ci->msg)
517                 xmlencode(fp, ci->msg, strlen(ci->msg));
518         fputs("\n</content>\n", fp);
519         if (ci->author) {
520                 fputs("<author><name>", fp);
521                 xmlencode(fp, ci->author->name, strlen(ci->author->name));
522                 fputs("</name>\n<email>", fp);
523                 xmlencode(fp, ci->author->email, strlen(ci->author->email));
524                 fputs("</email>\n</author>\n", fp);
525         }
526         fputs("</entry>\n", fp);
527 }
528
529 int
530 writeatom(FILE *fp)
531 {
532         struct commitinfo *ci;
533         git_revwalk *w = NULL;
534         git_oid id;
535         size_t i, m = 100; /* max */
536
537         fputs("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n", fp);
538         fputs("<feed xmlns=\"http://www.w3.org/2005/Atom\">\n<title>", fp);
539         xmlencode(fp, name, strlen(name));
540         fputs(", branch master</title>\n<subtitle>", fp);
541
542         xmlencode(fp, description, strlen(description));
543         fputs("</subtitle>\n", fp);
544
545         git_revwalk_new(&w, repo);
546         git_revwalk_push_head(w);
547         git_revwalk_sorting(w, GIT_SORT_TIME);
548         git_revwalk_simplify_first_parent(w);
549
550         for (i = 0; i < m && !git_revwalk_next(&id, w); i++) {
551                 if (!(ci = commitinfo_getbyoid(&id)))
552                         break;
553                 printcommitatom(fp, ci);
554                 commitinfo_free(ci);
555         }
556         git_revwalk_free(w);
557
558         fputs("</feed>", fp);
559
560         return 0;
561 }
562
563 int
564 writeblob(const git_index_entry *entry)
565 {
566         char fpath[PATH_MAX];
567         char ref[PATH_MAX];
568         char tmp[PATH_MAX] = "";
569         char *p;
570         git_object *obj = NULL;
571         FILE *fp;
572
573         snprintf(fpath, sizeof(fpath), "file/%s.html", entry->path);
574         snprintf(ref, sizeof(ref), "HEAD:%s", entry->path);
575
576         if (git_revparse_single(&obj, repo, ref))
577                 return 1;
578
579         if (mkdirp(dirname(fpath)))
580                 return 1;
581
582         p = fpath;
583         while (*p) {
584                 if (*p == '/')
585                         strlcat(tmp, "../", sizeof(tmp));
586                 p++;
587         }
588         relpath = tmp;
589
590         fp = efopen(fpath, "w");
591         writeheader(fp);
592         fprintf(fp, "<p>%s (%" PRIu32 "b)</p><hr/>", entry->path, entry->file_size);
593         if (git_blob_is_binary((git_blob *)obj)) {
594                 fprintf(fp, "<p>Binary file</p>\n");
595         } else {
596                 writeblobhtml(fp, (git_blob *)obj);
597                 if (ferror(fp))
598                         err(1, "fwrite");
599         }
600         git_object_free(obj);
601         writefooter(fp);
602         fclose(fp);
603
604         relpath = "";
605
606         return 0;
607 }
608
609 int
610 writefiles(FILE *fp)
611 {
612         const git_index_entry *entry;
613         git_index *index;
614         size_t count, i;
615
616         fputs("<table id=\"files\"><thead>\n"
617               "<tr><td>Mode</td><td>Name</td><td>Size</td></tr>\n"
618               "</thead><tbody>\n", fp);
619
620         git_repository_index(&index, repo);
621         count = git_index_entrycount(index);
622
623         for (i = 0; i < count; i++) {
624                 entry = git_index_get_byindex(index, i);
625
626                 fputs("<tr><td>", fp);
627                 fprintf(fp, "%u", entry->mode); /* TODO: fancy print, like: "-rw-r--r--" */
628                 fprintf(fp, "</td><td><a href=\"%sfile/", relpath);
629                 xmlencode(fp, entry->path, strlen(entry->path));
630                 fputs(".html\">", fp);
631                 xmlencode(fp, entry->path, strlen(entry->path));
632                 fputs("</a></td><td class=\"num\">", fp);
633                 fprintf(fp, "%" PRIu32, entry->file_size);
634                 fputs("</td></tr>\n", fp);
635
636                 writeblob(entry);
637         }
638
639         fputs("</tbody></table>", fp);
640
641         return 0;
642 }
643
644 int
645 main(int argc, char *argv[])
646 {
647         git_object *obj = NULL;
648         const git_error *e = NULL;
649         FILE *fp, *fpread;
650         char path[PATH_MAX], *p;
651         int status;
652
653         if (argc != 2) {
654                 fprintf(stderr, "%s <repodir>\n", argv[0]);
655                 return 1;
656         }
657         repodir = argv[1];
658
659         git_libgit2_init();
660
661         if ((status = git_repository_open_ext(&repo, repodir,
662                 GIT_REPOSITORY_OPEN_NO_SEARCH, NULL)) < 0) {
663                 e = giterr_last();
664                 fprintf(stderr, "error %d/%d: %s\n", status, e->klass, e->message);
665                 return status;
666         }
667
668         /* use directory name as name */
669         p = xbasename(repodir);
670         snprintf(name, sizeof(name), "%s", p);
671         free(p);
672
673         /* read description or .git/description */
674         snprintf(path, sizeof(path), "%s%s%s",
675                 repodir, repodir[strlen(repodir)] == '/' ? "" : "/", "description");
676         if (!(fpread = fopen(path, "r"))) {
677                 snprintf(path, sizeof(path), "%s%s%s",
678                         repodir, repodir[strlen(repodir)] == '/' ? "" : "/", ".git/description");
679                 fpread = fopen(path, "r");
680         }
681         if (fpread) {
682                 if (!fgets(description, sizeof(description), fpread))
683                         description[0] = '\0';
684                 fclose(fpread);
685         }
686
687         /* check LICENSE */
688         haslicense = !git_revparse_single(&obj, repo, "HEAD:LICENSE");
689         git_object_free(obj);
690         /* check README */
691         hasreadme = !git_revparse_single(&obj, repo, "HEAD:README");
692         git_object_free(obj);
693
694         fp = efopen("log.html", "w");
695         writeheader(fp);
696         writelog(fp);
697         writefooter(fp);
698         fclose(fp);
699
700         fp = efopen("files.html", "w");
701         writeheader(fp);
702         writefiles(fp);
703         writefooter(fp);
704         fclose(fp);
705
706         /* Atom feed */
707         fp = efopen("atom.xml", "w");
708         writeatom(fp);
709         fclose(fp);
710
711         /* cleanup */
712         git_repository_free(repo);
713         git_libgit2_shutdown();
714
715         return 0;
716 }