21 char oid[GIT_OID_HEXSZ + 1];
22 char parentoid[GIT_OID_HEXSZ + 1];
24 const git_signature *author;
28 git_diff_stats *stats;
32 git_tree *commit_tree;
33 git_tree *parent_tree;
40 static git_repository *repo;
42 static const char *relpath = "";
43 static const char *repodir;
45 static char *name = "";
46 static char *stripped_name;
47 static char description[255];
48 static char cloneurl[1024];
49 static int hasreadme, haslicense;
52 commitinfo_free(struct commitinfo *ci)
57 git_diff_stats_free(ci->stats);
58 git_diff_free(ci->diff);
59 git_tree_free(ci->commit_tree);
60 git_tree_free(ci->parent_tree);
61 git_commit_free(ci->commit);
65 commitinfo_getbyoid(const git_oid *id)
67 struct commitinfo *ci;
68 git_diff_options opts;
71 if (!(ci = calloc(1, sizeof(struct commitinfo))))
75 if (git_commit_lookup(&(ci->commit), repo, id))
78 git_oid_tostr(ci->oid, sizeof(ci->oid), git_commit_id(ci->commit));
79 git_oid_tostr(ci->parentoid, sizeof(ci->parentoid), git_commit_parent_id(ci->commit, 0));
81 ci->author = git_commit_author(ci->commit);
82 ci->summary = git_commit_summary(ci->commit);
83 ci->msg = git_commit_message(ci->commit);
85 if ((error = git_commit_tree(&(ci->commit_tree), ci->commit)))
87 if (!(error = git_commit_parent(&(ci->parent), ci->commit, 0))) {
88 if ((error = git_commit_tree(&(ci->parent_tree), ci->parent)))
92 ci->parent_tree = NULL;
95 git_diff_init_options(&opts, GIT_DIFF_OPTIONS_VERSION);
96 opts.flags |= GIT_DIFF_DISABLE_PATHSPEC_MATCH;
97 if ((error = git_diff_tree_to_tree(&(ci->diff), repo, ci->parent_tree, ci->commit_tree, &opts)))
99 if (git_diff_get_stats(&(ci->stats), ci->diff))
102 ci->addcount = git_diff_stats_insertions(ci->stats);
103 ci->delcount = git_diff_stats_deletions(ci->stats);
104 ci->filecount = git_diff_stats_files_changed(ci->stats);
116 efopen(const char *name, const char *flags)
120 if (!(fp = fopen(name, flags)))
126 /* Escape characters below as HTML 2.0 / XML 1.0. */
128 xmlencode(FILE *fp, const char *s, size_t len)
132 for (i = 0; *s && i < len; s++, i++) {
134 case '<': fputs("<", fp); break;
135 case '>': fputs(">", fp); break;
136 case '\'': fputs("'", fp); break;
137 case '&': fputs("&", fp); break;
138 case '"': fputs(""", fp); break;
139 default: fputc(*s, fp);
144 /* Some implementations of dirname(3) return a pointer to a static
145 * internal buffer (OpenBSD). Others modify the contents of `path` (POSIX).
146 * This is a wrapper function that is compatible with both versions.
147 * The program will error out if dirname(3) failed, this can only happen
148 * with the OpenBSD version. */
150 xdirname(const char *path)
154 if (!(p = strdup(path)))
156 if (!(b = dirname(p)))
158 if (!(b = strdup(b)))
166 mkdirp(const char *path)
168 char tmp[PATH_MAX], *p;
170 if (strlcpy(tmp, path, sizeof(tmp)) >= sizeof(tmp))
171 errx(1, "path truncated: '%s'", path);
172 for (p = tmp + (tmp[0] == '/'); *p; p++) {
176 if (mkdir(tmp, S_IRWXU | S_IRWXG | S_IRWXO) < 0 && errno != EEXIST)
180 if (mkdir(tmp, S_IRWXU | S_IRWXG | S_IRWXO) < 0 && errno != EEXIST)
186 printtimeformat(FILE *fp, const git_time *intime, const char *fmt)
192 t = (time_t) intime->time + (intime->offset * 60);
194 strftime(out, sizeof(out), fmt, intm);
199 printtimez(FILE *fp, const git_time *intime)
201 printtimeformat(fp, intime, "%Y-%m-%dT%H:%M:%SZ");
205 printtime(FILE *fp, const git_time *intime)
207 printtimeformat(fp, intime, "%a %b %e %T %Y");
211 printtimeshort(FILE *fp, const git_time *intime)
213 printtimeformat(fp, intime, "%Y-%m-%d %H:%M");
217 writeheader(FILE *fp, const char *title)
219 fputs("<!DOCTYPE html>\n"
220 "<html dir=\"ltr\" lang=\"en\">\n<head>\n"
221 "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />\n"
222 "<meta http-equiv=\"Content-Language\" content=\"en\" />\n<title>", fp);
223 xmlencode(fp, title, strlen(title));
224 if (title[0] && stripped_name[0])
226 xmlencode(fp, stripped_name, strlen(stripped_name));
229 xmlencode(fp, description, strlen(description));
230 fprintf(fp, "</title>\n<link rel=\"icon\" type=\"image/png\" href=\"%sfavicon.png\" />\n", relpath);
231 fprintf(fp, "<link rel=\"alternate\" type=\"application/atom+xml\" title=\"%s Atom Feed\" href=\"%satom.xml\" />\n",
233 fprintf(fp, "<link rel=\"stylesheet\" type=\"text/css\" href=\"%sstyle.css\" />\n", relpath);
234 fputs("</head>\n<body>\n<table><tr><td>", fp);
235 fprintf(fp, "<a href=\"../%s\"><img src=\"%slogo.png\" alt=\"\" width=\"32\" height=\"32\" /></a>",
237 fputs("</td><td><h1>", fp);
238 xmlencode(fp, stripped_name, strlen(stripped_name));
239 fputs("</h1><span class=\"desc\">", fp);
240 xmlencode(fp, description, strlen(description));
241 fputs("</span></td></tr>", fp);
243 fputs("<tr class=\"url\"><td></td><td>git clone <a href=\"", fp);
244 xmlencode(fp, cloneurl, strlen(cloneurl));
246 xmlencode(fp, cloneurl, strlen(cloneurl));
247 fputs("</a></td></tr>", fp);
249 fputs("<tr><td></td><td>\n", fp);
250 fprintf(fp, "<a href=\"%slog.html\">Log</a> | ", relpath);
251 fprintf(fp, "<a href=\"%sfiles.html\">Files</a> | ", relpath);
252 fprintf(fp, "<a href=\"%srefs.html\">Refs</a>", relpath);
254 fprintf(fp, " | <a href=\"%sfile/README.html\">README</a>", relpath);
256 fprintf(fp, " | <a href=\"%sfile/LICENSE.html\">LICENSE</a>", relpath);
257 fputs("</td></tr></table>\n<hr/>\n<div id=\"content\">\n", fp);
263 writefooter(FILE *fp)
265 return !fputs("</div>\n</body>\n</html>\n", fp);
269 writeblobhtml(FILE *fp, const git_blob *blob)
273 char *nfmt = "<a href=\"#l%d\" id=\"l%d\">%d</a>\n";
274 const char *s = git_blob_rawcontent(blob);
275 git_off_t len = git_blob_rawsize(blob);
277 fputs("<table id=\"blob\"><tr><td class=\"num\"><pre>\n", fp);
281 fprintf(fp, nfmt, n, n, n);
282 for (i = 0; i < len - 1; i++) {
285 fprintf(fp, nfmt, n, n, n);
290 fputs("</pre></td><td><pre>\n", fp);
291 xmlencode(fp, s, (size_t)len);
292 fputs("</pre></td></tr></table>\n", fp);
298 printcommit(FILE *fp, struct commitinfo *ci)
300 fprintf(fp, "<b>commit</b> <a href=\"%scommit/%s.html\">%s</a>\n",
301 relpath, ci->oid, ci->oid);
303 if (ci->parentoid[0])
304 fprintf(fp, "<b>parent</b> <a href=\"%scommit/%s.html\">%s</a>\n",
305 relpath, ci->parentoid, ci->parentoid);
308 fputs("<b>Author:</b> ", fp);
309 xmlencode(fp, ci->author->name, strlen(ci->author->name));
310 fputs(" <<a href=\"mailto:", fp);
311 xmlencode(fp, ci->author->email, strlen(ci->author->email));
313 xmlencode(fp, ci->author->email, strlen(ci->author->email));
314 fputs("</a>>\n<b>Date:</b> ", fp);
315 printtime(fp, &(ci->author->when));
320 xmlencode(fp, ci->msg, strlen(ci->msg));
326 printshowfile(FILE *fp, struct commitinfo *ci)
328 const git_diff_delta *delta;
329 const git_diff_hunk *hunk;
330 const git_diff_line *line;
333 size_t ndeltas, nhunks, nhunklines;
338 memset(&statsbuf, 0, sizeof(statsbuf));
342 !git_diff_stats_to_buf(&statsbuf, ci->stats,
343 GIT_DIFF_STATS_FULL | GIT_DIFF_STATS_SHORT, 80)) {
344 if (statsbuf.ptr && statsbuf.ptr[0]) {
345 fputs("<b>Diffstat:</b>\n", fp);
346 xmlencode(fp, statsbuf.ptr, strlen(statsbuf.ptr));
352 ndeltas = git_diff_num_deltas(ci->diff);
353 for (i = 0; i < ndeltas; i++) {
354 if (git_patch_from_diff(&patch, ci->diff, i)) {
355 git_patch_free(patch);
359 delta = git_patch_get_delta(patch);
360 fprintf(fp, "<b>diff --git a/<a href=\"%sfile/%s.html\">%s</a> b/<a href=\"%sfile/%s.html\">%s</a></b>\n",
361 relpath, delta->old_file.path, delta->old_file.path,
362 relpath, delta->new_file.path, delta->new_file.path);
364 /* check binary data */
365 if (delta->flags & GIT_DIFF_FLAG_BINARY) {
366 fputs("Binary files differ\n", fp);
367 git_patch_free(patch);
371 nhunks = git_patch_num_hunks(patch);
372 for (j = 0; j < nhunks; j++) {
373 if (git_patch_get_hunk(&hunk, &nhunklines, patch, j))
376 fprintf(fp, "<a href=\"#h%zu-%zu\" id=\"h%zu-%zu\" class=\"h\">", i, j, i, j);
377 xmlencode(fp, hunk->header, hunk->header_len);
381 if (git_patch_get_line_in_hunk(&line, patch, j, k))
383 if (line->old_lineno == -1)
384 fprintf(fp, "<a href=\"#h%zu-%zu-%zu\" id=\"h%zu-%zu-%zu\" class=\"i\">+",
386 else if (line->new_lineno == -1)
387 fprintf(fp, "<a href=\"#h%zu-%zu-%zu\" id=\"h%zu-%zu-%zu\" class=\"d\">-",
391 xmlencode(fp, line->content, line->content_len);
392 if (line->old_lineno == -1 || line->new_lineno == -1)
396 git_patch_free(patch);
398 git_buf_free(&statsbuf);
404 writelog(FILE *fp, const git_oid *oid)
406 struct commitinfo *ci;
407 git_revwalk *w = NULL;
414 git_revwalk_new(&w, repo);
415 git_revwalk_push(w, oid);
416 git_revwalk_sorting(w, GIT_SORT_TIME);
417 git_revwalk_simplify_first_parent(w);
419 fputs("<table id=\"log\"><thead>\n<tr><td>Date</td><td>Commit message</td>"
420 "<td>Author</td><td class=\"num\">Files</td><td class=\"num\">+</td>"
421 "<td class=\"num\">-</td></tr>\n</thead><tbody>\n", fp);
423 while (!git_revwalk_next(&id, w)) {
426 if (!(ci = commitinfo_getbyoid(&id)))
429 fputs("<tr><td>", fp);
431 printtimeshort(fp, &(ci->author->when));
432 fputs("</td><td>", fp);
434 fprintf(fp, "<a href=\"%scommit/%s.html\">", relpath, ci->oid);
435 if ((len = strlen(ci->summary)) > summarylen) {
436 xmlencode(fp, ci->summary, summarylen - 1);
439 xmlencode(fp, ci->summary, len);
443 fputs("</td><td>", fp);
445 xmlencode(fp, ci->author->name, strlen(ci->author->name));
446 fputs("</td><td class=\"num\">", fp);
447 fprintf(fp, "%zu", ci->filecount);
448 fputs("</td><td class=\"num\">", fp);
449 fprintf(fp, "+%zu", ci->addcount);
450 fputs("</td><td class=\"num\">", fp);
451 fprintf(fp, "-%zu", ci->delcount);
452 fputs("</td></tr>\n", fp);
456 r = snprintf(path, sizeof(path), "commit/%s.html", ci->oid);
457 if (r == -1 || (size_t)r >= sizeof(path))
458 errx(1, "path truncated: 'commit/%s.html'", ci->oid);
460 /* check if file exists if so skip it */
461 if (access(path, F_OK)) {
462 fpfile = efopen(path, "w");
463 writeheader(fpfile, ci->summary);
464 fputs("<pre>", fpfile);
465 printshowfile(fpfile, ci);
466 fputs("</pre>\n", fpfile);
472 fputs("</tbody></table>", fp);
482 printcommitatom(FILE *fp, struct commitinfo *ci)
484 fputs("<entry>\n", fp);
486 fprintf(fp, "<id>%s</id>\n", ci->oid);
488 fputs("<updated>", fp);
489 printtimez(fp, &(ci->author->when));
490 fputs("</updated>\n", fp);
493 fputs("<title type=\"text\">", fp);
494 xmlencode(fp, ci->summary, strlen(ci->summary));
495 fputs("</title>\n", fp);
497 fprintf(fp, "<link rel=\"alternate\" type=\"text/html\" href=\"commit/%s.html\" />",
501 fputs("<author><name>", fp);
502 xmlencode(fp, ci->author->name, strlen(ci->author->name));
503 fputs("</name>\n<email>", fp);
504 xmlencode(fp, ci->author->email, strlen(ci->author->email));
505 fputs("</email>\n</author>\n", fp);
508 fputs("<content type=\"text\">", fp);
509 fprintf(fp, "commit %s\n", ci->oid);
510 if (ci->parentoid[0])
511 fprintf(fp, "parent %s\n", ci->parentoid);
513 fputs("Author: ", fp);
514 xmlencode(fp, ci->author->name, strlen(ci->author->name));
516 xmlencode(fp, ci->author->email, strlen(ci->author->email));
517 fputs(">\nDate: ", fp);
518 printtime(fp, &(ci->author->when));
523 xmlencode(fp, ci->msg, strlen(ci->msg));
525 fputs("\n</content>\n", fp);
527 fputs("</entry>\n", fp);
533 struct commitinfo *ci;
534 git_revwalk *w = NULL;
536 size_t i, m = 100; /* max */
538 fputs("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
539 "<feed xmlns=\"http://www.w3.org/2005/Atom\">\n<title>", fp);
540 xmlencode(fp, stripped_name, strlen(stripped_name));
541 fputs(", branch HEAD</title>\n<subtitle>", fp);
542 xmlencode(fp, description, strlen(description));
543 fputs("</subtitle>\n", fp);
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);
550 for (i = 0; i < m && !git_revwalk_next(&id, w); i++) {
551 if (!(ci = commitinfo_getbyoid(&id)))
553 printcommitatom(fp, ci);
558 fputs("</feed>", fp);
564 writeblob(git_object *obj, const char *fpath, const char *filename, git_off_t filesize)
566 char tmp[PATH_MAX] = "";
581 if (*p == '/' && strlcat(tmp, "../", sizeof(tmp)) >= sizeof(tmp))
582 errx(1, "path truncated: '../%s'", tmp);
587 fp = efopen(fpath, "w");
588 writeheader(fp, filename);
590 xmlencode(fp, filename, strlen(filename));
591 fprintf(fp, " (%juB)", (uintmax_t)filesize);
592 fputs("</p><hr/>", fp);
594 if (git_blob_is_binary((git_blob *)obj)) {
595 fputs("<p>Binary file</p>\n", fp);
597 lc = writeblobhtml(fp, (git_blob *)obj);
610 filemode(git_filemode_t m)
612 static char mode[11];
614 memset(mode, '-', sizeof(mode) - 1);
625 else if (S_ISFIFO(m))
629 else if (S_ISSOCK(m))
634 if (m & S_IRUSR) mode[1] = 'r';
635 if (m & S_IWUSR) mode[2] = 'w';
636 if (m & S_IXUSR) mode[3] = 'x';
637 if (m & S_IRGRP) mode[4] = 'r';
638 if (m & S_IWGRP) mode[5] = 'w';
639 if (m & S_IXGRP) mode[6] = 'x';
640 if (m & S_IROTH) mode[7] = 'r';
641 if (m & S_IWOTH) mode[8] = 'w';
642 if (m & S_IXOTH) mode[9] = 'x';
644 if (m & S_ISUID) mode[3] = (mode[3] == 'x') ? 's' : 'S';
645 if (m & S_ISGID) mode[6] = (mode[6] == 'x') ? 's' : 'S';
646 if (m & S_ISVTX) mode[9] = (mode[9] == 'x') ? 't' : 'T';
652 writefilestree(FILE *fp, git_tree *tree, const char *branch, const char *path)
654 const git_tree_entry *entry = NULL;
655 const char *entryname;
656 char filepath[PATH_MAX], entrypath[PATH_MAX];
657 git_object *obj = NULL;
662 count = git_tree_entrycount(tree);
663 for (i = 0; i < count; i++) {
664 if (!(entry = git_tree_entry_byindex(tree, i)) ||
665 git_tree_entry_to_object(&obj, repo, entry))
667 entryname = git_tree_entry_name(entry);
668 r = snprintf(entrypath, sizeof(entrypath), "%s%s%s",
669 path, path[0] ? "/" : "", entryname);
670 if (r == -1 || (size_t)r >= sizeof(entrypath))
671 errx(1, "path truncated: '%s%s%s'",
672 path, path[0] ? "/" : "", entryname);
673 switch (git_object_type(obj)) {
678 ret = writefilestree(fp, (git_tree *)obj, branch,
680 git_object_free(obj);
685 git_object_free(obj);
689 r = snprintf(filepath, sizeof(filepath), "file/%s%s%s.html",
690 path, path[0] ? "/" : "", entryname);
691 if (r == -1 || (size_t)r >= sizeof(filepath))
692 errx(1, "path truncated: 'file/%s%s%s.html'",
693 path, path[0] ? "/" : "", entryname);
695 filesize = git_blob_rawsize((git_blob *)obj);
697 lc = writeblob(obj, filepath, entryname, filesize);
699 fputs("<tr><td>", fp);
700 fputs(filemode(git_tree_entry_filemode(entry)), fp);
701 fprintf(fp, "</td><td><a href=\"%s%s\">", relpath, filepath);
702 xmlencode(fp, entrypath, strlen(entrypath));
703 fputs("</a></td><td class=\"num\">", fp);
704 if (showlinecount && lc > 0)
705 fprintf(fp, "%dL", lc);
707 fprintf(fp, "%juB", (uintmax_t)filesize);
708 fputs("</td></tr>\n", fp);
715 writefiles(FILE *fp, const git_oid *id, const char *branch)
717 git_tree *tree = NULL;
718 git_commit *commit = NULL;
721 fputs("<table id=\"files\"><thead>\n<tr>"
722 "<td>Mode</td><td>Name</td><td class=\"num\">Size</td>"
723 "</tr>\n</thead><tbody>\n", fp);
725 if (git_commit_lookup(&commit, repo, id) ||
726 git_commit_tree(&tree, commit))
728 ret = writefilestree(fp, tree, branch, "");
731 fputs("</tbody></table>", fp);
733 git_commit_free(commit);
740 refs_cmp(const void *v1, const void *v2)
742 git_reference *r1 = (*(git_reference **)v1);
743 git_reference *r2 = (*(git_reference **)v2);
746 t1 = git_reference_is_branch(r1);
747 t2 = git_reference_is_branch(r2);
752 return strcmp(git_reference_shorthand(r1),
753 git_reference_shorthand(r2));
759 struct commitinfo *ci;
760 const git_oid *id = NULL;
761 git_object *obj = NULL;
762 git_reference *dref = NULL, *r, *ref = NULL;
763 git_reference_iterator *it = NULL;
764 git_reference **refs = NULL;
765 size_t count, i, j, refcount = 0;
766 const char *titles[] = { "Branches", "Tags" };
767 const char *ids[] = { "branches", "tags" };
770 if (git_reference_iterator_new(&it, repo))
773 for (refcount = 0; !git_reference_next(&ref, it); refcount++) {
774 if (!(refs = reallocarray(refs, refcount + 1, sizeof(git_reference *))))
776 refs[refcount] = ref;
778 git_reference_iterator_free(it);
780 /* sort by type then shorthand name */
781 qsort(refs, refcount, sizeof(git_reference *), refs_cmp);
783 for (j = 0; j < 2; j++) {
784 for (i = 0, count = 0; i < refcount; i++) {
785 if (!(git_reference_is_branch(refs[i]) && j == 0) &&
786 !(git_reference_is_tag(refs[i]) && j == 1))
789 switch (git_reference_type(refs[i])) {
790 case GIT_REF_SYMBOLIC:
791 if (git_reference_resolve(&dref, refs[i]))
801 if (!(id = git_reference_target(r)))
803 if (git_reference_peel(&obj, r, GIT_OBJ_ANY))
805 if (!(id = git_object_id(obj)))
807 if (!(ci = commitinfo_getbyoid(id)))
810 /* print header if it has an entry (first). */
812 fprintf(fp, "<h2>%s</h2><table id=\"%s\"><thead>\n<tr><td>Name</td>"
813 "<td>Last commit date</td><td>Author</td>\n</tr>\n</thead><tbody>\n",
818 name = git_reference_shorthand(r);
820 fputs("<tr><td>", fp);
821 xmlencode(fp, name, strlen(name));
822 fputs("</td><td>", fp);
824 printtimeshort(fp, &(ci->author->when));
825 fputs("</td><td>", fp);
827 xmlencode(fp, ci->author->name, strlen(ci->author->name));
828 fputs("</td></tr>\n", fp);
833 git_object_free(obj);
835 git_reference_free(dref);
840 fputs("</tbody></table><br/>", fp);
844 git_object_free(obj);
845 git_reference_free(dref);
847 for (i = 0; i < refcount; i++)
848 git_reference_free(refs[i]);
855 main(int argc, char *argv[])
857 git_object *obj = NULL;
858 const git_oid *head = NULL;
859 const git_error *e = NULL;
861 char path[PATH_MAX], repodirabs[PATH_MAX + 1], *p;
865 fprintf(stderr, "%s <repodir>\n", argv[0]);
869 if (!realpath(repodir, repodirabs))
874 if ((status = git_repository_open_ext(&repo, repodir,
875 GIT_REPOSITORY_OPEN_NO_SEARCH, NULL)) < 0) {
877 fprintf(stderr, "error %d/%d: %s\n", status, e->klass, e->message);
882 if (git_revparse_single(&obj, repo, "HEAD"))
884 head = git_object_id(obj);
885 git_object_free(obj);
887 /* use directory name as name */
888 if ((name = strrchr(repodirabs, '/')))
893 /* strip .git suffix */
894 if (!(stripped_name = strdup(name)))
896 if ((p = strrchr(stripped_name, '.')))
897 if (!strcmp(p, ".git"))
900 /* read description or .git/description */
901 r = snprintf(path, sizeof(path), "%s%s%s",
902 repodir, repodir[strlen(repodir)] == '/' ? "" : "/", "description");
903 if (r == -1 || (size_t)r >= sizeof(path))
904 errx(1, "path truncated: '%s%s%s'",
905 repodir, repodir[strlen(repodir)] == '/' ? "" : "/", "description");
906 if (!(fpread = fopen(path, "r"))) {
907 r = snprintf(path, sizeof(path), "%s%s%s",
908 repodir, repodir[strlen(repodir)] == '/' ? "" : "/", ".git/description");
909 if (r == -1 || (size_t)r >= sizeof(path))
910 errx(1, "path truncated: '%s%s%s'",
911 repodir, repodir[strlen(repodir)] == '/' ? "" : "/", ".git/description");
912 fpread = fopen(path, "r");
915 if (!fgets(description, sizeof(description), fpread))
916 description[0] = '\0';
920 /* read url or .git/url */
921 r = snprintf(path, sizeof(path), "%s%s%s",
922 repodir, repodir[strlen(repodir)] == '/' ? "" : "/", "url");
923 if (r == -1 || (size_t)r >= sizeof(path))
924 errx(1, "path truncated: '%s%s%s'",
925 repodir, repodir[strlen(repodir)] == '/' ? "" : "/", "url");
926 if (!(fpread = fopen(path, "r"))) {
927 r = snprintf(path, sizeof(path), "%s%s%s",
928 repodir, repodir[strlen(repodir)] == '/' ? "" : "/", ".git/url");
929 if (r == -1 || (size_t)r >= sizeof(path))
930 errx(1, "path truncated: '%s%s%s'",
931 repodir, repodir[strlen(repodir)] == '/' ? "" : "/", ".git/url");
932 fpread = fopen(path, "r");
935 if (!fgets(cloneurl, sizeof(cloneurl), fpread))
937 cloneurl[strcspn(cloneurl, "\n")] = '\0';
942 haslicense = !git_revparse_single(&obj, repo, "HEAD:LICENSE");
943 git_object_free(obj);
945 hasreadme = !git_revparse_single(&obj, repo, "HEAD:README");
946 git_object_free(obj);
949 fp = efopen("log.html", "w");
951 writeheader(fp, "Log");
952 mkdir("commit", 0755);
958 fp = efopen("files.html", "w");
959 writeheader(fp, "Files");
960 writefiles(fp, head, "HEAD");
964 /* summary page with branches and tags */
965 fp = efopen("refs.html", "w");
966 writeheader(fp, "Refs");
972 fp = efopen("atom.xml", "w");
977 git_repository_free(repo);
978 git_libgit2_shutdown();