]>
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();
75 const char *cgit_rooturl(void)
77 if (ctx
.cfg
.virtual_root
)
78 return ctx
.cfg
.virtual_root
;
80 return ctx
.cfg
.script_name
;
83 const char *cgit_loginurl(void)
85 static const char *login_url
= 0;
87 login_url
= fmtalloc("%s?p=login", cgit_rooturl());
91 char *cgit_repourl(const char *reponame
)
93 if (ctx
.cfg
.virtual_root
)
94 return fmtalloc("%s%s/", ctx
.cfg
.virtual_root
, reponame
);
96 return fmtalloc("?r=%s", reponame
);
99 char *cgit_fileurl(const char *reponame
, const char *pagename
,
100 const char *filename
, const char *query
)
102 struct strbuf sb
= STRBUF_INIT
;
105 if (ctx
.cfg
.virtual_root
) {
106 strbuf_addf(&sb
, "%s%s/%s/%s", ctx
.cfg
.virtual_root
, reponame
,
107 pagename
, (filename
? filename
:""));
110 strbuf_addf(&sb
, "?url=%s/%s/%s", reponame
, pagename
,
111 (filename
? filename
: ""));
115 strbuf_addf(&sb
, "%s%s", delim
, query
);
116 return strbuf_detach(&sb
, NULL
);
119 char *cgit_pageurl(const char *reponame
, const char *pagename
,
122 return cgit_fileurl(reponame
, pagename
, 0, query
);
125 const char *cgit_repobasename(const char *reponame
)
127 /* I assume we don't need to store more than one repo basename */
128 static char rvbuf
[1024];
131 strncpy(rvbuf
, reponame
, sizeof(rvbuf
));
132 if (rvbuf
[sizeof(rvbuf
)-1])
133 die("cgit_repobasename: truncated repository name '%s'", reponame
);
135 /* strip trailing slashes */
136 while (p
&& rvbuf
[p
] == '/') rvbuf
[p
--] = 0;
137 /* strip trailing .git */
138 if (p
>= 3 && starts_with(&rvbuf
[p
-3], ".git")) {
139 p
-= 3; rvbuf
[p
--] = 0;
141 /* strip more trailing slashes if any */
142 while ( p
&& rvbuf
[p
] == '/') rvbuf
[p
--] = 0;
143 /* find last slash in the remaining string */
144 rv
= strrchr(rvbuf
,'/');
150 static void site_url(const char *page
, const char *search
, const char *sort
, int ofs
, int always_root
)
154 if (always_root
|| page
)
155 html_attr(cgit_rooturl());
157 html_attr(cgit_currenturl());
160 htmlf("?p=%s", page
);
177 htmlf("ofs=%d", ofs
);
181 static void site_link(const char *page
, const char *name
, const char *title
,
182 const char *class, const char *search
, const char *sort
, int ofs
, int always_root
)
196 site_url(page
, search
, sort
, ofs
, always_root
);
202 void cgit_index_link(const char *name
, const char *title
, const char *class,
203 const char *pattern
, const char *sort
, int ofs
, int always_root
)
205 site_link(NULL
, name
, title
, class, pattern
, sort
, ofs
, always_root
);
208 static char *repolink(const char *title
, const char *class, const char *page
,
209 const char *head
, const char *path
)
225 if (ctx
.cfg
.virtual_root
) {
226 html_url_path(ctx
.cfg
.virtual_root
);
227 html_url_path(ctx
.repo
->url
);
228 if (ctx
.repo
->url
[strlen(ctx
.repo
->url
) - 1] != '/')
237 html_url_path(ctx
.cfg
.script_name
);
239 html_url_arg(ctx
.repo
->url
);
240 if (ctx
.repo
->url
[strlen(ctx
.repo
->url
) - 1] != '/')
250 if (head
&& strcmp(head
, ctx
.repo
->defbranch
)) {
256 return fmt("%s", delim
);
259 static void reporevlink(const char *page
, const char *name
, const char *title
,
260 const char *class, const char *head
, const char *rev
,
265 delim
= repolink(title
, class, page
, head
, path
);
266 if (rev
&& ctx
.qry
.head
!= NULL
&& strcmp(rev
, ctx
.qry
.head
)) {
276 void cgit_summary_link(const char *name
, const char *title
, const char *class,
279 reporevlink(NULL
, name
, title
, class, head
, NULL
, NULL
);
282 void cgit_tag_link(const char *name
, const char *title
, const char *class,
285 reporevlink("tag", name
, title
, class, tag
, NULL
, NULL
);
288 void cgit_tree_link(const char *name
, const char *title
, const char *class,
289 const char *head
, const char *rev
, const char *path
)
291 reporevlink("tree", name
, title
, class, head
, rev
, path
);
294 void cgit_plain_link(const char *name
, const char *title
, const char *class,
295 const char *head
, const char *rev
, const char *path
)
297 reporevlink("plain", name
, title
, class, head
, rev
, path
);
300 void cgit_log_link(const char *name
, const char *title
, const char *class,
301 const char *head
, const char *rev
, const char *path
,
302 int ofs
, const char *grep
, const char *pattern
, int showmsg
)
306 delim
= repolink(title
, class, "log", head
, path
);
307 if (rev
&& ctx
.qry
.head
&& strcmp(rev
, ctx
.qry
.head
)) {
313 if (grep
&& pattern
) {
320 html_url_arg(pattern
);
337 void cgit_commit_link(char *name
, const char *title
, const char *class,
338 const char *head
, const char *rev
, const char *path
)
340 if (strlen(name
) > ctx
.cfg
.max_msg_len
&& ctx
.cfg
.max_msg_len
>= 15) {
341 name
[ctx
.cfg
.max_msg_len
] = '\0';
342 name
[ctx
.cfg
.max_msg_len
- 1] = '.';
343 name
[ctx
.cfg
.max_msg_len
- 2] = '.';
344 name
[ctx
.cfg
.max_msg_len
- 3] = '.';
349 delim
= repolink(title
, class, "commit", head
, path
);
350 if (rev
&& ctx
.qry
.head
&& strcmp(rev
, ctx
.qry
.head
)) {
356 if (ctx
.qry
.difftype
) {
358 htmlf("dt=%d", ctx
.qry
.difftype
);
361 if (ctx
.qry
.context
> 0 && ctx
.qry
.context
!= 3) {
364 htmlf("%d", ctx
.qry
.context
);
367 if (ctx
.qry
.ignorews
) {
376 html_txt("(no commit message)");
380 void cgit_refs_link(const char *name
, const char *title
, const char *class,
381 const char *head
, const char *rev
, const char *path
)
383 reporevlink("refs", name
, title
, class, head
, rev
, path
);
386 void cgit_snapshot_link(const char *name
, const char *title
, const char *class,
387 const char *head
, const char *rev
,
388 const char *archivename
)
390 reporevlink("snapshot", name
, title
, class, head
, rev
, archivename
);
393 void cgit_diff_link(const char *name
, const char *title
, const char *class,
394 const char *head
, const char *new_rev
, const char *old_rev
,
399 delim
= repolink(title
, class, "diff", head
, path
);
400 if (new_rev
&& ctx
.qry
.head
!= NULL
&& strcmp(new_rev
, ctx
.qry
.head
)) {
403 html_url_arg(new_rev
);
409 html_url_arg(old_rev
);
412 if (ctx
.qry
.difftype
) {
414 htmlf("dt=%d", ctx
.qry
.difftype
);
417 if (ctx
.qry
.context
> 0 && ctx
.qry
.context
!= 3) {
420 htmlf("%d", ctx
.qry
.context
);
423 if (ctx
.qry
.ignorews
) {
433 void cgit_patch_link(const char *name
, const char *title
, const char *class,
434 const char *head
, const char *rev
, const char *path
)
436 reporevlink("patch", name
, title
, class, head
, rev
, path
);
439 void cgit_stats_link(const char *name
, const char *title
, const char *class,
440 const char *head
, const char *path
)
442 reporevlink("stats", name
, title
, class, head
, NULL
, path
);
445 static void cgit_self_link(char *name
, const char *title
, const char *class)
447 if (!strcmp(ctx
.qry
.page
, "repolist"))
448 cgit_index_link(name
, title
, class, ctx
.qry
.search
, ctx
.qry
.sort
,
450 else if (!strcmp(ctx
.qry
.page
, "summary"))
451 cgit_summary_link(name
, title
, class, ctx
.qry
.head
);
452 else if (!strcmp(ctx
.qry
.page
, "tag"))
453 cgit_tag_link(name
, title
, class, ctx
.qry
.has_sha1
?
454 ctx
.qry
.sha1
: ctx
.qry
.head
);
455 else if (!strcmp(ctx
.qry
.page
, "tree"))
456 cgit_tree_link(name
, title
, class, ctx
.qry
.head
,
457 ctx
.qry
.has_sha1
? ctx
.qry
.sha1
: NULL
,
459 else if (!strcmp(ctx
.qry
.page
, "plain"))
460 cgit_plain_link(name
, title
, class, ctx
.qry
.head
,
461 ctx
.qry
.has_sha1
? ctx
.qry
.sha1
: NULL
,
463 else if (!strcmp(ctx
.qry
.page
, "log"))
464 cgit_log_link(name
, title
, class, ctx
.qry
.head
,
465 ctx
.qry
.has_sha1
? ctx
.qry
.sha1
: NULL
,
466 ctx
.qry
.path
, ctx
.qry
.ofs
,
467 ctx
.qry
.grep
, ctx
.qry
.search
,
469 else if (!strcmp(ctx
.qry
.page
, "commit"))
470 cgit_commit_link(name
, title
, class, ctx
.qry
.head
,
471 ctx
.qry
.has_sha1
? ctx
.qry
.sha1
: NULL
,
473 else if (!strcmp(ctx
.qry
.page
, "patch"))
474 cgit_patch_link(name
, title
, class, ctx
.qry
.head
,
475 ctx
.qry
.has_sha1
? ctx
.qry
.sha1
: NULL
,
477 else if (!strcmp(ctx
.qry
.page
, "refs"))
478 cgit_refs_link(name
, title
, class, ctx
.qry
.head
,
479 ctx
.qry
.has_sha1
? ctx
.qry
.sha1
: NULL
,
481 else if (!strcmp(ctx
.qry
.page
, "snapshot"))
482 cgit_snapshot_link(name
, title
, class, ctx
.qry
.head
,
483 ctx
.qry
.has_sha1
? ctx
.qry
.sha1
: NULL
,
485 else if (!strcmp(ctx
.qry
.page
, "diff"))
486 cgit_diff_link(name
, title
, class, ctx
.qry
.head
,
487 ctx
.qry
.sha1
, ctx
.qry
.sha2
,
489 else if (!strcmp(ctx
.qry
.page
, "stats"))
490 cgit_stats_link(name
, title
, class, ctx
.qry
.head
,
493 /* Don't known how to make link for this page */
494 repolink(title
, class, ctx
.qry
.page
, ctx
.qry
.head
, ctx
.qry
.path
);
495 html("><!-- cgit_self_link() doesn't know how to make link for page '");
496 html_txt(ctx
.qry
.page
);
503 void cgit_object_link(struct object
*obj
)
505 char *page
, *shortrev
, *fullrev
, *name
;
507 fullrev
= sha1_to_hex(obj
->sha1
);
508 shortrev
= xstrdup(fullrev
);
510 if (obj
->type
== OBJ_COMMIT
) {
511 cgit_commit_link(fmt("commit %s...", shortrev
), NULL
, NULL
,
512 ctx
.qry
.head
, fullrev
, NULL
);
514 } else if (obj
->type
== OBJ_TREE
)
516 else if (obj
->type
== OBJ_TAG
)
520 name
= fmt("%s %s...", typename(obj
->type
), shortrev
);
521 reporevlink(page
, name
, NULL
, NULL
, ctx
.qry
.head
, fullrev
, NULL
);
524 static struct string_list_item
*lookup_path(struct string_list
*list
,
527 struct string_list_item
*item
;
529 while (path
&& path
[0]) {
530 if ((item
= string_list_lookup(list
, path
)))
532 if (!(path
= strchr(path
, '/')))
539 void cgit_submodule_link(const char *class, char *path
, const char *rev
)
541 struct string_list
*list
;
542 struct string_list_item
*item
;
548 list
= &ctx
.repo
->submodules
;
549 item
= lookup_path(list
, path
);
552 tail
= path
[len
- 1];
555 item
= lookup_path(list
, path
);
560 htmlf("class='%s' ", class);
563 html_attrf(item
->util
, rev
);
564 } else if (ctx
.repo
->module_link
) {
565 dir
= strrchr(path
, '/');
570 html_attrf(ctx
.repo
->module_link
, dir
, rev
);
577 html_txtf(" @ %.7s", rev
);
579 path
[len
- 1] = tail
;
582 void cgit_print_date(time_t secs
, const char *format
, int local_time
)
590 time
= localtime(&secs
);
592 time
= gmtime(&secs
);
593 strftime(buf
, sizeof(buf
)-1, format
, time
);
597 static void print_rel_date(time_t t
, double value
,
598 const char *class, const char *suffix
)
603 if (ctx
.cfg
.local_time
)
604 time
= localtime(&t
);
607 strftime(buf
, sizeof(buf
) - 1, FMT_LONGDATE
, time
);
609 htmlf("<span class='%s' title='", class);
611 htmlf("'>%.0f %s</span>", value
, suffix
);
614 void cgit_print_age(time_t t
, time_t max_relative
, const char *format
)
625 if (secs
> max_relative
&& max_relative
>= 0) {
626 cgit_print_date(t
, format
, ctx
.cfg
.local_time
);
630 if (secs
< TM_HOUR
* 2) {
631 print_rel_date(t
, secs
* 1.0 / TM_MIN
, "age-mins", "min.");
634 if (secs
< TM_DAY
* 2) {
635 print_rel_date(t
, secs
* 1.0 / TM_HOUR
, "age-hours", "hours");
638 if (secs
< TM_WEEK
* 2) {
639 print_rel_date(t
, secs
* 1.0 / TM_DAY
, "age-days", "days");
642 if (secs
< TM_MONTH
* 2) {
643 print_rel_date(t
, secs
* 1.0 / TM_WEEK
, "age-weeks", "weeks");
646 if (secs
< TM_YEAR
* 2) {
647 print_rel_date(t
, secs
* 1.0 / TM_MONTH
, "age-months", "months");
650 print_rel_date(t
, secs
* 1.0 / TM_YEAR
, "age-years", "years");
653 void cgit_print_http_headers(void)
655 if (ctx
.env
.no_http
&& !strcmp(ctx
.env
.no_http
, "1"))
659 htmlf("Status: %d %s\n", ctx
.page
.status
, ctx
.page
.statusmsg
);
660 if (ctx
.page
.mimetype
&& ctx
.page
.charset
)
661 htmlf("Content-Type: %s; charset=%s\n", ctx
.page
.mimetype
,
663 else if (ctx
.page
.mimetype
)
664 htmlf("Content-Type: %s\n", ctx
.page
.mimetype
);
666 htmlf("Content-Length: %zd\n", ctx
.page
.size
);
667 if (ctx
.page
.filename
)
668 htmlf("Content-Disposition: inline; filename=\"%s\"\n",
670 if (!ctx
.env
.authenticated
)
671 html("Cache-Control: no-cache, no-store\n");
672 htmlf("Last-Modified: %s\n", http_date(ctx
.page
.modified
));
673 htmlf("Expires: %s\n", http_date(ctx
.page
.expires
));
675 htmlf("ETag: \"%s\"\n", ctx
.page
.etag
);
677 if (ctx
.env
.request_method
&& !strcmp(ctx
.env
.request_method
, "HEAD"))
681 static void print_rel_vcs_link(const char *url
)
683 html("<link rel='vcs-git' href='");
686 html_attr(ctx
.repo
->name
);
687 html(" Git repository'/>\n");
690 void cgit_print_docstart(void)
692 if (ctx
.cfg
.embedded
) {
694 html_include(ctx
.cfg
.header
);
698 const char *host
= cgit_hosturl();
700 html("<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>\n");
703 html_txt(ctx
.page
.title
);
705 htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version
);
706 if (ctx
.cfg
.robots
&& *ctx
.cfg
.robots
)
707 htmlf("<meta name='robots' content='%s'/>\n", ctx
.cfg
.robots
);
708 html("<link rel='stylesheet' type='text/css' href='");
709 html_attr(ctx
.cfg
.css
);
711 if (ctx
.cfg
.favicon
) {
712 html("<link rel='shortcut icon' href='");
713 html_attr(ctx
.cfg
.favicon
);
716 if (host
&& ctx
.repo
&& ctx
.qry
.head
) {
717 struct strbuf sb
= STRBUF_INIT
;
718 strbuf_addf(&sb
, "h=%s", ctx
.qry
.head
);
720 html("<link rel='alternate' title='Atom feed' href='");
721 html(cgit_httpscheme());
722 html_attr(cgit_hosturl());
723 html_attr(cgit_fileurl(ctx
.repo
->url
, "atom", ctx
.qry
.vpath
,
725 html("' type='application/atom+xml'/>\n");
729 cgit_add_clone_urls(print_rel_vcs_link
);
730 if (ctx
.cfg
.head_include
)
731 html_include(ctx
.cfg
.head_include
);
735 html_include(ctx
.cfg
.header
);
738 void cgit_print_docend(void)
740 html("</div> <!-- class=content -->\n");
741 if (ctx
.cfg
.embedded
) {
742 html("</div> <!-- id=cgit -->\n");
744 html_include(ctx
.cfg
.footer
);
748 html_include(ctx
.cfg
.footer
);
750 htmlf("<div class='footer'>generated by <a href='http://git.zx2c4.com/cgit/about/'>cgit %s</a> at ",
752 cgit_print_date(time(NULL
), FMT_LONGDATE
, ctx
.cfg
.local_time
);
755 html("</div> <!-- id=cgit -->\n");
756 html("</body>\n</html>\n");
759 static void add_clone_urls(void (*fn
)(const char *), char *txt
, char *suffix
)
761 struct strbuf
**url_list
= strbuf_split_str(txt
, ' ', 0);
764 for (i
= 0; url_list
[i
]; i
++) {
765 strbuf_rtrim(url_list
[i
]);
766 if (url_list
[i
]->len
== 0)
768 if (suffix
&& *suffix
)
769 strbuf_addf(url_list
[i
], "/%s", suffix
);
770 fn(url_list
[i
]->buf
);
773 strbuf_list_free(url_list
);
776 void cgit_add_clone_urls(void (*fn
)(const char *))
778 if (ctx
.repo
->clone_url
)
779 add_clone_urls(fn
, expand_macros(ctx
.repo
->clone_url
), NULL
);
780 else if (ctx
.cfg
.clone_prefix
)
781 add_clone_urls(fn
, ctx
.cfg
.clone_prefix
, ctx
.repo
->url
);
784 static int print_branch_option(const char *refname
, const unsigned char *sha1
,
785 int flags
, void *cb_data
)
787 char *name
= (char *)refname
;
788 html_option(name
, name
, ctx
.qry
.head
);
792 void cgit_add_hidden_formfields(int incl_head
, int incl_search
,
795 if (!ctx
.cfg
.virtual_root
) {
796 struct strbuf url
= STRBUF_INIT
;
798 strbuf_addf(&url
, "%s/%s", ctx
.qry
.repo
, page
);
800 strbuf_addf(&url
, "/%s", ctx
.qry
.vpath
);
801 html_hidden("url", url
.buf
);
802 strbuf_release(&url
);
805 if (incl_head
&& ctx
.qry
.head
&& ctx
.repo
->defbranch
&&
806 strcmp(ctx
.qry
.head
, ctx
.repo
->defbranch
))
807 html_hidden("h", ctx
.qry
.head
);
810 html_hidden("id", ctx
.qry
.sha1
);
812 html_hidden("id2", ctx
.qry
.sha2
);
814 html_hidden("showmsg", "1");
818 html_hidden("qt", ctx
.qry
.grep
);
820 html_hidden("q", ctx
.qry
.search
);
824 static const char *hc(const char *page
)
826 return strcmp(ctx
.qry
.page
, page
) ? NULL
: "active";
829 static void cgit_print_path_crumbs(char *path
)
831 char *old_path
= ctx
.qry
.path
;
832 char *p
= path
, *q
, *end
= path
+ strlen(path
);
835 cgit_self_link("root", NULL
, NULL
);
836 ctx
.qry
.path
= p
= path
;
838 if (!(q
= strchr(p
, '/')))
842 cgit_self_link(p
, NULL
, NULL
);
847 ctx
.qry
.path
= old_path
;
850 static void print_header(void)
852 char *logo
= NULL
, *logo_link
= NULL
;
854 html("<table id='header'>\n");
857 if (ctx
.repo
&& ctx
.repo
->logo
&& *ctx
.repo
->logo
)
858 logo
= ctx
.repo
->logo
;
861 if (ctx
.repo
&& ctx
.repo
->logo_link
&& *ctx
.repo
->logo_link
)
862 logo_link
= ctx
.repo
->logo_link
;
864 logo_link
= ctx
.cfg
.logo_link
;
866 html("<td class='logo' rowspan='2'><a href='");
867 if (logo_link
&& *logo_link
)
868 html_attr(logo_link
);
870 html_attr(cgit_rooturl());
871 html("'><img src='");
873 html("' alt='cgit logo'/></a></td>\n");
876 html("<td class='main'>");
878 cgit_index_link("index", NULL
, NULL
, NULL
, NULL
, 0, 1);
880 cgit_summary_link(ctx
.repo
->name
, ctx
.repo
->name
, NULL
, NULL
);
881 if (ctx
.env
.authenticated
) {
882 html("</td><td class='form'>");
883 html("<form method='get' action=''>\n");
884 cgit_add_hidden_formfields(0, 1, ctx
.qry
.page
);
885 html("<select name='h' onchange='this.form.submit();'>\n");
886 for_each_branch_ref(print_branch_option
, ctx
.qry
.head
);
888 html("<input type='submit' name='' value='switch'/>");
892 html_txt(ctx
.cfg
.root_title
);
893 html("</td></tr>\n");
895 html("<tr><td class='sub'>");
897 html_txt(ctx
.repo
->desc
);
898 html("</td><td class='sub right'>");
899 html_txt(ctx
.repo
->owner
);
901 if (ctx
.cfg
.root_desc
)
902 html_txt(ctx
.cfg
.root_desc
);
903 else if (ctx
.cfg
.index_info
)
904 html_include(ctx
.cfg
.index_info
);
906 html("</td></tr></table>\n");
909 void cgit_print_pageheader(void)
911 html("<div id='cgit'>");
912 if (!ctx
.env
.authenticated
|| !ctx
.cfg
.noheader
)
915 html("<table class='tabs'><tr><td>\n");
916 if (ctx
.env
.authenticated
&& ctx
.repo
) {
917 if (ctx
.repo
->readme
.nr
)
918 reporevlink("about", "about", NULL
,
919 hc("about"), ctx
.qry
.head
, NULL
,
921 cgit_summary_link("summary", NULL
, hc("summary"),
923 cgit_refs_link("refs", NULL
, hc("refs"), ctx
.qry
.head
,
925 cgit_log_link("log", NULL
, hc("log"), ctx
.qry
.head
,
926 NULL
, ctx
.qry
.vpath
, 0, NULL
, NULL
,
928 cgit_tree_link("tree", NULL
, hc("tree"), ctx
.qry
.head
,
929 ctx
.qry
.sha1
, ctx
.qry
.vpath
);
930 cgit_commit_link("commit", NULL
, hc("commit"),
931 ctx
.qry
.head
, ctx
.qry
.sha1
, ctx
.qry
.vpath
);
932 cgit_diff_link("diff", NULL
, hc("diff"), ctx
.qry
.head
,
933 ctx
.qry
.sha1
, ctx
.qry
.sha2
, ctx
.qry
.vpath
);
934 if (ctx
.repo
->max_stats
)
935 cgit_stats_link("stats", NULL
, hc("stats"),
936 ctx
.qry
.head
, ctx
.qry
.vpath
);
937 html("</td><td class='form'>");
938 html("<form class='right' method='get' action='");
939 if (ctx
.cfg
.virtual_root
)
940 html_url_path(cgit_fileurl(ctx
.qry
.repo
, "log",
941 ctx
.qry
.vpath
, NULL
));
943 cgit_add_hidden_formfields(1, 0, "log");
944 html("<select name='qt'>\n");
945 html_option("grep", "log msg", ctx
.qry
.grep
);
946 html_option("author", "author", ctx
.qry
.grep
);
947 html_option("committer", "committer", ctx
.qry
.grep
);
948 html_option("range", "range", ctx
.qry
.grep
);
950 html("<input class='txt' type='text' size='10' name='q' value='");
951 html_attr(ctx
.qry
.search
);
953 html("<input type='submit' value='search'/>\n");
955 } else if (ctx
.env
.authenticated
) {
956 site_link(NULL
, "index", NULL
, hc("repolist"), NULL
, NULL
, 0, 1);
957 if (ctx
.cfg
.root_readme
)
958 site_link("about", "about", NULL
, hc("about"),
960 html("</td><td class='form'>");
961 html("<form method='get' action='");
962 html_attr(cgit_currenturl());
964 html("<input type='text' name='q' size='10' value='");
965 html_attr(ctx
.qry
.search
);
967 html("<input type='submit' value='search'/>\n");
970 html("</td></tr></table>\n");
971 if (ctx
.env
.authenticated
&& ctx
.qry
.vpath
) {
972 html("<div class='path'>");
974 cgit_print_path_crumbs(ctx
.qry
.vpath
);
977 html("<div class='content'>");
980 void cgit_print_filemode(unsigned short mode
)
984 else if (S_ISLNK(mode
))
986 else if (S_ISGITLINK(mode
))
990 html_fileperm(mode
>> 6);
991 html_fileperm(mode
>> 3);
995 void cgit_print_snapshot_links(const char *repo
, const char *head
,
996 const char *hex
, int snapshots
)
998 const struct cgit_snapshot_format
* f
;
999 struct strbuf filename
= STRBUF_INIT
;
1001 unsigned char sha1
[20];
1003 if (get_sha1(fmt("refs/tags/%s", hex
), sha1
) == 0 &&
1004 (hex
[0] == 'v' || hex
[0] == 'V') && isdigit(hex
[1]))
1006 strbuf_addf(&filename
, "%s-%s", cgit_repobasename(repo
), hex
);
1007 prefixlen
= filename
.len
;
1008 for (f
= cgit_snapshot_formats
; f
->suffix
; f
++) {
1009 if (!(snapshots
& f
->bit
))
1011 strbuf_setlen(&filename
, prefixlen
);
1012 strbuf_addstr(&filename
, f
->suffix
);
1013 cgit_snapshot_link(filename
.buf
, NULL
, NULL
, NULL
, NULL
,
1017 strbuf_release(&filename
);