From 1866ce5fc8eb8b3c4f013744ebc6efdf82f50ebd Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Mon, 21 Aug 2023 22:42:11 +1000 Subject: Adding functions for hmm transformers. my-cgit- functions that outputs url for revision id, branches, and files. Also updating the my-github- functions accordingly --- emacs/.emacs.d/lisp/my/my-github.el | 112 +++++++++++++++++++++++++++++++++++- 1 file changed, 111 insertions(+), 1 deletion(-) (limited to 'emacs/.emacs.d/lisp/my/my-github.el') diff --git a/emacs/.emacs.d/lisp/my/my-github.el b/emacs/.emacs.d/lisp/my/my-github.el index 2fe90fd..dfa159a 100644 --- a/emacs/.emacs.d/lisp/my/my-github.el +++ b/emacs/.emacs.d/lisp/my/my-github.el @@ -66,7 +66,117 @@ License; name; description; homepage; created at" ;;; urls with github ;; TODO: generalise the following to common forges, including -;; savannah, cgit, gitlab etc. +;; cgit, gitlab etc. +(defun my-github-revision-url (revision file remote) + "Returns the REMOTE github instance url of REVISION for FILE." + (let ((repo-url (vc-git-repository-url file remote))) + (format "%s/commit/%s" repo-url revision))) + +(defun my-github-revision-url-default (&optional revision file remote) + "Returns the REMOTE github instance url of REVISION for FILE. + +Same as `my-github-revision-url', but all params can be nil, and +sensible defaults are set first." + (setq file (or file (buffer-file-name) default-directory) + revision (or revision (vc-working-revision file))) + (my-github-revision-url revision file remote)) + +(defun my-github-branch-url (branch file remote) + "Returns the REMOTE github instance url of BRANCH containing FILE. + +https://github.com/MariaDB/server/commits/10.4" + (let ((repo-url (vc-git-repository-url file remote))) + (format "%s/commits/%s" repo-url branch))) + +(defun my-github-branch-url-default (&optional branch file remote) + "Returns the REMOTE github instance url of BRANCH containing FILE. + +Same as `my-github-branch-url', but all params can be nil, and +sensible defaults are set first." + (setq file (or file (buffer-file-name) default-directory) + branch (or branch (car (vc-git-branches)))) + (my-github-branch-url branch file remote)) + +(defun my-github-file-url (file line-no revision remote) + "Returns the REMOTE github instance url of the FILE at LINE-NO at REVISION. + +https://github.com/MariaDB/server/blob/0254eb9307f58409f856517a90109d37ef9e10c4/storage/spider/mysql-test/spider/bugfix/r/mdev_31463.result" + (let* ((repo-root (vc-git-root file)) + (path (file-relative-name file repo-root)) + (repo-url (vc-git-repository-url file remote))) + (format "%s/blob/%s/%s" repo-url revision path + (if line-no (format "#L%d" line-no) "")))) + +(defun my-github-file-url-default (&optional file line-no revision remote) + "Returns the REMOTE github instance url of the FILE at LINE-NO at REVISION. + +Same as `my-github-file-url', but all params can be nil, and +sensible defaults are set first." + (unless (setq file (or file (buffer-file-name))) + (error "Please supply a file")) + (setq revision (or revision (vc-working-revision file))) + (my-github-file-url file line-no revision remote)) + +(defun my-github-raw-file-url (file revision remote) + "Returns the REMOTE github instance url of the raw FILE at REVISION. + +https://g.ypei.me/librejs.git/plain/main_background.js?id=e2230c23e4aa7a74ea34825856acf7edd8a61e04" + (let* ((repo-root (vc-git-root file)) + (path (file-relative-name file repo-root)) + (repo-url (vc-git-repository-url file remote))) + (format "%s/raw/%s/%s" repo-url path revision))) + +(defun my-github-raw-file-url-default (&optional file revision remote) + "Returns the REMOTE github instance url of the raw FILE at REVISION. + +Same as `my-github-raw-file-url', but all params can be nil, and +sensible defaults are set first." + (unless (setq file (or file (buffer-file-name))) + (error "Please supply a file")) + (setq (revision (or revision (vc-working-revision file)))) + (my-github-raw-file-url file revision remote)) + +(defun my-github-revision-to-url (revision) + "Returns the remote github instance url of REVISION. + +Uses default remote." + (let ((file (or (buffer-file-name) default-directory))) + (my-github-revision-url revision file nil))) + +(defun my-github-file-to-url (file) + "Returns the remote github instance url of FILE. + +Uses default remote and currently checked out revision." + (let ((revision (vc-working-revision file))) + (my-github-file-url file nil revision nil))) + +(defun my-github-current-file-to-url () + "Returns the remote github instance url of the current buffer file-loc. + +Uses default remote and currently checked out revision." + (let ((file (buffer-file-name)) + (line-no (1+ (current-line))) + (revision (vc-working-revision file))) + (unless file (error "Current buffer is not associated with any file")) + (my-github-file-url file line-no revision nil))) + +(defun my-github-file-to-raw-url (file) + "Returns the remote github instance url of FILE. + +Uses default remote and currently checked out revision." + (let ((revision (vc-working-revision file))) + (my-github-raw-file-url file revision nil))) + +(defun my-github-current-file-to-raw-url () + "Returns the remote github instance url of the current buffer file. + +Uses default remote and currently checked out revision." + (let ((file (buffer-file-name)) + (revision (vc-working-revision file))) + (unless file (error "Current buffer is not associated with any file")) + (my-github-file-url file revision nil))) + +;; FIXME: remove the following redundant functions (defun my-github-revision-url (file revision) "Returns the github url of the upstream repo containing FILE at REVISION." (let ((repo-url (vc-git-repository-url file)) -- cgit v1.2.3