unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Omar Polo <op@omarpolo.com>
To: Dmitry Gutov <dgutov@yandex.ru>
Cc: 50240@debbugs.gnu.org
Subject: bug#50240: 28.0.50; incorrect handling of ignore files in project-files
Date: Sun, 29 Aug 2021 10:30:39 +0200	[thread overview]
Message-ID: <87wno48w9d.fsf@omarpolo.com> (raw)
In-Reply-To: <cb2813ae-1a05-dadd-546d-21e8c18c701f@yandex.ru>


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	other threads:[~2021-08-29  8:30 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-28 16:52 bug#50240: 28.0.50; incorrect handling of ignore files in project-files Omar Polo
2021-08-29  1:17 ` Dmitry Gutov
2021-08-29  8:30   ` Omar Polo [this message]
2021-08-30  2:22     ` Dmitry Gutov
2021-08-30  7:48       ` Omar Polo
2021-09-06  2:06         ` Dmitry Gutov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87wno48w9d.fsf@omarpolo.com \
    --to=op@omarpolo.com \
    --cc=50240@debbugs.gnu.org \
    --cc=dgutov@yandex.ru \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).