git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] checkout -p: handle tree arguments correctly again

From
Junio C Hamano <gitster@pobox.com>
Date
Dec 19, 2020, 17:40 UTC
Message-ID
<xmqq5z4xpuck.fsf@gitster.c.googlers.com>
In-Reply-To
<pull.819.git.1608389760050.gitgitgadget@gmail.com>

"Johannes Schindelin via GitGitGadget" <gitgitgadget@gmail.com> writes:

>     I literally just ran into this segmentation fault after rebasing Git for
>     Windows onto -rc1, and did not really think that the regression was
>     introduced in the v2.30.0 cycle, but was proven wrong by my
>     investigation: it was introduced by v2.30.0-rc0151^23.

As "checkout -p branch~4" is easier than "checkout -p branch~4:", I think you have to work harder to give a true tree object rather than the containing commit object.

It still is curious how you stumbled onto this, but I am glad you did ;-)

Show 6 quoted lines
> @@ -482,7 +482,7 @@ static int checkout_paths(const struct checkout_opts *opts,
>  		 * properly. However, there is special logic for the HEAD case
>  		 * so we mustn't replace that.
>  		 */
> -		if (rev && strcmp(rev, "HEAD"))
> +		if (rev && new_branch_info->commit && strcmp(rev, "HEAD"))

The comment above talks about why "&& strcmp()" is there. We now have two.

I'd squash this in while queuing.  Thanks.
 builtin/checkout.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
diff --git c/builtin/checkout.c w/builtin/checkout.c
index 6f24b381c5..728c67e8ca 100644
--- c/builtin/checkout.c
+++ w/builtin/checkout.c
@@ -479,7 +479,9 @@ static int checkout_paths(const struct checkout_opts *opts,
 		 * with the hex of the commit (whether it's in `...` form or
 		 * not) for the run_add_interactive() machinery to work
 		 * properly. However, there is special logic for the HEAD case
-		 * so we mustn't replace that.
+		 * so we mustn't replace that.  Also, when we were given a
+		 * tree-object, new_branch_info->commit would be NULL, but we
+		 * do not have to do any replacement, either.
 		 */
 		if (rev && new_branch_info->commit && strcmp(rev, "HEAD"))
 			rev = oid_to_hex_r(rev_oid, &new_branch_info->commit->object.oid);
Previous: Junio C Hamano
Message 4 of 4 in “checkout -p: handle tree arguments correctly again”
  1. checkout -p: handle tree arguments correctly againJohannes Schindelin via GitGitGadget, Dec 19, 2020
  2. Denton LiuDec 19, 2020
  3. Junio C HamanoDec 19, 2020
  4. Junio C HamanoDec 19, 2020

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.