|
diff --git a/ui-diff.c b/ui-diff.c index 625b5fd..12e78b1 100644 --- a/ ui-diff.c+++ b/ ui-diff.c |
|
@@ -197,99 +197,93 @@ static void header(unsigned char *sha1, char *path1, int mode1, |
197 | path2 = "dev/null"; |
197 | path2 = "dev/null"; |
198 | |
198 | |
199 | if (mode1 == 0) |
199 | if (mode1 == 0) |
200 | htmlf("<br/>new file mode %.6o", mode2); |
200 | htmlf("<br/>new file mode %.6o", mode2); |
201 | |
201 | |
202 | if (mode2 == 0) |
202 | if (mode2 == 0) |
203 | htmlf("<br/>deleted file mode %.6o", mode1); |
203 | htmlf("<br/>deleted file mode %.6o", mode1); |
204 | |
204 | |
205 | if (!subproject) { |
205 | if (!subproject) { |
206 | abbrev1 = xstrdup(find_unique_abbrev(sha1, DEFAULT_ABBREV)); |
206 | abbrev1 = xstrdup(find_unique_abbrev(sha1, DEFAULT_ABBREV)); |
207 | abbrev2 = xstrdup(find_unique_abbrev(sha2, DEFAULT_ABBREV)); |
207 | abbrev2 = xstrdup(find_unique_abbrev(sha2, DEFAULT_ABBREV)); |
208 | htmlf("<br/>index %s..%s", abbrev1, abbrev2); |
208 | htmlf("<br/>index %s..%s", abbrev1, abbrev2); |
209 | free(abbrev1); |
209 | free(abbrev1); |
210 | free(abbrev2); |
210 | free(abbrev2); |
211 | if (mode1 != 0 && mode2 != 0) { |
211 | if (mode1 != 0 && mode2 != 0) { |
212 | htmlf(" %.6o", mode1); |
212 | htmlf(" %.6o", mode1); |
213 | if (mode2 != mode1) |
213 | if (mode2 != mode1) |
214 | htmlf("..%.6o", mode2); |
214 | htmlf("..%.6o", mode2); |
215 | } |
215 | } |
216 | html("<br/>--- a/"); |
216 | html("<br/>--- a/"); |
217 | if (mode1 != 0) |
217 | if (mode1 != 0) |
218 | cgit_tree_link(path1, NULL, NULL, ctx.qry.head, |
218 | cgit_tree_link(path1, NULL, NULL, ctx.qry.head, |
219 | sha1_to_hex(old_rev_sha1), path1); |
219 | sha1_to_hex(old_rev_sha1), path1); |
220 | else |
220 | else |
221 | html_txt(path1); |
221 | html_txt(path1); |
222 | html("<br/>+++ b/"); |
222 | html("<br/>+++ b/"); |
223 | if (mode2 != 0) |
223 | if (mode2 != 0) |
224 | cgit_tree_link(path2, NULL, NULL, ctx.qry.head, |
224 | cgit_tree_link(path2, NULL, NULL, ctx.qry.head, |
225 | sha1_to_hex(new_rev_sha1), path2); |
225 | sha1_to_hex(new_rev_sha1), path2); |
226 | else |
226 | else |
227 | html_txt(path2); |
227 | html_txt(path2); |
228 | } |
228 | } |
229 | html("</div>"); |
229 | html("</div>"); |
230 | } |
230 | } |
231 | |
231 | |
232 | static void filepair_cb(struct diff_filepair *pair) |
232 | static void filepair_cb(struct diff_filepair *pair) |
233 | { |
233 | { |
234 | header(pair->one->sha1, pair->one->path, pair->one->mode, |
234 | header(pair->one->sha1, pair->one->path, pair->one->mode, |
235 | pair->two->sha1, pair->two->path, pair->two->mode); |
235 | pair->two->sha1, pair->two->path, pair->two->mode); |
236 | if (S_ISGITLINK(pair->one->mode) || S_ISGITLINK(pair->two->mode)) { |
236 | if (S_ISGITLINK(pair->one->mode) || S_ISGITLINK(pair->two->mode)) { |
237 | if (S_ISGITLINK(pair->one->mode)) |
237 | if (S_ISGITLINK(pair->one->mode)) |
238 | print_line(fmt("-Subproject %s", sha1_to_hex(pair->one->sha1)), 52); |
238 | print_line(fmt("-Subproject %s", sha1_to_hex(pair->one->sha1)), 52); |
239 | if (S_ISGITLINK(pair->two->mode)) |
239 | if (S_ISGITLINK(pair->two->mode)) |
240 | print_line(fmt("+Subproject %s", sha1_to_hex(pair->two->sha1)), 52); |
240 | print_line(fmt("+Subproject %s", sha1_to_hex(pair->two->sha1)), 52); |
241 | return; |
241 | return; |
242 | } |
242 | } |
243 | if (cgit_diff_files(pair->one->sha1, pair->two->sha1, print_line)) |
243 | if (cgit_diff_files(pair->one->sha1, pair->two->sha1, print_line)) |
244 | cgit_print_error("Error running diff"); |
244 | cgit_print_error("Error running diff"); |
245 | } |
245 | } |
246 | |
246 | |
247 | void cgit_print_diff(const char *new_rev, const char *old_rev, const char *prefix) |
247 | void cgit_print_diff(const char *new_rev, const char *old_rev, const char *prefix) |
248 | { |
248 | { |
249 | enum object_type type; |
249 | enum object_type type; |
250 | unsigned long size; |
250 | unsigned long size; |
251 | struct commit *commit, *commit2; |
251 | struct commit *commit, *commit2; |
252 | |
252 | |
253 | if (!new_rev) |
253 | if (!new_rev) |
254 | new_rev = ctx.qry.head; |
254 | new_rev = ctx.qry.head; |
255 | get_sha1(new_rev, new_rev_sha1); |
255 | get_sha1(new_rev, new_rev_sha1); |
256 | type = sha1_object_info(new_rev_sha1, &size); |
256 | type = sha1_object_info(new_rev_sha1, &size); |
257 | if (type == OBJ_BAD) { |
257 | if (type == OBJ_BAD) { |
258 | cgit_print_error(fmt("Bad object name: %s", new_rev)); |
258 | cgit_print_error(fmt("Bad object name: %s", new_rev)); |
259 | return; |
259 | return; |
260 | } |
260 | } |
261 | if (type != OBJ_COMMIT) { |
| |
262 | cgit_print_error(fmt("Unhandled object type: %s", |
| |
263 | typename(type))); |
| |
264 | return; |
| |
265 | } |
| |
266 | |
| |
267 | commit = lookup_commit_reference(new_rev_sha1); |
261 | commit = lookup_commit_reference(new_rev_sha1); |
268 | if (!commit || parse_commit(commit)) |
262 | if (!commit || parse_commit(commit)) |
269 | cgit_print_error(fmt("Bad commit: %s", sha1_to_hex(new_rev_sha1))); |
263 | cgit_print_error(fmt("Bad commit: %s", sha1_to_hex(new_rev_sha1))); |
270 | |
264 | |
271 | if (old_rev) |
265 | if (old_rev) |
272 | get_sha1(old_rev, old_rev_sha1); |
266 | get_sha1(old_rev, old_rev_sha1); |
273 | else if (commit->parents && commit->parents->item) |
267 | else if (commit->parents && commit->parents->item) |
274 | hashcpy(old_rev_sha1, commit->parents->item->object.sha1); |
268 | hashcpy(old_rev_sha1, commit->parents->item->object.sha1); |
275 | else |
269 | else |
276 | hashclr(old_rev_sha1); |
270 | hashclr(old_rev_sha1); |
277 | |
271 | |
278 | if (!is_null_sha1(old_rev_sha1)) { |
272 | if (!is_null_sha1(old_rev_sha1)) { |
279 | type = sha1_object_info(old_rev_sha1, &size); |
273 | type = sha1_object_info(old_rev_sha1, &size); |
280 | if (type == OBJ_BAD) { |
274 | if (type == OBJ_BAD) { |
281 | cgit_print_error(fmt("Bad object name: %s", sha1_to_hex(old_rev_sha1))); |
275 | cgit_print_error(fmt("Bad object name: %s", sha1_to_hex(old_rev_sha1))); |
282 | return; |
276 | return; |
283 | } |
277 | } |
284 | commit2 = lookup_commit_reference(old_rev_sha1); |
278 | commit2 = lookup_commit_reference(old_rev_sha1); |
285 | if (!commit2 || parse_commit(commit2)) |
279 | if (!commit2 || parse_commit(commit2)) |
286 | cgit_print_error(fmt("Bad commit: %s", sha1_to_hex(old_rev_sha1))); |
280 | cgit_print_error(fmt("Bad commit: %s", sha1_to_hex(old_rev_sha1))); |
287 | } |
281 | } |
288 | cgit_print_diffstat(old_rev_sha1, new_rev_sha1); |
282 | cgit_print_diffstat(old_rev_sha1, new_rev_sha1); |
289 | |
283 | |
290 | html("<table summary='diff' class='diff'>"); |
284 | html("<table summary='diff' class='diff'>"); |
291 | html("<tr><td>"); |
285 | html("<tr><td>"); |
292 | cgit_diff_tree(old_rev_sha1, new_rev_sha1, filepair_cb, prefix); |
286 | cgit_diff_tree(old_rev_sha1, new_rev_sha1, filepair_cb, prefix); |
293 | html("</td></tr>"); |
287 | html("</td></tr>"); |
294 | html("</table>"); |
288 | html("</table>"); |
295 | } |
289 | } |
|