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

Re: [PATCH v2] fsmonitor: query watchman with right valid json

From
Junio C Hamano <gitster@pobox.com>
Date
Jun 7, 2022, 17:00 UTC
Message-ID
<xmqqmteoz9wd.fsf@gitster.g>
In-Reply-To
<20220607111419.15753-1-sluongng@gmail.com>
Son Luong Ngoc <sluongng@gmail.com> writes:
Show 11 quoted lines
> In rare circumstances where the current git index does not carry the
> last_update_token, the fsmonitor v2 hook will be invoked with an
> empty string which would caused the final rendered json to be invalid.
>
>   ["query", "/path/to/my/git/repository/", {
>           "since": ,
>           "fields": ["name"],
>           "expression": ["not", ["dirname", ".git"]]
>   }]
>
> Which will left user with the following error message
"left" -> "leave" (or "give")
Show 8 quoted lines
>   > git status
>   failed to parse command from stdin: line 2, column 13, position 67: unexpected token near ','
>   Watchman: command returned no output.
>   Falling back to scanning...
>
> Hide the "since" field in json query when "last_update_token" is empty.
>
> Co-authored-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
It looked more like Helped-by to me, but I dunno.
Show 25 quoted lines
> Signed-off-by: Son Luong Ngoc <sluongng@gmail.com>
> ---
>  templates/hooks--fsmonitor-watchman.sample | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/templates/hooks--fsmonitor-watchman.sample b/templates/hooks--fsmonitor-watchman.sample
> index 14ed0aa42d..23e856f5de 100755
> --- a/templates/hooks--fsmonitor-watchman.sample
> +++ b/templates/hooks--fsmonitor-watchman.sample
> @@ -86,12 +86,13 @@ sub watchman_query {
>  	# recency index to select candidate nodes and "fields" to limit the
>  	# output to file names only. Then we're using the "expression" term to
>  	# further constrain the results.
> +	my $last_update_line = "";
>  	if (substr($last_update_token, 0, 1) eq "c") {
>  		$last_update_token = "\"$last_update_token\"";
> +		$last_update_line = qq[\n"since": $last_update_token,];
>  	}
>  	my $query = <<"	END";
> -		["query", "$git_work_tree", {
> -			"since": $last_update_token,
> +		["query", "$git_work_tree", {$last_update_line
>  			"fields": ["name"],
>  			"expression": ["not", ["dirname", ".git"]]
>  		}]
OK.  Compared to v1, this looks much more reasonable.

This is totally unrelated to the "hide invalid since" topic, but I wonder if $git_work_tree needs a bit more careful quoting. It comes directly from get_working_dir() but can it contain say a double quote character, to make the resulting string in the variable $query not quite well formed?

Previous: Ævar Arnfjörð Bjarmason
Message 6 of 6 in “fsmonitor: query watchman with right valid json”
  1. fsmonitor: query watchman with right valid jsonSon Luong Ngoc, Jun 7, 2022
  2. Ævar Arnfjörð BjarmasonJun 7, 2022
  3. Son Luong NgocJun 7, 2022
  4. fsmonitor: query watchman with right valid jsonSon Luong Ngoc, Jun 7, 2022
  5. Ævar Arnfjörð BjarmasonJun 7, 2022
  6. Junio C HamanoJun 7, 2022

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.