Commit 19ae6da15b9c1e2c10f4c66f2b654813419eb9cf

Stefan Sperling 2018-11-05T16:38:08

compare object IDs just once in diff_entry_old_new()

diff --git a/lib/diff.c b/lib/diff.c
index 23f25d0..f251838 100644
--- a/lib/diff.c
+++ b/lib/diff.c
@@ -393,6 +393,7 @@ diff_entry_old_new(struct got_tree_entry *te1, struct got_tree_entry *te2,
     struct got_repository *repo, FILE *outfile)
 {
 	const struct got_error *err = NULL;
+	int id_match;
 
 	if (te2 == NULL) {
 		if (S_ISDIR(te1->mode))
@@ -404,17 +405,18 @@ diff_entry_old_new(struct got_tree_entry *te1, struct got_tree_entry *te2,
 		return err;
 	}
 
+	id_match = (got_object_id_cmp(te1->id, te2->id) == 0);
 	if (S_ISDIR(te1->mode) && S_ISDIR(te2->mode)) {
-		if (got_object_id_cmp(te1->id, te2->id) != 0)
+		if (!id_match)
 			return diff_modified_tree(te1->id, te2->id,
 			    label1, label2, diff_context, repo, outfile);
 	} else if (S_ISREG(te1->mode) && S_ISREG(te2->mode)) {
-		if (got_object_id_cmp(te1->id, te2->id) != 0)
+		if (!id_match)
 			return diff_modified_blob(te1->id, te2->id,
 			    label1, label2, diff_context, repo, outfile);
 	}
 
-	if (got_object_id_cmp(te1->id, te2->id) == 0)
+	if (id_match)
 		return NULL;
 
 	return diff_kind_mismatch(te1->id, te2->id, label1, label2, outfile);