From: Junio C Hamano <gitster@pobox.com>
To: "brian m. carlson" <sandals@crustytoothpaste.net>
Cc: <git@vger.kernel.org>, Derrick Stolee <dstolee@microsoft.com>
Subject: Re: [PATCH v2 1/2] builtin/checkout: simplify metadata initialization
Date: Thu, 21 May 2020 10:35:22 -0700 [thread overview]
Message-ID: <xmqq1rndtcmd.fsf@gitster.c.googlers.com> (raw)
In-Reply-To: <20200521020712.1620993-2-sandals@crustytoothpaste.net> (brian m. carlson's message of "Thu, 21 May 2020 02:07:11 +0000")
"brian m. carlson" <sandals@crustytoothpaste.net> writes:
> ... The only case in which we do not have a commit object is when
> invoking git switch with --orphan. Moreover, we can only hit this code
> path without a commit object additionally with either --force or
> --discard-changes.
It was easy for me to trace the codepath to see when these options
are used we end up with no commit object, but I ran out of time
trying to see if the "forced orphan" is the only way to end up with
a NULL in new_branch_info->commit. Assuming that is true, of course
the following perfectly makes sense.
> In such a case, there is no point initializing the checkout metadata
> with a commit or tree because (a) there is no commit, only the empty
> tree, and (b) we will never use the data, since no files will be smudged
> when checking out a branch with no files. Pass the all-zeros object ID
> in this case, since we just need some value which is a valid pointer.
>
> Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
> ---
> builtin/checkout.c | 4 +---
> 1 file changed, 1 insertion(+), 3 deletions(-)
Thanks.
> diff --git a/builtin/checkout.c b/builtin/checkout.c
> index e9d111bb83..62b5e371bc 100644
> --- a/builtin/checkout.c
> +++ b/builtin/checkout.c
> @@ -621,9 +621,7 @@ static int reset_tree(struct tree *tree, const struct checkout_opts *o,
> opts.src_index = &the_index;
> opts.dst_index = &the_index;
> init_checkout_metadata(&opts.meta, info->refname,
> - info->commit ? &info->commit->object.oid :
> - is_null_oid(&info->oid) ? &tree->object.oid :
> - &info->oid,
> + info->commit ? &info->commit->object.oid : &null_oid,
> NULL);
> parse_tree(tree);
> init_tree_desc(&tree_desc, tree->buffer, tree->size);
next prev parent reply other threads:[~2020-05-21 17:35 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
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 [this message]
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqq1rndtcmd.fsf@gitster.c.googlers.com \
--to=gitster@pobox.com \
--cc=dstolee@microsoft.com \
--cc=git@vger.kernel.org \
--cc=sandals@crustytoothpaste.net \
/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.
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 NNTP newsgroup(s).