update packages
This commit is contained in:
@@ -1,14 +1,15 @@
|
||||
;; -*- no-byte-compile: t; lexical-binding: nil -*-
|
||||
(define-package "orgit" "20260301.1255"
|
||||
(define-package "orgit" "20260623.2148"
|
||||
"Support for Org links to Magit buffers."
|
||||
'((emacs "28.1")
|
||||
(compat "30.1")
|
||||
(cond-let "0.2")
|
||||
'((emacs "29.1")
|
||||
(compat "31.0")
|
||||
(cond-let "1.1")
|
||||
(llama "1.0")
|
||||
(magit "4.5")
|
||||
(org "9.7"))
|
||||
(org "9.8"))
|
||||
:url "https://github.com/magit/orgit"
|
||||
:commit "4fb91faff3bf32dac5f6f932654c280cd1f190f7"
|
||||
:revdesc "4fb91faff3bf"
|
||||
:commit "1aa3a27b1cb6aec913f7365caebdd6ffbe178443"
|
||||
:revdesc "1aa3a27b1cb6"
|
||||
:keywords '("hypermedia" "vc")
|
||||
:authors '(("Jonas Bernoulli" . "emacs.orgit@jonas.bernoulli.dev"))
|
||||
:maintainers '(("Jonas Bernoulli" . "emacs.orgit@jonas.bernoulli.dev")))
|
||||
|
||||
@@ -6,14 +6,15 @@
|
||||
;; Homepage: https://github.com/magit/orgit
|
||||
;; Keywords: hypermedia vc
|
||||
|
||||
;; Package-Version: 20260301.1255
|
||||
;; Package-Revision: 4fb91faff3bf
|
||||
;; Package-Version: 20260623.2148
|
||||
;; Package-Revision: 1aa3a27b1cb6
|
||||
;; Package-Requires: (
|
||||
;; (emacs "28.1")
|
||||
;; (compat "30.1")
|
||||
;; (cond-let "0.2")
|
||||
;; (emacs "29.1")
|
||||
;; (compat "31.0")
|
||||
;; (cond-let "1.1")
|
||||
;; (llama "1.0")
|
||||
;; (magit "4.5")
|
||||
;; (org "9.7"))
|
||||
;; (org "9.8"))
|
||||
|
||||
;; SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
@@ -50,11 +51,14 @@
|
||||
;; Format
|
||||
;; ------
|
||||
|
||||
;; The three link types defined here take these forms:
|
||||
;; The four link types defined here take these forms:
|
||||
;;
|
||||
;; orgit:/path/to/repo/ links to a `magit-status' buffer
|
||||
;; orgit-rev:/path/to/repo/::REV links to a `magit-revision' buffer
|
||||
;; orgit-log:/path/to/repo/::ARGS links to a `magit-log' buffer
|
||||
;; orgit-blob:/path/to/repo/::REV:path/to/file[#N[-M|,C]]
|
||||
;; links to a file- or blob-visiting buffer, optionally at
|
||||
;; a certain line and column (#N,C), or span of lines (#N-M)
|
||||
|
||||
;; Before v1.3.0 only the first revision was stored in `orgit-log'
|
||||
;; links, and all other revisions were discarded. All other arguments
|
||||
@@ -87,23 +91,20 @@
|
||||
|
||||
;; To explicitly define the web urls, use something like:
|
||||
;;
|
||||
;; git config orgit.status http://example.com/repo/overview
|
||||
;; git config orgit.rev http://example.com/repo/revision/%r
|
||||
;; git config orgit.log http://example.com/repo/history/%r
|
||||
;; git config orgit.status https://example.com/repo/overview
|
||||
;; git config orgit.rev https://example.com/repo/revision/%r
|
||||
;; git config orgit.log https://example.com/repo/history/%r
|
||||
;; git config orgit.blob https://example.com/repo/history/%r
|
||||
|
||||
;;; Code:
|
||||
|
||||
(require 'cl-lib)
|
||||
(require 'compat)
|
||||
(require 'cond-let)
|
||||
(require 'format-spec)
|
||||
(require 'llama)
|
||||
(require 'magit)
|
||||
(require 'org)
|
||||
|
||||
(unless (fboundp 'org-link-store-props)
|
||||
(defalias 'org-link-store-props 'org-store-link-props))
|
||||
|
||||
(eval-when-compile (require 'subr-x))
|
||||
(require 'seq)
|
||||
|
||||
;;; Options
|
||||
|
||||
@@ -116,39 +117,45 @@
|
||||
`(("github.com[:/]\\(.+?\\)\\(?:\\.git\\)?$"
|
||||
"https://github.com/%n"
|
||||
"https://github.com/%n/commits/%r"
|
||||
"https://github.com/%n/commit/%r")
|
||||
"https://github.com/%n/commit/%r"
|
||||
"https://github.com/%n/blob/%r/%p%C")
|
||||
("gitlab.com[:/]\\(.+?\\)\\(?:\\.git\\)?$"
|
||||
"https://gitlab.com/%n"
|
||||
"https://gitlab.com/%n/commits/%r"
|
||||
"https://gitlab.com/%n/commit/%r")
|
||||
("codeberg.org\\(/\\|:git@\\)\\(.+?\\)\\(?:\\.git\\)?$"
|
||||
"https://gitlab.com/%n/commit/%r"
|
||||
"https://gitlab.com/%n/-/blob/%r/%p%l")
|
||||
("\\(?:git@\\)?codeberg.org/\\(.+?\\)\\(?:\\.git\\)?$"
|
||||
"https://codeberg.org/%n"
|
||||
;; Redirects to commits/branch/%r.
|
||||
"https://codeberg.org/%n/commits/%r"
|
||||
"https://codeberg.org/%n/commit/%r")
|
||||
"https://codeberg.org/%n/commit/%r"
|
||||
"https://codeberg.org/%n/src/commit/%r/%p%L")
|
||||
("git.sr.ht[:/]\\(.+?\\)\\(?:\\.git\\)?$"
|
||||
"https://git.sr.ht/%n"
|
||||
"https://git.sr.ht/%n/log/%r"
|
||||
"https://git.sr.ht/%n/commit/%r")
|
||||
"https://git.sr.ht/%n/commit/%r"
|
||||
"https://git.sr.ht/%n/tree/%r/%p%l")
|
||||
("bitbucket.org[:/]\\(.+?\\)\\(?:\\.git\\)?$"
|
||||
"https://bitbucket.org/%n"
|
||||
"https://bitbucket.org/%n/commits/branch/%r"
|
||||
"https://bitbucket.org/%n/commits/%r")
|
||||
("git.kernel.org/pub/scm[:/]\\(.+\\)$"
|
||||
"https://git.kernel.org/cgit/%n"
|
||||
"https://git.kernel.org/cgit/%n/log/?h=%r"
|
||||
"https://git.kernel.org/cgit/%n/commit/?id=%r"))
|
||||
"https://bitbucket.org/%n/commits/%r"
|
||||
"https://bitbucket.org/%n/src/%r/%p%X")
|
||||
("git.kernel.org/pub/scm[:/]\\(.+?\\)\\.git$"
|
||||
"https://git.kernel.org/pub/scm/%n.git"
|
||||
"https://git.kernel.org/pub/scm/%n.git/log/?h=%r"
|
||||
"https://git.kernel.org/pub/scm/%n.git/commit/?id=%r"
|
||||
"https://git.kernel.org/pub/scm/%n.git/tree/%p?id=%r%x"))
|
||||
"Alist used to translate Git urls to web urls when exporting links.
|
||||
|
||||
Each entry has the form (REMOTE-REGEXP STATUS LOG REVISION). If
|
||||
a REMOTE-REGEXP matches the url of the chosen remote then one of
|
||||
the corresponding format strings STATUS, LOG or REVISION is used
|
||||
according to the major mode of the buffer being linked to.
|
||||
Each entry has the form (REMOTE-REGEXP STATUS LOG REVISION BLOB).
|
||||
If a REMOTE-REGEXP matches the url of the chosen remote then one
|
||||
of the corresponding format strings STATUS, LOG, REVISION or BLOB
|
||||
is used according to the major mode of the buffer being linked to.
|
||||
|
||||
The first submatch of REMOTE-REGEXP has to match the repository
|
||||
identifier (which usually consists of the username and repository
|
||||
name). The %n in the format string is replaced with that match.
|
||||
LOG and REVISION additionally have to contain %r which is
|
||||
LOG, REVISION and BLOB additionally have to contain %r which is
|
||||
replaced with the appropriate revision.
|
||||
|
||||
This can be overwritten in individual repositories using the Git
|
||||
@@ -161,7 +168,8 @@ are defined then `orgit-remote' and `orgit.remote' have no effect."
|
||||
(regexp :tag "Remote regexp")
|
||||
(string :tag "Status format")
|
||||
(string :tag "Log format" :format "%{%t%}: %v")
|
||||
(string :tag "Revision format"))))
|
||||
(string :tag "Revision format")
|
||||
(string :tag "Blob format"))))
|
||||
|
||||
(defcustom orgit-remote "origin"
|
||||
"Default remote used when exporting links.
|
||||
@@ -284,8 +292,8 @@ In that case `orgit-rev-store' stores one or more links instead."
|
||||
(magit-status-setup-buffer (orgit--repository-directory repo)))
|
||||
|
||||
;;;###autoload
|
||||
(defun orgit-status-export (path desc format)
|
||||
(orgit-export path desc format "status" 1))
|
||||
(defun orgit-status-export (path desc backend _info)
|
||||
(orgit-export path desc backend 'status))
|
||||
|
||||
;;;###autoload
|
||||
(defun orgit-status-complete-link (&optional arg)
|
||||
@@ -337,7 +345,7 @@ In that case `orgit-rev-store' stores one or more links instead."
|
||||
(magit-log-setup-buffer revs args files)))
|
||||
|
||||
;;;###autoload
|
||||
(defun orgit-log-export (path desc format)
|
||||
(defun orgit-log-export (path desc backend _info)
|
||||
(pcase-let* ((`(,repo ,args) (split-string path "::"))
|
||||
(first-branch (cond ((string-prefix-p "((" args)
|
||||
(caar (read args)))
|
||||
@@ -346,8 +354,7 @@ In that case `orgit-rev-store' stores one or more links instead."
|
||||
(args))))
|
||||
(when (string-prefix-p "--" first-branch)
|
||||
(setq first-branch nil))
|
||||
(orgit-export (concat repo "::" first-branch)
|
||||
desc format "log" 2)))
|
||||
(orgit-export (concat repo "::" first-branch) desc backend 'log)))
|
||||
|
||||
;;;###autoload
|
||||
(defun orgit-log-complete-link (&optional arg)
|
||||
@@ -427,8 +434,8 @@ store links to the Magit-Revision mode buffers for these commits."
|
||||
rev (car (magit-diff-arguments 'magit-revision-mode)) nil)))
|
||||
|
||||
;;;###autoload
|
||||
(defun orgit-rev-export (path desc format)
|
||||
(orgit-export path desc format "rev" 3))
|
||||
(defun orgit-rev-export (path desc backend _info)
|
||||
(orgit-export path desc backend 'rev))
|
||||
|
||||
;;;###autoload
|
||||
(defun orgit-rev-complete-link (&optional arg)
|
||||
@@ -437,11 +444,79 @@ store links to the Magit-Revision mode buffers for these commits."
|
||||
(orgit--current-repository)
|
||||
(magit-read-branch-or-commit "Revision"))))
|
||||
|
||||
;;; Blob
|
||||
|
||||
;;;###autoload
|
||||
(with-eval-after-load 'org
|
||||
(with-eval-after-load 'magit
|
||||
(org-link-set-parameters "orgit-blob"
|
||||
:store 'orgit-blob-store
|
||||
:follow 'orgit-blob-open
|
||||
:export 'orgit-blob-export
|
||||
:complete 'orgit-blob-complete-link)))
|
||||
|
||||
;;;###autoload
|
||||
(defun orgit-blob-store ()
|
||||
(and-let* ((file magit-buffer-file-name)
|
||||
(oid (or magit-buffer-revision-oid magit-buffer-blob-oid))
|
||||
(repo (orgit--current-repository))
|
||||
(file (file-relative-name file repo)))
|
||||
(org-link-store-props
|
||||
:type "orgit-blob"
|
||||
:link (cond ((region-active-p)
|
||||
(format "orgit-blob:%s::%s/%s#%s-%s" repo oid file
|
||||
(line-number-at-pos (region-beginning))
|
||||
(line-number-at-pos (region-end))))
|
||||
((format "orgit-blob:%s::%s/%s#%s,%s" repo oid file
|
||||
(line-number-at-pos)
|
||||
(current-column))))
|
||||
:description (format "%s:%s:%s" repo
|
||||
(magit-rev-abbrev oid)
|
||||
file))))
|
||||
|
||||
;;;###autoload
|
||||
(defun orgit-blob-open (path)
|
||||
(pcase-let* ((`(,repo ,value) (split-string path "::"))
|
||||
(`(,rev ,path ,beg ,end ,column) (orgit-blob--split value))
|
||||
(default-directory (orgit--repository-directory repo)))
|
||||
(with-current-buffer (magit-find-file rev path)
|
||||
(when beg
|
||||
(goto-char (point-min))
|
||||
(forward-line (1- beg))
|
||||
(cond (end (set-mark (point))
|
||||
(forward-line (- end beg)))
|
||||
(column (forward-char column)))))))
|
||||
|
||||
;;;###autoload
|
||||
(defun orgit-blob-export (path desc backend _info)
|
||||
(orgit-export path desc backend 'blob))
|
||||
|
||||
;;;###autoload
|
||||
(defun orgit-blob-complete-link (&optional arg)
|
||||
(let ((default-directory (magit-read-repository arg)))
|
||||
(apply #'format "orgit-blob:%s::%s"
|
||||
(orgit--current-repository)
|
||||
(magit-find-file-read-args "Find file"))))
|
||||
|
||||
(defun orgit-blob--split (value)
|
||||
(if (string-match "\\`\\([^/]+\\)/\\([^#]+\\)\
|
||||
\\(?:#\\([0-9]+\\)\\(?:\\([-,]\\)\\([0-9]+\\)\\)?\\)?\\'" value)
|
||||
(list (match-string 1 value)
|
||||
(match-string 2 value)
|
||||
(and (match-string 3 value)
|
||||
(string-to-number (match-string 3 value)))
|
||||
(and (equal (match-string 4 value) "-")
|
||||
(string-to-number (match-string 5 value)))
|
||||
(and (equal (match-string 4 value) ",")
|
||||
(string-to-number (match-string 5 value))))
|
||||
(list value)))
|
||||
|
||||
;;; Export
|
||||
|
||||
(defun orgit-export (path desc format gitvar idx)
|
||||
(defun orgit-export (path _desc backend type)
|
||||
(pcase-let* ((`(,dir ,rev) (split-string path "::"))
|
||||
(dir (orgit--repository-directory dir)))
|
||||
(dir (orgit--repository-directory dir))
|
||||
(format-n (pcase type ('status 0) ('log 1) ('rev 2) ('blob 3))))
|
||||
(cond-let*
|
||||
((not (file-exists-p dir))
|
||||
(signal 'org-link-broken
|
||||
@@ -457,38 +532,62 @@ store links to the Magit-Revision mode buffers for these commits."
|
||||
(signal 'org-link-broken
|
||||
(list (format "Cannot determine public remote for %s"
|
||||
default-directory))))
|
||||
([url (magit-get "orgit" gitvar)]
|
||||
(orgit--format-export (format-spec url `((?r . ,rev))) desc format))
|
||||
([url (magit-get "remote" remote "url")]
|
||||
[format (cl-find-if (lambda (elt)
|
||||
(string-match (car elt) url))
|
||||
orgit-export-alist)]
|
||||
(orgit--format-export (format-spec (nth idx format)
|
||||
`((?n . ,(match-string 1 url))
|
||||
(?r . ,rev)))
|
||||
desc format))
|
||||
([format (magit-get "orgit" (symbol-name type))]
|
||||
(orgit--format-export backend (orgit--format-url type format rev)))
|
||||
([git-url (magit-get "remote" remote "url")]
|
||||
[format:name (seq-some (pcase-lambda (`(,regexp . ,formats))
|
||||
(and (string-match regexp git-url)
|
||||
(cons (nth format-n formats)
|
||||
(match-string 1 git-url))))
|
||||
orgit-export-alist)]
|
||||
(orgit--format-export backend (orgit--format-url type format:name rev)))
|
||||
((signal 'org-link-broken
|
||||
(list (format "Cannot determine public url for %s" path)))))))
|
||||
|
||||
(defun orgit--format-export (link desc format)
|
||||
(pcase format
|
||||
('html (format "<a href=\"%s\">%s</a>" link desc))
|
||||
('latex (format "\\href{%s}{%s}" link desc))
|
||||
(defun orgit--format-export (backend link &optional desc)
|
||||
(pcase backend
|
||||
('html (format "<a href=\"%s\">%s</a>" link (or desc link)))
|
||||
('latex (format "\\href{%s}{%s}" link (or desc link)))
|
||||
('ascii link)
|
||||
(_ link)))
|
||||
|
||||
(defun orgit--format-url (type format value)
|
||||
(pcase-let ((`(,format . ,name)
|
||||
(if (consp format) format (list format)))
|
||||
(`(,rev ,path ,beg ,end)
|
||||
(if (eq type 'blob) (orgit-blob--split value) (list value))))
|
||||
(format-spec
|
||||
format `((?n . ,name)
|
||||
(?r . ,rev)
|
||||
(?p . ,path)
|
||||
(?l . ,(##cond (end (format "#L%s-%s" beg end))
|
||||
(beg (format "#L%s" beg))
|
||||
("")))
|
||||
(?L . ,(##cond (end (format "#L%s-L%s" beg end))
|
||||
(beg (format "#L%s" beg))
|
||||
("")))
|
||||
(?C . ,(##cond (end (format "?plain=1#L%s-L%s" beg end))
|
||||
(beg (format "?plain=1#L%s" beg))
|
||||
("")))
|
||||
(?x . ,(##cond (beg (format "#n%s" beg))
|
||||
("")))
|
||||
(?X . ,(##cond (end (format "#lines%s:%s" beg end))
|
||||
(beg (format "#lines%s" beg))
|
||||
("")))))))
|
||||
|
||||
;;; Utilities
|
||||
|
||||
(defun orgit--current-repository ()
|
||||
(or (and orgit-store-repository-id
|
||||
(car (rassoc default-directory (magit-repos-alist))))
|
||||
(abbreviate-file-name default-directory)))
|
||||
(abbreviate-file-name
|
||||
(or (and orgit-store-repository-id
|
||||
(car (rassoc default-directory (magit-repos-alist))))
|
||||
(magit-toplevel))))
|
||||
|
||||
(defun orgit--repository-directory (repo)
|
||||
(let ((dir (or (cdr (assoc repo (magit-repos-alist)))
|
||||
(file-name-as-directory (expand-file-name repo)))))
|
||||
(cond ((file-exists-p dir) dir)
|
||||
((string-match-p "\\`[./]" repo)
|
||||
((string-prefix-p "./" repo)
|
||||
(error "Cannot open link; %S does not exist" dir))
|
||||
((error "Cannot open link; no entry for %S in `%s'"
|
||||
repo 'magit-repository-directories)))))
|
||||
@@ -501,8 +600,16 @@ store links to the Magit-Revision mode buffers for these commits."
|
||||
;; (cond . 0)
|
||||
;; (interactive . 0))
|
||||
;; read-symbol-shorthands: (
|
||||
;; ("and-let" . "cond-let--and-let")
|
||||
;; ("if-let" . "cond-let--if-let")
|
||||
;; ("when-let" . "cond-let--when-let"))
|
||||
;; ("and$" . "cond-let--and$")
|
||||
;; ("thread$" . "cond-let--thread$")
|
||||
;; ("when$" . "cond-let--when$")
|
||||
;; ("and-let*" . "cond-let--and-let*")
|
||||
;; ("and-let" . "cond-let--and-let")
|
||||
;; ("if-let*" . "cond-let--if-let*")
|
||||
;; ("if-let" . "cond-let--if-let")
|
||||
;; ("when-let*" . "cond-let--when-let*")
|
||||
;; ("when-let" . "cond-let--when-let")
|
||||
;; ("while-let*" . "cond-let--while-let*")
|
||||
;; ("while-let" . "cond-let--while-let"))
|
||||
;; End:
|
||||
;;; orgit.el ends here
|
||||
|
||||
Reference in New Issue
Block a user