unpack-trees: convert clear_ce_flags* to avoid the_index

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> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nguyễn Thái Ngọc Duy committed Aug 13, 2018 at 18:14 UTC 27c82fb3b406e01bbcd6c7cb11dc1925b88f6a92
1 file changed +18 -13
unpack-trees.c
+18 -13
@@ -1092,13 +1092,15 @@ static int unpack_callback(int n, unsigned long mask, unsigned long dirmask, str
1092 return mask;
1093 }
1094
1095 -static int clear_ce_flags_1(struct cache_entry **cache, int nr,
1095 +static int clear_ce_flags_1(struct index_state *istate,
1096 + struct cache_entry **cache, int nr,
1097 struct strbuf *prefix,
1098 int select_mask, int clear_mask,
1099 struct exclude_list *el, int defval);
1100
1101 /* Whole directory matching */
1101 -static int clear_ce_flags_dir(struct cache_entry **cache, int nr,
1102 +static int clear_ce_flags_dir(struct index_state *istate,
1103 + struct cache_entry **cache, int nr,
1104 struct strbuf *prefix,
1105 char *basename,
1106 int select_mask, int clear_mask,
@@ -1107,7 +1109,7 @@ static int clear_ce_flags_dir(struct cache_entry **cache, int nr,
1109 struct cache_entry **cache_end;
1110 int dtype = DT_DIR;
1111 int ret = is_excluded_from_list(prefix->buf, prefix->len,
1110 - basename, &dtype, el, &the_index);
1112 + basename, &dtype, el, istate);
1113 int rc;
1114
1115 strbuf_addch(prefix, '/');
@@ -1129,7 +1131,7 @@ static int clear_ce_flags_dir(struct cache_entry **cache, int nr,
1131 * calling clear_ce_flags_1(). That function will call
1132 * the expensive is_excluded_from_list() on every entry.
1133 */
1132 - rc = clear_ce_flags_1(cache, cache_end - cache,
1134 + rc = clear_ce_flags_1(istate, cache, cache_end - cache,
1135 prefix,
1136 select_mask, clear_mask,
1137 el, ret);
@@ -1152,7 +1154,8 @@ static int clear_ce_flags_dir(struct cache_entry **cache, int nr,
1154 * cache[0]->name[0..(prefix_len-1)]
1155 * Top level path has prefix_len zero.
1156 */
1155 -static int clear_ce_flags_1(struct cache_entry **cache, int nr,
1157 +static int clear_ce_flags_1(struct index_state *istate,
1158 + struct cache_entry **cache, int nr,
1159 struct strbuf *prefix,
1160 int select_mask, int clear_mask,
1161 struct exclude_list *el, int defval)
@@ -1186,7 +1189,7 @@ static int clear_ce_flags_1(struct cache_entry **cache, int nr,
1189 len = slash - name;
1190 strbuf_add(prefix, name, len);
1191
1189 - processed = clear_ce_flags_dir(cache, cache_end - cache,
1192 + processed = clear_ce_flags_dir(istate, cache, cache_end - cache,
1193 prefix,
1194 prefix->buf + prefix->len - len,
1195 select_mask, clear_mask,
@@ -1200,7 +1203,7 @@ static int clear_ce_flags_1(struct cache_entry **cache, int nr,
1203 }
1204
1205 strbuf_addch(prefix, '/');
1203 - cache += clear_ce_flags_1(cache, cache_end - cache,
1206 + cache += clear_ce_flags_1(istate, cache, cache_end - cache,
1207 prefix,
1208 select_mask, clear_mask, el, defval);
1209 strbuf_setlen(prefix, prefix->len - len - 1);
@@ -1210,7 +1213,7 @@ static int clear_ce_flags_1(struct cache_entry **cache, int nr,
1213 /* Non-directory */
1214 dtype = ce_to_dtype(ce);
1215 ret = is_excluded_from_list(ce->name, ce_namelen(ce),
1213 - name, &dtype, el, &the_index);
1216 + name, &dtype, el, istate);
1217 if (ret < 0)
1218 ret = defval;
1219 if (ret > 0)
@@ -1220,15 +1223,17 @@ static int clear_ce_flags_1(struct cache_entry **cache, int nr,
1223 return nr - (cache_end - cache);
1224 }
1225
1223 -static int clear_ce_flags(struct cache_entry **cache, int nr,
1224 - int select_mask, int clear_mask,
1225 - struct exclude_list *el)
1226 +static int clear_ce_flags(struct index_state *istate,
1227 + int select_mask, int clear_mask,
1228 + struct exclude_list *el)
1229 {
1230 static struct strbuf prefix = STRBUF_INIT;
1231
1232 strbuf_reset(&prefix);
1233
1231 - return clear_ce_flags_1(cache, nr,
1234 + return clear_ce_flags_1(istate,
1235 + istate->cache,
1236 + istate->cache_nr,
1237 &prefix,
1238 select_mask, clear_mask,
1239 el, 0);
@@ -1263,7 +1268,7 @@ static void mark_new_skip_worktree(struct exclude_list *el,
1268 * 2. Widen worktree according to sparse-checkout file.
1269 * Matched entries will have skip_wt_flag cleared (i.e. "in")
1270 */
1266 - clear_ce_flags(istate->cache, istate->cache_nr, select_flag, skip_wt_flag, el);
1271 + clear_ce_flags(istate, select_flag, skip_wt_flag, el);
1272 }
1273
1274 static int verify_absent(const struct cache_entry *,