fsmonitor: use IPC to query the builtin FSMonitor daemon

Use simple IPC to directly communicate with the new builtin file system monitor daemon when `core.fsmonitor` is set to true. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff Hostetler committed Mar 25, 2022 at 18:02 UTC 9c307e8afd930485a8409cadf8cc7065512d9845
1 file changed +36 -2
fsmonitor.c
+36 -2
@@ -241,8 +241,41 @@ void refresh_fsmonitor(struct index_state *istate)
241 trace_printf_key(&trace_fsmonitor, "refresh fsmonitor");
242
243 if (fsm_mode == FSMONITOR_MODE_IPC) {
244 - /* TODO */
245 - return;
244 + query_success = !fsmonitor_ipc__send_query(
245 + istate->fsmonitor_last_update ?
246 + istate->fsmonitor_last_update : "builtin:fake",
247 + &query_result);
248 + if (query_success) {
249 + /*
250 + * The response contains a series of nul terminated
251 + * strings. The first is the new token.
252 + *
253 + * Use `char *buf` as an interlude to trick the CI
254 + * static analysis to let us use `strbuf_addstr()`
255 + * here (and only copy the token) rather than
256 + * `strbuf_addbuf()`.
257 + */
258 + buf = query_result.buf;
259 + strbuf_addstr(&last_update_token, buf);
260 + bol = last_update_token.len + 1;
261 + is_trivial = query_result.buf[bol] == '/';
262 + if (is_trivial)
263 + trace2_data_intmax("fsm_client", NULL,
264 + "query/trivial-response", 1);
265 + } else {
266 + /*
267 + * The builtin daemon is not available on this
268 + * platform -OR- we failed to get a response.
269 + *
270 + * Generate a fake token (rather than a V1
271 + * timestamp) for the index extension. (If
272 + * they switch back to the hook API, we don't
273 + * want ambiguous state.)
274 + */
275 + strbuf_addstr(&last_update_token, "builtin:fake");
276 + }
277 +
278 + goto apply_results;
279 }
280
281 assert(fsm_mode == FSMONITOR_MODE_HOOK);
@@ -315,6 +348,7 @@ void refresh_fsmonitor(struct index_state *istate)
348 query_success ? "success" : "failure");
349 }
350
351 +apply_results:
352 /*
353 * The response from FSMonitor (excluding the header token) is
354 * either: