summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--cgit.c2
-rw-r--r--cgit.css5
-rw-r--r--cgit.h2
-rw-r--r--ui-commit.c19
-rw-r--r--ui-diff.c45
5 files changed, 63 insertions, 10 deletions
diff --git a/cgit.c b/cgit.c
index aee7ba3..3d85a08 100644
--- a/cgit.c
+++ b/cgit.c
@@ -1,259 +1,259 @@
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
11const char cgit_version[] = CGIT_VERSION; 11const char cgit_version[] = CGIT_VERSION;
12 12
13 13
14static struct repoinfo *cgit_get_repoinfo(char *url) 14static 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
28static int cgit_prepare_cache(struct cacheitem *item) 28static 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
63static void cgit_print_repo_page(struct cacheitem *item) 63static 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 } else if (!strcmp(cgit_query_page, "tree")) { 112 } else if (!strcmp(cgit_query_page, "tree")) {
113 cgit_print_tree(cgit_query_sha1, cgit_query_path); 113 cgit_print_tree(cgit_query_sha1, cgit_query_path);
114 } else if (!strcmp(cgit_query_page, "commit")) { 114 } else if (!strcmp(cgit_query_page, "commit")) {
115 cgit_print_commit(cgit_query_sha1); 115 cgit_print_commit(cgit_query_sha1);
116 } else if (!strcmp(cgit_query_page, "view")) { 116 } else if (!strcmp(cgit_query_page, "view")) {
117 cgit_print_view(cgit_query_sha1, cgit_query_path); 117 cgit_print_view(cgit_query_sha1, cgit_query_path);
118 } else if (!strcmp(cgit_query_page, "diff")) { 118 } else if (!strcmp(cgit_query_page, "diff")) {
119 cgit_print_diff(cgit_query_sha1, cgit_query_sha2); 119 cgit_print_diff(cgit_query_sha1, cgit_query_sha2, cgit_query_path);
120 } else { 120 } else {
121 cgit_print_error("Invalid request"); 121 cgit_print_error("Invalid request");
122 } 122 }
123 cgit_print_docend(); 123 cgit_print_docend();
124} 124}
125 125
126static void cgit_fill_cache(struct cacheitem *item, int use_cache) 126static void cgit_fill_cache(struct cacheitem *item, int use_cache)
127{ 127{
128 static char buf[PATH_MAX]; 128 static char buf[PATH_MAX];
129 int stdout2; 129 int stdout2;
130 130
131 getcwd(buf, sizeof(buf)); 131 getcwd(buf, sizeof(buf));
132 item->st.st_mtime = time(NULL); 132 item->st.st_mtime = time(NULL);
133 133
134 if (use_cache) { 134 if (use_cache) {
135 stdout2 = chk_positive(dup(STDOUT_FILENO), 135 stdout2 = chk_positive(dup(STDOUT_FILENO),
136 "Preserving STDOUT"); 136 "Preserving STDOUT");
137 chk_zero(close(STDOUT_FILENO), "Closing STDOUT"); 137 chk_zero(close(STDOUT_FILENO), "Closing STDOUT");
138 chk_positive(dup2(item->fd, STDOUT_FILENO), "Dup2(cachefile)"); 138 chk_positive(dup2(item->fd, STDOUT_FILENO), "Dup2(cachefile)");
139 } 139 }
140 140
141 if (cgit_query_repo) 141 if (cgit_query_repo)
142 cgit_print_repo_page(item); 142 cgit_print_repo_page(item);
143 else 143 else
144 cgit_print_repolist(item); 144 cgit_print_repolist(item);
145 145
146 if (use_cache) { 146 if (use_cache) {
147 chk_zero(close(STDOUT_FILENO), "Close redirected STDOUT"); 147 chk_zero(close(STDOUT_FILENO), "Close redirected STDOUT");
148 chk_positive(dup2(stdout2, STDOUT_FILENO), 148 chk_positive(dup2(stdout2, STDOUT_FILENO),
149 "Restoring original STDOUT"); 149 "Restoring original STDOUT");
150 chk_zero(close(stdout2), "Closing temporary STDOUT"); 150 chk_zero(close(stdout2), "Closing temporary STDOUT");
151 } 151 }
152 152
153 chdir(buf); 153 chdir(buf);
154} 154}
155 155
156static void cgit_check_cache(struct cacheitem *item) 156static void cgit_check_cache(struct cacheitem *item)
157{ 157{
158 int i = 0; 158 int i = 0;
159 159
160 top: 160 top:
161 if (++i > cgit_max_lock_attempts) { 161 if (++i > cgit_max_lock_attempts) {
162 die("cgit_refresh_cache: unable to lock %s: %s", 162 die("cgit_refresh_cache: unable to lock %s: %s",
163 item->name, strerror(errno)); 163 item->name, strerror(errno));
164 } 164 }
165 if (!cache_exist(item)) { 165 if (!cache_exist(item)) {
166 if (!cache_lock(item)) { 166 if (!cache_lock(item)) {
167 sleep(1); 167 sleep(1);
168 goto top; 168 goto top;
169 } 169 }
170 if (!cache_exist(item)) { 170 if (!cache_exist(item)) {
171 cgit_fill_cache(item, 1); 171 cgit_fill_cache(item, 1);
172 cache_unlock(item); 172 cache_unlock(item);
173 } else { 173 } else {
174 cache_cancel_lock(item); 174 cache_cancel_lock(item);
175 } 175 }
176 } else if (cache_expired(item) && cache_lock(item)) { 176 } else if (cache_expired(item) && cache_lock(item)) {
177 if (cache_expired(item)) { 177 if (cache_expired(item)) {
178 cgit_fill_cache(item, 1); 178 cgit_fill_cache(item, 1);
179 cache_unlock(item); 179 cache_unlock(item);
180 } else { 180 } else {
181 cache_cancel_lock(item); 181 cache_cancel_lock(item);
182 } 182 }
183 } 183 }
184} 184}
185 185
186static void cgit_print_cache(struct cacheitem *item) 186static void cgit_print_cache(struct cacheitem *item)
187{ 187{
188 static char buf[4096]; 188 static char buf[4096];
189 ssize_t i; 189 ssize_t i;
190 190
191 int fd = open(item->name, O_RDONLY); 191 int fd = open(item->name, O_RDONLY);
192 if (fd<0) 192 if (fd<0)
193 die("Unable to open cached file %s", item->name); 193 die("Unable to open cached file %s", item->name);
194 194
195 while((i=read(fd, buf, sizeof(buf))) > 0) 195 while((i=read(fd, buf, sizeof(buf))) > 0)
196 write(STDOUT_FILENO, buf, i); 196 write(STDOUT_FILENO, buf, i);
197 197
198 close(fd); 198 close(fd);
199} 199}
200 200
201static void cgit_parse_args(int argc, const char **argv) 201static void cgit_parse_args(int argc, const char **argv)
202{ 202{
203 int i; 203 int i;
204 204
205 for (i = 1; i < argc; i++) { 205 for (i = 1; i < argc; i++) {
206 if (!strncmp(argv[i], "--cache=", 8)) { 206 if (!strncmp(argv[i], "--cache=", 8)) {
207 cgit_cache_root = xstrdup(argv[i]+8); 207 cgit_cache_root = xstrdup(argv[i]+8);
208 } 208 }
209 if (!strcmp(argv[i], "--nocache")) { 209 if (!strcmp(argv[i], "--nocache")) {
210 cgit_nocache = 1; 210 cgit_nocache = 1;
211 } 211 }
212 if (!strncmp(argv[i], "--query=", 8)) { 212 if (!strncmp(argv[i], "--query=", 8)) {
213 cgit_querystring = xstrdup(argv[i]+8); 213 cgit_querystring = xstrdup(argv[i]+8);
214 } 214 }
215 if (!strncmp(argv[i], "--repo=", 7)) { 215 if (!strncmp(argv[i], "--repo=", 7)) {
216 cgit_query_repo = xstrdup(argv[i]+7); 216 cgit_query_repo = xstrdup(argv[i]+7);
217 } 217 }
218 if (!strncmp(argv[i], "--page=", 7)) { 218 if (!strncmp(argv[i], "--page=", 7)) {
219 cgit_query_page = xstrdup(argv[i]+7); 219 cgit_query_page = xstrdup(argv[i]+7);
220 } 220 }
221 if (!strncmp(argv[i], "--head=", 7)) { 221 if (!strncmp(argv[i], "--head=", 7)) {
222 cgit_query_head = xstrdup(argv[i]+7); 222 cgit_query_head = xstrdup(argv[i]+7);
223 cgit_query_has_symref = 1; 223 cgit_query_has_symref = 1;
224 } 224 }
225 if (!strncmp(argv[i], "--sha1=", 7)) { 225 if (!strncmp(argv[i], "--sha1=", 7)) {
226 cgit_query_sha1 = xstrdup(argv[i]+7); 226 cgit_query_sha1 = xstrdup(argv[i]+7);
227 cgit_query_has_sha1 = 1; 227 cgit_query_has_sha1 = 1;
228 } 228 }
229 if (!strncmp(argv[i], "--ofs=", 6)) { 229 if (!strncmp(argv[i], "--ofs=", 6)) {
230 cgit_query_ofs = atoi(argv[i]+6); 230 cgit_query_ofs = atoi(argv[i]+6);
231 } 231 }
232 } 232 }
233} 233}
234 234
235int main(int argc, const char **argv) 235int main(int argc, const char **argv)
236{ 236{
237 struct cacheitem item; 237 struct cacheitem item;
238 238
239 htmlfd = STDOUT_FILENO; 239 htmlfd = STDOUT_FILENO;
240 item.st.st_mtime = time(NULL); 240 item.st.st_mtime = time(NULL);
241 cgit_repolist.length = 0; 241 cgit_repolist.length = 0;
242 cgit_repolist.count = 0; 242 cgit_repolist.count = 0;
243 cgit_repolist.repos = NULL; 243 cgit_repolist.repos = NULL;
244 244
245 cgit_read_config("/etc/cgitrc", cgit_global_config_cb); 245 cgit_read_config("/etc/cgitrc", cgit_global_config_cb);
246 if (getenv("QUERY_STRING")) 246 if (getenv("QUERY_STRING"))
247 cgit_querystring = xstrdup(getenv("QUERY_STRING")); 247 cgit_querystring = xstrdup(getenv("QUERY_STRING"));
248 cgit_parse_args(argc, argv); 248 cgit_parse_args(argc, argv);
249 cgit_parse_query(cgit_querystring, cgit_querystring_cb); 249 cgit_parse_query(cgit_querystring, cgit_querystring_cb);
250 if (!cgit_prepare_cache(&item)) 250 if (!cgit_prepare_cache(&item))
251 return 0; 251 return 0;
252 if (cgit_nocache) { 252 if (cgit_nocache) {
253 cgit_fill_cache(&item, 0); 253 cgit_fill_cache(&item, 0);
254 } else { 254 } else {
255 cgit_check_cache(&item); 255 cgit_check_cache(&item);
256 cgit_print_cache(&item); 256 cgit_print_cache(&item);
257 } 257 }
258 return 0; 258 return 0;
259} 259}
diff --git a/cgit.css b/cgit.css
index b736b19..fe0ba50 100644
--- a/cgit.css
+++ b/cgit.css
@@ -1,322 +1,327 @@
1body { 1body {
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
7body, table { 7body, table {
8 padding: 0em; 8 padding: 0em;
9 margin: 0em; 9 margin: 0em;
10} 10}
11 11
12table { 12table {
13 border-collapse: collapse; 13 border-collapse: collapse;
14} 14}
15 15
16h2 { 16h2 {
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
23h3 { 23h3 {
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
29h4 { 29h4 {
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
36a { 36a {
37 color: blue; 37 color: blue;
38 text-decoration: none; 38 text-decoration: none;
39} 39}
40 40
41a:hover { 41a:hover {
42 text-decoration: underline; 42 text-decoration: underline;
43} 43}
44 44
45table.list { 45table.list {
46 border: none; 46 border: none;
47 border-collapse: collapse; 47 border-collapse: collapse;
48} 48}
49 49
50table.list tr { 50table.list tr {
51 background: white; 51 background: white;
52} 52}
53 53
54table.list tr:hover { 54table.list tr:hover {
55 background: #eee; 55 background: #eee;
56} 56}
57 57
58table.list tr.nohover:hover { 58table.list tr.nohover:hover {
59 background: white; 59 background: white;
60} 60}
61 61
62table.list th { 62table.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
69table.list td { 69table.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
74img { 74img {
75 border: none; 75 border: none;
76} 76}
77 77
78table#layout { 78table#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
84td#header, td#logo { 84td#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
90td#header { 90td#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
97td#logo { 97td#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
103td#crumb, td#search { 103td#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
111td#crumb { 111td#crumb {
112 font-weight: bold; 112 font-weight: bold;
113} 113}
114 114
115td#crumb a { 115td#crumb a {
116 color: #ccc; 116 color: #ccc;
117} 117}
118 118
119td#crumb a:hover { 119td#crumb a:hover {
120 color: #eee; 120 color: #eee;
121} 121}
122 122
123td#search { 123td#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
129td#search form { 129td#search form {
130 margin: 0px; 130 margin: 0px;
131 padding: 0px; 131 padding: 0px;
132} 132}
133 133
134td#search input { 134td#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
143td#summary { 143td#summary {
144 vertical-align: top; 144 vertical-align: top;
145 padding-bottom: 1em; 145 padding-bottom: 1em;
146} 146}
147 147
148td#archivelist { 148td#archivelist {
149 padding-bottom: 1em; 149 padding-bottom: 1em;
150} 150}
151 151
152td#archivelist table { 152td#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
158td#archivelist table th { 158td#archivelist table th {
159 background-color: #ccc; 159 background-color: #ccc;
160} 160}
161 161
162td#content { 162td#content {
163 padding: 1em 0.5em; 163 padding: 1em 0.5em;
164} 164}
165 165
166div#blob { 166div#blob {
167 border: solid 1px black; 167 border: solid 1px black;
168} 168}
169 169
170div.error { 170div.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
176td.ls-blob, td.ls-dir, td.ls-mod { 176td.ls-blob, td.ls-dir, td.ls-mod {
177 font-family: monospace; 177 font-family: monospace;
178} 178}
179 179
180div.ls-dir a { 180div.ls-dir a {
181 font-weight: bold; 181 font-weight: bold;
182} 182}
183 183
184th.filesize, td.filesize { 184th.filesize, td.filesize {
185 text-align: right; 185 text-align: right;
186} 186}
187 187
188td.filesize { 188td.filesize {
189 font-family: monospace; 189 font-family: monospace;
190} 190}
191 191
192td.filemode { 192td.filemode {
193 font-family: monospace; 193 font-family: monospace;
194} 194}
195 195
196td.blob { 196td.blob {
197 white-space: pre; 197 white-space: pre;
198 font-family: monospace; 198 font-family: monospace;
199 background-color: white; 199 background-color: white;
200} 200}
201 201
202table.nowrap td { 202table.nowrap td {
203 white-space: nowrap; 203 white-space: nowrap;
204} 204}
205 205
206table.commit-info { 206table.commit-info {
207 border-collapse: collapse; 207 border-collapse: collapse;
208 margin-top: 1.5em; 208 margin-top: 1.5em;
209} 209}
210 210
211table.commit-info th { 211table.commit-info th {
212 text-align: left; 212 text-align: left;
213 font-weight: normal; 213 font-weight: normal;
214 padding: 0.1em 1em 0.1em 0.1em; 214 padding: 0.1em 1em 0.1em 0.1em;
215} 215}
216 216
217table.commit-info td { 217table.commit-info td {
218 font-weight: normal; 218 font-weight: normal;
219 padding: 0.1em 1em 0.1em 0.1em; 219 padding: 0.1em 1em 0.1em 0.1em;
220} 220}
221 221
222div.commit-subject { 222div.commit-subject {
223 font-weight: bold; 223 font-weight: bold;
224 font-size: 125%; 224 font-size: 125%;
225 margin: 1.5em 0em 0.5em 0em; 225 margin: 1.5em 0em 0.5em 0em;
226 padding: 0em; 226 padding: 0em;
227} 227}
228 228
229div.commit-msg { 229div.commit-msg {
230 white-space: pre; 230 white-space: pre;
231 font-family: monospace; 231 font-family: monospace;
232} 232}
233 233
234table.diffstat { 234table.diffstat {
235 border-collapse: collapse; 235 border-collapse: collapse;
236 margin-top: 1.5em; 236 margin-top: 1.5em;
237 width: 100%; 237 width: 100%;
238 border: solid 1px #aaa; 238 border: solid 1px #aaa;
239} 239}
240 240
241table.diffstat tr:hover { 241table.diffstat tr:hover {
242 background-color: #eee; 242 background-color: #eee;
243} 243}
244 244
245table.diffstat th { 245table.diffstat th {
246 font-weight: normal; 246 font-weight: normal;
247 text-align: left; 247 text-align: left;
248 text-decoration: underline; 248 text-decoration: underline;
249 padding: 0.1em 1em 0.1em 0.1em; 249 padding: 0.1em 1em 0.1em 0.1em;
250 font-size: 100%; 250 font-size: 100%;
251} 251}
252 252
253table.diffstat td { 253table.diffstat td {
254 padding: 0.2em 0.2em 0.1em 0.1em; 254 padding: 0.2em 0.2em 0.1em 0.1em;
255 font-size: 100%; 255 font-size: 100%;
256 border: none; 256 border: none;
257 border-top: solid 1px #aaa; 257 border-top: solid 1px #aaa;
258 border-bottom: solid 1px #aaa; 258 border-bottom: solid 1px #aaa;
259} 259}
260 260
261table.diffstat td span.modechange { 261table.diffstat td span.modechange {
262 padding-left: 1em; 262 padding-left: 1em;
263 color: red; 263 color: red;
264} 264}
265 265
266table.diffstat td.add a { 266table.diffstat td.add a {
267 color: green; 267 color: green;
268} 268}
269 269
270table.diffstat td.del a { 270table.diffstat td.del a {
271 color: red; 271 color: red;
272} 272}
273 273
274table.diffstat td.upd a { 274table.diffstat td.upd a {
275 color: blue; 275 color: blue;
276} 276}
277 277
278table.diffstat td.graph { 278table.diffstat td.graph {
279 width: 75%; 279 width: 75%;
280 vertical-align: center; 280 vertical-align: center;
281} 281}
282 282
283table.diffstat td.graph img { 283table.diffstat td.graph img {
284 border: none; 284 border: none;
285 height: 11pt; 285 height: 11pt;
286} 286}
287 287
288div.diffstat-summary { 288div.diffstat-summary {
289 color: #888; 289 color: #888;
290 padding-top: 0.5em; 290 padding-top: 0.5em;
291} 291}
292 292
293table.diff th {
294 padding: 1em 0em 0.1em 0.1em;
295 text-align: left;
296}
297
293table.diff td { 298table.diff td {
294 border: solid 1px black; 299 border: solid 1px black;
295 font-family: monospace; 300 font-family: monospace;
296 white-space: pre; 301 white-space: pre;
297} 302}
298 303
299table.diff td div.hunk { 304table.diff td div.hunk {
300 background: #ccc; 305 background: #ccc;
301} 306}
302 307
303table.diff td div.add { 308table.diff td div.add {
304 color: green; 309 color: green;
305} 310}
306 311
307table.diff td div.del { 312table.diff td div.del {
308 color: red; 313 color: red;
309} 314}
310 315
311.sha1 { 316.sha1 {
312 font-family: courier; 317 font-family: courier;
313 font-size: 90%; 318 font-size: 90%;
314} 319}
315 320
316.left { 321.left {
317 text-align: left; 322 text-align: left;
318} 323}
319 324
320.right { 325.right {
321 text-align: right; 326 text-align: right;
322} 327}
diff --git a/cgit.h b/cgit.h
index 46f3173..93699b5 100644
--- a/cgit.h
+++ b/cgit.h
@@ -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
21typedef void (*configfn)(const char *name, const char *value); 21typedef void (*configfn)(const char *name, const char *value);
22typedef void (*filepair_fn)(struct diff_filepair *pair); 22typedef void (*filepair_fn)(struct diff_filepair *pair);
23typedef void (*linediff_fn)(char *line, int len); 23typedef void (*linediff_fn)(char *line, int len);
24 24
25struct cacheitem { 25struct 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
32struct repoinfo { 32struct 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
42struct repolist { 42struct 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
48struct commitinfo { 48struct 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
60struct taginfo { 60struct 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
67extern const char cgit_version[]; 67extern const char cgit_version[];
68 68
69extern struct repolist cgit_repolist; 69extern struct repolist cgit_repolist;
70extern struct repoinfo *cgit_repo; 70extern struct repoinfo *cgit_repo;
71 71
72extern char *cgit_root_title; 72extern char *cgit_root_title;
73extern char *cgit_css; 73extern char *cgit_css;
74extern char *cgit_logo; 74extern char *cgit_logo;
75extern char *cgit_logo_link; 75extern char *cgit_logo_link;
76extern char *cgit_module_link; 76extern char *cgit_module_link;
77extern char *cgit_virtual_root; 77extern char *cgit_virtual_root;
78extern char *cgit_cache_root; 78extern char *cgit_cache_root;
79 79
80extern int cgit_nocache; 80extern int cgit_nocache;
81extern int cgit_snapshots; 81extern int cgit_snapshots;
82extern int cgit_max_lock_attempts; 82extern int cgit_max_lock_attempts;
83extern int cgit_cache_root_ttl; 83extern int cgit_cache_root_ttl;
84extern int cgit_cache_repo_ttl; 84extern int cgit_cache_repo_ttl;
85extern int cgit_cache_dynamic_ttl; 85extern int cgit_cache_dynamic_ttl;
86extern int cgit_cache_static_ttl; 86extern int cgit_cache_static_ttl;
87extern int cgit_cache_max_create_time; 87extern int cgit_cache_max_create_time;
88 88
89extern int cgit_max_msg_len; 89extern int cgit_max_msg_len;
90extern int cgit_max_commit_count; 90extern int cgit_max_commit_count;
91 91
92extern char *cgit_repo_name; 92extern char *cgit_repo_name;
93extern char *cgit_repo_desc; 93extern char *cgit_repo_desc;
94extern char *cgit_repo_owner; 94extern char *cgit_repo_owner;
95 95
96extern int cgit_query_has_symref; 96extern int cgit_query_has_symref;
97extern int cgit_query_has_sha1; 97extern int cgit_query_has_sha1;
98 98
99extern char *cgit_querystring; 99extern char *cgit_querystring;
100extern char *cgit_query_repo; 100extern char *cgit_query_repo;
101extern char *cgit_query_page; 101extern char *cgit_query_page;
102extern char *cgit_query_search; 102extern char *cgit_query_search;
103extern char *cgit_query_head; 103extern char *cgit_query_head;
104extern char *cgit_query_sha1; 104extern char *cgit_query_sha1;
105extern char *cgit_query_sha2; 105extern char *cgit_query_sha2;
106extern char *cgit_query_path; 106extern char *cgit_query_path;
107extern char *cgit_query_name; 107extern char *cgit_query_name;
108extern int cgit_query_ofs; 108extern int cgit_query_ofs;
109 109
110extern int htmlfd; 110extern int htmlfd;
111 111
112extern void cgit_global_config_cb(const char *name, const char *value); 112extern void cgit_global_config_cb(const char *name, const char *value);
113extern void cgit_repo_config_cb(const char *name, const char *value); 113extern void cgit_repo_config_cb(const char *name, const char *value);
114extern void cgit_querystring_cb(const char *name, const char *value); 114extern void cgit_querystring_cb(const char *name, const char *value);
115 115
116extern int chk_zero(int result, char *msg); 116extern int chk_zero(int result, char *msg);
117extern int chk_positive(int result, char *msg); 117extern int chk_positive(int result, char *msg);
118 118
119extern int hextoint(char c); 119extern int hextoint(char c);
120 120
121extern void *cgit_free_commitinfo(struct commitinfo *info); 121extern void *cgit_free_commitinfo(struct commitinfo *info);
122 122
123extern int cgit_diff_files(const unsigned char *old_sha1, 123extern 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
127extern void cgit_diff_tree(const unsigned char *old_sha1, 127extern 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
131extern void cgit_diff_commit(struct commit *commit, filepair_fn fn); 131extern void cgit_diff_commit(struct commit *commit, filepair_fn fn);
132 132
133extern char *fmt(const char *format,...); 133extern char *fmt(const char *format,...);
134 134
135extern void html(const char *txt); 135extern void html(const char *txt);
136extern void htmlf(const char *format,...); 136extern void htmlf(const char *format,...);
137extern void html_txt(char *txt); 137extern void html_txt(char *txt);
138extern void html_ntxt(int len, char *txt); 138extern void html_ntxt(int len, char *txt);
139extern void html_attr(char *txt); 139extern void html_attr(char *txt);
140extern void html_hidden(char *name, char *value); 140extern void html_hidden(char *name, char *value);
141extern void html_link_open(char *url, char *title, char *class); 141extern void html_link_open(char *url, char *title, char *class);
142extern void html_link_close(void); 142extern void html_link_close(void);
143extern void html_filemode(unsigned short mode); 143extern void html_filemode(unsigned short mode);
144 144
145extern int cgit_read_config(const char *filename, configfn fn); 145extern int cgit_read_config(const char *filename, configfn fn);
146extern int cgit_parse_query(char *txt, configfn fn); 146extern int cgit_parse_query(char *txt, configfn fn);
147extern struct commitinfo *cgit_parse_commit(struct commit *commit); 147extern struct commitinfo *cgit_parse_commit(struct commit *commit);
148extern struct taginfo *cgit_parse_tag(struct tag *tag); 148extern struct taginfo *cgit_parse_tag(struct tag *tag);
149 149
150extern char *cache_safe_filename(const char *unsafe); 150extern char *cache_safe_filename(const char *unsafe);
151extern int cache_lock(struct cacheitem *item); 151extern int cache_lock(struct cacheitem *item);
152extern int cache_unlock(struct cacheitem *item); 152extern int cache_unlock(struct cacheitem *item);
153extern int cache_cancel_lock(struct cacheitem *item); 153extern int cache_cancel_lock(struct cacheitem *item);
154extern int cache_exist(struct cacheitem *item); 154extern int cache_exist(struct cacheitem *item);
155extern int cache_expired(struct cacheitem *item); 155extern int cache_expired(struct cacheitem *item);
156 156
157extern char *cgit_repourl(const char *reponame); 157extern char *cgit_repourl(const char *reponame);
158extern char *cgit_pageurl(const char *reponame, const char *pagename, 158extern char *cgit_pageurl(const char *reponame, const char *pagename,
159 const char *query); 159 const char *query);
160 160
161extern void cgit_print_error(char *msg); 161extern void cgit_print_error(char *msg);
162extern void cgit_print_date(unsigned long secs); 162extern void cgit_print_date(unsigned long secs);
163extern void cgit_print_docstart(char *title, struct cacheitem *item); 163extern void cgit_print_docstart(char *title, struct cacheitem *item);
164extern void cgit_print_docend(); 164extern void cgit_print_docend();
165extern void cgit_print_pageheader(char *title, int show_search); 165extern void cgit_print_pageheader(char *title, int show_search);
166extern void cgit_print_snapshot_start(const char *mimetype, 166extern 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
170extern void cgit_print_repolist(struct cacheitem *item); 170extern void cgit_print_repolist(struct cacheitem *item);
171extern void cgit_print_summary(); 171extern void cgit_print_summary();
172extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep); 172extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep);
173extern void cgit_print_view(const char *hex, char *path); 173extern void cgit_print_view(const char *hex, char *path);
174extern void cgit_print_blob(struct cacheitem *item, const char *hex, char *path); 174extern void cgit_print_blob(struct cacheitem *item, const char *hex, char *path);
175extern void cgit_print_tree(const char *hex, char *path); 175extern void cgit_print_tree(const char *hex, char *path);
176extern void cgit_print_commit(const char *hex); 176extern void cgit_print_commit(const char *hex);
177extern void cgit_print_diff(const char *old_hex, const char *new_hex); 177extern void cgit_print_diff(const char *old_hex, const char *new_hex, char *path);
178extern void cgit_print_snapshot(struct cacheitem *item, const char *hex, 178extern 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 ce33cf9..b3d1c28 100644
--- a/ui-commit.c
+++ b/ui-commit.c
@@ -1,228 +1,239 @@
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
11int files = 0, slots = 0; 11int files = 0, slots = 0;
12int total_adds = 0, total_rems = 0, max_changes = 0; 12int total_adds = 0, total_rems = 0, max_changes = 0;
13int lines_added, lines_removed; 13int lines_added, lines_removed;
14 14
15struct fileinfo { 15struct 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
28void print_fileinfo(struct fileinfo *info) 28void 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", 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)); 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
113void cgit_count_diff_lines(char *line, int len) 113void 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
123void inspect_filepair(struct diff_filepair *pair) 123void 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
152void cgit_print_commit(const char *hex) 152void cgit_print_commit(const char *hex)
153{ 153{
154 struct commit *commit; 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("id=%s", sha1_to_hex(commit->tree->object.sha1));
190 html_attr(cgit_pageurl(cgit_query_repo, "tree", query)); 190 html_attr(cgit_pageurl(cgit_query_repo, "tree", query));
191 htmlf("'>%s</a></td></tr>\n", sha1_to_hex(commit->tree->object.sha1)); 191 htmlf("'>%s</a></td></tr>\n", sha1_to_hex(commit->tree->object.sha1));
192 for (p = commit->parents; p ; p = p->next) { 192 for (p = commit->parents; p ; p = p->next) {
193 parent = lookup_commit_reference(p->item->object.sha1);
194 if (!parent) {
195 html("<tr><td colspan='3'>");
196 cgit_print_error("Error reading parent commit");
197 html("</td></tr>");
198 continue;
199 }
193 html("<tr><th>parent</th>" 200 html("<tr><th>parent</th>"
194 "<td colspan='2' class='sha1'>" 201 "<td colspan='2' class='sha1'>"
195 "<a href='"); 202 "<a href='");
196 query = fmt("id=%s", sha1_to_hex(p->item->object.sha1)); 203 query = fmt("id=%s", sha1_to_hex(p->item->object.sha1));
197 html_attr(cgit_pageurl(cgit_query_repo, "commit", query)); 204 html_attr(cgit_pageurl(cgit_query_repo, "commit", query));
198 htmlf("'>%s</a></td></tr>\n", 205 htmlf("'>%s</a> (<a href='",
199 sha1_to_hex(p->item->object.sha1)); 206 sha1_to_hex(p->item->object.sha1));
207 query = fmt("id=%s&id2=%s", sha1_to_hex(parent->tree->object.sha1),
208 sha1_to_hex(commit->tree->object.sha1));
209 html_attr(cgit_pageurl(cgit_query_repo, "diff", query));
210 html("'>diff</a>)</td></tr>");
200 } 211 }
201 if (cgit_repo->snapshots) { 212 if (cgit_repo->snapshots) {
202 htmlf("<tr><th>download</th><td colspan='2' class='sha1'><a href='"); 213 htmlf("<tr><th>download</th><td colspan='2' class='sha1'><a href='");
203 filename = fmt("%s-%s.zip", cgit_query_repo, hex); 214 filename = fmt("%s-%s.zip", cgit_query_repo, hex);
204 html_attr(cgit_pageurl(cgit_query_repo, "snapshot", 215 html_attr(cgit_pageurl(cgit_query_repo, "snapshot",
205 fmt("id=%s&name=%s", hex, filename))); 216 fmt("id=%s&name=%s", hex, filename)));
206 htmlf("'>%s</a></td></tr>", filename); 217 htmlf("'>%s</a></td></tr>", filename);
207 } 218 }
208 html("</table>\n"); 219 html("</table>\n");
209 html("<div class='commit-subject'>"); 220 html("<div class='commit-subject'>");
210 html_txt(info->subject); 221 html_txt(info->subject);
211 html("</div>"); 222 html("</div>");
212 html("<div class='commit-msg'>"); 223 html("<div class='commit-msg'>");
213 html_txt(info->msg); 224 html_txt(info->msg);
214 html("</div>"); 225 html("</div>");
215 if (!(commit->parents && commit->parents->next && commit->parents->next->next)) { 226 if (!(commit->parents && commit->parents->next && commit->parents->next->next)) {
216 html("<table class='diffstat'>"); 227 html("<table class='diffstat'>");
217 max_changes = 0; 228 max_changes = 0;
218 cgit_diff_commit(commit, inspect_filepair); 229 cgit_diff_commit(commit, inspect_filepair);
219 for(i = 0; i<files; i++) 230 for(i = 0; i<files; i++)
220 print_fileinfo(&items[i]); 231 print_fileinfo(&items[i]);
221 html("</table>"); 232 html("</table>");
222 html("<div class='diffstat-summary'>"); 233 html("<div class='diffstat-summary'>");
223 htmlf("%d files changed, %d insertions, %d deletions\n", 234 htmlf("%d files changed, %d insertions, %d deletions\n",
224 files, total_adds, total_rems); 235 files, total_adds, total_rems);
225 html("</div>"); 236 html("</div>");
226 } 237 }
227 cgit_free_commitinfo(info); 238 cgit_free_commitinfo(info);
228} 239}
diff --git a/ui-diff.c b/ui-diff.c
index 96106af..10330d3 100644
--- a/ui-diff.c
+++ b/ui-diff.c
@@ -1,45 +1,82 @@
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 10
11 11
12/* 12/*
13 * print a single line returned from xdiff 13 * print a single line returned from xdiff
14 */ 14 */
15static void print_line(char *line, int len) 15static void print_line(char *line, int len)
16{ 16{
17 char *class = "ctx"; 17 char *class = "ctx";
18 char c = line[len-1]; 18 char c = line[len-1];
19 19
20 if (line[0] == '+') 20 if (line[0] == '+')
21 class = "add"; 21 class = "add";
22 else if (line[0] == '-') 22 else if (line[0] == '-')
23 class = "del"; 23 class = "del";
24 else if (line[0] == '@') 24 else if (line[0] == '@')
25 class = "hunk"; 25 class = "hunk";
26 26
27 htmlf("<div class='%s'>", class); 27 htmlf("<div class='%s'>", class);
28 line[len-1] = '\0'; 28 line[len-1] = '\0';
29 html_txt(line); 29 html_txt(line);
30 html("</div>"); 30 html("</div>");
31 line[len-1] = c; 31 line[len-1] = c;
32} 32}
33 33
34void cgit_print_diff(const char *old_hex, const char *new_hex) 34static void filepair_cb(struct diff_filepair *pair)
35{
36 html("<tr><th>");
37 html_txt(pair->two->path);
38 html("</th></tr>");
39 html("<tr><td>");
40 if (cgit_diff_files(pair->one->sha1, pair->two->sha1, print_line))
41 cgit_print_error("Error running diff");
42 html("</tr></td>");
43}
44
45void cgit_print_diff(const char *old_hex, const char *new_hex, char *path)
35{ 46{
36 unsigned char sha1[20], sha2[20]; 47 unsigned char sha1[20], sha2[20];
48 enum object_type type;
49 unsigned long size;
37 50
38 get_sha1(old_hex, sha1); 51 get_sha1(old_hex, sha1);
39 get_sha1(new_hex, sha2); 52 get_sha1(new_hex, sha2);
40 53
41 html("<table class='diff'><tr><td>"); 54 type = sha1_object_info(sha1, &size);
42 if (cgit_diff_files(sha1, sha2, print_line)) 55 if (type == OBJ_BAD) {
43 cgit_print_error("Error running diff"); 56 type = sha1_object_info(sha2, &size);
57 if (type == OBJ_BAD) {
58 cgit_print_error(fmt("Bad object names: %s, %s", old_hex, new_hex));
59 return;
60 }
61 }
62
63 html("<table class='diff'>");
64 switch(type) {
65 case OBJ_BLOB:
66 if (path)
67 htmlf("<tr><th>%s</th></tr>", path);
68 html("<tr><td>");
69 if (cgit_diff_files(sha1, sha2, print_line))
70 cgit_print_error("Error running diff");
71 html("</tr></td>");
72 break;
73 case OBJ_TREE:
74 cgit_diff_tree(sha1, sha2, filepair_cb);
75 break;
76 default:
77 cgit_print_error(fmt("Unhandled object type: %s",
78 typename(type)));
79 break;
80 }
44 html("</td></tr></table>"); 81 html("</td></tr></table>");
45} 82}