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

Re: [PATCH 1/1] builtin/checkout: simplify metadata initialization

From
brian m. carlson <sandals@crustytoothpaste.net>
Date
May 20, 2020, 22:37 UTC
Message-ID
<20200520223737.GT6362@camp.crustytoothpaste.net>
In-Reply-To
<xmqqmu62ws88.fsf@gitster.c.googlers.com>
On 2020-05-20 at 15:17:43, Junio C Hamano wrote:
Show 33 quoted lines
> "brian m. carlson" <sandals@crustytoothpaste.net> writes:
> 
> > When we call init_checkout_metadata in reset_tree, we want to pass the
> > object ID of the commit in question so that it can be passed to filters,
> > or if there is no commit, the tree.  We anticipated this latter case,
> > which can occur elsewhere in the checkout code, but it cannot occur
> > here, since reset_tree is called only (indirectly) via switch_branches,
> > which requires that we have a valid commit.  switch_branches dies if we
> > lack a name and cannot produce a commit from HEAD, and its caller dies
> > if we do have a branch name but still lack a commit pointer.
> >
> > Since we know we must always have a valid commit structure in this case,
> > let's remove the dead code paths and just refer to the commit structure.
> > This simplifies the code and makes it easier for the reader.
> 
> builtin/checkout.c::merge_working_tree() has these lines in its
> earlier part:
> 
> 	if (opts->new_orphan_branch && opts->orphan_from_empty_tree) {
> 		if (new_branch_info->commit)
> 			BUG("'switch --orphan' should never acc...");
> 		new_tree = parse_tree_indirect(the_hash_algo->empty_tree);
> 	} else
> 		new_tree = get_commit_tree(new_branch_info->commit);
> 	if (opts->discard_changes) {
> 		ret = reset_tree(new_tree, opts, 1, writeout_error, new_branch_info);
> 		if (ret)
> 			return ret;
> 	...
> 
> So, when orphan && orphan-from-empty are both set, we must not have
> commit, and then if discard is also there, we end up passing
> new_brnach_info that has NULL in its commit.
Good point.  I missed that part.
> Perhaps the "orphan && orphan-from-empty" is a dead combination and
> we won't hit the codepath and that is why this change is safe?  I
> dunno.

It looks like it's only triggered from git switch with --orphan, not with git checkout. And furthermore, it seems we require --force or --discard-changes to trigger that case, which we don't have anywhere in the testsuite.

I'll come up with a different patch. I'll probably just set a NULL object ID there, since if we're checking out a new orphan branch, we won't have any files to check out, and therefore there's no possibility that we'll actually use the value for a filter process (since there are no files to filter).

-- 
brian m. carlson: Houston, Texas, US
OpenPGP: https://keybase.io/bk2204
Previous: Junio C HamanoNext: brian m. carlson
Message 10 of 16 in “Git Test Coverage Report (v2.27.0-rc0)”
  1. Derrick StoleeMay 15, 2020
  2. Derrick StoleeMay 19, 2020
  3. René ScharfeMay 19, 2020
  4. brian m. carlsonMay 19, 2020
  5. brian m. carlsonMay 20, 2020
  6. t4067: make rename detection test output raw diffJonathan Tan, May 19, 2020
  7. Derrick StoleeMay 19, 2020
  8. 1/1 builtin/checkout: simplify metadata initializationbrian m. carlson, May 20, 2020
  9. Junio C HamanoMay 20, 2020
  10. brian m. carlsonMay 20, 2020
  11. 0/2 Improve Fix code coverage for checkoutbrian m. carlson, May 21, 2020
  12. 1/2 builtin/checkout: simplify metadata initializationbrian m. carlson, May 21, 2020
  13. Junio C HamanoMay 21, 2020
  14. brian m. carlsonMay 23, 2020
  15. 2/2 t2060: add a test for switch with --orphan and --discard-changesbrian m. carlson, May 21, 2020
  16. Derrick StoleeMay 21, 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.