From 30f1e7c1e93dda496412f76f70b2f49b30407b11 Mon Sep 17 00:00:00 2001 From: Philip Kaludercic Date: Sun, 30 Oct 2022 11:43:11 +0100 Subject: Extract last source package release from local VCS data * lisp/emacs-lisp/package-vc.el (package-vc-archive-spec-alist): Unmention :release-rev (package-vc-desc->spec): Fall back on other archives if a specification is missing. (package-vc-main-file): Add new function, copying the behaviour of elpa-admin.el. (package-vc-generate-description-file): Use 'package-vc-main-file'. (package-vc-unpack): Handle special value ':last-release'. (package-vc-release-rev): Add new function using 'last-change'. (package-vc-install): Pass ':last-release' as REV instead of a release. * lisp/vc/vc-git.el (vc-git-last-change): Add Git 'last-change' implementation. * lisp/vc/vc.el (vc-default-last-change): Add default 'last-change' implementation. This attempts to replicate the behaviour of elpa-admin.el's "elpaa--get-last-release-commit". --- lisp/vc/vc-git.el | 17 +++++++++++++++++ lisp/vc/vc.el | 18 ++++++++++++++++++ 2 files changed, 35 insertions(+) (limited to 'lisp/vc') diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el index 6137ce75ce4..cd62effd08d 100644 --- a/lisp/vc/vc-git.el +++ b/lisp/vc/vc-git.el @@ -1632,6 +1632,23 @@ This requires git 1.8.4 or later, for the \"-L\" option of \"git log\"." (expand-file-name fname (vc-git-root default-directory)))) revision))))) +(defun vc-git-last-change (from to) + (vc-buffer-sync) + (let ((file (file-relative-name + (buffer-file-name) + (vc-git-root (buffer-file-name)))) + (start (line-number-at-pos from t)) + (end (line-number-at-pos to t))) + (with-temp-buffer + (when (vc-git--out-ok + "blame" "--porcelain" + (format "-L%d,%d" start end) + file) + (goto-char (point-min)) + (save-match-data + (when (looking-at "\\`\\([[:alnum:]]+\\)[[:space:]]+") + (match-string 1))))))) + ;;; TAG/BRANCH SYSTEM (declare-function vc-read-revision "vc" diff --git a/lisp/vc/vc.el b/lisp/vc/vc.el index 38209ef39ed..c8d28c144b5 100644 --- a/lisp/vc/vc.el +++ b/lisp/vc/vc.el @@ -448,6 +448,11 @@ ;; - mergebase (rev1 &optional rev2) ;; ;; Return the common ancestor between REV1 and REV2 revisions. +;; +;; - last-change (from to) +;; +;; Return the most recent revision that made a change between FROM +;; and TO. ;; TAG/BRANCH SYSTEM ;; @@ -3584,6 +3589,19 @@ it indicates a specific revision to check out." remote directory rev))) (throw 'ok res))))))) +(declare-function log-view-current-tag "log-view" (&optional pos)) +(defun vc-default-last-change (_backend from to) + "Default `last-change' implementation. +FROM and TO are used as region markers" + (save-window-excursion + (let* ((buf (window-buffer (vc-region-history from to))) + (proc (get-buffer-process buf))) + (cl-assert (processp proc)) + (while (accept-process-output proc)) + (with-current-buffer buf + (prog1 (log-view-current-tag) + (kill-buffer)))))) + ;; These things should probably be generally available -- cgit v1.2.3