X-Git-Url: https://git.armaanb.net/?a=blobdiff_plain;f=stagit-index.c;h=2b243ec15660ba042313d4317b2d33810f9300a3;hb=ab6c98580a0d100618c8acc0602b36663517ba61;hp=09e5513051c1f13bc5565b52385fc3f705de8c2e;hpb=99583eee62af43c0504bfc2aab6058b69a46313b;p=stagit.git diff --git a/stagit-index.c b/stagit-index.c index 09e5513..2b243ec 100644 --- a/stagit-index.c +++ b/stagit-index.c @@ -1,18 +1,13 @@ -#include - #include -#include -#include #include #include #include #include +#include #include #include -#include "compat.h" - static git_repository *repo; static const char *relpath = ""; @@ -21,10 +16,6 @@ static char description[255] = "Repositories"; static char *name = ""; static char owner[255]; -#ifndef USE_PLEDGE -#define pledge(p1,p2) 0 -#endif - void joinpath(char *buf, size_t bufsiz, const char *path, const char *path2) { @@ -32,7 +23,7 @@ joinpath(char *buf, size_t bufsiz, const char *path, const char *path2) r = snprintf(buf, bufsiz, "%s%s%s", path, path[0] && path[strlen(path) - 1] != '/' ? "/" : "", path2); - if (r == -1 || (size_t)r >= bufsiz) + if (r < 0 || (size_t)r >= bufsiz) errx(1, "path truncated: '%s%s%s'", path, path[0] && path[strlen(path) - 1] != '/' ? "/" : "", path2); } @@ -109,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) || @@ -151,21 +141,27 @@ err: 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++) { @@ -175,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; }