Skip to content

Commit ff03836

Browse files
kewillfordgitster
authored andcommitted
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>
1 parent 29fbbf4 commit ff03836

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

fsmonitor.c

+26-5
Original file line numberDiff line numberDiff line change
@@ -190,13 +190,34 @@ int fsmonitor_is_trivial_response(const struct strbuf *query_result)
190190
return is_trivial;
191191
}
192192

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)
194194
{
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));
196216

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+
}
200221
}
201222

202223
/*

0 commit comments

Comments
 (0)