- if (commit->parents && commit->parents->item) {
- hashcpy(old_sha1, commit->parents->item->object.sha1);
- sprintf(rev_range, "%s..%s", sha1_to_hex(old_sha1),
- sha1_to_hex(sha1));
+ if (old_rev) {
+ if (get_sha1(old_rev, old_rev_sha1)) {
+ cgit_print_error_page(404, "Not found",
+ "Bad object id: %s", old_rev);
+ return;
+ }
+ if (!lookup_commit_reference(old_rev_sha1)) {
+ cgit_print_error_page(404, "Not found",
+ "Bad commit reference: %s", old_rev);
+ return;
+ }
+ } else if (commit->parents && commit->parents->item) {
+ hashcpy(old_rev_sha1, commit->parents->item->object.sha1);