#include <git2.h>
#include "compat.h"
-#include "config.h"
static git_repository *repo;
static char *name = "";
static char owner[255];
+#ifndef USE_PLEDGE
+int
+pledge(const char *promises, const char *paths[])
+{
+ return 0;
+}
+#endif
+
+void
+joinpath(char *buf, size_t bufsiz, const char *path, const char *path2)
+{
+ int r;
+
+ r = snprintf(buf, bufsiz, "%s%s%s",
+ path, path[0] && path[strlen(path) - 1] != '/' ? "/" : "", path2);
+ if (r == -1 || (size_t)r >= bufsiz)
+ errx(1, "path truncated: '%s%s%s'",
+ path, path[0] && path[strlen(path) - 1] != '/' ? "/" : "", path2);
+}
+
/* Escape characters below as HTML 2.0 / XML 1.0. */
void
xmlencode(FILE *fp, const char *s, size_t len)
}
void
-printtimeformat(FILE *fp, const git_time *intime, const char *fmt)
+printtimeshort(FILE *fp, const git_time *intime)
{
struct tm *intm;
time_t t;
char out[32];
- t = (time_t) intime->time + (intime->offset * 60);
- intm = gmtime(&t);
- strftime(out, sizeof(out), fmt, intm);
+ t = (time_t)intime->time;
+ if (!(intm = gmtime(&t)))
+ return;
+ strftime(out, sizeof(out), "%Y-%m-%d %H:%M", intm);
fputs(out, fp);
}
void
-printtimeshort(FILE *fp, const git_time *intime)
-{
- printtimeformat(fp, intime, "%Y-%m-%d %H:%M");
-}
-
-int
writeheader(FILE *fp)
{
fputs("<!DOCTYPE html>\n"
"<table id=\"index\"><thead>\n"
"<tr><td>Name</td><td>Description</td><td>Owner</td><td>Last commit</td></tr>"
"</thead><tbody>\n", fp);
-
- return 0;
}
-int
+void
writefooter(FILE *fp)
{
- return !fputs("</tbody>\n</table>\n</div>\n</body>\n</html>\n", fp);
+ fputs("</tbody>\n</table>\n</div>\n</body>\n</html>\n", fp);
}
int
writelog(FILE *fp)
{
- char *stripped_name = NULL, *p;
git_commit *commit = NULL;
const git_signature *author;
git_revwalk *w = NULL;
git_oid id;
+ char *stripped_name = NULL, *p;
int ret = 0;
git_revwalk_new(&w, repo);
const git_error *e = NULL;
FILE *fp;
char path[PATH_MAX], repodirabs[PATH_MAX + 1];
- int i, r, ret = 0;
+ int i, ret = 0;
+
+ if (pledge("stdio rpath", NULL) == -1)
+ err(1, "pledge");
if (argc < 2) {
fprintf(stderr, "%s [repodir...]\n", argv[0]);
name = "";
/* read description or .git/description */
- description[0] = '\0';
- r = snprintf(path, sizeof(path), "%s%s%s",
- repodir, repodir[strlen(repodir)] == '/' ? "" : "/", "description");
- if (r == -1 || (size_t)r >= sizeof(path))
- errx(1, "path truncated: '%s%s%s'",
- repodir, repodir[strlen(repodir)] == '/' ? "" : "/", "description");
+ joinpath(path, sizeof(path), repodir, "description");
if (!(fp = fopen(path, "r"))) {
- r = snprintf(path, sizeof(path), "%s%s%s",
- repodir, repodir[strlen(repodir)] == '/' ? "" : "/", ".git/description");
- if (r == -1 || (size_t)r >= sizeof(path))
- errx(1, "path truncated: '%s%s%s'",
- repodir, repodir[strlen(repodir)] == '/' ? "" : "/", ".git/description");
+ joinpath(path, sizeof(path), repodir, ".git/description");
fp = fopen(path, "r");
}
+ description[0] = '\0';
if (fp) {
if (!fgets(description, sizeof(description), fp))
description[0] = '\0';
}
/* read owner or .git/owner */
- owner[0] = '\0';
- r = snprintf(path, sizeof(path), "%s%s%s",
- repodir, repodir[strlen(repodir)] == '/' ? "" : "/", "owner");
- if (r == -1 || (size_t)r >= sizeof(path))
- errx(1, "path truncated: '%s%s%s'",
- repodir, repodir[strlen(repodir)] == '/' ? "" : "/", "owner");
+ joinpath(path, sizeof(path), repodir, "owner");
if (!(fp = fopen(path, "r"))) {
- r = snprintf(path, sizeof(path), "%s%s%s",
- repodir, repodir[strlen(repodir)] == '/' ? "" : "/", ".git/owner");
- if (r == -1 || (size_t)r >= sizeof(path))
- errx(1, "path truncated: '%s%s%s'",
- repodir, repodir[strlen(repodir)] == '/' ? "" : "/", ".git/owner");
+ joinpath(path, sizeof(path), repodir, ".git/owner");
fp = fopen(path, "r");
}
+ owner[0] = '\0';
if (fp) {
if (!fgets(owner, sizeof(owner), fp))
owner[0] = '\0';