Fossil SCM

Fix the repolist-skin setting so that it sets up URL on the header menu correctly. Back out the stylesheet hack is that is now covered by the same fix.

drh 2019-07-29 18:14 repolist-skin
Commit 6df7a853ec16865b33835bf346f3ef804a29b514bce209b5bdf25df2bfb45b1c
3 files changed +1 -1 +29 -23 +6 -12
+1 -1
--- src/main.c
+++ src/main.c
@@ -1194,11 +1194,11 @@
11941194
** The g.zBaseURL is normally set based on HTTP_HOST and SCRIPT_NAME
11951195
** environment variables. However, if zAltBase is not NULL then it
11961196
** is the argument to the --baseurl option command-line option and
11971197
** g.zBaseURL and g.zTop is set from that instead.
11981198
*/
1199
-static void set_base_url(const char *zAltBase){
1199
+void set_base_url(const char *zAltBase){
12001200
int i;
12011201
const char *zHost;
12021202
const char *zMode;
12031203
const char *zCur;
12041204
12051205
--- src/main.c
+++ src/main.c
@@ -1194,11 +1194,11 @@
1194 ** The g.zBaseURL is normally set based on HTTP_HOST and SCRIPT_NAME
1195 ** environment variables. However, if zAltBase is not NULL then it
1196 ** is the argument to the --baseurl option command-line option and
1197 ** g.zBaseURL and g.zTop is set from that instead.
1198 */
1199 static void set_base_url(const char *zAltBase){
1200 int i;
1201 const char *zHost;
1202 const char *zMode;
1203 const char *zCur;
1204
1205
--- src/main.c
+++ src/main.c
@@ -1194,11 +1194,11 @@
1194 ** The g.zBaseURL is normally set based on HTTP_HOST and SCRIPT_NAME
1195 ** environment variables. However, if zAltBase is not NULL then it
1196 ** is the argument to the --baseurl option command-line option and
1197 ** g.zBaseURL and g.zTop is set from that instead.
1198 */
1199 void set_base_url(const char *zAltBase){
1200 int i;
1201 const char *zHost;
1202 const char *zMode;
1203 const char *zCur;
1204
1205
+29 -23
--- src/repolist.c
+++ src/repolist.c
@@ -37,17 +37,12 @@
3737
};
3838
#endif
3939
4040
/*
4141
** Discover information about the repository given by
42
-** pRepo->zRepoName. The discovered information is stored in
43
-**
44
-**
45
-**
46
-**
47
-** This is an expensive routine in that it has to open and close an
48
-** SQLite database file.
42
+** pRepo->zRepoName. The discovered information is stored in other
43
+** fields of the RepoInfo object.
4944
*/
5045
static void remote_repo_info(RepoInfo *pRepo){
5146
sqlite3 *db;
5247
sqlite3_stmt *pStmt;
5348
int rc;
@@ -84,13 +79,10 @@
8479
pRepo->isValid = 1;
8580
sqlite3_finalize(pStmt);
8681
finish_repo_list:
8782
g.dbIgnoreErrors--;
8883
sqlite3_close(db);
89
- if( pRepo->isRepolistSkin && !g.repositoryOpen ){
90
- db_open_repository(pRepo->zRepoName);
91
- }
9284
}
9385
9486
/*
9587
** Generate a web-page that lists all repositories located under the
9688
** g.zRepositoryName directory and return non-zero.
@@ -107,15 +99,17 @@
10799
**
108100
** Or, if no repositories can be located beneath g.zRepositoryName,
109101
** return 0.
110102
*/
111103
int repo_list_page(void){
112
- Blob base; /* document root for all repositories */
113
- int n = 0; /* Number of repositories found */
114
- int allRepo; /* True if running "fossil ui all".
115
- ** False if a directory scan of base for repos */
116
- Blob html; /* Html for the body of the repository list */
104
+ Blob base; /* document root for all repositories */
105
+ int n = 0; /* Number of repositories found */
106
+ int allRepo; /* True if running "fossil ui all".
107
+ ** False if a directory scan of base for repos */
108
+ Blob html; /* Html for the body of the repository list */
109
+ char *zSkinRepo = 0; /* Name of the repository database used for skins */
110
+ char *zSkinUrl = 0; /* URL for the skin database */
117111
118112
assert( g.db==0 );
119113
blob_init(&html, 0, 0);
120114
if( fossil_strcmp(g.zRepositoryName,"/")==0 && !g.fJail ){
121115
/* For the special case of the "repository directory" being "/",
@@ -144,11 +138,14 @@
144138
vfile_scan(&base, blob_size(&base), 0, 0, 0);
145139
db_multi_exec("DELETE FROM sfile WHERE pathname NOT GLOB '*[^/].fossil'");
146140
allRepo = 0;
147141
}
148142
n = db_int(0, "SELECT count(*) FROM sfile");
149
- if( n>0 ){
143
+ if( n==0 ){
144
+ sqlite3_close(g.db);
145
+ return 0;
146
+ }else{
150147
Stmt q;
151148
double rNow;
152149
blob_append_sql(&html,
153150
"<table border='0' class='sortable' data-init-sort='1'"
154151
" data-column-types='txtxk'><thead>\n"
@@ -180,10 +177,16 @@
180177
}else{
181178
zFull = mprintf("%s/%s", g.zRepositoryName, zName);
182179
}
183180
x.zRepoName = zFull;
184181
remote_repo_info(&x);
182
+ if( x.isRepolistSkin ){
183
+ if( zSkinRepo==0 ){
184
+ zSkinRepo = mprintf("%s", x.zRepoName);
185
+ zSkinUrl = mprintf("%s", zUrl);
186
+ }
187
+ }
185188
fossil_free(zFull);
186189
if( !x.isValid ){
187190
continue;
188191
}
189192
if( x.isRepolistSkin==2 && !allRepo ){
@@ -203,15 +206,15 @@
203206
} else if( sqlite3_strglob("*/.*", zName)==0 ){
204207
/* Do not show hyperlinks for hidden repos */
205208
blob_append_sql(&html, "%h (hidden)", zName);
206209
} else if( allRepo && sqlite3_strglob("[a-zA-Z]:/?*", zName)!=0 ){
207210
blob_append_sql(&html,
208
- "<a href='%R/%T/home' target='_blank'>/%h</a>\n",
211
+ "<a href='/%T/home' target='_blank'>/%h</a>\n",
209212
zUrl, zName);
210213
}else{
211214
blob_append_sql(&html,
212
- "<a href='%R/%T/home' target='_blank'>%h</a>\n",
215
+ "<a href='/%T/home' target='_blank'>%h</a>\n",
213216
zUrl, zName);
214217
}
215218
if( x.zProjName ){
216219
blob_append_sql(&html, "<td></td><td>%h</td>\n", x.zProjName);
217220
fossil_free(x.zProjName);
@@ -224,23 +227,26 @@
224227
fossil_free(zAge);
225228
sqlite3_free(zUrl);
226229
}
227230
db_finalize(&q);
228231
blob_append_sql(&html,"</tbody></table>\n");
229
- }else{
230
- blob_append_sql(&html,"<h1>No Repositories Found</h1>\n");
232
+ }
233
+ if( zSkinRepo ){
234
+ char *zNewBase = mprintf("%s/%s", g.zBaseURL, zSkinUrl);
235
+ g.zBaseURL = 0;
236
+ set_base_url(zNewBase);
237
+ db_open_repository(zSkinRepo);
238
+ fossil_free(zSkinRepo);
239
+ fossil_free(zSkinUrl);
231240
}
232241
if( g.repositoryOpen ){
233242
/* This case runs if remote_repository_info() found a repository
234243
** that has the "repolist_skin" property set to non-zero and left
235244
** that repository open in g.db. Use the skin of that repository
236245
** for display. */
237246
login_check_credentials();
238247
style_header("Repository List");
239
- @ <style>
240
- style_render_stylesheet();
241
- @ </style>
242248
@ %s(blob_str(&html))
243249
style_table_sorter();
244250
style_footer();
245251
}else{
246252
/* If no repositories were found that had the "repolist_skin"
247253
--- src/repolist.c
+++ src/repolist.c
@@ -37,17 +37,12 @@
37 };
38 #endif
39
40 /*
41 ** Discover information about the repository given by
42 ** pRepo->zRepoName. The discovered information is stored in
43 **
44 **
45 **
46 **
47 ** This is an expensive routine in that it has to open and close an
48 ** SQLite database file.
49 */
50 static void remote_repo_info(RepoInfo *pRepo){
51 sqlite3 *db;
52 sqlite3_stmt *pStmt;
53 int rc;
@@ -84,13 +79,10 @@
84 pRepo->isValid = 1;
85 sqlite3_finalize(pStmt);
86 finish_repo_list:
87 g.dbIgnoreErrors--;
88 sqlite3_close(db);
89 if( pRepo->isRepolistSkin && !g.repositoryOpen ){
90 db_open_repository(pRepo->zRepoName);
91 }
92 }
93
94 /*
95 ** Generate a web-page that lists all repositories located under the
96 ** g.zRepositoryName directory and return non-zero.
@@ -107,15 +99,17 @@
107 **
108 ** Or, if no repositories can be located beneath g.zRepositoryName,
109 ** return 0.
110 */
111 int repo_list_page(void){
112 Blob base; /* document root for all repositories */
113 int n = 0; /* Number of repositories found */
114 int allRepo; /* True if running "fossil ui all".
115 ** False if a directory scan of base for repos */
116 Blob html; /* Html for the body of the repository list */
 
 
117
118 assert( g.db==0 );
119 blob_init(&html, 0, 0);
120 if( fossil_strcmp(g.zRepositoryName,"/")==0 && !g.fJail ){
121 /* For the special case of the "repository directory" being "/",
@@ -144,11 +138,14 @@
144 vfile_scan(&base, blob_size(&base), 0, 0, 0);
145 db_multi_exec("DELETE FROM sfile WHERE pathname NOT GLOB '*[^/].fossil'");
146 allRepo = 0;
147 }
148 n = db_int(0, "SELECT count(*) FROM sfile");
149 if( n>0 ){
 
 
 
150 Stmt q;
151 double rNow;
152 blob_append_sql(&html,
153 "<table border='0' class='sortable' data-init-sort='1'"
154 " data-column-types='txtxk'><thead>\n"
@@ -180,10 +177,16 @@
180 }else{
181 zFull = mprintf("%s/%s", g.zRepositoryName, zName);
182 }
183 x.zRepoName = zFull;
184 remote_repo_info(&x);
 
 
 
 
 
 
185 fossil_free(zFull);
186 if( !x.isValid ){
187 continue;
188 }
189 if( x.isRepolistSkin==2 && !allRepo ){
@@ -203,15 +206,15 @@
203 } else if( sqlite3_strglob("*/.*", zName)==0 ){
204 /* Do not show hyperlinks for hidden repos */
205 blob_append_sql(&html, "%h (hidden)", zName);
206 } else if( allRepo && sqlite3_strglob("[a-zA-Z]:/?*", zName)!=0 ){
207 blob_append_sql(&html,
208 "<a href='%R/%T/home' target='_blank'>/%h</a>\n",
209 zUrl, zName);
210 }else{
211 blob_append_sql(&html,
212 "<a href='%R/%T/home' target='_blank'>%h</a>\n",
213 zUrl, zName);
214 }
215 if( x.zProjName ){
216 blob_append_sql(&html, "<td></td><td>%h</td>\n", x.zProjName);
217 fossil_free(x.zProjName);
@@ -224,23 +227,26 @@
224 fossil_free(zAge);
225 sqlite3_free(zUrl);
226 }
227 db_finalize(&q);
228 blob_append_sql(&html,"</tbody></table>\n");
229 }else{
230 blob_append_sql(&html,"<h1>No Repositories Found</h1>\n");
 
 
 
 
 
 
231 }
232 if( g.repositoryOpen ){
233 /* This case runs if remote_repository_info() found a repository
234 ** that has the "repolist_skin" property set to non-zero and left
235 ** that repository open in g.db. Use the skin of that repository
236 ** for display. */
237 login_check_credentials();
238 style_header("Repository List");
239 @ <style>
240 style_render_stylesheet();
241 @ </style>
242 @ %s(blob_str(&html))
243 style_table_sorter();
244 style_footer();
245 }else{
246 /* If no repositories were found that had the "repolist_skin"
247
--- src/repolist.c
+++ src/repolist.c
@@ -37,17 +37,12 @@
37 };
38 #endif
39
40 /*
41 ** Discover information about the repository given by
42 ** pRepo->zRepoName. The discovered information is stored in other
43 ** fields of the RepoInfo object.
 
 
 
 
 
44 */
45 static void remote_repo_info(RepoInfo *pRepo){
46 sqlite3 *db;
47 sqlite3_stmt *pStmt;
48 int rc;
@@ -84,13 +79,10 @@
79 pRepo->isValid = 1;
80 sqlite3_finalize(pStmt);
81 finish_repo_list:
82 g.dbIgnoreErrors--;
83 sqlite3_close(db);
 
 
 
84 }
85
86 /*
87 ** Generate a web-page that lists all repositories located under the
88 ** g.zRepositoryName directory and return non-zero.
@@ -107,15 +99,17 @@
99 **
100 ** Or, if no repositories can be located beneath g.zRepositoryName,
101 ** return 0.
102 */
103 int repo_list_page(void){
104 Blob base; /* document root for all repositories */
105 int n = 0; /* Number of repositories found */
106 int allRepo; /* True if running "fossil ui all".
107 ** False if a directory scan of base for repos */
108 Blob html; /* Html for the body of the repository list */
109 char *zSkinRepo = 0; /* Name of the repository database used for skins */
110 char *zSkinUrl = 0; /* URL for the skin database */
111
112 assert( g.db==0 );
113 blob_init(&html, 0, 0);
114 if( fossil_strcmp(g.zRepositoryName,"/")==0 && !g.fJail ){
115 /* For the special case of the "repository directory" being "/",
@@ -144,11 +138,14 @@
138 vfile_scan(&base, blob_size(&base), 0, 0, 0);
139 db_multi_exec("DELETE FROM sfile WHERE pathname NOT GLOB '*[^/].fossil'");
140 allRepo = 0;
141 }
142 n = db_int(0, "SELECT count(*) FROM sfile");
143 if( n==0 ){
144 sqlite3_close(g.db);
145 return 0;
146 }else{
147 Stmt q;
148 double rNow;
149 blob_append_sql(&html,
150 "<table border='0' class='sortable' data-init-sort='1'"
151 " data-column-types='txtxk'><thead>\n"
@@ -180,10 +177,16 @@
177 }else{
178 zFull = mprintf("%s/%s", g.zRepositoryName, zName);
179 }
180 x.zRepoName = zFull;
181 remote_repo_info(&x);
182 if( x.isRepolistSkin ){
183 if( zSkinRepo==0 ){
184 zSkinRepo = mprintf("%s", x.zRepoName);
185 zSkinUrl = mprintf("%s", zUrl);
186 }
187 }
188 fossil_free(zFull);
189 if( !x.isValid ){
190 continue;
191 }
192 if( x.isRepolistSkin==2 && !allRepo ){
@@ -203,15 +206,15 @@
206 } else if( sqlite3_strglob("*/.*", zName)==0 ){
207 /* Do not show hyperlinks for hidden repos */
208 blob_append_sql(&html, "%h (hidden)", zName);
209 } else if( allRepo && sqlite3_strglob("[a-zA-Z]:/?*", zName)!=0 ){
210 blob_append_sql(&html,
211 "<a href='/%T/home' target='_blank'>/%h</a>\n",
212 zUrl, zName);
213 }else{
214 blob_append_sql(&html,
215 "<a href='/%T/home' target='_blank'>%h</a>\n",
216 zUrl, zName);
217 }
218 if( x.zProjName ){
219 blob_append_sql(&html, "<td></td><td>%h</td>\n", x.zProjName);
220 fossil_free(x.zProjName);
@@ -224,23 +227,26 @@
227 fossil_free(zAge);
228 sqlite3_free(zUrl);
229 }
230 db_finalize(&q);
231 blob_append_sql(&html,"</tbody></table>\n");
232 }
233 if( zSkinRepo ){
234 char *zNewBase = mprintf("%s/%s", g.zBaseURL, zSkinUrl);
235 g.zBaseURL = 0;
236 set_base_url(zNewBase);
237 db_open_repository(zSkinRepo);
238 fossil_free(zSkinRepo);
239 fossil_free(zSkinUrl);
240 }
241 if( g.repositoryOpen ){
242 /* This case runs if remote_repository_info() found a repository
243 ** that has the "repolist_skin" property set to non-zero and left
244 ** that repository open in g.db. Use the skin of that repository
245 ** for display. */
246 login_check_credentials();
247 style_header("Repository List");
 
 
 
248 @ %s(blob_str(&html))
249 style_table_sorter();
250 style_footer();
251 }else{
252 /* If no repositories were found that had the "repolist_skin"
253
+6 -12
--- src/style.c
+++ src/style.c
@@ -983,17 +983,20 @@
983983
Th_Render(zScript?zScript:"");
984984
}
985985
986986
987987
/*
988
-** Render the text of the stylesheet.
988
+** WEBPAGE: style.css
989
+**
990
+** Return the style sheet.
989991
*/
990
-void style_render_stylesheet(void){
992
+void page_style_css(void){
991993
Blob css;
992994
int i;
993995
int isInit = 0;
994996
997
+ cgi_set_content_type("text/css");
995998
blob_init(&css,skin_get("css"),-1);
996999
9971000
/* add special missing definitions */
9981001
for(i=1; cssDefaultList[i].elementClass; i++){
9991002
char *z = blob_str(&css);
@@ -1022,20 +1025,11 @@
10221025
Th_Store("secureurl", fossil_wants_https(1)? g.zHttpsURL: g.zBaseURL);
10231026
Th_Store("home", g.zTop);
10241027
image_url_var("logo");
10251028
image_url_var("background");
10261029
Th_Render(blob_str(&css));
1027
-}
1028
-
1029
-/*
1030
-** WEBPAGE: style.css
1031
-**
1032
-** Return the style sheet.
1033
-*/
1034
-void page_style_css(void){
1035
- cgi_set_content_type("text/css");
1036
- style_render_stylesheet();
1030
+
10371031
/* Tell CGI that the content returned by this page is considered cacheable */
10381032
g.isConst = 1;
10391033
}
10401034
10411035
/*
10421036
--- src/style.c
+++ src/style.c
@@ -983,17 +983,20 @@
983 Th_Render(zScript?zScript:"");
984 }
985
986
987 /*
988 ** Render the text of the stylesheet.
 
 
989 */
990 void style_render_stylesheet(void){
991 Blob css;
992 int i;
993 int isInit = 0;
994
 
995 blob_init(&css,skin_get("css"),-1);
996
997 /* add special missing definitions */
998 for(i=1; cssDefaultList[i].elementClass; i++){
999 char *z = blob_str(&css);
@@ -1022,20 +1025,11 @@
1022 Th_Store("secureurl", fossil_wants_https(1)? g.zHttpsURL: g.zBaseURL);
1023 Th_Store("home", g.zTop);
1024 image_url_var("logo");
1025 image_url_var("background");
1026 Th_Render(blob_str(&css));
1027 }
1028
1029 /*
1030 ** WEBPAGE: style.css
1031 **
1032 ** Return the style sheet.
1033 */
1034 void page_style_css(void){
1035 cgi_set_content_type("text/css");
1036 style_render_stylesheet();
1037 /* Tell CGI that the content returned by this page is considered cacheable */
1038 g.isConst = 1;
1039 }
1040
1041 /*
1042
--- src/style.c
+++ src/style.c
@@ -983,17 +983,20 @@
983 Th_Render(zScript?zScript:"");
984 }
985
986
987 /*
988 ** WEBPAGE: style.css
989 **
990 ** Return the style sheet.
991 */
992 void page_style_css(void){
993 Blob css;
994 int i;
995 int isInit = 0;
996
997 cgi_set_content_type("text/css");
998 blob_init(&css,skin_get("css"),-1);
999
1000 /* add special missing definitions */
1001 for(i=1; cssDefaultList[i].elementClass; i++){
1002 char *z = blob_str(&css);
@@ -1022,20 +1025,11 @@
1025 Th_Store("secureurl", fossil_wants_https(1)? g.zHttpsURL: g.zBaseURL);
1026 Th_Store("home", g.zTop);
1027 image_url_var("logo");
1028 image_url_var("background");
1029 Th_Render(blob_str(&css));
1030
 
 
 
 
 
 
 
 
 
1031 /* Tell CGI that the content returned by this page is considered cacheable */
1032 g.isConst = 1;
1033 }
1034
1035 /*
1036

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button