Commit ecd9c584ce5894f4a06d23eec5678a642c2f7020

Parents: 907134b7a29177cb45aa461c549c004b1ae875af

From: Naïm Favier <fnaim42@gmail.com>
Date: Mon Dec 9 19:38:14 2019 +0700

Make default pages configurable
Signed-off-by: Christian Hesse <mail@eworm.de>

Stats

cgit.c +10/-0
cgit.h +3/-0
cgitrc.5.txt +14/-0
cmd.c +9/-9
ui-repolist.c +1/-1
ui-shared.c +9/-3
ui-shared.h +2/-0

Changeset

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
diff --git a/cgit.c b/cgit.c
index 57d70974c50fbd0ade407d8fd46b0ee480d046b1..e7c01724d0ed58830dc8eb76581b721dfa9a764c 100644
--- a/cgit.c
+++ b/cgit.c
@@ -56,6 +56,8 @@ 	else if (!strcmp(name, "homepage"))
 		repo->homepage = xstrdup(value);
 	else if (!strcmp(name, "defbranch"))
 		repo->defbranch = xstrdup(value);
+	else if (!strcmp(name, "default-page"))
+		repo->default_page = xstrdup(value);
 	else if (!strcmp(name, "extra-head-content"))
 		repo->extra_head_content = xstrdup(value);
 	else if (!strcmp(name, "snapshots"))
@@ -141,6 +143,8 @@ 	else if (!strcmp(name, "root-desc"))
 		ctx.cfg.root_desc = xstrdup(value);
 	else if (!strcmp(name, "root-readme"))
 		ctx.cfg.root_readme = xstrdup(value);
+	else if (!strcmp(name, "root-default-page"))
+		ctx.cfg.root_default_page = xstrdup(value);
 	else if (!strcmp(name, "css"))
 		string_list_append(&ctx.cfg.css, xstrdup(value));
 	else if (!strcmp(name, "js"))
@@ -157,6 +161,8 @@ 	else if (!strcmp(name, "logo"))
 		ctx.cfg.logo = xstrdup(value);
 	else if (!strcmp(name, "logo-link"))
 		ctx.cfg.logo_link = xstrdup(value);
+	else if (!strcmp(name, "default-page"))
+		ctx.cfg.default_page = xstrdup(value);
 	else if (!strcmp(name, "module-link"))
 		ctx.cfg.module_link = xstrdup(value);
 	else if (!strcmp(name, "strict-export"))
@@ -380,6 +386,7 @@ 	ctx.cfg.cache_static_ttl = -1;
 	ctx.cfg.case_sensitive_sort = 1;
 	ctx.cfg.branch_sort = 0;
 	ctx.cfg.commit_sort = 0;
+	ctx.cfg.default_page= "summary";
 	ctx.cfg.logo = "/cgit.png";
 	ctx.cfg.favicon = "/favicon.ico";
 	ctx.cfg.local_time = 0;
@@ -400,6 +407,7 @@ 	ctx.cfg.remove_suffix = 0;
 	ctx.cfg.robots = "index, nofollow";
 	ctx.cfg.root_title = "Git repository browser";
 	ctx.cfg.root_desc = "a fast webinterface for the git dscm";
+	ctx.cfg.root_default_page = "repolist";
 	ctx.cfg.scan_hidden_path = 0;
 	ctx.cfg.script_name = CGIT_SCRIPT_NAME;
 	ctx.cfg.section = "";
@@ -811,6 +819,8 @@ 			fprintf(f, "repo.readme=%s\n", item->string);
 	}
 	if (repo->defbranch)
 		fprintf(f, "repo.defbranch=%s\n", repo->defbranch);
+	if (repo->default_page)
+		fprintf(f, "repo.default-page=%s\n", repo->default_page);
 	if (repo->extra_head_content)
 		fprintf(f, "repo.extra-head-content=%s\n", repo->extra_head_content);
 	if (repo->module_link)
diff --git a/cgit.h b/cgit.h
index ddd2ccba0b8849f9d90d8d0c430930ee96dab77c..9f9daac330c556a81a4b4b13a119ae0f9439a3d9 100644
--- a/cgit.h
+++ b/cgit.h
@@ -87,6 +87,7 @@ 	char *extra_head_content;
 	char *owner;
 	char *homepage;
 	char *defbranch;
+	char *default_page;
 	char *module_link;
 	struct string_list readme;
 	char *section;
@@ -196,6 +197,7 @@ 	char *agefile;
 	char *cache_root;
 	char *clone_prefix;
 	char *clone_url;
+	char *default_page;
 	char *favicon;
 	char *footer;
 	char *head_include;
@@ -211,6 +213,7 @@ 	char *robots;
 	char *root_title;
 	char *root_desc;
 	char *root_readme;
+	char *root_default_page;
 	char *script_name;
 	char *section;
 	char *repository_sort;
diff --git a/cgitrc.5.txt b/cgitrc.5.txt
index 6f3e9520c76b490756fe4096122ca07bc5efdca1..ac868648a5de63d75bc8a6d0d865bd4b6cd98af7 100644
--- a/cgitrc.5.txt
+++ b/cgitrc.5.txt
@@ -129,6 +129,12 @@ 	Url which specifies the css document to include in all cgit pages.
 	Default value: "/cgit.css".  May be given multiple times, each
 	css URL path is added in the head section of the document in turn.
 
+default-page::
+	Specifies the default page for repositories. This setting is only used
+	if `repo.default-page` is unspecified. Possible values: "about",
+	"summary", "refs", "log", "tree", "commit", "diff", "stats".  Default
+	value: "summary".
+
 email-filter::
 	Specifies a command which will be invoked to format names and email
 	address of committers, authors, and taggers, as represented in various
@@ -359,6 +365,10 @@ robots::
 	Text used as content for the "robots" meta-tag. Default value:
 	"index, nofollow".
 
+root-default-page::
+	Specifies the default root page. Possible values are "repolist" and
+	"about". Default value: "repolist".
+
 root-desc::
 	Text printed below the heading on the repository index page. Default
 	value: "a fast webinterface for the git dscm".
@@ -481,6 +491,10 @@ 	Flag which, when set to "date", enables strict date ordering in the
 	commit log, and when set to "topo" enables strict topological
 	ordering. If unset, the default ordering of "git log" is used. Default
 	value: unset.
+
+repo.default-page::
+	Specifies the default page for the repository. Default value: global
+	default-page.
 
 repo.defbranch::
 	The name of the default branch for this repository. If no such branch
diff --git a/cmd.c b/cmd.c
index 0eb75b1da87761ab935e14a40d301d1a30244eb9..669c345a4b94f55859f5e1494d5dc55098487043 100644
--- a/cmd.c
+++ b/cmd.c
@@ -51,13 +51,10 @@ 			free(currenturl);
 			free(redirect);
 		} else if (ctx.repo->readme.nr)
 			cgit_print_repo_readme(ctx.qry.path);
-		else if (ctx.repo->homepage)
-			cgit_redirect(ctx.repo->homepage, false);
 		else {
-			char *currenturl = cgit_currenturl();
-			char *redirect = fmtalloc("%s../", currenturl);
+			char *redirect = fmtalloc("%s%s/summary/",
+				ctx.cfg.virtual_root, ctx.repo->url);
 			cgit_redirect(redirect, false);
-			free(currenturl);
 			free(redirect);
 		}
 	} else
@@ -195,10 +192,13 @@ 	};
 	int i;
 
 	if (ctx.qry.page == NULL) {
-		if (ctx.repo)
-			ctx.qry.page = "summary";
-		else
-			ctx.qry.page = "repolist";
+		if (ctx.repo) {
+			if (ctx.repo->default_page && *ctx.repo->default_page)
+				ctx.qry.page = ctx.repo->default_page;
+			else
+				ctx.qry.page = ctx.cfg.default_page;
+		} else
+			ctx.qry.page = ctx.cfg.root_default_page;
 	}
 
 	for (i = 0; i < sizeof(cmds)/sizeof(*cmds); i++)
diff --git a/ui-repolist.c b/ui-repolist.c
index d12e3dd3593fda4179740c4540aee02260f47007..2390eae9260edbee5c76f4c0c41bedf5cbf035fe 100644
--- a/ui-repolist.c
+++ b/ui-repolist.c
@@ -321,7 +321,7 @@ 			last_section = section;
 		}
 		htmlf("<tr><td class='%s'>",
 		      !sorted && section ? "sublevel-repo" : "toplevel-repo");
-		cgit_summary_link(ctx.repo->name, NULL, NULL, NULL);
+		cgit_repo_link(ctx.repo->name, NULL, NULL, NULL);
 		html("</td><td>");
 		repourl = cgit_repourl(ctx.repo->url);
 		html_link_open(repourl, NULL, NULL);
diff --git a/ui-shared.c b/ui-shared.c
index 11aed19a80e882c6999eecb32250cd206fee5210..bf35a61520203577226b6e5b601a20ea59758fb3 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -328,10 +328,16 @@ 	html_txt(name);
 	html("</a>");
 }
 
+void cgit_repo_link(const char *name, const char *title, const char *class,
+			const char *head)
+{
+	reporevlink(NULL, name, title, class, head, NULL, NULL);
+}
+
 void cgit_summary_link(const char *name, const char *title, const char *class,
 		       const char *head)
 {
-	reporevlink(NULL, name, title, class, head, NULL, NULL);
+	reporevlink("summary", name, title, class, head, NULL, NULL);
 }
 
 void cgit_tag_link(const char *name, const char *title, const char *class,
@@ -1027,7 +1033,7 @@ 	html("<td class='main'>");
 	if (ctx.repo) {
 		cgit_index_link("index", NULL, NULL, NULL, NULL, 0, 1);
 		html(" : ");
-		cgit_summary_link(ctx.repo->name, NULL, NULL, NULL);
+		cgit_repo_link(ctx.repo->name, NULL, NULL, NULL);
 		if (ctx.env.authenticated) {
 			html("</td><td class='form'>");
 			html("<form method='get'>\n");
@@ -1122,7 +1128,7 @@ 		html("<input type='submit' value='search'/>\n");
 		html("</form>\n");
 	} else if (ctx.env.authenticated) {
 		char *currenturl = cgit_currenturl();
-		site_link(NULL, "index", NULL, hc("repolist"), NULL, NULL, 0, 1);
+		site_link("repolist", "index", NULL, hc("repolist"), NULL, NULL, 0, 1);
 		if (ctx.cfg.root_readme)
 			site_link("about", "about", NULL, hc("about"),
 				  NULL, NULL, 0, 1);
diff --git a/ui-shared.h b/ui-shared.h
index 6964873a63942e2222d3981d73d4178c52c51508..4d148581e9f2730c881d473fe065038f0d72231f 100644
--- a/ui-shared.h
+++ b/ui-shared.h
@@ -17,6 +17,8 @@ extern void cgit_add_clone_urls(void (*fn)(const char *));
 
 extern void cgit_index_link(const char *name, const char *title,
 			    const char *class, const char *pattern, const char *sort, int ofs, int always_root);
+extern void cgit_repo_link(const char *name, const char *title,
+				  const char *class, const char *head);
 extern void cgit_summary_link(const char *name, const char *title,
 			      const char *class, const char *head);
 extern void cgit_tag_link(const char *name, const char *title,