");
-
- if (head && !old_hex && !new_hex) {
- get_sha1(head, sha1);
- commit = lookup_commit_reference(sha1);
- if (commit && !parse_commit(commit))
- cgit_diff_commit(commit, filepair_cb);
- else
- cgit_print_error(fmt("Bad commit: %s", head));
+ int i, curr;
+
+ html("");
+ html(" diff options");
+ html(" ");
+ html(" ");
+}
+
+void cgit_print_diff(const char *new_rev, const char *old_rev,
+ const char *prefix, int show_ctrls, int raw)
+{
+ struct commit *commit, *commit2;
+
+ if (!new_rev)
+ new_rev = ctx.qry.head;
+ if (get_sha1(new_rev, new_rev_sha1)) {
+ cgit_print_error("Bad object name: %s", new_rev);
+ return;
+ }
+ commit = lookup_commit_reference(new_rev_sha1);
+ if (!commit || parse_commit(commit)) {
+ cgit_print_error("Bad commit: %s", sha1_to_hex(new_rev_sha1));
return;
}
- get_sha1(old_hex, sha1);
- get_sha1(new_hex, sha2);
+ if (old_rev) {
+ if (get_sha1(old_rev, old_rev_sha1)) {
+ cgit_print_error("Bad object name: %s", old_rev);
+ return;
+ }
+ } else if (commit->parents && commit->parents->item) {
+ hashcpy(old_rev_sha1, commit->parents->item->object.sha1);
+ } else {
+ hashclr(old_rev_sha1);
+ }
- type = sha1_object_info(sha1, &size);
- if (type == OBJ_BAD) {
- type = sha1_object_info(sha2, &size);
- if (type == OBJ_BAD) {
- cgit_print_error(fmt("Bad object names: %s, %s", old_hex, new_hex));
+ if (!is_null_sha1(old_rev_sha1)) {
+ commit2 = lookup_commit_reference(old_rev_sha1);
+ if (!commit2 || parse_commit(commit2)) {
+ cgit_print_error("Bad commit: %s", sha1_to_hex(old_rev_sha1));
return;
}
}
- switch(type) {
- case OBJ_BLOB:
- header(sha1, path, 0644, sha2, path, 0644);
- if (cgit_diff_files(sha1, sha2, print_line))
- cgit_print_error("Error running diff");
- break;
- case OBJ_TREE:
- cgit_diff_tree(sha1, sha2, filepair_cb);
- break;
- default:
- cgit_print_error(fmt("Unhandled object type: %s",
- typename(type)));
- break;
+ if (raw) {
+ ctx.page.mimetype = "text/plain";
+ cgit_print_http_headers(&ctx);
+ cgit_diff_tree(old_rev_sha1, new_rev_sha1, filepair_cb_raw,
+ prefix, 0);
+ return;
+ }
+
+ use_ssdiff = ctx.qry.has_ssdiff ? ctx.qry.ssdiff : ctx.cfg.ssdiff;
+
+ if (show_ctrls)
+ cgit_print_diff_ctrls();
+
+ cgit_print_diffstat(old_rev_sha1, new_rev_sha1, prefix);
+
+ if (use_ssdiff) {
+ html("");
+ } else {
+ html("");
+ html("| ");
}
- html(" | ");
+ cgit_diff_tree(old_rev_sha1, new_rev_sha1, filepair_cb, prefix,
+ ctx.qry.ignorews);
+ if (!use_ssdiff)
+ html("");
html(" ");
}
|