From afd1d2ec8f8f0927696da3837e076a0243a01f1a Mon Sep 17 00:00:00 2001 From: Andreas Gerler Date: Sun, 22 Dec 2024 13:00:51 +0100 Subject: [PATCH] update git-link Signed-off-by: Andreas Gerler --- elpa/git-link-20230518.204/git-link-pkg.el | 14 -- .../git-link-autoloads.el | 41 +++--- elpa/git-link-20241208.1850/git-link-pkg.el | 10 ++ .../git-link-transient.el | 128 ++++++++++++++++++ .../git-link.el | 88 ++++++++++-- 5 files changed, 240 insertions(+), 41 deletions(-) delete mode 100644 elpa/git-link-20230518.204/git-link-pkg.el rename elpa/{git-link-20230518.204 => git-link-20241208.1850}/git-link-autoloads.el (62%) create mode 100644 elpa/git-link-20241208.1850/git-link-pkg.el create mode 100644 elpa/git-link-20241208.1850/git-link-transient.el rename elpa/{git-link-20230518.204 => git-link-20241208.1850}/git-link.el (91%) diff --git a/elpa/git-link-20230518.204/git-link-pkg.el b/elpa/git-link-20230518.204/git-link-pkg.el deleted file mode 100644 index fac7e7e4..00000000 --- a/elpa/git-link-20230518.204/git-link-pkg.el +++ /dev/null @@ -1,14 +0,0 @@ -(define-package "git-link" "20230518.204" "Get the GitHub/Bitbucket/GitLab URL for a buffer location" - '((emacs "24.3")) - :commit "aded95807f277f30e1607313bdf9ac9a016a2305" :authors - '(("Skye Shaw" . "skye.shaw@gmail.com")) - :maintainers - '(("Skye Shaw" . "skye.shaw@gmail.com")) - :maintainer - '("Skye Shaw" . "skye.shaw@gmail.com") - :keywords - '("git" "vc" "github" "bitbucket" "gitlab" "sourcehut" "aws" "azure" "convenience") - :url "http://github.com/sshaw/git-link") -;; Local Variables: -;; no-byte-compile: t -;; End: diff --git a/elpa/git-link-20230518.204/git-link-autoloads.el b/elpa/git-link-20241208.1850/git-link-autoloads.el similarity index 62% rename from elpa/git-link-20230518.204/git-link-autoloads.el rename to elpa/git-link-20241208.1850/git-link-autoloads.el index e3ae51b5..a616f26d 100644 --- a/elpa/git-link-20230518.204/git-link-autoloads.el +++ b/elpa/git-link-20241208.1850/git-link-autoloads.el @@ -1,12 +1,14 @@ -;;; git-link-autoloads.el --- automatically extracted autoloads -*- lexical-binding: t -*- -;; +;;; git-link-autoloads.el --- automatically extracted autoloads (do not edit) -*- lexical-binding: t -*- +;; Generated by the `loaddefs-generate' function. + +;; This file is part of GNU Emacs. + ;;; Code: -(add-to-list 'load-path (directory-file-name - (or (file-name-directory #$) (car load-path)))) +(add-to-list 'load-path (or (and load-file-name (directory-file-name (file-name-directory load-file-name))) (car load-path))) + -;;;### (autoloads nil "git-link" "git-link.el" (0 0 0 0)) ;;; Generated autoloads from git-link.el (autoload 'git-link "git-link" "\ @@ -24,8 +26,7 @@ Defaults to \"origin\". With a double prefix argument invert the value of `git-link-use-commit'. -\(fn REMOTE START END)" t nil) - +(fn REMOTE START END)" t) (autoload 'git-link-commit "git-link" "\ Create a URL representing the commit for the hash under point in the current buffer's GitHub/Bitbucket/GitLab/... @@ -34,30 +35,36 @@ repository. The URL will be added to the kill ring. With a prefix argument prompt for the remote's name. Defaults to \"origin\". -\(fn REMOTE)" t nil) - +(fn REMOTE)" t) (autoload 'git-link-homepage "git-link" "\ Create a URL representing the homepage of the current -buffer's GitHub/Bitbucket/GitLab/... repository. The -URL will be added to the kill ring. +buffer's GitHub/Bitbucket/GitLab/... repository. The URL will be +added to the kill ring. If `git-link-open-in-browser' is non-nil +or if you pass the double prefix (Ctrl-u Ctrl-u), then also call +`browse-url'. With a prefix argument prompt for the remote's name. Defaults to \"origin\". -\(fn REMOTE)" t nil) - +(fn REMOTE)" t) (register-definition-prefixes "git-link" '("git-link-")) -;;;*** -;;;### (autoloads nil nil ("git-link-pkg.el") (0 0 0 0)) +;;; Generated autoloads from git-link-transient.el -;;;*** + (autoload 'git-link-dispatch "git-link-transient" nil t) +(register-definition-prefixes "git-link-transient" '("git-link-")) +;;; End of scraped data + +(provide 'git-link-autoloads) + ;; Local Variables: ;; version-control: never ;; no-byte-compile: t ;; no-update-autoloads: t -;; coding: utf-8 +;; no-native-compile: t +;; coding: utf-8-emacs-unix ;; End: + ;;; git-link-autoloads.el ends here diff --git a/elpa/git-link-20241208.1850/git-link-pkg.el b/elpa/git-link-20241208.1850/git-link-pkg.el new file mode 100644 index 00000000..6eeed771 --- /dev/null +++ b/elpa/git-link-20241208.1850/git-link-pkg.el @@ -0,0 +1,10 @@ +;; -*- no-byte-compile: t; lexical-binding: nil -*- +(define-package "git-link" "20241208.1850" + "Get the GitHub/Bitbucket/GitLab URL for a buffer location." + '((emacs "24.3")) + :url "https://github.com/sshaw/git-link" + :commit "40f7b1674d2c703199ff2f82b464f17aa6f61b4b" + :revdesc "40f7b1674d2c" + :keywords '("git" "vc" "github" "bitbucket" "gitlab" "sourcehut" "aws" "azure" "convenience") + :authors '(("Skye Shaw" . "skye.shaw@gmail.com")) + :maintainers '(("Skye Shaw" . "skye.shaw@gmail.com"))) diff --git a/elpa/git-link-20241208.1850/git-link-transient.el b/elpa/git-link-20241208.1850/git-link-transient.el new file mode 100644 index 00000000..13e5593a --- /dev/null +++ b/elpa/git-link-20241208.1850/git-link-transient.el @@ -0,0 +1,128 @@ +;;; git-link-transient.el --- Transient interface for git-link -*- lexical-binding: t; -*- + +;; Copyright (C) 2013-2024 Skye Shaw and others + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see . + +;;; Commentary: + +;; Transient interface (magit-like menu) for git-link. +;; Call `git-link-dispatch' to show the menu. +;; +;; You need to have `transient' installed as a dependency. +;; (it's not listed as the dependency of git-link because we want it to be optional.) + +;;; Code: + +(require 'cl-lib) +(require 'transient) +(require 'git-link) + +(defun git-link-dispatch--action () + "Finally call `git-link' with transient arguments." + (let* ((args (transient-args 'git-link-dispatch)) + (git-link-default-branch (transient-arg-value "branch=" args)) + (git-link-default-remote (transient-arg-value "remote=" args)) + (git-link-use-commit (transient-arg-value "use_commit" args)) + (git-link-use-single-line-number (transient-arg-value "line_number" args))) + (call-interactively #'git-link))) + +(defun git-link-dispatch--copy () + "The copy command in transient suffix." + (interactive) + (let ((git-link-open-in-browser nil) + (git-link-add-to-kill-ring t)) + (git-link-dispatch--action))) + +(defun git-link-dispatch--open () + "The open command in transient suffix." + (interactive) + (let ((git-link-open-in-browser t)) + (git-link-dispatch--action))) + +(defclass git-link--transient-bare-option (transient-option) () + "Similar to `transient-option', but format without argument string.") + +(cl-defmethod transient-format ((obj git-link--transient-bare-option)) + (format " %s %s (%s)" + (transient-format-key obj) + (transient-format-description obj) + (let ((v (oref obj value))) + (if (> (length v) 0) + (propertize v 'face 'transient-value) + (propertize "default" 'face 'transient-inactive-value))))) + +(defclass git-link--transient-bare-switch (transient-switch) () + "Similar to `transient-switch', but format without argument string, only yes/no.") + +(cl-defmethod transient-format ((obj git-link--transient-bare-switch)) + (format " %s %s (%s)" + (transient-format-key obj) + (transient-format-description obj) + (if (oref obj value) + (propertize "on" 'face 'transient-value) + (propertize "off" 'face 'transient-inactive-value)))) + +(transient-define-infix git-link-dispatch--branch () + :class git-link--transient-bare-option + :argument "branch=" + :description "Branch" + :prompt "Branch: " + :key "b" + :init-value (lambda (obj) (oset obj value git-link-default-branch)) + :reader (lambda (prompt &rest _) + (completing-read + prompt + (remove nil (list git-link-default-branch (git-link--branch)))))) + +(transient-define-infix git-link-dispatch--remote () + :class git-link--transient-bare-option + :argument "remote=" + :description "Remote" + :key "r" + :init-value (lambda (obj) (oset obj value git-link-default-remote)) + :reader (lambda (&rest _) (git-link--read-remote))) + +(transient-define-infix git-link-dispatch--use-commit () + :class git-link--transient-bare-switch + :argument "use_commit" + ;; the value should be "use_commit" (the argument) or nil. not t + :init-value (lambda (obj) (oset obj value (and git-link-use-commit "use_commit"))) + :description "Use commit" + :key "c") + +(transient-define-infix git-link-dispatch--line-number () + :class git-link--transient-bare-switch + :argument "line_number" + :description "Line number" + :init-value (lambda (obj) (oset obj value (and git-link-use-single-line-number "line_number"))) + :if-not 'use-region-p + :key "n") + +;;;###autoload (autoload 'git-link-dispatch "git-link-transient" nil t) +(transient-define-prefix git-link-dispatch () + "Git link dispatch." + [:description + "Options" + (git-link-dispatch--branch) + (git-link-dispatch--remote) + (git-link-dispatch--use-commit) + (git-link-dispatch--line-number)] + [:description + "Git link" + ("l" "Copy link" git-link-dispatch--copy) + ("o" "Open in browser" git-link-dispatch--open)]) + +(provide 'git-link-transient) +;;; git-link-transient.el ends here diff --git a/elpa/git-link-20230518.204/git-link.el b/elpa/git-link-20241208.1850/git-link.el similarity index 91% rename from elpa/git-link-20230518.204/git-link.el rename to elpa/git-link-20241208.1850/git-link.el index d5a6d6d4..f8535fa6 100644 --- a/elpa/git-link-20230518.204/git-link.el +++ b/elpa/git-link-20241208.1850/git-link.el @@ -2,7 +2,8 @@ ;; Copyright (C) 2013-2022 Skye Shaw and others ;; Author: Skye Shaw -;; Version: 0.9.0 +;; Package-Version: 20241208.1850 +;; Package-Revision: 40f7b1674d2c ;; Keywords: git, vc, github, bitbucket, gitlab, sourcehut, aws, azure, convenience ;; URL: http://github.com/sshaw/git-link ;; Package-Requires: ((emacs "24.3")) @@ -35,6 +36,14 @@ ;;; Change Log: +;; 2024-06-29 - v0.9.2 +;; * Add git-link-add-to-kill-ring to not add to kill ring (thanks Michael Hauser-Raspe) +;; * Add prefix arg to open in browser when calling git-link-homepage (thanks Sibi Prabakaran) +;; +;; 2024-03-03 - v0.9.1 +;; * Add support for remote host resolution via ssh config (thanks Sibi Prabakaran) +;; * Regexp escape parts when extracting host from scp-like URLs (thanks Sibi Prabakaran) +;; ;; 2023-02-15 - v0.9.0 ;; * Add support for GoogleSource (thanks Peter Becich) ;; * Add plain=1 to force showing a non rendered GitHub links (thanks Erick Navarro) @@ -199,6 +208,11 @@ function set to that function's symbol." :type '(choice boolean function) :group 'git-link) +(defcustom git-link-add-to-kill-ring t + "if t also add the link to the kill-ring" + :type 'boolean + :group 'git-link) + (defcustom git-link-use-commit nil "If non-nil use the latest commit's hash in the link instead of the branch name." :type 'boolean @@ -214,6 +228,11 @@ See its docs." :type 'boolean :group 'git-link) +(defcustom git-link-consider-ssh-config nil + "Consider ssh configuration file for resolving the remote's hostname." + :type 'boolean + :group 'git-link) + (defcustom git-link-remote-alist '(("git.sr.ht" git-link-sourcehut) ("codeberg.org" git-link-codeberg) @@ -286,6 +305,15 @@ we can prevent that behaviour." :type 'list :group 'git-link) +;; https://support.atlassian.com/bitbucket-cloud/docs/readme-content/#Extensions-and-Languages +(defcustom git-link-extensions-rendered-via-bitbucket-annotate '("org" "md" "mkd" "mkdn" "mdown" + "markdown" "text" "rst" "textile" + "asciidoc") + "List of extensions that should be rendered via annotate else +they will actually be rendered. We can prevent that behaviour." + :type 'list + :group 'git-link) + (defun git-link--exec(&rest args) (ignore-errors (with-temp-buffer @@ -431,10 +459,16 @@ return (FILENAME . REVISION) otherwise nil." (when (string-match ":" host) (let ((parts (split-string host ":" t)) (case-fold-search t)) - (string-match (concat (car parts) ":\\(" (cadr parts) "\\)/") url) + (string-match (concat (regexp-quote (car parts)) ":\\(" (cadr parts) "\\)/") url) (setq host (car parts) path (concat (match-string 1 url) "/" path)))) + + (when git-link-consider-ssh-config + (let* ((ssh-resolved-host (git-link--ssh-resolve-hostname host))) + (when ssh-resolved-host + (setq host ssh-resolved-host)))) + ;; Fix-up Azure SSH URLs (when (string= "ssh.dev.azure.com" host) (setq host "dev.azure.com") @@ -471,6 +505,15 @@ return (FILENAME . REVISION) otherwise nil." (list host path)))) +(defun git-link--ssh-resolve-hostname (hostname) + "Resolve HOSTNAME using ssh client." + (let ((output (shell-command-to-string (format "ssh -G %s" hostname))) + (host nil)) + (dolist (line (split-string output "\n")) + (when (string-match "^hostname \\(.*\\)" line) + (setq host (match-string 1 line)))) + host)) + (defun git-link--using-git-timemachine () (and (boundp 'git-timemachine-revision) git-timemachine-revision)) @@ -517,14 +560,18 @@ return (FILENAME . REVISION) otherwise nil." (list line-start line-end))))) (defun git-link--new (link) - (kill-new link) + (if git-link-add-to-kill-ring + (kill-new link)) + ;; prevent URL escapes from being interpreted as format strings (message (replace-regexp-in-string "%" "%%" link t t)) (setq deactivate-mark t) (when git-link-open-in-browser (if (fboundp git-link-open-in-browser) (funcall git-link-open-in-browser link) - (browse-url link)))) + (browse-url link))) + link + ) (defun git-link-codeberg (hostname dirname filename branch commit start end) (format "https://%s/%s/src/%s/%s" @@ -562,7 +609,7 @@ return (FILENAME . REVISION) otherwise nil." (format "L%s-L%s" start end) (format "L%s" start))))))) -(defun git-link-googlesource (hostname dirname filename branch commit start end) +(defun git-link-googlesource (hostname dirname filename branch commit start _end) (format "https://%s/%s/+/%s/%s" hostname dirname @@ -641,9 +688,10 @@ return (FILENAME . REVISION) otherwise nil." (defun git-link-bitbucket (hostname dirname filename _branch commit start end) ;; ?at=branch-name - (format "https://%s/%s/src/%s/%s" + (format "https://%s/%s/%s/%s/%s" hostname dirname + (git-link--should-render-via-bitbucket-annotate filename) commit (if (string= "" (file-name-nondirectory filename)) filename @@ -748,6 +796,9 @@ return (FILENAME . REVISION) otherwise nil." (define-obsolete-function-alias 'git-link-homepage-svannah 'git-link-homepage-savannah "cf947f9") +(defalias 'git-link-gitea 'git-link-codeberg) +(defalias 'git-link-commit-gitea 'git-link-commit-codeberg) + (defun git-link--select-remote () (if (equal '(4) current-prefix-arg) (git-link--read-remote) @@ -760,6 +811,15 @@ shown as a plain file" (let ((extension (or (file-name-extension filename) ""))) (member (downcase extension) git-link-extensions-rendered-plain))) +(defun git-link--should-render-via-bitbucket-annotate (filename) + "Check if the extension of the given filename belongs +to the list of extensions which generated link should be +shown via annotate in bitbucket." + (let ((extension (or (file-name-extension filename) ""))) + (if (member (downcase extension) git-link-extensions-rendered-via-bitbucket-annotate) + "annotate" + "src"))) + ;;;###autoload (defun git-link (remote start end) "Create a URL representing the current buffer's location in its @@ -821,7 +881,9 @@ With a double prefix argument invert the value of (not git-link-use-commit) git-link-use-commit)) nil - (url-hexify-string branch)) + (if branch + (url-hexify-string branch) + nil)) commit start end)))))))) @@ -860,14 +922,20 @@ Defaults to \"origin\"." ;;;###autoload (defun git-link-homepage (remote) "Create a URL representing the homepage of the current -buffer's GitHub/Bitbucket/GitLab/... repository. The -URL will be added to the kill ring. +buffer's GitHub/Bitbucket/GitLab/... repository. The URL will be +added to the kill ring. If `git-link-open-in-browser' is non-nil +or if you pass the double prefix (Ctrl-u Ctrl-u), then also call +`browse-url'. With a prefix argument prompt for the remote's name. Defaults to \"origin\"." (interactive (list (git-link--select-remote))) - (let* (handler remote-info (remote-url (git-link--remote-url remote))) + + (let* (handler remote-info + (remote-url (git-link--remote-url remote)) + (git-link-open-in-browser (or git-link-open-in-browser (equal (list 16) current-prefix-arg)))) + (if (null remote-url) (message "Remote `%s' not found" remote) -- 2.47.3