Commit 9b6978794ceef93ae5f616c11f62b66c71038c43

Stefan Sperling 2018-05-20T13:03:52

make got_diff_objects_as_commits() require obj2 parameter

diff --git a/lib/diff.c b/lib/diff.c
index b46cb06..f3a09e4 100644
--- a/lib/diff.c
+++ b/lib/diff.c
@@ -506,8 +506,9 @@ got_diff_objects_as_commits(struct got_object *obj1, struct got_object *obj2,
 	const struct got_error *err;
 	struct got_commit_object *commit1 = NULL, *commit2 = NULL;
 	struct got_object *tree_obj1  = NULL, *tree_obj2 = NULL;
+	char *id_str;
 
-	if (obj1 == NULL && obj2 == NULL)
+	if (obj2 == NULL)
 		return got_error(GOT_ERR_NO_OBJ);
 
 	if (obj1) {
@@ -518,25 +519,23 @@ got_diff_objects_as_commits(struct got_object *obj1, struct got_object *obj2,
 		if (err)
 			goto done;
 	}
-	if (obj2) {
-		char *id_str;
 
-		err = got_object_commit_open(&commit2, repo, obj2);
-		if (err)
-			goto done;
-		err = got_object_open(&tree_obj2, repo, commit2->tree_id);
-		if (err)
-			goto done;
-		err = got_object_get_id_str(&id_str, obj2);
-		if (err)
-			goto done;
-		fprintf(outfile, "commit: %s\n", id_str);
-		free(id_str);
-		fprintf(outfile, "author: %s\n", commit2->author);
-		if (strcmp(commit2->author, commit2->committer) != 0)
-			fprintf(outfile, "committer: %s\n", commit2->committer);
-		fprintf(outfile, "\n%s\n", commit2->logmsg);
-	}
+	err = got_object_commit_open(&commit2, repo, obj2);
+	if (err)
+		goto done;
+	err = got_object_open(&tree_obj2, repo, commit2->tree_id);
+	if (err)
+		goto done;
+	err = got_object_get_id_str(&id_str, obj2);
+	if (err)
+		goto done;
+	fprintf(outfile, "commit: %s\n", id_str);
+	free(id_str);
+	fprintf(outfile, "author: %s\n", commit2->author);
+	if (strcmp(commit2->author, commit2->committer) != 0)
+		fprintf(outfile, "committer: %s\n", commit2->committer);
+	fprintf(outfile, "\n%s\n", commit2->logmsg);
+
 	err = got_diff_objects_as_trees(tree_obj1, tree_obj2, repo, outfile);
 done:
 	if (tree_obj1)