GNU bug report logs - #64088
[PATCH] Make project-root for vc projects return an absolute path

Previous Next

Package: emacs;

Reported by: Spencer Baugh <sbaugh <at> janestreet.com>

Date: Thu, 15 Jun 2023 20:49:02 UTC

Severity: normal

Tags: patch

Done: Dmitry Gutov <dmitry <at> gutov.dev>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Eli Zaretskii <eliz <at> gnu.org>
To: Spencer Baugh <sbaugh <at> janestreet.com>
Cc: 64088 <at> debbugs.gnu.org
Subject: bug#64088: [PATCH] Make project-root for vc projects return an absolute path
Date: Fri, 16 Jun 2023 08:52:40 +0300
> From: Spencer Baugh <sbaugh <at> janestreet.com>
> Date: Thu, 15 Jun 2023 16:48:05 -0400
> 
> 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.

File names like "~/some/file" are considered absolute in Emacs:

  (file-name-absolute-p "~/foo") => t

> 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.

That problem is simple to solve where it happens, no?  That is,
project-forget-project should try looking not just for the literal
root, but also for its expanded and abbreviated forms, and that's all.

> 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.

And please do not use "path" when you mean file names.

> >From 2c3ed85f857759458130a7b707d9b6f4d2c1ef20 Mon Sep 17 00:00:00 2001
> From: Spencer Baugh <sbaugh <at> janestreet.com>
> 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))))

I think this fixes a problem in the wrong place.  It should be fixed
where it happens, i.e. in project--remove-from-project-list.

Thanks.




This bug report was last modified 1 year and 332 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.