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

Re: [PATCH v3 2/4] read-cache.c: Refactor --ignore-missing implementation

From
Junio C Hamano <gitster@pobox.com>
Date
Jan 27, 2014, 17:39 UTC
Message-ID
<xmqqy521nx25.fsf@gitster.dls.corp.google.com>
In-Reply-To
<e8a33f2e20e9f2041bf5f0fa952536755dbdf34c.1390833624.git.brad.king@kitware.com>
Brad King <brad.king@kitware.com> writes:
Show 6 quoted lines
> Move lstat ENOENT handling from refresh_index to refresh_cache_ent and
> activate it with a new CE_MATCH_IGNORE_MISSING option.  This will allow
> other call paths into refresh_cache_ent to use the feature.
>
> Signed-off-by: Brad King <brad.king@kitware.com>
> ---
Good!

I forgot that we had "update-index --ignore-missing --refresh", and that is conceptually the thing you want to use in your "perform merge-recursive in an empty tree while pretending that the working tree is fully populated and up-to-date" scenario.

Show 57 quoted lines
>  cache.h      | 2 ++
>  read-cache.c | 8 +++++---
>  2 files changed, 7 insertions(+), 3 deletions(-)
>
> diff --git a/cache.h b/cache.h
> index c9efe88..c96ada7 100644
> --- a/cache.h
> +++ b/cache.h
> @@ -498,6 +498,8 @@ extern void *read_blob_data_from_index(struct index_state *, const char *, unsig
>  #define CE_MATCH_RACY_IS_DIRTY		02
>  /* do stat comparison even if CE_SKIP_WORKTREE is true */
>  #define CE_MATCH_IGNORE_SKIP_WORKTREE	04
> +/* ignore non-existent files during stat update  */
> +#define CE_MATCH_IGNORE_MISSING		0x08
>  extern int ie_match_stat(const struct index_state *, const struct cache_entry *, struct stat *, unsigned int);
>  extern int ie_modified(const struct index_state *, const struct cache_entry *, struct stat *, unsigned int);
>  
> diff --git a/read-cache.c b/read-cache.c
> index 33dd676..d61846c 100644
> --- a/read-cache.c
> +++ b/read-cache.c
> @@ -1031,6 +1031,7 @@ static struct cache_entry *refresh_cache_ent(struct index_state *istate,
>  	int changed, size;
>  	int ignore_valid = options & CE_MATCH_IGNORE_VALID;
>  	int ignore_skip_worktree = options & CE_MATCH_IGNORE_SKIP_WORKTREE;
> +	int ignore_missing = options & CE_MATCH_IGNORE_MISSING;
>  
>  	if (ce_uptodate(ce))
>  		return ce;
> @@ -1050,6 +1051,8 @@ static struct cache_entry *refresh_cache_ent(struct index_state *istate,
>  	}
>  
>  	if (lstat(ce->name, &st) < 0) {
> +		if (ignore_missing && errno == ENOENT)
> +			return ce;
>  		if (err)
>  			*err = errno;
>  		return NULL;
> @@ -1127,7 +1130,8 @@ int refresh_index(struct index_state *istate, unsigned int flags,
>  	int ignore_submodules = (flags & REFRESH_IGNORE_SUBMODULES) != 0;
>  	int first = 1;
>  	int in_porcelain = (flags & REFRESH_IN_PORCELAIN);
> -	unsigned int options = really ? CE_MATCH_IGNORE_VALID : 0;
> +	unsigned int options = ((really ? CE_MATCH_IGNORE_VALID : 0) |
> +				(not_new ? CE_MATCH_IGNORE_MISSING : 0));
>  	const char *modified_fmt;
>  	const char *deleted_fmt;
>  	const char *typechange_fmt;
> @@ -1176,8 +1180,6 @@ int refresh_index(struct index_state *istate, unsigned int flags,
>  		if (!new) {
>  			const char *fmt;
>  
> -			if (not_new && cache_errno == ENOENT)
> -				continue;
>  			if (really && cache_errno == EINVAL) {
>  				/* If we are doing --really-refresh that
>  				 * means the index is not valid anymore.
Previous: Brad KingNext: Brad King
Message 17 of 21 in “merge-recursive: Avoid diagnostic on empty work tree”
  1. 0/3 merge-recursive: Avoid diagnostic on empty work treeBrad King, Jan 24, 2014
  2. 1/3 t3030-merge-recursive: Test known breakage with empty work treeBrad King, Jan 24, 2014
  3. Jonathan NiederJan 24, 2014
  4. Brad KingJan 24, 2014
  5. 2/3 read-cache.c: Thread lstat error through make_cache_entry signatureBrad King, Jan 24, 2014
  6. 3/3 merge-recursive: Tolerate missing file when HEAD is up to dateBrad King, Jan 24, 2014
  7. Junio C HamanoJan 24, 2014
  8. Brad KingJan 24, 2014
  9. 0/3 merge-recursive: Avoid diagnostic on empty work treeBrad King, Jan 24, 2014
  10. 1/3 t3030-merge-recursive: Test known breakage with empty work treeBrad King, Jan 24, 2014
  11. 2/3 read-cache.c: Optionally tolerate missing files in make_cache_entryBrad King, Jan 24, 2014
  12. Junio C HamanoJan 24, 2014
  13. 3/3 merge-recursive.c: Tolerate missing files while refreshing indexBrad King, Jan 24, 2014
  14. 0/3 merge-recursive: Avoid diagnostic on empty work treeBrad King, Jan 27, 2014
  15. 1/4 t3030-merge-recursive: Test known breakage with empty work treeBrad King, Jan 27, 2014
  16. 2/4 read-cache.c: Refactor --ignore-missing implementationBrad King, Jan 27, 2014
  17. Junio C HamanoJan 27, 2014
  18. 3/4 read-cache.c: Extend make_cache_entry refresh flag with optionsBrad King, Jan 27, 2014
  19. 4/4 merge-recursive.c: Tolerate missing files while refreshing indexBrad King, Jan 27, 2014
  20. Fwd: [PATCH/RFC 3/3] merge-recursive: Tolerate missing file when HEAD is up to datenewren, Jan 24, 2014
  21. Brad KingJan 24, 2014

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.