-rw-r--r-- | cgit.c | 2 | ||||
-rw-r--r-- | cgit.css | 5 | ||||
-rw-r--r-- | cgit.h | 2 | ||||
-rw-r--r-- | ui-commit.c | 19 | ||||
-rw-r--r-- | ui-diff.c | 45 |
5 files changed, 63 insertions, 10 deletions
@@ -71,97 +71,97 @@ static void cgit_print_repo_page(struct cacheitem *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 | ||
126 | static void cgit_fill_cache(struct cacheitem *item, int use_cache) | 126 | static 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 | ||
156 | static void cgit_check_cache(struct cacheitem *item) | 156 | static 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); |
@@ -245,78 +245,83 @@ table.diffstat tr:hover { | |||
245 | table.diffstat th { | 245 | table.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 | ||
253 | table.diffstat td { | 253 | table.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 | ||
261 | table.diffstat td span.modechange { | 261 | table.diffstat td span.modechange { |
262 | padding-left: 1em; | 262 | padding-left: 1em; |
263 | color: red; | 263 | color: red; |
264 | } | 264 | } |
265 | 265 | ||
266 | table.diffstat td.add a { | 266 | table.diffstat td.add a { |
267 | color: green; | 267 | color: green; |
268 | } | 268 | } |
269 | 269 | ||
270 | table.diffstat td.del a { | 270 | table.diffstat td.del a { |
271 | color: red; | 271 | color: red; |
272 | } | 272 | } |
273 | 273 | ||
274 | table.diffstat td.upd a { | 274 | table.diffstat td.upd a { |
275 | color: blue; | 275 | color: blue; |
276 | } | 276 | } |
277 | 277 | ||
278 | table.diffstat td.graph { | 278 | table.diffstat td.graph { |
279 | width: 75%; | 279 | width: 75%; |
280 | vertical-align: center; | 280 | vertical-align: center; |
281 | } | 281 | } |
282 | 282 | ||
283 | table.diffstat td.graph img { | 283 | table.diffstat td.graph img { |
284 | border: none; | 284 | border: none; |
285 | height: 11pt; | 285 | height: 11pt; |
286 | } | 286 | } |
287 | 287 | ||
288 | div.diffstat-summary { | 288 | div.diffstat-summary { |
289 | color: #888; | 289 | color: #888; |
290 | padding-top: 0.5em; | 290 | padding-top: 0.5em; |
291 | } | 291 | } |
292 | 292 | ||
293 | table.diff th { | ||
294 | padding: 1em 0em 0.1em 0.1em; | ||
295 | text-align: left; | ||
296 | } | ||
297 | |||
293 | table.diff td { | 298 | table.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 | ||
299 | table.diff td div.hunk { | 304 | table.diff td div.hunk { |
300 | background: #ccc; | 305 | background: #ccc; |
301 | } | 306 | } |
302 | 307 | ||
303 | table.diff td div.add { | 308 | table.diff td div.add { |
304 | color: green; | 309 | color: green; |
305 | } | 310 | } |
306 | 311 | ||
307 | table.diff td div.del { | 312 | table.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 | } |
@@ -129,54 +129,54 @@ extern void cgit_diff_tree(const unsigned char *old_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); |
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 *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); | 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 ce33cf9..b3d1c28 100644 --- a/ui-commit.c +++ b/ui-commit.c | |||
@@ -31,198 +31,209 @@ void print_fileinfo(struct fileinfo *info) | |||
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 | ||
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; | 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 | } |
@@ -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 | */ |
15 | static void print_line(char *line, int len) | 15 | static 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 | ||
34 | void cgit_print_diff(const char *old_hex, const char *new_hex) | 34 | static 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 | |||
45 | void 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 | } |