зеркало из https://github.com/microsoft/git.git
fsmonitor: enhance existing comments, clarify trivial response handling
Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Родитель
715d08a9e5
Коммит
974c1b3987
64
fsmonitor.c
64
fsmonitor.c
|
@ -168,29 +168,15 @@ static int query_fsmonitor(int version, const char *last_update, struct strbuf *
|
||||||
|
|
||||||
if (result)
|
if (result)
|
||||||
trace2_data_intmax("fsm_hook", NULL, "query/failed", result);
|
trace2_data_intmax("fsm_hook", NULL, "query/failed", result);
|
||||||
else {
|
else
|
||||||
trace2_data_intmax("fsm_hook", NULL, "query/response-length",
|
trace2_data_intmax("fsm_hook", NULL, "query/response-length",
|
||||||
query_result->len);
|
query_result->len);
|
||||||
|
|
||||||
if (fsmonitor_is_trivial_response(query_result))
|
|
||||||
trace2_data_intmax("fsm_hook", NULL,
|
|
||||||
"query/trivial-response", 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
trace2_region_leave("fsm_hook", "query", NULL);
|
trace2_region_leave("fsm_hook", "query", NULL);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
int fsmonitor_is_trivial_response(const struct strbuf *query_result)
|
|
||||||
{
|
|
||||||
static char trivial_response[3] = { '\0', '/', '\0' };
|
|
||||||
|
|
||||||
return query_result->len >= 3 &&
|
|
||||||
!memcmp(trivial_response,
|
|
||||||
&query_result->buf[query_result->len - 3], 3);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void fsmonitor_refresh_callback(struct index_state *istate, char *name)
|
static void fsmonitor_refresh_callback(struct index_state *istate, char *name)
|
||||||
{
|
{
|
||||||
int i, len = strlen(name);
|
int i, len = strlen(name);
|
||||||
|
@ -238,6 +224,7 @@ void refresh_fsmonitor(struct index_state *istate)
|
||||||
struct strbuf last_update_token = STRBUF_INIT;
|
struct strbuf last_update_token = STRBUF_INIT;
|
||||||
char *buf;
|
char *buf;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
int is_trivial = 0;
|
||||||
|
|
||||||
if (!core_fsmonitor || istate->fsmonitor_has_run_once)
|
if (!core_fsmonitor || istate->fsmonitor_has_run_once)
|
||||||
return;
|
return;
|
||||||
|
@ -283,6 +270,7 @@ void refresh_fsmonitor(struct index_state *istate)
|
||||||
query_success = 0;
|
query_success = 0;
|
||||||
} else {
|
} else {
|
||||||
bol = last_update_token.len + 1;
|
bol = last_update_token.len + 1;
|
||||||
|
is_trivial = query_result.buf[bol] == '/';
|
||||||
}
|
}
|
||||||
} else if (hook_version < 0) {
|
} else if (hook_version < 0) {
|
||||||
hook_version = HOOK_INTERFACE_VERSION1;
|
hook_version = HOOK_INTERFACE_VERSION1;
|
||||||
|
@ -294,16 +282,38 @@ void refresh_fsmonitor(struct index_state *istate)
|
||||||
if (hook_version == HOOK_INTERFACE_VERSION1) {
|
if (hook_version == HOOK_INTERFACE_VERSION1) {
|
||||||
query_success = !query_fsmonitor(HOOK_INTERFACE_VERSION1,
|
query_success = !query_fsmonitor(HOOK_INTERFACE_VERSION1,
|
||||||
istate->fsmonitor_last_update, &query_result);
|
istate->fsmonitor_last_update, &query_result);
|
||||||
|
if (query_success)
|
||||||
|
is_trivial = query_result.buf[0] == '/';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (is_trivial)
|
||||||
|
trace2_data_intmax("fsm_hook", NULL,
|
||||||
|
"query/trivial-response", 1);
|
||||||
|
|
||||||
trace_performance_since(last_update, "fsmonitor process '%s'", core_fsmonitor);
|
trace_performance_since(last_update, "fsmonitor process '%s'", core_fsmonitor);
|
||||||
trace_printf_key(&trace_fsmonitor, "fsmonitor process '%s' returned %s",
|
trace_printf_key(&trace_fsmonitor, "fsmonitor process '%s' returned %s",
|
||||||
core_fsmonitor, query_success ? "success" : "failure");
|
core_fsmonitor, query_success ? "success" : "failure");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* a fsmonitor process can return '/' to indicate all entries are invalid */
|
/*
|
||||||
if (query_success && query_result.buf[bol] != '/') {
|
* The response from FSMonitor (excluding the header token) is
|
||||||
/* Mark all entries returned by the monitor as dirty */
|
* either:
|
||||||
|
*
|
||||||
|
* [a] a (possibly empty) list of NUL delimited relative
|
||||||
|
* pathnames of changed paths. This list can contain
|
||||||
|
* files and directories. Directories have a trailing
|
||||||
|
* slash.
|
||||||
|
*
|
||||||
|
* [b] a single '/' to indicate the provider had no
|
||||||
|
* information and that we should consider everything
|
||||||
|
* invalid. We call this a trivial response.
|
||||||
|
*/
|
||||||
|
if (query_success && !is_trivial) {
|
||||||
|
/*
|
||||||
|
* Mark all pathnames returned by the monitor as dirty.
|
||||||
|
*
|
||||||
|
* This updates both the cache-entries and the untracked-cache.
|
||||||
|
*/
|
||||||
buf = query_result.buf;
|
buf = query_result.buf;
|
||||||
for (i = bol; i < query_result.len; i++) {
|
for (i = bol; i < query_result.len; i++) {
|
||||||
if (buf[i] != '\0')
|
if (buf[i] != '\0')
|
||||||
|
@ -318,11 +328,16 @@ void refresh_fsmonitor(struct index_state *istate)
|
||||||
if (istate->untracked)
|
if (istate->untracked)
|
||||||
istate->untracked->use_fsmonitor = 1;
|
istate->untracked->use_fsmonitor = 1;
|
||||||
} else {
|
} else {
|
||||||
|
/*
|
||||||
/* We only want to run the post index changed hook if we've actually changed entries, so keep track
|
* We failed to get a response or received a trivial response,
|
||||||
* if we actually changed entries or not */
|
* so invalidate everything.
|
||||||
|
*
|
||||||
|
* We only want to run the post index changed hook if
|
||||||
|
* we've actually changed entries, so keep track if we
|
||||||
|
* actually changed entries or not.
|
||||||
|
*/
|
||||||
int is_cache_changed = 0;
|
int is_cache_changed = 0;
|
||||||
/* Mark all entries invalid */
|
|
||||||
for (i = 0; i < istate->cache_nr; i++) {
|
for (i = 0; i < istate->cache_nr; i++) {
|
||||||
if (istate->cache[i]->ce_flags & CE_FSMONITOR_VALID) {
|
if (istate->cache[i]->ce_flags & CE_FSMONITOR_VALID) {
|
||||||
is_cache_changed = 1;
|
is_cache_changed = 1;
|
||||||
|
@ -330,7 +345,10 @@ void refresh_fsmonitor(struct index_state *istate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If we're going to check every file, ensure we save the results */
|
/*
|
||||||
|
* If we're going to check every file, ensure we save
|
||||||
|
* the results.
|
||||||
|
*/
|
||||||
if (is_cache_changed)
|
if (is_cache_changed)
|
||||||
istate->cache_changed |= FSMONITOR_CHANGED;
|
istate->cache_changed |= FSMONITOR_CHANGED;
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче