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

Re: [PATCH 4/6] checkout-index: handle "--no-index" option

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 1, 2016, 02:25 UTC
Message-ID
<xmqqr3gxw4j1.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<20160131112936.GD5116@sigill.intra.peff.net>
Jeff King <peff@peff.net> writes:
Show 6 quoted lines
> I also reformatted the comment that violated our style
> guidelines, but I am not sure if it is all that helpful. It
> seems we also cancel "--index" with "--temp" or
> "--stage=all", but I do not know why. I left the content
> as-is, but if somebody knows enough to elaborate, it might
> be worth doing.

Isn't the --index about updating the cached stat information, to allow us to then say "the working tree file hasn't been modified since we wrote it out"? After writing a file out to somewhere that is not its natural location (i.e. using prefix, stage or temp would all write the contents of F to somewhere that is not F), the next "diff-files" would not compare the index entry with the contents held in that relocated location, but with its natural location.

Admittedly, even if we update the cached stat info from that relocated place, the next "diff-files" would certainly not match (not just mtime but i-num would be different), but if the real working tree file were clean when --temp checkout happened, that would mean we would force another round of update-index --refresh, so...

Show 69 quoted lines
>  builtin/checkout-index.c | 34 ++++++++++------------------------
>  1 file changed, 10 insertions(+), 24 deletions(-)
>
> diff --git a/builtin/checkout-index.c b/builtin/checkout-index.c
> index 43bedde..f8179a7 100644
> --- a/builtin/checkout-index.c
> +++ b/builtin/checkout-index.c
> @@ -130,18 +130,6 @@ static const char * const builtin_checkout_index_usage[] = {
>  
>  static struct lock_file lock_file;
>  
> -static int option_parse_u(const struct option *opt,
> -			      const char *arg, int unset)
> -{
> -	int *newfd = opt->value;
> -
> -	state.refresh_cache = 1;
> -	state.istate = &the_index;
> -	if (*newfd < 0)
> -		*newfd = hold_locked_index(&lock_file, 1);
> -	return 0;
> -}
> -
>  static int option_parse_stage(const struct option *opt,
>  			      const char *arg, int unset)
>  {
> @@ -166,6 +154,7 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)
>  	int read_from_stdin = 0;
>  	int prefix_length;
>  	int force = 0, quiet = 0, not_new = 0;
> +	int index_opt = 0;
>  	struct option builtin_checkout_index_options[] = {
>  		OPT_BOOL('a', "all", &all,
>  			N_("check out all files in the index")),
> @@ -174,9 +163,8 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)
>  			N_("no warning for existing files and files not in index")),
>  		OPT_BOOL('n', "no-create", &not_new,
>  			N_("don't checkout new files")),
> -		{ OPTION_CALLBACK, 'u', "index", &newfd, NULL,
> -			N_("update stat information in the index file"),
> -			PARSE_OPT_NOARG, option_parse_u },
> +		OPT_BOOL('u', "index", &index_opt,
> +			 N_("update stat information in the index file")),
>  		OPT_BOOL('z', NULL, &nul_term_line,
>  			N_("paths are separated with NUL character")),
>  		OPT_BOOL(0, "stdin", &read_from_stdin,
> @@ -211,15 +199,13 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)
>  		state.base_dir = "";
>  	state.base_dir_len = strlen(state.base_dir);
>  
> -	if (state.base_dir_len || to_tempfile) {
> -		/* when --prefix is specified we do not
> -		 * want to update cache.
> -		 */
> -		if (state.refresh_cache) {
> -			rollback_lock_file(&lock_file);
> -			newfd = -1;
> -		}
> -		state.refresh_cache = 0;
> +	/*
> +	 * when --prefix is specified we do not want to update cache.
> +	 */
> +	if (index_opt && !state.base_dir_len && !to_tempfile) {
> +		state.refresh_cache = 1;
> +		state.istate = &the_index;
> +		newfd = hold_locked_index(&lock_file, 1);
>  	}
>  
>  	/* Check out named files first */
Previous: Jeff KingNext: Jeff King
Message 9 of 19 in “post-strbuf_getline cleanups”
  1. 0/6 post-strbuf_getline cleanupsJeff King, Jan 31, 2016
  2. 1/6 give "nbuf" strbuf a more meaningful nameJeff King, Jan 31, 2016
  3. Johannes SchindelinJan 31, 2016
  4. Jeff KingJan 31, 2016
  5. Johannes SchindelinJan 31, 2016
  6. 2/6 checkout-index: simplify "-z" option parsingJeff King, Jan 31, 2016
  7. 3/6 checkout-index: handle "--no-prefix" optionJeff King, Jan 31, 2016
  8. 4/6 checkout-index: handle "--no-index" optionJeff King, Jan 31, 2016
  9. Junio C HamanoFeb 1, 2016
  10. Jeff KingFeb 1, 2016
  11. 5/6 checkout-index: disallow "--no-stage" optionJeff King, Jan 31, 2016
  12. Junio C HamanoFeb 1, 2016
  13. Jeff KingFeb 1, 2016
  14. 6/6 apply, ls-files: simplify "-z" parsingJeff King, Jan 31, 2016
  15. Johannes SchindelinJan 31, 2016
  16. Junio C HamanoFeb 1, 2016
  17. Junio C HamanoFeb 1, 2016
  18. Jeff KingFeb 2, 2016
  19. Junio C HamanoFeb 1, 2016

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.