bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#50240: 28.0.50; incorrect handling of ignore files in project-files


From: Omar Polo
Subject: bug#50240: 28.0.50; incorrect handling of ignore files in project-files
Date: Sun, 29 Aug 2021 10:30:39 +0200
User-agent: mu4e 1.6.5; emacs 28.0.50

Dmitry Gutov <dgutov@yandex.ru> writes:

> Hi!
>
> On 28.08.2021 19:52, Omar Polo wrote:
>> Hello,
>> I'm working on a custom VC backend and noticed something strange
>> regarding the handling of ignore files in project-files: ignoring a file
>> that has the same name of the project makes project-files return nil.
>> To reproduce:
>> 1. create a directory structure as follows:
>>      mkdir /tmp/foo
>>      touch /tmp/foo/{foo,bar}
>> 2. define a trivial project:
>>      (cl-defmethod project-roots ((_ (eql foo)))
>>        '("/tmp/foo/"))
>>      (cl-defmethod project-ignores ((_ (eql foo)) _)
>>        '("foo"))
>> 3. invoke project-files
>>      (project-files 'foo)
>>      ;; => nil
>
>> This is because project--files-in-directory directory-file-name.
>> The
>> find command build is
>>      find -H /tmp/foo \( -path \*/foo \) -prune -o  -type f
>> -print0
>> and no files are found because are all pruned.
>
> It might be doing the correct thing, depending on how we define the
> exact semantics of ignores. I guess it will really depend on how this
> is going to be to fix without breaking the previous advancements. ;-)
>
> Try returning "./foo" instead of "foo". Would that work for you? Or
> does your usage require a more general fix?

Yes, with "./foo" the issue is resolved, but I think a more general fix
in project.el is warranted.

It's quite common (at least for C and Go which I use frequently) to
produce a binary in the root directory of the project with the same name
of the project, for example

        /home/op/w/foo/    <- project root
        /home/op/w/foo/foo <- the binary produced

and I expect users to have "foo" in their ignore file, not "./foo", as
they do for e.g. when using git and vc-git.

Also, if one day in the future someone decides to remove the specific
treatment of Git and Hg from project-files this issue will bite
vc-git/hg users too.

I guess I can hack something in my custom vc backend to replace an
ignore entry called "<projectname>" with "./<projectname>", but this
would probably need to be done on every vc backend, excluding git and
hg.

For the time being, I'm using the following patch, but I don't
particularly like it.


diff --git a/project.el b/project.el
index ae9bf03..176947e 100644
--- a/project.el
+++ b/project.el
@@ -302,6 +302,12 @@ to find the list of ignores for each directory."
          ;; expanded and not left for the shell command
          ;; to interpret.
          (localdir (file-name-unquote (file-local-name (expand-file-name 
dir))))
+         (projectname (file-name-nondirectory (directory-file-name dir)))
+         (ignores (mapcar (lambda (e)
+                            (if (string= projectname e)
+                                (concat "./" e)
+                              e))
+                          ignores))
          (command (format "%s -H %s %s -type f %s -print0"
                           find-program
                           (shell-quote-argument





reply via email to

[Prev in Thread] Current Thread [Next in Thread]