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 <jeffhostetler@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Jeff Hostetler 2024-02-26 21:39:14 +00:00 committed by Junio C Hamano
parent 32ca706fad
commit e5da3ddbe9

View file

@ -183,16 +183,11 @@ static int query_fsmonitor_hook(struct repository *r,
return result;
}
static void fsmonitor_refresh_callback(struct index_state *istate, char *name)
static void handle_path_with_trailing_slash(
struct index_state *istate, const char *name, int pos)
{
int i, len = strlen(name);
int pos = index_name_pos(istate, name, len);
int i;
trace_printf_key(&trace_fsmonitor,
"fsmonitor_refresh_callback '%s' (pos %d)",
name, pos);
if (name[len - 1] == '/') {
/*
* The daemon can decorate directory events, such as
* moves or renames, with a trailing slash if the OS
@ -215,6 +210,19 @@ static void fsmonitor_refresh_callback(struct index_state *istate, char *name)
break;
istate->cache[i]->ce_flags &= ~CE_FSMONITOR_VALID;
}
}
static void fsmonitor_refresh_callback(struct index_state *istate, char *name)
{
int i, len = strlen(name);
int pos = index_name_pos(istate, name, len);
trace_printf_key(&trace_fsmonitor,
"fsmonitor_refresh_callback '%s' (pos %d)",
name, pos);
if (name[len - 1] == '/') {
handle_path_with_trailing_slash(istate, name, pos);
/*
* We need to remove the traling "/" from the path