summaryrefslogtreecommitdiffabout
path: root/ui-shared.c
authorLars Hjemli <hjemli@gmail.com>2007-12-10 20:47:29 (UTC)
committer Lars Hjemli <hjemli@gmail.com>2007-12-11 01:43:24 (UTC)
commit620bb3e5e4ff87da740fe7232ba74330b5f862d4 (patch) (unidiff)
tree152cc090cfc56c387393f6aa6666b9d87ad4a23a /ui-shared.c
parentafcdd083dab81afef744e261d81a452698188c30 (diff)
downloadcgit-620bb3e5e4ff87da740fe7232ba74330b5f862d4.zip
cgit-620bb3e5e4ff87da740fe7232ba74330b5f862d4.tar.gz
cgit-620bb3e5e4ff87da740fe7232ba74330b5f862d4.tar.bz2
Add plain patch view
The new view mimics the output from `git format-patch`, making it possible to cherry-pick directly from cgit with something like `curl $url | git am`. Inspired by a patch to `git-apply` by Mike Hommey: http://thread.gmane.org/gmane.comp.version-control.git/67611/focus=67610 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.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/ui-shared.c b/ui-shared.c
index ece041c..60aa2e3 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -243,64 +243,70 @@ void cgit_refs_link(char *name, char *title, char *class, char *head,
243{ 243{
244 reporevlink("refs", name, title, class, head, rev, path); 244 reporevlink("refs", name, title, class, head, rev, path);
245} 245}
246 246
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, cgit_query_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);
272 html("</a>"); 272 html("</a>");
273} 273}
274 274
275void cgit_patch_link(char *name, char *title, char *class, char *head,
276 char *rev)
277{
278 reporevlink("patch", name, title, class, head, rev, NULL);
279}
280
275void cgit_object_link(struct object *obj) 281void cgit_object_link(struct object *obj)
276{ 282{
277 char *page, *arg, *url; 283 char *page, *arg, *url;
278 284
279 if (obj->type == OBJ_COMMIT) { 285 if (obj->type == OBJ_COMMIT) {
280 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,
281 cgit_query_head, sha1_to_hex(obj->sha1)); 287 cgit_query_head, sha1_to_hex(obj->sha1));
282 return; 288 return;
283 } else if (obj->type == OBJ_TREE) { 289 } else if (obj->type == OBJ_TREE) {
284 page = "tree"; 290 page = "tree";
285 arg = "id"; 291 arg = "id";
286 } else if (obj->type == OBJ_TAG) { 292 } else if (obj->type == OBJ_TAG) {
287 page = "tag"; 293 page = "tag";
288 arg = "id"; 294 arg = "id";
289 } else { 295 } else {
290 page = "blob"; 296 page = "blob";
291 arg = "id"; 297 arg = "id";
292 } 298 }
293 299
294 url = cgit_pageurl(cgit_query_repo, page, 300 url = cgit_pageurl(cgit_query_repo, page,
295 fmt("%s=%s", arg, sha1_to_hex(obj->sha1))); 301 fmt("%s=%s", arg, sha1_to_hex(obj->sha1)));
296 html_link_open(url, NULL, NULL); 302 html_link_open(url, NULL, NULL);
297 htmlf("%s %s", typename(obj->type), 303 htmlf("%s %s", typename(obj->type),
298 sha1_to_hex(obj->sha1)); 304 sha1_to_hex(obj->sha1));
299 html_link_close(); 305 html_link_close();
300} 306}
301 307
302void cgit_print_date(time_t secs, char *format) 308void cgit_print_date(time_t secs, char *format)
303{ 309{
304 char buf[64]; 310 char buf[64];
305 struct tm *time; 311 struct tm *time;
306 312
@@ -461,64 +467,66 @@ void cgit_print_pageheader(char *title, int show_search)
461 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";
462 int header = 0; 468 int header = 0;
463 char *url; 469 char *url;
464 470
465 html("<table id='layout' summary=''>\n"); 471 html("<table id='layout' summary=''>\n");
466 html("<tr><td id='sidebar'>\n"); 472 html("<tr><td id='sidebar'>\n");
467 html("<table class='sidebar' cellspacing='0' summary=''>\n"); 473 html("<table class='sidebar' cellspacing='0' summary=''>\n");
468 html("<tr><td class='sidebar'>\n<a href='"); 474 html("<tr><td class='sidebar'>\n<a href='");
469 html_attr(cgit_rooturl()); 475 html_attr(cgit_rooturl());
470 htmlf("'><img src='%s' alt='cgit'/></a>\n", 476 htmlf("'><img src='%s' alt='cgit'/></a>\n",
471 cgit_logo); 477 cgit_logo);
472 html("</td></tr>\n<tr><td class='sidebar'>\n"); 478 html("</td></tr>\n<tr><td class='sidebar'>\n");
473 if (cgit_query_repo) { 479 if (cgit_query_repo) {
474 html("<h1 class='first'>"); 480 html("<h1 class='first'>");
475 html_txt(strrpart(cgit_repo->name, 20)); 481 html_txt(strrpart(cgit_repo->name, 20));
476 html("</h1>\n"); 482 html("</h1>\n");
477 html_txt(cgit_repo->desc); 483 html_txt(cgit_repo->desc);
478 if (cgit_repo->owner) { 484 if (cgit_repo->owner) {
479 html("<h1>owner</h1>\n"); 485 html("<h1>owner</h1>\n");
480 html_txt(cgit_repo->owner); 486 html_txt(cgit_repo->owner);
481 } 487 }
482 html("<h1>navigate</h1>\n"); 488 html("<h1>navigate</h1>\n");
483 reporevlink(NULL, "summary", NULL, "menu", cgit_query_head, 489 reporevlink(NULL, "summary", NULL, "menu", cgit_query_head,
484 NULL, NULL); 490 NULL, NULL);
485 cgit_log_link("log", NULL, "menu", cgit_query_head, NULL, NULL, 491 cgit_log_link("log", NULL, "menu", cgit_query_head, NULL, NULL,
486 0, NULL, NULL); 492 0, NULL, NULL);
487 cgit_tree_link("tree", NULL, "menu", cgit_query_head, 493 cgit_tree_link("tree", NULL, "menu", cgit_query_head,
488 cgit_query_sha1, NULL); 494 cgit_query_sha1, NULL);
489 cgit_commit_link("commit", NULL, "menu", cgit_query_head, 495 cgit_commit_link("commit", NULL, "menu", cgit_query_head,
490 cgit_query_sha1); 496 cgit_query_sha1);
491 cgit_diff_link("diff", NULL, "menu", cgit_query_head, 497 cgit_diff_link("diff", NULL, "menu", cgit_query_head,
492 cgit_query_sha1, cgit_query_sha2, NULL); 498 cgit_query_sha1, cgit_query_sha2, NULL);
499 cgit_patch_link("patch", NULL, "menu", cgit_query_head,
500 cgit_query_sha1);
493 501
494 for_each_ref(print_archive_ref, &header); 502 for_each_ref(print_archive_ref, &header);
495 503
496 if (cgit_repo->clone_url || cgit_clone_prefix) { 504 if (cgit_repo->clone_url || cgit_clone_prefix) {
497 html("<h1>clone</h1>\n"); 505 html("<h1>clone</h1>\n");
498 if (cgit_repo->clone_url) 506 if (cgit_repo->clone_url)
499 url = cgit_repo->clone_url; 507 url = cgit_repo->clone_url;
500 else 508 else
501 url = fmt("%s%s", cgit_clone_prefix, 509 url = fmt("%s%s", cgit_clone_prefix,
502 cgit_repo->url); 510 cgit_repo->url);
503 html("<a class='menu' href='"); 511 html("<a class='menu' href='");
504 html_attr(url); 512 html_attr(url);
505 html("' title='"); 513 html("' title='");
506 html_attr(url); 514 html_attr(url);
507 html("'>\n"); 515 html("'>\n");
508 html_txt(strrpart(url, 20)); 516 html_txt(strrpart(url, 20));
509 html("</a>\n"); 517 html("</a>\n");
510 } 518 }
511 519
512 html("<h1>branch</h1>\n"); 520 html("<h1>branch</h1>\n");
513 html("<form method='get' action=''>\n"); 521 html("<form method='get' action=''>\n");
514 add_hidden_formfields(0, 1, cgit_query_page); 522 add_hidden_formfields(0, 1, cgit_query_page);
515 // 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'>");
516 html("<select name='h' onchange='this.form.submit();'>\n"); 524 html("<select name='h' onchange='this.form.submit();'>\n");
517 for_each_branch_ref(print_branch_option, cgit_query_head); 525 for_each_branch_ref(print_branch_option, cgit_query_head);
518 html("</select>\n"); 526 html("</select>\n");
519 // html("</td><td>"); 527 // html("</td><td>");
520 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");
521 // html("</td></tr></table>"); 529 // html("</td></tr></table>");
522 html("</form>\n"); 530 html("</form>\n");
523 531
524 html("<h1>search</h1>\n"); 532 html("<h1>search</h1>\n");