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

Re: [PATCH 1/5] Prevent diff machinery from examining worktree outside sparse checkout

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 31, 2009, 16:34 UTC
Message-ID
<7vprbgstfr.fsf@alter.siamese.dyndns.org>
In-Reply-To
<1248850154-5469-2-git-send-email-pclouds@gmail.com>
Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:
> ---
Sign off?  Oh, this is an RFC... Ok...
Show 21 quoted lines
> diff --git a/diff-lib.c b/diff-lib.c
> index b7813af..4094f18 100644
> --- a/diff-lib.c
> +++ b/diff-lib.c
> @@ -337,6 +337,8 @@ static void do_oneway_diff(struct unpack_trees_options *o,
>  	struct rev_info *revs = o->unpack_data;
>  	int match_missing, cached;
>  
> +	/* if the entry is not checked out, don't examine work tree */
> +	cached = o->index_only || (idx && idx->ce_flags & CE_VALID);
>  	/*
>  	 * Backward compatibility wart - "diff-index -m" does
>  	 * not mean "do not ignore merges", but "match_missing".
> @@ -344,7 +346,6 @@ static void do_oneway_diff(struct unpack_trees_options *o,
>  	 * But with the revision flag parsing, that's found in
>  	 * "!revs->ignore_merges".
>  	 */
> -	cached = o->index_only;
>  	match_missing = !revs->ignore_merges;
>  
>  	if (cached && idx && ce_stage(idx)) {

The big comment is about match_missing and not about cached, so the code movement is good. When we pass NULL idx to this function, it means that the tree has it but the index doesn't, so it cannot possibly be marked as "exists in the index but is not checked out". So the hunk makes sense.

Show 15 quoted lines
> diff --git a/diff.c b/diff.c
> index 91d6ea2..de1bd87 100644
> --- a/diff.c
> +++ b/diff.c
> @@ -1810,8 +1810,10 @@ static int reuse_worktree_file(const char *name, const unsigned char *sha1, int
>  
>  	/*
>  	 * If ce matches the file in the work tree, we can reuse it.
> +	 * For sparse checkout case, ce_uptodate() may be true although
> +	 * the file may or may not exist in the work tree.
>  	 */
> -	if (ce_uptodate(ce) ||
> +	if ((ce_uptodate(ce) && !(ce->ce_flags & CE_VALID)) ||
>  	    (!lstat(name, &st) && !ce_match_stat(ce, &st, 0)))
>  		return 1;

Why is this hunk necessary? A few lines above this we return 0 for any CE_VALID cache entry.

Previous: Nguyen Thai Ngoc DuyNext: skillzero@gmail.com
Message 13 of 15 in “Sparse checkout resurrection”
  1. 0/5 Sparse checkout resurrectionNguyễn Thái Ngọc Duy, Jul 29, 2009
  2. 1/5 Prevent diff machinery from examining worktree outside sparse checkoutNguyễn Thái Ngọc Duy, Jul 29, 2009
  3. 2/5 grep: skip files outside sparse checkout areaNguyễn Thái Ngọc Duy, Jul 29, 2009
  4. 3/5 gitignore: read from index if .gitignore is not in worktreeNguyễn Thái Ngọc Duy, Jul 29, 2009
  5. 4/5 unpack_trees(): keep track of unmerged entriesNguyễn Thái Ngọc Duy, Jul 29, 2009
  6. 5/5 unpack_trees(): add support for sparse checkoutNguyễn Thái Ngọc Duy, Jul 29, 2009
  7. Jakub NarebskiJul 29, 2009
  8. Nguyen Thai Ngoc DuyJul 29, 2009
  9. Jakub NarebskiJul 30, 2009
  10. Junio C HamanoJul 31, 2009
  11. Junio C HamanoJul 31, 2009
  12. Nguyen Thai Ngoc DuyAug 4, 2009
  13. Junio C HamanoJul 31, 2009
  14. skillzero@gmail.comJul 31, 2009
  15. Nguyen Thai Ngoc DuyAug 4, 2009

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.