git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 09/12] fsmonitor: refactor non-directory callback

From
Patrick Steinhardt <ps@pks.im>
Date
Feb 15, 2024, 09:32 UTC
Message-ID
<Zc3aS0Top36mf4wi@tanuki>
In-Reply-To
<a0cc4c8274c108d231816ac981781d9e3cf8fded.1707857541.git.gitgitgadget@gmail.com>
On Tue, Feb 13, 2024 at 08:52:18PM +0000, Jeff Hostetler via GitGitGadget wrote:
Show 96 quoted lines
> From: Jeff Hostetler <jeffhostetler@github.com>
> 
> Refactor the fsmonitor_refresh_callback_unqualified() code
> to try to use the _callback_slash() code and avoid having
> a custom filter in the child cache-entry scanner.
> 
> On platforms that DO NOT annotate FS events with a trailing
> slash, if we fail to find an exact match for the pathname
> in the index, we do not know if the pathname represents a
> directory or simply an untracked file.  Pretend that the pathname
> is a directory and try again before assuming it is an untracked
> file.
> 
> Signed-off-by: Jeff Hostetler <jeffhostetler@github.com>
> ---
>  fsmonitor.c | 59 +++++++++++++++++++++++++++++++----------------------
>  1 file changed, 35 insertions(+), 24 deletions(-)
> 
> diff --git a/fsmonitor.c b/fsmonitor.c
> index 73e6ac82af7..cb27bae8aa8 100644
> --- a/fsmonitor.c
> +++ b/fsmonitor.c
> @@ -287,41 +287,52 @@ static int my_callback_dir_name_hash(
>  	return nr_in_cone;
>  }
>  
> -static void fsmonitor_refresh_callback_unqualified(
> +/*
> + * The daemon sent an observed pathname without a trailing slash.
> + * (This is the normal case.)  We do not know if it is a tracked or
> + * untracked file, a sparse-directory, or a populated directory (on a
> + * platform such as Windows where FSEvents are not qualified).
> + *
> + * The pathname contains the observed case reported by the FS. We
> + * do not know it is case-correct or -incorrect.
> + *
> + * Assume it is case-correct and try an exact match.
> + *
> + * Return the number of cache-entries that we invalidated.
> + */
> +static int fsmonitor_refresh_callback_unqualified(
>  	struct index_state *istate, const char *name, int len, int pos)
>  {
> -	int i;
> -
>  	my_invalidate_untracked_cache(istate, name, len);
>  
>  	if (pos >= 0) {
>  		/*
> -		 * We have an exact match for this path and can just
> -		 * invalidate it.
> +		 * An exact match on a tracked file. We assume that we
> +		 * do not need to scan forward for a sparse-directory
> +		 * cache-entry with the same pathname, nor for a cone
> +		 * at that directory. (That is, assume no D/F conflicts.)
>  		 */
>  		istate->cache[pos]->ce_flags &= ~CE_FSMONITOR_VALID;
> +		return 1;
>  	} else {
> +		int nr_in_cone;
> +		struct strbuf work_path = STRBUF_INIT;
> +
>  		/*
> -		 * 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.".
> +		 * The negative "pos" gives us the suggested insertion
> +		 * point for the pathname (without the trailing slash).
> +		 * We need to see if there is a directory with that
> +		 * prefix, but there can be lots of pathnames between
> +		 * "foo" and "foo/" like "foo-" or "foo-bar", so we
> +		 * don't want to do our own scan.
>  		 */
> -		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;
> -		}
> +		strbuf_add(&work_path, name, len);
> +		strbuf_addch(&work_path, '/');
> +		pos = index_name_pos(istate, work_path.buf, work_path.len);
> +		nr_in_cone = fsmonitor_refresh_callback_slash(
> +			istate, work_path.buf, work_path.len, pos);
> +		strbuf_release(&work_path);
> +		return nr_in_cone;

I didn't spot any users of this return value, and Junio also mentioned this in a preceding patch for a different function. Would it make sense to introduce this return value as-needed in a later patch so that the reader isn't left wondering why it's changed now?

Patrick
Show 7 quoted lines
>  	}
>  }
>  
> -- 
> gitgitgadget
> 
> 
Previous: Jeff Hostetler via GitGitGadgetNext: Jeff Hostetler via GitGitGadget
Message 30 of 91 in “FSMonitor edge cases on case-insensitive file systems”
  1. 00/12 FSMonitor edge cases on case-insensitive file systemsJeff Hostetler via GitGitGadget, Feb 13, 2024
  2. 01/12 sparse-index: pass string length to index_file_exists()Jeff Hostetler via GitGitGadget, Feb 13, 2024
  3. Junio C HamanoFeb 13, 2024
  4. Jeff HostetlerFeb 20, 2024
  5. 02/12 name-hash: add index_dir_exists2()Jeff Hostetler via GitGitGadget, Feb 13, 2024
  6. Junio C HamanoFeb 13, 2024
  7. Jeff HostetlerFeb 20, 2024
  8. Junio C HamanoFeb 20, 2024
  9. Patrick SteinhardtFeb 15, 2024
  10. 03/12 t7527: add case-insensitve test for FSMonitorJeff Hostetler via GitGitGadget, Feb 13, 2024
  11. 04/12 fsmonitor: refactor refresh callback on directory eventsJeff Hostetler via GitGitGadget, Feb 13, 2024
  12. Patrick SteinhardtFeb 15, 2024
  13. Jeff HostetlerFeb 20, 2024
  14. Patrick SteinhardtFeb 21, 2024
  15. 05/12 fsmonitor: refactor refresh callback for non-directory eventsJeff Hostetler via GitGitGadget, Feb 13, 2024
  16. Junio C HamanoFeb 14, 2024
  17. Patrick SteinhardtFeb 15, 2024
  18. 06/12 fsmonitor: clarify handling of directory events in callbackJeff Hostetler via GitGitGadget, Feb 13, 2024
  19. Junio C HamanoFeb 14, 2024
  20. Jeff HostetlerFeb 20, 2024
  21. Junio C HamanoFeb 20, 2024
  22. Patrick SteinhardtFeb 15, 2024
  23. Jeff HostetlerFeb 20, 2024
  24. 07/12 fsmonitor: refactor untracked-cache invalidationJeff Hostetler via GitGitGadget, Feb 13, 2024
  25. Junio C HamanoFeb 14, 2024
  26. Patrick SteinhardtFeb 15, 2024
  27. 08/12 fsmonitor: support case-insensitive directory eventsJeff Hostetler via GitGitGadget, Feb 13, 2024
  28. Patrick SteinhardtFeb 15, 2024
  29. 09/12 fsmonitor: refactor non-directory callbackJeff Hostetler via GitGitGadget, Feb 13, 2024
  30. Patrick SteinhardtFeb 15, 2024
  31. 10/12 fsmonitor: support case-insensitive non-directory eventsJeff Hostetler via GitGitGadget, Feb 13, 2024
  32. 11/12 fsmonitor: refactor bit invalidation in refresh callbackJeff Hostetler via GitGitGadget, Feb 13, 2024
  33. Patrick SteinhardtFeb 15, 2024
  34. 12/12 t7527: update case-insenstive fsmonitor testJeff Hostetler via GitGitGadget, Feb 13, 2024
  35. 00/16 FSMonitor edge cases on case-insensitive file systemsJeff Hostetler via GitGitGadget, Feb 23, 2024
  36. 01/16 name-hash: add index_dir_find()Jeff Hostetler via GitGitGadget, Feb 23, 2024
  37. Junio C HamanoFeb 23, 2024
  38. 03/16 t7527: temporarily disable case-insensitive testsJeff Hostetler via GitGitGadget, Feb 23, 2024
  39. Junio C HamanoFeb 23, 2024
  40. Jeff HostetlerFeb 26, 2024
  41. 02/16 t7527: add case-insensitve test for FSMonitorJeff Hostetler via GitGitGadget, Feb 23, 2024
  42. 05/16 fsmonitor: clarify handling of directory events in callback helperJeff Hostetler via GitGitGadget, Feb 23, 2024
  43. 04/16 fsmonitor: refactor refresh callback on directory eventsJeff Hostetler via GitGitGadget, Feb 23, 2024
  44. Junio C HamanoFeb 23, 2024
  45. 06/16 fsmonitor: refactor refresh callback for non-directory eventsJeff Hostetler via GitGitGadget, Feb 23, 2024
  46. Junio C HamanoFeb 23, 2024
  47. Torsten BögershausenFeb 25, 2024
  48. Junio C HamanoFeb 25, 2024
  49. 07/16 dir: create untracked_cache_invalidate_trimmed_path()Jeff Hostetler via GitGitGadget, Feb 23, 2024
  50. Torsten BögershausenFeb 25, 2024
  51. 08/16 fsmonitor: refactor untracked-cache invalidationJeff Hostetler via GitGitGadget, Feb 23, 2024
  52. 09/16 fsmonitor: move untracked invalidation into helper functionsJeff Hostetler via GitGitGadget, Feb 23, 2024
  53. Junio C HamanoFeb 23, 2024
  54. Jeff HostetlerFeb 26, 2024
  55. 10/16 fsmonitor: return invalidated cache-entry count on directory eventJeff Hostetler via GitGitGadget, Feb 23, 2024
  56. 11/16 fsmonitor: remove custom loop from non-directory path handlerJeff Hostetler via GitGitGadget, Feb 23, 2024
  57. Junio C HamanoFeb 23, 2024
  58. 13/16 fsmonitor: trace the new invalidated cache-entry countJeff Hostetler via GitGitGadget, Feb 23, 2024
  59. Junio C HamanoFeb 23, 2024
  60. 12/16 fsmonitor: return invalided cache-entry count on non-directory eventJeff Hostetler via GitGitGadget, Feb 23, 2024
  61. Junio C HamanoFeb 23, 2024
  62. 14/16 fsmonitor: support case-insensitive eventsJeff Hostetler via GitGitGadget, Feb 23, 2024
  63. Junio C HamanoFeb 23, 2024
  64. Jeff HostetlerFeb 26, 2024
  65. Junio C HamanoFeb 26, 2024
  66. Torsten BögershausenFeb 25, 2024
  67. Jeff HostetlerFeb 26, 2024
  68. 15/16 fsmonitor: refactor bit invalidation in refresh callbackJeff Hostetler via GitGitGadget, Feb 23, 2024
  69. Junio C HamanoFeb 23, 2024
  70. 16/16 t7527: update case-insenstive fsmonitor testJeff Hostetler via GitGitGadget, Feb 23, 2024
  71. 00/14 FSMonitor edge cases on case-insensitive file systemsJeff Hostetler via GitGitGadget, Feb 26, 2024
  72. 01/14 name-hash: add index_dir_find()Jeff Hostetler via GitGitGadget, Feb 26, 2024
  73. 02/14 t7527: add case-insensitve test for FSMonitorJeff Hostetler via GitGitGadget, Feb 26, 2024
  74. 03/14 fsmonitor: refactor refresh callback on directory eventsJeff Hostetler via GitGitGadget, Feb 26, 2024
  75. 04/14 fsmonitor: clarify handling of directory events in callback helperJeff Hostetler via GitGitGadget, Feb 26, 2024
  76. 05/14 fsmonitor: refactor refresh callback for non-directory eventsJeff Hostetler via GitGitGadget, Feb 26, 2024
  77. 06/14 dir: create untracked_cache_invalidate_trimmed_path()Jeff Hostetler via GitGitGadget, Feb 26, 2024
  78. 07/14 fsmonitor: refactor untracked-cache invalidationJeff Hostetler via GitGitGadget, Feb 26, 2024
  79. 08/14 fsmonitor: move untracked-cache invalidation into helper functionsJeff Hostetler via GitGitGadget, Feb 26, 2024
  80. 09/14 fsmonitor: return invalidated cache-entry count on directory eventJeff Hostetler via GitGitGadget, Feb 26, 2024
  81. 10/14 fsmonitor: remove custom loop from non-directory path handlerJeff Hostetler via GitGitGadget, Feb 26, 2024
  82. 11/14 fsmonitor: return invalided cache-entry count on non-directory eventJeff Hostetler via GitGitGadget, Feb 26, 2024
  83. Patrick SteinhardtMar 6, 2024
  84. 12/14 fsmonitor: trace the new invalidated cache-entry countJeff Hostetler via GitGitGadget, Feb 26, 2024
  85. 13/14 fsmonitor: refactor bit invalidation in refresh callbackJeff Hostetler via GitGitGadget, Feb 26, 2024
  86. 14/14 fsmonitor: support case-insensitive eventsJeff Hostetler via GitGitGadget, Feb 26, 2024
  87. Patrick SteinhardtMar 6, 2024
  88. Junio C HamanoFeb 27, 2024
  89. Patrick SteinhardtMar 6, 2024
  90. Junio C HamanoMar 6, 2024
  91. Jeff HostetlerMar 6, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.