fsmonitor: allow all entries for a folder to be invalidated
Allow fsmonitor to report directory changes by reporting paths with a trailing slash. Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com> Signed-off-by: Kevin Willford <Kevin.Willford@microsoft.com> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Reviewed-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Kevin Willford committed
Feb 3, 2021 at 15:34 UTC
ff03836b9d696617d699da2e4108057f9a48b9ef
1 file changed
+26
-5
fsmonitor.c
+26
-5
@@ -190,13 +190,34 @@ int fsmonitor_is_trivial_response(const struct strbuf *query_result)
190
return is_trivial;
191
}
192
193
-static void fsmonitor_refresh_callback(struct index_state *istate, const char *name)
193
+static void fsmonitor_refresh_callback(struct index_state *istate, char *name)
194
{
195
- int pos = index_name_pos(istate, name, strlen(name));
195
+ int i, len = strlen(name);
196
+ if (name[len - 1] == '/') {
197
+
198
+ /*
199
+ * TODO We should binary search to find the first path with
200
+ * TODO this directory prefix. Then linearly update entries
201
+ * TODO while the prefix matches. Taking care to search without
202
+ * TODO the trailing slash -- because '/' sorts after a few
203
+ * TODO interesting special chars, like '.' and ' '.
204
+ */
205
+
206
+ /* Mark all entries for the folder invalid */
207
+ for (i = 0; i < istate->cache_nr; i++) {
208
+ if (istate->cache[i]->ce_flags & CE_FSMONITOR_VALID &&
209
+ starts_with(istate->cache[i]->name, name))
210
+ istate->cache[i]->ce_flags &= ~CE_FSMONITOR_VALID;
211
+ }
212
+ /* Need to remove the / from the path for the untracked cache */
213
+ name[len - 1] = '\0';
214
+ } else {
215
+ int pos = index_name_pos(istate, name, strlen(name));
216
197
- if (pos >= 0) {
198
- struct cache_entry *ce = istate->cache[pos];
199
- ce->ce_flags &= ~CE_FSMONITOR_VALID;
217
+ if (pos >= 0) {
218
+ struct cache_entry *ce = istate->cache[pos];
219
+ ce->ce_flags &= ~CE_FSMONITOR_VALID;
220
+ }
221
}
222
223
/*