ctucx.git: stagit

ctucx' stagit fork

commit 94ff57d20ecb9c7248660a1dd91244706d035071
parent 1afb160527da0698f76094d7f323205013aa0a00
Author: Leah (ctucx) <leah@ctu.cx>
Date: Tue, 24 May 2022 13:59:16 +0200

about: show last two commits above readme
1 file changed, 25 insertions(+), 0 deletions(-)
M
stagit.c
|
25
+++++++++++++++++++++++++
diff --git a/stagit.c b/stagit.c
@@ -1265,6 +1265,8 @@ int
 main(int argc, char *argv[])
 {
 	git_object *obj = NULL;
+	git_revwalk *walker = NULL;
+	git_oid id;
 	const git_oid *head = NULL;
 	mode_t mask;
 	FILE *fp, *fpread;

@@ -1272,6 +1274,8 @@ main(int argc, char *argv[])
 	char tmppath[64] = "cache.XXXXXXXXXXXX", buf[BUFSIZ];
 	size_t n;
 	int i, fd, r;
+	int count = 0;
+	struct commitinfo *ci;
 
     time_t now = time(&now);
 	gen_time = ctime(&now);

@@ -1397,6 +1401,26 @@ main(int argc, char *argv[])
 	if (readme) {
 		fp = efopen("about.html", "w");
 		writeheader(fp, "about", "about");
+
+		git_revwalk_new(&walker, repo);
+		git_revwalk_push(walker, head);
+
+		fputs("<h3>last commits</h3><div class=\"log\">", fp);
+		while (!git_revwalk_next(&id, walker)) {
+			if (!(ci = commitinfo_getbyoid(&id))) break;
+			if (count == 2) {
+				fputs("<a href=\"log.html\"><div class=\"event center-text\">more</div></a>", fp);
+				break;
+			}
+			count++;
+
+			writelogline(fp, ci);
+
+			commitinfo_free(ci);
+		}
+		git_revwalk_free(walker);
+		fputs("</div>", fp);
+
 		git_revparse_single(&obj, repo, readmefiles[r]);
 		const char *s = git_blob_rawcontent((git_blob *)obj);
 		if (r == 1 | r == 2) {

@@ -1412,6 +1436,7 @@ main(int argc, char *argv[])
 			fputs("</pre></div>", fp);
 		}
 		git_object_free(obj);
+
 		writefooter(fp);
 		fclose(fp);
 	}