]>
git.cameronkatri.com Git - cgit.git/blob - ui-shared.c
1 /* ui-shared.c: common web output functions
3 * Copyright (C) 2006-2014 cgit Development Team <cgit@lists.zx2c4.com>
5 * Licensed under GNU General Public License v2
6 * (see COPYING for full license text)
10 #include "ui-shared.h"
14 static const char cgit_doctype
[] =
15 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n"
16 " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
18 static char *http_date(time_t t
)
20 static char day
[][4] =
21 {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
22 static char month
[][4] =
23 {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
24 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
25 struct tm
*tm
= gmtime(&t
);
26 return fmt("%s, %02d %s %04d %02d:%02d:%02d GMT", day
[tm
->tm_wday
],
27 tm
->tm_mday
, month
[tm
->tm_mon
], 1900 + tm
->tm_year
,
28 tm
->tm_hour
, tm
->tm_min
, tm
->tm_sec
);
31 void cgit_print_error(const char *fmt
, ...)
35 cgit_vprint_error(fmt
, ap
);
39 void cgit_vprint_error(const char *fmt
, va_list ap
)
42 html("<div class='error'>");
49 const char *cgit_httpscheme(void)
51 if (ctx
.env
.https
&& !strcmp(ctx
.env
.https
, "on"))
57 char *cgit_hosturl(void)
59 if (ctx
.env
.http_host
)
60 return xstrdup(ctx
.env
.http_host
);
61 if (!ctx
.env
.server_name
)
63 if (!ctx
.env
.server_port
|| atoi(ctx
.env
.server_port
) == 80)
64 return xstrdup(ctx
.env
.server_name
);
65 return fmtalloc("%s:%s", ctx
.env
.server_name
, ctx
.env
.server_port
);
68 char *cgit_currenturl(void)
71 return xstrdup(cgit_rooturl());
72 const char *root
= cgit_rooturl();
73 size_t len
= strlen(root
);
74 if (len
&& root
[len
- 1] == '/')
75 return fmtalloc("%s%s", root
, ctx
.qry
.url
);
76 return fmtalloc("%s/%s", root
, ctx
.qry
.url
);
79 const char *cgit_rooturl(void)
81 if (ctx
.cfg
.virtual_root
)
82 return ctx
.cfg
.virtual_root
;
84 return ctx
.cfg
.script_name
;
87 const char *cgit_loginurl(void)
89 static const char *login_url
;
91 login_url
= fmtalloc("%s?p=login", cgit_rooturl());
95 char *cgit_repourl(const char *reponame
)
97 if (ctx
.cfg
.virtual_root
)
98 return fmtalloc("%s%s/", ctx
.cfg
.virtual_root
, reponame
);
100 return fmtalloc("?r=%s", reponame
);
103 char *cgit_fileurl(const char *reponame
, const char *pagename
,
104 const char *filename
, const char *query
)
106 struct strbuf sb
= STRBUF_INIT
;
109 if (ctx
.cfg
.virtual_root
) {
110 strbuf_addf(&sb
, "%s%s/%s/%s", ctx
.cfg
.virtual_root
, reponame
,
111 pagename
, (filename
? filename
:""));
114 strbuf_addf(&sb
, "?url=%s/%s/%s", reponame
, pagename
,
115 (filename
? filename
: ""));
119 strbuf_addf(&sb
, "%s%s", delim
, query
);
120 return strbuf_detach(&sb
, NULL
);
123 char *cgit_pageurl(const char *reponame
, const char *pagename
,
126 return cgit_fileurl(reponame
, pagename
, NULL
, query
);
129 const char *cgit_repobasename(const char *reponame
)
131 /* I assume we don't need to store more than one repo basename */
132 static char rvbuf
[1024];
135 strncpy(rvbuf
, reponame
, sizeof(rvbuf
));
136 if (rvbuf
[sizeof(rvbuf
)-1])
137 die("cgit_repobasename: truncated repository name '%s'", reponame
);
139 /* strip trailing slashes */
140 while (p
&& rvbuf
[p
] == '/') rvbuf
[p
--] = 0;
141 /* strip trailing .git */
142 if (p
>= 3 && starts_with(&rvbuf
[p
-3], ".git")) {
143 p
-= 3; rvbuf
[p
--] = 0;
145 /* strip more trailing slashes if any */
146 while ( p
&& rvbuf
[p
] == '/') rvbuf
[p
--] = 0;
147 /* find last slash in the remaining string */
148 rv
= strrchr(rvbuf
,'/');
154 static void site_url(const char *page
, const char *search
, const char *sort
, int ofs
, int always_root
)
158 if (always_root
|| page
)
159 html_attr(cgit_rooturl());
161 char *currenturl
= cgit_currenturl();
162 html_attr(currenturl
);
167 htmlf("?p=%s", page
);
184 htmlf("ofs=%d", ofs
);
188 static void site_link(const char *page
, const char *name
, const char *title
,
189 const char *class, const char *search
, const char *sort
, int ofs
, int always_root
)
203 site_url(page
, search
, sort
, ofs
, always_root
);
209 void cgit_index_link(const char *name
, const char *title
, const char *class,
210 const char *pattern
, const char *sort
, int ofs
, int always_root
)
212 site_link(NULL
, name
, title
, class, pattern
, sort
, ofs
, always_root
);
215 static char *repolink(const char *title
, const char *class, const char *page
,
216 const char *head
, const char *path
)
232 if (ctx
.cfg
.virtual_root
) {
233 html_url_path(ctx
.cfg
.virtual_root
);
234 html_url_path(ctx
.repo
->url
);
235 if (ctx
.repo
->url
[strlen(ctx
.repo
->url
) - 1] != '/')
244 html_url_path(ctx
.cfg
.script_name
);
246 html_url_arg(ctx
.repo
->url
);
247 if (ctx
.repo
->url
[strlen(ctx
.repo
->url
) - 1] != '/')
257 if (head
&& strcmp(head
, ctx
.repo
->defbranch
)) {
263 return fmt("%s", delim
);
266 static void reporevlink(const char *page
, const char *name
, const char *title
,
267 const char *class, const char *head
, const char *rev
,
272 delim
= repolink(title
, class, page
, head
, path
);
273 if (rev
&& ctx
.qry
.head
!= NULL
&& strcmp(rev
, ctx
.qry
.head
)) {
283 void cgit_summary_link(const char *name
, const char *title
, const char *class,
286 reporevlink(NULL
, name
, title
, class, head
, NULL
, NULL
);
289 void cgit_tag_link(const char *name
, const char *title
, const char *class,
292 reporevlink("tag", name
, title
, class, tag
, NULL
, NULL
);
295 void cgit_tree_link(const char *name
, const char *title
, const char *class,
296 const char *head
, const char *rev
, const char *path
)
298 reporevlink("tree", name
, title
, class, head
, rev
, path
);
301 void cgit_plain_link(const char *name
, const char *title
, const char *class,
302 const char *head
, const char *rev
, const char *path
)
304 reporevlink("plain", name
, title
, class, head
, rev
, path
);
307 void cgit_log_link(const char *name
, const char *title
, const char *class,
308 const char *head
, const char *rev
, const char *path
,
309 int ofs
, const char *grep
, const char *pattern
, int showmsg
,
314 delim
= repolink(title
, class, "log", head
, path
);
315 if (rev
&& ctx
.qry
.head
&& strcmp(rev
, ctx
.qry
.head
)) {
321 if (grep
&& pattern
) {
328 html_url_arg(pattern
);
350 void cgit_commit_link(char *name
, const char *title
, const char *class,
351 const char *head
, const char *rev
, const char *path
)
353 if (strlen(name
) > ctx
.cfg
.max_msg_len
&& ctx
.cfg
.max_msg_len
>= 15) {
354 name
[ctx
.cfg
.max_msg_len
] = '\0';
355 name
[ctx
.cfg
.max_msg_len
- 1] = '.';
356 name
[ctx
.cfg
.max_msg_len
- 2] = '.';
357 name
[ctx
.cfg
.max_msg_len
- 3] = '.';
362 delim
= repolink(title
, class, "commit", head
, path
);
363 if (rev
&& ctx
.qry
.head
&& strcmp(rev
, ctx
.qry
.head
)) {
369 if (ctx
.qry
.difftype
) {
371 htmlf("dt=%d", ctx
.qry
.difftype
);
374 if (ctx
.qry
.context
> 0 && ctx
.qry
.context
!= 3) {
377 htmlf("%d", ctx
.qry
.context
);
380 if (ctx
.qry
.ignorews
) {
385 if (ctx
.qry
.follow
) {
393 html_txt("(no commit message)");
397 void cgit_refs_link(const char *name
, const char *title
, const char *class,
398 const char *head
, const char *rev
, const char *path
)
400 reporevlink("refs", name
, title
, class, head
, rev
, path
);
403 void cgit_snapshot_link(const char *name
, const char *title
, const char *class,
404 const char *head
, const char *rev
,
405 const char *archivename
)
407 reporevlink("snapshot", name
, title
, class, head
, rev
, archivename
);
410 void cgit_diff_link(const char *name
, const char *title
, const char *class,
411 const char *head
, const char *new_rev
, const char *old_rev
,
416 delim
= repolink(title
, class, "diff", head
, path
);
417 if (new_rev
&& ctx
.qry
.head
!= NULL
&& strcmp(new_rev
, ctx
.qry
.head
)) {
420 html_url_arg(new_rev
);
426 html_url_arg(old_rev
);
429 if (ctx
.qry
.difftype
) {
431 htmlf("dt=%d", ctx
.qry
.difftype
);
434 if (ctx
.qry
.context
> 0 && ctx
.qry
.context
!= 3) {
437 htmlf("%d", ctx
.qry
.context
);
440 if (ctx
.qry
.ignorews
) {
445 if (ctx
.qry
.follow
) {
454 void cgit_patch_link(const char *name
, const char *title
, const char *class,
455 const char *head
, const char *rev
, const char *path
)
457 reporevlink("patch", name
, title
, class, head
, rev
, path
);
460 void cgit_stats_link(const char *name
, const char *title
, const char *class,
461 const char *head
, const char *path
)
463 reporevlink("stats", name
, title
, class, head
, NULL
, path
);
466 static void cgit_self_link(char *name
, const char *title
, const char *class)
468 if (!strcmp(ctx
.qry
.page
, "repolist"))
469 cgit_index_link(name
, title
, class, ctx
.qry
.search
, ctx
.qry
.sort
,
471 else if (!strcmp(ctx
.qry
.page
, "summary"))
472 cgit_summary_link(name
, title
, class, ctx
.qry
.head
);
473 else if (!strcmp(ctx
.qry
.page
, "tag"))
474 cgit_tag_link(name
, title
, class, ctx
.qry
.has_sha1
?
475 ctx
.qry
.sha1
: ctx
.qry
.head
);
476 else if (!strcmp(ctx
.qry
.page
, "tree"))
477 cgit_tree_link(name
, title
, class, ctx
.qry
.head
,
478 ctx
.qry
.has_sha1
? ctx
.qry
.sha1
: NULL
,
480 else if (!strcmp(ctx
.qry
.page
, "plain"))
481 cgit_plain_link(name
, title
, class, ctx
.qry
.head
,
482 ctx
.qry
.has_sha1
? ctx
.qry
.sha1
: NULL
,
484 else if (!strcmp(ctx
.qry
.page
, "log"))
485 cgit_log_link(name
, title
, class, ctx
.qry
.head
,
486 ctx
.qry
.has_sha1
? ctx
.qry
.sha1
: NULL
,
487 ctx
.qry
.path
, ctx
.qry
.ofs
,
488 ctx
.qry
.grep
, ctx
.qry
.search
,
489 ctx
.qry
.showmsg
, ctx
.qry
.follow
);
490 else if (!strcmp(ctx
.qry
.page
, "commit"))
491 cgit_commit_link(name
, title
, class, ctx
.qry
.head
,
492 ctx
.qry
.has_sha1
? ctx
.qry
.sha1
: NULL
,
494 else if (!strcmp(ctx
.qry
.page
, "patch"))
495 cgit_patch_link(name
, title
, class, ctx
.qry
.head
,
496 ctx
.qry
.has_sha1
? ctx
.qry
.sha1
: NULL
,
498 else if (!strcmp(ctx
.qry
.page
, "refs"))
499 cgit_refs_link(name
, title
, class, ctx
.qry
.head
,
500 ctx
.qry
.has_sha1
? ctx
.qry
.sha1
: NULL
,
502 else if (!strcmp(ctx
.qry
.page
, "snapshot"))
503 cgit_snapshot_link(name
, title
, class, ctx
.qry
.head
,
504 ctx
.qry
.has_sha1
? ctx
.qry
.sha1
: NULL
,
506 else if (!strcmp(ctx
.qry
.page
, "diff"))
507 cgit_diff_link(name
, title
, class, ctx
.qry
.head
,
508 ctx
.qry
.sha1
, ctx
.qry
.sha2
,
510 else if (!strcmp(ctx
.qry
.page
, "stats"))
511 cgit_stats_link(name
, title
, class, ctx
.qry
.head
,
514 /* Don't known how to make link for this page */
515 repolink(title
, class, ctx
.qry
.page
, ctx
.qry
.head
, ctx
.qry
.path
);
516 html("><!-- cgit_self_link() doesn't know how to make link for page '");
517 html_txt(ctx
.qry
.page
);
524 void cgit_object_link(struct object
*obj
)
526 char *page
, *shortrev
, *fullrev
, *name
;
528 fullrev
= sha1_to_hex(obj
->sha1
);
529 shortrev
= xstrdup(fullrev
);
531 if (obj
->type
== OBJ_COMMIT
) {
532 cgit_commit_link(fmt("commit %s...", shortrev
), NULL
, NULL
,
533 ctx
.qry
.head
, fullrev
, NULL
);
535 } else if (obj
->type
== OBJ_TREE
)
537 else if (obj
->type
== OBJ_TAG
)
541 name
= fmt("%s %s...", typename(obj
->type
), shortrev
);
542 reporevlink(page
, name
, NULL
, NULL
, ctx
.qry
.head
, fullrev
, NULL
);
545 static struct string_list_item
*lookup_path(struct string_list
*list
,
548 struct string_list_item
*item
;
550 while (path
&& path
[0]) {
551 if ((item
= string_list_lookup(list
, path
)))
553 if (!(path
= strchr(path
, '/')))
560 void cgit_submodule_link(const char *class, char *path
, const char *rev
)
562 struct string_list
*list
;
563 struct string_list_item
*item
;
569 list
= &ctx
.repo
->submodules
;
570 item
= lookup_path(list
, path
);
573 tail
= path
[len
- 1];
576 item
= lookup_path(list
, path
);
579 if (item
|| ctx
.repo
->module_link
) {
582 htmlf("class='%s' ", class);
585 html_attrf(item
->util
, rev
);
587 dir
= strrchr(path
, '/');
592 html_attrf(ctx
.repo
->module_link
, dir
, rev
);
600 htmlf(" class='%s'", class);
605 html_txtf(" @ %.7s", rev
);
607 path
[len
- 1] = tail
;
610 static const char *fmt_date(time_t secs
, const char *format
, int local_time
)
618 time
= localtime(&secs
);
620 time
= gmtime(&secs
);
621 strftime(buf
, sizeof(buf
)-1, format
, time
);
625 void cgit_print_date(time_t secs
, const char *format
, int local_time
)
627 html_txt(fmt_date(secs
, format
, local_time
));
630 static void print_rel_date(time_t t
, double value
,
631 const char *class, const char *suffix
)
633 htmlf("<span class='%s' title='", class);
634 html_attr(fmt_date(t
, FMT_LONGDATE
, ctx
.cfg
.local_time
));
635 htmlf("'>%.0f %s</span>", value
, suffix
);
638 void cgit_print_age(time_t t
, time_t max_relative
, const char *format
)
649 if (secs
> max_relative
&& max_relative
>= 0) {
650 html("<span title='");
651 html_attr(fmt_date(t
, FMT_LONGDATE
, ctx
.cfg
.local_time
));
653 cgit_print_date(t
, format
, ctx
.cfg
.local_time
);
658 if (secs
< TM_HOUR
* 2) {
659 print_rel_date(t
, secs
* 1.0 / TM_MIN
, "age-mins", "min.");
662 if (secs
< TM_DAY
* 2) {
663 print_rel_date(t
, secs
* 1.0 / TM_HOUR
, "age-hours", "hours");
666 if (secs
< TM_WEEK
* 2) {
667 print_rel_date(t
, secs
* 1.0 / TM_DAY
, "age-days", "days");
670 if (secs
< TM_MONTH
* 2) {
671 print_rel_date(t
, secs
* 1.0 / TM_WEEK
, "age-weeks", "weeks");
674 if (secs
< TM_YEAR
* 2) {
675 print_rel_date(t
, secs
* 1.0 / TM_MONTH
, "age-months", "months");
678 print_rel_date(t
, secs
* 1.0 / TM_YEAR
, "age-years", "years");
681 void cgit_print_http_headers(void)
683 if (ctx
.env
.no_http
&& !strcmp(ctx
.env
.no_http
, "1"))
687 htmlf("Status: %d %s\n", ctx
.page
.status
, ctx
.page
.statusmsg
);
688 if (ctx
.page
.mimetype
&& ctx
.page
.charset
)
689 htmlf("Content-Type: %s; charset=%s\n", ctx
.page
.mimetype
,
691 else if (ctx
.page
.mimetype
)
692 htmlf("Content-Type: %s\n", ctx
.page
.mimetype
);
694 htmlf("Content-Length: %zd\n", ctx
.page
.size
);
695 if (ctx
.page
.filename
)
696 htmlf("Content-Disposition: inline; filename=\"%s\"\n",
698 if (!ctx
.env
.authenticated
)
699 html("Cache-Control: no-cache, no-store\n");
700 htmlf("Last-Modified: %s\n", http_date(ctx
.page
.modified
));
701 htmlf("Expires: %s\n", http_date(ctx
.page
.expires
));
703 htmlf("ETag: \"%s\"\n", ctx
.page
.etag
);
705 if (ctx
.env
.request_method
&& !strcmp(ctx
.env
.request_method
, "HEAD"))
709 void cgit_redirect(const char *url
, bool permanent
)
711 htmlf("Status: %d %s\n", permanent
? 301 : 302, permanent
? "Moved" : "Found");
712 htmlf("Location: %s\n\n", url
);
716 static void print_rel_vcs_link(const char *url
)
718 html("<link rel='vcs-git' href='");
721 html_attr(ctx
.repo
->name
);
722 html(" Git repository'/>\n");
725 void cgit_print_docstart(void)
727 if (ctx
.cfg
.embedded
) {
729 html_include(ctx
.cfg
.header
);
733 char *host
= cgit_hosturl();
735 html("<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>\n");
738 html_txt(ctx
.page
.title
);
740 htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version
);
741 if (ctx
.cfg
.robots
&& *ctx
.cfg
.robots
)
742 htmlf("<meta name='robots' content='%s'/>\n", ctx
.cfg
.robots
);
743 html("<link rel='stylesheet' type='text/css' href='");
744 html_attr(ctx
.cfg
.css
);
746 if (ctx
.cfg
.favicon
) {
747 html("<link rel='shortcut icon' href='");
748 html_attr(ctx
.cfg
.favicon
);
751 if (host
&& ctx
.repo
&& ctx
.qry
.head
) {
753 struct strbuf sb
= STRBUF_INIT
;
754 strbuf_addf(&sb
, "h=%s", ctx
.qry
.head
);
756 html("<link rel='alternate' title='Atom feed' href='");
757 html(cgit_httpscheme());
759 fileurl
= cgit_fileurl(ctx
.repo
->url
, "atom", ctx
.qry
.vpath
,
762 html("' type='application/atom+xml'/>\n");
767 cgit_add_clone_urls(print_rel_vcs_link
);
768 if (ctx
.cfg
.head_include
)
769 html_include(ctx
.cfg
.head_include
);
773 html_include(ctx
.cfg
.header
);
777 void cgit_print_docend(void)
779 html("</div> <!-- class=content -->\n");
780 if (ctx
.cfg
.embedded
) {
781 html("</div> <!-- id=cgit -->\n");
783 html_include(ctx
.cfg
.footer
);
787 html_include(ctx
.cfg
.footer
);
789 htmlf("<div class='footer'>generated by <a href='http://git.zx2c4.com/cgit/about/'>cgit %s</a> at ",
791 cgit_print_date(time(NULL
), FMT_LONGDATE
, ctx
.cfg
.local_time
);
794 html("</div> <!-- id=cgit -->\n");
795 html("</body>\n</html>\n");
798 void cgit_print_error_page(int code
, const char *msg
, const char *fmt
, ...)
801 ctx
.page
.expires
= ctx
.cfg
.cache_dynamic_ttl
;
802 ctx
.page
.status
= code
;
803 ctx
.page
.statusmsg
= msg
;
804 cgit_print_http_headers();
805 cgit_print_docstart();
806 cgit_print_pageheader();
808 cgit_vprint_error(fmt
, ap
);
813 void cgit_print_layout_start(void)
815 cgit_print_http_headers();
816 cgit_print_docstart();
817 cgit_print_pageheader();
820 void cgit_print_layout_end(void)
825 static void add_clone_urls(void (*fn
)(const char *), char *txt
, char *suffix
)
827 struct strbuf
**url_list
= strbuf_split_str(txt
, ' ', 0);
830 for (i
= 0; url_list
[i
]; i
++) {
831 strbuf_rtrim(url_list
[i
]);
832 if (url_list
[i
]->len
== 0)
834 if (suffix
&& *suffix
)
835 strbuf_addf(url_list
[i
], "/%s", suffix
);
836 fn(url_list
[i
]->buf
);
839 strbuf_list_free(url_list
);
842 void cgit_add_clone_urls(void (*fn
)(const char *))
844 if (ctx
.repo
->clone_url
)
845 add_clone_urls(fn
, expand_macros(ctx
.repo
->clone_url
), NULL
);
846 else if (ctx
.cfg
.clone_prefix
)
847 add_clone_urls(fn
, ctx
.cfg
.clone_prefix
, ctx
.repo
->url
);
850 static int print_branch_option(const char *refname
, const struct object_id
*oid
,
851 int flags
, void *cb_data
)
853 char *name
= (char *)refname
;
854 html_option(name
, name
, ctx
.qry
.head
);
858 void cgit_add_hidden_formfields(int incl_head
, int incl_search
,
861 if (!ctx
.cfg
.virtual_root
) {
862 struct strbuf url
= STRBUF_INIT
;
864 strbuf_addf(&url
, "%s/%s", ctx
.qry
.repo
, page
);
866 strbuf_addf(&url
, "/%s", ctx
.qry
.vpath
);
867 html_hidden("url", url
.buf
);
868 strbuf_release(&url
);
871 if (incl_head
&& ctx
.qry
.head
&& ctx
.repo
->defbranch
&&
872 strcmp(ctx
.qry
.head
, ctx
.repo
->defbranch
))
873 html_hidden("h", ctx
.qry
.head
);
876 html_hidden("id", ctx
.qry
.sha1
);
878 html_hidden("id2", ctx
.qry
.sha2
);
880 html_hidden("showmsg", "1");
884 html_hidden("qt", ctx
.qry
.grep
);
886 html_hidden("q", ctx
.qry
.search
);
890 static const char *hc(const char *page
)
892 return strcmp(ctx
.qry
.page
, page
) ? NULL
: "active";
895 static void cgit_print_path_crumbs(char *path
)
897 char *old_path
= ctx
.qry
.path
;
898 char *p
= path
, *q
, *end
= path
+ strlen(path
);
901 cgit_self_link("root", NULL
, NULL
);
902 ctx
.qry
.path
= p
= path
;
904 if (!(q
= strchr(p
, '/')))
908 cgit_self_link(p
, NULL
, NULL
);
913 ctx
.qry
.path
= old_path
;
916 static void print_header(void)
918 char *logo
= NULL
, *logo_link
= NULL
;
920 html("<table id='header'>\n");
923 if (ctx
.repo
&& ctx
.repo
->logo
&& *ctx
.repo
->logo
)
924 logo
= ctx
.repo
->logo
;
927 if (ctx
.repo
&& ctx
.repo
->logo_link
&& *ctx
.repo
->logo_link
)
928 logo_link
= ctx
.repo
->logo_link
;
930 logo_link
= ctx
.cfg
.logo_link
;
932 html("<td class='logo' rowspan='2'><a href='");
933 if (logo_link
&& *logo_link
)
934 html_attr(logo_link
);
936 html_attr(cgit_rooturl());
937 html("'><img src='");
939 html("' alt='cgit logo'/></a></td>\n");
942 html("<td class='main'>");
944 cgit_index_link("index", NULL
, NULL
, NULL
, NULL
, 0, 1);
946 cgit_summary_link(ctx
.repo
->name
, ctx
.repo
->name
, NULL
, NULL
);
947 if (ctx
.env
.authenticated
) {
948 html("</td><td class='form'>");
949 html("<form method='get' action=''>\n");
950 cgit_add_hidden_formfields(0, 1, ctx
.qry
.page
);
951 html("<select name='h' onchange='this.form.submit();'>\n");
952 for_each_branch_ref(print_branch_option
, ctx
.qry
.head
);
953 if (ctx
.repo
->enable_remote_branches
)
954 for_each_remote_ref(print_branch_option
, ctx
.qry
.head
);
956 html("<input type='submit' name='' value='switch'/>");
960 html_txt(ctx
.cfg
.root_title
);
961 html("</td></tr>\n");
963 html("<tr><td class='sub'>");
965 html_txt(ctx
.repo
->desc
);
966 html("</td><td class='sub right'>");
967 html_txt(ctx
.repo
->owner
);
969 if (ctx
.cfg
.root_desc
)
970 html_txt(ctx
.cfg
.root_desc
);
971 else if (ctx
.cfg
.index_info
)
972 html_include(ctx
.cfg
.index_info
);
974 html("</td></tr></table>\n");
977 void cgit_print_pageheader(void)
979 html("<div id='cgit'>");
980 if (!ctx
.env
.authenticated
|| !ctx
.cfg
.noheader
)
983 html("<table class='tabs'><tr><td>\n");
984 if (ctx
.env
.authenticated
&& ctx
.repo
) {
985 if (ctx
.repo
->readme
.nr
)
986 reporevlink("about", "about", NULL
,
987 hc("about"), ctx
.qry
.head
, NULL
,
989 cgit_summary_link("summary", NULL
, hc("summary"),
991 cgit_refs_link("refs", NULL
, hc("refs"), ctx
.qry
.head
,
993 cgit_log_link("log", NULL
, hc("log"), ctx
.qry
.head
,
994 NULL
, ctx
.qry
.vpath
, 0, NULL
, NULL
,
995 ctx
.qry
.showmsg
, ctx
.qry
.follow
);
996 cgit_tree_link("tree", NULL
, hc("tree"), ctx
.qry
.head
,
997 ctx
.qry
.sha1
, ctx
.qry
.vpath
);
998 cgit_commit_link("commit", NULL
, hc("commit"),
999 ctx
.qry
.head
, ctx
.qry
.sha1
, ctx
.qry
.vpath
);
1000 cgit_diff_link("diff", NULL
, hc("diff"), ctx
.qry
.head
,
1001 ctx
.qry
.sha1
, ctx
.qry
.sha2
, ctx
.qry
.vpath
);
1002 if (ctx
.repo
->max_stats
)
1003 cgit_stats_link("stats", NULL
, hc("stats"),
1004 ctx
.qry
.head
, ctx
.qry
.vpath
);
1005 html("</td><td class='form'>");
1006 html("<form class='right' method='get' action='");
1007 if (ctx
.cfg
.virtual_root
) {
1008 char *fileurl
= cgit_fileurl(ctx
.qry
.repo
, "log",
1009 ctx
.qry
.vpath
, NULL
);
1010 html_url_path(fileurl
);
1014 cgit_add_hidden_formfields(1, 0, "log");
1015 html("<select name='qt'>\n");
1016 html_option("grep", "log msg", ctx
.qry
.grep
);
1017 html_option("author", "author", ctx
.qry
.grep
);
1018 html_option("committer", "committer", ctx
.qry
.grep
);
1019 html_option("range", "range", ctx
.qry
.grep
);
1020 html("</select>\n");
1021 html("<input class='txt' type='text' size='10' name='q' value='");
1022 html_attr(ctx
.qry
.search
);
1024 html("<input type='submit' value='search'/>\n");
1026 } else if (ctx
.env
.authenticated
) {
1027 char *currenturl
= cgit_currenturl();
1028 site_link(NULL
, "index", NULL
, hc("repolist"), NULL
, NULL
, 0, 1);
1029 if (ctx
.cfg
.root_readme
)
1030 site_link("about", "about", NULL
, hc("about"),
1032 html("</td><td class='form'>");
1033 html("<form method='get' action='");
1034 html_attr(currenturl
);
1036 html("<input type='text' name='q' size='10' value='");
1037 html_attr(ctx
.qry
.search
);
1039 html("<input type='submit' value='search'/>\n");
1043 html("</td></tr></table>\n");
1044 if (ctx
.env
.authenticated
&& ctx
.qry
.vpath
) {
1045 html("<div class='path'>");
1047 cgit_print_path_crumbs(ctx
.qry
.vpath
);
1048 if (ctx
.cfg
.enable_follow_links
&& !strcmp(ctx
.qry
.page
, "log")) {
1050 ctx
.qry
.follow
= !ctx
.qry
.follow
;
1051 cgit_self_link(ctx
.qry
.follow
? "follow" : "unfollow",
1053 ctx
.qry
.follow
= !ctx
.qry
.follow
;
1058 html("<div class='content'>");
1061 void cgit_print_filemode(unsigned short mode
)
1065 else if (S_ISLNK(mode
))
1067 else if (S_ISGITLINK(mode
))
1071 html_fileperm(mode
>> 6);
1072 html_fileperm(mode
>> 3);
1073 html_fileperm(mode
);
1076 void cgit_print_snapshot_links(const char *repo
, const char *head
,
1077 const char *hex
, int snapshots
)
1079 const struct cgit_snapshot_format
* f
;
1080 struct strbuf filename
= STRBUF_INIT
;
1082 unsigned char sha1
[20];
1084 if (get_sha1(fmt("refs/tags/%s", hex
), sha1
) == 0 &&
1085 (hex
[0] == 'v' || hex
[0] == 'V') && isdigit(hex
[1]))
1087 strbuf_addf(&filename
, "%s-%s", cgit_repobasename(repo
), hex
);
1088 prefixlen
= filename
.len
;
1089 for (f
= cgit_snapshot_formats
; f
->suffix
; f
++) {
1090 if (!(snapshots
& f
->bit
))
1092 strbuf_setlen(&filename
, prefixlen
);
1093 strbuf_addstr(&filename
, f
->suffix
);
1094 cgit_snapshot_link(filename
.buf
, NULL
, NULL
, NULL
, NULL
,
1098 strbuf_release(&filename
);