Commit 7310c1c396a8a6126c9feed52a5243917fb4af99

Stefan Sperling 2018-11-18T23:33:59

don't open tree unnecessarily in detect_changed_path()

diff --git a/lib/commit_graph.c b/lib/commit_graph.c
index bab4b0a..2e7bb67 100644
--- a/lib/commit_graph.c
+++ b/lib/commit_graph.c
@@ -181,10 +181,6 @@ detect_changed_path(int *changed, struct got_commit_object *commit,
 
 	*changed = 0;
 
-	err = got_object_open_as_tree(&tree, repo, commit->tree_id);
-	if (err)
-		return err;
-
 	pid = SIMPLEQ_FIRST(&commit->parent_ids);
 	if (pid == NULL) {
 		struct got_object_id *obj_id;
@@ -196,6 +192,10 @@ detect_changed_path(int *changed, struct got_commit_object *commit,
 			*changed = 1; /* The path was created in this commit. */
 		free(obj_id);
 	} else {
+		err = got_object_open_as_tree(&tree, repo, commit->tree_id);
+		if (err)
+			return err;
+
 		err = got_object_open_as_commit(&pcommit, repo, pid->id);
 		if (err)
 			goto done;