stagit

My fork of stagit

git clone git://git.shimmy1996.com/stagit.git
commit 75e3dd75e3b8fb19d91c33d91ea5647ca22a9b17
parent 75555cd99ee4d5df765f7dd6f0d09f2f925be725
Author: Shimmy Xu <shimmy.xu@shimmy1996.com>
Date:   Sat,  4 Apr 2020 11:21:53 -0500

Only generate index for public repositories

Diffstat:
Mstagit-index.c | 27++++++++++++++++++++-------
1 file changed, 20 insertions(+), 7 deletions(-)
diff --git a/stagit-index.c b/stagit-index.c
@@ -1,5 +1,6 @@
 #include <err.h>
 #include <limits.h>
+#include <stdbool.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -89,7 +90,7 @@ writefooter(FILE *fp)
 }
 
 int
-writelog(FILE *fp)
+writelog(FILE *fp, bool is_public)
 {
 	git_commit *commit = NULL;
 	const git_signature *author;
@@ -117,11 +118,17 @@ writelog(FILE *fp)
 		if (!strcmp(p, ".git"))
 			*p = '\0';
 
-	fputs("<tr><td><a href=\"", fp);
-	xmlencode(fp, stripped_name, strlen(stripped_name));
-	fputs("/log.html\">", fp);
-	xmlencode(fp, stripped_name, strlen(stripped_name));
-	fputs("</a></td><td>", fp);
+	fputs("<tr><td>", fp);
+    if (is_public) {
+		fputs("<a href=\"", fp);
+		xmlencode(fp, stripped_name, strlen(stripped_name));
+		fputs("/log.html\">", fp);
+		xmlencode(fp, stripped_name, strlen(stripped_name));
+		fputs("</a>", fp);
+    } else {
+		xmlencode(fp, stripped_name, strlen(stripped_name));
+    }
+	fputs("</td><td>", fp);
 	xmlencode(fp, description, strlen(description));
 	fputs("</td><td>", fp);
 	xmlencode(fp, owner, strlen(owner));
@@ -145,6 +152,7 @@ main(int argc, char *argv[])
 	char path[PATH_MAX], repodirabs[PATH_MAX + 1];
 	const char *repodir;
 	int i, ret = 0;
+    bool is_public = false;
 
 	if (argc < 2) {
 		fprintf(stderr, "%s [repodir...]\n", argv[0]);
@@ -204,7 +212,12 @@ main(int argc, char *argv[])
 			owner[strcspn(owner, "\n")] = '\0';
 			fclose(fp);
 		}
-		writelog(stdout);
+
+		/* check if repo is public */
+		joinpath(path, sizeof(path), repodir, "git-daemon-export-ok");
+		is_public = fopen(path, "r");
+
+		writelog(stdout, is_public);
 	}
 	writefooter(stdout);