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

From:
Stefan Sperling <stsp@stsp.name>
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 12:18:26 +0100

Download raw body.

Thread
On Sat, Jan 28, 2023 at 05:44:16PM +1100, Mark Jamsek 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 :)

Yes, ok.
 
> 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 <fnc.bsdbox.org>
> GPG: F2FF 13DE 6A06 C471 CA80  E6E2 2930 DC66 86EE CF68