"GOT", but the "O" is a cute, smiling pufferfish. Index | Thread | Search

From:
Omar Polo <op@omarpolo.com>
Subject:
gotwebd: customize the number of tags/commits in summary page
To:
gameoftrees@openbsd.org
Date:
Sun, 17 Dec 2023 20:39:01 +0100

Download raw body.

Thread
i'm playing with some layout changes over at my instance, and it
occurred to me that we don't have any knobs to change the number of tags
and commits showed in the summary page.  Since we allow to change the
number of these per-page (although only via a single knob) and we also
changed the defaults over time, I don't think it's bad to allow to
change these.

opinions?  oks?

diff /home/op/w/got
commit - e83a9e2aae680ffbdfb86afc896276d7010ce907
path + /home/op/w/got
blob - e3dca64b089f1e1e0d76ef5826837a9f3b31cf50
file + gotwebd/gotweb.c
--- gotwebd/gotweb.c
+++ gotwebd/gotweb.c
@@ -346,11 +346,11 @@ gotweb_process_request(struct request *c)
 			    error->msg);
 			goto err;
 		}
-		error = got_get_repo_commits(c, D_MAXSLCOMMDISP);
+		error = got_get_repo_commits(c, srv->summary_commits_display);
 		if (error)
 			goto err;
 		qs->action = TAGS;
-		error = got_get_repo_tags(c, D_MAXSLTAGDISP);
+		error = got_get_repo_tags(c, srv->summary_tags_display);
 		if (error) {
 			log_warnx("%s: got_get_repo_tags: %s", __func__,
 			    error->msg);
blob - 0a41fb98df13059fc8f142e386a1d099a8d24de9
file + gotwebd/gotwebd.conf.5
--- gotwebd/gotwebd.conf.5
+++ gotwebd/gotwebd.conf.5
@@ -156,6 +156,10 @@ Set the displayed site name title.
 Set the displayed site owner.
 .It Ic show_site_owner Ar on | off
 Toggle display of the site owner.
+.It Ic summary_commits_display Ar number
+The maximum number of commits to show in the summary page.
+.It Ic summary_tags_display Ar number
+The maximum number of tags to show in the summary page.
 .El
 .Sh FILES
 .Bl -tag -width Ds -compact
@@ -198,6 +202,9 @@ server "localhost-unix" {
 	#max_repos   0
 	#max_repos_display  25
 	#max_commits_display  25
+
+	#summary_commits_display 10
+	#summary_tags_display 3
 }
 
 # Example server context for FCGI over TCP connections:
blob - 23dfd5628aac5e91500730e48a91ab1fb553f397
file + gotwebd/gotwebd.h
--- gotwebd/gotwebd.h
+++ gotwebd/gotwebd.h
@@ -301,6 +301,8 @@ struct server {
 	size_t		 max_repos;
 	size_t		 max_repos_display;
 	size_t		 max_commits_display;
+	size_t		 summary_commits_display;
+	size_t		 summary_tags_display;
 
 	int		 show_site_owner;
 	int		 show_repo_owner;
blob - 207d9f20026688bdc8849f0125e73b94a285504e
file + gotwebd/parse.y
--- gotwebd/parse.y
+++ gotwebd/parse.y
@@ -113,6 +113,7 @@ typedef struct {
 %token	MAX_REPOS_DISPLAY REPOS_PATH MAX_COMMITS_DISPLAY ON ERROR
 %token	SHOW_SITE_OWNER SHOW_REPO_CLONEURL PORT PREFORK RESPECT_EXPORTOK
 %token	UNIX_SOCKET UNIX_SOCKET_NAME SERVER CHROOT CUSTOM_CSS SOCKET
+%token	SUMMARY_COMMITS_DISPLAY SUMMARY_TAGS_DISPLAY
 
 %token	<v.string>	STRING
 %token	<v.number>	NUMBER
@@ -408,6 +409,22 @@ serveropts1	: REPOS_PATH STRING {
 			}
 			new_srv->max_commits_display = $2;
 		}
+		| SUMMARY_COMMITS_DISPLAY NUMBER {
+			if ($2 < 1) {
+				yyerror("summary_commits_display is too small:"
+				    " %lld", $2);
+				YYERROR;
+			}
+			new_srv->summary_commits_display = $2;
+		}
+		| SUMMARY_TAGS_DISPLAY NUMBER {
+			if ($2 < 1) {
+				yyerror("summary_tags_display is too small:"
+				    " %lld", $2);
+				YYERROR;
+			}
+			new_srv->summary_tags_display = $2;
+		}
 		;
 
 serveropts2	: serveropts2 serveropts1 nl
@@ -478,6 +495,8 @@ lookup(char *s)
 		{ "site_name",			SITE_NAME },
 		{ "site_owner",			SITE_OWNER },
 		{ "socket",			SOCKET },
+		{ "summary_commits_display",	SUMMARY_COMMITS_DISPLAY },
+		{ "summary_tags_display",	SUMMARY_TAGS_DISPLAY },
 		{ "unix_socket",		UNIX_SOCKET },
 		{ "unix_socket_name",		UNIX_SOCKET_NAME },
 	};
@@ -909,6 +928,8 @@ conf_new_server(const char *name)
 
 	srv->max_repos_display = D_MAXREPODISP;
 	srv->max_commits_display = D_MAXCOMMITDISP;
+	srv->summary_commits_display = D_MAXSLCOMMDISP;
+	srv->summary_tags_display = D_MAXSLTAGDISP;
 	srv->max_repos = D_MAXREPO;
 
 	srv->unix_socket = 1;