Re: [PATCH v2 06/16] fsmonitor: refactor refresh callback for non-directory events
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Feb 25, 2024, 17:24 UTC
- Message-ID
- <xmqq4jdwjw2h.fsf@gitster.g>
- In-Reply-To
- <20240225123050.GA1952@tb-raspi4>
Torsten Bögershausen <tboegi@web.de> writes:
Show 10 quoted lines
>> + pos = -pos - 1;
>> +
>> + for (i = pos; i < istate->cache_nr; i++) {
>> + if (!starts_with(istate->cache[i]->name, name))
>> + break;
>> + if ((unsigned char)istate->cache[i]->name[len] > '/')
>> + break;
>
> Hm, this covers all digits, letters, :;<=>?
> but not e.g. !+-. (and others). What do i miss ?This is scanning an in-core array of cache entries, which is sorted by name in lexicographic order, and the loop knows that files under the directory "foo", whose pathnames all share prefix "foo/", would sort between "foo.h" and "foo00", because "." sorts before "/" and "0" sorts after "/".
It is trying to find where in the array a hypothetical directory would appear, if any of the files in it existed in the array, and exiting early, taking advantage of the fact that after seeing something that sorts after a '/', it will never see an entry that shares cache[i]->name[] as a prefix.
It is not a new code in the patch, of course; merely got moved from elsewhere below.
Show 29 quoted lines
>> - /*
>> - * The path is not a tracked file -or- it is a
>> - * directory event on a platform that cannot
>> - * distinguish between file and directory events in
>> - * the event handler, such as Windows.
>> - *
>> - * Scan as if it is a directory and invalidate the
>> - * cone under it. (But remember to ignore items
>> - * between "name" and "name/", such as "name-" and
>> - * "name.".
>> - */
>> - pos = -pos - 1;
>> -
>> - for (i = pos; i < istate->cache_nr; i++) {
>> - if (!starts_with(istate->cache[i]->name, name))
>> - break;
>> - if ((unsigned char)istate->cache[i]->name[len] > '/')
>> - break;
>> - if (istate->cache[i]->name[len] == '/')
>> - istate->cache[i]->ce_flags &= ~CE_FSMONITOR_VALID;
>> - }
>> + handle_path_without_trailing_slash(istate, name, pos);
>> }
>>
>> /*
>> --
>> gitgitgadget
>>
>>