]>
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 const char *cgit_hosturl(void)
59 if (ctx
.env
.http_host
)
60 return ctx
.env
.http_host
;
61 if (!ctx
.env
.server_name
)
63 if (!ctx
.env
.server_port
|| atoi(ctx
.env
.server_port
) == 80)
64 return ctx
.env
.server_name
;
65 return fmtalloc("%s:%s", ctx
.env
.server_name
, ctx
.env
.server_port
);
68 const char *cgit_currenturl(void)
71 return 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 html_attr(cgit_currenturl());
164 htmlf("?p=%s", page
);
181 htmlf("ofs=%d", ofs
);
185 static void site_link(const char *page
, const char *name
, const char *title
,
186 const char *class, const char *search
, const char *sort
, int ofs
, int always_root
)
200 site_url(page
, search
, sort
, ofs
, always_root
);
206 void cgit_index_link(const char *name
, const char *title
, const char *class,
207 const char *pattern
, const char *sort
, int ofs
, int always_root
)
209 site_link(NULL
, name
, title
, class, pattern
, sort
, ofs
, always_root
);
212 static char *repolink(const char *title
, const char *class, const char *page
,
213 const char *head
, const char *path
)
229 if (ctx
.cfg
.virtual_root
) {
230 html_url_path(ctx
.cfg
.virtual_root
);
231 html_url_path(ctx
.repo
->url
);
232 if (ctx
.repo
->url
[strlen(ctx
.repo
->url
) - 1] != '/')
241 html_url_path(ctx
.cfg
.script_name
);
243 html_url_arg(ctx
.repo
->url
);
244 if (ctx
.repo
->url
[strlen(ctx
.repo
->url
) - 1] != '/')
254 if (head
&& strcmp(head
, ctx
.repo
->defbranch
)) {
260 return fmt("%s", delim
);
263 static void reporevlink(const char *page
, const char *name
, const char *title
,
264 const char *class, const char *head
, const char *rev
,
269 delim
= repolink(title
, class, page
, head
, path
);
270 if (rev
&& ctx
.qry
.head
!= NULL
&& strcmp(rev
, ctx
.qry
.head
)) {
280 void cgit_summary_link(const char *name
, const char *title
, const char *class,
283 reporevlink(NULL
, name
, title
, class, head
, NULL
, NULL
);
286 void cgit_tag_link(const char *name
, const char *title
, const char *class,
289 reporevlink("tag", name
, title
, class, tag
, NULL
, NULL
);
292 void cgit_tree_link(const char *name
, const char *title
, const char *class,
293 const char *head
, const char *rev
, const char *path
)
295 reporevlink("tree", name
, title
, class, head
, rev
, path
);
298 void cgit_plain_link(const char *name
, const char *title
, const char *class,
299 const char *head
, const char *rev
, const char *path
)
301 reporevlink("plain", name
, title
, class, head
, rev
, path
);
304 void cgit_log_link(const char *name
, const char *title
, const char *class,
305 const char *head
, const char *rev
, const char *path
,
306 int ofs
, const char *grep
, const char *pattern
, int showmsg
)
310 delim
= repolink(title
, class, "log", head
, path
);
311 if (rev
&& ctx
.qry
.head
&& strcmp(rev
, ctx
.qry
.head
)) {
317 if (grep
&& pattern
) {
324 html_url_arg(pattern
);
341 void cgit_commit_link(char *name
, const char *title
, const char *class,
342 const char *head
, const char *rev
, const char *path
)
344 if (strlen(name
) > ctx
.cfg
.max_msg_len
&& ctx
.cfg
.max_msg_len
>= 15) {
345 name
[ctx
.cfg
.max_msg_len
] = '\0';
346 name
[ctx
.cfg
.max_msg_len
- 1] = '.';
347 name
[ctx
.cfg
.max_msg_len
- 2] = '.';
348 name
[ctx
.cfg
.max_msg_len
- 3] = '.';
353 delim
= repolink(title
, class, "commit", head
, path
);
354 if (rev
&& ctx
.qry
.head
&& strcmp(rev
, ctx
.qry
.head
)) {
360 if (ctx
.qry
.difftype
) {
362 htmlf("dt=%d", ctx
.qry
.difftype
);
365 if (ctx
.qry
.context
> 0 && ctx
.qry
.context
!= 3) {
368 htmlf("%d", ctx
.qry
.context
);
371 if (ctx
.qry
.ignorews
) {
380 html_txt("(no commit message)");
384 void cgit_refs_link(const char *name
, const char *title
, const char *class,
385 const char *head
, const char *rev
, const char *path
)
387 reporevlink("refs", name
, title
, class, head
, rev
, path
);
390 void cgit_snapshot_link(const char *name
, const char *title
, const char *class,
391 const char *head
, const char *rev
,
392 const char *archivename
)
394 reporevlink("snapshot", name
, title
, class, head
, rev
, archivename
);
397 void cgit_diff_link(const char *name
, const char *title
, const char *class,
398 const char *head
, const char *new_rev
, const char *old_rev
,
403 delim
= repolink(title
, class, "diff", head
, path
);
404 if (new_rev
&& ctx
.qry
.head
!= NULL
&& strcmp(new_rev
, ctx
.qry
.head
)) {
407 html_url_arg(new_rev
);
413 html_url_arg(old_rev
);
416 if (ctx
.qry
.difftype
) {
418 htmlf("dt=%d", ctx
.qry
.difftype
);
421 if (ctx
.qry
.context
> 0 && ctx
.qry
.context
!= 3) {
424 htmlf("%d", ctx
.qry
.context
);
427 if (ctx
.qry
.ignorews
) {
437 void cgit_patch_link(const char *name
, const char *title
, const char *class,
438 const char *head
, const char *rev
, const char *path
)
440 reporevlink("patch", name
, title
, class, head
, rev
, path
);
443 void cgit_stats_link(const char *name
, const char *title
, const char *class,
444 const char *head
, const char *path
)
446 reporevlink("stats", name
, title
, class, head
, NULL
, path
);
449 static void cgit_self_link(char *name
, const char *title
, const char *class)
451 if (!strcmp(ctx
.qry
.page
, "repolist"))
452 cgit_index_link(name
, title
, class, ctx
.qry
.search
, ctx
.qry
.sort
,
454 else if (!strcmp(ctx
.qry
.page
, "summary"))
455 cgit_summary_link(name
, title
, class, ctx
.qry
.head
);
456 else if (!strcmp(ctx
.qry
.page
, "tag"))
457 cgit_tag_link(name
, title
, class, ctx
.qry
.has_sha1
?
458 ctx
.qry
.sha1
: ctx
.qry
.head
);
459 else if (!strcmp(ctx
.qry
.page
, "tree"))
460 cgit_tree_link(name
, title
, class, ctx
.qry
.head
,
461 ctx
.qry
.has_sha1
? ctx
.qry
.sha1
: NULL
,
463 else if (!strcmp(ctx
.qry
.page
, "plain"))
464 cgit_plain_link(name
, title
, class, ctx
.qry
.head
,
465 ctx
.qry
.has_sha1
? ctx
.qry
.sha1
: NULL
,
467 else if (!strcmp(ctx
.qry
.page
, "log"))
468 cgit_log_link(name
, title
, class, ctx
.qry
.head
,
469 ctx
.qry
.has_sha1
? ctx
.qry
.sha1
: NULL
,
470 ctx
.qry
.path
, ctx
.qry
.ofs
,
471 ctx
.qry
.grep
, ctx
.qry
.search
,
473 else if (!strcmp(ctx
.qry
.page
, "commit"))
474 cgit_commit_link(name
, title
, class, ctx
.qry
.head
,
475 ctx
.qry
.has_sha1
? ctx
.qry
.sha1
: NULL
,
477 else if (!strcmp(ctx
.qry
.page
, "patch"))
478 cgit_patch_link(name
, title
, class, ctx
.qry
.head
,
479 ctx
.qry
.has_sha1
? ctx
.qry
.sha1
: NULL
,
481 else if (!strcmp(ctx
.qry
.page
, "refs"))
482 cgit_refs_link(name
, title
, class, ctx
.qry
.head
,
483 ctx
.qry
.has_sha1
? ctx
.qry
.sha1
: NULL
,
485 else if (!strcmp(ctx
.qry
.page
, "snapshot"))
486 cgit_snapshot_link(name
, title
, class, ctx
.qry
.head
,
487 ctx
.qry
.has_sha1
? ctx
.qry
.sha1
: NULL
,
489 else if (!strcmp(ctx
.qry
.page
, "diff"))
490 cgit_diff_link(name
, title
, class, ctx
.qry
.head
,
491 ctx
.qry
.sha1
, ctx
.qry
.sha2
,
493 else if (!strcmp(ctx
.qry
.page
, "stats"))
494 cgit_stats_link(name
, title
, class, ctx
.qry
.head
,
497 /* Don't known how to make link for this page */
498 repolink(title
, class, ctx
.qry
.page
, ctx
.qry
.head
, ctx
.qry
.path
);
499 html("><!-- cgit_self_link() doesn't know how to make link for page '");
500 html_txt(ctx
.qry
.page
);
507 void cgit_object_link(struct object
*obj
)
509 char *page
, *shortrev
, *fullrev
, *name
;
511 fullrev
= sha1_to_hex(obj
->sha1
);
512 shortrev
= xstrdup(fullrev
);
514 if (obj
->type
== OBJ_COMMIT
) {
515 cgit_commit_link(fmt("commit %s...", shortrev
), NULL
, NULL
,
516 ctx
.qry
.head
, fullrev
, NULL
);
518 } else if (obj
->type
== OBJ_TREE
)
520 else if (obj
->type
== OBJ_TAG
)
524 name
= fmt("%s %s...", typename(obj
->type
), shortrev
);
525 reporevlink(page
, name
, NULL
, NULL
, ctx
.qry
.head
, fullrev
, NULL
);
528 static struct string_list_item
*lookup_path(struct string_list
*list
,
531 struct string_list_item
*item
;
533 while (path
&& path
[0]) {
534 if ((item
= string_list_lookup(list
, path
)))
536 if (!(path
= strchr(path
, '/')))
543 void cgit_submodule_link(const char *class, char *path
, const char *rev
)
545 struct string_list
*list
;
546 struct string_list_item
*item
;
552 list
= &ctx
.repo
->submodules
;
553 item
= lookup_path(list
, path
);
556 tail
= path
[len
- 1];
559 item
= lookup_path(list
, path
);
562 if (item
|| ctx
.repo
->module_link
) {
565 htmlf("class='%s' ", class);
568 html_attrf(item
->util
, rev
);
570 dir
= strrchr(path
, '/');
575 html_attrf(ctx
.repo
->module_link
, dir
, rev
);
583 htmlf(" class='%s'", class);
588 html_txtf(" @ %.7s", rev
);
590 path
[len
- 1] = tail
;
593 void cgit_print_date(time_t secs
, const char *format
, int local_time
)
601 time
= localtime(&secs
);
603 time
= gmtime(&secs
);
604 strftime(buf
, sizeof(buf
)-1, format
, time
);
608 static void print_rel_date(time_t t
, double value
,
609 const char *class, const char *suffix
)
614 if (ctx
.cfg
.local_time
)
615 time
= localtime(&t
);
618 strftime(buf
, sizeof(buf
) - 1, FMT_LONGDATE
, time
);
620 htmlf("<span class='%s' title='", class);
622 htmlf("'>%.0f %s</span>", value
, suffix
);
625 void cgit_print_age(time_t t
, time_t max_relative
, const char *format
)
636 if (secs
> max_relative
&& max_relative
>= 0) {
637 cgit_print_date(t
, format
, ctx
.cfg
.local_time
);
641 if (secs
< TM_HOUR
* 2) {
642 print_rel_date(t
, secs
* 1.0 / TM_MIN
, "age-mins", "min.");
645 if (secs
< TM_DAY
* 2) {
646 print_rel_date(t
, secs
* 1.0 / TM_HOUR
, "age-hours", "hours");
649 if (secs
< TM_WEEK
* 2) {
650 print_rel_date(t
, secs
* 1.0 / TM_DAY
, "age-days", "days");
653 if (secs
< TM_MONTH
* 2) {
654 print_rel_date(t
, secs
* 1.0 / TM_WEEK
, "age-weeks", "weeks");
657 if (secs
< TM_YEAR
* 2) {
658 print_rel_date(t
, secs
* 1.0 / TM_MONTH
, "age-months", "months");
661 print_rel_date(t
, secs
* 1.0 / TM_YEAR
, "age-years", "years");
664 void cgit_print_http_headers(void)
666 if (ctx
.env
.no_http
&& !strcmp(ctx
.env
.no_http
, "1"))
670 htmlf("Status: %d %s\n", ctx
.page
.status
, ctx
.page
.statusmsg
);
671 if (ctx
.page
.mimetype
&& ctx
.page
.charset
)
672 htmlf("Content-Type: %s; charset=%s\n", ctx
.page
.mimetype
,
674 else if (ctx
.page
.mimetype
)
675 htmlf("Content-Type: %s\n", ctx
.page
.mimetype
);
677 htmlf("Content-Length: %zd\n", ctx
.page
.size
);
678 if (ctx
.page
.filename
)
679 htmlf("Content-Disposition: inline; filename=\"%s\"\n",
681 if (!ctx
.env
.authenticated
)
682 html("Cache-Control: no-cache, no-store\n");
683 htmlf("Last-Modified: %s\n", http_date(ctx
.page
.modified
));
684 htmlf("Expires: %s\n", http_date(ctx
.page
.expires
));
686 htmlf("ETag: \"%s\"\n", ctx
.page
.etag
);
688 if (ctx
.env
.request_method
&& !strcmp(ctx
.env
.request_method
, "HEAD"))
692 static void print_rel_vcs_link(const char *url
)
694 html("<link rel='vcs-git' href='");
697 html_attr(ctx
.repo
->name
);
698 html(" Git repository'/>\n");
701 void cgit_print_docstart(void)
703 if (ctx
.cfg
.embedded
) {
705 html_include(ctx
.cfg
.header
);
709 const char *host
= cgit_hosturl();
711 html("<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>\n");
714 html_txt(ctx
.page
.title
);
716 htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version
);
717 if (ctx
.cfg
.robots
&& *ctx
.cfg
.robots
)
718 htmlf("<meta name='robots' content='%s'/>\n", ctx
.cfg
.robots
);
719 html("<link rel='stylesheet' type='text/css' href='");
720 html_attr(ctx
.cfg
.css
);
722 if (ctx
.cfg
.favicon
) {
723 html("<link rel='shortcut icon' href='");
724 html_attr(ctx
.cfg
.favicon
);
727 if (host
&& ctx
.repo
&& ctx
.qry
.head
) {
728 struct strbuf sb
= STRBUF_INIT
;
729 strbuf_addf(&sb
, "h=%s", ctx
.qry
.head
);
731 html("<link rel='alternate' title='Atom feed' href='");
732 html(cgit_httpscheme());
733 html_attr(cgit_hosturl());
734 html_attr(cgit_fileurl(ctx
.repo
->url
, "atom", ctx
.qry
.vpath
,
736 html("' type='application/atom+xml'/>\n");
740 cgit_add_clone_urls(print_rel_vcs_link
);
741 if (ctx
.cfg
.head_include
)
742 html_include(ctx
.cfg
.head_include
);
746 html_include(ctx
.cfg
.header
);
749 void cgit_print_docend(void)
751 html("</div> <!-- class=content -->\n");
752 if (ctx
.cfg
.embedded
) {
753 html("</div> <!-- id=cgit -->\n");
755 html_include(ctx
.cfg
.footer
);
759 html_include(ctx
.cfg
.footer
);
761 htmlf("<div class='footer'>generated by <a href='http://git.zx2c4.com/cgit/about/'>cgit %s</a> at ",
763 cgit_print_date(time(NULL
), FMT_LONGDATE
, ctx
.cfg
.local_time
);
766 html("</div> <!-- id=cgit -->\n");
767 html("</body>\n</html>\n");
770 static void add_clone_urls(void (*fn
)(const char *), char *txt
, char *suffix
)
772 struct strbuf
**url_list
= strbuf_split_str(txt
, ' ', 0);
775 for (i
= 0; url_list
[i
]; i
++) {
776 strbuf_rtrim(url_list
[i
]);
777 if (url_list
[i
]->len
== 0)
779 if (suffix
&& *suffix
)
780 strbuf_addf(url_list
[i
], "/%s", suffix
);
781 fn(url_list
[i
]->buf
);
784 strbuf_list_free(url_list
);
787 void cgit_add_clone_urls(void (*fn
)(const char *))
789 if (ctx
.repo
->clone_url
)
790 add_clone_urls(fn
, expand_macros(ctx
.repo
->clone_url
), NULL
);
791 else if (ctx
.cfg
.clone_prefix
)
792 add_clone_urls(fn
, ctx
.cfg
.clone_prefix
, ctx
.repo
->url
);
795 static int print_branch_option(const char *refname
, const unsigned char *sha1
,
796 int flags
, void *cb_data
)
798 char *name
= (char *)refname
;
799 html_option(name
, name
, ctx
.qry
.head
);
803 void cgit_add_hidden_formfields(int incl_head
, int incl_search
,
806 if (!ctx
.cfg
.virtual_root
) {
807 struct strbuf url
= STRBUF_INIT
;
809 strbuf_addf(&url
, "%s/%s", ctx
.qry
.repo
, page
);
811 strbuf_addf(&url
, "/%s", ctx
.qry
.vpath
);
812 html_hidden("url", url
.buf
);
813 strbuf_release(&url
);
816 if (incl_head
&& ctx
.qry
.head
&& ctx
.repo
->defbranch
&&
817 strcmp(ctx
.qry
.head
, ctx
.repo
->defbranch
))
818 html_hidden("h", ctx
.qry
.head
);
821 html_hidden("id", ctx
.qry
.sha1
);
823 html_hidden("id2", ctx
.qry
.sha2
);
825 html_hidden("showmsg", "1");
829 html_hidden("qt", ctx
.qry
.grep
);
831 html_hidden("q", ctx
.qry
.search
);
835 static const char *hc(const char *page
)
837 return strcmp(ctx
.qry
.page
, page
) ? NULL
: "active";
840 static void cgit_print_path_crumbs(char *path
)
842 char *old_path
= ctx
.qry
.path
;
843 char *p
= path
, *q
, *end
= path
+ strlen(path
);
846 cgit_self_link("root", NULL
, NULL
);
847 ctx
.qry
.path
= p
= path
;
849 if (!(q
= strchr(p
, '/')))
853 cgit_self_link(p
, NULL
, NULL
);
858 ctx
.qry
.path
= old_path
;
861 static void print_header(void)
863 char *logo
= NULL
, *logo_link
= NULL
;
865 html("<table id='header'>\n");
868 if (ctx
.repo
&& ctx
.repo
->logo
&& *ctx
.repo
->logo
)
869 logo
= ctx
.repo
->logo
;
872 if (ctx
.repo
&& ctx
.repo
->logo_link
&& *ctx
.repo
->logo_link
)
873 logo_link
= ctx
.repo
->logo_link
;
875 logo_link
= ctx
.cfg
.logo_link
;
877 html("<td class='logo' rowspan='2'><a href='");
878 if (logo_link
&& *logo_link
)
879 html_attr(logo_link
);
881 html_attr(cgit_rooturl());
882 html("'><img src='");
884 html("' alt='cgit logo'/></a></td>\n");
887 html("<td class='main'>");
889 cgit_index_link("index", NULL
, NULL
, NULL
, NULL
, 0, 1);
891 cgit_summary_link(ctx
.repo
->name
, ctx
.repo
->name
, NULL
, NULL
);
892 if (ctx
.env
.authenticated
) {
893 html("</td><td class='form'>");
894 html("<form method='get' action=''>\n");
895 cgit_add_hidden_formfields(0, 1, ctx
.qry
.page
);
896 html("<select name='h' onchange='this.form.submit();'>\n");
897 for_each_branch_ref(print_branch_option
, ctx
.qry
.head
);
898 if (ctx
.repo
->enable_remote_branches
)
899 for_each_remote_ref(print_branch_option
, ctx
.qry
.head
);
901 html("<input type='submit' name='' value='switch'/>");
905 html_txt(ctx
.cfg
.root_title
);
906 html("</td></tr>\n");
908 html("<tr><td class='sub'>");
910 html_txt(ctx
.repo
->desc
);
911 html("</td><td class='sub right'>");
912 html_txt(ctx
.repo
->owner
);
914 if (ctx
.cfg
.root_desc
)
915 html_txt(ctx
.cfg
.root_desc
);
916 else if (ctx
.cfg
.index_info
)
917 html_include(ctx
.cfg
.index_info
);
919 html("</td></tr></table>\n");
922 void cgit_print_pageheader(void)
924 html("<div id='cgit'>");
925 if (!ctx
.env
.authenticated
|| !ctx
.cfg
.noheader
)
928 html("<table class='tabs'><tr><td>\n");
929 if (ctx
.env
.authenticated
&& ctx
.repo
) {
930 if (ctx
.repo
->readme
.nr
)
931 reporevlink("about", "about", NULL
,
932 hc("about"), ctx
.qry
.head
, NULL
,
934 cgit_summary_link("summary", NULL
, hc("summary"),
936 cgit_refs_link("refs", NULL
, hc("refs"), ctx
.qry
.head
,
938 cgit_log_link("log", NULL
, hc("log"), ctx
.qry
.head
,
939 NULL
, ctx
.qry
.vpath
, 0, NULL
, NULL
,
941 cgit_tree_link("tree", NULL
, hc("tree"), ctx
.qry
.head
,
942 ctx
.qry
.sha1
, ctx
.qry
.vpath
);
943 cgit_commit_link("commit", NULL
, hc("commit"),
944 ctx
.qry
.head
, ctx
.qry
.sha1
, ctx
.qry
.vpath
);
945 cgit_diff_link("diff", NULL
, hc("diff"), ctx
.qry
.head
,
946 ctx
.qry
.sha1
, ctx
.qry
.sha2
, ctx
.qry
.vpath
);
947 if (ctx
.repo
->max_stats
)
948 cgit_stats_link("stats", NULL
, hc("stats"),
949 ctx
.qry
.head
, ctx
.qry
.vpath
);
950 html("</td><td class='form'>");
951 html("<form class='right' method='get' action='");
952 if (ctx
.cfg
.virtual_root
)
953 html_url_path(cgit_fileurl(ctx
.qry
.repo
, "log",
954 ctx
.qry
.vpath
, NULL
));
956 cgit_add_hidden_formfields(1, 0, "log");
957 html("<select name='qt'>\n");
958 html_option("grep", "log msg", ctx
.qry
.grep
);
959 html_option("author", "author", ctx
.qry
.grep
);
960 html_option("committer", "committer", ctx
.qry
.grep
);
961 html_option("range", "range", ctx
.qry
.grep
);
963 html("<input class='txt' type='text' size='10' name='q' value='");
964 html_attr(ctx
.qry
.search
);
966 html("<input type='submit' value='search'/>\n");
968 } else if (ctx
.env
.authenticated
) {
969 site_link(NULL
, "index", NULL
, hc("repolist"), NULL
, NULL
, 0, 1);
970 if (ctx
.cfg
.root_readme
)
971 site_link("about", "about", NULL
, hc("about"),
973 html("</td><td class='form'>");
974 html("<form method='get' action='");
975 html_attr(cgit_currenturl());
977 html("<input type='text' name='q' size='10' value='");
978 html_attr(ctx
.qry
.search
);
980 html("<input type='submit' value='search'/>\n");
983 html("</td></tr></table>\n");
984 if (ctx
.env
.authenticated
&& ctx
.qry
.vpath
) {
985 html("<div class='path'>");
987 cgit_print_path_crumbs(ctx
.qry
.vpath
);
990 html("<div class='content'>");
993 void cgit_print_filemode(unsigned short mode
)
997 else if (S_ISLNK(mode
))
999 else if (S_ISGITLINK(mode
))
1003 html_fileperm(mode
>> 6);
1004 html_fileperm(mode
>> 3);
1005 html_fileperm(mode
);
1008 void cgit_print_snapshot_links(const char *repo
, const char *head
,
1009 const char *hex
, int snapshots
)
1011 const struct cgit_snapshot_format
* f
;
1012 struct strbuf filename
= STRBUF_INIT
;
1014 unsigned char sha1
[20];
1016 if (get_sha1(fmt("refs/tags/%s", hex
), sha1
) == 0 &&
1017 (hex
[0] == 'v' || hex
[0] == 'V') && isdigit(hex
[1]))
1019 strbuf_addf(&filename
, "%s-%s", cgit_repobasename(repo
), hex
);
1020 prefixlen
= filename
.len
;
1021 for (f
= cgit_snapshot_formats
; f
->suffix
; f
++) {
1022 if (!(snapshots
& f
->bit
))
1024 strbuf_setlen(&filename
, prefixlen
);
1025 strbuf_addstr(&filename
, f
->suffix
);
1026 cgit_snapshot_link(filename
.buf
, NULL
, NULL
, NULL
, NULL
,
1030 strbuf_release(&filename
);