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

[PATCH v4 04/23] unpack-tress: convert clear_ce_flags* to avoid the_index

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Jun 6, 2018, 16:49 UTC
Message-ID
<20180606165016.3285-5-pclouds@gmail.com>
In-Reply-To
<20180606165016.3285-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 45fcda3169..5268de7af5 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -1085,13 +1085,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,
@@ -1100,7 +1102,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, '/');
@@ -1122,7 +1124,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);
@@ -1145,7 +1147,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)
@@ -1179,7 +1182,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,
@@ -1193,7 +1196,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);
@@ -1203,7 +1206,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)
@@ -1213,15 +1216,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);
@@ -1256,7 +1261,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.rc0.333.g22e6ee6cdf
Previous: Nguyễn Thái Ngọc DuyNext: Elijah Newren
Message 55 of 92 in “unpack-trees.c: do not use "the_index"”
  1. unpack-trees.c: do not use "the_index"Nguyễn Thái Ngọc Duy, Jun 1, 2018
  2. Elijah NewrenJun 1, 2018
  3. Stefan BellerJun 1, 2018
  4. Duy NguyenJun 2, 2018
  5. Duy NguyenJun 2, 2018
  6. Elijah NewrenJun 3, 2018
  7. Brandon WilliamsJun 4, 2018
  8. 0/6 Fix "the_index" usage in unpack-trees.cNguyễn Thái Ngọc Duy, Jun 5, 2018
  9. 1/6 unpack-trees: remove 'extern' on function declarationNguyễn Thái Ngọc Duy, Jun 5, 2018
  10. 3/6 unpack-trees: don't shadow global var the_indexNguyễn Thái Ngọc Duy, Jun 5, 2018
  11. Ramsay JonesJun 5, 2018
  12. 4/6 unpack-tress: convert clear_ce_flags* to avoid the_indexNguyễn Thái Ngọc Duy, Jun 5, 2018
  13. Ramsay JonesJun 5, 2018
  14. 5/6 unpack-trees: avoid the_index in verify_absent()Nguyễn Thái Ngọc Duy, Jun 5, 2018
  15. 6/6 Forbid "the_index" in dir.c and unpack-trees.cNguyễn Thái Ngọc Duy, Jun 5, 2018
  16. Brandon WilliamsJun 5, 2018
  17. Duy NguyenJun 6, 2018
  18. 2/6 unpack-trees: add a note about path invalidationNguyễn Thái Ngọc Duy, Jun 5, 2018
  19. 0/5 Fix "the_index" usage in unpack-trees.cNguyễn Thái Ngọc Duy, Jun 6, 2018
  20. 1/5 unpack-trees: remove 'extern' on function declarationNguyễn Thái Ngọc Duy, Jun 6, 2018
  21. 4/5 unpack-tress: convert clear_ce_flags* to avoid the_indexNguyễn Thái Ngọc Duy, Jun 6, 2018
  22. 3/5 unpack-trees: don't shadow global var the_indexNguyễn Thái Ngọc Duy, Jun 6, 2018
  23. 2/5 unpack-trees: add a note about path invalidationNguyễn Thái Ngọc Duy, Jun 6, 2018
  24. 5/5 unpack-trees: avoid the_index in verify_absent()Nguyễn Thái Ngọc Duy, Jun 6, 2018
  25. 00/20 Fix incorrect use of the_indexNguyễn Thái Ngọc Duy, Jun 6, 2018
  26. 02/20 unpack-trees: add a note about path invalidationNguyễn Thái Ngọc Duy, Jun 6, 2018
  27. 01/20 unpack-trees: remove 'extern' on function declarationNguyễn Thái Ngọc Duy, Jun 6, 2018
  28. 04/20 unpack-tress: convert clear_ce_flags* to avoid the_indexNguyễn Thái Ngọc Duy, Jun 6, 2018
  29. 05/20 unpack-trees: avoid the_index in verify_absent()Nguyễn Thái Ngọc Duy, Jun 6, 2018
  30. 03/20 unpack-trees: don't shadow global var the_indexNguyễn Thái Ngọc Duy, Jun 6, 2018
  31. 11/20 ls-files: correct index argument to get_convert_attr_ascii()Nguyễn Thái Ngọc Duy, Jun 6, 2018
  32. 10/20 dir.c: remove an implicit dependency on the_index in pathspec codeNguyễn Thái Ngọc Duy, Jun 6, 2018
  33. 14/20 entry.c: use the right index instead of the_indexNguyễn Thái Ngọc Duy, Jun 6, 2018
  34. 09/20 convert.c: remove an implicit dependency on the_indexNguyễn Thái Ngọc Duy, Jun 6, 2018
  35. 19/20 grep: use the right index instead of the_indexNguyễn Thái Ngọc Duy, Jun 6, 2018
  36. 17/20 cache.c: remove an implicit dependency on the_indexNguyễn Thái Ngọc Duy, Jun 6, 2018
  37. Brandon WilliamsJun 6, 2018
  38. 18/20 resolve-undo.c: use the right index instead of the_indexNguyễn Thái Ngọc Duy, Jun 6, 2018
  39. 20/20 cache.h: make the_index part of "compatibility macros"Nguyễn Thái Ngọc Duy, Jun 6, 2018
  40. 16/20 preload-index.c: use the right index instead of the_indexNguyễn Thái Ngọc Duy, Jun 6, 2018
  41. 12/20 pathspec.c: use the right index instead of the_indexNguyễn Thái Ngọc Duy, Jun 6, 2018
  42. 15/20 attr: remove index from git_attr_set_direction()Nguyễn Thái Ngọc Duy, Jun 6, 2018
  43. Brandon WilliamsJun 6, 2018
  44. 08/20 convert.h: drop 'extern' from function declarationNguyễn Thái Ngọc Duy, Jun 6, 2018
  45. 13/20 submodule.c: use the right index instead of the_indexNguyễn Thái Ngọc Duy, Jun 6, 2018
  46. 06/20 attr.h: drop extern from function declarationNguyễn Thái Ngọc Duy, Jun 6, 2018
  47. 07/20 attr: remove an implicit dependency on the_indexNguyễn Thái Ngọc Duy, Jun 6, 2018
  48. Ramsay JonesJun 6, 2018
  49. Brandon WilliamsJun 6, 2018
  50. Duy NguyenJun 6, 2018
  51. Brandon WilliamsJun 6, 2018
  52. 00/23 Fix incorrect use of the_indexNguyễn Thái Ngọc Duy, Jun 6, 2018
  53. 01/23 unpack-trees: remove 'extern' on function declarationNguyễn Thái Ngọc Duy, Jun 6, 2018
  54. 02/23 unpack-trees: add a note about path invalidationNguyễn Thái Ngọc Duy, Jun 6, 2018
  55. 04/23 unpack-tress: convert clear_ce_flags* to avoid the_indexNguyễn Thái Ngọc Duy, Jun 6, 2018
  56. Elijah NewrenJun 7, 2018
  57. Duy NguyenJun 7, 2018
  58. Duy NguyenJun 8, 2018
  59. 03/23 unpack-trees: don't shadow global var the_indexNguyễn Thái Ngọc Duy, Jun 6, 2018
  60. 05/23 unpack-trees: avoid the_index in verify_absent()Nguyễn Thái Ngọc Duy, Jun 6, 2018
  61. 06/23 attr.h: drop extern from function declarationNguyễn Thái Ngọc Duy, Jun 6, 2018
  62. 08/23 convert.h: drop 'extern' from function declarationNguyễn Thái Ngọc Duy, Jun 6, 2018
  63. 09/23 convert.c: remove an implicit dependency on the_indexNguyễn Thái Ngọc Duy, Jun 6, 2018
  64. 11/23 ls-files: correct index argument to get_convert_attr_ascii()Nguyễn Thái Ngọc Duy, Jun 6, 2018
  65. 10/23 dir.c: remove an implicit dependency on the_index in pathspec codeNguyễn Thái Ngọc Duy, Jun 6, 2018
  66. 14/23 entry.c: use the right index instead of the_indexNguyễn Thái Ngọc Duy, Jun 6, 2018
  67. 13/23 submodule.c: use the right index instead of the_indexNguyễn Thái Ngọc Duy, Jun 6, 2018
  68. 16/23 preload-index.c: use the right index instead of the_indexNguyễn Thái Ngọc Duy, Jun 6, 2018
  69. 20/23 checkout: avoid the_index when possibleNguyễn Thái Ngọc Duy, Jun 6, 2018
  70. 23/23 cache.h: make the_index part of "compatibility macros"Nguyễn Thái Ngọc Duy, Jun 6, 2018
  71. 22/23 grep: use the right index instead of the_indexNguyễn Thái Ngọc Duy, Jun 6, 2018
  72. 19/23 difftool: use the right index instead of the_indexNguyễn Thái Ngọc Duy, Jun 6, 2018
  73. 21/23 resolve-undo.c: use the right index instead of the_indexNguyễn Thái Ngọc Duy, Jun 6, 2018
  74. 18/23 apply.c: use the right index instead of the_indexNguyễn Thái Ngọc Duy, Jun 6, 2018
  75. 15/23 attr: remove index from git_attr_set_direction()Nguyễn Thái Ngọc Duy, Jun 6, 2018
  76. Elijah NewrenJun 9, 2018
  77. 17/23 read-cache.c: remove an implicit dependency on the_indexNguyễn Thái Ngọc Duy, Jun 6, 2018
  78. Elijah NewrenJun 9, 2018
  79. Duy NguyenJun 9, 2018
  80. Elijah NewrenJun 9, 2018
  81. 12/23 pathspec.c: use the right index instead of the_indexNguyễn Thái Ngọc Duy, Jun 6, 2018
  82. 07/23 attr: remove an implicit dependency on the_indexNguyễn Thái Ngọc Duy, Jun 6, 2018
  83. Elijah NewrenJun 7, 2018
  84. Elijah NewrenJun 9, 2018
  85. Duy NguyenJun 11, 2018
  86. Elijah NewrenJun 11, 2018
  87. Duy NguyenJun 11, 2018
  88. Elijah NewrenJun 11, 2018
  89. Duy NguyenJun 11, 2018
  90. Duy NguyenJun 14, 2018
  91. Elijah NewrenJun 14, 2018
  92. Duy NguyenJun 11, 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.