From: Duy Nguyen <pclouds@gmail.com>
To: Kevin Willford <kcwillford@gmail.com>
Cc: git@vger.kernel.org, gitster@pobox.com, peff@peff.net,
Kevin Willford <kewillf@microsoft.com>
Subject: Re: [PATCH 2/3] apply.c: do not checkout file when skip-worktree bit set
Date: Mon, 10 Apr 2017 17:11:23 +0700 [thread overview]
Message-ID: <20170410101123.GA19325@ash> (raw)
In-Reply-To: <20170407192357.948-3-kewillf@microsoft.com>
On Fri, Apr 07, 2017 at 12:23:56PM -0700, Kevin Willford wrote:
> When using the sparse-checkout feature git should not write to
> the working directory for files with the skip-worktree bit on.
> With the skip-worktree bit on the file may or may not be in
> the working directory and if it is not we don't want or need to
> create it by calling checkout_entry.
>
> There are two callers of checkout_target. Both of which check
> that the file does not exist before calling checkout_target.
> load_current which make a call to lstat right before calling checkout_target
> and check_preimage which will only run checkout_taret it stat_ret
> is less than zero. It sets stat_ret to zero and only if
> !stat->cached will it lstat the file and set stat_ret to
> something other than zero.
>
> This patch checks if skip-worktree bit is on in checkout_target
> and just returns so that the entry doesn't not end up in the
> working directory. This is so that apply will not create a file
> in the working directory, then update the index but not keep the
> working directory up to date with the changes that happened in the index.
No. I think we should check the skip-worktree at the call sites
instead of just exit early here. What if the caller expects the file
to exist if checkout_target returns zero? We just don't have enough
information to decide what is the right thing to do in this function.
There are two call sites.
In load_current() we could skip the lstat() call before
checkout_target() too if skip-worktree is set. We also need to skip
the verify_index_match(). I'm not exactly sure if that code expects
the target file on disk afterwarsd though (apply.c is not really my
thing).
In check_preimage() it looks easier because we could follow the
state->cached code for skip-worktree, I think.
>
> Signed-off-by: Kevin Willford <kewillf@microsoft.com>
> ---
> apply.c | 18 ++++++++++++++++++
> 1 file changed, 18 insertions(+)
>
> diff --git a/apply.c b/apply.c
> index 0e2caeab9c..0da5d0b7c9 100644
> --- a/apply.c
> +++ b/apply.c
> @@ -3327,6 +3327,24 @@ static int checkout_target(struct index_state *istate,
> {
> struct checkout costate = CHECKOUT_INIT;
>
> + /*
> + * Do not checkout the entry if the skipworktree bit is set
> + *
> + * Both callers of this method (check_preimage and load_current)
> + * check for the existance of the file before calling this
> + * method so we know that the file doesn't exist at this point
> + * and we don't need to perform that check again here.
> + * We just need to check the skip-worktree and return.
> + *
> + * This is to prevent git from creating a file in the
> + * working directory that has the skip-worktree bit on,
> + * then updating the index from the patch and not keeping
> + * the working directory version up to date with what it
> + * changed the index version to be.
> + */
> + if (ce_skip_worktree(ce))
> + return 0;
> +
> costate.refresh_cache = 1;
> costate.istate = istate;
> if (checkout_entry(ce, &costate, NULL) || lstat(ce->name, st))
> --
> 2.12.2.windows.2.1.g7df5db8d31
>
next prev parent reply other threads:[~2017-04-10 10:11 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-07 19:23 [PATCH 0/3] fix working directory file issues while using sparse-checkout Kevin Willford
2017-04-07 19:23 ` [PATCH 1/3] merge-recursive.c: conflict using sparse should update file Kevin Willford
2017-04-10 10:36 ` Duy Nguyen
2017-04-07 19:23 ` [PATCH 2/3] apply.c: do not checkout file when skip-worktree bit set Kevin Willford
2017-04-07 22:28 ` Stefan Beller
2017-04-10 10:11 ` Duy Nguyen [this message]
2017-04-07 19:23 ` [PATCH 3/3] reset.c: update files when using sparse to avoid data loss Kevin Willford
2017-04-07 22:41 ` Stefan Beller
2017-04-10 10:24 ` Duy Nguyen
2017-04-11 22:30 ` Kevin Willford
2017-04-12 13:21 ` Duy Nguyen
2017-04-12 15:37 ` Kevin Willford
2017-04-16 4:25 ` Duy Nguyen
2017-04-17 12:09 ` Duy Nguyen
2017-04-07 19:27 ` [PATCH 0/3] fix working directory file issues while using sparse-checkout Stefan Beller
2017-04-07 19:27 ` Stefan Beller
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=20170410101123.GA19325@ash \
--to=pclouds@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=kcwillford@gmail.com \
--cc=kewillf@microsoft.com \
--cc=peff@peff.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.
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).