author | Lars Hjemli <hjemli@gmail.com> | 2007-05-14 09:10:59 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2007-05-14 09:13:18 (UTC) |
commit | 9fb53af215639fcd3bfb876fa9c8bac221244bdf (patch) (unidiff) | |
tree | 3ebbebebed59b53066e16720a32e1b34c54dc609 | |
parent | 4fdf571c888fd38ae362684c429a3bdf24240ef7 (diff) | |
download | cgit-9fb53af215639fcd3bfb876fa9c8bac221244bdf.zip cgit-9fb53af215639fcd3bfb876fa9c8bac221244bdf.tar.gz cgit-9fb53af215639fcd3bfb876fa9c8bac221244bdf.tar.bz2 |
Add log filtering by path and link to it from tree view
This enables path-filtering in log-view, and adds a link per entry in
tree-view to show the log for each file/directory.
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
-rw-r--r-- | cgit.c | 5 | ||||
-rw-r--r-- | cgit.css | 5 | ||||
-rw-r--r-- | cgit.h | 4 | ||||
-rw-r--r-- | ui-commit.c | 3 | ||||
-rw-r--r-- | ui-log.c | 8 | ||||
-rw-r--r-- | ui-tree.c | 25 |
6 files changed, 37 insertions, 13 deletions
@@ -1,259 +1,260 @@ | |||
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_query_page) { | 82 | if (cgit_query_page) { |
83 | if (cgit_repo->snapshots && !strcmp(cgit_query_page, "snapshot")) { | 83 | if (cgit_repo->snapshots && !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 | if (!strcmp(cgit_query_page, "blob")) { | 88 | if (!strcmp(cgit_query_page, "blob")) { |
89 | cgit_print_blob(item, cgit_query_sha1, cgit_query_path); | 89 | cgit_print_blob(item, cgit_query_sha1, cgit_query_path); |
90 | return; | 90 | return; |
91 | } | 91 | } |
92 | } | 92 | } |
93 | 93 | ||
94 | if (cgit_query_page && !strcmp(cgit_query_page, "log")) | 94 | if (cgit_query_page && !strcmp(cgit_query_page, "log")) |
95 | show_search = 1; | 95 | show_search = 1; |
96 | 96 | ||
97 | cgit_print_docstart(title, item); | 97 | cgit_print_docstart(title, item); |
98 | 98 | ||
99 | 99 | ||
100 | if (!cgit_query_page) { | 100 | if (!cgit_query_page) { |
101 | cgit_print_pageheader("summary", show_search); | 101 | cgit_print_pageheader("summary", show_search); |
102 | cgit_print_summary(); | 102 | cgit_print_summary(); |
103 | cgit_print_docend(); | 103 | cgit_print_docend(); |
104 | return; | 104 | return; |
105 | } | 105 | } |
106 | 106 | ||
107 | cgit_print_pageheader(cgit_query_page, show_search); | 107 | cgit_print_pageheader(cgit_query_page, show_search); |
108 | 108 | ||
109 | if (!strcmp(cgit_query_page, "log")) { | 109 | if (!strcmp(cgit_query_page, "log")) { |
110 | cgit_print_log(cgit_query_head, cgit_query_ofs, | 110 | cgit_print_log(cgit_query_head, cgit_query_ofs, |
111 | cgit_max_commit_count, cgit_query_search); | 111 | cgit_max_commit_count, cgit_query_search, |
112 | cgit_query_path); | ||
112 | } else if (!strcmp(cgit_query_page, "tree")) { | 113 | } else if (!strcmp(cgit_query_page, "tree")) { |
113 | cgit_print_tree(cgit_query_sha1, cgit_query_path); | 114 | cgit_print_tree(cgit_query_head, cgit_query_sha1, cgit_query_path); |
114 | } else if (!strcmp(cgit_query_page, "commit")) { | 115 | } else if (!strcmp(cgit_query_page, "commit")) { |
115 | cgit_print_commit(cgit_query_sha1); | 116 | cgit_print_commit(cgit_query_sha1); |
116 | } else if (!strcmp(cgit_query_page, "view")) { | 117 | } else if (!strcmp(cgit_query_page, "view")) { |
117 | cgit_print_view(cgit_query_sha1, cgit_query_path); | 118 | cgit_print_view(cgit_query_sha1, cgit_query_path); |
118 | } else if (!strcmp(cgit_query_page, "diff")) { | 119 | } else if (!strcmp(cgit_query_page, "diff")) { |
119 | cgit_print_diff(cgit_query_sha1, cgit_query_sha2, cgit_query_path); | 120 | cgit_print_diff(cgit_query_sha1, cgit_query_sha2, cgit_query_path); |
120 | } else { | 121 | } else { |
121 | cgit_print_error("Invalid request"); | 122 | cgit_print_error("Invalid request"); |
122 | } | 123 | } |
123 | cgit_print_docend(); | 124 | cgit_print_docend(); |
124 | } | 125 | } |
125 | 126 | ||
126 | static void cgit_fill_cache(struct cacheitem *item, int use_cache) | 127 | static void cgit_fill_cache(struct cacheitem *item, int use_cache) |
127 | { | 128 | { |
128 | static char buf[PATH_MAX]; | 129 | static char buf[PATH_MAX]; |
129 | int stdout2; | 130 | int stdout2; |
130 | 131 | ||
131 | getcwd(buf, sizeof(buf)); | 132 | getcwd(buf, sizeof(buf)); |
132 | item->st.st_mtime = time(NULL); | 133 | item->st.st_mtime = time(NULL); |
133 | 134 | ||
134 | if (use_cache) { | 135 | if (use_cache) { |
135 | stdout2 = chk_positive(dup(STDOUT_FILENO), | 136 | stdout2 = chk_positive(dup(STDOUT_FILENO), |
136 | "Preserving STDOUT"); | 137 | "Preserving STDOUT"); |
137 | chk_zero(close(STDOUT_FILENO), "Closing STDOUT"); | 138 | chk_zero(close(STDOUT_FILENO), "Closing STDOUT"); |
138 | chk_positive(dup2(item->fd, STDOUT_FILENO), "Dup2(cachefile)"); | 139 | chk_positive(dup2(item->fd, STDOUT_FILENO), "Dup2(cachefile)"); |
139 | } | 140 | } |
140 | 141 | ||
141 | if (cgit_query_repo) | 142 | if (cgit_query_repo) |
142 | cgit_print_repo_page(item); | 143 | cgit_print_repo_page(item); |
143 | else | 144 | else |
144 | cgit_print_repolist(item); | 145 | cgit_print_repolist(item); |
145 | 146 | ||
146 | if (use_cache) { | 147 | if (use_cache) { |
147 | chk_zero(close(STDOUT_FILENO), "Close redirected STDOUT"); | 148 | chk_zero(close(STDOUT_FILENO), "Close redirected STDOUT"); |
148 | chk_positive(dup2(stdout2, STDOUT_FILENO), | 149 | chk_positive(dup2(stdout2, STDOUT_FILENO), |
149 | "Restoring original STDOUT"); | 150 | "Restoring original STDOUT"); |
150 | chk_zero(close(stdout2), "Closing temporary STDOUT"); | 151 | chk_zero(close(stdout2), "Closing temporary STDOUT"); |
151 | } | 152 | } |
152 | 153 | ||
153 | chdir(buf); | 154 | chdir(buf); |
154 | } | 155 | } |
155 | 156 | ||
156 | static void cgit_check_cache(struct cacheitem *item) | 157 | static void cgit_check_cache(struct cacheitem *item) |
157 | { | 158 | { |
158 | int i = 0; | 159 | int i = 0; |
159 | 160 | ||
160 | top: | 161 | top: |
161 | if (++i > cgit_max_lock_attempts) { | 162 | if (++i > cgit_max_lock_attempts) { |
162 | die("cgit_refresh_cache: unable to lock %s: %s", | 163 | die("cgit_refresh_cache: unable to lock %s: %s", |
163 | item->name, strerror(errno)); | 164 | item->name, strerror(errno)); |
164 | } | 165 | } |
165 | if (!cache_exist(item)) { | 166 | if (!cache_exist(item)) { |
166 | if (!cache_lock(item)) { | 167 | if (!cache_lock(item)) { |
167 | sleep(1); | 168 | sleep(1); |
168 | goto top; | 169 | goto top; |
169 | } | 170 | } |
170 | if (!cache_exist(item)) { | 171 | if (!cache_exist(item)) { |
171 | cgit_fill_cache(item, 1); | 172 | cgit_fill_cache(item, 1); |
172 | cache_unlock(item); | 173 | cache_unlock(item); |
173 | } else { | 174 | } else { |
174 | cache_cancel_lock(item); | 175 | cache_cancel_lock(item); |
175 | } | 176 | } |
176 | } else if (cache_expired(item) && cache_lock(item)) { | 177 | } else if (cache_expired(item) && cache_lock(item)) { |
177 | if (cache_expired(item)) { | 178 | if (cache_expired(item)) { |
178 | cgit_fill_cache(item, 1); | 179 | cgit_fill_cache(item, 1); |
179 | cache_unlock(item); | 180 | cache_unlock(item); |
180 | } else { | 181 | } else { |
181 | cache_cancel_lock(item); | 182 | cache_cancel_lock(item); |
182 | } | 183 | } |
183 | } | 184 | } |
184 | } | 185 | } |
185 | 186 | ||
186 | static void cgit_print_cache(struct cacheitem *item) | 187 | static void cgit_print_cache(struct cacheitem *item) |
187 | { | 188 | { |
188 | static char buf[4096]; | 189 | static char buf[4096]; |
189 | ssize_t i; | 190 | ssize_t i; |
190 | 191 | ||
191 | int fd = open(item->name, O_RDONLY); | 192 | int fd = open(item->name, O_RDONLY); |
192 | if (fd<0) | 193 | if (fd<0) |
193 | die("Unable to open cached file %s", item->name); | 194 | die("Unable to open cached file %s", item->name); |
194 | 195 | ||
195 | while((i=read(fd, buf, sizeof(buf))) > 0) | 196 | while((i=read(fd, buf, sizeof(buf))) > 0) |
196 | write(STDOUT_FILENO, buf, i); | 197 | write(STDOUT_FILENO, buf, i); |
197 | 198 | ||
198 | close(fd); | 199 | close(fd); |
199 | } | 200 | } |
200 | 201 | ||
201 | static void cgit_parse_args(int argc, const char **argv) | 202 | static void cgit_parse_args(int argc, const char **argv) |
202 | { | 203 | { |
203 | int i; | 204 | int i; |
204 | 205 | ||
205 | for (i = 1; i < argc; i++) { | 206 | for (i = 1; i < argc; i++) { |
206 | if (!strncmp(argv[i], "--cache=", 8)) { | 207 | if (!strncmp(argv[i], "--cache=", 8)) { |
207 | cgit_cache_root = xstrdup(argv[i]+8); | 208 | cgit_cache_root = xstrdup(argv[i]+8); |
208 | } | 209 | } |
209 | if (!strcmp(argv[i], "--nocache")) { | 210 | if (!strcmp(argv[i], "--nocache")) { |
210 | cgit_nocache = 1; | 211 | cgit_nocache = 1; |
211 | } | 212 | } |
212 | if (!strncmp(argv[i], "--query=", 8)) { | 213 | if (!strncmp(argv[i], "--query=", 8)) { |
213 | cgit_querystring = xstrdup(argv[i]+8); | 214 | cgit_querystring = xstrdup(argv[i]+8); |
214 | } | 215 | } |
215 | if (!strncmp(argv[i], "--repo=", 7)) { | 216 | if (!strncmp(argv[i], "--repo=", 7)) { |
216 | cgit_query_repo = xstrdup(argv[i]+7); | 217 | cgit_query_repo = xstrdup(argv[i]+7); |
217 | } | 218 | } |
218 | if (!strncmp(argv[i], "--page=", 7)) { | 219 | if (!strncmp(argv[i], "--page=", 7)) { |
219 | cgit_query_page = xstrdup(argv[i]+7); | 220 | cgit_query_page = xstrdup(argv[i]+7); |
220 | } | 221 | } |
221 | if (!strncmp(argv[i], "--head=", 7)) { | 222 | if (!strncmp(argv[i], "--head=", 7)) { |
222 | cgit_query_head = xstrdup(argv[i]+7); | 223 | cgit_query_head = xstrdup(argv[i]+7); |
223 | cgit_query_has_symref = 1; | 224 | cgit_query_has_symref = 1; |
224 | } | 225 | } |
225 | if (!strncmp(argv[i], "--sha1=", 7)) { | 226 | if (!strncmp(argv[i], "--sha1=", 7)) { |
226 | cgit_query_sha1 = xstrdup(argv[i]+7); | 227 | cgit_query_sha1 = xstrdup(argv[i]+7); |
227 | cgit_query_has_sha1 = 1; | 228 | cgit_query_has_sha1 = 1; |
228 | } | 229 | } |
229 | if (!strncmp(argv[i], "--ofs=", 6)) { | 230 | if (!strncmp(argv[i], "--ofs=", 6)) { |
230 | cgit_query_ofs = atoi(argv[i]+6); | 231 | cgit_query_ofs = atoi(argv[i]+6); |
231 | } | 232 | } |
232 | } | 233 | } |
233 | } | 234 | } |
234 | 235 | ||
235 | int main(int argc, const char **argv) | 236 | int main(int argc, const char **argv) |
236 | { | 237 | { |
237 | struct cacheitem item; | 238 | struct cacheitem item; |
238 | 239 | ||
239 | htmlfd = STDOUT_FILENO; | 240 | htmlfd = STDOUT_FILENO; |
240 | item.st.st_mtime = time(NULL); | 241 | item.st.st_mtime = time(NULL); |
241 | cgit_repolist.length = 0; | 242 | cgit_repolist.length = 0; |
242 | cgit_repolist.count = 0; | 243 | cgit_repolist.count = 0; |
243 | cgit_repolist.repos = NULL; | 244 | cgit_repolist.repos = NULL; |
244 | 245 | ||
245 | cgit_read_config("/etc/cgitrc", cgit_global_config_cb); | 246 | cgit_read_config("/etc/cgitrc", cgit_global_config_cb); |
246 | if (getenv("QUERY_STRING")) | 247 | if (getenv("QUERY_STRING")) |
247 | cgit_querystring = xstrdup(getenv("QUERY_STRING")); | 248 | cgit_querystring = xstrdup(getenv("QUERY_STRING")); |
248 | cgit_parse_args(argc, argv); | 249 | cgit_parse_args(argc, argv); |
249 | cgit_parse_query(cgit_querystring, cgit_querystring_cb); | 250 | cgit_parse_query(cgit_querystring, cgit_querystring_cb); |
250 | if (!cgit_prepare_cache(&item)) | 251 | if (!cgit_prepare_cache(&item)) |
251 | return 0; | 252 | return 0; |
252 | if (cgit_nocache) { | 253 | if (cgit_nocache) { |
253 | cgit_fill_cache(&item, 0); | 254 | cgit_fill_cache(&item, 0); |
254 | } else { | 255 | } else { |
255 | cgit_check_cache(&item); | 256 | cgit_check_cache(&item); |
256 | cgit_print_cache(&item); | 257 | cgit_print_cache(&item); |
257 | } | 258 | } |
258 | return 0; | 259 | return 0; |
259 | } | 260 | } |
@@ -1,327 +1,332 @@ | |||
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 | } | 5 | } |
6 | 6 | ||
7 | body, table { | 7 | body, table { |
8 | padding: 0em; | 8 | padding: 0em; |
9 | margin: 0em; | 9 | margin: 0em; |
10 | } | 10 | } |
11 | 11 | ||
12 | table { | 12 | table { |
13 | border-collapse: collapse; | 13 | border-collapse: collapse; |
14 | } | 14 | } |
15 | 15 | ||
16 | h2 { | 16 | h2 { |
17 | font-size: 120%; | 17 | font-size: 120%; |
18 | font-weight: bold; | 18 | font-weight: bold; |
19 | margin-top: 0em; | 19 | margin-top: 0em; |
20 | margin-bottom: 0.25em; | 20 | margin-bottom: 0.25em; |
21 | } | 21 | } |
22 | 22 | ||
23 | h3 { | 23 | h3 { |
24 | margin-top: 0em; | 24 | margin-top: 0em; |
25 | font-size: 100%; | 25 | font-size: 100%; |
26 | font-weight: normal; | 26 | font-weight: normal; |
27 | } | 27 | } |
28 | 28 | ||
29 | h4 { | 29 | h4 { |
30 | margin-top: 1.5em; | 30 | margin-top: 1.5em; |
31 | margin-bottom: 0.1em; | 31 | margin-bottom: 0.1em; |
32 | font-size: 100%; | 32 | font-size: 100%; |
33 | font-weight: bold; | 33 | font-weight: bold; |
34 | } | 34 | } |
35 | 35 | ||
36 | a { | 36 | a { |
37 | color: blue; | 37 | color: blue; |
38 | text-decoration: none; | 38 | text-decoration: none; |
39 | } | 39 | } |
40 | 40 | ||
41 | a:hover { | 41 | a:hover { |
42 | text-decoration: underline; | 42 | text-decoration: underline; |
43 | } | 43 | } |
44 | 44 | ||
45 | table.list { | 45 | table.list { |
46 | border: none; | 46 | border: none; |
47 | border-collapse: collapse; | 47 | border-collapse: collapse; |
48 | } | 48 | } |
49 | 49 | ||
50 | table.list tr { | 50 | table.list tr { |
51 | background: white; | 51 | background: white; |
52 | } | 52 | } |
53 | 53 | ||
54 | table.list tr:hover { | 54 | table.list tr:hover { |
55 | background: #eee; | 55 | background: #eee; |
56 | } | 56 | } |
57 | 57 | ||
58 | table.list tr.nohover:hover { | 58 | table.list tr.nohover:hover { |
59 | background: white; | 59 | background: white; |
60 | } | 60 | } |
61 | 61 | ||
62 | table.list th { | 62 | table.list th { |
63 | font-weight: normal; | 63 | font-weight: normal; |
64 | border-bottom: solid 1px #777; | 64 | border-bottom: solid 1px #777; |
65 | padding: 0.1em 0.5em 0.1em 0.5em; | 65 | padding: 0.1em 0.5em 0.1em 0.5em; |
66 | vertical-align: baseline; | 66 | vertical-align: baseline; |
67 | } | 67 | } |
68 | 68 | ||
69 | table.list td { | 69 | table.list td { |
70 | border: none; | 70 | border: none; |
71 | padding: 0.1em 0.5em 0.1em 0.5em; | 71 | padding: 0.1em 0.5em 0.1em 0.5em; |
72 | } | 72 | } |
73 | 73 | ||
74 | img { | 74 | img { |
75 | border: none; | 75 | border: none; |
76 | } | 76 | } |
77 | 77 | ||
78 | table#layout { | 78 | table#layout { |
79 | width: 100%; | 79 | width: 100%; |
80 | border-collapse: collapse; | 80 | border-collapse: collapse; |
81 | margin: 0px; | 81 | margin: 0px; |
82 | } | 82 | } |
83 | 83 | ||
84 | td#header, td#logo { | 84 | td#header, td#logo { |
85 | color: #666; | 85 | color: #666; |
86 | background-color: #ddd; | 86 | background-color: #ddd; |
87 | border-bottom: solid 1px #000; | 87 | border-bottom: solid 1px #000; |
88 | } | 88 | } |
89 | 89 | ||
90 | td#header { | 90 | td#header { |
91 | font-size: 150%; | 91 | font-size: 150%; |
92 | font-weight: bold; | 92 | font-weight: bold; |
93 | padding: 0.2em 0.5em; | 93 | padding: 0.2em 0.5em; |
94 | vertical-align: text-bottom; | 94 | vertical-align: text-bottom; |
95 | } | 95 | } |
96 | 96 | ||
97 | td#logo { | 97 | td#logo { |
98 | text-align: right; | 98 | text-align: right; |
99 | vertical-align: middle; | 99 | vertical-align: middle; |
100 | padding-right: 0.5em; | 100 | padding-right: 0.5em; |
101 | } | 101 | } |
102 | 102 | ||
103 | td#crumb, td#search { | 103 | td#crumb, td#search { |
104 | color: #ccc; | 104 | color: #ccc; |
105 | border-top: solid 3px #555; | 105 | border-top: solid 3px #555; |
106 | background-color: #666; | 106 | background-color: #666; |
107 | border-bottom: solid 1px #333; | 107 | border-bottom: solid 1px #333; |
108 | padding: 2px 1em; | 108 | padding: 2px 1em; |
109 | } | 109 | } |
110 | 110 | ||
111 | td#crumb { | 111 | td#crumb { |
112 | font-weight: bold; | 112 | font-weight: bold; |
113 | } | 113 | } |
114 | 114 | ||
115 | td#crumb a { | 115 | td#crumb a { |
116 | color: #ccc; | 116 | color: #ccc; |
117 | } | 117 | } |
118 | 118 | ||
119 | td#crumb a:hover { | 119 | td#crumb a:hover { |
120 | color: #eee; | 120 | color: #eee; |
121 | } | 121 | } |
122 | 122 | ||
123 | td#search { | 123 | td#search { |
124 | text-align: right; | 124 | text-align: right; |
125 | vertical-align: center; | 125 | vertical-align: center; |
126 | padding-right: 0.5em; | 126 | padding-right: 0.5em; |
127 | } | 127 | } |
128 | 128 | ||
129 | td#search form { | 129 | td#search form { |
130 | margin: 0px; | 130 | margin: 0px; |
131 | padding: 0px; | 131 | padding: 0px; |
132 | } | 132 | } |
133 | 133 | ||
134 | td#search input { | 134 | td#search input { |
135 | font-size: 9pt; | 135 | font-size: 9pt; |
136 | padding: 0px; | 136 | padding: 0px; |
137 | width: 10em; | 137 | width: 10em; |
138 | border: solid 1px #333; | 138 | border: solid 1px #333; |
139 | color: #333; | 139 | color: #333; |
140 | background-color: #fff; | 140 | background-color: #fff; |
141 | } | 141 | } |
142 | 142 | ||
143 | td#summary { | 143 | td#summary { |
144 | vertical-align: top; | 144 | vertical-align: top; |
145 | padding-bottom: 1em; | 145 | padding-bottom: 1em; |
146 | } | 146 | } |
147 | 147 | ||
148 | td#archivelist { | 148 | td#archivelist { |
149 | padding-bottom: 1em; | 149 | padding-bottom: 1em; |
150 | } | 150 | } |
151 | 151 | ||
152 | td#archivelist table { | 152 | td#archivelist table { |
153 | float: right; | 153 | float: right; |
154 | border-collapse: collapse; | 154 | border-collapse: collapse; |
155 | border: solid 1px #777; | 155 | border: solid 1px #777; |
156 | } | 156 | } |
157 | 157 | ||
158 | td#archivelist table th { | 158 | td#archivelist table th { |
159 | background-color: #ccc; | 159 | background-color: #ccc; |
160 | } | 160 | } |
161 | 161 | ||
162 | td#content { | 162 | td#content { |
163 | padding: 1em 0.5em; | 163 | padding: 1em 0.5em; |
164 | } | 164 | } |
165 | 165 | ||
166 | div#blob { | 166 | div#blob { |
167 | border: solid 1px black; | 167 | border: solid 1px black; |
168 | } | 168 | } |
169 | 169 | ||
170 | div.error { | 170 | div.error { |
171 | color: red; | 171 | color: red; |
172 | font-weight: bold; | 172 | font-weight: bold; |
173 | margin: 1em 2em; | 173 | margin: 1em 2em; |
174 | } | 174 | } |
175 | 175 | ||
176 | td.ls-blob, td.ls-dir, td.ls-mod { | 176 | td.ls-blob, td.ls-dir, td.ls-mod { |
177 | font-family: monospace; | 177 | font-family: monospace; |
178 | } | 178 | } |
179 | 179 | ||
180 | div.ls-dir a { | 180 | div.ls-dir a { |
181 | font-weight: bold; | 181 | font-weight: bold; |
182 | } | 182 | } |
183 | 183 | ||
184 | th.filesize, td.filesize { | 184 | th.filesize, td.filesize { |
185 | text-align: right; | 185 | text-align: right; |
186 | } | 186 | } |
187 | 187 | ||
188 | td.filesize { | 188 | td.filesize { |
189 | font-family: monospace; | 189 | font-family: monospace; |
190 | } | 190 | } |
191 | 191 | ||
192 | td.links { | ||
193 | font-size: 80%; | ||
194 | padding-left: 2em; | ||
195 | } | ||
196 | |||
192 | td.filemode { | 197 | td.filemode { |
193 | font-family: monospace; | 198 | font-family: monospace; |
194 | } | 199 | } |
195 | 200 | ||
196 | td.blob { | 201 | td.blob { |
197 | white-space: pre; | 202 | white-space: pre; |
198 | font-family: monospace; | 203 | font-family: monospace; |
199 | background-color: white; | 204 | background-color: white; |
200 | } | 205 | } |
201 | 206 | ||
202 | table.nowrap td { | 207 | table.nowrap td { |
203 | white-space: nowrap; | 208 | white-space: nowrap; |
204 | } | 209 | } |
205 | 210 | ||
206 | table.commit-info { | 211 | table.commit-info { |
207 | border-collapse: collapse; | 212 | border-collapse: collapse; |
208 | margin-top: 1.5em; | 213 | margin-top: 1.5em; |
209 | } | 214 | } |
210 | 215 | ||
211 | table.commit-info th { | 216 | table.commit-info th { |
212 | text-align: left; | 217 | text-align: left; |
213 | font-weight: normal; | 218 | font-weight: normal; |
214 | padding: 0.1em 1em 0.1em 0.1em; | 219 | padding: 0.1em 1em 0.1em 0.1em; |
215 | } | 220 | } |
216 | 221 | ||
217 | table.commit-info td { | 222 | table.commit-info td { |
218 | font-weight: normal; | 223 | font-weight: normal; |
219 | padding: 0.1em 1em 0.1em 0.1em; | 224 | padding: 0.1em 1em 0.1em 0.1em; |
220 | } | 225 | } |
221 | 226 | ||
222 | div.commit-subject { | 227 | div.commit-subject { |
223 | font-weight: bold; | 228 | font-weight: bold; |
224 | font-size: 125%; | 229 | font-size: 125%; |
225 | margin: 1.5em 0em 0.5em 0em; | 230 | margin: 1.5em 0em 0.5em 0em; |
226 | padding: 0em; | 231 | padding: 0em; |
227 | } | 232 | } |
228 | 233 | ||
229 | div.commit-msg { | 234 | div.commit-msg { |
230 | white-space: pre; | 235 | white-space: pre; |
231 | font-family: monospace; | 236 | font-family: monospace; |
232 | } | 237 | } |
233 | 238 | ||
234 | table.diffstat { | 239 | table.diffstat { |
235 | border-collapse: collapse; | 240 | border-collapse: collapse; |
236 | margin-top: 1.5em; | 241 | margin-top: 1.5em; |
237 | width: 100%; | 242 | width: 100%; |
238 | border: solid 1px #aaa; | 243 | border: solid 1px #aaa; |
239 | } | 244 | } |
240 | 245 | ||
241 | table.diffstat tr:hover { | 246 | table.diffstat tr:hover { |
242 | background-color: #eee; | 247 | background-color: #eee; |
243 | } | 248 | } |
244 | 249 | ||
245 | table.diffstat th { | 250 | table.diffstat th { |
246 | font-weight: normal; | 251 | font-weight: normal; |
247 | text-align: left; | 252 | text-align: left; |
248 | text-decoration: underline; | 253 | text-decoration: underline; |
249 | padding: 0.1em 1em 0.1em 0.1em; | 254 | padding: 0.1em 1em 0.1em 0.1em; |
250 | font-size: 100%; | 255 | font-size: 100%; |
251 | } | 256 | } |
252 | 257 | ||
253 | table.diffstat td { | 258 | table.diffstat td { |
254 | padding: 0.2em 0.2em 0.1em 0.1em; | 259 | padding: 0.2em 0.2em 0.1em 0.1em; |
255 | font-size: 100%; | 260 | font-size: 100%; |
256 | border: none; | 261 | border: none; |
257 | border-top: solid 1px #aaa; | 262 | border-top: solid 1px #aaa; |
258 | border-bottom: solid 1px #aaa; | 263 | border-bottom: solid 1px #aaa; |
259 | } | 264 | } |
260 | 265 | ||
261 | table.diffstat td span.modechange { | 266 | table.diffstat td span.modechange { |
262 | padding-left: 1em; | 267 | padding-left: 1em; |
263 | color: red; | 268 | color: red; |
264 | } | 269 | } |
265 | 270 | ||
266 | table.diffstat td.add a { | 271 | table.diffstat td.add a { |
267 | color: green; | 272 | color: green; |
268 | } | 273 | } |
269 | 274 | ||
270 | table.diffstat td.del a { | 275 | table.diffstat td.del a { |
271 | color: red; | 276 | color: red; |
272 | } | 277 | } |
273 | 278 | ||
274 | table.diffstat td.upd a { | 279 | table.diffstat td.upd a { |
275 | color: blue; | 280 | color: blue; |
276 | } | 281 | } |
277 | 282 | ||
278 | table.diffstat td.graph { | 283 | table.diffstat td.graph { |
279 | width: 75%; | 284 | width: 75%; |
280 | vertical-align: center; | 285 | vertical-align: center; |
281 | } | 286 | } |
282 | 287 | ||
283 | table.diffstat td.graph img { | 288 | table.diffstat td.graph img { |
284 | border: none; | 289 | border: none; |
285 | height: 11pt; | 290 | height: 11pt; |
286 | } | 291 | } |
287 | 292 | ||
288 | div.diffstat-summary { | 293 | div.diffstat-summary { |
289 | color: #888; | 294 | color: #888; |
290 | padding-top: 0.5em; | 295 | padding-top: 0.5em; |
291 | } | 296 | } |
292 | 297 | ||
293 | table.diff th { | 298 | table.diff th { |
294 | padding: 1em 0em 0.1em 0.1em; | 299 | padding: 1em 0em 0.1em 0.1em; |
295 | text-align: left; | 300 | text-align: left; |
296 | } | 301 | } |
297 | 302 | ||
298 | table.diff td { | 303 | table.diff td { |
299 | border: solid 1px black; | 304 | border: solid 1px black; |
300 | font-family: monospace; | 305 | font-family: monospace; |
301 | white-space: pre; | 306 | white-space: pre; |
302 | } | 307 | } |
303 | 308 | ||
304 | table.diff td div.hunk { | 309 | table.diff td div.hunk { |
305 | background: #ccc; | 310 | background: #ccc; |
306 | } | 311 | } |
307 | 312 | ||
308 | table.diff td div.add { | 313 | table.diff td div.add { |
309 | color: green; | 314 | color: green; |
310 | } | 315 | } |
311 | 316 | ||
312 | table.diff td div.del { | 317 | table.diff td div.del { |
313 | color: red; | 318 | color: red; |
314 | } | 319 | } |
315 | 320 | ||
316 | .sha1 { | 321 | .sha1 { |
317 | font-family: courier; | 322 | font-family: courier; |
318 | font-size: 90%; | 323 | font-size: 90%; |
319 | } | 324 | } |
320 | 325 | ||
321 | .left { | 326 | .left { |
322 | text-align: left; | 327 | text-align: left; |
323 | } | 328 | } |
324 | 329 | ||
325 | .right { | 330 | .right { |
326 | text-align: right; | 331 | text-align: right; |
327 | } | 332 | } |
@@ -1,182 +1,182 @@ | |||
1 | #ifndef CGIT_H | 1 | #ifndef CGIT_H |
2 | #define CGIT_H | 2 | #define CGIT_H |
3 | 3 | ||
4 | 4 | ||
5 | #include <git-compat-util.h> | 5 | #include <git-compat-util.h> |
6 | #include <cache.h> | 6 | #include <cache.h> |
7 | #include <grep.h> | 7 | #include <grep.h> |
8 | #include <object.h> | 8 | #include <object.h> |
9 | #include <tree.h> | 9 | #include <tree.h> |
10 | #include <commit.h> | 10 | #include <commit.h> |
11 | #include <tag.h> | 11 | #include <tag.h> |
12 | #include <diff.h> | 12 | #include <diff.h> |
13 | #include <diffcore.h> | 13 | #include <diffcore.h> |
14 | #include <refs.h> | 14 | #include <refs.h> |
15 | #include <revision.h> | 15 | #include <revision.h> |
16 | #include <log-tree.h> | 16 | #include <log-tree.h> |
17 | #include <archive.h> | 17 | #include <archive.h> |
18 | #include <xdiff/xdiff.h> | 18 | #include <xdiff/xdiff.h> |
19 | 19 | ||
20 | 20 | ||
21 | typedef void (*configfn)(const char *name, const char *value); | 21 | typedef void (*configfn)(const char *name, const char *value); |
22 | typedef void (*filepair_fn)(struct diff_filepair *pair); | 22 | typedef void (*filepair_fn)(struct diff_filepair *pair); |
23 | typedef void (*linediff_fn)(char *line, int len); | 23 | typedef void (*linediff_fn)(char *line, int len); |
24 | 24 | ||
25 | struct cacheitem { | 25 | struct cacheitem { |
26 | char *name; | 26 | char *name; |
27 | struct stat st; | 27 | struct stat st; |
28 | int ttl; | 28 | int ttl; |
29 | int fd; | 29 | int fd; |
30 | }; | 30 | }; |
31 | 31 | ||
32 | struct repoinfo { | 32 | struct repoinfo { |
33 | char *url; | 33 | char *url; |
34 | char *name; | 34 | char *name; |
35 | char *path; | 35 | char *path; |
36 | char *desc; | 36 | char *desc; |
37 | char *owner; | 37 | char *owner; |
38 | char *module_link; | 38 | char *module_link; |
39 | int snapshots; | 39 | int snapshots; |
40 | }; | 40 | }; |
41 | 41 | ||
42 | struct repolist { | 42 | struct repolist { |
43 | int length; | 43 | int length; |
44 | int count; | 44 | int count; |
45 | struct repoinfo *repos; | 45 | struct repoinfo *repos; |
46 | }; | 46 | }; |
47 | 47 | ||
48 | struct commitinfo { | 48 | struct commitinfo { |
49 | struct commit *commit; | 49 | struct commit *commit; |
50 | char *author; | 50 | char *author; |
51 | char *author_email; | 51 | char *author_email; |
52 | unsigned long author_date; | 52 | unsigned long author_date; |
53 | char *committer; | 53 | char *committer; |
54 | char *committer_email; | 54 | char *committer_email; |
55 | unsigned long committer_date; | 55 | unsigned long committer_date; |
56 | char *subject; | 56 | char *subject; |
57 | char *msg; | 57 | char *msg; |
58 | }; | 58 | }; |
59 | 59 | ||
60 | struct taginfo { | 60 | struct taginfo { |
61 | char *tagger; | 61 | char *tagger; |
62 | char *tagger_email; | 62 | char *tagger_email; |
63 | int tagger_date; | 63 | int tagger_date; |
64 | char *msg; | 64 | char *msg; |
65 | }; | 65 | }; |
66 | 66 | ||
67 | extern const char cgit_version[]; | 67 | extern const char cgit_version[]; |
68 | 68 | ||
69 | extern struct repolist cgit_repolist; | 69 | extern struct repolist cgit_repolist; |
70 | extern struct repoinfo *cgit_repo; | 70 | extern struct repoinfo *cgit_repo; |
71 | 71 | ||
72 | extern char *cgit_root_title; | 72 | extern char *cgit_root_title; |
73 | extern char *cgit_css; | 73 | extern char *cgit_css; |
74 | extern char *cgit_logo; | 74 | extern char *cgit_logo; |
75 | extern char *cgit_logo_link; | 75 | extern char *cgit_logo_link; |
76 | extern char *cgit_module_link; | 76 | extern char *cgit_module_link; |
77 | extern char *cgit_virtual_root; | 77 | extern char *cgit_virtual_root; |
78 | extern char *cgit_cache_root; | 78 | extern char *cgit_cache_root; |
79 | 79 | ||
80 | extern int cgit_nocache; | 80 | extern int cgit_nocache; |
81 | extern int cgit_snapshots; | 81 | extern int cgit_snapshots; |
82 | extern int cgit_max_lock_attempts; | 82 | extern int cgit_max_lock_attempts; |
83 | extern int cgit_cache_root_ttl; | 83 | extern int cgit_cache_root_ttl; |
84 | extern int cgit_cache_repo_ttl; | 84 | extern int cgit_cache_repo_ttl; |
85 | extern int cgit_cache_dynamic_ttl; | 85 | extern int cgit_cache_dynamic_ttl; |
86 | extern int cgit_cache_static_ttl; | 86 | extern int cgit_cache_static_ttl; |
87 | extern int cgit_cache_max_create_time; | 87 | extern int cgit_cache_max_create_time; |
88 | 88 | ||
89 | extern int cgit_max_msg_len; | 89 | extern int cgit_max_msg_len; |
90 | extern int cgit_max_commit_count; | 90 | extern int cgit_max_commit_count; |
91 | 91 | ||
92 | extern char *cgit_repo_name; | 92 | extern char *cgit_repo_name; |
93 | extern char *cgit_repo_desc; | 93 | extern char *cgit_repo_desc; |
94 | extern char *cgit_repo_owner; | 94 | extern char *cgit_repo_owner; |
95 | 95 | ||
96 | extern int cgit_query_has_symref; | 96 | extern int cgit_query_has_symref; |
97 | extern int cgit_query_has_sha1; | 97 | extern int cgit_query_has_sha1; |
98 | 98 | ||
99 | extern char *cgit_querystring; | 99 | extern char *cgit_querystring; |
100 | extern char *cgit_query_repo; | 100 | extern char *cgit_query_repo; |
101 | extern char *cgit_query_page; | 101 | extern char *cgit_query_page; |
102 | extern char *cgit_query_search; | 102 | extern char *cgit_query_search; |
103 | extern char *cgit_query_head; | 103 | extern char *cgit_query_head; |
104 | extern char *cgit_query_sha1; | 104 | extern char *cgit_query_sha1; |
105 | extern char *cgit_query_sha2; | 105 | extern char *cgit_query_sha2; |
106 | extern char *cgit_query_path; | 106 | extern char *cgit_query_path; |
107 | extern char *cgit_query_name; | 107 | extern char *cgit_query_name; |
108 | extern int cgit_query_ofs; | 108 | extern int cgit_query_ofs; |
109 | 109 | ||
110 | extern int htmlfd; | 110 | extern int htmlfd; |
111 | 111 | ||
112 | extern void cgit_global_config_cb(const char *name, const char *value); | 112 | extern void cgit_global_config_cb(const char *name, const char *value); |
113 | extern void cgit_repo_config_cb(const char *name, const char *value); | 113 | extern void cgit_repo_config_cb(const char *name, const char *value); |
114 | extern void cgit_querystring_cb(const char *name, const char *value); | 114 | extern void cgit_querystring_cb(const char *name, const char *value); |
115 | 115 | ||
116 | extern int chk_zero(int result, char *msg); | 116 | extern int chk_zero(int result, char *msg); |
117 | extern int chk_positive(int result, char *msg); | 117 | extern int chk_positive(int result, char *msg); |
118 | 118 | ||
119 | extern int hextoint(char c); | 119 | extern int hextoint(char c); |
120 | 120 | ||
121 | extern void *cgit_free_commitinfo(struct commitinfo *info); | 121 | extern void *cgit_free_commitinfo(struct commitinfo *info); |
122 | 122 | ||
123 | extern int cgit_diff_files(const unsigned char *old_sha1, | 123 | extern int cgit_diff_files(const unsigned char *old_sha1, |
124 | const unsigned char *new_sha1, | 124 | const unsigned char *new_sha1, |
125 | linediff_fn fn); | 125 | linediff_fn fn); |
126 | 126 | ||
127 | extern void cgit_diff_tree(const unsigned char *old_sha1, | 127 | extern void cgit_diff_tree(const unsigned char *old_sha1, |
128 | const unsigned char *new_sha1, | 128 | const unsigned char *new_sha1, |
129 | filepair_fn fn); | 129 | filepair_fn fn); |
130 | 130 | ||
131 | extern void cgit_diff_commit(struct commit *commit, filepair_fn fn); | 131 | extern void cgit_diff_commit(struct commit *commit, filepair_fn fn); |
132 | 132 | ||
133 | extern char *fmt(const char *format,...); | 133 | extern char *fmt(const char *format,...); |
134 | 134 | ||
135 | extern void html(const char *txt); | 135 | extern void html(const char *txt); |
136 | extern void htmlf(const char *format,...); | 136 | extern void htmlf(const char *format,...); |
137 | extern void html_txt(char *txt); | 137 | extern void html_txt(char *txt); |
138 | extern void html_ntxt(int len, char *txt); | 138 | extern void html_ntxt(int len, char *txt); |
139 | extern void html_attr(char *txt); | 139 | extern void html_attr(char *txt); |
140 | extern void html_hidden(char *name, char *value); | 140 | extern void html_hidden(char *name, char *value); |
141 | extern void html_link_open(char *url, char *title, char *class); | 141 | extern void html_link_open(char *url, char *title, char *class); |
142 | extern void html_link_close(void); | 142 | extern void html_link_close(void); |
143 | extern void html_filemode(unsigned short mode); | 143 | extern void html_filemode(unsigned short mode); |
144 | 144 | ||
145 | extern int cgit_read_config(const char *filename, configfn fn); | 145 | extern int cgit_read_config(const char *filename, configfn fn); |
146 | extern int cgit_parse_query(char *txt, configfn fn); | 146 | extern int cgit_parse_query(char *txt, configfn fn); |
147 | extern struct commitinfo *cgit_parse_commit(struct commit *commit); | 147 | extern struct commitinfo *cgit_parse_commit(struct commit *commit); |
148 | extern struct taginfo *cgit_parse_tag(struct tag *tag); | 148 | extern struct taginfo *cgit_parse_tag(struct tag *tag); |
149 | 149 | ||
150 | extern char *cache_safe_filename(const char *unsafe); | 150 | extern char *cache_safe_filename(const char *unsafe); |
151 | extern int cache_lock(struct cacheitem *item); | 151 | extern int cache_lock(struct cacheitem *item); |
152 | extern int cache_unlock(struct cacheitem *item); | 152 | extern int cache_unlock(struct cacheitem *item); |
153 | extern int cache_cancel_lock(struct cacheitem *item); | 153 | extern int cache_cancel_lock(struct cacheitem *item); |
154 | extern int cache_exist(struct cacheitem *item); | 154 | extern int cache_exist(struct cacheitem *item); |
155 | extern int cache_expired(struct cacheitem *item); | 155 | extern int cache_expired(struct cacheitem *item); |
156 | 156 | ||
157 | extern char *cgit_repourl(const char *reponame); | 157 | extern char *cgit_repourl(const char *reponame); |
158 | extern char *cgit_pageurl(const char *reponame, const char *pagename, | 158 | extern char *cgit_pageurl(const char *reponame, const char *pagename, |
159 | const char *query); | 159 | const char *query); |
160 | 160 | ||
161 | extern void cgit_print_error(char *msg); | 161 | extern void cgit_print_error(char *msg); |
162 | extern void cgit_print_date(unsigned long secs); | 162 | extern void cgit_print_date(unsigned long secs); |
163 | extern void cgit_print_docstart(char *title, struct cacheitem *item); | 163 | extern void cgit_print_docstart(char *title, struct cacheitem *item); |
164 | extern void cgit_print_docend(); | 164 | extern void cgit_print_docend(); |
165 | extern void cgit_print_pageheader(char *title, int show_search); | 165 | extern void cgit_print_pageheader(char *title, int show_search); |
166 | extern void cgit_print_snapshot_start(const char *mimetype, | 166 | extern void cgit_print_snapshot_start(const char *mimetype, |
167 | const char *filename, | 167 | const char *filename, |
168 | struct cacheitem *item); | 168 | struct cacheitem *item); |
169 | 169 | ||
170 | extern void cgit_print_repolist(struct cacheitem *item); | 170 | extern void cgit_print_repolist(struct cacheitem *item); |
171 | extern void cgit_print_summary(); | 171 | extern void cgit_print_summary(); |
172 | extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep); | 172 | extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *path); |
173 | extern void cgit_print_view(const char *hex, char *path); | 173 | extern void cgit_print_view(const char *hex, char *path); |
174 | extern void cgit_print_blob(struct cacheitem *item, const char *hex, char *path); | 174 | extern void cgit_print_blob(struct cacheitem *item, const char *hex, char *path); |
175 | extern void cgit_print_tree(const char *hex, char *path); | 175 | extern void cgit_print_tree(const char *rev, const char *hex, char *path); |
176 | extern void cgit_print_commit(const char *hex); | 176 | extern void cgit_print_commit(const char *hex); |
177 | extern void cgit_print_diff(const char *old_hex, const char *new_hex, char *path); | 177 | extern void cgit_print_diff(const char *old_hex, const char *new_hex, char *path); |
178 | extern void cgit_print_snapshot(struct cacheitem *item, const char *hex, | 178 | extern void cgit_print_snapshot(struct cacheitem *item, const char *hex, |
179 | const char *format, const char *prefix, | 179 | const char *format, const char *prefix, |
180 | const char *filename); | 180 | const char *filename); |
181 | 181 | ||
182 | #endif /* CGIT_H */ | 182 | #endif /* CGIT_H */ |
diff --git a/ui-commit.c b/ui-commit.c index b3d1c28..20a7cb2 100644 --- a/ui-commit.c +++ b/ui-commit.c | |||
@@ -1,239 +1,240 @@ | |||
1 | /* ui-commit.c: generate commit view | 1 | /* ui-commit.c: generate commit view |
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 | int files = 0, slots = 0; | 11 | int files = 0, slots = 0; |
12 | int total_adds = 0, total_rems = 0, max_changes = 0; | 12 | int total_adds = 0, total_rems = 0, max_changes = 0; |
13 | int lines_added, lines_removed; | 13 | int lines_added, lines_removed; |
14 | 14 | ||
15 | struct fileinfo { | 15 | struct fileinfo { |
16 | char status; | 16 | char status; |
17 | unsigned char old_sha1[20]; | 17 | unsigned char old_sha1[20]; |
18 | unsigned char new_sha1[20]; | 18 | unsigned char new_sha1[20]; |
19 | unsigned short old_mode; | 19 | unsigned short old_mode; |
20 | unsigned short new_mode; | 20 | unsigned short new_mode; |
21 | char *old_path; | 21 | char *old_path; |
22 | char *new_path; | 22 | char *new_path; |
23 | unsigned int added; | 23 | unsigned int added; |
24 | unsigned int removed; | 24 | unsigned int removed; |
25 | } *items; | 25 | } *items; |
26 | 26 | ||
27 | 27 | ||
28 | void print_fileinfo(struct fileinfo *info) | 28 | void print_fileinfo(struct fileinfo *info) |
29 | { | 29 | { |
30 | char *query, *query2; | 30 | char *query, *query2; |
31 | char *class; | 31 | char *class; |
32 | double width; | 32 | double width; |
33 | 33 | ||
34 | switch (info->status) { | 34 | switch (info->status) { |
35 | case DIFF_STATUS_ADDED: | 35 | case DIFF_STATUS_ADDED: |
36 | class = "add"; | 36 | class = "add"; |
37 | break; | 37 | break; |
38 | case DIFF_STATUS_COPIED: | 38 | case DIFF_STATUS_COPIED: |
39 | class = "cpy"; | 39 | class = "cpy"; |
40 | break; | 40 | break; |
41 | case DIFF_STATUS_DELETED: | 41 | case DIFF_STATUS_DELETED: |
42 | class = "del"; | 42 | class = "del"; |
43 | break; | 43 | break; |
44 | case DIFF_STATUS_MODIFIED: | 44 | case DIFF_STATUS_MODIFIED: |
45 | class = "upd"; | 45 | class = "upd"; |
46 | break; | 46 | break; |
47 | case DIFF_STATUS_RENAMED: | 47 | case DIFF_STATUS_RENAMED: |
48 | class = "mov"; | 48 | class = "mov"; |
49 | break; | 49 | break; |
50 | case DIFF_STATUS_TYPE_CHANGED: | 50 | case DIFF_STATUS_TYPE_CHANGED: |
51 | class = "typ"; | 51 | class = "typ"; |
52 | break; | 52 | break; |
53 | case DIFF_STATUS_UNKNOWN: | 53 | case DIFF_STATUS_UNKNOWN: |
54 | class = "unk"; | 54 | class = "unk"; |
55 | break; | 55 | break; |
56 | case DIFF_STATUS_UNMERGED: | 56 | case DIFF_STATUS_UNMERGED: |
57 | class = "stg"; | 57 | class = "stg"; |
58 | break; | 58 | break; |
59 | default: | 59 | default: |
60 | die("bug: unhandled diff status %c", info->status); | 60 | die("bug: unhandled diff status %c", info->status); |
61 | } | 61 | } |
62 | 62 | ||
63 | html("<tr>"); | 63 | html("<tr>"); |
64 | htmlf("<td class='mode'>"); | 64 | htmlf("<td class='mode'>"); |
65 | if (is_null_sha1(info->new_sha1)) { | 65 | if (is_null_sha1(info->new_sha1)) { |
66 | html_filemode(info->old_mode); | 66 | html_filemode(info->old_mode); |
67 | } else { | 67 | } else { |
68 | html_filemode(info->new_mode); | 68 | html_filemode(info->new_mode); |
69 | } | 69 | } |
70 | 70 | ||
71 | if (info->old_mode != info->new_mode && | 71 | if (info->old_mode != info->new_mode && |
72 | !is_null_sha1(info->old_sha1) && | 72 | !is_null_sha1(info->old_sha1) && |
73 | !is_null_sha1(info->new_sha1)) { | 73 | !is_null_sha1(info->new_sha1)) { |
74 | html("<span class='modechange'>["); | 74 | html("<span class='modechange'>["); |
75 | html_filemode(info->old_mode); | 75 | html_filemode(info->old_mode); |
76 | html("]</span>"); | 76 | html("]</span>"); |
77 | } | 77 | } |
78 | htmlf("</td><td class='%s'>", class); | 78 | htmlf("</td><td class='%s'>", class); |
79 | query = fmt("id=%s&id2=%s&path=%s", sha1_to_hex(info->old_sha1), | 79 | query = fmt("id=%s&id2=%s&path=%s", sha1_to_hex(info->old_sha1), |
80 | sha1_to_hex(info->new_sha1), info->new_path); | 80 | sha1_to_hex(info->new_sha1), info->new_path); |
81 | html_link_open(cgit_pageurl(cgit_query_repo, "diff", query), | 81 | html_link_open(cgit_pageurl(cgit_query_repo, "diff", query), |
82 | NULL, NULL); | 82 | NULL, NULL); |
83 | if (info->status == DIFF_STATUS_COPIED || | 83 | if (info->status == DIFF_STATUS_COPIED || |
84 | info->status == DIFF_STATUS_RENAMED) { | 84 | info->status == DIFF_STATUS_RENAMED) { |
85 | html_txt(info->new_path); | 85 | html_txt(info->new_path); |
86 | htmlf("</a> (%s from ", info->status == DIFF_STATUS_COPIED ? | 86 | htmlf("</a> (%s from ", info->status == DIFF_STATUS_COPIED ? |
87 | "copied" : "renamed"); | 87 | "copied" : "renamed"); |
88 | query2 = fmt("id=%s", sha1_to_hex(info->old_sha1)); | 88 | query2 = fmt("id=%s", sha1_to_hex(info->old_sha1)); |
89 | html_link_open(cgit_pageurl(cgit_query_repo, "view", query2), | 89 | html_link_open(cgit_pageurl(cgit_query_repo, "view", query2), |
90 | NULL, NULL); | 90 | NULL, NULL); |
91 | html_txt(info->old_path); | 91 | html_txt(info->old_path); |
92 | html("</a>)"); | 92 | html("</a>)"); |
93 | } else { | 93 | } else { |
94 | html_txt(info->new_path); | 94 | html_txt(info->new_path); |
95 | html("</a>"); | 95 | html("</a>"); |
96 | } | 96 | } |
97 | html("</td><td class='right'>"); | 97 | html("</td><td class='right'>"); |
98 | htmlf("%d", info->added + info->removed); | 98 | htmlf("%d", info->added + info->removed); |
99 | 99 | ||
100 | html("</td><td class='graph'>"); | 100 | html("</td><td class='graph'>"); |
101 | width = (info->added + info->removed) * 100.0 / max_changes; | 101 | width = (info->added + info->removed) * 100.0 / max_changes; |
102 | if (width < 0.1) | 102 | if (width < 0.1) |
103 | width = 0.1; | 103 | width = 0.1; |
104 | html_link_open(cgit_pageurl(cgit_query_repo, "diff", query), | 104 | html_link_open(cgit_pageurl(cgit_query_repo, "diff", query), |
105 | NULL, NULL); | 105 | NULL, NULL); |
106 | htmlf("<img src='/cgit/add.png' style='width: %.1f%%;'/>", | 106 | htmlf("<img src='/cgit/add.png' style='width: %.1f%%;'/>", |
107 | info->added * width / (info->added + info->removed)); | 107 | info->added * width / (info->added + info->removed)); |
108 | htmlf("<img src='/cgit/del.png' style='width: %.1f%%;'/>", | 108 | htmlf("<img src='/cgit/del.png' style='width: %.1f%%;'/>", |
109 | info->removed * width / (info->added + info->removed)); | 109 | info->removed * width / (info->added + info->removed)); |
110 | html("</a></td></tr>\n"); | 110 | html("</a></td></tr>\n"); |
111 | } | 111 | } |
112 | 112 | ||
113 | void cgit_count_diff_lines(char *line, int len) | 113 | void cgit_count_diff_lines(char *line, int len) |
114 | { | 114 | { |
115 | if (line && (len > 0)) { | 115 | if (line && (len > 0)) { |
116 | if (line[0] == '+') | 116 | if (line[0] == '+') |
117 | lines_added++; | 117 | lines_added++; |
118 | else if (line[0] == '-') | 118 | else if (line[0] == '-') |
119 | lines_removed++; | 119 | lines_removed++; |
120 | } | 120 | } |
121 | } | 121 | } |
122 | 122 | ||
123 | void inspect_filepair(struct diff_filepair *pair) | 123 | void inspect_filepair(struct diff_filepair *pair) |
124 | { | 124 | { |
125 | files++; | 125 | files++; |
126 | lines_added = 0; | 126 | lines_added = 0; |
127 | lines_removed = 0; | 127 | lines_removed = 0; |
128 | cgit_diff_files(pair->one->sha1, pair->two->sha1, cgit_count_diff_lines); | 128 | cgit_diff_files(pair->one->sha1, pair->two->sha1, cgit_count_diff_lines); |
129 | if (files >= slots) { | 129 | if (files >= slots) { |
130 | if (slots == 0) | 130 | if (slots == 0) |
131 | slots = 4; | 131 | slots = 4; |
132 | else | 132 | else |
133 | slots = slots * 2; | 133 | slots = slots * 2; |
134 | items = xrealloc(items, slots * sizeof(struct fileinfo)); | 134 | items = xrealloc(items, slots * sizeof(struct fileinfo)); |
135 | } | 135 | } |
136 | items[files-1].status = pair->status; | 136 | items[files-1].status = pair->status; |
137 | hashcpy(items[files-1].old_sha1, pair->one->sha1); | 137 | hashcpy(items[files-1].old_sha1, pair->one->sha1); |
138 | hashcpy(items[files-1].new_sha1, pair->two->sha1); | 138 | hashcpy(items[files-1].new_sha1, pair->two->sha1); |
139 | items[files-1].old_mode = pair->one->mode; | 139 | items[files-1].old_mode = pair->one->mode; |
140 | items[files-1].new_mode = pair->two->mode; | 140 | items[files-1].new_mode = pair->two->mode; |
141 | items[files-1].old_path = xstrdup(pair->one->path); | 141 | items[files-1].old_path = xstrdup(pair->one->path); |
142 | items[files-1].new_path = xstrdup(pair->two->path); | 142 | items[files-1].new_path = xstrdup(pair->two->path); |
143 | items[files-1].added = lines_added; | 143 | items[files-1].added = lines_added; |
144 | items[files-1].removed = lines_removed; | 144 | items[files-1].removed = lines_removed; |
145 | if (lines_added + lines_removed > max_changes) | 145 | if (lines_added + lines_removed > max_changes) |
146 | max_changes = lines_added + lines_removed; | 146 | max_changes = lines_added + lines_removed; |
147 | total_adds += lines_added; | 147 | total_adds += lines_added; |
148 | total_rems += lines_removed; | 148 | total_rems += lines_removed; |
149 | } | 149 | } |
150 | 150 | ||
151 | 151 | ||
152 | void cgit_print_commit(const char *hex) | 152 | void cgit_print_commit(const char *hex) |
153 | { | 153 | { |
154 | struct commit *commit, *parent; | 154 | struct commit *commit, *parent; |
155 | struct commitinfo *info; | 155 | struct commitinfo *info; |
156 | struct commit_list *p; | 156 | struct commit_list *p; |
157 | unsigned char sha1[20]; | 157 | unsigned char sha1[20]; |
158 | char *query; | 158 | char *query; |
159 | char *filename; | 159 | char *filename; |
160 | int i; | 160 | int i; |
161 | 161 | ||
162 | if (get_sha1(hex, sha1)) { | 162 | if (get_sha1(hex, sha1)) { |
163 | cgit_print_error(fmt("Bad object id: %s", hex)); | 163 | cgit_print_error(fmt("Bad object id: %s", hex)); |
164 | return; | 164 | return; |
165 | } | 165 | } |
166 | commit = lookup_commit_reference(sha1); | 166 | commit = lookup_commit_reference(sha1); |
167 | if (!commit) { | 167 | if (!commit) { |
168 | cgit_print_error(fmt("Bad commit reference: %s", hex)); | 168 | cgit_print_error(fmt("Bad commit reference: %s", hex)); |
169 | return; | 169 | return; |
170 | } | 170 | } |
171 | info = cgit_parse_commit(commit); | 171 | info = cgit_parse_commit(commit); |
172 | 172 | ||
173 | html("<table class='commit-info'>\n"); | 173 | html("<table class='commit-info'>\n"); |
174 | html("<tr><th>author</th><td>"); | 174 | html("<tr><th>author</th><td>"); |
175 | html_txt(info->author); | 175 | html_txt(info->author); |
176 | html(" "); | 176 | html(" "); |
177 | html_txt(info->author_email); | 177 | html_txt(info->author_email); |
178 | html("</td><td class='right'>"); | 178 | html("</td><td class='right'>"); |
179 | cgit_print_date(info->author_date); | 179 | cgit_print_date(info->author_date); |
180 | html("</td></tr>\n"); | 180 | html("</td></tr>\n"); |
181 | html("<tr><th>committer</th><td>"); | 181 | html("<tr><th>committer</th><td>"); |
182 | html_txt(info->committer); | 182 | html_txt(info->committer); |
183 | html(" "); | 183 | html(" "); |
184 | html_txt(info->committer_email); | 184 | html_txt(info->committer_email); |
185 | html("</td><td class='right'>"); | 185 | html("</td><td class='right'>"); |
186 | cgit_print_date(info->committer_date); | 186 | cgit_print_date(info->committer_date); |
187 | html("</td></tr>\n"); | 187 | html("</td></tr>\n"); |
188 | html("<tr><th>tree</th><td colspan='2' class='sha1'><a href='"); | 188 | html("<tr><th>tree</th><td colspan='2' class='sha1'><a href='"); |
189 | query = fmt("id=%s", sha1_to_hex(commit->tree->object.sha1)); | 189 | query = fmt("h=%s&id=%s", sha1_to_hex(commit->object.sha1), |
190 | sha1_to_hex(commit->tree->object.sha1)); | ||
190 | html_attr(cgit_pageurl(cgit_query_repo, "tree", query)); | 191 | html_attr(cgit_pageurl(cgit_query_repo, "tree", query)); |
191 | htmlf("'>%s</a></td></tr>\n", sha1_to_hex(commit->tree->object.sha1)); | 192 | htmlf("'>%s</a></td></tr>\n", sha1_to_hex(commit->tree->object.sha1)); |
192 | for (p = commit->parents; p ; p = p->next) { | 193 | for (p = commit->parents; p ; p = p->next) { |
193 | parent = lookup_commit_reference(p->item->object.sha1); | 194 | parent = lookup_commit_reference(p->item->object.sha1); |
194 | if (!parent) { | 195 | if (!parent) { |
195 | html("<tr><td colspan='3'>"); | 196 | html("<tr><td colspan='3'>"); |
196 | cgit_print_error("Error reading parent commit"); | 197 | cgit_print_error("Error reading parent commit"); |
197 | html("</td></tr>"); | 198 | html("</td></tr>"); |
198 | continue; | 199 | continue; |
199 | } | 200 | } |
200 | html("<tr><th>parent</th>" | 201 | html("<tr><th>parent</th>" |
201 | "<td colspan='2' class='sha1'>" | 202 | "<td colspan='2' class='sha1'>" |
202 | "<a href='"); | 203 | "<a href='"); |
203 | query = fmt("id=%s", sha1_to_hex(p->item->object.sha1)); | 204 | query = fmt("id=%s", sha1_to_hex(p->item->object.sha1)); |
204 | html_attr(cgit_pageurl(cgit_query_repo, "commit", query)); | 205 | html_attr(cgit_pageurl(cgit_query_repo, "commit", query)); |
205 | htmlf("'>%s</a> (<a href='", | 206 | htmlf("'>%s</a> (<a href='", |
206 | sha1_to_hex(p->item->object.sha1)); | 207 | sha1_to_hex(p->item->object.sha1)); |
207 | query = fmt("id=%s&id2=%s", sha1_to_hex(parent->tree->object.sha1), | 208 | query = fmt("id=%s&id2=%s", sha1_to_hex(parent->tree->object.sha1), |
208 | sha1_to_hex(commit->tree->object.sha1)); | 209 | sha1_to_hex(commit->tree->object.sha1)); |
209 | html_attr(cgit_pageurl(cgit_query_repo, "diff", query)); | 210 | html_attr(cgit_pageurl(cgit_query_repo, "diff", query)); |
210 | html("'>diff</a>)</td></tr>"); | 211 | html("'>diff</a>)</td></tr>"); |
211 | } | 212 | } |
212 | if (cgit_repo->snapshots) { | 213 | if (cgit_repo->snapshots) { |
213 | htmlf("<tr><th>download</th><td colspan='2' class='sha1'><a href='"); | 214 | htmlf("<tr><th>download</th><td colspan='2' class='sha1'><a href='"); |
214 | filename = fmt("%s-%s.zip", cgit_query_repo, hex); | 215 | filename = fmt("%s-%s.zip", cgit_query_repo, hex); |
215 | html_attr(cgit_pageurl(cgit_query_repo, "snapshot", | 216 | html_attr(cgit_pageurl(cgit_query_repo, "snapshot", |
216 | fmt("id=%s&name=%s", hex, filename))); | 217 | fmt("id=%s&name=%s", hex, filename))); |
217 | htmlf("'>%s</a></td></tr>", filename); | 218 | htmlf("'>%s</a></td></tr>", filename); |
218 | } | 219 | } |
219 | html("</table>\n"); | 220 | html("</table>\n"); |
220 | html("<div class='commit-subject'>"); | 221 | html("<div class='commit-subject'>"); |
221 | html_txt(info->subject); | 222 | html_txt(info->subject); |
222 | html("</div>"); | 223 | html("</div>"); |
223 | html("<div class='commit-msg'>"); | 224 | html("<div class='commit-msg'>"); |
224 | html_txt(info->msg); | 225 | html_txt(info->msg); |
225 | html("</div>"); | 226 | html("</div>"); |
226 | if (!(commit->parents && commit->parents->next && commit->parents->next->next)) { | 227 | if (!(commit->parents && commit->parents->next && commit->parents->next->next)) { |
227 | html("<table class='diffstat'>"); | 228 | html("<table class='diffstat'>"); |
228 | max_changes = 0; | 229 | max_changes = 0; |
229 | cgit_diff_commit(commit, inspect_filepair); | 230 | cgit_diff_commit(commit, inspect_filepair); |
230 | for(i = 0; i<files; i++) | 231 | for(i = 0; i<files; i++) |
231 | print_fileinfo(&items[i]); | 232 | print_fileinfo(&items[i]); |
232 | html("</table>"); | 233 | html("</table>"); |
233 | html("<div class='diffstat-summary'>"); | 234 | html("<div class='diffstat-summary'>"); |
234 | htmlf("%d files changed, %d insertions, %d deletions\n", | 235 | htmlf("%d files changed, %d insertions, %d deletions\n", |
235 | files, total_adds, total_rems); | 236 | files, total_adds, total_rems); |
236 | html("</div>"); | 237 | html("</div>"); |
237 | } | 238 | } |
238 | cgit_free_commitinfo(info); | 239 | cgit_free_commitinfo(info); |
239 | } | 240 | } |
@@ -1,120 +1,124 @@ | |||
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 | int files, lines; | 11 | int files, lines; |
12 | 12 | ||
13 | void count_lines(char *line, int size) | 13 | void count_lines(char *line, int size) |
14 | { | 14 | { |
15 | if (size>0 && (line[0] == '+' || line[0] == '-')) | 15 | if (size>0 && (line[0] == '+' || line[0] == '-')) |
16 | lines++; | 16 | lines++; |
17 | } | 17 | } |
18 | 18 | ||
19 | void inspect_files(struct diff_filepair *pair) | 19 | void inspect_files(struct diff_filepair *pair) |
20 | { | 20 | { |
21 | files++; | 21 | files++; |
22 | cgit_diff_files(pair->one->sha1, pair->two->sha1, count_lines); | 22 | cgit_diff_files(pair->one->sha1, pair->two->sha1, count_lines); |
23 | } | 23 | } |
24 | 24 | ||
25 | void print_commit(struct commit *commit) | 25 | void print_commit(struct commit *commit) |
26 | { | 26 | { |
27 | char buf[32]; | 27 | char buf[32]; |
28 | struct commitinfo *info; | 28 | struct commitinfo *info; |
29 | struct tm *time; | 29 | struct tm *time; |
30 | 30 | ||
31 | info = cgit_parse_commit(commit); | 31 | info = cgit_parse_commit(commit); |
32 | time = gmtime(&commit->date); | 32 | time = gmtime(&commit->date); |
33 | html("<tr><td>"); | 33 | html("<tr><td>"); |
34 | strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M", time); | 34 | strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M", time); |
35 | html_txt(buf); | 35 | html_txt(buf); |
36 | html("</td><td>"); | 36 | html("</td><td>"); |
37 | char *qry = fmt("id=%s", sha1_to_hex(commit->object.sha1)); | 37 | char *qry = fmt("id=%s", sha1_to_hex(commit->object.sha1)); |
38 | char *url = cgit_pageurl(cgit_query_repo, "commit", qry); | 38 | char *url = cgit_pageurl(cgit_query_repo, "commit", qry); |
39 | html_link_open(url, NULL, NULL); | 39 | html_link_open(url, NULL, NULL); |
40 | html_ntxt(cgit_max_msg_len, info->subject); | 40 | html_ntxt(cgit_max_msg_len, info->subject); |
41 | html_link_close(); | 41 | html_link_close(); |
42 | files = 0; | 42 | files = 0; |
43 | lines = 0; | 43 | lines = 0; |
44 | cgit_diff_commit(commit, inspect_files); | 44 | cgit_diff_commit(commit, inspect_files); |
45 | html("</td><td class='right'>"); | 45 | html("</td><td class='right'>"); |
46 | htmlf("%d", files); | 46 | htmlf("%d", files); |
47 | html("</td><td class='right'>"); | 47 | html("</td><td class='right'>"); |
48 | htmlf("%d", lines); | 48 | htmlf("%d", lines); |
49 | html("</td><td>"); | 49 | html("</td><td>"); |
50 | html_txt(info->author); | 50 | html_txt(info->author); |
51 | html("</td></tr>\n"); | 51 | html("</td></tr>\n"); |
52 | cgit_free_commitinfo(info); | 52 | cgit_free_commitinfo(info); |
53 | } | 53 | } |
54 | 54 | ||
55 | 55 | ||
56 | void cgit_print_log(const char *tip, int ofs, int cnt, char *grep) | 56 | void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *path) |
57 | { | 57 | { |
58 | struct rev_info rev; | 58 | struct rev_info rev; |
59 | struct commit *commit; | 59 | struct commit *commit; |
60 | const char *argv[3] = {NULL, tip, NULL}; | 60 | const char *argv[] = {NULL, tip, NULL, NULL, NULL}; |
61 | int argc = 2; | 61 | int argc = 2; |
62 | int i; | 62 | int i; |
63 | 63 | ||
64 | if (grep) | 64 | if (grep) |
65 | argv[argc++] = fmt("--grep=%s", grep); | 65 | argv[argc++] = fmt("--grep=%s", grep); |
66 | if (path) { | ||
67 | argv[argc++] = "--"; | ||
68 | argv[argc++] = path; | ||
69 | } | ||
66 | init_revisions(&rev, NULL); | 70 | init_revisions(&rev, NULL); |
67 | rev.abbrev = DEFAULT_ABBREV; | 71 | rev.abbrev = DEFAULT_ABBREV; |
68 | rev.commit_format = CMIT_FMT_DEFAULT; | 72 | rev.commit_format = CMIT_FMT_DEFAULT; |
69 | rev.verbose_header = 1; | 73 | rev.verbose_header = 1; |
70 | rev.show_root_diff = 0; | 74 | rev.show_root_diff = 0; |
71 | setup_revisions(argc, argv, &rev, NULL); | 75 | setup_revisions(argc, argv, &rev, NULL); |
72 | if (rev.grep_filter) { | 76 | if (rev.grep_filter) { |
73 | rev.grep_filter->regflags |= REG_ICASE; | 77 | rev.grep_filter->regflags |= REG_ICASE; |
74 | compile_grep_patterns(rev.grep_filter); | 78 | compile_grep_patterns(rev.grep_filter); |
75 | } | 79 | } |
76 | prepare_revision_walk(&rev); | 80 | prepare_revision_walk(&rev); |
77 | 81 | ||
78 | html("<table class='list nowrap'>"); | 82 | html("<table class='list nowrap'>"); |
79 | html("<tr class='nohover'><th class='left'>Date</th>" | 83 | html("<tr class='nohover'><th class='left'>Date</th>" |
80 | "<th class='left'>Message</th>" | 84 | "<th class='left'>Message</th>" |
81 | "<th class='left'>Files</th>" | 85 | "<th class='left'>Files</th>" |
82 | "<th class='left'>Lines</th>" | 86 | "<th class='left'>Lines</th>" |
83 | "<th class='left'>Author</th></tr>\n"); | 87 | "<th class='left'>Author</th></tr>\n"); |
84 | 88 | ||
85 | if (ofs<0) | 89 | if (ofs<0) |
86 | ofs = 0; | 90 | ofs = 0; |
87 | 91 | ||
88 | for (i = 0; i < ofs && (commit = get_revision(&rev)) != NULL; i++) { | 92 | for (i = 0; i < ofs && (commit = get_revision(&rev)) != NULL; i++) { |
89 | free(commit->buffer); | 93 | free(commit->buffer); |
90 | commit->buffer = NULL; | 94 | commit->buffer = NULL; |
91 | free_commit_list(commit->parents); | 95 | free_commit_list(commit->parents); |
92 | commit->parents = NULL; | 96 | commit->parents = NULL; |
93 | } | 97 | } |
94 | 98 | ||
95 | for (i = 0; i < cnt && (commit = get_revision(&rev)) != NULL; i++) { | 99 | for (i = 0; i < cnt && (commit = get_revision(&rev)) != NULL; i++) { |
96 | print_commit(commit); | 100 | print_commit(commit); |
97 | free(commit->buffer); | 101 | free(commit->buffer); |
98 | commit->buffer = NULL; | 102 | commit->buffer = NULL; |
99 | free_commit_list(commit->parents); | 103 | free_commit_list(commit->parents); |
100 | commit->parents = NULL; | 104 | commit->parents = NULL; |
101 | } | 105 | } |
102 | html("</table>\n"); | 106 | html("</table>\n"); |
103 | 107 | ||
104 | html("<div class='pager'>"); | 108 | html("<div class='pager'>"); |
105 | if (ofs > 0) { | 109 | if (ofs > 0) { |
106 | html(" <a href='"); | 110 | html(" <a href='"); |
107 | html(cgit_pageurl(cgit_query_repo, cgit_query_page, | 111 | html(cgit_pageurl(cgit_query_repo, cgit_query_page, |
108 | fmt("h=%s&ofs=%d", tip, ofs-cnt))); | 112 | fmt("h=%s&ofs=%d", tip, ofs-cnt))); |
109 | html("'>[prev]</a> "); | 113 | html("'>[prev]</a> "); |
110 | } | 114 | } |
111 | 115 | ||
112 | if ((commit = get_revision(&rev)) != NULL) { | 116 | if ((commit = get_revision(&rev)) != NULL) { |
113 | html(" <a href='"); | 117 | html(" <a href='"); |
114 | html(cgit_pageurl(cgit_query_repo, "log", | 118 | html(cgit_pageurl(cgit_query_repo, "log", |
115 | fmt("h=%s&ofs=%d", tip, ofs+cnt))); | 119 | fmt("h=%s&ofs=%d", tip, ofs+cnt))); |
116 | html("'>[next]</a> "); | 120 | html("'>[next]</a> "); |
117 | } | 121 | } |
118 | html("</div>"); | 122 | html("</div>"); |
119 | } | 123 | } |
120 | 124 | ||
@@ -1,81 +1,94 @@ | |||
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 | char *curr_rev; | ||
11 | 12 | ||
12 | static int print_entry(const unsigned char *sha1, const char *base, | 13 | static int print_entry(const unsigned char *sha1, const char *base, |
13 | int baselen, const char *pathname, unsigned int mode, | 14 | int baselen, const char *pathname, unsigned int mode, |
14 | int stage) | 15 | int stage) |
15 | { | 16 | { |
16 | char *name; | 17 | char *name; |
17 | enum object_type type; | 18 | enum object_type type; |
18 | unsigned long size = 0; | 19 | unsigned long size = 0; |
19 | 20 | ||
20 | name = xstrdup(pathname); | 21 | name = xstrdup(pathname); |
21 | type = sha1_object_info(sha1, &size); | 22 | type = sha1_object_info(sha1, &size); |
22 | if (type == OBJ_BAD && !S_ISDIRLNK(mode)) { | 23 | if (type == OBJ_BAD && !S_ISDIRLNK(mode)) { |
23 | htmlf("<tr><td colspan='3'>Bad object: %s %s</td></tr>", | 24 | htmlf("<tr><td colspan='3'>Bad object: %s %s</td></tr>", |
24 | name, | 25 | name, |
25 | sha1_to_hex(sha1)); | 26 | sha1_to_hex(sha1)); |
26 | return 0; | 27 | return 0; |
27 | } | 28 | } |
28 | html("<tr><td class='filemode'>"); | 29 | html("<tr><td class='filemode'>"); |
29 | html_filemode(mode); | 30 | html_filemode(mode); |
30 | html("</td><td "); | 31 | html("</td><td "); |
31 | if (S_ISDIRLNK(mode)) { | 32 | if (S_ISDIRLNK(mode)) { |
32 | htmlf("class='ls-mod'><a href='"); | 33 | htmlf("class='ls-mod'><a href='"); |
33 | html_attr(fmt(cgit_repo->module_link, | 34 | html_attr(fmt(cgit_repo->module_link, |
34 | name, | 35 | name, |
35 | sha1_to_hex(sha1))); | 36 | sha1_to_hex(sha1))); |
36 | } else if (S_ISDIR(mode)) { | 37 | } else if (S_ISDIR(mode)) { |
37 | html("class='ls-dir'><a href='"); | 38 | html("class='ls-dir'><a href='"); |
38 | html_attr(cgit_pageurl(cgit_query_repo, "tree", | 39 | html_attr(cgit_pageurl(cgit_query_repo, "tree", |
39 | fmt("id=%s&path=%s%s/", | 40 | fmt("h=%s&id=%s&path=%s%s/", |
41 | curr_rev, | ||
40 | sha1_to_hex(sha1), | 42 | sha1_to_hex(sha1), |
41 | cgit_query_path ? cgit_query_path : "", | 43 | cgit_query_path ? cgit_query_path : "", |
42 | pathname))); | 44 | pathname))); |
43 | } else { | 45 | } else { |
44 | html("class='ls-blob'><a href='"); | 46 | html("class='ls-blob'><a href='"); |
45 | html_attr(cgit_pageurl(cgit_query_repo, "view", | 47 | html_attr(cgit_pageurl(cgit_query_repo, "view", |
46 | fmt("id=%s&path=%s%s", sha1_to_hex(sha1), | 48 | fmt("h=%s&id=%s&path=%s%s", curr_rev, |
49 | sha1_to_hex(sha1), | ||
47 | cgit_query_path ? cgit_query_path : "", | 50 | cgit_query_path ? cgit_query_path : "", |
48 | pathname))); | 51 | pathname))); |
49 | } | 52 | } |
50 | htmlf("'>%s</a></div></td>", name); | 53 | htmlf("'>%s</a></div></td>", name); |
51 | htmlf("<td class='filesize'>%li</td>", size); | 54 | htmlf("<td class='filesize'>%li</td>", size); |
55 | |||
56 | html("<td class='links'><a href='"); | ||
57 | html_attr(cgit_pageurl(cgit_query_repo, "log", | ||
58 | fmt("h=%s&path=%s%s", | ||
59 | curr_rev, | ||
60 | cgit_query_path ? cgit_query_path : "", | ||
61 | pathname))); | ||
62 | html("'>history</a></td>"); | ||
52 | html("</tr>\n"); | 63 | html("</tr>\n"); |
53 | free(name); | 64 | free(name); |
54 | return 0; | 65 | return 0; |
55 | } | 66 | } |
56 | 67 | ||
57 | void cgit_print_tree(const char *hex, char *path) | 68 | void cgit_print_tree(const char *rev, const char *hex, char *path) |
58 | { | 69 | { |
59 | struct tree *tree; | 70 | struct tree *tree; |
60 | unsigned char sha1[20]; | 71 | unsigned char sha1[20]; |
61 | 72 | ||
73 | curr_rev = xstrdup(rev); | ||
62 | if (get_sha1_hex(hex, sha1)) { | 74 | if (get_sha1_hex(hex, sha1)) { |
63 | cgit_print_error(fmt("Invalid object id: %s", hex)); | 75 | cgit_print_error(fmt("Invalid object id: %s", hex)); |
64 | return; | 76 | return; |
65 | } | 77 | } |
66 | tree = parse_tree_indirect(sha1); | 78 | tree = parse_tree_indirect(sha1); |
67 | if (!tree) { | 79 | if (!tree) { |
68 | cgit_print_error(fmt("Not a tree object: %s", hex)); | 80 | cgit_print_error(fmt("Not a tree object: %s", hex)); |
69 | return; | 81 | return; |
70 | } | 82 | } |
71 | 83 | ||
72 | html_txt(path); | 84 | html_txt(path); |
73 | html("<table class='list'>\n"); | 85 | html("<table class='list'>\n"); |
74 | html("<tr class='nohover'>"); | 86 | html("<tr class='nohover'>"); |
75 | html("<th class='left'>Mode</th>"); | 87 | html("<th class='left'>Mode</th>"); |
76 | html("<th class='left'>Name</th>"); | 88 | html("<th class='left'>Name</th>"); |
77 | html("<th class='right'>Size</th>"); | 89 | html("<th class='right'>Size</th>"); |
90 | html("<th/>"); | ||
78 | html("</tr>\n"); | 91 | html("</tr>\n"); |
79 | read_tree_recursive(tree, "", 0, 1, NULL, print_entry); | 92 | read_tree_recursive(tree, "", 0, 1, NULL, print_entry); |
80 | html("</table>\n"); | 93 | html("</table>\n"); |
81 | } | 94 | } |