Subject: Re: bug#47799: 28.0.50; Default `project-files' implementation doesn't work with quoted filenames

From: Philipp Stephani <[email-masked]>
Date: Sun, 18 Apr 2021 22:06:43 +0200

Am Fr., 16. Apr. 2021 um 03:08 Uhr schrieb Dmitry Gutov <[email-masked]>:
>
> On 15.04.2021 19:44, Philipp Stephani wrote:
> > Am Do., 15. Apr. 2021 um 18:15 Uhr schrieb Dmitry Gutov <[email-masked]>:
> >>
> >> Hi Philipp,
> >>
> >> On 15.04.2021 16:43, Philipp Stephani wrote:
> >>> emacs -Q -batch -l project -eval '(print (project-files (quote (transient . "/:/"))))'
> >>>
> >>> ("find: ‘/:/’: No such file or directory
> >>> ")
> >>>
> >>> Note that the error message is listed as a file.
> >>>
> >>> 1. `project-files' should unquote local filenames before passing them to
> >>>      `find'.
> >>>
> >>> 2. `project-files' should check for errors returned from `find'.
> >>
> >> Would you like to propose a patch?
> >
> > I've now pushed a minimal fix to this specific problem (commit
> > 157bfc1812c51a0a48162c71eadf7959f7de9ac6), but there are probably more
> > places that should get fixed, e.g. xref--find-ignores-arguments.
> > project--files-in-directory also still ignores any errors from the
> > find binary.
>
> Thank you.
>
> I've added error handling to project--files-in-directory in a follow-up
> commit.

Thanks.

>
> Regarding xref--find-ignores-arguments, it seems it would be economical
> to do the quoting on the value passed to it. See f955df1.

Since it's an internal function, this is mostly a matter of style. I
prefer using Emacs filenames as function arguments as much as
possible; it's the expected behavior for functions dealing with files,
and Emacs doesn't have a strong enough type system to distinguish
"Emacs filename" (which can be quoted or remote) from "filename for
external programs" (which must be unquoted and local).

>
> Regarding your change, though, have you tried project-find-regexp in a
> "transient" project with a quoted root directory name?
>
> You've made project--files-in-directory quote the returned file names,
> but that list gets passed to xref-matches-in-files, which pipes them to
> find-grep in the end. I suppose xref-matches-in-files could use a step
> similar to (when remote-id ...) that is already there.

Good point, I've pushed 6ebc6e12cf to fix. But xref.el should also be
fixed. Maybe I'll find some time to take a look at it.

>
> A bit unfortunate for the users of large projects with quoted names, but
> not sure what else we could do.

Quoting is a purely lexical operation which should be reasonably fast
even for a large list of files.
For truly enormous projects, something like "list of all project
files" is infeasible anyway.