- 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_oid(old_rev, &old_rev_oid)) {
+ cgit_print_error_page(404, "Not found",
+ "Bad object id: %s", old_rev);
+ return;
+ }
+ if (!lookup_commit_reference(&old_rev_oid)) {
+ cgit_print_error_page(404, "Not found",
+ "Bad commit reference: %s", old_rev);
+ return;
+ }
+ } else if (commit->parents && commit->parents->item) {
+ oidcpy(&old_rev_oid, &commit->parents->item->object.oid);
+ } else {
+ oidclr(&old_rev_oid);
+ }
+
+ if (is_null_oid(&old_rev_oid)) {
+ memcpy(rev_range, oid_to_hex(&new_rev_oid), GIT_SHA1_HEXSZ + 1);