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);
193 if (!(intm = gmtime(&t)))
195 strftime(out, sizeof(out), fmt, intm);
200 printtimez(FILE *fp, const git_time *intime)
202 printtimeformat(fp, intime, "%Y-%m-%dT%H:%M:%SZ");
206 printtime(FILE *fp, const git_time *intime)
208 printtimeformat(fp, intime, "%a %b %e %T %Y");
212 printtimeshort(FILE *fp, const git_time *intime)
214 printtimeformat(fp, intime, "%Y-%m-%d %H:%M");
218 writeheader(FILE *fp, const char *title)
220 fputs("<!DOCTYPE html>\n"
221 "<html dir=\"ltr\" lang=\"en\">\n<head>\n"
222 "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />\n"
223 "<meta http-equiv=\"Content-Language\" content=\"en\" />\n<title>", fp);
224 xmlencode(fp, title, strlen(title));
225 if (title[0] && stripped_name[0])
227 xmlencode(fp, stripped_name, strlen(stripped_name));
230 xmlencode(fp, description, strlen(description));
231 fprintf(fp, "</title>\n<link rel=\"icon\" type=\"image/png\" href=\"%sfavicon.png\" />\n", relpath);
232 fprintf(fp, "<link rel=\"alternate\" type=\"application/atom+xml\" title=\"%s Atom Feed\" href=\"%satom.xml\" />\n",
234 fprintf(fp, "<link rel=\"stylesheet\" type=\"text/css\" href=\"%sstyle.css\" />\n", relpath);
235 fputs("</head>\n<body>\n<table><tr><td>", fp);
236 fprintf(fp, "<a href=\"../%s\"><img src=\"%slogo.png\" alt=\"\" width=\"32\" height=\"32\" /></a>",
238 fputs("</td><td><h1>", fp);
239 xmlencode(fp, stripped_name, strlen(stripped_name));
240 fputs("</h1><span class=\"desc\">", fp);
241 xmlencode(fp, description, strlen(description));
242 fputs("</span></td></tr>", fp);
244 fputs("<tr class=\"url\"><td></td><td>git clone <a href=\"", fp);
245 xmlencode(fp, cloneurl, strlen(cloneurl));
247 xmlencode(fp, cloneurl, strlen(cloneurl));
248 fputs("</a></td></tr>", fp);
250 fputs("<tr><td></td><td>\n", fp);
251 fprintf(fp, "<a href=\"%slog.html\">Log</a> | ", relpath);
252 fprintf(fp, "<a href=\"%sfiles.html\">Files</a> | ", relpath);
253 fprintf(fp, "<a href=\"%srefs.html\">Refs</a>", relpath);
255 fprintf(fp, " | <a href=\"%sfile/README.html\">README</a>", relpath);
257 fprintf(fp, " | <a href=\"%sfile/LICENSE.html\">LICENSE</a>", relpath);
258 fputs("</td></tr></table>\n<hr/>\n<div id=\"content\">\n", fp);
264 writefooter(FILE *fp)
266 return !fputs("</div>\n</body>\n</html>\n", fp);
270 writeblobhtml(FILE *fp, const git_blob *blob)
274 char *nfmt = "<a href=\"#l%d\" id=\"l%d\">%d</a>\n";
275 const char *s = git_blob_rawcontent(blob);
276 git_off_t len = git_blob_rawsize(blob);
278 fputs("<table id=\"blob\"><tr><td class=\"num\"><pre>\n", fp);
282 fprintf(fp, nfmt, n, n, n);
283 for (i = 0; i < len - 1; i++) {
286 fprintf(fp, nfmt, n, n, n);
291 fputs("</pre></td><td><pre>\n", fp);
292 xmlencode(fp, s, (size_t)len);
293 fputs("</pre></td></tr></table>\n", fp);
299 printcommit(FILE *fp, struct commitinfo *ci)
301 fprintf(fp, "<b>commit</b> <a href=\"%scommit/%s.html\">%s</a>\n",
302 relpath, ci->oid, ci->oid);
304 if (ci->parentoid[0])
305 fprintf(fp, "<b>parent</b> <a href=\"%scommit/%s.html\">%s</a>\n",
306 relpath, ci->parentoid, ci->parentoid);
309 fputs("<b>Author:</b> ", fp);
310 xmlencode(fp, ci->author->name, strlen(ci->author->name));
311 fputs(" <<a href=\"mailto:", fp);
312 xmlencode(fp, ci->author->email, strlen(ci->author->email));
314 xmlencode(fp, ci->author->email, strlen(ci->author->email));
315 fputs("</a>>\n<b>Date:</b> ", fp);
316 printtime(fp, &(ci->author->when));
321 xmlencode(fp, ci->msg, strlen(ci->msg));
327 printshowfile(FILE *fp, struct commitinfo *ci)
329 const git_diff_delta *delta;
330 const git_diff_hunk *hunk;
331 const git_diff_line *line;
334 size_t ndeltas, nhunks, nhunklines;
339 memset(&statsbuf, 0, sizeof(statsbuf));
343 !git_diff_stats_to_buf(&statsbuf, ci->stats,
344 GIT_DIFF_STATS_FULL | GIT_DIFF_STATS_SHORT, 80)) {
345 if (statsbuf.ptr && statsbuf.ptr[0]) {
346 fputs("<b>Diffstat:</b>\n", fp);
347 xmlencode(fp, statsbuf.ptr, strlen(statsbuf.ptr));
353 ndeltas = git_diff_num_deltas(ci->diff);
354 for (i = 0; i < ndeltas; i++) {
355 if (git_patch_from_diff(&patch, ci->diff, i)) {
356 git_patch_free(patch);
360 delta = git_patch_get_delta(patch);
361 fprintf(fp, "<b>diff --git a/<a href=\"%sfile/%s.html\">%s</a> b/<a href=\"%sfile/%s.html\">%s</a></b>\n",
362 relpath, delta->old_file.path, delta->old_file.path,
363 relpath, delta->new_file.path, delta->new_file.path);
365 /* check binary data */
366 if (delta->flags & GIT_DIFF_FLAG_BINARY) {
367 fputs("Binary files differ\n", fp);
368 git_patch_free(patch);
372 nhunks = git_patch_num_hunks(patch);
373 for (j = 0; j < nhunks; j++) {
374 if (git_patch_get_hunk(&hunk, &nhunklines, patch, j))
377 fprintf(fp, "<a href=\"#h%zu-%zu\" id=\"h%zu-%zu\" class=\"h\">", i, j, i, j);
378 xmlencode(fp, hunk->header, hunk->header_len);
382 if (git_patch_get_line_in_hunk(&line, patch, j, k))
384 if (line->old_lineno == -1)
385 fprintf(fp, "<a href=\"#h%zu-%zu-%zu\" id=\"h%zu-%zu-%zu\" class=\"i\">+",
387 else if (line->new_lineno == -1)
388 fprintf(fp, "<a href=\"#h%zu-%zu-%zu\" id=\"h%zu-%zu-%zu\" class=\"d\">-",
392 xmlencode(fp, line->content, line->content_len);
393 if (line->old_lineno == -1 || line->new_lineno == -1)
397 git_patch_free(patch);
399 git_buf_free(&statsbuf);
405 writelog(FILE *fp, const git_oid *oid)
407 struct commitinfo *ci;
408 git_revwalk *w = NULL;
415 git_revwalk_new(&w, repo);
416 git_revwalk_push(w, oid);
417 git_revwalk_sorting(w, GIT_SORT_TIME);
418 git_revwalk_simplify_first_parent(w);
420 fputs("<table id=\"log\"><thead>\n<tr><td>Date</td><td>Commit message</td>"
421 "<td>Author</td><td class=\"num\">Files</td><td class=\"num\">+</td>"
422 "<td class=\"num\">-</td></tr>\n</thead><tbody>\n", fp);
424 while (!git_revwalk_next(&id, w)) {
427 if (!(ci = commitinfo_getbyoid(&id)))
430 fputs("<tr><td>", fp);
432 printtimeshort(fp, &(ci->author->when));
433 fputs("</td><td>", fp);
435 fprintf(fp, "<a href=\"%scommit/%s.html\">", relpath, ci->oid);
436 if ((len = strlen(ci->summary)) > summarylen) {
437 xmlencode(fp, ci->summary, summarylen - 1);
440 xmlencode(fp, ci->summary, len);
444 fputs("</td><td>", fp);
446 xmlencode(fp, ci->author->name, strlen(ci->author->name));
447 fputs("</td><td class=\"num\">", fp);
448 fprintf(fp, "%zu", ci->filecount);
449 fputs("</td><td class=\"num\">", fp);
450 fprintf(fp, "+%zu", ci->addcount);
451 fputs("</td><td class=\"num\">", fp);
452 fprintf(fp, "-%zu", ci->delcount);
453 fputs("</td></tr>\n", fp);
457 r = snprintf(path, sizeof(path), "commit/%s.html", ci->oid);
458 if (r == -1 || (size_t)r >= sizeof(path))
459 errx(1, "path truncated: 'commit/%s.html'", ci->oid);
461 /* check if file exists if so skip it */
462 if (access(path, F_OK)) {
463 fpfile = efopen(path, "w");
464 writeheader(fpfile, ci->summary);
465 fputs("<pre>", fpfile);
466 printshowfile(fpfile, ci);
467 fputs("</pre>\n", fpfile);
473 fputs("</tbody></table>", fp);
483 printcommitatom(FILE *fp, struct commitinfo *ci)
485 fputs("<entry>\n", fp);
487 fprintf(fp, "<id>%s</id>\n", ci->oid);
489 fputs("<updated>", fp);
490 printtimez(fp, &(ci->author->when));
491 fputs("</updated>\n", fp);
494 fputs("<title type=\"text\">", fp);
495 xmlencode(fp, ci->summary, strlen(ci->summary));
496 fputs("</title>\n", fp);
498 fprintf(fp, "<link rel=\"alternate\" type=\"text/html\" href=\"commit/%s.html\" />",
502 fputs("<author><name>", fp);
503 xmlencode(fp, ci->author->name, strlen(ci->author->name));
504 fputs("</name>\n<email>", fp);
505 xmlencode(fp, ci->author->email, strlen(ci->author->email));
506 fputs("</email>\n</author>\n", fp);
509 fputs("<content type=\"text\">", fp);
510 fprintf(fp, "commit %s\n", ci->oid);
511 if (ci->parentoid[0])
512 fprintf(fp, "parent %s\n", ci->parentoid);
514 fputs("Author: ", fp);
515 xmlencode(fp, ci->author->name, strlen(ci->author->name));
517 xmlencode(fp, ci->author->email, strlen(ci->author->email));
518 fputs(">\nDate: ", fp);
519 printtime(fp, &(ci->author->when));
524 xmlencode(fp, ci->msg, strlen(ci->msg));
526 fputs("\n</content>\n", fp);
528 fputs("</entry>\n", fp);
534 struct commitinfo *ci;
535 git_revwalk *w = NULL;
537 size_t i, m = 100; /* max */
539 fputs("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
540 "<feed xmlns=\"http://www.w3.org/2005/Atom\">\n<title>", fp);
541 xmlencode(fp, stripped_name, strlen(stripped_name));
542 fputs(", branch HEAD</title>\n<subtitle>", fp);
543 xmlencode(fp, description, strlen(description));
544 fputs("</subtitle>\n", fp);
546 git_revwalk_new(&w, repo);
547 git_revwalk_push_head(w);
548 git_revwalk_sorting(w, GIT_SORT_TIME);
549 git_revwalk_simplify_first_parent(w);
551 for (i = 0; i < m && !git_revwalk_next(&id, w); i++) {
552 if (!(ci = commitinfo_getbyoid(&id)))
554 printcommitatom(fp, ci);
559 fputs("</feed>", fp);
565 writeblob(git_object *obj, const char *fpath, const char *filename, git_off_t filesize)
567 char tmp[PATH_MAX] = "";
582 if (*p == '/' && strlcat(tmp, "../", sizeof(tmp)) >= sizeof(tmp))
583 errx(1, "path truncated: '../%s'", tmp);
588 fp = efopen(fpath, "w");
589 writeheader(fp, filename);
591 xmlencode(fp, filename, strlen(filename));
592 fprintf(fp, " (%juB)", (uintmax_t)filesize);
593 fputs("</p><hr/>", fp);
595 if (git_blob_is_binary((git_blob *)obj)) {
596 fputs("<p>Binary file</p>\n", fp);
598 lc = writeblobhtml(fp, (git_blob *)obj);
611 filemode(git_filemode_t m)
613 static char mode[11];
615 memset(mode, '-', sizeof(mode) - 1);
626 else if (S_ISFIFO(m))
630 else if (S_ISSOCK(m))
635 if (m & S_IRUSR) mode[1] = 'r';
636 if (m & S_IWUSR) mode[2] = 'w';
637 if (m & S_IXUSR) mode[3] = 'x';
638 if (m & S_IRGRP) mode[4] = 'r';
639 if (m & S_IWGRP) mode[5] = 'w';
640 if (m & S_IXGRP) mode[6] = 'x';
641 if (m & S_IROTH) mode[7] = 'r';
642 if (m & S_IWOTH) mode[8] = 'w';
643 if (m & S_IXOTH) mode[9] = 'x';
645 if (m & S_ISUID) mode[3] = (mode[3] == 'x') ? 's' : 'S';
646 if (m & S_ISGID) mode[6] = (mode[6] == 'x') ? 's' : 'S';
647 if (m & S_ISVTX) mode[9] = (mode[9] == 'x') ? 't' : 'T';
653 writefilestree(FILE *fp, git_tree *tree, const char *branch, const char *path)
655 const git_tree_entry *entry = NULL;
656 git_submodule *module = NULL;
657 const char *entryname, *moduleurl;
658 char filepath[PATH_MAX], entrypath[PATH_MAX];
659 git_object *obj = NULL;
664 count = git_tree_entrycount(tree);
665 for (i = 0; i < count; i++) {
666 if (!(entry = git_tree_entry_byindex(tree, i)) ||
667 !(entryname = git_tree_entry_name(entry)))
669 r = snprintf(entrypath, sizeof(entrypath), "%s%s%s",
670 path, path[0] ? "/" : "", entryname);
671 if (r == -1 || (size_t)r >= sizeof(entrypath))
672 errx(1, "path truncated: '%s%s%s'",
673 path, path[0] ? "/" : "", entryname);
675 r = snprintf(filepath, sizeof(filepath), "file/%s%s%s.html",
676 path, path[0] ? "/" : "", entryname);
677 if (r == -1 || (size_t)r >= sizeof(filepath))
678 errx(1, "path truncated: 'file/%s%s%s.html'",
679 path, path[0] ? "/" : "", entryname);
681 if (!git_tree_entry_to_object(&obj, repo, entry)) {
682 switch (git_object_type(obj)) {
687 ret = writefilestree(fp, (git_tree *)obj, branch,
689 git_object_free(obj);
694 git_object_free(obj);
698 filesize = git_blob_rawsize((git_blob *)obj);
699 lc = writeblob(obj, filepath, entryname, filesize);
701 fputs("<tr><td>", fp);
702 fputs(filemode(git_tree_entry_filemode(entry)), fp);
703 fprintf(fp, "</td><td><a href=\"%s%s\">", relpath, filepath);
704 xmlencode(fp, entrypath, strlen(entrypath));
705 fputs("</a></td><td class=\"num\">", fp);
706 if (showlinecount && lc > 0)
707 fprintf(fp, "%dL", lc);
709 fprintf(fp, "%juB", (uintmax_t)filesize);
710 fputs("</td></tr>\n", fp);
711 } else if (!git_submodule_lookup(&module, repo, entryname)) {
712 fputs("<tr><td>m---------</td><td>", fp);
713 if ((moduleurl = git_submodule_url(module))) {
714 fprintf(fp, "<a class=\"module\" href=\"%s\">",
717 xmlencode(fp, entrypath, strlen(entrypath));
720 xmlencode(fp, moduleurl, strlen(moduleurl));
723 fprintf(fp, "</td><td class=\"num\">0%c",
724 showlinecount ? 'L' : 'B');
725 git_submodule_free(module);
726 fputs("</td></tr>\n", fp);
734 writefiles(FILE *fp, const git_oid *id, const char *branch)
736 git_tree *tree = NULL;
737 git_commit *commit = NULL;
740 fputs("<table id=\"files\"><thead>\n<tr>"
741 "<td>Mode</td><td>Name</td><td class=\"num\">Size</td>"
742 "</tr>\n</thead><tbody>\n", fp);
744 if (git_commit_lookup(&commit, repo, id) ||
745 git_commit_tree(&tree, commit))
747 ret = writefilestree(fp, tree, branch, "");
750 fputs("</tbody></table>", fp);
752 git_commit_free(commit);
759 refs_cmp(const void *v1, const void *v2)
761 git_reference *r1 = (*(git_reference **)v1);
762 git_reference *r2 = (*(git_reference **)v2);
765 t1 = git_reference_is_branch(r1);
766 t2 = git_reference_is_branch(r2);
771 return strcmp(git_reference_shorthand(r1),
772 git_reference_shorthand(r2));
778 struct commitinfo *ci;
779 const git_oid *id = NULL;
780 git_object *obj = NULL;
781 git_reference *dref = NULL, *r, *ref = NULL;
782 git_reference_iterator *it = NULL;
783 git_reference **refs = NULL;
784 size_t count, i, j, refcount = 0;
785 const char *titles[] = { "Branches", "Tags" };
786 const char *ids[] = { "branches", "tags" };
789 if (git_reference_iterator_new(&it, repo))
792 for (refcount = 0; !git_reference_next(&ref, it); refcount++) {
793 if (!(refs = reallocarray(refs, refcount + 1, sizeof(git_reference *))))
795 refs[refcount] = ref;
797 git_reference_iterator_free(it);
799 /* sort by type then shorthand name */
800 qsort(refs, refcount, sizeof(git_reference *), refs_cmp);
802 for (j = 0; j < 2; j++) {
803 for (i = 0, count = 0; i < refcount; i++) {
804 if (!(git_reference_is_branch(refs[i]) && j == 0) &&
805 !(git_reference_is_tag(refs[i]) && j == 1))
808 switch (git_reference_type(refs[i])) {
809 case GIT_REF_SYMBOLIC:
810 if (git_reference_resolve(&dref, refs[i]))
820 if (!(id = git_reference_target(r)))
822 if (git_reference_peel(&obj, r, GIT_OBJ_ANY))
824 if (!(id = git_object_id(obj)))
826 if (!(ci = commitinfo_getbyoid(id)))
829 /* print header if it has an entry (first). */
831 fprintf(fp, "<h2>%s</h2><table id=\"%s\"><thead>\n<tr><td>Name</td>"
832 "<td>Last commit date</td><td>Author</td>\n</tr>\n</thead><tbody>\n",
837 name = git_reference_shorthand(r);
839 fputs("<tr><td>", fp);
840 xmlencode(fp, name, strlen(name));
841 fputs("</td><td>", fp);
843 printtimeshort(fp, &(ci->author->when));
844 fputs("</td><td>", fp);
846 xmlencode(fp, ci->author->name, strlen(ci->author->name));
847 fputs("</td></tr>\n", fp);
852 git_object_free(obj);
854 git_reference_free(dref);
859 fputs("</tbody></table><br/>", fp);
863 git_object_free(obj);
864 git_reference_free(dref);
866 for (i = 0; i < refcount; i++)
867 git_reference_free(refs[i]);
874 main(int argc, char *argv[])
876 git_object *obj = NULL;
877 const git_oid *head = NULL;
878 const git_error *e = NULL;
880 char path[PATH_MAX], repodirabs[PATH_MAX + 1], *p;
884 fprintf(stderr, "%s <repodir>\n", argv[0]);
888 if (!realpath(repodir, repodirabs))
893 if ((status = git_repository_open_ext(&repo, repodir,
894 GIT_REPOSITORY_OPEN_NO_SEARCH, NULL)) < 0) {
896 fprintf(stderr, "error %d/%d: %s\n", status, e->klass, e->message);
901 if (git_revparse_single(&obj, repo, "HEAD"))
903 head = git_object_id(obj);
904 git_object_free(obj);
906 /* use directory name as name */
907 if ((name = strrchr(repodirabs, '/')))
912 /* strip .git suffix */
913 if (!(stripped_name = strdup(name)))
915 if ((p = strrchr(stripped_name, '.')))
916 if (!strcmp(p, ".git"))
919 /* read description or .git/description */
920 r = snprintf(path, sizeof(path), "%s%s%s",
921 repodir, repodir[strlen(repodir)] == '/' ? "" : "/", "description");
922 if (r == -1 || (size_t)r >= sizeof(path))
923 errx(1, "path truncated: '%s%s%s'",
924 repodir, repodir[strlen(repodir)] == '/' ? "" : "/", "description");
925 if (!(fpread = fopen(path, "r"))) {
926 r = snprintf(path, sizeof(path), "%s%s%s",
927 repodir, repodir[strlen(repodir)] == '/' ? "" : "/", ".git/description");
928 if (r == -1 || (size_t)r >= sizeof(path))
929 errx(1, "path truncated: '%s%s%s'",
930 repodir, repodir[strlen(repodir)] == '/' ? "" : "/", ".git/description");
931 fpread = fopen(path, "r");
934 if (!fgets(description, sizeof(description), fpread))
935 description[0] = '\0';
939 /* read url or .git/url */
940 r = snprintf(path, sizeof(path), "%s%s%s",
941 repodir, repodir[strlen(repodir)] == '/' ? "" : "/", "url");
942 if (r == -1 || (size_t)r >= sizeof(path))
943 errx(1, "path truncated: '%s%s%s'",
944 repodir, repodir[strlen(repodir)] == '/' ? "" : "/", "url");
945 if (!(fpread = fopen(path, "r"))) {
946 r = snprintf(path, sizeof(path), "%s%s%s",
947 repodir, repodir[strlen(repodir)] == '/' ? "" : "/", ".git/url");
948 if (r == -1 || (size_t)r >= sizeof(path))
949 errx(1, "path truncated: '%s%s%s'",
950 repodir, repodir[strlen(repodir)] == '/' ? "" : "/", ".git/url");
951 fpread = fopen(path, "r");
954 if (!fgets(cloneurl, sizeof(cloneurl), fpread))
956 cloneurl[strcspn(cloneurl, "\n")] = '\0';
961 haslicense = !git_revparse_single(&obj, repo, "HEAD:LICENSE");
962 git_object_free(obj);
964 hasreadme = !git_revparse_single(&obj, repo, "HEAD:README");
965 git_object_free(obj);
968 fp = efopen("log.html", "w");
970 writeheader(fp, "Log");
971 mkdir("commit", 0755);
977 fp = efopen("files.html", "w");
978 writeheader(fp, "Files");
979 writefiles(fp, head, "HEAD");
983 /* summary page with branches and tags */
984 fp = efopen("refs.html", "w");
985 writeheader(fp, "Refs");
991 fp = efopen("atom.xml", "w");
996 git_repository_free(repo);
997 git_libgit2_shutdown();