Skip to content

Commit

Permalink
forge--split-forge-url: Fix handling of ssh host aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
tarsius committed Aug 13, 2024
1 parent 5073184 commit 2f5e03f
Showing 1 changed file with 32 additions and 18 deletions.
50 changes: 32 additions & 18 deletions lisp/forge-core.el
Original file line number Diff line number Diff line change
Expand Up @@ -246,25 +246,39 @@ is non-nil."
(and demand
(error "No entry for \"%s\" in `forge-alist'" host))))

(defun forge--split-forge-url (url)
(defun forge--split-forge-url (url &optional relax)
(save-match-data
(and (string-match
(concat "\\`"
"\\(?:git://\\|"
"[^/@]+@\\|"
"\\(?:ssh\\|ssh\\+git\\|git\\+ssh\\)://\\(?:[^/@]+@\\)?\\|"
"https?://\\(?:[^/@]+@\\)?\\)?"
(regexp-opt (mapcar #'car forge-alist) t)
"\\(?::[0-9]+\\)?"
"\\(?:/\\|:/?\\)"
"~?\\(.+?\\)/"
"\\([^/]+?\\)"
"\\(?:\\.git\\|/\\)?"
"\\'")
url)
(list (caddr (forge--get-forge-host (match-string 1 url) t))
(match-string 2 url)
(match-string 3 url)))))
(cond
((string-match
(concat "\\`"
"\\(?:git://\\|"
"[^/@]+@\\|"
"\\(?:ssh\\|ssh\\+git\\|git\\+ssh\\)://\\(?:[^/@]+@\\)?\\|"
"https?://\\(?:[^/@]+@\\)?\\)?"
(if relax
"\\(?1:[^:/]+\\)"
(regexp-opt (mapcar #'car forge-alist) t))
"\\(?::[0-9]+\\)?"
"\\(?:/\\|:/?\\)"
"~?\\(?2:.+?\\)/"
"\\(?3:[^/]+?\\)"
"\\(?:\\.git\\|/\\)?"
"\\'")
url)
(and-let* ((elt (forge--get-forge-host (match-string 1 url) (not relax))))
;; Return the WEBHOST (not the GITHOST, URLs passed to this
;; function usually contain a GITHOST) because the IDs used to
;; identify a repository in the database are based on WEBHOSTs.
(list (caddr elt)
(match-string 2 url)
(match-string 3 url))))
((not relax)
;; The host part didn't match any GITHOST in `forge-alist', but it
;; might be a ssh host alias. We have to relax strictness; in the
;; extremely unlikely case that there is a common path between the
;; HOST and the OWNER for this forge, we would incorrectly end up
;; making that path part of the owner.
(forge--split-forge-url url t)))))

;;; Identity

Expand Down

0 comments on commit 2f5e03f

Please sign in to comment.