From: Mark Jamsek Subject: Re: check we have a parent commit it commit_path_changed_in_worktree() To: Game of Trees Date: Sat, 28 Jan 2023 17:44:16 +1100 On 23-01-28 05:37PM, Mark Jamsek wrote: > This fixes an invalid assumption in commit_path_changed_in_worktree(); > namely, that we always have a parent commit. Even better, let's not make wrap the commit in there too :) diff /home/mark/src/got commit - 22d6be814cfc21a663987c0dcb547f99e48a9860 path + /home/mark/src/got blob - 326ea521fa760c8c7507f7ebcb14de2cc202defc file + got/got.c --- got/got.c +++ got/got.c @@ -8417,22 +8417,23 @@ commit_path_changed_in_worktree(int *add_logmsg, struc if (err) goto done; - pid = STAILQ_FIRST(got_object_commit_get_parent_ids(commit)); - - err = got_object_open_as_commit(&pcommit, repo, &pid->id); - if (err) - goto done; - err = got_object_open_as_tree(&tree, repo, got_object_commit_get_tree_id(commit)); if (err) goto done; - err = got_object_open_as_tree(&ptree, repo, - got_object_commit_get_tree_id(pcommit)); - if (err) - goto done; + pid = STAILQ_FIRST(got_object_commit_get_parent_ids(commit)); + if (pid != NULL) { + err = got_object_open_as_commit(&pcommit, repo, &pid->id); + if (err) + goto done; + err = got_object_open_as_tree(&ptree, repo, + got_object_commit_get_tree_id(pcommit)); + if (err) + goto done; + } + err = got_diff_tree(ptree, tree, NULL, NULL, -1, -1, "", "", repo, got_diff_tree_collect_changed_paths, &paths, 0); if (err) -- Mark Jamsek GPG: F2FF 13DE 6A06 C471 CA80 E6E2 2930 DC66 86EE CF68