Subject: bug#78855: [PATCH] Expand DIR arg on `package-vc-install-from-checkout'

From: Eli Zaretskii <[email-masked]>
Date: Sat, 21 Jun 2025 22:09:51 +0300

> From: Roi Martin <[email-masked]>
> Cc: [email-masked], [email-masked]
> Date: Sat, 21 Jun 2025 20:28:17 +0200
> 
> Eli Zaretskii <[email-masked]> writes:
> 
> >>    (interactive (let* ((dir (read-directory-name "Directory: "))
> >> -                      (base (file-name-base (directory-file-name dir))))
> >> +                      (base (file-name-base (directory-file-name (expand-file-name dir)))))
> >>                   (list dir (and current-prefix-arg
> >>                                  (read-string
> >>                                   (format-prompt "Package name" base)
> >>                                   nil nil base)))))
> >>    (package-vc--archives-initialize)
> >> -  (let* ((name (or name (file-name-base (directory-file-name dir))))
> >> +  (let* ((dir (expand-file-name dir))
> >> +         (name (or name (file-name-base (directory-file-name dir))))
> >
> > Can we avoid this duplicate call to expand-file-name in the
> > interactive invocation?
> 
> I don't think so.  If I'm not wrong, `interactive' must be located at
> top-level and be the first form in the body (not counting `declare').
> Additionally, we also want to expand the directory name when the command
> is called from Emacs Lisp.  So, I don't see how to deduplicate that
> call.

But there are ways to know if the call was interactive, right?

> In fact,
> 
>   (file-name-base (directory-file-name ...))
> 
> was already duplicated.  Maybe because of the same reason?  Any hint to
> avoid this?

It would be good to avoid that as well.  However, while file-name-base
is a very simple function that just transforms its string argument,
expand-file-name is much more complex, and can be expensive,
especially if the file name is remote.