"GOT", but the "O" is a cute, smiling pufferfish. Index | Thread | Search

From:
Omar Polo <op@omarpolo.com>
Subject:
Re: check we have a parent commit it commit_path_changed_in_worktree()
To:
Mark Jamsek <mark@jamsek.com>
Cc:
Game of Trees <gameoftrees@openbsd.org>
Date:
Sat, 28 Jan 2023 10:16:21 +0100

Download raw body.

Thread
On 2023/01/28 17:44:16 +1100, Mark Jamsek <mark@jamsek.com> wrote:
> 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 :)

reads fine, ok for me.

got_diff_tree accepts NULL as one of the trees passed to it, so the
case of a parent commit should work.

> 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)