-rw-r--r-- | cgit.c | 13 | ||||
-rw-r--r-- | cgit.css | 98 | ||||
-rw-r--r-- | ui-diff.c | 1 | ||||
-rw-r--r-- | ui-log.c | 1 | ||||
-rw-r--r-- | ui-repolist.c | 1 | ||||
-rw-r--r-- | ui-shared.c | 37 | ||||
-rw-r--r-- | ui-summary.c | 6 | ||||
-rw-r--r-- | ui-tree.c | 1 | ||||
-rw-r--r-- | ui-view.c | 1 |
9 files changed, 127 insertions, 32 deletions
@@ -1,245 +1,254 @@ | |||
1 | /* cgit.c: cgi for the git scm | 1 | /* cgit.c: cgi for the git scm |
2 | * | 2 | * |
3 | * Copyright (C) 2006 Lars Hjemli | 3 | * Copyright (C) 2006 Lars Hjemli |
4 | * | 4 | * |
5 | * Licensed under GNU General Public License v2 | 5 | * Licensed under GNU General Public License v2 |
6 | * (see COPYING for full license text) | 6 | * (see COPYING for full license text) |
7 | */ | 7 | */ |
8 | 8 | ||
9 | #include "cgit.h" | 9 | #include "cgit.h" |
10 | 10 | ||
11 | const char cgit_version[] = CGIT_VERSION; | 11 | const char cgit_version[] = CGIT_VERSION; |
12 | 12 | ||
13 | 13 | ||
14 | static struct repoinfo *cgit_get_repoinfo(char *url) | 14 | static struct repoinfo *cgit_get_repoinfo(char *url) |
15 | { | 15 | { |
16 | int i; | 16 | int i; |
17 | struct repoinfo *repo; | 17 | struct repoinfo *repo; |
18 | 18 | ||
19 | for (i=0; i<cgit_repolist.count; i++) { | 19 | for (i=0; i<cgit_repolist.count; i++) { |
20 | repo = &cgit_repolist.repos[i]; | 20 | repo = &cgit_repolist.repos[i]; |
21 | if (!strcmp(repo->url, url)) | 21 | if (!strcmp(repo->url, url)) |
22 | return repo; | 22 | return repo; |
23 | } | 23 | } |
24 | return NULL; | 24 | return NULL; |
25 | } | 25 | } |
26 | 26 | ||
27 | 27 | ||
28 | static int cgit_prepare_cache(struct cacheitem *item) | 28 | static int cgit_prepare_cache(struct cacheitem *item) |
29 | { | 29 | { |
30 | if (!cgit_query_repo) { | 30 | if (!cgit_query_repo) { |
31 | item->name = xstrdup(fmt("%s/index.html", cgit_cache_root)); | 31 | item->name = xstrdup(fmt("%s/index.html", cgit_cache_root)); |
32 | item->ttl = cgit_cache_root_ttl; | 32 | item->ttl = cgit_cache_root_ttl; |
33 | return 1; | 33 | return 1; |
34 | } | 34 | } |
35 | cgit_repo = cgit_get_repoinfo(cgit_query_repo); | 35 | cgit_repo = cgit_get_repoinfo(cgit_query_repo); |
36 | if (!cgit_repo) { | 36 | if (!cgit_repo) { |
37 | char *title = fmt("%s - %s", cgit_root_title, "Bad request"); | 37 | char *title = fmt("%s - %s", cgit_root_title, "Bad request"); |
38 | cgit_print_docstart(title, item); | 38 | cgit_print_docstart(title, item); |
39 | cgit_print_pageheader(title, 0); | 39 | cgit_print_pageheader(title, 0); |
40 | cgit_print_error(fmt("Unknown repo: %s", cgit_query_repo)); | 40 | cgit_print_error(fmt("Unknown repo: %s", cgit_query_repo)); |
41 | cgit_print_docend(); | 41 | cgit_print_docend(); |
42 | return 0; | 42 | return 0; |
43 | } | 43 | } |
44 | 44 | ||
45 | if (!cgit_query_page) { | 45 | if (!cgit_query_page) { |
46 | item->name = xstrdup(fmt("%s/%s/index.html", cgit_cache_root, | 46 | item->name = xstrdup(fmt("%s/%s/index.html", cgit_cache_root, |
47 | cgit_repo->url)); | 47 | cgit_repo->url)); |
48 | item->ttl = cgit_cache_repo_ttl; | 48 | item->ttl = cgit_cache_repo_ttl; |
49 | } else { | 49 | } else { |
50 | item->name = xstrdup(fmt("%s/%s/%s/%s.html", cgit_cache_root, | 50 | item->name = xstrdup(fmt("%s/%s/%s/%s.html", cgit_cache_root, |
51 | cgit_repo->url, cgit_query_page, | 51 | cgit_repo->url, cgit_query_page, |
52 | cache_safe_filename(cgit_querystring))); | 52 | cache_safe_filename(cgit_querystring))); |
53 | if (cgit_query_has_symref) | 53 | if (cgit_query_has_symref) |
54 | item->ttl = cgit_cache_dynamic_ttl; | 54 | item->ttl = cgit_cache_dynamic_ttl; |
55 | else if (cgit_query_has_sha1) | 55 | else if (cgit_query_has_sha1) |
56 | item->ttl = cgit_cache_static_ttl; | 56 | item->ttl = cgit_cache_static_ttl; |
57 | else | 57 | else |
58 | item->ttl = cgit_cache_repo_ttl; | 58 | item->ttl = cgit_cache_repo_ttl; |
59 | } | 59 | } |
60 | return 1; | 60 | return 1; |
61 | } | 61 | } |
62 | 62 | ||
63 | static void cgit_print_repo_page(struct cacheitem *item) | 63 | static void cgit_print_repo_page(struct cacheitem *item) |
64 | { | 64 | { |
65 | char *title; | 65 | char *title; |
66 | int show_search; | 66 | int show_search; |
67 | 67 | ||
68 | if (chdir(cgit_repo->path)) { | 68 | if (chdir(cgit_repo->path)) { |
69 | title = fmt("%s - %s", cgit_root_title, "Bad request"); | 69 | title = fmt("%s - %s", cgit_root_title, "Bad request"); |
70 | cgit_print_docstart(title, item); | 70 | cgit_print_docstart(title, item); |
71 | cgit_print_pageheader(title, 0); | 71 | cgit_print_pageheader(title, 0); |
72 | cgit_print_error(fmt("Unable to scan repository: %s", | 72 | cgit_print_error(fmt("Unable to scan repository: %s", |
73 | strerror(errno))); | 73 | strerror(errno))); |
74 | cgit_print_docend(); | 74 | cgit_print_docend(); |
75 | return; | 75 | return; |
76 | } | 76 | } |
77 | 77 | ||
78 | title = fmt("%s - %s", cgit_repo->name, cgit_repo->desc); | 78 | title = fmt("%s - %s", cgit_repo->name, cgit_repo->desc); |
79 | show_search = 0; | 79 | show_search = 0; |
80 | setenv("GIT_DIR", cgit_repo->path, 1); | 80 | setenv("GIT_DIR", cgit_repo->path, 1); |
81 | 81 | ||
82 | if (cgit_repo->snapshots && cgit_query_page && | 82 | if (cgit_repo->snapshots && cgit_query_page && |
83 | !strcmp(cgit_query_page, "snapshot")) { | 83 | !strcmp(cgit_query_page, "snapshot")) { |
84 | cgit_print_snapshot(item, cgit_query_sha1, "zip", | 84 | cgit_print_snapshot(item, cgit_query_sha1, "zip", |
85 | cgit_repo->url, cgit_query_name); | 85 | cgit_repo->url, cgit_query_name); |
86 | return; | 86 | return; |
87 | } | 87 | } |
88 | 88 | ||
89 | if (cgit_query_page && !strcmp(cgit_query_page, "log")) | 89 | if (cgit_query_page && !strcmp(cgit_query_page, "log")) |
90 | show_search = 1; | 90 | show_search = 1; |
91 | |||
91 | cgit_print_docstart(title, item); | 92 | cgit_print_docstart(title, item); |
92 | cgit_print_pageheader(title, show_search); | 93 | |
94 | |||
93 | if (!cgit_query_page) { | 95 | if (!cgit_query_page) { |
96 | cgit_print_pageheader("summary", show_search); | ||
94 | cgit_print_summary(); | 97 | cgit_print_summary(); |
95 | } else if (!strcmp(cgit_query_page, "log")) { | 98 | cgit_print_docend(); |
99 | return; | ||
100 | } | ||
101 | |||
102 | cgit_print_pageheader(cgit_query_page, show_search); | ||
103 | |||
104 | if (!strcmp(cgit_query_page, "log")) { | ||
96 | cgit_print_log(cgit_query_head, cgit_query_ofs, 100, | 105 | cgit_print_log(cgit_query_head, cgit_query_ofs, 100, |
97 | cgit_query_search); | 106 | cgit_query_search); |
98 | } else if (!strcmp(cgit_query_page, "tree")) { | 107 | } else if (!strcmp(cgit_query_page, "tree")) { |
99 | cgit_print_tree(cgit_query_sha1, cgit_query_path); | 108 | cgit_print_tree(cgit_query_sha1, cgit_query_path); |
100 | } else if (!strcmp(cgit_query_page, "commit")) { | 109 | } else if (!strcmp(cgit_query_page, "commit")) { |
101 | cgit_print_commit(cgit_query_sha1); | 110 | cgit_print_commit(cgit_query_sha1); |
102 | } else if (!strcmp(cgit_query_page, "view")) { | 111 | } else if (!strcmp(cgit_query_page, "view")) { |
103 | cgit_print_view(cgit_query_sha1); | 112 | cgit_print_view(cgit_query_sha1); |
104 | } else if (!strcmp(cgit_query_page, "diff")) { | 113 | } else if (!strcmp(cgit_query_page, "diff")) { |
105 | cgit_print_diff(cgit_query_sha1, cgit_query_sha2); | 114 | cgit_print_diff(cgit_query_sha1, cgit_query_sha2); |
106 | } else { | 115 | } else { |
107 | cgit_print_error("Invalid request"); | 116 | cgit_print_error("Invalid request"); |
108 | } | 117 | } |
109 | cgit_print_docend(); | 118 | cgit_print_docend(); |
110 | } | 119 | } |
111 | 120 | ||
112 | static void cgit_fill_cache(struct cacheitem *item, int use_cache) | 121 | static void cgit_fill_cache(struct cacheitem *item, int use_cache) |
113 | { | 122 | { |
114 | static char buf[PATH_MAX]; | 123 | static char buf[PATH_MAX]; |
115 | int stdout2; | 124 | int stdout2; |
116 | 125 | ||
117 | getcwd(buf, sizeof(buf)); | 126 | getcwd(buf, sizeof(buf)); |
118 | item->st.st_mtime = time(NULL); | 127 | item->st.st_mtime = time(NULL); |
119 | 128 | ||
120 | if (use_cache) { | 129 | if (use_cache) { |
121 | stdout2 = chk_positive(dup(STDOUT_FILENO), | 130 | stdout2 = chk_positive(dup(STDOUT_FILENO), |
122 | "Preserving STDOUT"); | 131 | "Preserving STDOUT"); |
123 | chk_zero(close(STDOUT_FILENO), "Closing STDOUT"); | 132 | chk_zero(close(STDOUT_FILENO), "Closing STDOUT"); |
124 | chk_positive(dup2(item->fd, STDOUT_FILENO), "Dup2(cachefile)"); | 133 | chk_positive(dup2(item->fd, STDOUT_FILENO), "Dup2(cachefile)"); |
125 | } | 134 | } |
126 | 135 | ||
127 | if (cgit_query_repo) | 136 | if (cgit_query_repo) |
128 | cgit_print_repo_page(item); | 137 | cgit_print_repo_page(item); |
129 | else | 138 | else |
130 | cgit_print_repolist(item); | 139 | cgit_print_repolist(item); |
131 | 140 | ||
132 | if (use_cache) { | 141 | if (use_cache) { |
133 | chk_zero(close(STDOUT_FILENO), "Close redirected STDOUT"); | 142 | chk_zero(close(STDOUT_FILENO), "Close redirected STDOUT"); |
134 | chk_positive(dup2(stdout2, STDOUT_FILENO), | 143 | chk_positive(dup2(stdout2, STDOUT_FILENO), |
135 | "Restoring original STDOUT"); | 144 | "Restoring original STDOUT"); |
136 | chk_zero(close(stdout2), "Closing temporary STDOUT"); | 145 | chk_zero(close(stdout2), "Closing temporary STDOUT"); |
137 | } | 146 | } |
138 | 147 | ||
139 | chdir(buf); | 148 | chdir(buf); |
140 | } | 149 | } |
141 | 150 | ||
142 | static void cgit_check_cache(struct cacheitem *item) | 151 | static void cgit_check_cache(struct cacheitem *item) |
143 | { | 152 | { |
144 | int i = 0; | 153 | int i = 0; |
145 | 154 | ||
146 | top: | 155 | top: |
147 | if (++i > cgit_max_lock_attempts) { | 156 | if (++i > cgit_max_lock_attempts) { |
148 | die("cgit_refresh_cache: unable to lock %s: %s", | 157 | die("cgit_refresh_cache: unable to lock %s: %s", |
149 | item->name, strerror(errno)); | 158 | item->name, strerror(errno)); |
150 | } | 159 | } |
151 | if (!cache_exist(item)) { | 160 | if (!cache_exist(item)) { |
152 | if (!cache_lock(item)) { | 161 | if (!cache_lock(item)) { |
153 | sleep(1); | 162 | sleep(1); |
154 | goto top; | 163 | goto top; |
155 | } | 164 | } |
156 | if (!cache_exist(item)) { | 165 | if (!cache_exist(item)) { |
157 | cgit_fill_cache(item, 1); | 166 | cgit_fill_cache(item, 1); |
158 | cache_unlock(item); | 167 | cache_unlock(item); |
159 | } else { | 168 | } else { |
160 | cache_cancel_lock(item); | 169 | cache_cancel_lock(item); |
161 | } | 170 | } |
162 | } else if (cache_expired(item) && cache_lock(item)) { | 171 | } else if (cache_expired(item) && cache_lock(item)) { |
163 | if (cache_expired(item)) { | 172 | if (cache_expired(item)) { |
164 | cgit_fill_cache(item, 1); | 173 | cgit_fill_cache(item, 1); |
165 | cache_unlock(item); | 174 | cache_unlock(item); |
166 | } else { | 175 | } else { |
167 | cache_cancel_lock(item); | 176 | cache_cancel_lock(item); |
168 | } | 177 | } |
169 | } | 178 | } |
170 | } | 179 | } |
171 | 180 | ||
172 | static void cgit_print_cache(struct cacheitem *item) | 181 | static void cgit_print_cache(struct cacheitem *item) |
173 | { | 182 | { |
174 | static char buf[4096]; | 183 | static char buf[4096]; |
175 | ssize_t i; | 184 | ssize_t i; |
176 | 185 | ||
177 | int fd = open(item->name, O_RDONLY); | 186 | int fd = open(item->name, O_RDONLY); |
178 | if (fd<0) | 187 | if (fd<0) |
179 | die("Unable to open cached file %s", item->name); | 188 | die("Unable to open cached file %s", item->name); |
180 | 189 | ||
181 | while((i=read(fd, buf, sizeof(buf))) > 0) | 190 | while((i=read(fd, buf, sizeof(buf))) > 0) |
182 | write(STDOUT_FILENO, buf, i); | 191 | write(STDOUT_FILENO, buf, i); |
183 | 192 | ||
184 | close(fd); | 193 | close(fd); |
185 | } | 194 | } |
186 | 195 | ||
187 | static void cgit_parse_args(int argc, const char **argv) | 196 | static void cgit_parse_args(int argc, const char **argv) |
188 | { | 197 | { |
189 | int i; | 198 | int i; |
190 | 199 | ||
191 | for (i = 1; i < argc; i++) { | 200 | for (i = 1; i < argc; i++) { |
192 | if (!strncmp(argv[i], "--cache=", 8)) { | 201 | if (!strncmp(argv[i], "--cache=", 8)) { |
193 | cgit_cache_root = xstrdup(argv[i]+8); | 202 | cgit_cache_root = xstrdup(argv[i]+8); |
194 | } | 203 | } |
195 | if (!strcmp(argv[i], "--nocache")) { | 204 | if (!strcmp(argv[i], "--nocache")) { |
196 | cgit_nocache = 1; | 205 | cgit_nocache = 1; |
197 | } | 206 | } |
198 | if (!strncmp(argv[i], "--query=", 8)) { | 207 | if (!strncmp(argv[i], "--query=", 8)) { |
199 | cgit_querystring = xstrdup(argv[i]+8); | 208 | cgit_querystring = xstrdup(argv[i]+8); |
200 | } | 209 | } |
201 | if (!strncmp(argv[i], "--repo=", 7)) { | 210 | if (!strncmp(argv[i], "--repo=", 7)) { |
202 | cgit_query_repo = xstrdup(argv[i]+7); | 211 | cgit_query_repo = xstrdup(argv[i]+7); |
203 | } | 212 | } |
204 | if (!strncmp(argv[i], "--page=", 7)) { | 213 | if (!strncmp(argv[i], "--page=", 7)) { |
205 | cgit_query_page = xstrdup(argv[i]+7); | 214 | cgit_query_page = xstrdup(argv[i]+7); |
206 | } | 215 | } |
207 | if (!strncmp(argv[i], "--head=", 7)) { | 216 | if (!strncmp(argv[i], "--head=", 7)) { |
208 | cgit_query_head = xstrdup(argv[i]+7); | 217 | cgit_query_head = xstrdup(argv[i]+7); |
209 | cgit_query_has_symref = 1; | 218 | cgit_query_has_symref = 1; |
210 | } | 219 | } |
211 | if (!strncmp(argv[i], "--sha1=", 7)) { | 220 | if (!strncmp(argv[i], "--sha1=", 7)) { |
212 | cgit_query_sha1 = xstrdup(argv[i]+7); | 221 | cgit_query_sha1 = xstrdup(argv[i]+7); |
213 | cgit_query_has_sha1 = 1; | 222 | cgit_query_has_sha1 = 1; |
214 | } | 223 | } |
215 | if (!strncmp(argv[i], "--ofs=", 6)) { | 224 | if (!strncmp(argv[i], "--ofs=", 6)) { |
216 | cgit_query_ofs = atoi(argv[i]+6); | 225 | cgit_query_ofs = atoi(argv[i]+6); |
217 | } | 226 | } |
218 | } | 227 | } |
219 | } | 228 | } |
220 | 229 | ||
221 | int main(int argc, const char **argv) | 230 | int main(int argc, const char **argv) |
222 | { | 231 | { |
223 | struct cacheitem item; | 232 | struct cacheitem item; |
224 | 233 | ||
225 | htmlfd = STDOUT_FILENO; | 234 | htmlfd = STDOUT_FILENO; |
226 | item.st.st_mtime = time(NULL); | 235 | item.st.st_mtime = time(NULL); |
227 | cgit_repolist.length = 0; | 236 | cgit_repolist.length = 0; |
228 | cgit_repolist.count = 0; | 237 | cgit_repolist.count = 0; |
229 | cgit_repolist.repos = NULL; | 238 | cgit_repolist.repos = NULL; |
230 | 239 | ||
231 | cgit_read_config("/etc/cgitrc", cgit_global_config_cb); | 240 | cgit_read_config("/etc/cgitrc", cgit_global_config_cb); |
232 | if (getenv("QUERY_STRING")) | 241 | if (getenv("QUERY_STRING")) |
233 | cgit_querystring = xstrdup(getenv("QUERY_STRING")); | 242 | cgit_querystring = xstrdup(getenv("QUERY_STRING")); |
234 | cgit_parse_args(argc, argv); | 243 | cgit_parse_args(argc, argv); |
235 | cgit_parse_query(cgit_querystring, cgit_querystring_cb); | 244 | cgit_parse_query(cgit_querystring, cgit_querystring_cb); |
236 | if (!cgit_prepare_cache(&item)) | 245 | if (!cgit_prepare_cache(&item)) |
237 | return 0; | 246 | return 0; |
238 | if (cgit_nocache) { | 247 | if (cgit_nocache) { |
239 | cgit_fill_cache(&item, 0); | 248 | cgit_fill_cache(&item, 0); |
240 | } else { | 249 | } else { |
241 | cgit_check_cache(&item); | 250 | cgit_check_cache(&item); |
242 | cgit_print_cache(&item); | 251 | cgit_print_cache(&item); |
243 | } | 252 | } |
244 | return 0; | 253 | return 0; |
245 | } | 254 | } |
@@ -1,199 +1,271 @@ | |||
1 | body { | 1 | body { |
2 | font-family: arial; | 2 | font-family: arial; |
3 | font-size: 11pt; | 3 | font-size: 11pt; |
4 | background: white; | 4 | background: white; |
5 | padding: 0em; | 5 | padding: 0em; |
6 | margin: 0em; | 6 | margin: 0em; |
7 | } | 7 | } |
8 | 8 | ||
9 | 9 | ||
10 | h2 { | 10 | h2 { |
11 | font-size: 120%; | 11 | font-size: 120%; |
12 | font-weight: bold; | 12 | font-weight: bold; |
13 | margin-bottom: 0.5em; | 13 | margin-bottom: 0.25em; |
14 | } | ||
15 | |||
16 | h3 { | ||
17 | margin-top: 0em; | ||
18 | font-size: 100%; | ||
19 | font-weight: normal; | ||
14 | } | 20 | } |
15 | 21 | ||
16 | a { | 22 | a { |
17 | color: blue; | 23 | color: blue; |
18 | text-decoration: none; | 24 | text-decoration: none; |
19 | } | 25 | } |
20 | 26 | ||
21 | a:hover { | 27 | a:hover { |
22 | text-decoration: underline; | 28 | text-decoration: underline; |
23 | } | 29 | } |
24 | 30 | ||
25 | table.list { | 31 | table.list { |
26 | border: none; | 32 | border: none; |
27 | border-collapse: collapse; | 33 | border-collapse: collapse; |
28 | } | 34 | } |
35 | |||
29 | table.list tr { | 36 | table.list tr { |
30 | background: white; | 37 | background: white; |
31 | } | 38 | } |
39 | |||
32 | table.list tr:hover { | 40 | table.list tr:hover { |
33 | background: #eee; | 41 | background: #eee; |
34 | } | 42 | } |
43 | |||
35 | table.list tr.nohover:hover { | 44 | table.list tr.nohover:hover { |
36 | background: white; | 45 | background: white; |
37 | } | 46 | } |
47 | |||
38 | table.list th { | 48 | table.list th { |
39 | font-weight: normal; | 49 | font-weight: normal; |
40 | border-bottom: solid 1px #777; | 50 | border-bottom: solid 1px #777; |
41 | padding: 0.1em 0.5em 0.1em 0.5em; | 51 | padding: 0.1em 0.5em 0.1em 0.5em; |
42 | vertical-align: baseline; | 52 | vertical-align: baseline; |
43 | } | 53 | } |
54 | |||
44 | table.list td { | 55 | table.list td { |
45 | border: none; | 56 | border: none; |
46 | padding: 0.1em 0.5em 0.1em 0.5em; | 57 | padding: 0.1em 0.5em 0.1em 0.5em; |
47 | } | 58 | } |
59 | |||
48 | img { | 60 | img { |
49 | border: none; | 61 | border: none; |
50 | } | 62 | } |
63 | |||
51 | table#layout { | 64 | table#layout { |
52 | width: 100%; | 65 | width: 100%; |
53 | border-collapse: collapse; | 66 | border-collapse: separate; |
67 | border-spacing: 0px; | ||
54 | margin: 0px; | 68 | margin: 0px; |
55 | } | 69 | } |
56 | td#header { | 70 | |
71 | td#header, td#logo { | ||
72 | color: #666; | ||
57 | background-color: #ddd; | 73 | background-color: #ddd; |
58 | padding: 0.25em 0.25em 0.25em 0.5em; | 74 | border-bottom: solid 1px #000; |
75 | } | ||
76 | |||
77 | td#header { | ||
59 | font-size: 150%; | 78 | font-size: 150%; |
60 | font-weight: bold; | 79 | font-weight: bold; |
61 | border-bottom: solid 1px #aaa; | 80 | padding: 0.2em 0.5em; |
81 | vertical-align: text-bottom; | ||
82 | } | ||
83 | |||
84 | td#logo { | ||
85 | text-align: right; | ||
62 | vertical-align: middle; | 86 | vertical-align: middle; |
87 | padding-right: 0.5em; | ||
88 | } | ||
89 | |||
90 | td#crumb, td#search { | ||
91 | color: #ccc; | ||
92 | border-top: solid 3px #555; | ||
93 | background-color: #666; | ||
94 | border-bottom: solid 1px #333; | ||
95 | padding: 2px 1em; | ||
96 | } | ||
97 | |||
98 | td#crumb { | ||
99 | font-weight: bold; | ||
100 | } | ||
101 | |||
102 | td#crumb a { | ||
103 | color: #ccc; | ||
63 | } | 104 | } |
64 | td#header img#logo { | 105 | |
65 | float: right; | 106 | td#crumb a:hover { |
107 | color: #eee; | ||
66 | } | 108 | } |
67 | 109 | ||
68 | td#header input { | 110 | td#search { |
69 | float: right; | 111 | text-align: right; |
70 | margin: 0.25em 1em; | 112 | vertical-align: center; |
113 | padding-right: 0.5em; | ||
71 | } | 114 | } |
72 | td#header a { | 115 | |
73 | color: black; | 116 | td#search form { |
117 | margin: 0px; | ||
118 | padding: 0px; | ||
119 | } | ||
120 | |||
121 | td#search input { | ||
122 | font-size: 9pt; | ||
123 | padding: 0px; | ||
124 | width: 10em; | ||
125 | border: solid 1px #333; | ||
126 | color: #333; | ||
127 | background-color: #fff; | ||
74 | } | 128 | } |
75 | 129 | ||
76 | td#content { | 130 | td#content { |
77 | padding: 1em 0.5em; | 131 | padding: 1em 0.5em; |
78 | } | 132 | } |
79 | 133 | ||
80 | div#blob { | 134 | div#blob { |
81 | border: solid 1px black; | 135 | border: solid 1px black; |
82 | } | 136 | } |
83 | 137 | ||
84 | div.error { | 138 | div.error { |
85 | color: red; | 139 | color: red; |
86 | font-weight: bold; | 140 | font-weight: bold; |
87 | margin: 1em 2em; | 141 | margin: 1em 2em; |
88 | } | 142 | } |
143 | |||
89 | div.ls-blob, div.ls-dir { | 144 | div.ls-blob, div.ls-dir { |
90 | font-family: monospace; | 145 | font-family: monospace; |
91 | } | 146 | } |
147 | |||
92 | div.ls-dir a { | 148 | div.ls-dir a { |
93 | font-weight: bold; | 149 | font-weight: bold; |
94 | } | 150 | } |
151 | |||
95 | th.filesize, td.filesize { | 152 | th.filesize, td.filesize { |
96 | text-align: right; | 153 | text-align: right; |
97 | } | 154 | } |
155 | |||
98 | td.filesize { | 156 | td.filesize { |
99 | font-family: monospace; | 157 | font-family: monospace; |
100 | } | 158 | } |
159 | |||
101 | td.filemode { | 160 | td.filemode { |
102 | font-family: monospace; | 161 | font-family: monospace; |
103 | } | 162 | } |
104 | 163 | ||
105 | td.blob { | 164 | td.blob { |
106 | white-space: pre; | 165 | white-space: pre; |
107 | font-family: monospace; | 166 | font-family: monospace; |
108 | background-color: white; | 167 | background-color: white; |
109 | } | 168 | } |
110 | 169 | ||
111 | table.nowrap td { | 170 | table.nowrap td { |
112 | white-space: nowrap; | 171 | white-space: nowrap; |
113 | } | 172 | } |
114 | 173 | ||
115 | table.commit-info { | 174 | table.commit-info { |
116 | border-collapse: collapse; | 175 | border-collapse: collapse; |
117 | margin-top: 1.5em; | 176 | margin-top: 1.5em; |
118 | } | 177 | } |
178 | |||
119 | table.commit-info th { | 179 | table.commit-info th { |
120 | text-align: left; | 180 | text-align: left; |
121 | font-weight: normal; | 181 | font-weight: normal; |
122 | padding: 0.1em 1em 0.1em 0.1em; | 182 | padding: 0.1em 1em 0.1em 0.1em; |
123 | } | 183 | } |
184 | |||
124 | table.commit-info td { | 185 | table.commit-info td { |
125 | font-weight: normal; | 186 | font-weight: normal; |
126 | padding: 0.1em 1em 0.1em 0.1em; | 187 | padding: 0.1em 1em 0.1em 0.1em; |
127 | } | 188 | } |
189 | |||
128 | div.commit-subject { | 190 | div.commit-subject { |
129 | font-weight: bold; | 191 | font-weight: bold; |
130 | font-size: 125%; | 192 | font-size: 125%; |
131 | margin: 1.5em 0em 0.5em 0em; | 193 | margin: 1.5em 0em 0.5em 0em; |
132 | padding: 0em; | 194 | padding: 0em; |
133 | } | 195 | } |
196 | |||
134 | div.commit-msg { | 197 | div.commit-msg { |
135 | white-space: pre; | 198 | white-space: pre; |
136 | font-family: monospace; | 199 | font-family: monospace; |
137 | } | 200 | } |
201 | |||
138 | table.diffstat { | 202 | table.diffstat { |
139 | border-collapse: collapse; | 203 | border-collapse: collapse; |
140 | margin-top: 1.5em; | 204 | margin-top: 1.5em; |
141 | } | 205 | } |
206 | |||
142 | table.diffstat th { | 207 | table.diffstat th { |
143 | font-weight: normal; | 208 | font-weight: normal; |
144 | text-align: left; | 209 | text-align: left; |
145 | text-decoration: underline; | 210 | text-decoration: underline; |
146 | padding: 0.1em 1em 0.1em 0.1em; | 211 | padding: 0.1em 1em 0.1em 0.1em; |
147 | font-size: 100%; | 212 | font-size: 100%; |
148 | } | 213 | } |
214 | |||
149 | table.diffstat td { | 215 | table.diffstat td { |
150 | padding: 0.1em 1em 0.1em 0.1em; | 216 | padding: 0.1em 1em 0.1em 0.1em; |
151 | font-size: 100%; | 217 | font-size: 100%; |
152 | } | 218 | } |
219 | |||
153 | table.diffstat td span.modechange { | 220 | table.diffstat td span.modechange { |
154 | padding-left: 1em; | 221 | padding-left: 1em; |
155 | color: red; | 222 | color: red; |
156 | } | 223 | } |
224 | |||
157 | table.diffstat td.add a { | 225 | table.diffstat td.add a { |
158 | color: green; | 226 | color: green; |
159 | } | 227 | } |
228 | |||
160 | table.diffstat td.del a { | 229 | table.diffstat td.del a { |
161 | color: red; | 230 | color: red; |
162 | } | 231 | } |
232 | |||
163 | table.diffstat td.upd a { | 233 | table.diffstat td.upd a { |
164 | color: blue; | 234 | color: blue; |
165 | } | 235 | } |
236 | |||
166 | table.diffstat td.summary { | 237 | table.diffstat td.summary { |
167 | /* border-top: solid 1px black; */ | ||
168 | color: #888; | 238 | color: #888; |
169 | padding-top: 0.5em; | 239 | padding-top: 0.5em; |
170 | } | 240 | } |
171 | 241 | ||
172 | table.diff td { | 242 | table.diff td { |
173 | border: solid 1px black; | 243 | border: solid 1px black; |
174 | font-family: monospace; | 244 | font-family: monospace; |
175 | white-space: pre; | 245 | white-space: pre; |
176 | } | 246 | } |
177 | 247 | ||
178 | table.diff td div.hunk { | 248 | table.diff td div.hunk { |
179 | background: #ccc; | 249 | background: #ccc; |
180 | } | 250 | } |
181 | 251 | ||
182 | table.diff td div.add { | 252 | table.diff td div.add { |
183 | color: green; | 253 | color: green; |
184 | } | 254 | } |
185 | 255 | ||
186 | table.diff td div.del { | 256 | table.diff td div.del { |
187 | color: red; | 257 | color: red; |
188 | } | 258 | } |
189 | 259 | ||
190 | .sha1 { | 260 | .sha1 { |
191 | font-family: courier; | 261 | font-family: courier; |
192 | font-size: 90%; | 262 | font-size: 90%; |
193 | } | 263 | } |
264 | |||
194 | .left { | 265 | .left { |
195 | text-align: left; | 266 | text-align: left; |
196 | } | 267 | } |
268 | |||
197 | .right { | 269 | .right { |
198 | text-align: right; | 270 | text-align: right; |
199 | } | 271 | } |
@@ -1,131 +1,130 @@ | |||
1 | /* ui-diff.c: show diff between two blobs | 1 | /* ui-diff.c: show diff between two blobs |
2 | * | 2 | * |
3 | * Copyright (C) 2006 Lars Hjemli | 3 | * Copyright (C) 2006 Lars Hjemli |
4 | * | 4 | * |
5 | * Licensed under GNU General Public License v2 | 5 | * Licensed under GNU General Public License v2 |
6 | * (see COPYING for full license text) | 6 | * (see COPYING for full license text) |
7 | */ | 7 | */ |
8 | 8 | ||
9 | #include "cgit.h" | 9 | #include "cgit.h" |
10 | #include "xdiff.h" | 10 | #include "xdiff.h" |
11 | 11 | ||
12 | char *diff_buffer; | 12 | char *diff_buffer; |
13 | int diff_buffer_size; | 13 | int diff_buffer_size; |
14 | 14 | ||
15 | 15 | ||
16 | /* | 16 | /* |
17 | * print a single line returned from xdiff | 17 | * print a single line returned from xdiff |
18 | */ | 18 | */ |
19 | static void print_line(char *line, int len) | 19 | static void print_line(char *line, int len) |
20 | { | 20 | { |
21 | char *class = "ctx"; | 21 | char *class = "ctx"; |
22 | char c = line[len-1]; | 22 | char c = line[len-1]; |
23 | 23 | ||
24 | if (line[0] == '+') | 24 | if (line[0] == '+') |
25 | class = "add"; | 25 | class = "add"; |
26 | else if (line[0] == '-') | 26 | else if (line[0] == '-') |
27 | class = "del"; | 27 | class = "del"; |
28 | else if (line[0] == '@') | 28 | else if (line[0] == '@') |
29 | class = "hunk"; | 29 | class = "hunk"; |
30 | 30 | ||
31 | htmlf("<div class='%s'>", class); | 31 | htmlf("<div class='%s'>", class); |
32 | line[len-1] = '\0'; | 32 | line[len-1] = '\0'; |
33 | html_txt(line); | 33 | html_txt(line); |
34 | html("</div>"); | 34 | html("</div>"); |
35 | line[len-1] = c; | 35 | line[len-1] = c; |
36 | } | 36 | } |
37 | 37 | ||
38 | /* | 38 | /* |
39 | * Receive diff-buffers from xdiff and concatenate them as | 39 | * Receive diff-buffers from xdiff and concatenate them as |
40 | * needed across multiple callbacks. | 40 | * needed across multiple callbacks. |
41 | * | 41 | * |
42 | * This is basically a copy of xdiff-interface.c/xdiff_outf(), | 42 | * This is basically a copy of xdiff-interface.c/xdiff_outf(), |
43 | * ripped from git and modified to use globals instead of | 43 | * ripped from git and modified to use globals instead of |
44 | * a special callback-struct. | 44 | * a special callback-struct. |
45 | */ | 45 | */ |
46 | int diff_cb(void *priv_, mmbuffer_t *mb, int nbuf) | 46 | int diff_cb(void *priv_, mmbuffer_t *mb, int nbuf) |
47 | { | 47 | { |
48 | int i; | 48 | int i; |
49 | 49 | ||
50 | for (i = 0; i < nbuf; i++) { | 50 | for (i = 0; i < nbuf; i++) { |
51 | if (mb[i].ptr[mb[i].size-1] != '\n') { | 51 | if (mb[i].ptr[mb[i].size-1] != '\n') { |
52 | /* Incomplete line */ | 52 | /* Incomplete line */ |
53 | diff_buffer = xrealloc(diff_buffer, | 53 | diff_buffer = xrealloc(diff_buffer, |
54 | diff_buffer_size + mb[i].size); | 54 | diff_buffer_size + mb[i].size); |
55 | memcpy(diff_buffer + diff_buffer_size, | 55 | memcpy(diff_buffer + diff_buffer_size, |
56 | mb[i].ptr, mb[i].size); | 56 | mb[i].ptr, mb[i].size); |
57 | diff_buffer_size += mb[i].size; | 57 | diff_buffer_size += mb[i].size; |
58 | continue; | 58 | continue; |
59 | } | 59 | } |
60 | 60 | ||
61 | /* we have a complete line */ | 61 | /* we have a complete line */ |
62 | if (!diff_buffer) { | 62 | if (!diff_buffer) { |
63 | print_line(mb[i].ptr, mb[i].size); | 63 | print_line(mb[i].ptr, mb[i].size); |
64 | continue; | 64 | continue; |
65 | } | 65 | } |
66 | diff_buffer = xrealloc(diff_buffer, | 66 | diff_buffer = xrealloc(diff_buffer, |
67 | diff_buffer_size + mb[i].size); | 67 | diff_buffer_size + mb[i].size); |
68 | memcpy(diff_buffer + diff_buffer_size, mb[i].ptr, mb[i].size); | 68 | memcpy(diff_buffer + diff_buffer_size, mb[i].ptr, mb[i].size); |
69 | print_line(diff_buffer, diff_buffer_size + mb[i].size); | 69 | print_line(diff_buffer, diff_buffer_size + mb[i].size); |
70 | free(diff_buffer); | 70 | free(diff_buffer); |
71 | diff_buffer = NULL; | 71 | diff_buffer = NULL; |
72 | diff_buffer_size = 0; | 72 | diff_buffer_size = 0; |
73 | } | 73 | } |
74 | if (diff_buffer) { | 74 | if (diff_buffer) { |
75 | print_line(diff_buffer, diff_buffer_size); | 75 | print_line(diff_buffer, diff_buffer_size); |
76 | free(diff_buffer); | 76 | free(diff_buffer); |
77 | diff_buffer = NULL; | 77 | diff_buffer = NULL; |
78 | diff_buffer_size = 0; | 78 | diff_buffer_size = 0; |
79 | } | 79 | } |
80 | return 0; | 80 | return 0; |
81 | } | 81 | } |
82 | 82 | ||
83 | static int load_mmfile(mmfile_t *file, const unsigned char *sha1) | 83 | static int load_mmfile(mmfile_t *file, const unsigned char *sha1) |
84 | { | 84 | { |
85 | char type[20]; | 85 | char type[20]; |
86 | 86 | ||
87 | if (is_null_sha1(sha1)) { | 87 | if (is_null_sha1(sha1)) { |
88 | file->ptr = (char *)""; | 88 | file->ptr = (char *)""; |
89 | file->size = 0; | 89 | file->size = 0; |
90 | } else { | 90 | } else { |
91 | file->ptr = read_sha1_file(sha1, type, &file->size); | 91 | file->ptr = read_sha1_file(sha1, type, &file->size); |
92 | } | 92 | } |
93 | return 1; | 93 | return 1; |
94 | } | 94 | } |
95 | 95 | ||
96 | static void run_diff(const unsigned char *sha1, const unsigned char *sha2) | 96 | static void run_diff(const unsigned char *sha1, const unsigned char *sha2) |
97 | { | 97 | { |
98 | mmfile_t file1, file2; | 98 | mmfile_t file1, file2; |
99 | xpparam_t diff_params; | 99 | xpparam_t diff_params; |
100 | xdemitconf_t emit_params; | 100 | xdemitconf_t emit_params; |
101 | xdemitcb_t emit_cb; | 101 | xdemitcb_t emit_cb; |
102 | 102 | ||
103 | if (!load_mmfile(&file1, sha1) || !load_mmfile(&file2, sha2)) { | 103 | if (!load_mmfile(&file1, sha1) || !load_mmfile(&file2, sha2)) { |
104 | cgit_print_error("Unable to load files for diff"); | 104 | cgit_print_error("Unable to load files for diff"); |
105 | return; | 105 | return; |
106 | } | 106 | } |
107 | 107 | ||
108 | diff_params.flags = XDF_NEED_MINIMAL; | 108 | diff_params.flags = XDF_NEED_MINIMAL; |
109 | 109 | ||
110 | emit_params.ctxlen = 3; | 110 | emit_params.ctxlen = 3; |
111 | emit_params.flags = XDL_EMIT_FUNCNAMES; | 111 | emit_params.flags = XDL_EMIT_FUNCNAMES; |
112 | 112 | ||
113 | emit_cb.outf = diff_cb; | 113 | emit_cb.outf = diff_cb; |
114 | 114 | ||
115 | xdl_diff(&file1, &file2, &diff_params, &emit_params, &emit_cb); | 115 | xdl_diff(&file1, &file2, &diff_params, &emit_params, &emit_cb); |
116 | } | 116 | } |
117 | 117 | ||
118 | 118 | ||
119 | 119 | ||
120 | void cgit_print_diff(const char *old_hex, const char *new_hex) | 120 | void cgit_print_diff(const char *old_hex, const char *new_hex) |
121 | { | 121 | { |
122 | unsigned char sha1[20], sha2[20]; | 122 | unsigned char sha1[20], sha2[20]; |
123 | 123 | ||
124 | get_sha1(old_hex, sha1); | 124 | get_sha1(old_hex, sha1); |
125 | get_sha1(new_hex, sha2); | 125 | get_sha1(new_hex, sha2); |
126 | 126 | ||
127 | html("<h2>diff</h2>\n"); | ||
128 | html("<table class='diff'><tr><td>"); | 127 | html("<table class='diff'><tr><td>"); |
129 | run_diff(sha1, sha2); | 128 | run_diff(sha1, sha2); |
130 | html("</td></tr></table>"); | 129 | html("</td></tr></table>"); |
131 | } | 130 | } |
@@ -1,98 +1,97 @@ | |||
1 | /* ui-log.c: functions for log output | 1 | /* ui-log.c: functions for log output |
2 | * | 2 | * |
3 | * Copyright (C) 2006 Lars Hjemli | 3 | * Copyright (C) 2006 Lars Hjemli |
4 | * | 4 | * |
5 | * Licensed under GNU General Public License v2 | 5 | * Licensed under GNU General Public License v2 |
6 | * (see COPYING for full license text) | 6 | * (see COPYING for full license text) |
7 | */ | 7 | */ |
8 | 8 | ||
9 | #include "cgit.h" | 9 | #include "cgit.h" |
10 | 10 | ||
11 | void print_commit(struct commit *commit) | 11 | void print_commit(struct commit *commit) |
12 | { | 12 | { |
13 | char buf[32]; | 13 | char buf[32]; |
14 | struct commitinfo *info; | 14 | struct commitinfo *info; |
15 | struct tm *time; | 15 | struct tm *time; |
16 | 16 | ||
17 | info = cgit_parse_commit(commit); | 17 | info = cgit_parse_commit(commit); |
18 | time = gmtime(&commit->date); | 18 | time = gmtime(&commit->date); |
19 | html("<tr><td>"); | 19 | html("<tr><td>"); |
20 | strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", time); | 20 | strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", time); |
21 | html_txt(buf); | 21 | html_txt(buf); |
22 | html("</td><td>"); | 22 | html("</td><td>"); |
23 | char *qry = fmt("id=%s", sha1_to_hex(commit->object.sha1)); | 23 | char *qry = fmt("id=%s", sha1_to_hex(commit->object.sha1)); |
24 | char *url = cgit_pageurl(cgit_query_repo, "commit", qry); | 24 | char *url = cgit_pageurl(cgit_query_repo, "commit", qry); |
25 | html_link_open(url, NULL, NULL); | 25 | html_link_open(url, NULL, NULL); |
26 | html_ntxt(cgit_max_msg_len, info->subject); | 26 | html_ntxt(cgit_max_msg_len, info->subject); |
27 | html_link_close(); | 27 | html_link_close(); |
28 | html("</td><td>"); | 28 | html("</td><td>"); |
29 | html_txt(info->author); | 29 | html_txt(info->author); |
30 | html("</td></tr>\n"); | 30 | html("</td></tr>\n"); |
31 | cgit_free_commitinfo(info); | 31 | cgit_free_commitinfo(info); |
32 | } | 32 | } |
33 | 33 | ||
34 | 34 | ||
35 | void cgit_print_log(const char *tip, int ofs, int cnt, char *grep) | 35 | void cgit_print_log(const char *tip, int ofs, int cnt, char *grep) |
36 | { | 36 | { |
37 | struct rev_info rev; | 37 | struct rev_info rev; |
38 | struct commit *commit; | 38 | struct commit *commit; |
39 | const char *argv[3] = {NULL, tip, NULL}; | 39 | const char *argv[3] = {NULL, tip, NULL}; |
40 | int argc = 2; | 40 | int argc = 2; |
41 | int i; | 41 | int i; |
42 | 42 | ||
43 | if (grep) | 43 | if (grep) |
44 | argv[argc++] = fmt("--grep=%s", grep); | 44 | argv[argc++] = fmt("--grep=%s", grep); |
45 | init_revisions(&rev, NULL); | 45 | init_revisions(&rev, NULL); |
46 | rev.abbrev = DEFAULT_ABBREV; | 46 | rev.abbrev = DEFAULT_ABBREV; |
47 | rev.commit_format = CMIT_FMT_DEFAULT; | 47 | rev.commit_format = CMIT_FMT_DEFAULT; |
48 | rev.verbose_header = 1; | 48 | rev.verbose_header = 1; |
49 | rev.show_root_diff = 0; | 49 | rev.show_root_diff = 0; |
50 | setup_revisions(argc, argv, &rev, NULL); | 50 | setup_revisions(argc, argv, &rev, NULL); |
51 | if (rev.grep_filter) { | 51 | if (rev.grep_filter) { |
52 | rev.grep_filter->regflags |= REG_ICASE; | 52 | rev.grep_filter->regflags |= REG_ICASE; |
53 | compile_grep_patterns(rev.grep_filter); | 53 | compile_grep_patterns(rev.grep_filter); |
54 | } | 54 | } |
55 | prepare_revision_walk(&rev); | 55 | prepare_revision_walk(&rev); |
56 | 56 | ||
57 | html("<h2>Log</h2>"); | ||
58 | html("<table class='list nowrap'>"); | 57 | html("<table class='list nowrap'>"); |
59 | html("<tr class='nohover'><th class='left'>Date</th>" | 58 | html("<tr class='nohover'><th class='left'>Date</th>" |
60 | "<th class='left'>Message</th>" | 59 | "<th class='left'>Message</th>" |
61 | "<th class='left'>Author</th></tr>\n"); | 60 | "<th class='left'>Author</th></tr>\n"); |
62 | 61 | ||
63 | if (ofs<0) | 62 | if (ofs<0) |
64 | ofs = 0; | 63 | ofs = 0; |
65 | 64 | ||
66 | for (i = 0; i < ofs && (commit = get_revision(&rev)) != NULL; i++) { | 65 | for (i = 0; i < ofs && (commit = get_revision(&rev)) != NULL; i++) { |
67 | free(commit->buffer); | 66 | free(commit->buffer); |
68 | commit->buffer = NULL; | 67 | commit->buffer = NULL; |
69 | free_commit_list(commit->parents); | 68 | free_commit_list(commit->parents); |
70 | commit->parents = NULL; | 69 | commit->parents = NULL; |
71 | } | 70 | } |
72 | 71 | ||
73 | for (i = 0; i < cnt && (commit = get_revision(&rev)) != NULL; i++) { | 72 | for (i = 0; i < cnt && (commit = get_revision(&rev)) != NULL; i++) { |
74 | print_commit(commit); | 73 | print_commit(commit); |
75 | free(commit->buffer); | 74 | free(commit->buffer); |
76 | commit->buffer = NULL; | 75 | commit->buffer = NULL; |
77 | free_commit_list(commit->parents); | 76 | free_commit_list(commit->parents); |
78 | commit->parents = NULL; | 77 | commit->parents = NULL; |
79 | } | 78 | } |
80 | html("</table>\n"); | 79 | html("</table>\n"); |
81 | 80 | ||
82 | html("<div class='pager'>"); | 81 | html("<div class='pager'>"); |
83 | if (ofs > 0) { | 82 | if (ofs > 0) { |
84 | html(" <a href='"); | 83 | html(" <a href='"); |
85 | html(cgit_pageurl(cgit_query_repo, cgit_query_page, | 84 | html(cgit_pageurl(cgit_query_repo, cgit_query_page, |
86 | fmt("h=%s&ofs=%d", tip, ofs-cnt))); | 85 | fmt("h=%s&ofs=%d", tip, ofs-cnt))); |
87 | html("'>[prev]</a> "); | 86 | html("'>[prev]</a> "); |
88 | } | 87 | } |
89 | 88 | ||
90 | if ((commit = get_revision(&rev)) != NULL) { | 89 | if ((commit = get_revision(&rev)) != NULL) { |
91 | html(" <a href='"); | 90 | html(" <a href='"); |
92 | html(cgit_pageurl(cgit_query_repo, "log", | 91 | html(cgit_pageurl(cgit_query_repo, "log", |
93 | fmt("h=%s&ofs=%d", tip, ofs+cnt))); | 92 | fmt("h=%s&ofs=%d", tip, ofs+cnt))); |
94 | html("'>[next]</a> "); | 93 | html("'>[next]</a> "); |
95 | } | 94 | } |
96 | html("</div>"); | 95 | html("</div>"); |
97 | } | 96 | } |
98 | 97 | ||
diff --git a/ui-repolist.c b/ui-repolist.c index 011ec95..2ce0d6a 100644 --- a/ui-repolist.c +++ b/ui-repolist.c | |||
@@ -1,40 +1,39 @@ | |||
1 | /* ui-repolist.c: functions for generating the repolist page | 1 | /* ui-repolist.c: functions for generating the repolist page |
2 | * | 2 | * |
3 | * Copyright (C) 2006 Lars Hjemli | 3 | * Copyright (C) 2006 Lars Hjemli |
4 | * | 4 | * |
5 | * Licensed under GNU General Public License v2 | 5 | * Licensed under GNU General Public License v2 |
6 | * (see COPYING for full license text) | 6 | * (see COPYING for full license text) |
7 | */ | 7 | */ |
8 | 8 | ||
9 | #include "cgit.h" | 9 | #include "cgit.h" |
10 | 10 | ||
11 | void cgit_print_repolist(struct cacheitem *item) | 11 | void cgit_print_repolist(struct cacheitem *item) |
12 | { | 12 | { |
13 | struct repoinfo *repo; | 13 | struct repoinfo *repo; |
14 | int i; | 14 | int i; |
15 | 15 | ||
16 | cgit_print_docstart(cgit_root_title, item); | 16 | cgit_print_docstart(cgit_root_title, item); |
17 | cgit_print_pageheader(cgit_root_title, 0); | 17 | cgit_print_pageheader(cgit_root_title, 0); |
18 | 18 | ||
19 | html("<h2>Repositories</h2>\n"); | ||
20 | html("<table class='list nowrap'>"); | 19 | html("<table class='list nowrap'>"); |
21 | html("<tr class='nohover'>" | 20 | html("<tr class='nohover'>" |
22 | "<th class='left'>Name</th>" | 21 | "<th class='left'>Name</th>" |
23 | "<th class='left'>Description</th>" | 22 | "<th class='left'>Description</th>" |
24 | "<th class='left'>Owner</th></tr>\n"); | 23 | "<th class='left'>Owner</th></tr>\n"); |
25 | 24 | ||
26 | for (i=0; i<cgit_repolist.count; i++) { | 25 | for (i=0; i<cgit_repolist.count; i++) { |
27 | repo = &cgit_repolist.repos[i]; | 26 | repo = &cgit_repolist.repos[i]; |
28 | html("<tr><td>"); | 27 | html("<tr><td>"); |
29 | html_link_open(cgit_repourl(repo->url), NULL, NULL); | 28 | html_link_open(cgit_repourl(repo->url), NULL, NULL); |
30 | html_txt(repo->name); | 29 | html_txt(repo->name); |
31 | html_link_close(); | 30 | html_link_close(); |
32 | html("</td><td>"); | 31 | html("</td><td>"); |
33 | html_txt(repo->desc); | 32 | html_txt(repo->desc); |
34 | html("</td><td>"); | 33 | html("</td><td>"); |
35 | html_txt(repo->owner); | 34 | html_txt(repo->owner); |
36 | html("</td></tr>\n"); | 35 | html("</td></tr>\n"); |
37 | } | 36 | } |
38 | html("</table>"); | 37 | html("</table>"); |
39 | cgit_print_docend(); | 38 | cgit_print_docend(); |
40 | } | 39 | } |
diff --git a/ui-shared.c b/ui-shared.c index 172499c..bca50aa 100644 --- a/ui-shared.c +++ b/ui-shared.c | |||
@@ -1,157 +1,174 @@ | |||
1 | /* ui-shared.c: common web output functions | 1 | /* ui-shared.c: common web output functions |
2 | * | 2 | * |
3 | * Copyright (C) 2006 Lars Hjemli | 3 | * Copyright (C) 2006 Lars Hjemli |
4 | * | 4 | * |
5 | * Licensed under GNU General Public License v2 | 5 | * Licensed under GNU General Public License v2 |
6 | * (see COPYING for full license text) | 6 | * (see COPYING for full license text) |
7 | */ | 7 | */ |
8 | 8 | ||
9 | #include "cgit.h" | 9 | #include "cgit.h" |
10 | 10 | ||
11 | const char cgit_doctype[] = | 11 | const char cgit_doctype[] = |
12 | "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n" | 12 | "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n" |
13 | " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"; | 13 | " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"; |
14 | 14 | ||
15 | static char *http_date(time_t t) | 15 | static char *http_date(time_t t) |
16 | { | 16 | { |
17 | static char day[][4] = | 17 | static char day[][4] = |
18 | {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; | 18 | {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; |
19 | static char month[][4] = | 19 | static char month[][4] = |
20 | {"Jan", "Feb", "Mar", "Apr", "May", "Jun", | 20 | {"Jan", "Feb", "Mar", "Apr", "May", "Jun", |
21 | "Jul", "Aug", "Sep", "Oct", "Now", "Dec"}; | 21 | "Jul", "Aug", "Sep", "Oct", "Now", "Dec"}; |
22 | struct tm *tm = gmtime(&t); | 22 | struct tm *tm = gmtime(&t); |
23 | return fmt("%s, %02d %s %04d %02d:%02d:%02d GMT", day[tm->tm_wday], | 23 | return fmt("%s, %02d %s %04d %02d:%02d:%02d GMT", day[tm->tm_wday], |
24 | tm->tm_mday, month[tm->tm_mon], 1900+tm->tm_year, | 24 | tm->tm_mday, month[tm->tm_mon], 1900+tm->tm_year, |
25 | tm->tm_hour, tm->tm_min, tm->tm_sec); | 25 | tm->tm_hour, tm->tm_min, tm->tm_sec); |
26 | } | 26 | } |
27 | 27 | ||
28 | static long ttl_seconds(long ttl) | 28 | static long ttl_seconds(long ttl) |
29 | { | 29 | { |
30 | if (ttl<0) | 30 | if (ttl<0) |
31 | return 60 * 60 * 24 * 365; | 31 | return 60 * 60 * 24 * 365; |
32 | else | 32 | else |
33 | return ttl * 60; | 33 | return ttl * 60; |
34 | } | 34 | } |
35 | 35 | ||
36 | void cgit_print_error(char *msg) | 36 | void cgit_print_error(char *msg) |
37 | { | 37 | { |
38 | html("<div class='error'>"); | 38 | html("<div class='error'>"); |
39 | html_txt(msg); | 39 | html_txt(msg); |
40 | html("</div>\n"); | 40 | html("</div>\n"); |
41 | } | 41 | } |
42 | 42 | ||
43 | char *cgit_rooturl() | ||
44 | { | ||
45 | if (cgit_virtual_root) | ||
46 | return fmt("%s/", cgit_virtual_root); | ||
47 | else | ||
48 | return "./cgit.cgi"; | ||
49 | } | ||
50 | |||
43 | char *cgit_repourl(const char *reponame) | 51 | char *cgit_repourl(const char *reponame) |
44 | { | 52 | { |
45 | if (cgit_virtual_root) { | 53 | if (cgit_virtual_root) { |
46 | return fmt("%s/%s/", cgit_virtual_root, reponame); | 54 | return fmt("%s/%s/", cgit_virtual_root, reponame); |
47 | } else { | 55 | } else { |
48 | return fmt("?r=%s", reponame); | 56 | return fmt("?r=%s", reponame); |
49 | } | 57 | } |
50 | } | 58 | } |
51 | 59 | ||
52 | char *cgit_pageurl(const char *reponame, const char *pagename, | 60 | char *cgit_pageurl(const char *reponame, const char *pagename, |
53 | const char *query) | 61 | const char *query) |
54 | { | 62 | { |
55 | if (cgit_virtual_root) { | 63 | if (cgit_virtual_root) { |
56 | return fmt("%s/%s/%s/?%s", cgit_virtual_root, reponame, | 64 | return fmt("%s/%s/%s/?%s", cgit_virtual_root, reponame, |
57 | pagename, query); | 65 | pagename, query); |
58 | } else { | 66 | } else { |
59 | return fmt("?r=%s&p=%s&%s", reponame, pagename, query); | 67 | return fmt("?r=%s&p=%s&%s", reponame, pagename, query); |
60 | } | 68 | } |
61 | } | 69 | } |
62 | 70 | ||
63 | char *cgit_currurl() | 71 | char *cgit_currurl() |
64 | { | 72 | { |
65 | if (!cgit_virtual_root) | 73 | if (!cgit_virtual_root) |
66 | return "./cgit.cgi"; | 74 | return "./cgit.cgi"; |
67 | else if (cgit_query_page) | 75 | else if (cgit_query_page) |
68 | return fmt("%s/%s/%s/", cgit_virtual_root, cgit_query_repo, cgit_query_page); | 76 | return fmt("%s/%s/%s/", cgit_virtual_root, cgit_query_repo, cgit_query_page); |
69 | else if (cgit_query_repo) | 77 | else if (cgit_query_repo) |
70 | return fmt("%s/%s/", cgit_virtual_root, cgit_query_repo); | 78 | return fmt("%s/%s/", cgit_virtual_root, cgit_query_repo); |
71 | else | 79 | else |
72 | return fmt("%s/", cgit_virtual_root); | 80 | return fmt("%s/", cgit_virtual_root); |
73 | } | 81 | } |
74 | 82 | ||
75 | 83 | ||
76 | void cgit_print_date(unsigned long secs) | 84 | void cgit_print_date(unsigned long secs) |
77 | { | 85 | { |
78 | char buf[32]; | 86 | char buf[32]; |
79 | struct tm *time; | 87 | struct tm *time; |
80 | 88 | ||
81 | time = gmtime(&secs); | 89 | time = gmtime(&secs); |
82 | strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", time); | 90 | strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", time); |
83 | html_txt(buf); | 91 | html_txt(buf); |
84 | 92 | ||
85 | } | 93 | } |
86 | 94 | ||
87 | void cgit_print_docstart(char *title, struct cacheitem *item) | 95 | void cgit_print_docstart(char *title, struct cacheitem *item) |
88 | { | 96 | { |
89 | html("Content-Type: text/html; charset=utf-8\n"); | 97 | html("Content-Type: text/html; charset=utf-8\n"); |
90 | htmlf("Last-Modified: %s\n", http_date(item->st.st_mtime)); | 98 | htmlf("Last-Modified: %s\n", http_date(item->st.st_mtime)); |
91 | htmlf("Expires: %s\n", http_date(item->st.st_mtime + | 99 | htmlf("Expires: %s\n", http_date(item->st.st_mtime + |
92 | ttl_seconds(item->ttl))); | 100 | ttl_seconds(item->ttl))); |
93 | html("\n"); | 101 | html("\n"); |
94 | html(cgit_doctype); | 102 | html(cgit_doctype); |
95 | html("<html>\n"); | 103 | html("<html>\n"); |
96 | html("<head>\n"); | 104 | html("<head>\n"); |
97 | html("<title>"); | 105 | html("<title>"); |
98 | html_txt(title); | 106 | html_txt(title); |
99 | html("</title>\n"); | 107 | html("</title>\n"); |
100 | htmlf("<meta name='generator' content='cgit v%s'/>\n", cgit_version); | 108 | htmlf("<meta name='generator' content='cgit v%s'/>\n", cgit_version); |
101 | html("<link rel='stylesheet' type='text/css' href='"); | 109 | html("<link rel='stylesheet' type='text/css' href='"); |
102 | html_attr(cgit_css); | 110 | html_attr(cgit_css); |
103 | html("'/>\n"); | 111 | html("'/>\n"); |
104 | html("</head>\n"); | 112 | html("</head>\n"); |
105 | html("<body>\n"); | 113 | html("<body>\n"); |
106 | } | 114 | } |
107 | 115 | ||
108 | void cgit_print_docend() | 116 | void cgit_print_docend() |
109 | { | 117 | { |
110 | html("</td></tr></table>"); | 118 | html("</td></tr></table>"); |
111 | html("</body>\n</html>\n"); | 119 | html("</body>\n</html>\n"); |
112 | } | 120 | } |
113 | 121 | ||
114 | void cgit_print_pageheader(char *title, int show_search) | 122 | void cgit_print_pageheader(char *title, int show_search) |
115 | { | 123 | { |
116 | html("<table id='layout'><tr><td id='header'>"); | 124 | html("<table id='layout'>"); |
117 | htmlf("<a href='%s'>", cgit_logo_link); | 125 | html("<tr><td id='header'>"); |
118 | htmlf("<img id='logo' src='%s'/>\n", cgit_logo); | 126 | html(cgit_root_title); |
119 | htmlf("</a>"); | 127 | html("</td><td id='logo'>"); |
128 | html("<a href='"); | ||
129 | html_attr(cgit_logo_link); | ||
130 | htmlf("'><img src='%s'/></a>", cgit_logo); | ||
131 | html("</td></tr>"); | ||
132 | html("<tr><td id='crumb'>"); | ||
133 | htmlf("<a href='%s'>root</a>", cgit_rooturl()); | ||
134 | if (cgit_query_repo) { | ||
135 | htmlf(" : <a href='%s'>", cgit_repourl(cgit_repo->url)); | ||
136 | html_txt(cgit_repo->name); | ||
137 | htmlf("</a> : %s", title); | ||
138 | } | ||
139 | html("</td>"); | ||
140 | html("<td id='search'>"); | ||
120 | if (show_search) { | 141 | if (show_search) { |
121 | html("<form method='get' href='"); | 142 | html("<form method='get' href='"); |
122 | html_attr(cgit_currurl()); | 143 | html_attr(cgit_currurl()); |
123 | html("'>"); | 144 | html("'>"); |
124 | if (!cgit_virtual_root) { | 145 | if (!cgit_virtual_root) { |
125 | if (cgit_query_repo) | 146 | if (cgit_query_repo) |
126 | html_hidden("r", cgit_query_repo); | 147 | html_hidden("r", cgit_query_repo); |
127 | if (cgit_query_page) | 148 | if (cgit_query_page) |
128 | html_hidden("p", cgit_query_page); | 149 | html_hidden("p", cgit_query_page); |
129 | } | 150 | } |
130 | if (cgit_query_head) | 151 | if (cgit_query_head) |
131 | html_hidden("h", cgit_query_head); | 152 | html_hidden("h", cgit_query_head); |
132 | if (cgit_query_sha1) | 153 | if (cgit_query_sha1) |
133 | html_hidden("id", cgit_query_sha1); | 154 | html_hidden("id", cgit_query_sha1); |
134 | if (cgit_query_sha2) | 155 | if (cgit_query_sha2) |
135 | html_hidden("id2", cgit_query_sha2); | 156 | html_hidden("id2", cgit_query_sha2); |
136 | html("<input type='text' name='q' value='"); | 157 | html("<input type='text' name='q' value='"); |
137 | html_attr(cgit_query_search); | 158 | html_attr(cgit_query_search); |
138 | html("'/></form>"); | 159 | html("'/></form>"); |
139 | } | 160 | } |
140 | if (cgit_query_repo) | 161 | html("</td></tr>"); |
141 | htmlf("<a href='%s'>", cgit_repourl(cgit_query_repo)); | 162 | html("<tr><td id='content' colspan='2'>"); |
142 | html_txt(title); | ||
143 | if (cgit_query_repo) | ||
144 | html("</a>"); | ||
145 | html("</td></tr><tr><td id='content'>"); | ||
146 | } | 163 | } |
147 | 164 | ||
148 | void cgit_print_snapshot_start(const char *mimetype, const char *filename, | 165 | void cgit_print_snapshot_start(const char *mimetype, const char *filename, |
149 | struct cacheitem *item) | 166 | struct cacheitem *item) |
150 | { | 167 | { |
151 | htmlf("Content-Type: %s\n", mimetype); | 168 | htmlf("Content-Type: %s\n", mimetype); |
152 | htmlf("Content-Disposition: inline; filename=\"%s\"\n", filename); | 169 | htmlf("Content-Disposition: inline; filename=\"%s\"\n", filename); |
153 | htmlf("Last-Modified: %s\n", http_date(item->st.st_mtime)); | 170 | htmlf("Last-Modified: %s\n", http_date(item->st.st_mtime)); |
154 | htmlf("Expires: %s\n", http_date(item->st.st_mtime + | 171 | htmlf("Expires: %s\n", http_date(item->st.st_mtime + |
155 | ttl_seconds(item->ttl))); | 172 | ttl_seconds(item->ttl))); |
156 | html("\n"); | 173 | html("\n"); |
157 | } | 174 | } |
diff --git a/ui-summary.c b/ui-summary.c index ff3ed4d..42f4300 100644 --- a/ui-summary.c +++ b/ui-summary.c | |||
@@ -1,139 +1,141 @@ | |||
1 | /* ui-summary.c: functions for generating repo summary page | 1 | /* ui-summary.c: functions for generating repo summary page |
2 | * | 2 | * |
3 | * Copyright (C) 2006 Lars Hjemli | 3 | * Copyright (C) 2006 Lars Hjemli |
4 | * | 4 | * |
5 | * Licensed under GNU General Public License v2 | 5 | * Licensed under GNU General Public License v2 |
6 | * (see COPYING for full license text) | 6 | * (see COPYING for full license text) |
7 | */ | 7 | */ |
8 | 8 | ||
9 | #include "cgit.h" | 9 | #include "cgit.h" |
10 | 10 | ||
11 | static int cgit_print_branch_cb(const char *refname, const unsigned char *sha1, | 11 | static int cgit_print_branch_cb(const char *refname, const unsigned char *sha1, |
12 | int flags, void *cb_data) | 12 | int flags, void *cb_data) |
13 | { | 13 | { |
14 | struct commit *commit; | 14 | struct commit *commit; |
15 | struct commitinfo *info; | 15 | struct commitinfo *info; |
16 | char buf[256], *url; | 16 | char buf[256], *url; |
17 | 17 | ||
18 | strncpy(buf, refname, sizeof(buf)); | 18 | strncpy(buf, refname, sizeof(buf)); |
19 | commit = lookup_commit(sha1); | 19 | commit = lookup_commit(sha1); |
20 | if (commit && !parse_commit(commit)){ | 20 | if (commit && !parse_commit(commit)){ |
21 | info = cgit_parse_commit(commit); | 21 | info = cgit_parse_commit(commit); |
22 | html("<tr><td>"); | 22 | html("<tr><td>"); |
23 | url = cgit_pageurl(cgit_query_repo, "log", | 23 | url = cgit_pageurl(cgit_query_repo, "log", |
24 | fmt("h=%s", refname)); | 24 | fmt("h=%s", refname)); |
25 | html_link_open(url, NULL, NULL); | 25 | html_link_open(url, NULL, NULL); |
26 | html_txt(buf); | 26 | html_txt(buf); |
27 | html_link_close(); | 27 | html_link_close(); |
28 | html("</td><td>"); | 28 | html("</td><td>"); |
29 | cgit_print_date(commit->date); | 29 | cgit_print_date(commit->date); |
30 | html("</td><td>"); | 30 | html("</td><td>"); |
31 | html_txt(info->author); | 31 | html_txt(info->author); |
32 | html("</td><td>"); | 32 | html("</td><td>"); |
33 | url = cgit_pageurl(cgit_query_repo, "commit", | 33 | url = cgit_pageurl(cgit_query_repo, "commit", |
34 | fmt("id=%s", sha1_to_hex(sha1))); | 34 | fmt("id=%s", sha1_to_hex(sha1))); |
35 | html_link_open(url, NULL, NULL); | 35 | html_link_open(url, NULL, NULL); |
36 | html_ntxt(cgit_max_msg_len, info->subject); | 36 | html_ntxt(cgit_max_msg_len, info->subject); |
37 | html_link_close(); | 37 | html_link_close(); |
38 | html("</td></tr>\n"); | 38 | html("</td></tr>\n"); |
39 | cgit_free_commitinfo(info); | 39 | cgit_free_commitinfo(info); |
40 | } else { | 40 | } else { |
41 | html("<tr><td>"); | 41 | html("<tr><td>"); |
42 | html_txt(buf); | 42 | html_txt(buf); |
43 | html("</td><td colspan='3'>"); | 43 | html("</td><td colspan='3'>"); |
44 | htmlf("*** bad ref %s ***", sha1_to_hex(sha1)); | 44 | htmlf("*** bad ref %s ***", sha1_to_hex(sha1)); |
45 | html("</td></tr>\n"); | 45 | html("</td></tr>\n"); |
46 | } | 46 | } |
47 | return 0; | 47 | return 0; |
48 | } | 48 | } |
49 | 49 | ||
50 | 50 | ||
51 | static void cgit_print_object_ref(struct object *obj) | 51 | static void cgit_print_object_ref(struct object *obj) |
52 | { | 52 | { |
53 | char *page, *url; | 53 | char *page, *url; |
54 | 54 | ||
55 | if (obj->type == OBJ_COMMIT) | 55 | if (obj->type == OBJ_COMMIT) |
56 | page = "commit"; | 56 | page = "commit"; |
57 | else if (obj->type == OBJ_TREE) | 57 | else if (obj->type == OBJ_TREE) |
58 | page = "tree"; | 58 | page = "tree"; |
59 | else | 59 | else |
60 | page = "view"; | 60 | page = "view"; |
61 | 61 | ||
62 | url = cgit_pageurl(cgit_query_repo, page, | 62 | url = cgit_pageurl(cgit_query_repo, page, |
63 | fmt("id=%s", sha1_to_hex(obj->sha1))); | 63 | fmt("id=%s", sha1_to_hex(obj->sha1))); |
64 | html_link_open(url, NULL, NULL); | 64 | html_link_open(url, NULL, NULL); |
65 | htmlf("%s %s", type_names[obj->type], | 65 | htmlf("%s %s", type_names[obj->type], |
66 | sha1_to_hex(obj->sha1)); | 66 | sha1_to_hex(obj->sha1)); |
67 | html_link_close(); | 67 | html_link_close(); |
68 | } | 68 | } |
69 | 69 | ||
70 | static int cgit_print_tag_cb(const char *refname, const unsigned char *sha1, | 70 | static int cgit_print_tag_cb(const char *refname, const unsigned char *sha1, |
71 | int flags, void *cb_data) | 71 | int flags, void *cb_data) |
72 | { | 72 | { |
73 | struct tag *tag; | 73 | struct tag *tag; |
74 | struct taginfo *info; | 74 | struct taginfo *info; |
75 | struct object *obj; | 75 | struct object *obj; |
76 | char buf[256], *url; | 76 | char buf[256], *url; |
77 | 77 | ||
78 | strncpy(buf, refname, sizeof(buf)); | 78 | strncpy(buf, refname, sizeof(buf)); |
79 | obj = parse_object(sha1); | 79 | obj = parse_object(sha1); |
80 | if (!obj) | 80 | if (!obj) |
81 | return 1; | 81 | return 1; |
82 | if (obj->type == OBJ_TAG) { | 82 | if (obj->type == OBJ_TAG) { |
83 | tag = lookup_tag(sha1); | 83 | tag = lookup_tag(sha1); |
84 | if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) | 84 | if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) |
85 | return 2; | 85 | return 2; |
86 | html("<tr><td>"); | 86 | html("<tr><td>"); |
87 | url = cgit_pageurl(cgit_query_repo, "view", | 87 | url = cgit_pageurl(cgit_query_repo, "view", |
88 | fmt("id=%s", sha1_to_hex(sha1))); | 88 | fmt("id=%s", sha1_to_hex(sha1))); |
89 | html_link_open(url, NULL, NULL); | 89 | html_link_open(url, NULL, NULL); |
90 | html_txt(buf); | 90 | html_txt(buf); |
91 | html_link_close(); | 91 | html_link_close(); |
92 | html("</td><td>"); | 92 | html("</td><td>"); |
93 | if (info->tagger_date > 0) | 93 | if (info->tagger_date > 0) |
94 | cgit_print_date(info->tagger_date); | 94 | cgit_print_date(info->tagger_date); |
95 | html("</td><td>"); | 95 | html("</td><td>"); |
96 | if (info->tagger) | 96 | if (info->tagger) |
97 | html(info->tagger); | 97 | html(info->tagger); |
98 | html("</td><td>"); | 98 | html("</td><td>"); |
99 | cgit_print_object_ref(tag->tagged); | 99 | cgit_print_object_ref(tag->tagged); |
100 | html("</td></tr>\n"); | 100 | html("</td></tr>\n"); |
101 | } else { | 101 | } else { |
102 | html("<tr><td>"); | 102 | html("<tr><td>"); |
103 | html_txt(buf); | 103 | html_txt(buf); |
104 | html("</td><td colspan='2'/><td>"); | 104 | html("</td><td colspan='2'/><td>"); |
105 | cgit_print_object_ref(obj); | 105 | cgit_print_object_ref(obj); |
106 | html("</td></tr>\n"); | 106 | html("</td></tr>\n"); |
107 | } | 107 | } |
108 | return 0; | 108 | return 0; |
109 | } | 109 | } |
110 | 110 | ||
111 | static void cgit_print_branches() | 111 | static void cgit_print_branches() |
112 | { | 112 | { |
113 | html("<tr class='nohover'><th class='left'>Branch</th>" | 113 | html("<tr class='nohover'><th class='left'>Branch</th>" |
114 | "<th class='left'>Updated</th>" | 114 | "<th class='left'>Updated</th>" |
115 | "<th class='left'>Author</th>" | 115 | "<th class='left'>Author</th>" |
116 | "<th class='left'>Head commit</th></tr>\n"); | 116 | "<th class='left'>Head commit</th></tr>\n"); |
117 | for_each_branch_ref(cgit_print_branch_cb, NULL); | 117 | for_each_branch_ref(cgit_print_branch_cb, NULL); |
118 | } | 118 | } |
119 | 119 | ||
120 | static void cgit_print_tags() | 120 | static void cgit_print_tags() |
121 | { | 121 | { |
122 | html("<tr class='nohover'><th class='left'>Tag</th>" | 122 | html("<tr class='nohover'><th class='left'>Tag</th>" |
123 | "<th class='left'>Created</th>" | 123 | "<th class='left'>Created</th>" |
124 | "<th class='left'>Author</th>" | 124 | "<th class='left'>Author</th>" |
125 | "<th class='left'>Reference</th></tr>\n"); | 125 | "<th class='left'>Reference</th></tr>\n"); |
126 | for_each_tag_ref(cgit_print_tag_cb, NULL); | 126 | for_each_tag_ref(cgit_print_tag_cb, NULL); |
127 | } | 127 | } |
128 | 128 | ||
129 | void cgit_print_summary() | 129 | void cgit_print_summary() |
130 | { | 130 | { |
131 | html("<h2>"); | 131 | html("<h2>"); |
132 | html_txt("Repo summary page"); | 132 | html(cgit_repo->name); |
133 | html("</h2>"); | 133 | html("</h2><h3>"); |
134 | html(cgit_repo->desc); | ||
135 | html("</h3>"); | ||
134 | html("<table class='list nowrap'>"); | 136 | html("<table class='list nowrap'>"); |
135 | cgit_print_branches(); | 137 | cgit_print_branches(); |
136 | html("<tr class='nohover'><td colspan='4'> </td></tr>"); | 138 | html("<tr class='nohover'><td colspan='4'> </td></tr>"); |
137 | cgit_print_tags(); | 139 | cgit_print_tags(); |
138 | html("</table>"); | 140 | html("</table>"); |
139 | } | 141 | } |
@@ -1,79 +1,78 @@ | |||
1 | /* ui-tree.c: functions for tree output | 1 | /* ui-tree.c: functions for tree output |
2 | * | 2 | * |
3 | * Copyright (C) 2006 Lars Hjemli | 3 | * Copyright (C) 2006 Lars Hjemli |
4 | * | 4 | * |
5 | * Licensed under GNU General Public License v2 | 5 | * Licensed under GNU General Public License v2 |
6 | * (see COPYING for full license text) | 6 | * (see COPYING for full license text) |
7 | */ | 7 | */ |
8 | 8 | ||
9 | #include "cgit.h" | 9 | #include "cgit.h" |
10 | 10 | ||
11 | 11 | ||
12 | static int print_entry(const unsigned char *sha1, const char *base, | 12 | static int print_entry(const unsigned char *sha1, const char *base, |
13 | int baselen, const char *pathname, unsigned int mode, | 13 | int baselen, const char *pathname, unsigned int mode, |
14 | int stage) | 14 | int stage) |
15 | { | 15 | { |
16 | char *name; | 16 | char *name; |
17 | char type[20]; | 17 | char type[20]; |
18 | unsigned long size; | 18 | unsigned long size; |
19 | 19 | ||
20 | if (sha1_object_info(sha1, type, &size)) { | 20 | if (sha1_object_info(sha1, type, &size)) { |
21 | cgit_print_error(fmt("Bad object name: %s", | 21 | cgit_print_error(fmt("Bad object name: %s", |
22 | sha1_to_hex(sha1))); | 22 | sha1_to_hex(sha1))); |
23 | return 0; | 23 | return 0; |
24 | } | 24 | } |
25 | name = xstrdup(pathname); | 25 | name = xstrdup(pathname); |
26 | html("<tr><td class='filemode'>"); | 26 | html("<tr><td class='filemode'>"); |
27 | html_filemode(mode); | 27 | html_filemode(mode); |
28 | html("</td><td>"); | 28 | html("</td><td>"); |
29 | if (S_ISDIR(mode)) { | 29 | if (S_ISDIR(mode)) { |
30 | html("<div class='ls-dir'><a href='"); | 30 | html("<div class='ls-dir'><a href='"); |
31 | html_attr(cgit_pageurl(cgit_query_repo, "tree", | 31 | html_attr(cgit_pageurl(cgit_query_repo, "tree", |
32 | fmt("id=%s&path=%s%s/", | 32 | fmt("id=%s&path=%s%s/", |
33 | sha1_to_hex(sha1), | 33 | sha1_to_hex(sha1), |
34 | cgit_query_path ? cgit_query_path : "", | 34 | cgit_query_path ? cgit_query_path : "", |
35 | pathname))); | 35 | pathname))); |
36 | } else { | 36 | } else { |
37 | html("<div class='ls-blob'><a href='"); | 37 | html("<div class='ls-blob'><a href='"); |
38 | html_attr(cgit_pageurl(cgit_query_repo, "view", | 38 | html_attr(cgit_pageurl(cgit_query_repo, "view", |
39 | fmt("id=%s&path=%s%s", sha1_to_hex(sha1), | 39 | fmt("id=%s&path=%s%s", sha1_to_hex(sha1), |
40 | cgit_query_path ? cgit_query_path : "", | 40 | cgit_query_path ? cgit_query_path : "", |
41 | pathname))); | 41 | pathname))); |
42 | } | 42 | } |
43 | html("'>"); | 43 | html("'>"); |
44 | html_txt(name); | 44 | html_txt(name); |
45 | if (S_ISDIR(mode)) | 45 | if (S_ISDIR(mode)) |
46 | html("/"); | 46 | html("/"); |
47 | html("</a></div></td>"); | 47 | html("</a></div></td>"); |
48 | htmlf("<td class='filesize'>%li</td>", size); | 48 | htmlf("<td class='filesize'>%li</td>", size); |
49 | html("</tr>\n"); | 49 | html("</tr>\n"); |
50 | free(name); | 50 | free(name); |
51 | return 0; | 51 | return 0; |
52 | } | 52 | } |
53 | 53 | ||
54 | void cgit_print_tree(const char *hex, char *path) | 54 | void cgit_print_tree(const char *hex, char *path) |
55 | { | 55 | { |
56 | struct tree *tree; | 56 | struct tree *tree; |
57 | unsigned char sha1[20]; | 57 | unsigned char sha1[20]; |
58 | 58 | ||
59 | if (get_sha1_hex(hex, sha1)) { | 59 | if (get_sha1_hex(hex, sha1)) { |
60 | cgit_print_error(fmt("Invalid object id: %s", hex)); | 60 | cgit_print_error(fmt("Invalid object id: %s", hex)); |
61 | return; | 61 | return; |
62 | } | 62 | } |
63 | tree = parse_tree_indirect(sha1); | 63 | tree = parse_tree_indirect(sha1); |
64 | if (!tree) { | 64 | if (!tree) { |
65 | cgit_print_error(fmt("Not a tree object: %s", hex)); | 65 | cgit_print_error(fmt("Not a tree object: %s", hex)); |
66 | return; | 66 | return; |
67 | } | 67 | } |
68 | 68 | ||
69 | html("<h2>Tree content</h2>\n"); | ||
70 | html_txt(path); | 69 | html_txt(path); |
71 | html("<table class='list'>\n"); | 70 | html("<table class='list'>\n"); |
72 | html("<tr class='nohover'>"); | 71 | html("<tr class='nohover'>"); |
73 | html("<th class='left'>Mode</th>"); | 72 | html("<th class='left'>Mode</th>"); |
74 | html("<th class='left'>Name</th>"); | 73 | html("<th class='left'>Name</th>"); |
75 | html("<th class='right'>Size</th>"); | 74 | html("<th class='right'>Size</th>"); |
76 | html("</tr>\n"); | 75 | html("</tr>\n"); |
77 | read_tree_recursive(tree, "", 0, 1, NULL, print_entry); | 76 | read_tree_recursive(tree, "", 0, 1, NULL, print_entry); |
78 | html("</table>\n"); | 77 | html("</table>\n"); |
79 | } | 78 | } |
@@ -1,42 +1,41 @@ | |||
1 | /* ui-view.c: functions to output _any_ object, given it's sha1 | 1 | /* ui-view.c: functions to output _any_ object, given it's sha1 |
2 | * | 2 | * |
3 | * Copyright (C) 2006 Lars Hjemli | 3 | * Copyright (C) 2006 Lars Hjemli |
4 | * | 4 | * |
5 | * Licensed under GNU General Public License v2 | 5 | * Licensed under GNU General Public License v2 |
6 | * (see COPYING for full license text) | 6 | * (see COPYING for full license text) |
7 | */ | 7 | */ |
8 | 8 | ||
9 | #include "cgit.h" | 9 | #include "cgit.h" |
10 | 10 | ||
11 | void cgit_print_view(const char *hex) | 11 | void cgit_print_view(const char *hex) |
12 | { | 12 | { |
13 | unsigned char sha1[20]; | 13 | unsigned char sha1[20]; |
14 | char type[20]; | 14 | char type[20]; |
15 | unsigned char *buf; | 15 | unsigned char *buf; |
16 | unsigned long size; | 16 | unsigned long size; |
17 | 17 | ||
18 | if (get_sha1_hex(hex, sha1)){ | 18 | if (get_sha1_hex(hex, sha1)){ |
19 | cgit_print_error(fmt("Bad hex value: %s", hex)); | 19 | cgit_print_error(fmt("Bad hex value: %s", hex)); |
20 | return; | 20 | return; |
21 | } | 21 | } |
22 | 22 | ||
23 | if (sha1_object_info(sha1, type, &size)){ | 23 | if (sha1_object_info(sha1, type, &size)){ |
24 | cgit_print_error("Bad object name"); | 24 | cgit_print_error("Bad object name"); |
25 | return; | 25 | return; |
26 | } | 26 | } |
27 | 27 | ||
28 | buf = read_sha1_file(sha1, type, &size); | 28 | buf = read_sha1_file(sha1, type, &size); |
29 | if (!buf) { | 29 | if (!buf) { |
30 | cgit_print_error("Error reading object"); | 30 | cgit_print_error("Error reading object"); |
31 | return; | 31 | return; |
32 | } | 32 | } |
33 | 33 | ||
34 | buf[size] = '\0'; | 34 | buf[size] = '\0'; |
35 | html("<h2>Object content</h2>\n"); | ||
36 | html("<table class='list'>\n"); | 35 | html("<table class='list'>\n"); |
37 | htmlf("<tr class='nohover'><th class='left'>%s %s, %li bytes</th></tr>\n", type, hex, size); | 36 | htmlf("<tr class='nohover'><th class='left'>%s %s, %li bytes</th></tr>\n", type, hex, size); |
38 | html("<tr><td class='blob'>\n"); | 37 | html("<tr><td class='blob'>\n"); |
39 | html_txt(buf); | 38 | html_txt(buf); |
40 | html("\n</td></tr>\n"); | 39 | html("\n</td></tr>\n"); |
41 | html("</table>\n"); | 40 | html("</table>\n"); |
42 | } | 41 | } |