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 haslicense, hasreadme, hassubmodules;
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/.gitmodules.html\">Submodules</a>", relpath);
257 fprintf(fp, " | <a href=\"%sfile/README.html\">README</a>", relpath);
259 fprintf(fp, " | <a href=\"%sfile/LICENSE.html\">LICENSE</a>", relpath);
260 fputs("</td></tr></table>\n<hr/>\n<div id=\"content\">\n", fp);
266 writefooter(FILE *fp)
268 return !fputs("</div>\n</body>\n</html>\n", fp);
272 writeblobhtml(FILE *fp, const git_blob *blob)
276 char *nfmt = "<a href=\"#l%d\" id=\"l%d\">%d</a>\n";
277 const char *s = git_blob_rawcontent(blob);
278 git_off_t len = git_blob_rawsize(blob);
280 fputs("<table id=\"blob\"><tr><td class=\"num\"><pre>\n", fp);
284 fprintf(fp, nfmt, n, n, n);
285 for (i = 0; i < len - 1; i++) {
288 fprintf(fp, nfmt, n, n, n);
293 fputs("</pre></td><td><pre>\n", fp);
294 xmlencode(fp, s, (size_t)len);
295 fputs("</pre></td></tr></table>\n", fp);
301 printcommit(FILE *fp, struct commitinfo *ci)
303 fprintf(fp, "<b>commit</b> <a href=\"%scommit/%s.html\">%s</a>\n",
304 relpath, ci->oid, ci->oid);
306 if (ci->parentoid[0])
307 fprintf(fp, "<b>parent</b> <a href=\"%scommit/%s.html\">%s</a>\n",
308 relpath, ci->parentoid, ci->parentoid);
311 fputs("<b>Author:</b> ", fp);
312 xmlencode(fp, ci->author->name, strlen(ci->author->name));
313 fputs(" <<a href=\"mailto:", fp);
314 xmlencode(fp, ci->author->email, strlen(ci->author->email));
316 xmlencode(fp, ci->author->email, strlen(ci->author->email));
317 fputs("</a>>\n<b>Date:</b> ", fp);
318 printtime(fp, &(ci->author->when));
323 xmlencode(fp, ci->msg, strlen(ci->msg));
329 printshowfile(FILE *fp, struct commitinfo *ci)
331 const git_diff_delta *delta;
332 const git_diff_hunk *hunk;
333 const git_diff_line *line;
336 size_t ndeltas, nhunks, nhunklines;
341 memset(&statsbuf, 0, sizeof(statsbuf));
345 !git_diff_stats_to_buf(&statsbuf, ci->stats,
346 GIT_DIFF_STATS_FULL | GIT_DIFF_STATS_SHORT, 80)) {
347 if (statsbuf.ptr && statsbuf.ptr[0]) {
348 fputs("<b>Diffstat:</b>\n", fp);
349 xmlencode(fp, statsbuf.ptr, strlen(statsbuf.ptr));
355 ndeltas = git_diff_num_deltas(ci->diff);
356 for (i = 0; i < ndeltas; i++) {
357 if (git_patch_from_diff(&patch, ci->diff, i)) {
358 git_patch_free(patch);
362 delta = git_patch_get_delta(patch);
363 fprintf(fp, "<b>diff --git a/<a href=\"%sfile/%s.html\">%s</a> b/<a href=\"%sfile/%s.html\">%s</a></b>\n",
364 relpath, delta->old_file.path, delta->old_file.path,
365 relpath, delta->new_file.path, delta->new_file.path);
367 /* check binary data */
368 if (delta->flags & GIT_DIFF_FLAG_BINARY) {
369 fputs("Binary files differ\n", fp);
370 git_patch_free(patch);
374 nhunks = git_patch_num_hunks(patch);
375 for (j = 0; j < nhunks; j++) {
376 if (git_patch_get_hunk(&hunk, &nhunklines, patch, j))
379 fprintf(fp, "<a href=\"#h%zu-%zu\" id=\"h%zu-%zu\" class=\"h\">", i, j, i, j);
380 xmlencode(fp, hunk->header, hunk->header_len);
384 if (git_patch_get_line_in_hunk(&line, patch, j, k))
386 if (line->old_lineno == -1)
387 fprintf(fp, "<a href=\"#h%zu-%zu-%zu\" id=\"h%zu-%zu-%zu\" class=\"i\">+",
389 else if (line->new_lineno == -1)
390 fprintf(fp, "<a href=\"#h%zu-%zu-%zu\" id=\"h%zu-%zu-%zu\" class=\"d\">-",
394 xmlencode(fp, line->content, line->content_len);
395 if (line->old_lineno == -1 || line->new_lineno == -1)
399 git_patch_free(patch);
401 git_buf_free(&statsbuf);
407 writelog(FILE *fp, const git_oid *oid)
409 struct commitinfo *ci;
410 git_revwalk *w = NULL;
417 git_revwalk_new(&w, repo);
418 git_revwalk_push(w, oid);
419 git_revwalk_sorting(w, GIT_SORT_TIME);
420 git_revwalk_simplify_first_parent(w);
422 fputs("<table id=\"log\"><thead>\n<tr><td>Date</td><td>Commit message</td>"
423 "<td>Author</td><td class=\"num\">Files</td><td class=\"num\">+</td>"
424 "<td class=\"num\">-</td></tr>\n</thead><tbody>\n", fp);
426 while (!git_revwalk_next(&id, w)) {
429 if (!(ci = commitinfo_getbyoid(&id)))
432 fputs("<tr><td>", fp);
434 printtimeshort(fp, &(ci->author->when));
435 fputs("</td><td>", fp);
437 fprintf(fp, "<a href=\"%scommit/%s.html\">", relpath, ci->oid);
438 if ((len = strlen(ci->summary)) > summarylen) {
439 xmlencode(fp, ci->summary, summarylen - 1);
442 xmlencode(fp, ci->summary, len);
446 fputs("</td><td>", fp);
448 xmlencode(fp, ci->author->name, strlen(ci->author->name));
449 fputs("</td><td class=\"num\">", fp);
450 fprintf(fp, "%zu", ci->filecount);
451 fputs("</td><td class=\"num\">", fp);
452 fprintf(fp, "+%zu", ci->addcount);
453 fputs("</td><td class=\"num\">", fp);
454 fprintf(fp, "-%zu", ci->delcount);
455 fputs("</td></tr>\n", fp);
459 r = snprintf(path, sizeof(path), "commit/%s.html", ci->oid);
460 if (r == -1 || (size_t)r >= sizeof(path))
461 errx(1, "path truncated: 'commit/%s.html'", ci->oid);
463 /* check if file exists if so skip it */
464 if (access(path, F_OK)) {
465 fpfile = efopen(path, "w");
466 writeheader(fpfile, ci->summary);
467 fputs("<pre>", fpfile);
468 printshowfile(fpfile, ci);
469 fputs("</pre>\n", fpfile);
475 fputs("</tbody></table>", fp);
485 printcommitatom(FILE *fp, struct commitinfo *ci)
487 fputs("<entry>\n", fp);
489 fprintf(fp, "<id>%s</id>\n", ci->oid);
491 fputs("<updated>", fp);
492 printtimez(fp, &(ci->author->when));
493 fputs("</updated>\n", fp);
496 fputs("<title type=\"text\">", fp);
497 xmlencode(fp, ci->summary, strlen(ci->summary));
498 fputs("</title>\n", fp);
500 fprintf(fp, "<link rel=\"alternate\" type=\"text/html\" href=\"commit/%s.html\" />",
504 fputs("<author><name>", fp);
505 xmlencode(fp, ci->author->name, strlen(ci->author->name));
506 fputs("</name>\n<email>", fp);
507 xmlencode(fp, ci->author->email, strlen(ci->author->email));
508 fputs("</email>\n</author>\n", fp);
511 fputs("<content type=\"text\">", fp);
512 fprintf(fp, "commit %s\n", ci->oid);
513 if (ci->parentoid[0])
514 fprintf(fp, "parent %s\n", ci->parentoid);
516 fputs("Author: ", fp);
517 xmlencode(fp, ci->author->name, strlen(ci->author->name));
519 xmlencode(fp, ci->author->email, strlen(ci->author->email));
520 fputs(">\nDate: ", fp);
521 printtime(fp, &(ci->author->when));
526 xmlencode(fp, ci->msg, strlen(ci->msg));
528 fputs("\n</content>\n", fp);
530 fputs("</entry>\n", fp);
536 struct commitinfo *ci;
537 git_revwalk *w = NULL;
539 size_t i, m = 100; /* max */
541 fputs("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
542 "<feed xmlns=\"http://www.w3.org/2005/Atom\">\n<title>", fp);
543 xmlencode(fp, stripped_name, strlen(stripped_name));
544 fputs(", branch HEAD</title>\n<subtitle>", fp);
545 xmlencode(fp, description, strlen(description));
546 fputs("</subtitle>\n", fp);
548 git_revwalk_new(&w, repo);
549 git_revwalk_push_head(w);
550 git_revwalk_sorting(w, GIT_SORT_TIME);
551 git_revwalk_simplify_first_parent(w);
553 for (i = 0; i < m && !git_revwalk_next(&id, w); i++) {
554 if (!(ci = commitinfo_getbyoid(&id)))
556 printcommitatom(fp, ci);
561 fputs("</feed>", fp);
567 writeblob(git_object *obj, const char *fpath, const char *filename, git_off_t filesize)
569 char tmp[PATH_MAX] = "";
584 if (*p == '/' && strlcat(tmp, "../", sizeof(tmp)) >= sizeof(tmp))
585 errx(1, "path truncated: '../%s'", tmp);
590 fp = efopen(fpath, "w");
591 writeheader(fp, filename);
593 xmlencode(fp, filename, strlen(filename));
594 fprintf(fp, " (%juB)", (uintmax_t)filesize);
595 fputs("</p><hr/>", fp);
597 if (git_blob_is_binary((git_blob *)obj)) {
598 fputs("<p>Binary file</p>\n", fp);
600 lc = writeblobhtml(fp, (git_blob *)obj);
613 filemode(git_filemode_t m)
615 static char mode[11];
617 memset(mode, '-', sizeof(mode) - 1);
628 else if (S_ISFIFO(m))
632 else if (S_ISSOCK(m))
637 if (m & S_IRUSR) mode[1] = 'r';
638 if (m & S_IWUSR) mode[2] = 'w';
639 if (m & S_IXUSR) mode[3] = 'x';
640 if (m & S_IRGRP) mode[4] = 'r';
641 if (m & S_IWGRP) mode[5] = 'w';
642 if (m & S_IXGRP) mode[6] = 'x';
643 if (m & S_IROTH) mode[7] = 'r';
644 if (m & S_IWOTH) mode[8] = 'w';
645 if (m & S_IXOTH) mode[9] = 'x';
647 if (m & S_ISUID) mode[3] = (mode[3] == 'x') ? 's' : 'S';
648 if (m & S_ISGID) mode[6] = (mode[6] == 'x') ? 's' : 'S';
649 if (m & S_ISVTX) mode[9] = (mode[9] == 'x') ? 't' : 'T';
655 writefilestree(FILE *fp, git_tree *tree, const char *branch, const char *path)
657 const git_tree_entry *entry = NULL;
658 git_submodule *module = NULL;
659 const char *entryname;
660 char filepath[PATH_MAX], entrypath[PATH_MAX];
661 git_object *obj = NULL;
666 count = git_tree_entrycount(tree);
667 for (i = 0; i < count; i++) {
668 if (!(entry = git_tree_entry_byindex(tree, i)) ||
669 !(entryname = git_tree_entry_name(entry)))
671 r = snprintf(entrypath, sizeof(entrypath), "%s%s%s",
672 path, path[0] ? "/" : "", entryname);
673 if (r == -1 || (size_t)r >= sizeof(entrypath))
674 errx(1, "path truncated: '%s%s%s'",
675 path, path[0] ? "/" : "", entryname);
677 r = snprintf(filepath, sizeof(filepath), "file/%s%s%s.html",
678 path, path[0] ? "/" : "", entryname);
679 if (r == -1 || (size_t)r >= sizeof(filepath))
680 errx(1, "path truncated: 'file/%s%s%s.html'",
681 path, path[0] ? "/" : "", entryname);
683 if (!git_tree_entry_to_object(&obj, repo, entry)) {
684 switch (git_object_type(obj)) {
689 ret = writefilestree(fp, (git_tree *)obj, branch,
691 git_object_free(obj);
696 git_object_free(obj);
700 filesize = git_blob_rawsize((git_blob *)obj);
701 lc = writeblob(obj, filepath, entryname, filesize);
703 fputs("<tr><td>", fp);
704 fputs(filemode(git_tree_entry_filemode(entry)), fp);
705 fprintf(fp, "</td><td><a href=\"%s%s\">", relpath, filepath);
706 xmlencode(fp, entrypath, strlen(entrypath));
707 fputs("</a></td><td class=\"num\">", fp);
708 if (showlinecount && lc > 0)
709 fprintf(fp, "%dL", lc);
711 fprintf(fp, "%juB", (uintmax_t)filesize);
712 fputs("</td></tr>\n", fp);
713 } else if (!git_submodule_lookup(&module, repo, entryname)) {
714 fprintf(fp, "<tr><td>m------</td><td><a href=\"%sfile/.gitmodules.html\">",
716 xmlencode(fp, entrypath, strlen(entrypath));
717 git_submodule_free(module);
718 fputs("</a></td><td class=\"num\"></td></tr>\n", fp);
726 writefiles(FILE *fp, const git_oid *id, const char *branch)
728 git_tree *tree = NULL;
729 git_commit *commit = NULL;
732 fputs("<table id=\"files\"><thead>\n<tr>"
733 "<td>Mode</td><td>Name</td><td class=\"num\">Size</td>"
734 "</tr>\n</thead><tbody>\n", fp);
736 if (git_commit_lookup(&commit, repo, id) ||
737 git_commit_tree(&tree, commit))
739 ret = writefilestree(fp, tree, branch, "");
742 fputs("</tbody></table>", fp);
744 git_commit_free(commit);
751 refs_cmp(const void *v1, const void *v2)
753 git_reference *r1 = (*(git_reference **)v1);
754 git_reference *r2 = (*(git_reference **)v2);
757 t1 = git_reference_is_branch(r1);
758 t2 = git_reference_is_branch(r2);
763 return strcmp(git_reference_shorthand(r1),
764 git_reference_shorthand(r2));
770 struct commitinfo *ci;
771 const git_oid *id = NULL;
772 git_object *obj = NULL;
773 git_reference *dref = NULL, *r, *ref = NULL;
774 git_reference_iterator *it = NULL;
775 git_reference **refs = NULL;
776 size_t count, i, j, refcount = 0;
777 const char *titles[] = { "Branches", "Tags" };
778 const char *ids[] = { "branches", "tags" };
781 if (git_reference_iterator_new(&it, repo))
784 for (refcount = 0; !git_reference_next(&ref, it); refcount++) {
785 if (!(refs = reallocarray(refs, refcount + 1, sizeof(git_reference *))))
787 refs[refcount] = ref;
789 git_reference_iterator_free(it);
791 /* sort by type then shorthand name */
792 qsort(refs, refcount, sizeof(git_reference *), refs_cmp);
794 for (j = 0; j < 2; j++) {
795 for (i = 0, count = 0; i < refcount; i++) {
796 if (!(git_reference_is_branch(refs[i]) && j == 0) &&
797 !(git_reference_is_tag(refs[i]) && j == 1))
800 switch (git_reference_type(refs[i])) {
801 case GIT_REF_SYMBOLIC:
802 if (git_reference_resolve(&dref, refs[i]))
812 if (!(id = git_reference_target(r)))
814 if (git_reference_peel(&obj, r, GIT_OBJ_ANY))
816 if (!(id = git_object_id(obj)))
818 if (!(ci = commitinfo_getbyoid(id)))
821 /* print header if it has an entry (first). */
823 fprintf(fp, "<h2>%s</h2><table id=\"%s\"><thead>\n<tr><td>Name</td>"
824 "<td>Last commit date</td><td>Author</td>\n</tr>\n</thead><tbody>\n",
829 name = git_reference_shorthand(r);
831 fputs("<tr><td>", fp);
832 xmlencode(fp, name, strlen(name));
833 fputs("</td><td>", fp);
835 printtimeshort(fp, &(ci->author->when));
836 fputs("</td><td>", fp);
838 xmlencode(fp, ci->author->name, strlen(ci->author->name));
839 fputs("</td></tr>\n", fp);
844 git_object_free(obj);
846 git_reference_free(dref);
851 fputs("</tbody></table><br/>", fp);
855 git_object_free(obj);
856 git_reference_free(dref);
858 for (i = 0; i < refcount; i++)
859 git_reference_free(refs[i]);
866 main(int argc, char *argv[])
868 git_object *obj = NULL;
869 const git_oid *head = NULL;
870 const git_error *e = NULL;
872 char path[PATH_MAX], repodirabs[PATH_MAX + 1], *p;
876 fprintf(stderr, "%s <repodir>\n", argv[0]);
880 if (!realpath(repodir, repodirabs))
885 if ((status = git_repository_open_ext(&repo, repodir,
886 GIT_REPOSITORY_OPEN_NO_SEARCH, NULL)) < 0) {
888 fprintf(stderr, "%s: %s\n", argv[0], e->message);
893 if (git_revparse_single(&obj, repo, "HEAD"))
895 head = git_object_id(obj);
896 git_object_free(obj);
898 /* use directory name as name */
899 if ((name = strrchr(repodirabs, '/')))
904 /* strip .git suffix */
905 if (!(stripped_name = strdup(name)))
907 if ((p = strrchr(stripped_name, '.')))
908 if (!strcmp(p, ".git"))
911 /* read description or .git/description */
912 r = snprintf(path, sizeof(path), "%s%s%s",
913 repodir, repodir[strlen(repodir)] == '/' ? "" : "/", "description");
914 if (r == -1 || (size_t)r >= sizeof(path))
915 errx(1, "path truncated: '%s%s%s'",
916 repodir, repodir[strlen(repodir)] == '/' ? "" : "/", "description");
917 if (!(fpread = fopen(path, "r"))) {
918 r = snprintf(path, sizeof(path), "%s%s%s",
919 repodir, repodir[strlen(repodir)] == '/' ? "" : "/", ".git/description");
920 if (r == -1 || (size_t)r >= sizeof(path))
921 errx(1, "path truncated: '%s%s%s'",
922 repodir, repodir[strlen(repodir)] == '/' ? "" : "/", ".git/description");
923 fpread = fopen(path, "r");
926 if (!fgets(description, sizeof(description), fpread))
927 description[0] = '\0';
931 /* read url or .git/url */
932 r = snprintf(path, sizeof(path), "%s%s%s",
933 repodir, repodir[strlen(repodir)] == '/' ? "" : "/", "url");
934 if (r == -1 || (size_t)r >= sizeof(path))
935 errx(1, "path truncated: '%s%s%s'",
936 repodir, repodir[strlen(repodir)] == '/' ? "" : "/", "url");
937 if (!(fpread = fopen(path, "r"))) {
938 r = snprintf(path, sizeof(path), "%s%s%s",
939 repodir, repodir[strlen(repodir)] == '/' ? "" : "/", ".git/url");
940 if (r == -1 || (size_t)r >= sizeof(path))
941 errx(1, "path truncated: '%s%s%s'",
942 repodir, repodir[strlen(repodir)] == '/' ? "" : "/", ".git/url");
943 fpread = fopen(path, "r");
946 if (!fgets(cloneurl, sizeof(cloneurl), fpread))
948 cloneurl[strcspn(cloneurl, "\n")] = '\0';
953 haslicense = !git_revparse_single(&obj, repo, "HEAD:LICENSE");
954 git_object_free(obj);
956 hasreadme = !git_revparse_single(&obj, repo, "HEAD:README");
957 git_object_free(obj);
958 hassubmodules = !git_revparse_single(&obj, repo, "HEAD:.gitmodules");
959 git_object_free(obj);
962 fp = efopen("log.html", "w");
964 writeheader(fp, "Log");
965 mkdir("commit", 0755);
971 fp = efopen("files.html", "w");
972 writeheader(fp, "Files");
973 writefiles(fp, head, "HEAD");
977 /* summary page with branches and tags */
978 fp = efopen("refs.html", "w");
979 writeheader(fp, "Refs");
985 fp = efopen("atom.xml", "w");
990 git_repository_free(repo);
991 git_libgit2_shutdown();