@@ -168,29 +168,15 @@ static int query_fsmonitor(int version, const char *last_update, struct strbuf *
168
168
169
169
if (result )
170
170
trace2_data_intmax ("fsm_hook" , NULL , "query/failed" , result );
171
- else {
171
+ else
172
172
trace2_data_intmax ("fsm_hook" , NULL , "query/response-length" ,
173
173
query_result -> len );
174
174
175
- if (fsmonitor_is_trivial_response (query_result ))
176
- trace2_data_intmax ("fsm_hook" , NULL ,
177
- "query/trivial-response" , 1 );
178
- }
179
-
180
175
trace2_region_leave ("fsm_hook" , "query" , NULL );
181
176
182
177
return result ;
183
178
}
184
179
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
-
194
180
static void fsmonitor_refresh_callback (struct index_state * istate , char * name )
195
181
{
196
182
int i , len = strlen (name );
@@ -238,6 +224,7 @@ void refresh_fsmonitor(struct index_state *istate)
238
224
struct strbuf last_update_token = STRBUF_INIT ;
239
225
char * buf ;
240
226
unsigned int i ;
227
+ int is_trivial = 0 ;
241
228
242
229
if (!core_fsmonitor || istate -> fsmonitor_has_run_once )
243
230
return ;
@@ -283,6 +270,7 @@ void refresh_fsmonitor(struct index_state *istate)
283
270
query_success = 0 ;
284
271
} else {
285
272
bol = last_update_token .len + 1 ;
273
+ is_trivial = query_result .buf [bol ] == '/' ;
286
274
}
287
275
} else if (hook_version < 0 ) {
288
276
hook_version = HOOK_INTERFACE_VERSION1 ;
@@ -294,16 +282,38 @@ void refresh_fsmonitor(struct index_state *istate)
294
282
if (hook_version == HOOK_INTERFACE_VERSION1 ) {
295
283
query_success = !query_fsmonitor (HOOK_INTERFACE_VERSION1 ,
296
284
istate -> fsmonitor_last_update , & query_result );
285
+ if (query_success )
286
+ is_trivial = query_result .buf [0 ] == '/' ;
297
287
}
298
288
289
+ if (is_trivial )
290
+ trace2_data_intmax ("fsm_hook" , NULL ,
291
+ "query/trivial-response" , 1 );
292
+
299
293
trace_performance_since (last_update , "fsmonitor process '%s'" , core_fsmonitor );
300
294
trace_printf_key (& trace_fsmonitor , "fsmonitor process '%s' returned %s" ,
301
295
core_fsmonitor , query_success ? "success" : "failure" );
302
296
}
303
297
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
+ */
307
317
buf = query_result .buf ;
308
318
for (i = bol ; i < query_result .len ; i ++ ) {
309
319
if (buf [i ] != '\0' )
@@ -318,19 +328,27 @@ void refresh_fsmonitor(struct index_state *istate)
318
328
if (istate -> untracked )
319
329
istate -> untracked -> use_fsmonitor = 1 ;
320
330
} 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
+ */
324
339
int is_cache_changed = 0 ;
325
- /* Mark all entries invalid */
340
+
326
341
for (i = 0 ; i < istate -> cache_nr ; i ++ ) {
327
342
if (istate -> cache [i ]-> ce_flags & CE_FSMONITOR_VALID ) {
328
343
is_cache_changed = 1 ;
329
344
istate -> cache [i ]-> ce_flags &= ~CE_FSMONITOR_VALID ;
330
345
}
331
346
}
332
347
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
+ */
334
352
if (is_cache_changed )
335
353
istate -> cache_changed |= FSMONITOR_CHANGED ;
336
354
0 commit comments