From 7c419a8bac26e491206953bf2646ac634296b160 Mon Sep 17 00:00:00 2001
From: Hiltjo Posthuma
Date: Tue, 15 Mar 2022 16:58:32 +0100
Subject: [PATCH 1/6] add dark mode support for the example stylesheet
---
style.css | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 48 insertions(+)
diff --git a/style.css b/style.css
index f8780ea..a2ba187 100644
--- a/style.css
+++ b/style.css
@@ -104,3 +104,51 @@ pre a.i:hover,
pre a.d:hover {
text-decoration: none;
}
+
+@media (prefers-color-scheme: dark) {
+ body {
+ background-color: #000;
+ color: #bdbdbd;
+ }
+ hr {
+ border-color: #222;
+ }
+ a {
+ color: #56c8ff;
+ }
+ a:target {
+ background-color: #222;
+ }
+ .desc {
+ color: #aaa;
+ }
+ #blob a {
+ color: #555;
+ }
+ #blob a:target {
+ color: #eee;
+ }
+ #blob a:hover {
+ color: #56c8ff;
+ }
+ pre a.h {
+ color: #00cdcd;
+ }
+ .A,
+ span.i,
+ pre a.i {
+ color: #00cd00;
+ }
+ .D,
+ span.d,
+ pre a.d {
+ color: #cd0000;
+ }
+ #branches tr:hover td,
+ #tags tr:hover td,
+ #index tr:hover td,
+ #log tr:hover td,
+ #files tr:hover td {
+ background-color: #111;
+ }
+}
From d0e36eb6abce72c587dd53dcabc35120c3cf3a81 Mon Sep 17 00:00:00 2001
From: Hiltjo Posthuma
Date: Sat, 19 Mar 2022 12:22:43 +0100
Subject: [PATCH 2/6] improve stream read and write error handling
---
stagit-index.c | 16 +++++++++++++++-
stagit.c | 35 +++++++++++++++++++++++++++--------
2 files changed, 42 insertions(+), 9 deletions(-)
diff --git a/stagit-index.c b/stagit-index.c
index 7c1f76d..26ef16d 100644
--- a/stagit-index.c
+++ b/stagit-index.c
@@ -16,6 +16,16 @@ static char description[255] = "Repositories";
static char *name = "";
static char owner[255];
+/* Handle read or write errors for a FILE * stream */
+void
+checkfileerror(FILE *fp, const char *name, int mode)
+{
+ if (mode == 'r' && ferror(fp))
+ errx(1, "read error: %s", name);
+ else if (mode == 'w' && (fflush(fp) || ferror(fp)))
+ errx(1, "write error: %s", name);
+}
+
void
joinpath(char *buf, size_t bufsiz, const char *path, const char *path2)
{
@@ -214,6 +224,7 @@ main(int argc, char *argv[])
if (fp) {
if (!fgets(description, sizeof(description), fp))
description[0] = '\0';
+ checkfileerror(fp, "description", 'r');
fclose(fp);
}
@@ -227,8 +238,9 @@ main(int argc, char *argv[])
if (fp) {
if (!fgets(owner, sizeof(owner), fp))
owner[0] = '\0';
- owner[strcspn(owner, "\n")] = '\0';
+ checkfileerror(fp, "owner", 'r');
fclose(fp);
+ owner[strcspn(owner, "\n")] = '\0';
}
writelog(stdout);
}
@@ -238,5 +250,7 @@ main(int argc, char *argv[])
git_repository_free(repo);
git_libgit2_shutdown();
+ checkfileerror(stdout, "", 'w');
+
return ret;
}
diff --git a/stagit.c b/stagit.c
index 0d53b72..54622a1 100644
--- a/stagit.c
+++ b/stagit.c
@@ -79,6 +79,16 @@ static char lastoidstr[GIT_OID_HEXSZ + 2]; /* id + newline + NUL byte */
static FILE *rcachefp, *wcachefp;
static const char *cachefile;
+/* Handle read or write errors for a FILE * stream */
+void
+checkfileerror(FILE *fp, const char *name, int mode)
+{
+ if (mode == 'r' && ferror(fp))
+ errx(1, "read error: %s", name);
+ else if (mode == 'w' && (fflush(fp) || ferror(fp)))
+ errx(1, "write error: %s", name);
+}
+
void
joinpath(char *buf, size_t bufsiz, const char *path, const char *path2)
{
@@ -814,6 +824,7 @@ writelog(FILE *fp, const git_oid *oid)
printshowfile(fpfile, ci);
fputs("\n", fpfile);
writefooter(fpfile);
+ checkfileerror(fpfile, path, 'w');
fclose(fpfile);
}
err:
@@ -963,14 +974,13 @@ writeblob(git_object *obj, const char *fpath, const char *filename, size_t files
fprintf(fp, " (%zuB)", filesize);
fputs("
", fp);
- if (git_blob_is_binary((git_blob *)obj)) {
+ if (git_blob_is_binary((git_blob *)obj))
fputs("Binary file.
\n", fp);
- } else {
+ else
lc = writeblobhtml(fp, (git_blob *)obj);
- if (ferror(fp))
- err(1, "fwrite");
- }
+
writefooter(fp);
+ checkfileerror(fp, fpath, 'w');
fclose(fp);
relpath = "";
@@ -1276,6 +1286,7 @@ main(int argc, char *argv[])
if (fpread) {
if (!fgets(description, sizeof(description), fpread))
description[0] = '\0';
+ checkfileerror(fpread, path, 'r');
fclose(fpread);
}
@@ -1288,8 +1299,9 @@ main(int argc, char *argv[])
if (fpread) {
if (!fgets(cloneurl, sizeof(cloneurl), fpread))
cloneurl[0] = '\0';
- cloneurl[strcspn(cloneurl, "\n")] = '\0';
+ checkfileerror(fpread, path, 'r');
fclose(fpread);
+ cloneurl[strcspn(cloneurl, "\n")] = '\0';
}
/* check LICENSE */
@@ -1349,13 +1361,15 @@ main(int argc, char *argv[])
while (!feof(rcachefp)) {
n = fread(buf, 1, sizeof(buf), rcachefp);
if (ferror(rcachefp))
- err(1, "fread");
+ break;
if (fwrite(buf, 1, n, fp) != n ||
fwrite(buf, 1, n, wcachefp) != n)
- err(1, "fwrite");
+ break;
}
+ checkfileerror(rcachefp, cachefile, 'r');
fclose(rcachefp);
}
+ checkfileerror(wcachefp, tmppath, 'w');
fclose(wcachefp);
} else {
if (head)
@@ -1364,6 +1378,7 @@ main(int argc, char *argv[])
fputs("", fp);
writefooter(fp);
+ checkfileerror(fp, "log.html", 'w');
fclose(fp);
/* files for HEAD */
@@ -1372,6 +1387,7 @@ main(int argc, char *argv[])
if (head)
writefiles(fp, head);
writefooter(fp);
+ checkfileerror(fp, "files.html", 'w');
fclose(fp);
/* summary page with branches and tags */
@@ -1379,16 +1395,19 @@ main(int argc, char *argv[])
writeheader(fp, "Refs");
writerefs(fp);
writefooter(fp);
+ checkfileerror(fp, "refs.html", 'w');
fclose(fp);
/* Atom feed */
fp = efopen("atom.xml", "w");
writeatom(fp, 1);
+ checkfileerror(fp, "atom.xml", 'w');
fclose(fp);
/* Atom feed for tags / releases */
fp = efopen("tags.xml", "w");
writeatom(fp, 0);
+ checkfileerror(fp, "tags.xml", 'w');
fclose(fp);
/* rename new cache file on success */
From a8a5e9c3b37e133d26fe3ea5cd361281d7a56c85 Mon Sep 17 00:00:00 2001
From: Hiltjo Posthuma
Date: Sat, 2 Apr 2022 17:35:47 +0200
Subject: [PATCH 3/6] bump version to 1.1
---
Makefile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Makefile b/Makefile
index 3558552..0c03f81 100644
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,7 @@
.POSIX:
NAME = stagit
-VERSION = 1.0
+VERSION = 1.1
# paths
PREFIX = /usr/local
From 1357ad5181f80a99fe9c436af134e947ec7f4d29 Mon Sep 17 00:00:00 2001
From: Anton Lindqvist
Date: Tue, 24 May 2022 10:58:37 +0200
Subject: [PATCH 4/6] Allow git to run on an other user repository
Reported by Anton:
"Recent versions of libgit2 broke stagit for me due to the added opt-out
GIT_OPT_SET_OWNER_VALIDATION configuration knob. My repositories are owned by
root:vcs and I run stagit as another user which happens to be in vcs group but
not the owner of the repository. Disabling the validation makes stagit work as
expected again."
Some notes:
When using regular git it also provides a knob. This is due to a security
concern in some cases, which is not applicable to stagit.
git log somerepo
fatal: unsafe repository ('somerepo' is owned by someone else)
To add an exception for this directory, call:
git config --global --add safe.directory somerepo
See also / related:
- https://github.blog/2022-04-12-git-security-vulnerability-announced/
---
stagit-index.c | 2 ++
stagit.c | 2 ++
2 files changed, 4 insertions(+)
diff --git a/stagit-index.c b/stagit-index.c
index 26ef16d..735775b 100644
--- a/stagit-index.c
+++ b/stagit-index.c
@@ -188,6 +188,8 @@ main(int argc, char *argv[])
git_libgit2_init();
for (i = 1; i <= GIT_CONFIG_LEVEL_APP; i++)
git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, i, "");
+ /* do not require the git repository to be owned by the current user */
+ git_libgit2_opts(GIT_OPT_SET_OWNER_VALIDATION, 0);
#ifdef __OpenBSD__
if (pledge("stdio rpath", NULL) == -1)
diff --git a/stagit.c b/stagit.c
index 54622a1..2a9c3fe 100644
--- a/stagit.c
+++ b/stagit.c
@@ -1235,6 +1235,8 @@ main(int argc, char *argv[])
git_libgit2_init();
for (i = 1; i <= GIT_CONFIG_LEVEL_APP; i++)
git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, i, "");
+ /* do not require the git repository to be owned by the current user */
+ git_libgit2_opts(GIT_OPT_SET_OWNER_VALIDATION, 0);
#ifdef __OpenBSD__
if (unveil(repodir, "r") == -1)
From 70541c5e2cbdc141ba94e76899aba5f07047cecf Mon Sep 17 00:00:00 2001
From: Hiltjo Posthuma
Date: Tue, 24 May 2022 14:07:27 +0200
Subject: [PATCH 5/6] remain compatible with slightly older libgit versions for
now
---
stagit-index.c | 2 ++
stagit.c | 2 ++
2 files changed, 4 insertions(+)
diff --git a/stagit-index.c b/stagit-index.c
index 735775b..d2f22a5 100644
--- a/stagit-index.c
+++ b/stagit-index.c
@@ -188,8 +188,10 @@ main(int argc, char *argv[])
git_libgit2_init();
for (i = 1; i <= GIT_CONFIG_LEVEL_APP; i++)
git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, i, "");
+#ifdef GIT_OPT_SET_OWNER_VALIDATION
/* do not require the git repository to be owned by the current user */
git_libgit2_opts(GIT_OPT_SET_OWNER_VALIDATION, 0);
+#endif
#ifdef __OpenBSD__
if (pledge("stdio rpath", NULL) == -1)
diff --git a/stagit.c b/stagit.c
index 2a9c3fe..911643e 100644
--- a/stagit.c
+++ b/stagit.c
@@ -1235,8 +1235,10 @@ main(int argc, char *argv[])
git_libgit2_init();
for (i = 1; i <= GIT_CONFIG_LEVEL_APP; i++)
git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, i, "");
+#ifdef GIT_OPT_SET_OWNER_VALIDATION
/* do not require the git repository to be owned by the current user */
git_libgit2_opts(GIT_OPT_SET_OWNER_VALIDATION, 0);
+#endif
#ifdef __OpenBSD__
if (unveil(repodir, "r") == -1)
From 289045115432562f5fb4ddc721bd9008e8df4ad5 Mon Sep 17 00:00:00 2001
From: Hiltjo Posthuma
Date: Fri, 27 May 2022 21:29:14 +0200
Subject: [PATCH 6/6] Revert "remain compatible with slightly older libgit
versions for now"
This reverts commit 70541c5e2cbdc141ba94e76899aba5f07047cecf.
Reported by Anton:
The last commit[1] is not correct as GIT_OPT_SET_OWNER_VALIDATION is not
a preprocessor directive but rather an enum. Causing the branch to never
be entered.
---
stagit-index.c | 2 --
stagit.c | 2 --
2 files changed, 4 deletions(-)
diff --git a/stagit-index.c b/stagit-index.c
index d2f22a5..735775b 100644
--- a/stagit-index.c
+++ b/stagit-index.c
@@ -188,10 +188,8 @@ main(int argc, char *argv[])
git_libgit2_init();
for (i = 1; i <= GIT_CONFIG_LEVEL_APP; i++)
git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, i, "");
-#ifdef GIT_OPT_SET_OWNER_VALIDATION
/* do not require the git repository to be owned by the current user */
git_libgit2_opts(GIT_OPT_SET_OWNER_VALIDATION, 0);
-#endif
#ifdef __OpenBSD__
if (pledge("stdio rpath", NULL) == -1)
diff --git a/stagit.c b/stagit.c
index 911643e..2a9c3fe 100644
--- a/stagit.c
+++ b/stagit.c
@@ -1235,10 +1235,8 @@ main(int argc, char *argv[])
git_libgit2_init();
for (i = 1; i <= GIT_CONFIG_LEVEL_APP; i++)
git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, i, "");
-#ifdef GIT_OPT_SET_OWNER_VALIDATION
/* do not require the git repository to be owned by the current user */
git_libgit2_opts(GIT_OPT_SET_OWNER_VALIDATION, 0);
-#endif
#ifdef __OpenBSD__
if (unveil(repodir, "r") == -1)