branch: elpa/git-commit
commit 7b4ab4348ea9ab1022a2717c2bcada62575bf091
Author: Nicholas Vollmer <[email protected]>
Commit: Jonas Bernoulli <[email protected]>
magit--chase-links: Replace magit--straight-chase-links
Refactor function to also work with Elpaca and rename accordingly.
Closes #5171.
Re #2070.
---
lisp/magit-base.el | 28 +++++++++++++++++++---------
lisp/magit.el | 4 ++--
2 files changed, 21 insertions(+), 11 deletions(-)
diff --git a/lisp/magit-base.el b/lisp/magit-base.el
index c7bc75c025..a1c00f27d5 100644
--- a/lisp/magit-base.el
+++ b/lisp/magit-base.el
@@ -1153,19 +1153,29 @@ the %s(1) manpage.
;;; Kludges for Package Managers
-(defun magit--straight-chase-links (filename)
+(defun magit--chase-links (filename)
"Chase links in FILENAME until a name that is not a link.
-This is the same as `file-chase-links', except that it also
-handles fake symlinks that are created by the package manager
-straight.el on Windows.
+This is the same as `file-chase-links', except that it also handles
+fake symlinks that are created by some source based package managers
+\(Elpaca and Straight) on Windows.
See <https://github.com/raxod502/straight.el/issues/520>."
- (when (and (bound-and-true-p straight-symlink-emulation-mode)
- (fboundp 'straight-chase-emulated-symlink))
- (when-let ((target (straight-chase-emulated-symlink filename)))
- (unless (eq target 'broken)
- (setq filename target))))
+ (when-let*
+ ((manager (cond ((bound-and-true-p straight-symlink-mode) 'straight)
+ ((bound-and-true-p elpaca-no-symlink-mode) 'elpaca)))
+ (build (pcase manager
+ ('straight (bound-and-true-p straight-build-dir))
+ ('elpaca (bound-and-true-p elpaca-builds-directory))))
+ ((string-prefix-p build filename))
+ (repo (pcase manager
+ ('straight
+ (and (bound-and-true-p straight-base-dir)
+ (expand-file-name "repos/magit/lisp/" straight-base-dir)))
+ ('elpaca
+ (and (bound-and-true-p elpaca-repos-directory)
+ (expand-file-name "magit/lisp/"
elpaca-repos-directory))))))
+ (setq filename (expand-file-name (file-name-nondirectory filename) repo)))
(file-chase-links filename))
;;; Kludges for older Emacs versions
diff --git a/lisp/magit.el b/lisp/magit.el
index f7775994bb..5906b8d42f 100644
--- a/lisp/magit.el
+++ b/lisp/magit.el
@@ -598,7 +598,7 @@ the output in the kill ring.
'("magit.el" "magit.el.gz")))
(let ((load-suffixes (reverse load-suffixes))) ; prefer .el than .elc
(setq toplib (locate-library "magit"))))
- (setq toplib (and toplib (magit--straight-chase-links toplib)))
+ (setq toplib (and toplib (magit--chase-links toplib)))
(push toplib debug)
(when toplib
(let* ((topdir (file-name-directory toplib))
@@ -606,7 +606,7 @@ the output in the kill ring.
".git" (file-name-directory
(directory-file-name topdir))))
(static (locate-library "magit-version.el" nil (list topdir)))
- (static (and static (magit--straight-chase-links static))))
+ (static (and static (magit--chase-links static))))
(or (progn
(push 'repo debug)
(when (and (file-exists-p gitdir)