summaryrefslogtreecommitdiffabout
path: root/ui-shared.c
authorLars Hjemli <hjemli@gmail.com>2007-11-03 09:42:37 (UTC)
committer Lars Hjemli <hjemli@gmail.com>2007-11-03 09:42:37 (UTC)
commit51140311bb3b0d4d0e859d5045ffe4c74478f5fe (patch) (unidiff)
tree6575f174e32abd5f5d1f481e5f7f5978525ae416 /ui-shared.c
parentdf203a293e3ac19245f8761cf7c5808f8735f917 (diff)
downloadcgit-51140311bb3b0d4d0e859d5045ffe4c74478f5fe.zip
cgit-51140311bb3b0d4d0e859d5045ffe4c74478f5fe.tar.gz
cgit-51140311bb3b0d4d0e859d5045ffe4c74478f5fe.tar.bz2
Add search parameters to cgit_log_link
This makes the [prev] and [next] links work correctly on search results. Signed-off-by: Lars Hjemli <hjemli@gmail.com>
Diffstat (limited to 'ui-shared.c') (more/less context) (ignore whitespace changes)
-rw-r--r--ui-shared.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/ui-shared.c b/ui-shared.c
index 1d66940..a03661a 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -149,107 +149,116 @@ static char *repolink(char *title, char *class, char *page, char *head,
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, char *grep, char *pattern)
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 (grep && pattern) {
209 html(delim);
210 html("qt=");
211 html_attr(grep);
212 delim = "&";
213 html(delim);
214 html("q=");
215 html_attr(pattern);
216 }
208 if (ofs > 0) { 217 if (ofs > 0) {
209 html(delim); 218 html(delim);
210 html("ofs="); 219 html("ofs=");
211 htmlf("%d", ofs); 220 htmlf("%d", ofs);
212 } 221 }
213 html("'>"); 222 html("'>");
214 html_txt(name); 223 html_txt(name);
215 html("</a>"); 224 html("</a>");
216} 225}
217 226
218void cgit_commit_link(char *name, char *title, char *class, char *head, 227void cgit_commit_link(char *name, char *title, char *class, char *head,
219 char *rev) 228 char *rev)
220{ 229{
221 if (strlen(name) > cgit_max_msg_len && cgit_max_msg_len >= 15) { 230 if (strlen(name) > cgit_max_msg_len && cgit_max_msg_len >= 15) {
222 name[cgit_max_msg_len] = '\0'; 231 name[cgit_max_msg_len] = '\0';
223 name[cgit_max_msg_len - 1] = '.'; 232 name[cgit_max_msg_len - 1] = '.';
224 name[cgit_max_msg_len - 2] = '.'; 233 name[cgit_max_msg_len - 2] = '.';
225 name[cgit_max_msg_len - 3] = '.'; 234 name[cgit_max_msg_len - 3] = '.';
226 } 235 }
227 reporevlink("commit", name, title, class, head, rev, NULL); 236 reporevlink("commit", name, title, class, head, rev, NULL);
228} 237}
229 238
230void cgit_refs_link(char *name, char *title, char *class, char *head, 239void cgit_refs_link(char *name, char *title, char *class, char *head,
231 char *rev, char *path) 240 char *rev, char *path)
232{ 241{
233 reporevlink("refs", name, title, class, head, rev, path); 242 reporevlink("refs", name, title, class, head, rev, path);
234} 243}
235 244
236void cgit_snapshot_link(char *name, char *title, char *class, char *head, 245void cgit_snapshot_link(char *name, char *title, char *class, char *head,
237 char *rev, char *archivename) 246 char *rev, char *archivename)
238{ 247{
239 reporevlink("snapshot", name, title, class, head, rev, archivename); 248 reporevlink("snapshot", name, title, class, head, rev, archivename);
240} 249}
241 250
242void cgit_diff_link(char *name, char *title, char *class, char *head, 251void cgit_diff_link(char *name, char *title, char *class, char *head,
243 char *new_rev, char *old_rev, char *path) 252 char *new_rev, char *old_rev, char *path)
244{ 253{
245 char *delim; 254 char *delim;
246 255
247 delim = repolink(title, class, "diff", head, path); 256 delim = repolink(title, class, "diff", head, path);
248 if (new_rev && strcmp(new_rev, cgit_query_head)) { 257 if (new_rev && strcmp(new_rev, cgit_query_head)) {
249 html(delim); 258 html(delim);
250 html("id="); 259 html("id=");
251 html_attr(new_rev); 260 html_attr(new_rev);
252 delim = "&amp;"; 261 delim = "&amp;";
253 } 262 }
254 if (old_rev) { 263 if (old_rev) {
255 html(delim); 264 html(delim);
@@ -416,97 +425,97 @@ void add_hidden_formfields(int incl_head, int incl_search)
416{ 425{
417 if (!cgit_virtual_root) { 426 if (!cgit_virtual_root) {
418 if (cgit_query_repo) 427 if (cgit_query_repo)
419 html_hidden("r", cgit_query_repo); 428 html_hidden("r", cgit_query_repo);
420 if (cgit_query_page) 429 if (cgit_query_page)
421 html_hidden("p", cgit_query_page); 430 html_hidden("p", cgit_query_page);
422 } 431 }
423 432
424 if (incl_head && strcmp(cgit_query_head, cgit_repo->defbranch)) 433 if (incl_head && strcmp(cgit_query_head, cgit_repo->defbranch))
425 html_hidden("h", cgit_query_head); 434 html_hidden("h", cgit_query_head);
426 435
427 if (cgit_query_sha1) 436 if (cgit_query_sha1)
428 html_hidden("id", cgit_query_sha1); 437 html_hidden("id", cgit_query_sha1);
429 if (cgit_query_sha2) 438 if (cgit_query_sha2)
430 html_hidden("id2", cgit_query_sha2); 439 html_hidden("id2", cgit_query_sha2);
431 440
432 if (incl_search) { 441 if (incl_search) {
433 if (cgit_query_grep) 442 if (cgit_query_grep)
434 html_hidden("qt", cgit_query_grep); 443 html_hidden("qt", cgit_query_grep);
435 if (cgit_query_search) 444 if (cgit_query_search)
436 html_hidden("q", cgit_query_search); 445 html_hidden("q", cgit_query_search);
437 } 446 }
438} 447}
439 448
440void cgit_print_pageheader(char *title, int show_search) 449void cgit_print_pageheader(char *title, int show_search)
441{ 450{
442 static const char *default_info = "This is cgit, a fast webinterface for git repositories"; 451 static const char *default_info = "This is cgit, a fast webinterface for git repositories";
443 int header = 0; 452 int header = 0;
444 453
445 html("<div id='sidebar'>\n"); 454 html("<div id='sidebar'>\n");
446 html("<a href='"); 455 html("<a href='");
447 html_attr(cgit_rooturl()); 456 html_attr(cgit_rooturl());
448 htmlf("'><div id='logo'><img src='%s' alt='cgit'/></div></a>\n", 457 htmlf("'><div id='logo'><img src='%s' alt='cgit'/></div></a>\n",
449 cgit_logo); 458 cgit_logo);
450 html("<div class='infobox'>"); 459 html("<div class='infobox'>");
451 if (cgit_query_repo) { 460 if (cgit_query_repo) {
452 html("<h1>"); 461 html("<h1>");
453 html_txt(strrpart(cgit_repo->name, 20)); 462 html_txt(strrpart(cgit_repo->name, 20));
454 html("</h1>\n"); 463 html("</h1>\n");
455 html_txt(cgit_repo->desc); 464 html_txt(cgit_repo->desc);
456 if (cgit_repo->owner) { 465 if (cgit_repo->owner) {
457 html("<p>\n<h1>owner</h1>\n"); 466 html("<p>\n<h1>owner</h1>\n");
458 html_txt(cgit_repo->owner); 467 html_txt(cgit_repo->owner);
459 } 468 }
460 html("<p>\n<h1>navigate</h1>\n"); 469 html("<p>\n<h1>navigate</h1>\n");
461 reporevlink(NULL, "summary", NULL, "menu", cgit_query_head, 470 reporevlink(NULL, "summary", NULL, "menu", cgit_query_head,
462 NULL, NULL); 471 NULL, NULL);
463 cgit_log_link("log", NULL, "menu", cgit_query_head, 472 cgit_log_link("log", NULL, "menu", cgit_query_head,
464 cgit_query_sha1, cgit_query_path, 0); 473 cgit_query_sha1, cgit_query_path, 0, NULL, NULL);
465 cgit_tree_link("tree", NULL, "menu", cgit_query_head, 474 cgit_tree_link("tree", NULL, "menu", cgit_query_head,
466 cgit_query_sha1, NULL); 475 cgit_query_sha1, NULL);
467 cgit_commit_link("commit", NULL, "menu", cgit_query_head, 476 cgit_commit_link("commit", NULL, "menu", cgit_query_head,
468 cgit_query_sha1); 477 cgit_query_sha1);
469 cgit_diff_link("diff", NULL, "menu", cgit_query_head, 478 cgit_diff_link("diff", NULL, "menu", cgit_query_head,
470 cgit_query_sha1, cgit_query_sha2, 479 cgit_query_sha1, cgit_query_sha2,
471 cgit_query_path); 480 cgit_query_path);
472 481
473 for_each_ref(print_archive_ref, &header); 482 for_each_ref(print_archive_ref, &header);
474 483
475 html("<p>\n<h1>branch</h1>\n"); 484 html("<p>\n<h1>branch</h1>\n");
476 html("<form method='get' action=''>\n"); 485 html("<form method='get' action=''>\n");
477 add_hidden_formfields(0, 1); 486 add_hidden_formfields(0, 1);
478 html("<select name='h' onchange='this.form.submit();'>\n"); 487 html("<select name='h' onchange='this.form.submit();'>\n");
479 for_each_branch_ref(print_branch_option, cgit_query_head); 488 for_each_branch_ref(print_branch_option, cgit_query_head);
480 html("</select>\n"); 489 html("</select>\n");
481 html("</form>\n"); 490 html("</form>\n");
482 491
483 html("<p>\n<h1>search</h1>\n"); 492 html("<p>\n<h1>search</h1>\n");
484 html("<form method='get' action='"); 493 html("<form method='get' action='");
485 html_attr(cgit_pageurl(cgit_query_repo, "log", NULL)); 494 html_attr(cgit_pageurl(cgit_query_repo, "log", NULL));
486 html("'>\n"); 495 html("'>\n");
487 add_hidden_formfields(1, 0); 496 add_hidden_formfields(1, 0);
488 html("<select name='qt'>\n"); 497 html("<select name='qt'>\n");
489 html_option("grep", "log msg", cgit_query_grep); 498 html_option("grep", "log msg", cgit_query_grep);
490 html_option("author", "author", cgit_query_grep); 499 html_option("author", "author", cgit_query_grep);
491 html_option("committer", "committer", cgit_query_grep); 500 html_option("committer", "committer", cgit_query_grep);
492 html("</select>\n"); 501 html("</select>\n");
493 html("<input class='txt' type='text' name='q' value='"); 502 html("<input class='txt' type='text' name='q' value='");
494 html_attr(cgit_query_search); 503 html_attr(cgit_query_search);
495 html("'/>\n"); 504 html("'/>\n");
496 html("</form>\n"); 505 html("</form>\n");
497 } else { 506 } else {
498 if (!cgit_index_info || html_include(cgit_index_info)) 507 if (!cgit_index_info || html_include(cgit_index_info))
499 html(default_info); 508 html(default_info);
500 } 509 }
501 510
502 html("</div>\n"); 511 html("</div>\n");
503 512
504 html("</div>\n<table class='grid'><tr><td id='content'>\n"); 513 html("</div>\n<table class='grid'><tr><td id='content'>\n");
505} 514}
506 515
507 516
508void cgit_print_snapshot_start(const char *mimetype, const char *filename, 517void cgit_print_snapshot_start(const char *mimetype, const char *filename,
509 struct cacheitem *item) 518 struct cacheitem *item)
510{ 519{
511 htmlf("Content-Type: %s\n", mimetype); 520 htmlf("Content-Type: %s\n", mimetype);
512 htmlf("Content-Disposition: inline; filename=\"%s\"\n", filename); 521 htmlf("Content-Disposition: inline; filename=\"%s\"\n", filename);