From: "brian m. carlson" <sandals@crustytoothpaste.net>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org, Derrick Stolee <dstolee@microsoft.com>
Subject: Re: [PATCH 1/1] builtin/checkout: simplify metadata initialization
Date: Wed, 20 May 2020 22:37:37 +0000 [thread overview]
Message-ID: <20200520223737.GT6362@camp.crustytoothpaste.net> (raw)
In-Reply-To: <xmqqmu62ws88.fsf@gitster.c.googlers.com>
[-- Attachment #1: Type: text/plain, Size: 2459 bytes --]
On 2020-05-20 at 15:17:43, Junio C Hamano wrote:
> "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
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 263 bytes --]
next prev parent reply other threads:[~2020-05-20 22:38 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-15 17:22 Git Test Coverage Report (v2.27.0-rc0) Derrick Stolee
2020-05-19 12:11 ` Derrick Stolee
2020-05-19 20:07 ` René Scharfe
2020-05-19 23:42 ` brian m. carlson
2020-05-20 1:38 ` brian m. carlson
2020-05-19 18:31 ` [PATCH] t4067: make rename detection test output raw diff Jonathan Tan
2020-05-19 19:00 ` Derrick Stolee
2020-05-20 1:41 ` [PATCH 1/1] builtin/checkout: simplify metadata initialization brian m. carlson
2020-05-20 15:17 ` Junio C Hamano
2020-05-20 22:37 ` brian m. carlson [this message]
2020-05-21 2:07 ` [PATCH v2 0/2] Improve Fix code coverage for checkout brian m. carlson
2020-05-21 2:07 ` [PATCH v2 1/2] builtin/checkout: simplify metadata initialization brian m. carlson
2020-05-21 17:35 ` Junio C Hamano
2020-05-23 12:22 ` brian m. carlson
2020-05-21 2:07 ` [PATCH v2 2/2] t2060: add a test for switch with --orphan and --discard-changes brian m. carlson
2020-05-21 12:38 ` [PATCH v2 0/2] Improve Fix code coverage for checkout Derrick Stolee
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200520223737.GT6362@camp.crustytoothpaste.net \
--to=sandals@crustytoothpaste.net \
--cc=dstolee@microsoft.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).