28 char oid[GIT_OID_HEXSZ + 1];
29 char parentoid[GIT_OID_HEXSZ + 1];
31 const git_signature *author;
38 git_tree *commit_tree;
39 git_tree *parent_tree;
45 struct deltainfo **deltas;
49 static git_repository *repo;
51 static const char *relpath = "";
52 static const char *repodir;
54 static char *name = "";
55 static char *stripped_name;
56 static char description[255];
57 static char cloneurl[1024];
58 static int haslicense, hasreadme, hassubmodules;
61 deltainfo_free(struct deltainfo *di)
65 git_patch_free(di->patch);
71 commitinfo_getstats(struct commitinfo *ci)
74 const git_diff_delta *delta;
75 const git_diff_hunk *hunk;
76 const git_diff_line *line;
77 git_patch *patch = NULL;
78 size_t ndeltas, nhunks, nhunklines;
81 ndeltas = git_diff_num_deltas(ci->diff);
82 if (ndeltas && !(ci->deltas = calloc(ndeltas, sizeof(struct deltainfo *))))
85 for (i = 0; i < ndeltas; i++) {
86 if (!(di = calloc(1, sizeof(struct deltainfo))))
88 if (git_patch_from_diff(&patch, ci->diff, i)) {
89 git_patch_free(patch);
95 delta = git_patch_get_delta(patch);
97 /* check binary data */
98 if (delta->flags & GIT_DIFF_FLAG_BINARY)
101 nhunks = git_patch_num_hunks(patch);
102 for (j = 0; j < nhunks; j++) {
103 if (git_patch_get_hunk(&hunk, &nhunklines, patch, j))
106 if (git_patch_get_line_in_hunk(&line, patch, j, k))
108 if (line->old_lineno == -1) {
111 } else if (line->new_lineno == -1) {
125 for (i = 0; i < ci->ndeltas; i++)
126 deltainfo_free(ci->deltas[i]);
138 commitinfo_free(struct commitinfo *ci)
145 for (i = 0; i < ci->ndeltas; i++)
146 deltainfo_free(ci->deltas[i]);
149 git_diff_free(ci->diff);
150 git_tree_free(ci->commit_tree);
151 git_tree_free(ci->parent_tree);
152 git_commit_free(ci->commit);
156 commitinfo_getbyoid(const git_oid *id)
158 struct commitinfo *ci;
159 git_diff_options opts;
161 if (!(ci = calloc(1, sizeof(struct commitinfo))))
164 if (git_commit_lookup(&(ci->commit), repo, id))
168 git_oid_tostr(ci->oid, sizeof(ci->oid), git_commit_id(ci->commit));
169 git_oid_tostr(ci->parentoid, sizeof(ci->parentoid), git_commit_parent_id(ci->commit, 0));
171 ci->author = git_commit_author(ci->commit);
172 ci->summary = git_commit_summary(ci->commit);
173 ci->msg = git_commit_message(ci->commit);
175 if (git_tree_lookup(&(ci->commit_tree), repo, git_commit_tree_id(ci->commit)))
177 if (!git_commit_parent(&(ci->parent), ci->commit, 0)) {
178 if (git_tree_lookup(&(ci->parent_tree), repo, git_commit_tree_id(ci->parent))) {
180 ci->parent_tree = NULL;
184 git_diff_init_options(&opts, GIT_DIFF_OPTIONS_VERSION);
185 opts.flags |= GIT_DIFF_DISABLE_PATHSPEC_MATCH;
186 if (git_diff_tree_to_tree(&(ci->diff), repo, ci->parent_tree, ci->commit_tree, &opts))
188 if (commitinfo_getstats(ci) == -1)
201 efopen(const char *name, const char *flags)
205 if (!(fp = fopen(name, flags)))
211 /* Escape characters below as HTML 2.0 / XML 1.0. */
213 xmlencode(FILE *fp, const char *s, size_t len)
217 for (i = 0; *s && i < len; s++, i++) {
219 case '<': fputs("<", fp); break;
220 case '>': fputs(">", fp); break;
221 case '\'': fputs("'", fp); break;
222 case '&': fputs("&", fp); break;
223 case '"': fputs(""", fp); break;
224 default: fputc(*s, fp);
229 /* Some implementations of dirname(3) return a pointer to a static
230 * internal buffer (OpenBSD). Others modify the contents of `path` (POSIX).
231 * This is a wrapper function that is compatible with both versions.
232 * The program will error out if dirname(3) failed, this can only happen
233 * with the OpenBSD version. */
235 xdirname(const char *path)
239 if (!(p = strdup(path)))
241 if (!(b = dirname(p)))
243 if (!(b = strdup(b)))
251 mkdirp(const char *path)
253 char tmp[PATH_MAX], *p;
255 if (strlcpy(tmp, path, sizeof(tmp)) >= sizeof(tmp))
256 errx(1, "path truncated: '%s'", path);
257 for (p = tmp + (tmp[0] == '/'); *p; p++) {
261 if (mkdir(tmp, S_IRWXU | S_IRWXG | S_IRWXO) < 0 && errno != EEXIST)
265 if (mkdir(tmp, S_IRWXU | S_IRWXG | S_IRWXO) < 0 && errno != EEXIST)
271 printtimeformat(FILE *fp, const git_time *intime, const char *fmt)
277 t = (time_t) intime->time + (intime->offset * 60);
278 if (!(intm = gmtime(&t)))
280 strftime(out, sizeof(out), fmt, intm);
285 printtimez(FILE *fp, const git_time *intime)
287 printtimeformat(fp, intime, "%Y-%m-%dT%H:%M:%SZ");
291 printtime(FILE *fp, const git_time *intime)
293 printtimeformat(fp, intime, "%a %b %e %T %Y");
297 printtimeshort(FILE *fp, const git_time *intime)
299 printtimeformat(fp, intime, "%Y-%m-%d %H:%M");
303 writeheader(FILE *fp, const char *title)
305 fputs("<!DOCTYPE html>\n"
306 "<html dir=\"ltr\" lang=\"en\">\n<head>\n"
307 "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />\n"
308 "<meta http-equiv=\"Content-Language\" content=\"en\" />\n<title>", fp);
309 xmlencode(fp, title, strlen(title));
310 if (title[0] && stripped_name[0])
312 xmlencode(fp, stripped_name, strlen(stripped_name));
315 xmlencode(fp, description, strlen(description));
316 fprintf(fp, "</title>\n<link rel=\"icon\" type=\"image/png\" href=\"%sfavicon.png\" />\n", relpath);
317 fprintf(fp, "<link rel=\"alternate\" type=\"application/atom+xml\" title=\"%s Atom Feed\" href=\"%satom.xml\" />\n",
319 fprintf(fp, "<link rel=\"stylesheet\" type=\"text/css\" href=\"%sstyle.css\" />\n", relpath);
320 fputs("</head>\n<body>\n<table><tr><td>", fp);
321 fprintf(fp, "<a href=\"../%s\"><img src=\"%slogo.png\" alt=\"\" width=\"32\" height=\"32\" /></a>",
323 fputs("</td><td><h1>", fp);
324 xmlencode(fp, stripped_name, strlen(stripped_name));
325 fputs("</h1><span class=\"desc\">", fp);
326 xmlencode(fp, description, strlen(description));
327 fputs("</span></td></tr>", fp);
329 fputs("<tr class=\"url\"><td></td><td>git clone <a href=\"", fp);
330 xmlencode(fp, cloneurl, strlen(cloneurl));
332 xmlencode(fp, cloneurl, strlen(cloneurl));
333 fputs("</a></td></tr>", fp);
335 fputs("<tr><td></td><td>\n", fp);
336 fprintf(fp, "<a href=\"%slog.html\">Log</a> | ", relpath);
337 fprintf(fp, "<a href=\"%sfiles.html\">Files</a> | ", relpath);
338 fprintf(fp, "<a href=\"%srefs.html\">Refs</a>", relpath);
340 fprintf(fp, " | <a href=\"%sfile/.gitmodules.html\">Submodules</a>", relpath);
342 fprintf(fp, " | <a href=\"%sfile/README.html\">README</a>", relpath);
344 fprintf(fp, " | <a href=\"%sfile/LICENSE.html\">LICENSE</a>", relpath);
345 fputs("</td></tr></table>\n<hr/>\n<div id=\"content\">\n", fp);
351 writefooter(FILE *fp)
353 return !fputs("</div>\n</body>\n</html>\n", fp);
357 writeblobhtml(FILE *fp, const git_blob *blob)
361 char *nfmt = "<a href=\"#l%d\" id=\"l%d\">%d</a>\n";
362 const char *s = git_blob_rawcontent(blob);
363 git_off_t len = git_blob_rawsize(blob);
365 fputs("<table id=\"blob\"><tr><td class=\"num\"><pre>\n", fp);
369 fprintf(fp, nfmt, n, n, n);
370 for (i = 0; i < len - 1; i++) {
373 fprintf(fp, nfmt, n, n, n);
378 fputs("</pre></td><td><pre>\n", fp);
379 xmlencode(fp, s, (size_t)len);
380 fputs("</pre></td></tr></table>\n", fp);
386 printcommit(FILE *fp, struct commitinfo *ci)
388 fprintf(fp, "<b>commit</b> <a href=\"%scommit/%s.html\">%s</a>\n",
389 relpath, ci->oid, ci->oid);
391 if (ci->parentoid[0])
392 fprintf(fp, "<b>parent</b> <a href=\"%scommit/%s.html\">%s</a>\n",
393 relpath, ci->parentoid, ci->parentoid);
396 fputs("<b>Author:</b> ", fp);
397 xmlencode(fp, ci->author->name, strlen(ci->author->name));
398 fputs(" <<a href=\"mailto:", fp);
399 xmlencode(fp, ci->author->email, strlen(ci->author->email));
401 xmlencode(fp, ci->author->email, strlen(ci->author->email));
402 fputs("</a>>\n<b>Date:</b> ", fp);
403 printtime(fp, &(ci->author->when));
408 xmlencode(fp, ci->msg, strlen(ci->msg));
414 printshowfile(FILE *fp, struct commitinfo *ci)
416 const git_diff_delta *delta;
417 const git_diff_hunk *hunk;
418 const git_diff_line *line;
420 size_t nhunks, nhunklines, changed, add, del, total, i, j, k;
428 if (ci->filecount > 1000 ||
429 ci->ndeltas > 1000 ||
430 ci->addcount > 100000 ||
431 ci->delcount > 100000) {
432 fprintf(fp, "(diff is too large, output suppressed)");
437 fputs("<b>Diffstat:</b>\n<table>", fp);
438 for (i = 0; i < ci->ndeltas; i++) {
439 delta = git_patch_get_delta(ci->deltas[i]->patch);
440 fputs("<tr><td>", fp);
441 xmlencode(fp, delta->old_file.path, strlen(delta->old_file.path));
442 if (strcmp(delta->old_file.path, delta->new_file.path)) {
443 fputs(" -> ", fp);
444 xmlencode(fp, delta->new_file.path, strlen(delta->new_file.path));
447 add = ci->deltas[i]->addcount;
448 del = ci->deltas[i]->delcount;
450 total = sizeof(linestr) - 2;
451 if (changed > total) {
453 add = ((float)total / changed * add) + 1;
455 del = ((float)total / changed * del) + 1;
457 memset(&linestr, '+', add);
458 memset(&linestr[add], '-', del);
460 fprintf(fp, "</td><td> | </td><td class=\"num\">%zu</td><td><span class=\"i\">",
461 ci->deltas[i]->addcount + ci->deltas[i]->delcount);
462 fwrite(&linestr, 1, add, fp);
463 fputs("</span><span class=\"d\">", fp);
464 fwrite(&linestr[add], 1, del, fp);
465 fputs("</span></td></tr>\n", fp);
467 fprintf(fp, "</table>%zu file%s changed, %zu insertion%s(+), %zu deletion%s(-)\n",
468 ci->filecount, ci->filecount == 1 ? "" : "s",
469 ci->addcount, ci->addcount == 1 ? "" : "s",
470 ci->delcount, ci->delcount == 1 ? "" : "s");
474 for (i = 0; i < ci->ndeltas; i++) {
475 patch = ci->deltas[i]->patch;
476 delta = git_patch_get_delta(patch);
477 fprintf(fp, "<b>diff --git a/<a href=\"%sfile/%s.html\">%s</a> b/<a href=\"%sfile/%s.html\">%s</a></b>\n",
478 relpath, delta->old_file.path, delta->old_file.path,
479 relpath, delta->new_file.path, delta->new_file.path);
481 /* check binary data */
482 if (delta->flags & GIT_DIFF_FLAG_BINARY) {
483 fputs("Binary files differ\n", fp);
487 nhunks = git_patch_num_hunks(patch);
488 for (j = 0; j < nhunks; j++) {
489 if (git_patch_get_hunk(&hunk, &nhunklines, patch, j))
492 fprintf(fp, "<a href=\"#h%zu-%zu\" id=\"h%zu-%zu\" class=\"h\">", i, j, i, j);
493 xmlencode(fp, hunk->header, hunk->header_len);
497 if (git_patch_get_line_in_hunk(&line, patch, j, k))
499 if (line->old_lineno == -1)
500 fprintf(fp, "<a href=\"#h%zu-%zu-%zu\" id=\"h%zu-%zu-%zu\" class=\"i\">+",
502 else if (line->new_lineno == -1)
503 fprintf(fp, "<a href=\"#h%zu-%zu-%zu\" id=\"h%zu-%zu-%zu\" class=\"d\">-",
507 xmlencode(fp, line->content, line->content_len);
508 if (line->old_lineno == -1 || line->new_lineno == -1)
516 writelog(FILE *fp, const git_oid *oid)
518 struct commitinfo *ci;
519 git_revwalk *w = NULL;
526 git_revwalk_new(&w, repo);
527 git_revwalk_push(w, oid);
528 git_revwalk_sorting(w, GIT_SORT_TIME);
529 git_revwalk_simplify_first_parent(w);
531 fputs("<table id=\"log\"><thead>\n<tr><td>Date</td><td>Commit message</td>"
532 "<td>Author</td><td class=\"num\">Files</td><td class=\"num\">+</td>"
533 "<td class=\"num\">-</td></tr>\n</thead><tbody>\n", fp);
535 while (!git_revwalk_next(&id, w)) {
538 if (!(ci = commitinfo_getbyoid(&id)))
541 fputs("<tr><td>", fp);
543 printtimeshort(fp, &(ci->author->when));
544 fputs("</td><td>", fp);
546 fprintf(fp, "<a href=\"%scommit/%s.html\">", relpath, ci->oid);
547 if ((len = strlen(ci->summary)) > summarylen) {
548 xmlencode(fp, ci->summary, summarylen - 1);
551 xmlencode(fp, ci->summary, len);
555 fputs("</td><td>", fp);
557 xmlencode(fp, ci->author->name, strlen(ci->author->name));
558 fputs("</td><td class=\"num\">", fp);
559 fprintf(fp, "%zu", ci->filecount);
560 fputs("</td><td class=\"num\">", fp);
561 fprintf(fp, "+%zu", ci->addcount);
562 fputs("</td><td class=\"num\">", fp);
563 fprintf(fp, "-%zu", ci->delcount);
564 fputs("</td></tr>\n", fp);
568 r = snprintf(path, sizeof(path), "commit/%s.html", ci->oid);
569 if (r == -1 || (size_t)r >= sizeof(path))
570 errx(1, "path truncated: 'commit/%s.html'", ci->oid);
572 /* check if file exists if so skip it */
573 if (access(path, F_OK)) {
574 fpfile = efopen(path, "w");
575 writeheader(fpfile, ci->summary);
576 fputs("<pre>", fpfile);
577 printshowfile(fpfile, ci);
578 fputs("</pre>\n", fpfile);
584 fputs("</tbody></table>", fp);
594 printcommitatom(FILE *fp, struct commitinfo *ci)
596 fputs("<entry>\n", fp);
598 fprintf(fp, "<id>%s</id>\n", ci->oid);
600 fputs("<updated>", fp);
601 printtimez(fp, &(ci->author->when));
602 fputs("</updated>\n", fp);
605 fputs("<title type=\"text\">", fp);
606 xmlencode(fp, ci->summary, strlen(ci->summary));
607 fputs("</title>\n", fp);
609 fprintf(fp, "<link rel=\"alternate\" type=\"text/html\" href=\"commit/%s.html\" />",
613 fputs("<author><name>", fp);
614 xmlencode(fp, ci->author->name, strlen(ci->author->name));
615 fputs("</name>\n<email>", fp);
616 xmlencode(fp, ci->author->email, strlen(ci->author->email));
617 fputs("</email>\n</author>\n", fp);
620 fputs("<content type=\"text\">", fp);
621 fprintf(fp, "commit %s\n", ci->oid);
622 if (ci->parentoid[0])
623 fprintf(fp, "parent %s\n", ci->parentoid);
625 fputs("Author: ", fp);
626 xmlencode(fp, ci->author->name, strlen(ci->author->name));
628 xmlencode(fp, ci->author->email, strlen(ci->author->email));
629 fputs(">\nDate: ", fp);
630 printtime(fp, &(ci->author->when));
635 xmlencode(fp, ci->msg, strlen(ci->msg));
637 fputs("\n</content>\n", fp);
639 fputs("</entry>\n", fp);
645 struct commitinfo *ci;
646 git_revwalk *w = NULL;
648 size_t i, m = 100; /* last 'm' commits */
650 fputs("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
651 "<feed xmlns=\"http://www.w3.org/2005/Atom\">\n<title>", fp);
652 xmlencode(fp, stripped_name, strlen(stripped_name));
653 fputs(", branch HEAD</title>\n<subtitle>", fp);
654 xmlencode(fp, description, strlen(description));
655 fputs("</subtitle>\n", fp);
657 git_revwalk_new(&w, repo);
658 git_revwalk_push_head(w);
659 git_revwalk_sorting(w, GIT_SORT_TIME);
660 git_revwalk_simplify_first_parent(w);
662 for (i = 0; i < m && !git_revwalk_next(&id, w); i++) {
663 if (!(ci = commitinfo_getbyoid(&id)))
665 printcommitatom(fp, ci);
670 fputs("</feed>", fp);
676 writeblob(git_object *obj, const char *fpath, const char *filename, git_off_t filesize)
678 char tmp[PATH_MAX] = "", *d;
692 if (*p == '/' && strlcat(tmp, "../", sizeof(tmp)) >= sizeof(tmp))
693 errx(1, "path truncated: '../%s'", tmp);
698 fp = efopen(fpath, "w");
699 writeheader(fp, filename);
701 xmlencode(fp, filename, strlen(filename));
702 fprintf(fp, " (%juB)", (uintmax_t)filesize);
703 fputs("</p><hr/>", fp);
705 if (git_blob_is_binary((git_blob *)obj)) {
706 fputs("<p>Binary file</p>\n", fp);
708 lc = writeblobhtml(fp, (git_blob *)obj);
721 filemode(git_filemode_t m)
723 static char mode[11];
725 memset(mode, '-', sizeof(mode) - 1);
736 else if (S_ISFIFO(m))
740 else if (S_ISSOCK(m))
745 if (m & S_IRUSR) mode[1] = 'r';
746 if (m & S_IWUSR) mode[2] = 'w';
747 if (m & S_IXUSR) mode[3] = 'x';
748 if (m & S_IRGRP) mode[4] = 'r';
749 if (m & S_IWGRP) mode[5] = 'w';
750 if (m & S_IXGRP) mode[6] = 'x';
751 if (m & S_IROTH) mode[7] = 'r';
752 if (m & S_IWOTH) mode[8] = 'w';
753 if (m & S_IXOTH) mode[9] = 'x';
755 if (m & S_ISUID) mode[3] = (mode[3] == 'x') ? 's' : 'S';
756 if (m & S_ISGID) mode[6] = (mode[6] == 'x') ? 's' : 'S';
757 if (m & S_ISVTX) mode[9] = (mode[9] == 'x') ? 't' : 'T';
763 writefilestree(FILE *fp, git_tree *tree, const char *branch, const char *path)
765 const git_tree_entry *entry = NULL;
766 git_submodule *module = NULL;
767 git_object *obj = NULL;
769 const char *entryname;
770 char filepath[PATH_MAX], entrypath[PATH_MAX];
774 count = git_tree_entrycount(tree);
775 for (i = 0; i < count; i++) {
776 if (!(entry = git_tree_entry_byindex(tree, i)) ||
777 !(entryname = git_tree_entry_name(entry)))
779 r = snprintf(entrypath, sizeof(entrypath), "%s%s%s",
780 path, path[0] ? "/" : "", entryname);
781 if (r == -1 || (size_t)r >= sizeof(entrypath))
782 errx(1, "path truncated: '%s%s%s'",
783 path, path[0] ? "/" : "", entryname);
785 r = snprintf(filepath, sizeof(filepath), "file/%s%s%s.html",
786 path, path[0] ? "/" : "", entryname);
787 if (r == -1 || (size_t)r >= sizeof(filepath))
788 errx(1, "path truncated: 'file/%s%s%s.html'",
789 path, path[0] ? "/" : "", entryname);
791 if (!git_tree_entry_to_object(&obj, repo, entry)) {
792 switch (git_object_type(obj)) {
797 ret = writefilestree(fp, (git_tree *)obj, branch,
799 git_object_free(obj);
804 git_object_free(obj);
808 filesize = git_blob_rawsize((git_blob *)obj);
809 lc = writeblob(obj, filepath, entryname, filesize);
811 fputs("<tr><td>", fp);
812 fputs(filemode(git_tree_entry_filemode(entry)), fp);
813 fprintf(fp, "</td><td><a href=\"%s%s\">", relpath, filepath);
814 xmlencode(fp, entrypath, strlen(entrypath));
815 fputs("</a></td><td class=\"num\">", fp);
816 if (showlinecount && lc > 0)
817 fprintf(fp, "%dL", lc);
819 fprintf(fp, "%juB", (uintmax_t)filesize);
820 fputs("</td></tr>\n", fp);
821 } else if (!git_submodule_lookup(&module, repo, entryname)) {
822 fprintf(fp, "<tr><td>m---------</td><td><a href=\"%sfile/.gitmodules.html\">",
824 xmlencode(fp, entrypath, strlen(entrypath));
825 git_submodule_free(module);
826 fputs("</a></td><td class=\"num\"></td></tr>\n", fp);
834 writefiles(FILE *fp, const git_oid *id, const char *branch)
836 git_tree *tree = NULL;
837 git_commit *commit = NULL;
840 fputs("<table id=\"files\"><thead>\n<tr>"
841 "<td>Mode</td><td>Name</td><td class=\"num\">Size</td>"
842 "</tr>\n</thead><tbody>\n", fp);
844 if (git_commit_lookup(&commit, repo, id) ||
845 git_commit_tree(&tree, commit))
847 ret = writefilestree(fp, tree, branch, "");
850 fputs("</tbody></table>", fp);
852 git_commit_free(commit);
859 refs_cmp(const void *v1, const void *v2)
861 git_reference *r1 = (*(git_reference **)v1);
862 git_reference *r2 = (*(git_reference **)v2);
865 t1 = git_reference_is_branch(r1);
866 t2 = git_reference_is_branch(r2);
871 return strcmp(git_reference_shorthand(r1),
872 git_reference_shorthand(r2));
878 struct commitinfo *ci;
879 const git_oid *id = NULL;
880 git_object *obj = NULL;
881 git_reference *dref = NULL, *r, *ref = NULL;
882 git_reference_iterator *it = NULL;
883 git_reference **refs = NULL;
884 size_t count, i, j, refcount;
885 const char *titles[] = { "Branches", "Tags" };
886 const char *ids[] = { "branches", "tags" };
889 if (git_reference_iterator_new(&it, repo))
892 for (refcount = 0; !git_reference_next(&ref, it); refcount++) {
893 if (!(refs = reallocarray(refs, refcount + 1, sizeof(git_reference *))))
895 refs[refcount] = ref;
897 git_reference_iterator_free(it);
899 /* sort by type then shorthand name */
900 qsort(refs, refcount, sizeof(git_reference *), refs_cmp);
902 for (j = 0; j < 2; j++) {
903 for (i = 0, count = 0; i < refcount; i++) {
904 if (!(git_reference_is_branch(refs[i]) && j == 0) &&
905 !(git_reference_is_tag(refs[i]) && j == 1))
908 switch (git_reference_type(refs[i])) {
909 case GIT_REF_SYMBOLIC:
910 if (git_reference_resolve(&dref, refs[i]))
920 if (!(id = git_reference_target(r)))
922 if (git_reference_peel(&obj, r, GIT_OBJ_ANY))
924 if (!(id = git_object_id(obj)))
926 if (!(ci = commitinfo_getbyoid(id)))
929 /* print header if it has an entry (first). */
931 fprintf(fp, "<h2>%s</h2><table id=\"%s\"><thead>\n<tr><td>Name</td>"
932 "<td>Last commit date</td><td>Author</td>\n</tr>\n</thead><tbody>\n",
937 name = git_reference_shorthand(r);
939 fputs("<tr><td>", fp);
940 xmlencode(fp, name, strlen(name));
941 fputs("</td><td>", fp);
943 printtimeshort(fp, &(ci->author->when));
944 fputs("</td><td>", fp);
946 xmlencode(fp, ci->author->name, strlen(ci->author->name));
947 fputs("</td></tr>\n", fp);
952 git_object_free(obj);
954 git_reference_free(dref);
959 fputs("</tbody></table><br/>", fp);
963 git_object_free(obj);
964 git_reference_free(dref);
966 for (i = 0; i < refcount; i++)
967 git_reference_free(refs[i]);
974 main(int argc, char *argv[])
976 git_object *obj = NULL;
977 const git_oid *head = NULL;
978 const git_error *e = NULL;
980 char path[PATH_MAX], repodirabs[PATH_MAX + 1], *p;
984 fprintf(stderr, "%s <repodir>\n", argv[0]);
988 if (!realpath(repodir, repodirabs))
993 if ((status = git_repository_open_ext(&repo, repodir,
994 GIT_REPOSITORY_OPEN_NO_SEARCH, NULL)) < 0) {
996 fprintf(stderr, "%s: %s\n", argv[0], e->message);
1001 if (git_revparse_single(&obj, repo, "HEAD"))
1003 head = git_object_id(obj);
1004 git_object_free(obj);
1006 /* use directory name as name */
1007 if ((name = strrchr(repodirabs, '/')))
1012 /* strip .git suffix */
1013 if (!(stripped_name = strdup(name)))
1015 if ((p = strrchr(stripped_name, '.')))
1016 if (!strcmp(p, ".git"))
1019 /* read description or .git/description */
1020 r = snprintf(path, sizeof(path), "%s%s%s",
1021 repodir, repodir[strlen(repodir)] == '/' ? "" : "/", "description");
1022 if (r == -1 || (size_t)r >= sizeof(path))
1023 errx(1, "path truncated: '%s%s%s'",
1024 repodir, repodir[strlen(repodir)] == '/' ? "" : "/", "description");
1025 if (!(fpread = fopen(path, "r"))) {
1026 r = snprintf(path, sizeof(path), "%s%s%s",
1027 repodir, repodir[strlen(repodir)] == '/' ? "" : "/", ".git/description");
1028 if (r == -1 || (size_t)r >= sizeof(path))
1029 errx(1, "path truncated: '%s%s%s'",
1030 repodir, repodir[strlen(repodir)] == '/' ? "" : "/", ".git/description");
1031 fpread = fopen(path, "r");
1034 if (!fgets(description, sizeof(description), fpread))
1035 description[0] = '\0';
1039 /* read url or .git/url */
1040 r = snprintf(path, sizeof(path), "%s%s%s",
1041 repodir, repodir[strlen(repodir)] == '/' ? "" : "/", "url");
1042 if (r == -1 || (size_t)r >= sizeof(path))
1043 errx(1, "path truncated: '%s%s%s'",
1044 repodir, repodir[strlen(repodir)] == '/' ? "" : "/", "url");
1045 if (!(fpread = fopen(path, "r"))) {
1046 r = snprintf(path, sizeof(path), "%s%s%s",
1047 repodir, repodir[strlen(repodir)] == '/' ? "" : "/", ".git/url");
1048 if (r == -1 || (size_t)r >= sizeof(path))
1049 errx(1, "path truncated: '%s%s%s'",
1050 repodir, repodir[strlen(repodir)] == '/' ? "" : "/", ".git/url");
1051 fpread = fopen(path, "r");
1054 if (!fgets(cloneurl, sizeof(cloneurl), fpread))
1056 cloneurl[strcspn(cloneurl, "\n")] = '\0';
1061 haslicense = !git_revparse_single(&obj, repo, "HEAD:LICENSE");
1062 git_object_free(obj);
1064 hasreadme = !git_revparse_single(&obj, repo, "HEAD:README");
1065 git_object_free(obj);
1066 hassubmodules = !git_revparse_single(&obj, repo, "HEAD:.gitmodules");
1067 git_object_free(obj);
1070 fp = efopen("log.html", "w");
1072 writeheader(fp, "Log");
1073 mkdir("commit", 0755);
1078 /* files for HEAD */
1079 fp = efopen("files.html", "w");
1080 writeheader(fp, "Files");
1081 writefiles(fp, head, "HEAD");
1085 /* summary page with branches and tags */
1086 fp = efopen("refs.html", "w");
1087 writeheader(fp, "Refs");
1093 fp = efopen("atom.xml", "w");
1098 git_repository_free(repo);
1099 git_libgit2_shutdown();