Skip to content

Commit 974c1b3

Browse files
jeffhostetlergitster
authored andcommitted
fsmonitor: enhance existing comments, clarify trivial response handling
Signed-off-by: Jeff Hostetler <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 715d08a commit 974c1b3

File tree

1 file changed

+41
-23
lines changed

1 file changed

+41
-23
lines changed

fsmonitor.c

Lines changed: 41 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -168,29 +168,15 @@ static int query_fsmonitor(int version, const char *last_update, struct strbuf *
168168

169169
if (result)
170170
trace2_data_intmax("fsm_hook", NULL, "query/failed", result);
171-
else {
171+
else
172172
trace2_data_intmax("fsm_hook", NULL, "query/response-length",
173173
query_result->len);
174174

175-
if (fsmonitor_is_trivial_response(query_result))
176-
trace2_data_intmax("fsm_hook", NULL,
177-
"query/trivial-response", 1);
178-
}
179-
180175
trace2_region_leave("fsm_hook", "query", NULL);
181176

182177
return result;
183178
}
184179

185-
int fsmonitor_is_trivial_response(const struct strbuf *query_result)
186-
{
187-
static char trivial_response[3] = { '\0', '/', '\0' };
188-
189-
return query_result->len >= 3 &&
190-
!memcmp(trivial_response,
191-
&query_result->buf[query_result->len - 3], 3);
192-
}
193-
194180
static void fsmonitor_refresh_callback(struct index_state *istate, char *name)
195181
{
196182
int i, len = strlen(name);
@@ -238,6 +224,7 @@ void refresh_fsmonitor(struct index_state *istate)
238224
struct strbuf last_update_token = STRBUF_INIT;
239225
char *buf;
240226
unsigned int i;
227+
int is_trivial = 0;
241228

242229
if (!core_fsmonitor || istate->fsmonitor_has_run_once)
243230
return;
@@ -283,6 +270,7 @@ void refresh_fsmonitor(struct index_state *istate)
283270
query_success = 0;
284271
} else {
285272
bol = last_update_token.len + 1;
273+
is_trivial = query_result.buf[bol] == '/';
286274
}
287275
} else if (hook_version < 0) {
288276
hook_version = HOOK_INTERFACE_VERSION1;
@@ -294,16 +282,38 @@ void refresh_fsmonitor(struct index_state *istate)
294282
if (hook_version == HOOK_INTERFACE_VERSION1) {
295283
query_success = !query_fsmonitor(HOOK_INTERFACE_VERSION1,
296284
istate->fsmonitor_last_update, &query_result);
285+
if (query_success)
286+
is_trivial = query_result.buf[0] == '/';
297287
}
298288

289+
if (is_trivial)
290+
trace2_data_intmax("fsm_hook", NULL,
291+
"query/trivial-response", 1);
292+
299293
trace_performance_since(last_update, "fsmonitor process '%s'", core_fsmonitor);
300294
trace_printf_key(&trace_fsmonitor, "fsmonitor process '%s' returned %s",
301295
core_fsmonitor, query_success ? "success" : "failure");
302296
}
303297

304-
/* a fsmonitor process can return '/' to indicate all entries are invalid */
305-
if (query_success && query_result.buf[bol] != '/') {
306-
/* Mark all entries returned by the monitor as dirty */
298+
/*
299+
* The response from FSMonitor (excluding the header token) is
300+
* either:
301+
*
302+
* [a] a (possibly empty) list of NUL delimited relative
303+
* pathnames of changed paths. This list can contain
304+
* files and directories. Directories have a trailing
305+
* slash.
306+
*
307+
* [b] a single '/' to indicate the provider had no
308+
* information and that we should consider everything
309+
* invalid. We call this a trivial response.
310+
*/
311+
if (query_success && !is_trivial) {
312+
/*
313+
* Mark all pathnames returned by the monitor as dirty.
314+
*
315+
* This updates both the cache-entries and the untracked-cache.
316+
*/
307317
buf = query_result.buf;
308318
for (i = bol; i < query_result.len; i++) {
309319
if (buf[i] != '\0')
@@ -318,19 +328,27 @@ void refresh_fsmonitor(struct index_state *istate)
318328
if (istate->untracked)
319329
istate->untracked->use_fsmonitor = 1;
320330
} else {
321-
322-
/* We only want to run the post index changed hook if we've actually changed entries, so keep track
323-
* if we actually changed entries or not */
331+
/*
332+
* We failed to get a response or received a trivial response,
333+
* so invalidate everything.
334+
*
335+
* We only want to run the post index changed hook if
336+
* we've actually changed entries, so keep track if we
337+
* actually changed entries or not.
338+
*/
324339
int is_cache_changed = 0;
325-
/* Mark all entries invalid */
340+
326341
for (i = 0; i < istate->cache_nr; i++) {
327342
if (istate->cache[i]->ce_flags & CE_FSMONITOR_VALID) {
328343
is_cache_changed = 1;
329344
istate->cache[i]->ce_flags &= ~CE_FSMONITOR_VALID;
330345
}
331346
}
332347

333-
/* If we're going to check every file, ensure we save the results */
348+
/*
349+
* If we're going to check every file, ensure we save
350+
* the results.
351+
*/
334352
if (is_cache_changed)
335353
istate->cache_changed |= FSMONITOR_CHANGED;
336354

0 commit comments

Comments
 (0)