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

[PATCH 11/24] unpack-trees: convert clear_ce_flags* to avoid the_index

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Aug 13, 2018, 16:14 UTC
Message-ID
<20180813161441.16824-12-pclouds@gmail.com>
In-Reply-To
<20180813161441.16824-1-pclouds@gmail.com>

Prior to fba92be8f7, this code implicitly (and incorrectly) assumes the_index when running the exclude machinery. fba92be8f7 helps show this problem clearer because unpack-trees operation is supposed to work on whatever index the caller specifies... not specifically the_index.

Update the code to use "istate" argument that's originally from mark_new_skip_worktree(). From the call sites, both in unpack_trees(), you can see that this function works on two separate indexes: o->src_index and o->result. The second mark_new_skip_worktree() so far has incorecctly applied exclude rules on o->src_index instead of o->result. It's unclear what is the consequences of this, but it's definitely wrong.

[1] fba92be8f7 (dir: convert is_excluded_from_list to take an index -
    2017-05-05)
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 unpack-trees.c | 31 ++++++++++++++++++-------------
 1 file changed, 18 insertions(+), 13 deletions(-)
diff --git a/unpack-trees.c b/unpack-trees.c
index f50b463f65..5d11f10e66 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -1092,13 +1092,15 @@ static int unpack_callback(int n, unsigned long mask, unsigned long dirmask, str
 	return mask;
 }
 
-static int clear_ce_flags_1(struct cache_entry **cache, int nr,
+static int clear_ce_flags_1(struct index_state *istate,
+			    struct cache_entry **cache, int nr,
 			    struct strbuf *prefix,
 			    int select_mask, int clear_mask,
 			    struct exclude_list *el, int defval);
 
 /* Whole directory matching */
-static int clear_ce_flags_dir(struct cache_entry **cache, int nr,
+static int clear_ce_flags_dir(struct index_state *istate,
+			      struct cache_entry **cache, int nr,
 			      struct strbuf *prefix,
 			      char *basename,
 			      int select_mask, int clear_mask,
@@ -1107,7 +1109,7 @@ static int clear_ce_flags_dir(struct cache_entry **cache, int nr,
 	struct cache_entry **cache_end;
 	int dtype = DT_DIR;
 	int ret = is_excluded_from_list(prefix->buf, prefix->len,
-					basename, &dtype, el, &the_index);
+					basename, &dtype, el, istate);
 	int rc;
 
 	strbuf_addch(prefix, '/');
@@ -1129,7 +1131,7 @@ static int clear_ce_flags_dir(struct cache_entry **cache, int nr,
 	 * calling clear_ce_flags_1(). That function will call
 	 * the expensive is_excluded_from_list() on every entry.
 	 */
-	rc = clear_ce_flags_1(cache, cache_end - cache,
+	rc = clear_ce_flags_1(istate, cache, cache_end - cache,
 			      prefix,
 			      select_mask, clear_mask,
 			      el, ret);
@@ -1152,7 +1154,8 @@ static int clear_ce_flags_dir(struct cache_entry **cache, int nr,
  *   cache[0]->name[0..(prefix_len-1)]
  * Top level path has prefix_len zero.
  */
-static int clear_ce_flags_1(struct cache_entry **cache, int nr,
+static int clear_ce_flags_1(struct index_state *istate,
+			    struct cache_entry **cache, int nr,
 			    struct strbuf *prefix,
 			    int select_mask, int clear_mask,
 			    struct exclude_list *el, int defval)
@@ -1186,7 +1189,7 @@ static int clear_ce_flags_1(struct cache_entry **cache, int nr,
 			len = slash - name;
 			strbuf_add(prefix, name, len);
 
-			processed = clear_ce_flags_dir(cache, cache_end - cache,
+			processed = clear_ce_flags_dir(istate, cache, cache_end - cache,
 						       prefix,
 						       prefix->buf + prefix->len - len,
 						       select_mask, clear_mask,
@@ -1200,7 +1203,7 @@ static int clear_ce_flags_1(struct cache_entry **cache, int nr,
 			}
 
 			strbuf_addch(prefix, '/');
-			cache += clear_ce_flags_1(cache, cache_end - cache,
+			cache += clear_ce_flags_1(istate, cache, cache_end - cache,
 						  prefix,
 						  select_mask, clear_mask, el, defval);
 			strbuf_setlen(prefix, prefix->len - len - 1);
@@ -1210,7 +1213,7 @@ static int clear_ce_flags_1(struct cache_entry **cache, int nr,
 		/* Non-directory */
 		dtype = ce_to_dtype(ce);
 		ret = is_excluded_from_list(ce->name, ce_namelen(ce),
-					    name, &dtype, el, &the_index);
+					    name, &dtype, el, istate);
 		if (ret < 0)
 			ret = defval;
 		if (ret > 0)
@@ -1220,15 +1223,17 @@ static int clear_ce_flags_1(struct cache_entry **cache, int nr,
 	return nr - (cache_end - cache);
 }
 
-static int clear_ce_flags(struct cache_entry **cache, int nr,
-			    int select_mask, int clear_mask,
-			    struct exclude_list *el)
+static int clear_ce_flags(struct index_state *istate,
+			  int select_mask, int clear_mask,
+			  struct exclude_list *el)
 {
 	static struct strbuf prefix = STRBUF_INIT;
 
 	strbuf_reset(&prefix);
 
-	return clear_ce_flags_1(cache, nr,
+	return clear_ce_flags_1(istate,
+				istate->cache,
+				istate->cache_nr,
 				&prefix,
 				select_mask, clear_mask,
 				el, 0);
@@ -1263,7 +1268,7 @@ static void mark_new_skip_worktree(struct exclude_list *el,
 	 * 2. Widen worktree according to sparse-checkout file.
 	 * Matched entries will have skip_wt_flag cleared (i.e. "in")
 	 */
-	clear_ce_flags(istate->cache, istate->cache_nr, select_flag, skip_wt_flag, el);
+	clear_ce_flags(istate, select_flag, skip_wt_flag, el);
 }
 
 static int verify_absent(const struct cache_entry *,
-- 
2.18.0.1004.g6639190530
Previous: Nguyễn Thái Ngọc DuyNext: Nguyễn Thái Ngọc Duy
Message 21 of 38 in “Kill the_index part3”
  1. 00/24 Kill the_index part3Nguyễn Thái Ngọc Duy, Aug 13, 2018
  2. 01/24 diff.c: move read_index() code back to the callerNguyễn Thái Ngọc Duy, Aug 13, 2018
  3. 02/24 cache-tree: wrap the_index based wrappers with #ifdefNguyễn Thái Ngọc Duy, Aug 13, 2018
  4. Junio C HamanoAug 13, 2018
  5. 03/24 attr: remove an implicit dependency on the_indexNguyễn Thái Ngọc Duy, Aug 13, 2018
  6. Brandon WilliamsAug 13, 2018
  7. 04/24 convert.c: remove an implicit dependency on the_indexNguyễn Thái Ngọc Duy, Aug 13, 2018
  8. Junio C HamanoAug 13, 2018
  9. 06/24 preload-index.c: use the right index instead of the_indexNguyễn Thái Ngọc Duy, Aug 13, 2018
  10. 05/24 dir.c: remove an implicit dependency on the_index in pathspec codeNguyễn Thái Ngọc Duy, Aug 13, 2018
  11. Brandon WilliamsAug 13, 2018
  12. Duy NguyenAug 13, 2018
  13. 07/24 ls-files: correct index argument to get_convert_attr_ascii()Nguyễn Thái Ngọc Duy, Aug 13, 2018
  14. Stefan BellerAug 15, 2018
  15. 08/24 unpack-trees: remove 'extern' on function declarationNguyễn Thái Ngọc Duy, Aug 13, 2018
  16. Stefan BellerAug 15, 2018
  17. Duy NguyenAug 15, 2018
  18. Stefan BellerAug 15, 2018
  19. 09/24 unpack-trees: add a note about path invalidationNguyễn Thái Ngọc Duy, Aug 13, 2018
  20. 10/24 unpack-trees: don't shadow global var the_indexNguyễn Thái Ngọc Duy, Aug 13, 2018
  21. 11/24 unpack-trees: convert clear_ce_flags* to avoid the_indexNguyễn Thái Ngọc Duy, Aug 13, 2018
  22. 13/24 pathspec.c: use the right index instead of the_indexNguyễn Thái Ngọc Duy, Aug 13, 2018
  23. 12/24 unpack-trees: avoid the_index in verify_absent()Nguyễn Thái Ngọc Duy, Aug 13, 2018
  24. 14/24 submodule.c: use the right index instead of the_indexNguyễn Thái Ngọc Duy, Aug 13, 2018
  25. 16/24 attr: remove index from git_attr_set_direction()Nguyễn Thái Ngọc Duy, Aug 13, 2018
  26. Brandon WilliamsAug 13, 2018
  27. 15/24 entry.c: use the right index instead of the_indexNguyễn Thái Ngọc Duy, Aug 13, 2018
  28. 17/24 grep: use the right index instead of the_indexNguyễn Thái Ngọc Duy, Aug 13, 2018
  29. 19/24 archive-*.c: use the right repositoryNguyễn Thái Ngọc Duy, Aug 13, 2018
  30. 20/24 resolve-undo.c: use the right index instead of the_indexNguyễn Thái Ngọc Duy, Aug 13, 2018
  31. 21/24 apply.c: pass struct apply_state to more functionsNguyễn Thái Ngọc Duy, Aug 13, 2018
  32. 22/24 apply.c: make init_apply_state() take a struct repositoryNguyễn Thái Ngọc Duy, Aug 13, 2018
  33. 18/24 archive.c: avoid access to the_indexNguyễn Thái Ngọc Duy, Aug 13, 2018
  34. 23/24 apply.c: remove implicit dependency on the_indexNguyễn Thái Ngọc Duy, Aug 13, 2018
  35. 24/24 blame.c: remove implicit dependency on the_indexNguyễn Thái Ngọc Duy, Aug 13, 2018
  36. Brandon WilliamsAug 13, 2018
  37. Junio C HamanoAug 13, 2018
  38. Stefan BellerAug 15, 2018

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.