git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Brandon Williams <bmwill@google.com>
To: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Cc: git@vger.kernel.org, newren@gmail.com, ramsay@ramsayjones.plus.com
Subject: Re: [PATCH v3 17/20] cache.c: remove an implicit dependency on the_index
Date: Wed, 6 Jun 2018 10:00:42 -0700	[thread overview]
Message-ID: <20180606170042.GJ158365@google.com> (raw)
In-Reply-To: <20180606073933.14755-18-pclouds@gmail.com>

On 06/06, Nguyễn Thái Ngọc Duy wrote:
> Make some index API take an index_state instead of assuming the_index
> in read-cache.c. All external call sites are converted blindly to keep
> the patch simple and retain current behavior.  Individual call sites
> may receive further updates to use the right index instead of the_index.
> 
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> ---
>  apply.c            |  2 +-
>  builtin/checkout.c |  2 +-
>  builtin/difftool.c |  4 ++--
>  builtin/reset.c    |  2 +-
>  cache.h            |  5 +++--
>  merge-recursive.c  |  2 +-
>  read-cache.c       | 19 +++++++++++--------
>  resolve-undo.c     |  2 +-
>  8 files changed, 21 insertions(+), 17 deletions(-)
> 
> diff --git a/apply.c b/apply.c
> index 9720855590..811ff2ad5e 100644
> --- a/apply.c
> +++ b/apply.c
> @@ -4090,7 +4090,7 @@ static int build_fake_ancestor(struct apply_state *state, struct patch *list)
>  			return error(_("sha1 information is lacking or useless "
>  				       "(%s)."), name);
>  
> -		ce = make_cache_entry(patch->old_mode, oid.hash, name, 0, 0);
> +		ce = make_cache_entry(&the_index, patch->old_mode, oid.hash, name, 0, 0);
>  		if (!ce)
>  			return error(_("make_cache_entry failed for path '%s'"),
>  				     name);
> diff --git a/builtin/checkout.c b/builtin/checkout.c
> index f8c208cea1..3c8218304e 100644
> --- a/builtin/checkout.c
> +++ b/builtin/checkout.c
> @@ -230,7 +230,7 @@ static int checkout_merged(int pos, const struct checkout *state)
>  	if (write_object_file(result_buf.ptr, result_buf.size, blob_type, &oid))
>  		die(_("Unable to add merge result for '%s'"), path);
>  	free(result_buf.ptr);
> -	ce = make_cache_entry(mode, oid.hash, path, 2, 0);
> +	ce = make_cache_entry(&the_index, mode, oid.hash, path, 2, 0);
>  	if (!ce)
>  		die(_("make_cache_entry failed for path '%s'"), path);
>  	status = checkout_entry(ce, state, NULL);
> diff --git a/builtin/difftool.c b/builtin/difftool.c
> index bc97d4aef2..e34e75a42d 100644
> --- a/builtin/difftool.c
> +++ b/builtin/difftool.c
> @@ -321,7 +321,7 @@ static int checkout_path(unsigned mode, struct object_id *oid,
>  	struct cache_entry *ce;
>  	int ret;
>  
> -	ce = make_cache_entry(mode, oid->hash, path, 0, 0);
> +	ce = make_cache_entry(&the_index, mode, oid->hash, path, 0, 0);
>  	ret = checkout_entry(ce, state, NULL);
>  
>  	free(ce);
> @@ -488,7 +488,7 @@ static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix,
>  				 * index.
>  				 */
>  				struct cache_entry *ce2 =
> -					make_cache_entry(rmode, roid.hash,
> +					make_cache_entry(&the_index, rmode, roid.hash,
>  							 dst_path, 0, 0);
>  
>  				add_index_entry(&wtindex, ce2,
> diff --git a/builtin/reset.c b/builtin/reset.c
> index a862c70fab..0ea0a19d5e 100644
> --- a/builtin/reset.c
> +++ b/builtin/reset.c
> @@ -134,7 +134,7 @@ static void update_index_from_diff(struct diff_queue_struct *q,
>  			continue;
>  		}
>  
> -		ce = make_cache_entry(one->mode, one->oid.hash, one->path,
> +		ce = make_cache_entry(&the_index, one->mode, one->oid.hash, one->path,
>  				      0, 0);
>  		if (!ce)
>  			die(_("make_cache_entry failed for path '%s'"),
> diff --git a/cache.h b/cache.h
> index 89a107a7f7..5939233eb7 100644
> --- a/cache.h
> +++ b/cache.h
> @@ -355,6 +355,7 @@ extern void free_name_hash(struct index_state *istate);
>  #define unmerged_cache() unmerged_index(&the_index)
>  #define cache_name_pos(name, namelen) index_name_pos(&the_index,(name),(namelen))
>  #define add_cache_entry(ce, option) add_index_entry(&the_index, (ce), (option))
> +#define refresh_cache_entry(ce, flags) refresh_index_entry(&the_index, ce, flags)
>  #define rename_cache_entry_at(pos, new_name) rename_index_entry_at(&the_index, (pos), (new_name))
>  #define remove_cache_entry_at(pos) remove_index_entry_at(&the_index, (pos))
>  #define remove_file_from_cache(path) remove_file_from_index(&the_index, (path))
> @@ -698,7 +699,7 @@ extern int remove_file_from_index(struct index_state *, const char *path);
>  extern int add_to_index(struct index_state *, const char *path, struct stat *, int flags);
>  extern int add_file_to_index(struct index_state *, const char *path, int flags);
>  
> -extern struct cache_entry *make_cache_entry(unsigned int mode, const unsigned char *sha1, const char *path, int stage, unsigned int refresh_options);
> +extern struct cache_entry *make_cache_entry(struct index_state *istate,unsigned int mode, const unsigned char *sha1, const char *path, int stage, unsigned int refresh_options);

minor nit: s/istate,unsigned/istate, unsigned/

>  extern int chmod_index_entry(struct index_state *, struct cache_entry *ce, char flip);
>  extern int ce_same_name(const struct cache_entry *a, const struct cache_entry *b);
>  extern void set_object_name_for_intent_to_add_entry(struct cache_entry *ce);
> @@ -751,7 +752,7 @@ extern void fill_stat_cache_info(struct cache_entry *ce, struct stat *st);
>  #define REFRESH_IGNORE_SUBMODULES	0x0010	/* ignore submodules */
>  #define REFRESH_IN_PORCELAIN	0x0020	/* user friendly output, not "needs update" */
>  extern int refresh_index(struct index_state *, unsigned int flags, const struct pathspec *pathspec, char *seen, const char *header_msg);
> -extern struct cache_entry *refresh_cache_entry(struct cache_entry *, unsigned int);
> +extern struct cache_entry *refresh_index_entry(struct index_state *istate, struct cache_entry *, unsigned int);
>  
>  /*
>   * Opportunistically update the index but do not complain if we can't.
> diff --git a/merge-recursive.c b/merge-recursive.c
> index b404ebac7c..9280deb6a1 100644
> --- a/merge-recursive.c
> +++ b/merge-recursive.c
> @@ -315,7 +315,7 @@ static int add_cacheinfo(struct merge_options *o,
>  	struct cache_entry *ce;
>  	int ret;
>  
> -	ce = make_cache_entry(mode, oid ? oid->hash : null_sha1, path, stage, 0);
> +	ce = make_cache_entry(&the_index, mode, oid ? oid->hash : null_sha1, path, stage, 0);
>  	if (!ce)
>  		return err(o, _("add_cacheinfo failed for path '%s'; merge aborting."), path);
>  
> diff --git a/read-cache.c b/read-cache.c
> index 12cc22d157..c083318aa7 100644
> --- a/read-cache.c
> +++ b/read-cache.c
> @@ -745,9 +745,11 @@ int add_file_to_index(struct index_state *istate, const char *path, int flags)
>  	return add_to_index(istate, path, &st, flags);
>  }
>  
> -struct cache_entry *make_cache_entry(unsigned int mode,
> -		const unsigned char *sha1, const char *path, int stage,
> -		unsigned int refresh_options)
> +struct cache_entry *make_cache_entry(struct index_state *istate,
> +				     unsigned int mode,
> +				     const unsigned char *sha1,
> +				     const char *path, int stage,
> +				     unsigned int refresh_options)
>  {
>  	int size, len;
>  	struct cache_entry *ce, *ret;
> @@ -767,7 +769,7 @@ struct cache_entry *make_cache_entry(unsigned int mode,
>  	ce->ce_namelen = len;
>  	ce->ce_mode = create_ce_mode(mode);
>  
> -	ret = refresh_cache_entry(ce, refresh_options);
> +	ret = refresh_index_entry(istate, ce, refresh_options);
>  	if (ret != ce)
>  		free(ce);
>  	return ret;
> @@ -1415,7 +1417,7 @@ int refresh_index(struct index_state *istate, unsigned int flags,
>  		if (ignore_submodules && S_ISGITLINK(ce->ce_mode))
>  			continue;
>  
> -		if (pathspec && !ce_path_match(&the_index, ce, pathspec, seen))
> +		if (pathspec && !ce_path_match(istate, ce, pathspec, seen))
>  			filtered = 1;
>  
>  		if (ce_stage(ce)) {
> @@ -1473,10 +1475,11 @@ int refresh_index(struct index_state *istate, unsigned int flags,
>  	return has_errors;
>  }
>  
> -struct cache_entry *refresh_cache_entry(struct cache_entry *ce,
> -					       unsigned int options)
> +struct cache_entry *refresh_index_entry(struct index_state *istate,
> +					struct cache_entry *ce,
> +					unsigned int options)
>  {
> -	return refresh_cache_ent(&the_index, ce, options, NULL, NULL);
> +	return refresh_cache_ent(istate, ce, options, NULL, NULL);
>  }
>  
>  
> diff --git a/resolve-undo.c b/resolve-undo.c
> index 5e4c8c5f75..9c45fe5d1d 100644
> --- a/resolve-undo.c
> +++ b/resolve-undo.c
> @@ -146,7 +146,7 @@ int unmerge_index_entry_at(struct index_state *istate, int pos)
>  		struct cache_entry *nce;
>  		if (!ru->mode[i])
>  			continue;
> -		nce = make_cache_entry(ru->mode[i], ru->oid[i].hash,
> +		nce = make_cache_entry(&the_index, ru->mode[i], ru->oid[i].hash,
>  				       name, i + 1, 0);
>  		if (matched)
>  			nce->ce_flags |= CE_MATCHED;
> -- 
> 2.18.0.rc0.333.g22e6ee6cdf
> 

-- 
Brandon Williams

  reply	other threads:[~2018-06-06 17:05 UTC|newest]

Thread overview: 92+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-01 16:11 [PATCH/RFC/BUG] unpack-trees.c: do not use "the_index" Nguyễn Thái Ngọc Duy
2018-06-01 18:34 ` Elijah Newren
2018-06-01 18:51   ` Stefan Beller
2018-06-02  5:01     ` Duy Nguyen
2018-06-02  5:03   ` Duy Nguyen
2018-06-03  4:58     ` Elijah Newren
2018-06-04 17:33       ` Brandon Williams
2018-06-05 15:43 ` [PATCH 0/6] Fix "the_index" usage in unpack-trees.c Nguyễn Thái Ngọc Duy
2018-06-05 15:43   ` [PATCH 1/6] unpack-trees: remove 'extern' on function declaration Nguyễn Thái Ngọc Duy
2018-06-05 15:43   ` [PATCH 2/6] unpack-trees: add a note about path invalidation Nguyễn Thái Ngọc Duy
2018-06-05 15:43   ` [PATCH 3/6] unpack-trees: don't shadow global var the_index Nguyễn Thái Ngọc Duy
2018-06-05 17:11     ` Ramsay Jones
2018-06-05 15:43   ` [PATCH 4/6] unpack-tress: convert clear_ce_flags* to avoid the_index Nguyễn Thái Ngọc Duy
2018-06-05 17:37     ` Ramsay Jones
2018-06-05 15:43   ` [PATCH 5/6] unpack-trees: avoid the_index in verify_absent() Nguyễn Thái Ngọc Duy
2018-06-05 15:43   ` [PATCH 6/6] Forbid "the_index" in dir.c and unpack-trees.c Nguyễn Thái Ngọc Duy
2018-06-05 16:58     ` Brandon Williams
2018-06-06  4:57       ` Duy Nguyen
2018-06-06  5:02   ` [PATCH v2 0/5] Fix "the_index" usage in unpack-trees.c Nguyễn Thái Ngọc Duy
2018-06-06  5:02     ` [PATCH v2 1/5] unpack-trees: remove 'extern' on function declaration Nguyễn Thái Ngọc Duy
2018-06-06  5:02     ` [PATCH v2 2/5] unpack-trees: add a note about path invalidation Nguyễn Thái Ngọc Duy
2018-06-06  5:02     ` [PATCH v2 3/5] unpack-trees: don't shadow global var the_index Nguyễn Thái Ngọc Duy
2018-06-06  5:02     ` [PATCH v2 4/5] unpack-tress: convert clear_ce_flags* to avoid the_index Nguyễn Thái Ngọc Duy
2018-06-06  5:02     ` [PATCH v2 5/5] unpack-trees: avoid the_index in verify_absent() Nguyễn Thái Ngọc Duy
2018-06-06  7:39     ` [PATCH v3 00/20] Fix incorrect use of the_index Nguyễn Thái Ngọc Duy
2018-06-06  7:39       ` [PATCH v3 01/20] unpack-trees: remove 'extern' on function declaration Nguyễn Thái Ngọc Duy
2018-06-06  7:39       ` [PATCH v3 02/20] unpack-trees: add a note about path invalidation Nguyễn Thái Ngọc Duy
2018-06-06  7:39       ` [PATCH v3 03/20] unpack-trees: don't shadow global var the_index Nguyễn Thái Ngọc Duy
2018-06-06  7:39       ` [PATCH v3 04/20] unpack-tress: convert clear_ce_flags* to avoid the_index Nguyễn Thái Ngọc Duy
2018-06-06  7:39       ` [PATCH v3 05/20] unpack-trees: avoid the_index in verify_absent() Nguyễn Thái Ngọc Duy
2018-06-06  7:39       ` [PATCH v3 06/20] attr.h: drop extern from function declaration Nguyễn Thái Ngọc Duy
2018-06-06  7:39       ` [PATCH v3 07/20] attr: remove an implicit dependency on the_index Nguyễn Thái Ngọc Duy
2018-06-06 13:35         ` Ramsay Jones
2018-06-06 16:50         ` Brandon Williams
2018-06-06 16:58           ` Duy Nguyen
2018-06-06 17:02             ` Brandon Williams
2018-06-06  7:39       ` [PATCH v3 08/20] convert.h: drop 'extern' from function declaration Nguyễn Thái Ngọc Duy
2018-06-06  7:39       ` [PATCH v3 09/20] convert.c: remove an implicit dependency on the_index Nguyễn Thái Ngọc Duy
2018-06-06  7:39       ` [PATCH v3 10/20] dir.c: remove an implicit dependency on the_index in pathspec code Nguyễn Thái Ngọc Duy
2018-06-06  7:39       ` [PATCH v3 11/20] ls-files: correct index argument to get_convert_attr_ascii() Nguyễn Thái Ngọc Duy
2018-06-06  7:39       ` [PATCH v3 12/20] pathspec.c: use the right index instead of the_index Nguyễn Thái Ngọc Duy
2018-06-06  7:39       ` [PATCH v3 13/20] submodule.c: " Nguyễn Thái Ngọc Duy
2018-06-06  7:39       ` [PATCH v3 14/20] entry.c: " Nguyễn Thái Ngọc Duy
2018-06-06  7:39       ` [PATCH v3 15/20] attr: remove index from git_attr_set_direction() Nguyễn Thái Ngọc Duy
2018-06-06 16:58         ` Brandon Williams
2018-06-06  7:39       ` [PATCH v3 16/20] preload-index.c: use the right index instead of the_index Nguyễn Thái Ngọc Duy
2018-06-06  7:39       ` [PATCH v3 17/20] cache.c: remove an implicit dependency on the_index Nguyễn Thái Ngọc Duy
2018-06-06 17:00         ` Brandon Williams [this message]
2018-06-06  7:39       ` [PATCH v3 18/20] resolve-undo.c: use the right index instead of the_index Nguyễn Thái Ngọc Duy
2018-06-06  7:39       ` [PATCH v3 19/20] grep: " Nguyễn Thái Ngọc Duy
2018-06-06  7:39       ` [PATCH v3 20/20] cache.h: make the_index part of "compatibility macros" Nguyễn Thái Ngọc Duy
2018-06-06 16:49       ` [PATCH v4 00/23] Fix incorrect use of the_index Nguyễn Thái Ngọc Duy
2018-06-06 16:49         ` [PATCH v4 01/23] unpack-trees: remove 'extern' on function declaration Nguyễn Thái Ngọc Duy
2018-06-06 16:49         ` [PATCH v4 02/23] unpack-trees: add a note about path invalidation Nguyễn Thái Ngọc Duy
2018-06-06 16:49         ` [PATCH v4 03/23] unpack-trees: don't shadow global var the_index Nguyễn Thái Ngọc Duy
2018-06-06 16:49         ` [PATCH v4 04/23] unpack-tress: convert clear_ce_flags* to avoid the_index Nguyễn Thái Ngọc Duy
2018-06-07  7:41           ` Elijah Newren
2018-06-07 15:11             ` Duy Nguyen
2018-06-08 15:58               ` Duy Nguyen
2018-06-06 16:49         ` [PATCH v4 05/23] unpack-trees: avoid the_index in verify_absent() Nguyễn Thái Ngọc Duy
2018-06-06 17:02         ` [PATCH v4 06/23] attr.h: drop extern from function declaration Nguyễn Thái Ngọc Duy
2018-06-06 17:02           ` [PATCH v4 07/23] attr: remove an implicit dependency on the_index Nguyễn Thái Ngọc Duy
2018-06-06 17:02           ` [PATCH v4 08/23] convert.h: drop 'extern' from function declaration Nguyễn Thái Ngọc Duy
2018-06-06 17:02           ` [PATCH v4 09/23] convert.c: remove an implicit dependency on the_index Nguyễn Thái Ngọc Duy
2018-06-06 17:02           ` [PATCH v4 10/23] dir.c: remove an implicit dependency on the_index in pathspec code Nguyễn Thái Ngọc Duy
2018-06-06 17:02           ` [PATCH v4 11/23] ls-files: correct index argument to get_convert_attr_ascii() Nguyễn Thái Ngọc Duy
2018-06-06 17:02           ` [PATCH v4 12/23] pathspec.c: use the right index instead of the_index Nguyễn Thái Ngọc Duy
2018-06-06 17:02           ` [PATCH v4 13/23] submodule.c: " Nguyễn Thái Ngọc Duy
2018-06-06 17:02           ` [PATCH v4 14/23] entry.c: " Nguyễn Thái Ngọc Duy
2018-06-06 17:02           ` [PATCH v4 15/23] attr: remove index from git_attr_set_direction() Nguyễn Thái Ngọc Duy
2018-06-09 17:57             ` Elijah Newren
2018-06-06 17:02           ` [PATCH v4 16/23] preload-index.c: use the right index instead of the_index Nguyễn Thái Ngọc Duy
2018-06-06 17:02           ` [PATCH v4 17/23] read-cache.c: remove an implicit dependency on the_index Nguyễn Thái Ngọc Duy
2018-06-09 18:10             ` Elijah Newren
2018-06-09 18:45               ` Duy Nguyen
2018-06-09 19:48                 ` Elijah Newren
2018-06-06 17:02           ` [PATCH v4 18/23] apply.c: use the right index instead of the_index Nguyễn Thái Ngọc Duy
2018-06-06 17:02           ` [PATCH v4 19/23] difftool: " Nguyễn Thái Ngọc Duy
2018-06-06 17:02           ` [PATCH v4 20/23] checkout: avoid the_index when possible Nguyễn Thái Ngọc Duy
2018-06-06 17:02           ` [PATCH v4 21/23] resolve-undo.c: use the right index instead of the_index Nguyễn Thái Ngọc Duy
2018-06-06 17:02           ` [PATCH v4 22/23] grep: " Nguyễn Thái Ngọc Duy
2018-06-06 17:02           ` [PATCH v4 23/23] cache.h: make the_index part of "compatibility macros" Nguyễn Thái Ngọc Duy
2018-06-07  7:44         ` [PATCH v4 00/23] Fix incorrect use of the_index Elijah Newren
2018-06-09 19:58           ` Elijah Newren
2018-06-11 16:05             ` Duy Nguyen
2018-06-11 16:11               ` Elijah Newren
2018-06-11 16:24                 ` Duy Nguyen
2018-06-11 16:44                   ` Elijah Newren
2018-06-11 16:49                     ` Duy Nguyen
2018-06-14 17:18                       ` Duy Nguyen
2018-06-14 20:57                         ` Elijah Newren
2018-06-11 18:20               ` Duy Nguyen

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=20180606170042.GJ158365@google.com \
    --to=bmwill@google.com \
    --cc=git@vger.kernel.org \
    --cc=newren@gmail.com \
    --cc=pclouds@gmail.com \
    --cc=ramsay@ramsayjones.plus.com \
    /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).