summaryrefslogtreecommitdiffabout
path: root/ui-shared.c
Unidiff
Diffstat (limited to 'ui-shared.c') (more/less context) (ignore whitespace changes)
-rw-r--r--ui-shared.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/ui-shared.c b/ui-shared.c
index 5c5bcf3..e4bb98f 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -102,256 +102,262 @@ const char *cgit_repobasename(const char *reponame)
102 /* find last slash in the remaining string */ 102 /* find last slash in the remaining string */
103 rv = strrchr(rvbuf,'/'); 103 rv = strrchr(rvbuf,'/');
104 if(rv) 104 if(rv)
105 return ++rv; 105 return ++rv;
106 return rvbuf; 106 return rvbuf;
107} 107}
108 108
109char *cgit_currurl() 109char *cgit_currurl()
110{ 110{
111 if (!cgit_virtual_root) 111 if (!cgit_virtual_root)
112 return cgit_script_name; 112 return cgit_script_name;
113 else if (cgit_query_page) 113 else if (cgit_query_page)
114 return fmt("%s/%s/%s/", cgit_virtual_root, cgit_query_repo, cgit_query_page); 114 return fmt("%s/%s/%s/", cgit_virtual_root, cgit_query_repo, cgit_query_page);
115 else if (cgit_query_repo) 115 else if (cgit_query_repo)
116 return fmt("%s/%s/", cgit_virtual_root, cgit_query_repo); 116 return fmt("%s/%s/", cgit_virtual_root, cgit_query_repo);
117 else 117 else
118 return fmt("%s/", cgit_virtual_root); 118 return fmt("%s/", cgit_virtual_root);
119} 119}
120 120
121static char *repolink(char *title, char *class, char *page, char *head, 121static char *repolink(char *title, char *class, char *page, char *head,
122 char *path) 122 char *path)
123{ 123{
124 char *delim = "?"; 124 char *delim = "?";
125 125
126 html("<a"); 126 html("<a");
127 if (title) { 127 if (title) {
128 html(" title='"); 128 html(" title='");
129 html_attr(title); 129 html_attr(title);
130 html("'"); 130 html("'");
131 } 131 }
132 if (class) { 132 if (class) {
133 html(" class='"); 133 html(" class='");
134 html_attr(class); 134 html_attr(class);
135 html("'"); 135 html("'");
136 } 136 }
137 html(" href='"); 137 html(" href='");
138 if (cgit_virtual_root) { 138 if (cgit_virtual_root) {
139 html_attr(cgit_virtual_root); 139 html_attr(cgit_virtual_root);
140 if (cgit_virtual_root[strlen(cgit_virtual_root) - 1] != '/') 140 if (cgit_virtual_root[strlen(cgit_virtual_root) - 1] != '/')
141 html("/"); 141 html("/");
142 html_attr(cgit_repo->url); 142 html_attr(cgit_repo->url);
143 if (cgit_repo->url[strlen(cgit_repo->url) - 1] != '/') 143 if (cgit_repo->url[strlen(cgit_repo->url) - 1] != '/')
144 html("/"); 144 html("/");
145 if (page) { 145 if (page) {
146 html(page); 146 html(page);
147 html("/"); 147 html("/");
148 if (path) 148 if (path)
149 html_attr(path); 149 html_attr(path);
150 } 150 }
151 } else { 151 } else {
152 html(cgit_script_name); 152 html(cgit_script_name);
153 html("?url="); 153 html("?url=");
154 html_attr(cgit_repo->url); 154 html_attr(cgit_repo->url);
155 if (cgit_repo->url[strlen(cgit_repo->url) - 1] != '/') 155 if (cgit_repo->url[strlen(cgit_repo->url) - 1] != '/')
156 html("/"); 156 html("/");
157 if (page) { 157 if (page) {
158 html(page); 158 html(page);
159 html("/"); 159 html("/");
160 if (path) 160 if (path)
161 html_attr(path); 161 html_attr(path);
162 } 162 }
163 delim = "&amp;"; 163 delim = "&amp;";
164 } 164 }
165 if (head && strcmp(head, cgit_repo->defbranch)) { 165 if (head && strcmp(head, cgit_repo->defbranch)) {
166 html(delim); 166 html(delim);
167 html("h="); 167 html("h=");
168 html_attr(head); 168 html_attr(head);
169 delim = "&amp;"; 169 delim = "&amp;";
170 } 170 }
171 return fmt("%s", delim); 171 return fmt("%s", delim);
172} 172}
173 173
174static void reporevlink(char *page, char *name, char *title, char *class, 174static void reporevlink(char *page, char *name, char *title, char *class,
175 char *head, char *rev, char *path) 175 char *head, char *rev, char *path)
176{ 176{
177 char *delim; 177 char *delim;
178 178
179 delim = repolink(title, class, page, head, path); 179 delim = repolink(title, class, page, head, path);
180 if (rev && strcmp(rev, cgit_query_head)) { 180 if (rev && strcmp(rev, cgit_query_head)) {
181 html(delim); 181 html(delim);
182 html("id="); 182 html("id=");
183 html_attr(rev); 183 html_attr(rev);
184 } 184 }
185 html("'>"); 185 html("'>");
186 html_txt(name); 186 html_txt(name);
187 html("</a>"); 187 html("</a>");
188} 188}
189 189
190void cgit_tree_link(char *name, char *title, char *class, char *head, 190void cgit_tree_link(char *name, char *title, char *class, char *head,
191 char *rev, char *path) 191 char *rev, char *path)
192{ 192{
193 reporevlink("tree", name, title, class, head, rev, path); 193 reporevlink("tree", name, title, class, head, rev, path);
194} 194}
195 195
196void cgit_log_link(char *name, char *title, char *class, char *head, 196void cgit_log_link(char *name, char *title, char *class, char *head,
197 char *rev, char *path, int ofs) 197 char *rev, char *path, int ofs)
198{ 198{
199 char *delim; 199 char *delim;
200 200
201 delim = repolink(title, class, "log", head, path); 201 delim = repolink(title, class, "log", head, path);
202 if (rev && strcmp(rev, cgit_query_head)) { 202 if (rev && strcmp(rev, cgit_query_head)) {
203 html(delim); 203 html(delim);
204 html("id="); 204 html("id=");
205 html_attr(rev); 205 html_attr(rev);
206 delim = "&"; 206 delim = "&";
207 } 207 }
208 if (ofs > 0) { 208 if (ofs > 0) {
209 html(delim); 209 html(delim);
210 html("ofs="); 210 html("ofs=");
211 htmlf("%d", ofs); 211 htmlf("%d", ofs);
212 } 212 }
213 html("'>"); 213 html("'>");
214 html_txt(name); 214 html_txt(name);
215 html("</a>"); 215 html("</a>");
216} 216}
217 217
218void cgit_commit_link(char *name, char *title, char *class, char *head, 218void cgit_commit_link(char *name, char *title, char *class, char *head,
219 char *rev) 219 char *rev)
220{ 220{
221 if (strlen(name) > cgit_max_msg_len && cgit_max_msg_len >= 15) { 221 if (strlen(name) > cgit_max_msg_len && cgit_max_msg_len >= 15) {
222 name[cgit_max_msg_len] = '\0'; 222 name[cgit_max_msg_len] = '\0';
223 name[cgit_max_msg_len - 1] = '.'; 223 name[cgit_max_msg_len - 1] = '.';
224 name[cgit_max_msg_len - 2] = '.'; 224 name[cgit_max_msg_len - 2] = '.';
225 name[cgit_max_msg_len - 3] = '.'; 225 name[cgit_max_msg_len - 3] = '.';
226 } 226 }
227 reporevlink("commit", name, title, class, head, rev, NULL); 227 reporevlink("commit", name, title, class, head, rev, NULL);
228} 228}
229 229
230void cgit_refs_link(char *name, char *title, char *class, char *head,
231 char *rev, char *path)
232{
233 reporevlink("refs", name, title, class, head, rev, path);
234}
235
230void cgit_snapshot_link(char *name, char *title, char *class, char *head, 236void cgit_snapshot_link(char *name, char *title, char *class, char *head,
231 char *rev, char *archivename) 237 char *rev, char *archivename)
232{ 238{
233 reporevlink("snapshot", name, title, class, head, rev, archivename); 239 reporevlink("snapshot", name, title, class, head, rev, archivename);
234} 240}
235 241
236void cgit_diff_link(char *name, char *title, char *class, char *head, 242void cgit_diff_link(char *name, char *title, char *class, char *head,
237 char *new_rev, char *old_rev, char *path) 243 char *new_rev, char *old_rev, char *path)
238{ 244{
239 char *delim; 245 char *delim;
240 246
241 delim = repolink(title, class, "diff", head, path); 247 delim = repolink(title, class, "diff", head, path);
242 if (new_rev && strcmp(new_rev, cgit_query_head)) { 248 if (new_rev && strcmp(new_rev, cgit_query_head)) {
243 html(delim); 249 html(delim);
244 html("id="); 250 html("id=");
245 html_attr(new_rev); 251 html_attr(new_rev);
246 delim = "&amp;"; 252 delim = "&amp;";
247 } 253 }
248 if (old_rev) { 254 if (old_rev) {
249 html(delim); 255 html(delim);
250 html("id2="); 256 html("id2=");
251 html_attr(old_rev); 257 html_attr(old_rev);
252 } 258 }
253 html("'>"); 259 html("'>");
254 html_txt(name); 260 html_txt(name);
255 html("</a>"); 261 html("</a>");
256} 262}
257 263
258void cgit_object_link(struct object *obj) 264void cgit_object_link(struct object *obj)
259{ 265{
260 char *page, *arg, *url; 266 char *page, *arg, *url;
261 267
262 if (obj->type == OBJ_COMMIT) { 268 if (obj->type == OBJ_COMMIT) {
263 cgit_commit_link(fmt("commit %s", sha1_to_hex(obj->sha1)), NULL, NULL, 269 cgit_commit_link(fmt("commit %s", sha1_to_hex(obj->sha1)), NULL, NULL,
264 cgit_query_head, sha1_to_hex(obj->sha1)); 270 cgit_query_head, sha1_to_hex(obj->sha1));
265 return; 271 return;
266 } else if (obj->type == OBJ_TREE) { 272 } else if (obj->type == OBJ_TREE) {
267 page = "tree"; 273 page = "tree";
268 arg = "id"; 274 arg = "id";
269 } else { 275 } else {
270 page = "blob"; 276 page = "blob";
271 arg = "id"; 277 arg = "id";
272 } 278 }
273 279
274 url = cgit_pageurl(cgit_query_repo, page, 280 url = cgit_pageurl(cgit_query_repo, page,
275 fmt("%s=%s", arg, sha1_to_hex(obj->sha1))); 281 fmt("%s=%s", arg, sha1_to_hex(obj->sha1)));
276 html_link_open(url, NULL, NULL); 282 html_link_open(url, NULL, NULL);
277 htmlf("%s %s", typename(obj->type), 283 htmlf("%s %s", typename(obj->type),
278 sha1_to_hex(obj->sha1)); 284 sha1_to_hex(obj->sha1));
279 html_link_close(); 285 html_link_close();
280} 286}
281 287
282void cgit_print_date(time_t secs, char *format) 288void cgit_print_date(time_t secs, char *format)
283{ 289{
284 char buf[64]; 290 char buf[64];
285 struct tm *time; 291 struct tm *time;
286 292
287 time = gmtime(&secs); 293 time = gmtime(&secs);
288 strftime(buf, sizeof(buf)-1, format, time); 294 strftime(buf, sizeof(buf)-1, format, time);
289 html_txt(buf); 295 html_txt(buf);
290} 296}
291 297
292void cgit_print_age(time_t t, time_t max_relative, char *format) 298void cgit_print_age(time_t t, time_t max_relative, char *format)
293{ 299{
294 time_t now, secs; 300 time_t now, secs;
295 301
296 time(&now); 302 time(&now);
297 secs = now - t; 303 secs = now - t;
298 304
299 if (secs > max_relative && max_relative >= 0) { 305 if (secs > max_relative && max_relative >= 0) {
300 cgit_print_date(t, format); 306 cgit_print_date(t, format);
301 return; 307 return;
302 } 308 }
303 309
304 if (secs < TM_HOUR * 2) { 310 if (secs < TM_HOUR * 2) {
305 htmlf("<span class='age-mins'>%.0f min.</span>", 311 htmlf("<span class='age-mins'>%.0f min.</span>",
306 secs * 1.0 / TM_MIN); 312 secs * 1.0 / TM_MIN);
307 return; 313 return;
308 } 314 }
309 if (secs < TM_DAY * 2) { 315 if (secs < TM_DAY * 2) {
310 htmlf("<span class='age-hours'>%.0f hours</span>", 316 htmlf("<span class='age-hours'>%.0f hours</span>",
311 secs * 1.0 / TM_HOUR); 317 secs * 1.0 / TM_HOUR);
312 return; 318 return;
313 } 319 }
314 if (secs < TM_WEEK * 2) { 320 if (secs < TM_WEEK * 2) {
315 htmlf("<span class='age-days'>%.0f days</span>", 321 htmlf("<span class='age-days'>%.0f days</span>",
316 secs * 1.0 / TM_DAY); 322 secs * 1.0 / TM_DAY);
317 return; 323 return;
318 } 324 }
319 if (secs < TM_MONTH * 2) { 325 if (secs < TM_MONTH * 2) {
320 htmlf("<span class='age-weeks'>%.0f weeks</span>", 326 htmlf("<span class='age-weeks'>%.0f weeks</span>",
321 secs * 1.0 / TM_WEEK); 327 secs * 1.0 / TM_WEEK);
322 return; 328 return;
323 } 329 }
324 if (secs < TM_YEAR * 2) { 330 if (secs < TM_YEAR * 2) {
325 htmlf("<span class='age-months'>%.0f months</span>", 331 htmlf("<span class='age-months'>%.0f months</span>",
326 secs * 1.0 / TM_MONTH); 332 secs * 1.0 / TM_MONTH);
327 return; 333 return;
328 } 334 }
329 htmlf("<span class='age-years'>%.0f years</span>", 335 htmlf("<span class='age-years'>%.0f years</span>",
330 secs * 1.0 / TM_YEAR); 336 secs * 1.0 / TM_YEAR);
331} 337}
332 338
333void cgit_print_docstart(char *title, struct cacheitem *item) 339void cgit_print_docstart(char *title, struct cacheitem *item)
334{ 340{
335 html("Content-Type: text/html; charset=utf-8\n"); 341 html("Content-Type: text/html; charset=utf-8\n");
336 htmlf("Last-Modified: %s\n", http_date(item->st.st_mtime)); 342 htmlf("Last-Modified: %s\n", http_date(item->st.st_mtime));
337 htmlf("Expires: %s\n", http_date(item->st.st_mtime + 343 htmlf("Expires: %s\n", http_date(item->st.st_mtime +
338 ttl_seconds(item->ttl))); 344 ttl_seconds(item->ttl)));
339 html("\n"); 345 html("\n");
340 html(cgit_doctype); 346 html(cgit_doctype);
341 html("<html>\n"); 347 html("<html>\n");
342 html("<head>\n"); 348 html("<head>\n");
343 html("<title>"); 349 html("<title>");
344 html_txt(title); 350 html_txt(title);
345 html("</title>\n"); 351 html("</title>\n");
346 htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version); 352 htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version);
347 html("<link rel='stylesheet' type='text/css' href='"); 353 html("<link rel='stylesheet' type='text/css' href='");
348 html_attr(cgit_css); 354 html_attr(cgit_css);
349 html("'/>\n"); 355 html("'/>\n");
350 html("</head>\n"); 356 html("</head>\n");
351 html("<body>\n"); 357 html("<body>\n");
352} 358}
353 359
354void cgit_print_docend() 360void cgit_print_docend()
355{ 361{
356 html("</td></tr></table>"); 362 html("</td></tr></table>");
357 html("</body>\n</html>\n"); 363 html("</body>\n</html>\n");