summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--cgit.c4
-rw-r--r--cgit.css5
-rw-r--r--cgit.h4
-rw-r--r--html.c10
-rw-r--r--shared.c3
-rw-r--r--ui-repolist.c2
-rw-r--r--ui-shared.c28
7 files changed, 51 insertions, 5 deletions
diff --git a/cgit.c b/cgit.c
index ac43441..277b849 100644
--- a/cgit.c
+++ b/cgit.c
@@ -7,34 +7,34 @@
7 */ 7 */
8 8
9#include "cgit.h" 9#include "cgit.h"
10 10
11const char cgit_version[] = CGIT_VERSION; 11const char cgit_version[] = CGIT_VERSION;
12 12
13static void cgit_print_repo_page(struct cacheitem *item) 13static void cgit_print_repo_page(struct cacheitem *item)
14{ 14{
15 if (chdir(fmt("%s/%s", cgit_root, cgit_query_repo)) || 15 if (chdir(fmt("%s/%s", cgit_root, cgit_query_repo)) ||
16 cgit_read_config("info/cgit", cgit_repo_config_cb)) { 16 cgit_read_config("info/cgit", cgit_repo_config_cb)) {
17 char *title = fmt("%s - %s", cgit_root_title, "Bad request"); 17 char *title = fmt("%s - %s", cgit_root_title, "Bad request");
18 cgit_print_docstart(title, item); 18 cgit_print_docstart(title, item);
19 cgit_print_pageheader(title); 19 cgit_print_pageheader(title, 0);
20 cgit_print_error(fmt("Unable to scan repository: %s", 20 cgit_print_error(fmt("Unable to scan repository: %s",
21 strerror(errno))); 21 strerror(errno)));
22 cgit_print_docend(); 22 cgit_print_docend();
23 return; 23 return;
24 } 24 }
25 setenv("GIT_DIR", fmt("%s/%s", cgit_root, cgit_query_repo), 1); 25 setenv("GIT_DIR", fmt("%s/%s", cgit_root, cgit_query_repo), 1);
26 char *title = fmt("%s - %s", cgit_repo_name, cgit_repo_desc); 26 char *title = fmt("%s - %s", cgit_repo_name, cgit_repo_desc);
27 cgit_print_docstart(title, item); 27 cgit_print_docstart(title, item);
28 cgit_print_pageheader(title); 28 cgit_print_pageheader(title, 0);
29 if (!cgit_query_page) { 29 if (!cgit_query_page) {
30 cgit_print_summary(); 30 cgit_print_summary();
31 } else if (!strcmp(cgit_query_page, "log")) { 31 } else if (!strcmp(cgit_query_page, "log")) {
32 cgit_print_log(cgit_query_head, cgit_query_ofs, 100); 32 cgit_print_log(cgit_query_head, cgit_query_ofs, 100);
33 } else if (!strcmp(cgit_query_page, "tree")) { 33 } else if (!strcmp(cgit_query_page, "tree")) {
34 cgit_print_tree(cgit_query_sha1); 34 cgit_print_tree(cgit_query_sha1);
35 } else if (!strcmp(cgit_query_page, "commit")) { 35 } else if (!strcmp(cgit_query_page, "commit")) {
36 cgit_print_commit(cgit_query_sha1); 36 cgit_print_commit(cgit_query_sha1);
37 } else if (!strcmp(cgit_query_page, "view")) { 37 } else if (!strcmp(cgit_query_page, "view")) {
38 cgit_print_view(cgit_query_sha1); 38 cgit_print_view(cgit_query_sha1);
39 } else if (!strcmp(cgit_query_page, "diff")) { 39 } else if (!strcmp(cgit_query_page, "diff")) {
40 cgit_print_diff(cgit_query_sha1, cgit_query_sha2); 40 cgit_print_diff(cgit_query_sha1, cgit_query_sha2);
diff --git a/cgit.css b/cgit.css
index 459dca7..9112bfe 100644
--- a/cgit.css
+++ b/cgit.css
@@ -52,24 +52,29 @@ img {
52div#header { 52div#header {
53 background-color: #ddd; 53 background-color: #ddd;
54 padding: 0.25em 0.25em 0.25em 0.5em; 54 padding: 0.25em 0.25em 0.25em 0.5em;
55 font-size: 150%; 55 font-size: 150%;
56 font-weight: bold; 56 font-weight: bold;
57 border: solid 1px #aaa; 57 border: solid 1px #aaa;
58 vertical-align: middle; 58 vertical-align: middle;
59 margin-bottom: 2em; 59 margin-bottom: 2em;
60} 60}
61div#header img#logo { 61div#header img#logo {
62 float: right; 62 float: right;
63} 63}
64
65div#header input {
66 float: right;
67 margin: 0.25em 1em;
68}
64div#header a { 69div#header a {
65 color: black; 70 color: black;
66} 71}
67 72
68div#content { 73div#content {
69 margin: 0.5em 0.5em; 74 margin: 0.5em 0.5em;
70} 75}
71 76
72div#blob { 77div#blob {
73 border: solid 1px black; 78 border: solid 1px black;
74} 79}
75 80
diff --git a/cgit.h b/cgit.h
index 362b435..e114a50 100644
--- a/cgit.h
+++ b/cgit.h
@@ -46,66 +46,68 @@ extern int cgit_cache_static_ttl;
46extern int cgit_cache_max_create_time; 46extern int cgit_cache_max_create_time;
47 47
48extern char *cgit_repo_name; 48extern char *cgit_repo_name;
49extern char *cgit_repo_desc; 49extern char *cgit_repo_desc;
50extern char *cgit_repo_owner; 50extern char *cgit_repo_owner;
51 51
52extern int cgit_query_has_symref; 52extern int cgit_query_has_symref;
53extern int cgit_query_has_sha1; 53extern int cgit_query_has_sha1;
54 54
55extern char *cgit_querystring; 55extern char *cgit_querystring;
56extern char *cgit_query_repo; 56extern char *cgit_query_repo;
57extern char *cgit_query_page; 57extern char *cgit_query_page;
58extern char *cgit_query_search;
58extern char *cgit_query_head; 59extern char *cgit_query_head;
59extern char *cgit_query_sha1; 60extern char *cgit_query_sha1;
60extern char *cgit_query_sha2; 61extern char *cgit_query_sha2;
61extern int cgit_query_ofs; 62extern int cgit_query_ofs;
62 63
63extern int htmlfd; 64extern int htmlfd;
64 65
65extern void cgit_global_config_cb(const char *name, const char *value); 66extern void cgit_global_config_cb(const char *name, const char *value);
66extern void cgit_repo_config_cb(const char *name, const char *value); 67extern void cgit_repo_config_cb(const char *name, const char *value);
67extern void cgit_querystring_cb(const char *name, const char *value); 68extern void cgit_querystring_cb(const char *name, const char *value);
68 69
69extern void *cgit_free_commitinfo(struct commitinfo *info); 70extern void *cgit_free_commitinfo(struct commitinfo *info);
70 71
71extern char *fmt(const char *format,...); 72extern char *fmt(const char *format,...);
72 73
73extern void html(const char *txt); 74extern void html(const char *txt);
74extern void htmlf(const char *format,...); 75extern void htmlf(const char *format,...);
75extern void html_txt(char *txt); 76extern void html_txt(char *txt);
76extern void html_ntxt(int len, char *txt); 77extern void html_ntxt(int len, char *txt);
77extern void html_attr(char *txt); 78extern void html_attr(char *txt);
79extern void html_hidden(char *name, char *value);
78extern void html_link_open(char *url, char *title, char *class); 80extern void html_link_open(char *url, char *title, char *class);
79extern void html_link_close(void); 81extern void html_link_close(void);
80extern void html_filemode(unsigned short mode); 82extern void html_filemode(unsigned short mode);
81 83
82extern int cgit_read_config(const char *filename, configfn fn); 84extern int cgit_read_config(const char *filename, configfn fn);
83extern int cgit_parse_query(char *txt, configfn fn); 85extern int cgit_parse_query(char *txt, configfn fn);
84extern struct commitinfo *cgit_parse_commit(struct commit *commit); 86extern struct commitinfo *cgit_parse_commit(struct commit *commit);
85 87
86extern void cache_prepare(struct cacheitem *item); 88extern void cache_prepare(struct cacheitem *item);
87extern int cache_lock(struct cacheitem *item); 89extern int cache_lock(struct cacheitem *item);
88extern int cache_unlock(struct cacheitem *item); 90extern int cache_unlock(struct cacheitem *item);
89extern int cache_cancel_lock(struct cacheitem *item); 91extern int cache_cancel_lock(struct cacheitem *item);
90extern int cache_exist(struct cacheitem *item); 92extern int cache_exist(struct cacheitem *item);
91extern int cache_expired(struct cacheitem *item); 93extern int cache_expired(struct cacheitem *item);
92 94
93extern char *cgit_repourl(const char *reponame); 95extern char *cgit_repourl(const char *reponame);
94extern char *cgit_pageurl(const char *reponame, const char *pagename, 96extern char *cgit_pageurl(const char *reponame, const char *pagename,
95 const char *query); 97 const char *query);
96 98
97extern void cgit_print_error(char *msg); 99extern void cgit_print_error(char *msg);
98extern void cgit_print_date(unsigned long secs); 100extern void cgit_print_date(unsigned long secs);
99extern void cgit_print_docstart(char *title, struct cacheitem *item); 101extern void cgit_print_docstart(char *title, struct cacheitem *item);
100extern void cgit_print_docend(); 102extern void cgit_print_docend();
101extern void cgit_print_pageheader(char *title); 103extern void cgit_print_pageheader(char *title, int show_search);
102 104
103extern void cgit_print_repolist(struct cacheitem *item); 105extern void cgit_print_repolist(struct cacheitem *item);
104extern void cgit_print_summary(); 106extern void cgit_print_summary();
105extern void cgit_print_log(const char *tip, int ofs, int cnt); 107extern void cgit_print_log(const char *tip, int ofs, int cnt);
106extern void cgit_print_view(const char *hex); 108extern void cgit_print_view(const char *hex);
107extern void cgit_print_tree(const char *hex); 109extern void cgit_print_tree(const char *hex);
108extern void cgit_print_commit(const char *hex); 110extern void cgit_print_commit(const char *hex);
109extern void cgit_print_diff(const char *old_hex, const char *new_hex); 111extern void cgit_print_diff(const char *old_hex, const char *new_hex);
110 112
111#endif /* CGIT_H */ 113#endif /* CGIT_H */
diff --git a/html.c b/html.c
index 3a5d28d..c0b2ed4 100644
--- a/html.c
+++ b/html.c
@@ -108,24 +108,33 @@ void html_attr(char *txt)
108 else if (c=='<') 108 else if (c=='<')
109 html("&lt;"); 109 html("&lt;");
110 else if (c=='\'') 110 else if (c=='\'')
111 html("&quote;"); 111 html("&quote;");
112 txt = t+1; 112 txt = t+1;
113 } 113 }
114 t++; 114 t++;
115 } 115 }
116 if (t!=txt) 116 if (t!=txt)
117 html(txt); 117 html(txt);
118} 118}
119 119
120void html_hidden(char *name, char *value)
121{
122 html("<input type='hidden' name='");
123 html_attr(name);
124 html("' value='");
125 html_attr(value);
126 html("'/>");
127}
128
120void html_link_open(char *url, char *title, char *class) 129void html_link_open(char *url, char *title, char *class)
121{ 130{
122 html("<a href='"); 131 html("<a href='");
123 html_attr(url); 132 html_attr(url);
124 if (title) { 133 if (title) {
125 html("' title='"); 134 html("' title='");
126 html_attr(title); 135 html_attr(title);
127 } 136 }
128 if (class) { 137 if (class) {
129 html("' class='"); 138 html("' class='");
130 html_attr(class); 139 html_attr(class);
131 } 140 }
@@ -146,12 +155,13 @@ void html_fileperm(unsigned short mode)
146void html_filemode(unsigned short mode) 155void html_filemode(unsigned short mode)
147{ 156{
148 if (S_ISDIR(mode)) 157 if (S_ISDIR(mode))
149 html("d"); 158 html("d");
150 else if (S_ISLNK(mode)) 159 else if (S_ISLNK(mode))
151 html("l"); 160 html("l");
152 else 161 else
153 html("-"); 162 html("-");
154 html_fileperm(mode >> 6); 163 html_fileperm(mode >> 6);
155 html_fileperm(mode >> 3); 164 html_fileperm(mode >> 3);
156 html_fileperm(mode); 165 html_fileperm(mode);
157} 166}
167
diff --git a/shared.c b/shared.c
index 18b795b..7def51a 100644
--- a/shared.c
+++ b/shared.c
@@ -27,24 +27,25 @@ int cgit_cache_max_create_time = 5;
27 27
28char *cgit_repo_name = NULL; 28char *cgit_repo_name = NULL;
29char *cgit_repo_desc = NULL; 29char *cgit_repo_desc = NULL;
30char *cgit_repo_owner = NULL; 30char *cgit_repo_owner = NULL;
31 31
32int cgit_query_has_symref = 0; 32int cgit_query_has_symref = 0;
33int cgit_query_has_sha1 = 0; 33int cgit_query_has_sha1 = 0;
34 34
35char *cgit_querystring = NULL; 35char *cgit_querystring = NULL;
36char *cgit_query_repo = NULL; 36char *cgit_query_repo = NULL;
37char *cgit_query_page = NULL; 37char *cgit_query_page = NULL;
38char *cgit_query_head = NULL; 38char *cgit_query_head = NULL;
39char *cgit_query_search = NULL;
39char *cgit_query_sha1 = NULL; 40char *cgit_query_sha1 = NULL;
40char *cgit_query_sha2 = NULL; 41char *cgit_query_sha2 = NULL;
41int cgit_query_ofs = 0; 42int cgit_query_ofs = 0;
42 43
43int htmlfd = 0; 44int htmlfd = 0;
44 45
45void cgit_global_config_cb(const char *name, const char *value) 46void cgit_global_config_cb(const char *name, const char *value)
46{ 47{
47 if (!strcmp(name, "root")) 48 if (!strcmp(name, "root"))
48 cgit_root = xstrdup(value); 49 cgit_root = xstrdup(value);
49 else if (!strcmp(name, "root-title")) 50 else if (!strcmp(name, "root-title"))
50 cgit_root_title = xstrdup(value); 51 cgit_root_title = xstrdup(value);
@@ -77,24 +78,26 @@ void cgit_repo_config_cb(const char *name, const char *value)
77 else if (!strcmp(name, "desc")) 78 else if (!strcmp(name, "desc"))
78 cgit_repo_desc = xstrdup(value); 79 cgit_repo_desc = xstrdup(value);
79 else if (!strcmp(name, "owner")) 80 else if (!strcmp(name, "owner"))
80 cgit_repo_owner = xstrdup(value); 81 cgit_repo_owner = xstrdup(value);
81} 82}
82 83
83void cgit_querystring_cb(const char *name, const char *value) 84void cgit_querystring_cb(const char *name, const char *value)
84{ 85{
85 if (!strcmp(name,"r")) { 86 if (!strcmp(name,"r")) {
86 cgit_query_repo = xstrdup(value); 87 cgit_query_repo = xstrdup(value);
87 } else if (!strcmp(name, "p")) { 88 } else if (!strcmp(name, "p")) {
88 cgit_query_page = xstrdup(value); 89 cgit_query_page = xstrdup(value);
90 } else if (!strcmp(name, "q")) {
91 cgit_query_search = xstrdup(value);
89 } else if (!strcmp(name, "h")) { 92 } else if (!strcmp(name, "h")) {
90 cgit_query_head = xstrdup(value); 93 cgit_query_head = xstrdup(value);
91 cgit_query_has_symref = 1; 94 cgit_query_has_symref = 1;
92 } else if (!strcmp(name, "id")) { 95 } else if (!strcmp(name, "id")) {
93 cgit_query_sha1 = xstrdup(value); 96 cgit_query_sha1 = xstrdup(value);
94 cgit_query_has_sha1 = 1; 97 cgit_query_has_sha1 = 1;
95 } else if (!strcmp(name, "id2")) { 98 } else if (!strcmp(name, "id2")) {
96 cgit_query_sha2 = xstrdup(value); 99 cgit_query_sha2 = xstrdup(value);
97 cgit_query_has_sha1 = 1; 100 cgit_query_has_sha1 = 1;
98 } else if (!strcmp(name, "ofs")) { 101 } else if (!strcmp(name, "ofs")) {
99 cgit_query_ofs = atoi(value); 102 cgit_query_ofs = atoi(value);
100 } 103 }
diff --git a/ui-repolist.c b/ui-repolist.c
index 7090c12..9f12b18 100644
--- a/ui-repolist.c
+++ b/ui-repolist.c
@@ -8,25 +8,25 @@
8 8
9#include "cgit.h" 9#include "cgit.h"
10 10
11void cgit_print_repolist(struct cacheitem *item) 11void cgit_print_repolist(struct cacheitem *item)
12{ 12{
13 DIR *d; 13 DIR *d;
14 struct dirent *de; 14 struct dirent *de;
15 struct stat st; 15 struct stat st;
16 char *name; 16 char *name;
17 17
18 chdir(cgit_root); 18 chdir(cgit_root);
19 cgit_print_docstart(cgit_root_title, item); 19 cgit_print_docstart(cgit_root_title, item);
20 cgit_print_pageheader(cgit_root_title); 20 cgit_print_pageheader(cgit_root_title, 0);
21 21
22 if (!(d = opendir("."))) { 22 if (!(d = opendir("."))) {
23 cgit_print_error(fmt("Unable to scan repository directory: %s", 23 cgit_print_error(fmt("Unable to scan repository directory: %s",
24 strerror(errno))); 24 strerror(errno)));
25 cgit_print_docend(); 25 cgit_print_docend();
26 return; 26 return;
27 } 27 }
28 28
29 html("<h2>Repositories</h2>\n"); 29 html("<h2>Repositories</h2>\n");
30 html("<table class='list nowrap'>"); 30 html("<table class='list nowrap'>");
31 html("<tr>" 31 html("<tr>"
32 "<th class='left'>Name</th>" 32 "<th class='left'>Name</th>"
diff --git a/ui-shared.c b/ui-shared.c
index 9ec4be8..b9c1243 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -51,24 +51,36 @@ char *cgit_repourl(const char *reponame)
51 51
52char *cgit_pageurl(const char *reponame, const char *pagename, 52char *cgit_pageurl(const char *reponame, const char *pagename,
53 const char *query) 53 const char *query)
54{ 54{
55 if (cgit_virtual_root) { 55 if (cgit_virtual_root) {
56 return fmt("%s/%s/%s/?%s", cgit_virtual_root, reponame, 56 return fmt("%s/%s/%s/?%s", cgit_virtual_root, reponame,
57 pagename, query); 57 pagename, query);
58 } else { 58 } else {
59 return fmt("?r=%s&p=%s&%s", reponame, pagename, query); 59 return fmt("?r=%s&p=%s&%s", reponame, pagename, query);
60 } 60 }
61} 61}
62 62
63char *cgit_currurl()
64{
65 if (!cgit_virtual_root)
66 return "./cgit.cgi";
67 else if (cgit_query_page)
68 return fmt("%s/%s/%s/", cgit_virtual_root, cgit_query_repo, cgit_query_page);
69 else if (cgit_query_repo)
70 return fmt("%s/%s/", cgit_virtual_root, cgit_query_repo);
71 else
72 return fmt("%s/", cgit_virtual_root);
73}
74
63 75
64void cgit_print_date(unsigned long secs) 76void cgit_print_date(unsigned long secs)
65{ 77{
66 char buf[32]; 78 char buf[32];
67 struct tm *time; 79 struct tm *time;
68 80
69 time = gmtime(&secs); 81 time = gmtime(&secs);
70 strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", time); 82 strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", time);
71 html_txt(buf); 83 html_txt(buf);
72 84
73} 85}
74 86
@@ -89,25 +101,39 @@ void cgit_print_docstart(char *title, struct cacheitem *item)
89 html("<link rel='stylesheet' type='text/css' href='"); 101 html("<link rel='stylesheet' type='text/css' href='");
90 html_attr(cgit_css); 102 html_attr(cgit_css);
91 html("'/>\n"); 103 html("'/>\n");
92 html("</head>\n"); 104 html("</head>\n");
93 html("<body>\n"); 105 html("<body>\n");
94} 106}
95 107
96void cgit_print_docend() 108void cgit_print_docend()
97{ 109{
98 html("</body>\n</html>\n"); 110 html("</body>\n</html>\n");
99} 111}
100 112
101void cgit_print_pageheader(char *title) 113void cgit_print_pageheader(char *title, int show_search)
102{ 114{
103 html("<div id='header'>"); 115 html("<div id='header'>");
104 htmlf("<a href='%s'>", cgit_logo_link); 116 htmlf("<a href='%s'>", cgit_logo_link);
105 htmlf("<img id='logo' src='%s'/>\n", cgit_logo); 117 htmlf("<img id='logo' src='%s'/>\n", cgit_logo);
106 htmlf("</a>"); 118 htmlf("</a>");
119 if (show_search) {
120 html("<form method='get' href='");
121 html_attr(cgit_currurl());
122 html("'>");
123 if (cgit_query_head)
124 html_hidden("h", cgit_query_head);
125 if (cgit_query_sha1)
126 html_hidden("id", cgit_query_sha1);
127 if (cgit_query_sha2)
128 html_hidden("id2", cgit_query_sha2);
129 html("<input type='text' name='q' value='");
130 html_attr(cgit_query_search);
131 html("'/></form>");
132 }
107 if (cgit_query_repo) 133 if (cgit_query_repo)
108 htmlf("<a href='%s'>", cgit_repourl(cgit_query_repo)); 134 htmlf("<a href='%s'>", cgit_repourl(cgit_query_repo));
109 html_txt(title); 135 html_txt(title);
110 if (cgit_query_repo) 136 if (cgit_query_repo)
111 html("</a>"); 137 html("</a>");
112 html("</div>"); 138 html("</div>");
113} 139}