Skip to content

Commit e5da3dd

Browse files
jeffhostetlergitster
authored andcommitted
fsmonitor: refactor refresh callback on directory events
Move the code to handle directory FSEvents (containing pathnames with a trailing slash) into a helper function. Signed-off-by: Jeff Hostetler <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 32ca706 commit e5da3dd

File tree

1 file changed

+30
-22
lines changed

1 file changed

+30
-22
lines changed

fsmonitor.c

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

186+
static void handle_path_with_trailing_slash(
187+
struct index_state *istate, const char *name, int pos)
188+
{
189+
int i;
190+
191+
/*
192+
* The daemon can decorate directory events, such as
193+
* moves or renames, with a trailing slash if the OS
194+
* FS Event contains sufficient information, such as
195+
* MacOS.
196+
*
197+
* Use this to invalidate the entire cone under that
198+
* directory.
199+
*
200+
* We do not expect an exact match because the index
201+
* does not normally contain directory entries, so we
202+
* start at the insertion point and scan.
203+
*/
204+
if (pos < 0)
205+
pos = -pos - 1;
206+
207+
/* Mark all entries for the folder invalid */
208+
for (i = pos; i < istate->cache_nr; i++) {
209+
if (!starts_with(istate->cache[i]->name, name))
210+
break;
211+
istate->cache[i]->ce_flags &= ~CE_FSMONITOR_VALID;
212+
}
213+
}
214+
186215
static void fsmonitor_refresh_callback(struct index_state *istate, char *name)
187216
{
188217
int i, len = strlen(name);
@@ -193,28 +222,7 @@ static void fsmonitor_refresh_callback(struct index_state *istate, char *name)
193222
name, pos);
194223

195224
if (name[len - 1] == '/') {
196-
/*
197-
* The daemon can decorate directory events, such as
198-
* moves or renames, with a trailing slash if the OS
199-
* FS Event contains sufficient information, such as
200-
* MacOS.
201-
*
202-
* Use this to invalidate the entire cone under that
203-
* directory.
204-
*
205-
* We do not expect an exact match because the index
206-
* does not normally contain directory entries, so we
207-
* start at the insertion point and scan.
208-
*/
209-
if (pos < 0)
210-
pos = -pos - 1;
211-
212-
/* Mark all entries for the folder invalid */
213-
for (i = pos; i < istate->cache_nr; i++) {
214-
if (!starts_with(istate->cache[i]->name, name))
215-
break;
216-
istate->cache[i]->ce_flags &= ~CE_FSMONITOR_VALID;
217-
}
225+
handle_path_with_trailing_slash(istate, name, pos);
218226

219227
/*
220228
* We need to remove the traling "/" from the path

0 commit comments

Comments
 (0)