Commit Diff


commit - 6f04a9f3014abece8f6e4cecccc3d7e7e35c9984
commit + ce631d355cc5c9d10e40a7d35b331afba2f3d964
blob - c8c1fee8278da6aa0241a91d1b28affaf190a9c2
blob + ead293d381171fe6a5cefeb397cc88b5de8b9910
--- tog/tog.c
+++ tog/tog.c
@@ -5312,6 +5312,7 @@ create_diff(struct tog_diff_view_state *s)
 	int obj_type;
 	struct got_diff_line *lines = NULL;
 	struct got_pathlist_head changed_paths;
+	struct got_commit_object *commit2 = NULL;
 
 	TAILQ_INIT(&changed_paths);
 
@@ -5361,7 +5362,6 @@ create_diff(struct tog_diff_view_state *s)
 	case GOT_OBJ_TYPE_COMMIT: {
 		const struct got_object_id_queue *parent_ids;
 		struct got_object_qid *pid;
-		struct got_commit_object *commit2;
 		struct got_reflist_head *refs;
 		size_t nlines = 0;
 		struct got_diffstat_cb_arg dsa = {
@@ -5386,9 +5386,6 @@ create_diff(struct tog_diff_view_state *s)
 		if (err)
 			break;
 
-		err = got_object_open_as_commit(&commit2, s->repo, s->id2);
-		if (err)
-			goto done;
 		refs = got_reflist_object_id_map_lookup(tog_refs_idmap, s->id2);
 		/* Show commit info if we're diffing to a parent/root commit. */
 		if (s->id1 == NULL) {
@@ -5398,6 +5395,11 @@ create_diff(struct tog_diff_view_state *s)
 			if (err)
 				goto done;
 		} else {
+			err = got_object_open_as_commit(&commit2, s->repo,
+			    s->id2);
+			if (err)
+				goto done;
+
 			parent_ids = got_object_commit_get_parent_ids(commit2);
 			STAILQ_FOREACH(pid, parent_ids, entry) {
 				if (got_object_id_cmp(s->id1, &pid->id) == 0) {
@@ -5411,7 +5413,6 @@ create_diff(struct tog_diff_view_state *s)
 				}
 			}
 		}
-		got_object_commit_close(commit2);
 
 		err = cat_diff(s->f, tmp_diff_file, &s->lines, &s->nlines,
 		    lines, nlines);
@@ -5423,6 +5424,8 @@ create_diff(struct tog_diff_view_state *s)
 	}
 done:
 	free(lines);
+	if (commit2 != NULL)
+		got_object_commit_close(commit2);
 	got_pathlist_free(&changed_paths, GOT_PATHLIST_FREE_ALL);
 	if (s->f && fflush(s->f) != 0 && err == NULL)
 		err = got_error_from_errno("fflush");