[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
feature/package+vc 98381366b5: Guess Git repositories from the URL heade
From: |
Philip Kaludercic |
Subject: |
feature/package+vc 98381366b5: Guess Git repositories from the URL header |
Date: |
Thu, 11 Aug 2022 04:54:43 -0400 (EDT) |
branch: feature/package+vc
commit 98381366b5fce7f54cd10545f051906fe9240f10
Author: Philip Kaludercic <philipk@posteo.net>
Commit: Philip Kaludercic <philipk@posteo.net>
Guess Git repositories from the URL header
* package-vc.el (package-vc-probable-repository-regexp): Add new user
option.
(package-vc-sourced-packages-list): Add new function using
'package-vc-probable-repository-regexp'.
(package-vc-fetch): Use 'package-vc-sourced-packages-list'.
---
lisp/emacs-lisp/package-vc.el | 45 +++++++++++++++++++++++++++++++++++++++----
1 file changed, 41 insertions(+), 4 deletions(-)
diff --git a/lisp/emacs-lisp/package-vc.el b/lisp/emacs-lisp/package-vc.el
index a6694edc9f..bd02dcb072 100644
--- a/lisp/emacs-lisp/package-vc.el
+++ b/lisp/emacs-lisp/package-vc.el
@@ -48,6 +48,25 @@
:group 'package
:version "29.1")
+(defcustom package-vc-probable-repository-regexp
+ (rx bos "http" (? "s") "://"
+ (or (: (? "www.") "github.com"
+ "/" (+ (or alnum "-" "." "_"))
+ "/" (+ (or alnum "-" "." "_")))
+ (: "codeberg.org"
+ "/" (+ (or alnum "-" "." "_"))
+ "/" (+ (or alnum "-" "." "_")))
+ (: (? "www.") "gitlab" (+ "." (+ alnum))
+ "/" (+ (or alnum "-" "." "_"))
+ "/" (+ (or alnum "-" "." "_")))
+ (: "git.sr.ht"
+ "/~" (+ (or alnum "-" "." "_"))
+ "/" (+ (or alnum "-" "." "_"))))
+ (or (? "/") ".git") eos)
+ "Regular expression matching URLs that are repositories."
+ :version "29.1"
+ :type 'regex)
+
(defun package-vc-commit (pkg)
"Extract the commit of a development package PKG."
(cl-assert (eq (package-desc-kind pkg) 'vc))
@@ -177,6 +196,27 @@ The output is written out into PKG-FILE."
;; `activate-1', so that we use the byte-compiled definitions.
(package--reload-previously-loaded new-desc)))))
+(defun package-vc-sourced-packages-list ()
+ "Generate a list of packages with VC data."
+ (seq-filter
+ (lambda (pkg)
+ (let ((extras (package-desc-extras (cadr pkg))))
+ (or (alist-get :vc extras)
+ ;; If we have no explicit VC data, we can try a kind of
+ ;; heuristic and use the URL header, that might already be
+ ;; pointing towards a repository, and use that as a backup
+ (and-let* ((url (alist-get :url extras))
+ ((string-match-p package-vc-probable-repository-regexp
+ url)))
+ ;; XXX: Currently `package-vc-probable-repository-regexp'
+ ;; only contains Git repositories, so we can infer the
+ ;; repository type. This might work for now, but is not a
+ ;; particularly resilient approach.
+ (setf (alist-get :vc (package-desc-extras (cadr pkg)))
+ (list 'Git url))
+ t))))
+ package-archive-contents))
+
(defun package-vc-fetch (name-or-url &optional name rev)
"Fetch the source of NAME-OR-URL.
If NAME-OR-URL is a URL, then the package will be downloaded from
@@ -191,10 +231,7 @@ be requested using REV."
;; Initialize the package system to get the list of package
;; symbols for completion.
(package--archives-initialize)
- (let* ((packages (seq-filter
- (lambda (pkg)
- (alist-get :vc (package-desc-extras (cadr pkg))))
- package-archive-contents))
+ (let* ((packages (package-vc-sourced-packages-list))
(input (completing-read
"Fetch package source (name or URL): " packages))
(name (file-name-base input)))
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- feature/package+vc 98381366b5: Guess Git repositories from the URL header,
Philip Kaludercic <=