Subject: bug#64088: closed (Re: bug#64088: [PATCH] Make project-root for vc projects return an absolute path)

From: [email-masked] (GNU bug Tracking System)
Date: Wed, 23 Aug 2023 00:25:02 +0000

Your bug report

#64088: [PATCH] Make project-root for vc projects return an absolute path

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
64088: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=64088
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#64088: [PATCH] Make project-root for vc projects return an absolute path
From: Dmitry Gutov <[email-masked]>
To: [email-masked]
Cc: Spencer Baugh <[email-masked]>, [email-masked]
Date: Wed, 23 Aug 2023 03:24:02 +0300
List-Id: <debbugs-submit.debbugs.gnu.org>

On 19/08/2023 15:57, [email-masked] wrote:
>>> Meaning it will be called N times (for the number of projects) every
>>> time the list is displayed, instead of just once, when the project is
>>> saved/visited. But maybe it's fine too? How slow could that be?
>> I was sad about this but I think I've got the solution now: We just
>> maintain project--list in abbreviated form and project-list-file in
>> expanded form.

Here's something else I thought of: project--write-project-list is 
called every time a different project is returned by (project-current t) 
-- i.e. when MAYBE-PROMPT=t, and when the found dir is not at the top of 
the project history already.

So under certain conditions (slow CPU/spinning media/long project 
history) it might slow down (project-current t) calls. In my testing 
it's totally fine, though, and there are possible mitigations (limit the 
history and/or move saving to kill-hook). Just something to keep in mind.

>> I think that solves all the problems: the persistent file is independent
>> of user configuration, so if the user changes their abbreviations
>> they'll get new ones the next time the file is read (presumably the next
>> time they run Emacs).  But project--list is abbreviated, so
>> project-prompt-project-dir gets abbreviated dirs.
>>
>> It does mean that if they change their directory-abbrev-alist while
>> Emacs is running they could get duplicate entries, but that already
>> could happen before this patch, and it's not a big problem IMO.
>>
>> See patch below.
> Oops, this patch needed a few tweaks.  Especially, skipping the
> expansion and abbreviation for remote files, to avoid making unnecesary
> remote connections.

Thanks! Pushed to master, and finally closing ;-)

Subject: [PATCH] Make project-root for vc projects return an absolute path
From: Spencer Baugh <[email-masked]>
To: [email-masked]
Date: Thu, 15 Jun 2023 16:48:05 -0400
List-Id: <debbugs-submit.debbugs.gnu.org>

Tags: patch

Before this, if a vc project was in the user's home directory,
project-root would be "~/some/path".  This violates the spec of
project-root, which requires an absolute path.  One concrete bug
caused by this is that (project-forget-project "~/some/path") would
work but (project-forget-project "/home/user/some/path") would not.

I ran into this while trying to use file-notify to automatically
discover and forget projects.  file-notify returns truly absolute paths,
so I ran into the aforementioned concrete bug.

In GNU Emacs 29.0.90 (build 8, x86_64-pc-linux-gnu, X toolkit, cairo
 version 1.15.12, Xaw scroll bars) of 2023-06-04 built on
 igm-qws-u22796a
Repository revision: 11d76029db5f0d9e016f247aac24dd430b729c2a
Repository branch: emacs-29
Windowing system distributor 'The X.Org Foundation', version 11.0.12011000
System Description: CentOS Linux 7 (Core)

Configured using:
 'configure --with-x-toolkit=lucid --with-gif=ifavailable'

>From 2c3ed85f857759458130a7b707d9b6f4d2c1ef20 Mon Sep 17 00:00:00 2001
From: Spencer Baugh <[email-masked]>
Date: Thu, 15 Jun 2023 16:45:48 -0400
Subject: [PATCH] Make project-root for vc projects return an absolute path

Before this, if a vc project was in the user's home directory,
project-root would be "~/some/path".  This violates the spec of
project-root, which requires an absolute path.  One concrete bug
caused by this is that (project-forget-project "~/some/path") would
work but (project-forget-project "/home/user/some/path") would not.

* lisp/progmodes/project.el (project-try-vc): Expand root directory
before returning project.
---
 lisp/progmodes/project.el | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el
index 2cffc1c0669..72cdb94bce4 100644
--- a/lisp/progmodes/project.el
+++ b/lisp/progmodes/project.el
@@ -689,7 +689,7 @@ project-try-vc
           (let* ((parent (file-name-directory (directory-file-name root))))
             (setq root (vc-call-backend 'Git 'root parent))))
         (when root
-          (setq project (list 'vc backend root))
+          (setq project (list 'vc backend (expand-file-name root)))
           ;; FIXME: Cache for a shorter time.
           (vc-file-setprop dir 'project-vc project)
           project))))
-- 
2.39.3