summaryrefslogtreecommitdiffabout
path: root/ui-shared.c
authorLars Hjemli <hjemli@gmail.com>2008-02-16 10:53:40 (UTC)
committer Lars Hjemli <hjemli@gmail.com>2008-02-16 11:07:28 (UTC)
commitd14d77fe95c3b6224b40df9b101dded0deea913c (patch) (unidiff)
tree7e0d9c8f2c0f86b8946aea0bb823085c33b164b3 /ui-shared.c
parente5ed227ef0da561e2bde8646ec816842392377ee (diff)
downloadcgit-d14d77fe95c3b6224b40df9b101dded0deea913c.zip
cgit-d14d77fe95c3b6224b40df9b101dded0deea913c.tar.gz
cgit-d14d77fe95c3b6224b40df9b101dded0deea913c.tar.bz2
Introduce struct cgit_context
This struct will hold all the cgit runtime information currently found in a multitude of global variables. The first cleanup removes all querystring-related variables. Signed-off-by: Lars Hjemli <hjemli@gmail.com>
Diffstat (limited to 'ui-shared.c') (more/less context) (show whitespace changes)
-rw-r--r--ui-shared.c86
1 files changed, 43 insertions, 43 deletions
diff --git a/ui-shared.c b/ui-shared.c
index 60aa2e3..6a41fb0 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -103,28 +103,28 @@ const char *cgit_repobasename(const char *reponame)
103 while( p && rvbuf[p]=='/') rvbuf[p--]=0; 103 while( p && rvbuf[p]=='/') rvbuf[p--]=0;
104 /* find last slash in the remaining string */ 104 /* find last slash in the remaining string */
105 rv = strrchr(rvbuf,'/'); 105 rv = strrchr(rvbuf,'/');
106 if(rv) 106 if(rv)
107 return ++rv; 107 return ++rv;
108 return rvbuf; 108 return rvbuf;
109} 109}
110 110
111char *cgit_currurl() 111char *cgit_currurl()
112{ 112{
113 if (!cgit_virtual_root) 113 if (!cgit_virtual_root)
114 return cgit_script_name; 114 return cgit_script_name;
115 else if (cgit_query_page) 115 else if (ctx.qry.page)
116 return fmt("%s/%s/%s/", cgit_virtual_root, cgit_query_repo, cgit_query_page); 116 return fmt("%s/%s/%s/", cgit_virtual_root, ctx.qry.repo, ctx.qry.page);
117 else if (cgit_query_repo) 117 else if (ctx.qry.repo)
118 return fmt("%s/%s/", cgit_virtual_root, cgit_query_repo); 118 return fmt("%s/%s/", cgit_virtual_root, ctx.qry.repo);
119 else 119 else
120 return fmt("%s/", cgit_virtual_root); 120 return fmt("%s/", cgit_virtual_root);
121} 121}
122 122
123static char *repolink(char *title, char *class, char *page, char *head, 123static char *repolink(char *title, char *class, char *page, char *head,
124 char *path) 124 char *path)
125{ 125{
126 char *delim = "?"; 126 char *delim = "?";
127 127
128 html("<a"); 128 html("<a");
129 if (title) { 129 if (title) {
130 html(" title='"); 130 html(" title='");
@@ -170,47 +170,47 @@ static char *repolink(char *title, char *class, char *page, char *head,
170 html_attr(head); 170 html_attr(head);
171 delim = "&amp;"; 171 delim = "&amp;";
172 } 172 }
173 return fmt("%s", delim); 173 return fmt("%s", delim);
174} 174}
175 175
176static void reporevlink(char *page, char *name, char *title, char *class, 176static void reporevlink(char *page, char *name, char *title, char *class,
177 char *head, char *rev, char *path) 177 char *head, char *rev, char *path)
178{ 178{
179 char *delim; 179 char *delim;
180 180
181 delim = repolink(title, class, page, head, path); 181 delim = repolink(title, class, page, head, path);
182 if (rev && strcmp(rev, cgit_query_head)) { 182 if (rev && strcmp(rev, ctx.qry.head)) {
183 html(delim); 183 html(delim);
184 html("id="); 184 html("id=");
185 html_attr(rev); 185 html_attr(rev);
186 } 186 }
187 html("'>"); 187 html("'>");
188 html_txt(name); 188 html_txt(name);
189 html("</a>"); 189 html("</a>");
190} 190}
191 191
192void cgit_tree_link(char *name, char *title, char *class, char *head, 192void cgit_tree_link(char *name, char *title, char *class, char *head,
193 char *rev, char *path) 193 char *rev, char *path)
194{ 194{
195 reporevlink("tree", name, title, class, head, rev, path); 195 reporevlink("tree", name, title, class, head, rev, path);
196} 196}
197 197
198void cgit_log_link(char *name, char *title, char *class, char *head, 198void cgit_log_link(char *name, char *title, char *class, char *head,
199 char *rev, char *path, int ofs, char *grep, char *pattern) 199 char *rev, char *path, int ofs, char *grep, char *pattern)
200{ 200{
201 char *delim; 201 char *delim;
202 202
203 delim = repolink(title, class, "log", head, path); 203 delim = repolink(title, class, "log", head, path);
204 if (rev && strcmp(rev, cgit_query_head)) { 204 if (rev && strcmp(rev, ctx.qry.head)) {
205 html(delim); 205 html(delim);
206 html("id="); 206 html("id=");
207 html_attr(rev); 207 html_attr(rev);
208 delim = "&"; 208 delim = "&";
209 } 209 }
210 if (grep && pattern) { 210 if (grep && pattern) {
211 html(delim); 211 html(delim);
212 html("qt="); 212 html("qt=");
213 html_attr(grep); 213 html_attr(grep);
214 delim = "&"; 214 delim = "&";
215 html(delim); 215 html(delim);
216 html("q="); 216 html("q=");
@@ -247,25 +247,25 @@ void cgit_refs_link(char *name, char *title, char *class, char *head,
247void cgit_snapshot_link(char *name, char *title, char *class, char *head, 247void cgit_snapshot_link(char *name, char *title, char *class, char *head,
248 char *rev, char *archivename) 248 char *rev, char *archivename)
249{ 249{
250 reporevlink("snapshot", name, title, class, head, rev, archivename); 250 reporevlink("snapshot", name, title, class, head, rev, archivename);
251} 251}
252 252
253void cgit_diff_link(char *name, char *title, char *class, char *head, 253void cgit_diff_link(char *name, char *title, char *class, char *head,
254 char *new_rev, char *old_rev, char *path) 254 char *new_rev, char *old_rev, char *path)
255{ 255{
256 char *delim; 256 char *delim;
257 257
258 delim = repolink(title, class, "diff", head, path); 258 delim = repolink(title, class, "diff", head, path);
259 if (new_rev && strcmp(new_rev, cgit_query_head)) { 259 if (new_rev && strcmp(new_rev, ctx.qry.head)) {
260 html(delim); 260 html(delim);
261 html("id="); 261 html("id=");
262 html_attr(new_rev); 262 html_attr(new_rev);
263 delim = "&amp;"; 263 delim = "&amp;";
264 } 264 }
265 if (old_rev) { 265 if (old_rev) {
266 html(delim); 266 html(delim);
267 html("id2="); 267 html("id2=");
268 html_attr(old_rev); 268 html_attr(old_rev);
269 } 269 }
270 html("'>"); 270 html("'>");
271 html_txt(name); 271 html_txt(name);
@@ -275,38 +275,38 @@ void cgit_diff_link(char *name, char *title, char *class, char *head,
275void cgit_patch_link(char *name, char *title, char *class, char *head, 275void cgit_patch_link(char *name, char *title, char *class, char *head,
276 char *rev) 276 char *rev)
277{ 277{
278 reporevlink("patch", name, title, class, head, rev, NULL); 278 reporevlink("patch", name, title, class, head, rev, NULL);
279} 279}
280 280
281void cgit_object_link(struct object *obj) 281void cgit_object_link(struct object *obj)
282{ 282{
283 char *page, *arg, *url; 283 char *page, *arg, *url;
284 284
285 if (obj->type == OBJ_COMMIT) { 285 if (obj->type == OBJ_COMMIT) {
286 cgit_commit_link(fmt("commit %s", sha1_to_hex(obj->sha1)), NULL, NULL, 286 cgit_commit_link(fmt("commit %s", sha1_to_hex(obj->sha1)), NULL, NULL,
287 cgit_query_head, sha1_to_hex(obj->sha1)); 287 ctx.qry.head, sha1_to_hex(obj->sha1));
288 return; 288 return;
289 } else if (obj->type == OBJ_TREE) { 289 } else if (obj->type == OBJ_TREE) {
290 page = "tree"; 290 page = "tree";
291 arg = "id"; 291 arg = "id";
292 } else if (obj->type == OBJ_TAG) { 292 } else if (obj->type == OBJ_TAG) {
293 page = "tag"; 293 page = "tag";
294 arg = "id"; 294 arg = "id";
295 } else { 295 } else {
296 page = "blob"; 296 page = "blob";
297 arg = "id"; 297 arg = "id";
298 } 298 }
299 299
300 url = cgit_pageurl(cgit_query_repo, page, 300 url = cgit_pageurl(ctx.qry.repo, page,
301 fmt("%s=%s", arg, sha1_to_hex(obj->sha1))); 301 fmt("%s=%s", arg, sha1_to_hex(obj->sha1)));
302 html_link_open(url, NULL, NULL); 302 html_link_open(url, NULL, NULL);
303 htmlf("%s %s", typename(obj->type), 303 htmlf("%s %s", typename(obj->type),
304 sha1_to_hex(obj->sha1)); 304 sha1_to_hex(obj->sha1));
305 html_link_close(); 305 html_link_close();
306} 306}
307 307
308void cgit_print_date(time_t secs, char *format) 308void cgit_print_date(time_t secs, char *format)
309{ 309{
310 char buf[64]; 310 char buf[64];
311 struct tm *time; 311 struct tm *time;
312 312
@@ -383,25 +383,25 @@ void cgit_print_docstart(char *title, struct cacheitem *item)
383 html("<body>\n"); 383 html("<body>\n");
384} 384}
385 385
386void cgit_print_docend() 386void cgit_print_docend()
387{ 387{
388 html("</td>\n</tr>\n</table>\n</body>\n</html>\n"); 388 html("</td>\n</tr>\n</table>\n</body>\n</html>\n");
389} 389}
390 390
391int print_branch_option(const char *refname, const unsigned char *sha1, 391int print_branch_option(const char *refname, const unsigned char *sha1,
392 int flags, void *cb_data) 392 int flags, void *cb_data)
393{ 393{
394 char *name = (char *)refname; 394 char *name = (char *)refname;
395 html_option(name, name, cgit_query_head); 395 html_option(name, name, ctx.qry.head);
396 return 0; 396 return 0;
397} 397}
398 398
399int print_archive_ref(const char *refname, const unsigned char *sha1, 399int print_archive_ref(const char *refname, const unsigned char *sha1,
400 int flags, void *cb_data) 400 int flags, void *cb_data)
401{ 401{
402 struct tag *tag; 402 struct tag *tag;
403 struct taginfo *info; 403 struct taginfo *info;
404 struct object *obj; 404 struct object *obj;
405 char buf[256], *url; 405 char buf[256], *url;
406 unsigned char fileid[20]; 406 unsigned char fileid[20];
407 int *header = (int *)cb_data; 407 int *header = (int *)cb_data;
@@ -417,141 +417,141 @@ int print_archive_ref(const char *refname, const unsigned char *sha1,
417 if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) 417 if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag)))
418 return 0; 418 return 0;
419 hashcpy(fileid, tag->tagged->sha1); 419 hashcpy(fileid, tag->tagged->sha1);
420 } else if (obj->type != OBJ_BLOB) { 420 } else if (obj->type != OBJ_BLOB) {
421 return 0; 421 return 0;
422 } else { 422 } else {
423 hashcpy(fileid, sha1); 423 hashcpy(fileid, sha1);
424 } 424 }
425 if (!*header) { 425 if (!*header) {
426 html("<h1>download</h1>\n"); 426 html("<h1>download</h1>\n");
427 *header = 1; 427 *header = 1;
428 } 428 }
429 url = cgit_pageurl(cgit_query_repo, "blob", 429 url = cgit_pageurl(ctx.qry.repo, "blob",
430 fmt("id=%s&amp;path=%s", sha1_to_hex(fileid), 430 fmt("id=%s&amp;path=%s", sha1_to_hex(fileid),
431 buf)); 431 buf));
432 html_link_open(url, NULL, "menu"); 432 html_link_open(url, NULL, "menu");
433 html_txt(strlpart(buf, 20)); 433 html_txt(strlpart(buf, 20));
434 html_link_close(); 434 html_link_close();
435 return 0; 435 return 0;
436} 436}
437 437
438void add_hidden_formfields(int incl_head, int incl_search, char *page) 438void add_hidden_formfields(int incl_head, int incl_search, char *page)
439{ 439{
440 char *url; 440 char *url;
441 441
442 if (!cgit_virtual_root) { 442 if (!cgit_virtual_root) {
443 url = fmt("%s/%s", cgit_query_repo, page); 443 url = fmt("%s/%s", ctx.qry.repo, page);
444 if (cgit_query_path) 444 if (ctx.qry.path)
445 url = fmt("%s/%s", url, cgit_query_path); 445 url = fmt("%s/%s", url, ctx.qry.path);
446 html_hidden("url", url); 446 html_hidden("url", url);
447 } 447 }
448 448
449 if (incl_head && strcmp(cgit_query_head, cgit_repo->defbranch)) 449 if (incl_head && strcmp(ctx.qry.head, cgit_repo->defbranch))
450 html_hidden("h", cgit_query_head); 450 html_hidden("h", ctx.qry.head);
451 451
452 if (cgit_query_sha1) 452 if (ctx.qry.sha1)
453 html_hidden("id", cgit_query_sha1); 453 html_hidden("id", ctx.qry.sha1);
454 if (cgit_query_sha2) 454 if (ctx.qry.sha2)
455 html_hidden("id2", cgit_query_sha2); 455 html_hidden("id2", ctx.qry.sha2);
456 456
457 if (incl_search) { 457 if (incl_search) {
458 if (cgit_query_grep) 458 if (ctx.qry.grep)
459 html_hidden("qt", cgit_query_grep); 459 html_hidden("qt", ctx.qry.grep);
460 if (cgit_query_search) 460 if (ctx.qry.search)
461 html_hidden("q", cgit_query_search); 461 html_hidden("q", ctx.qry.search);
462 } 462 }
463} 463}
464 464
465void cgit_print_pageheader(char *title, int show_search) 465void cgit_print_pageheader(char *title, int show_search)
466{ 466{
467 static const char *default_info = "This is cgit, a fast webinterface for git repositories"; 467 static const char *default_info = "This is cgit, a fast webinterface for git repositories";
468 int header = 0; 468 int header = 0;
469 char *url; 469 char *url;
470 470
471 html("<table id='layout' summary=''>\n"); 471 html("<table id='layout' summary=''>\n");
472 html("<tr><td id='sidebar'>\n"); 472 html("<tr><td id='sidebar'>\n");
473 html("<table class='sidebar' cellspacing='0' summary=''>\n"); 473 html("<table class='sidebar' cellspacing='0' summary=''>\n");
474 html("<tr><td class='sidebar'>\n<a href='"); 474 html("<tr><td class='sidebar'>\n<a href='");
475 html_attr(cgit_rooturl()); 475 html_attr(cgit_rooturl());
476 htmlf("'><img src='%s' alt='cgit'/></a>\n", 476 htmlf("'><img src='%s' alt='cgit'/></a>\n",
477 cgit_logo); 477 cgit_logo);
478 html("</td></tr>\n<tr><td class='sidebar'>\n"); 478 html("</td></tr>\n<tr><td class='sidebar'>\n");
479 if (cgit_query_repo) { 479 if (ctx.qry.repo) {
480 html("<h1 class='first'>"); 480 html("<h1 class='first'>");
481 html_txt(strrpart(cgit_repo->name, 20)); 481 html_txt(strrpart(cgit_repo->name, 20));
482 html("</h1>\n"); 482 html("</h1>\n");
483 html_txt(cgit_repo->desc); 483 html_txt(cgit_repo->desc);
484 if (cgit_repo->owner) { 484 if (cgit_repo->owner) {
485 html("<h1>owner</h1>\n"); 485 html("<h1>owner</h1>\n");
486 html_txt(cgit_repo->owner); 486 html_txt(cgit_repo->owner);
487 } 487 }
488 html("<h1>navigate</h1>\n"); 488 html("<h1>navigate</h1>\n");
489 reporevlink(NULL, "summary", NULL, "menu", cgit_query_head, 489 reporevlink(NULL, "summary", NULL, "menu", ctx.qry.head,
490 NULL, NULL); 490 NULL, NULL);
491 cgit_log_link("log", NULL, "menu", cgit_query_head, NULL, NULL, 491 cgit_log_link("log", NULL, "menu", ctx.qry.head, NULL, NULL,
492 0, NULL, NULL); 492 0, NULL, NULL);
493 cgit_tree_link("tree", NULL, "menu", cgit_query_head, 493 cgit_tree_link("tree", NULL, "menu", ctx.qry.head,
494 cgit_query_sha1, NULL); 494 ctx.qry.sha1, NULL);
495 cgit_commit_link("commit", NULL, "menu", cgit_query_head, 495 cgit_commit_link("commit", NULL, "menu", ctx.qry.head,
496 cgit_query_sha1); 496 ctx.qry.sha1);
497 cgit_diff_link("diff", NULL, "menu", cgit_query_head, 497 cgit_diff_link("diff", NULL, "menu", ctx.qry.head,
498 cgit_query_sha1, cgit_query_sha2, NULL); 498 ctx.qry.sha1, ctx.qry.sha2, NULL);
499 cgit_patch_link("patch", NULL, "menu", cgit_query_head, 499 cgit_patch_link("patch", NULL, "menu", ctx.qry.head,
500 cgit_query_sha1); 500 ctx.qry.sha1);
501 501
502 for_each_ref(print_archive_ref, &header); 502 for_each_ref(print_archive_ref, &header);
503 503
504 if (cgit_repo->clone_url || cgit_clone_prefix) { 504 if (cgit_repo->clone_url || cgit_clone_prefix) {
505 html("<h1>clone</h1>\n"); 505 html("<h1>clone</h1>\n");
506 if (cgit_repo->clone_url) 506 if (cgit_repo->clone_url)
507 url = cgit_repo->clone_url; 507 url = cgit_repo->clone_url;
508 else 508 else
509 url = fmt("%s%s", cgit_clone_prefix, 509 url = fmt("%s%s", cgit_clone_prefix,
510 cgit_repo->url); 510 cgit_repo->url);
511 html("<a class='menu' href='"); 511 html("<a class='menu' href='");
512 html_attr(url); 512 html_attr(url);
513 html("' title='"); 513 html("' title='");
514 html_attr(url); 514 html_attr(url);
515 html("'>\n"); 515 html("'>\n");
516 html_txt(strrpart(url, 20)); 516 html_txt(strrpart(url, 20));
517 html("</a>\n"); 517 html("</a>\n");
518 } 518 }
519 519
520 html("<h1>branch</h1>\n"); 520 html("<h1>branch</h1>\n");
521 html("<form method='get' action=''>\n"); 521 html("<form method='get' action=''>\n");
522 add_hidden_formfields(0, 1, cgit_query_page); 522 add_hidden_formfields(0, 1, ctx.qry.page);
523 // html("<table summary='branch selector' class='grid'><tr><td id='branch-dropdown-cell'>"); 523 // html("<table summary='branch selector' class='grid'><tr><td id='branch-dropdown-cell'>");
524 html("<select name='h' onchange='this.form.submit();'>\n"); 524 html("<select name='h' onchange='this.form.submit();'>\n");
525 for_each_branch_ref(print_branch_option, cgit_query_head); 525 for_each_branch_ref(print_branch_option, ctx.qry.head);
526 html("</select>\n"); 526 html("</select>\n");
527 // html("</td><td>"); 527 // html("</td><td>");
528 html("<noscript><input type='submit' id='switch-btn' value='switch'/></noscript>\n"); 528 html("<noscript><input type='submit' id='switch-btn' value='switch'/></noscript>\n");
529 // html("</td></tr></table>"); 529 // html("</td></tr></table>");
530 html("</form>\n"); 530 html("</form>\n");
531 531
532 html("<h1>search</h1>\n"); 532 html("<h1>search</h1>\n");
533 html("<form method='get' action='"); 533 html("<form method='get' action='");
534 if (cgit_virtual_root) 534 if (cgit_virtual_root)
535 html_attr(cgit_fileurl(cgit_query_repo, "log", 535 html_attr(cgit_fileurl(ctx.qry.repo, "log",
536 cgit_query_path, NULL)); 536 ctx.qry.path, NULL));
537 html("'>\n"); 537 html("'>\n");
538 add_hidden_formfields(1, 0, "log"); 538 add_hidden_formfields(1, 0, "log");
539 html("<select name='qt'>\n"); 539 html("<select name='qt'>\n");
540 html_option("grep", "log msg", cgit_query_grep); 540 html_option("grep", "log msg", ctx.qry.grep);
541 html_option("author", "author", cgit_query_grep); 541 html_option("author", "author", ctx.qry.grep);
542 html_option("committer", "committer", cgit_query_grep); 542 html_option("committer", "committer", ctx.qry.grep);
543 html("</select>\n"); 543 html("</select>\n");
544 html("<input class='txt' type='text' name='q' value='"); 544 html("<input class='txt' type='text' name='q' value='");
545 html_attr(cgit_query_search); 545 html_attr(ctx.qry.search);
546 html("'/>\n"); 546 html("'/>\n");
547 html("</form>\n"); 547 html("</form>\n");
548 } else { 548 } else {
549 if (!cgit_index_info || html_include(cgit_index_info)) 549 if (!cgit_index_info || html_include(cgit_index_info))
550 html(default_info); 550 html(default_info);
551 } 551 }
552 552
553 html("</td></tr></table></td>\n"); 553 html("</td></tr></table></td>\n");
554 554
555 html("<td id='content'>\n"); 555 html("<td id='content'>\n");
556} 556}
557 557