Skip to content

Commit 8687c2b

Browse files
jeffhostetlergitster
authored andcommitted
fsmonitor: refactor refresh callback for non-directory events
Move the code that handles unqualified FSEvents (without a trailing slash) into a helper function. Signed-off-by: Jeff Hostetler <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7a15a62 commit 8687c2b

File tree

1 file changed

+39
-28
lines changed

1 file changed

+39
-28
lines changed

fsmonitor.c

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,43 @@ static int query_fsmonitor_hook(struct repository *r,
183183
return result;
184184
}
185185

186+
static void handle_path_without_trailing_slash(
187+
struct index_state *istate, const char *name, int pos)
188+
{
189+
int i;
190+
191+
if (pos >= 0) {
192+
/*
193+
* We have an exact match for this path and can just
194+
* invalidate it.
195+
*/
196+
istate->cache[pos]->ce_flags &= ~CE_FSMONITOR_VALID;
197+
} else {
198+
/*
199+
* The path is not a tracked file -or- it is a
200+
* directory event on a platform that cannot
201+
* distinguish between file and directory events in
202+
* the event handler, such as Windows.
203+
*
204+
* Scan as if it is a directory and invalidate the
205+
* cone under it. (But remember to ignore items
206+
* between "name" and "name/", such as "name-" and
207+
* "name.".
208+
*/
209+
int len = strlen(name);
210+
pos = -pos - 1;
211+
212+
for (i = pos; i < istate->cache_nr; i++) {
213+
if (!starts_with(istate->cache[i]->name, name))
214+
break;
215+
if ((unsigned char)istate->cache[i]->name[len] > '/')
216+
break;
217+
if (istate->cache[i]->name[len] == '/')
218+
istate->cache[i]->ce_flags &= ~CE_FSMONITOR_VALID;
219+
}
220+
}
221+
}
222+
186223
/*
187224
* The daemon can decorate directory events, such as a move or rename,
188225
* by adding a trailing slash to the observed name. Use this to
@@ -225,7 +262,7 @@ static void handle_path_with_trailing_slash(
225262

226263
static void fsmonitor_refresh_callback(struct index_state *istate, char *name)
227264
{
228-
int i, len = strlen(name);
265+
int len = strlen(name);
229266
int pos = index_name_pos(istate, name, len);
230267

231268
trace_printf_key(&trace_fsmonitor,
@@ -240,34 +277,8 @@ static void fsmonitor_refresh_callback(struct index_state *istate, char *name)
240277
* for the untracked cache.
241278
*/
242279
name[len - 1] = '\0';
243-
} else if (pos >= 0) {
244-
/*
245-
* We have an exact match for this path and can just
246-
* invalidate it.
247-
*/
248-
istate->cache[pos]->ce_flags &= ~CE_FSMONITOR_VALID;
249280
} else {
250-
/*
251-
* The path is not a tracked file -or- it is a
252-
* directory event on a platform that cannot
253-
* distinguish between file and directory events in
254-
* the event handler, such as Windows.
255-
*
256-
* Scan as if it is a directory and invalidate the
257-
* cone under it. (But remember to ignore items
258-
* between "name" and "name/", such as "name-" and
259-
* "name.".
260-
*/
261-
pos = -pos - 1;
262-
263-
for (i = pos; i < istate->cache_nr; i++) {
264-
if (!starts_with(istate->cache[i]->name, name))
265-
break;
266-
if ((unsigned char)istate->cache[i]->name[len] > '/')
267-
break;
268-
if (istate->cache[i]->name[len] == '/')
269-
istate->cache[i]->ce_flags &= ~CE_FSMONITOR_VALID;
270-
}
281+
handle_path_without_trailing_slash(istate, name, pos);
271282
}
272283

273284
/*

0 commit comments

Comments
 (0)