X-Git-Url: https://git.armaanb.net/?a=blobdiff_plain;f=stagit-index.c;h=2b243ec15660ba042313d4317b2d33810f9300a3;hb=dd32948ba00cb30c852de72260255a5ebb24ccff;hp=8a01894d3c20a6a0a8e345b3f12ecce69b275994;hpb=069f105725677ce2784d3d0def156c3115c9e330;p=stagit.git diff --git a/stagit-index.c b/stagit-index.c index 8a01894..2b243ec 100644 --- a/stagit-index.c +++ b/stagit-index.c @@ -1,34 +1,32 @@ -#include - #include -#include -#include #include #include #include #include +#include #include #include -#include "compat.h" - static git_repository *repo; static const char *relpath = ""; -static const char *repodir; static char description[255] = "Repositories"; static char *name = ""; static char owner[255]; -#ifndef USE_PLEDGE -int -pledge(const char *promises, const char *paths[]) +void +joinpath(char *buf, size_t bufsiz, const char *path, const char *path2) { - return 0; + int r; + + r = snprintf(buf, bufsiz, "%s%s%s", + path, path[0] && path[strlen(path) - 1] != '/' ? "/" : "", path2); + if (r < 0 || (size_t)r >= bufsiz) + errx(1, "path truncated: '%s%s%s'", + path, path[0] && path[strlen(path) - 1] != '/' ? "/" : "", path2); } -#endif /* Escape characters below as HTML 2.0 / XML 1.0. */ void @@ -40,7 +38,7 @@ xmlencode(FILE *fp, const char *s, size_t len) switch(*s) { case '<': fputs("<", fp); break; case '>': fputs(">", fp); break; - case '\'': fputs("'", fp); break; + case '\'': fputs("'" , fp); break; case '&': fputs("&", fp); break; case '"': fputs(""", fp); break; default: fputc(*s, fp); @@ -62,32 +60,32 @@ printtimeshort(FILE *fp, const git_time *intime) fputs(out, fp); } -int +void writeheader(FILE *fp) { fputs("\n" - "\n\n" + "\n\n" "\n" - "\n", fp); + "<title>", fp); xmlencode(fp, description, strlen(description)); fprintf(fp, "\n\n", relpath); fprintf(fp, "\n", relpath); fputs("\n\n", fp); fprintf(fp, "\n\n" - "\n
\"\"

%s

%s
\n", - relpath, name, description); - fputs("
\n
\n
\n" - "\n" - "" - "\n", fp); - - return 0; + "\n
NameDescriptionOwnerLast commit
", relpath); + xmlencode(fp, description, strlen(description)); + fputs("
\n" + "
\n
\n
\n" + "\n" + "" + "" + "\n", fp); } -int +void writefooter(FILE *fp) { - return !fputs("\n
NameDescriptionOwnerLast commit
\n
\n\n\n", fp); + fputs("\n\n
\n\n\n", fp); } int @@ -102,7 +100,6 @@ writelog(FILE *fp) git_revwalk_new(&w, repo); git_revwalk_push_head(w); - git_revwalk_sorting(w, GIT_SORT_TIME); git_revwalk_simplify_first_parent(w); if (git_revwalk_next(&id, w) || @@ -141,35 +138,30 @@ err: return ret; } -void -joinpath(char *buf, size_t bufsiz, const char *path, const char *path2) -{ - int r; - - r = snprintf(buf, bufsiz, "%s%s%s", - repodir, 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); -} - int main(int argc, char *argv[]) { - const git_error *e = NULL; FILE *fp; char path[PATH_MAX], repodirabs[PATH_MAX + 1]; + const char *repodir; int i, ret = 0; - if (pledge("stdio rpath", NULL) == -1) - err(1, "pledge"); - if (argc < 2) { fprintf(stderr, "%s [repodir...]\n", argv[0]); return 1; } + git_libgit2_init(); +#ifdef __OpenBSD__ + for (i = 1; i < argc; i++) + if (unveil(argv[i], "r") == -1) + err(1, "unveil: %s", argv[i]); + + if (pledge("stdio rpath", NULL) == -1) + err(1, "pledge"); +#endif + writeheader(stdout); for (i = 1; i < argc; i++) { @@ -179,8 +171,7 @@ main(int argc, char *argv[]) if (git_repository_open_ext(&repo, repodir, GIT_REPOSITORY_OPEN_NO_SEARCH, NULL)) { - e = giterr_last(); - fprintf(stderr, "%s: %s\n", argv[0], e->message); + fprintf(stderr, "%s: cannot open repository\n", argv[0]); ret = 1; continue; }