- diff_params.flags = XDF_NEED_MINIMAL;
-
- emit_params.ctxlen = 3;
- emit_params.flags = XDL_EMIT_FUNCNAMES;
-
- emit_cb.outf = diff_cb;
-
- xdl_diff(&file1, &file2, &diff_params, &emit_params, &emit_cb);
-}
-
-
-
-void cgit_print_diff(const char *old_hex, const char *new_hex)
-{
- unsigned char sha1[20], sha2[20];
-
- get_sha1(old_hex, sha1);
- get_sha1(new_hex, sha2);
-
- html("<h2>diff</h2>\n");
- html("<table class='diff'><tr><td>");
- run_diff(sha1, sha2);
- html("</td></tr></table>");
+ commit = lookup_commit_reference(new_rev_sha1);
+ if (!commit || parse_commit(commit))
+ cgit_print_error(fmt("Bad commit: %s", sha1_to_hex(new_rev_sha1)));
+
+ if (old_rev)
+ get_sha1(old_rev, old_rev_sha1);
+ else if (commit->parents && commit->parents->item)
+ hashcpy(old_rev_sha1, commit->parents->item->object.sha1);
+ else
+ hashclr(old_rev_sha1);
+
+ if (!is_null_sha1(old_rev_sha1)) {
+ type = sha1_object_info(old_rev_sha1, &size);
+ if (type == OBJ_BAD) {
+ cgit_print_error(fmt("Bad object name: %s", sha1_to_hex(old_rev_sha1)));
+ return;
+ }
+ commit2 = lookup_commit_reference(old_rev_sha1);
+ if (!commit2 || parse_commit(commit2))
+ cgit_print_error(fmt("Bad commit: %s", sha1_to_hex(old_rev_sha1)));
+ }
+ html("<table summary='diff' class='diff'>");
+ html("<tr><td>");
+ cgit_diff_tree(old_rev_sha1, new_rev_sha1, filepair_cb, prefix);
+ html("</td></tr>");
+ html("</table>");