From: Sean Whitton Date: Sun, 1 Jun 2025 10:55:27 +0000 (+0100) Subject: New incoming-revision VC backend action X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=421c0890a6616c458669c2a6bb1f29f33d0bcbeb;p=emacs.git New incoming-revision VC backend action * lisp/vc/vc.el: New incoming-revision backend action (bug#62940). * lisp/vc/vc-git.el (vc-git--fetch-incoming): New function, factored out of vc-git-log-incoming. (vc-git-log-incoming): Use it. (vc-git-incoming-revision): * lisp/vc/vc-hg.el (vc-hg-incoming-revision): New functions. (cherry picked from commit 59516a75eb70296da426184b3bf22990198fd569) --- diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el index ed71a278887..e751f49f636 100644 --- a/lisp/vc/vc-git.el +++ b/lisp/vc/vc-git.el @@ -1581,29 +1581,41 @@ If LIMIT is a revision string, use it as an end-revision." ,(format "--pretty=tformat:%s" (car vc-git-root-log-format)) "--abbrev-commit" ,@(ensure-list vc-git-shortlog-switches) - ,(concat (if (string= remote-location "") + ,(concat (if (string-empty-p remote-location) "@{upstream}" remote-location) "..HEAD")))) +(defun vc-git--fetch-incoming (remote-location) + (vc-git-command nil 0 nil "fetch" + (and (not (string-empty-p remote-location)) + ;; Extract remote from "remote/branch". + (replace-regexp-in-string "/.*" "" + remote-location)))) + (defun vc-git-log-incoming (buffer remote-location) (vc-setup-buffer buffer) - (vc-git-command nil 0 nil "fetch" - (unless (string= remote-location "") - ;; `remote-location' is in format "repository/branch", - ;; so remove everything except a repository name. - (replace-regexp-in-string - "/.*" "" remote-location))) + (vc-git--fetch-incoming remote-location) (apply #'vc-git-command buffer 'async nil `("log" "--no-color" "--graph" "--decorate" "--date=short" ,(format "--pretty=tformat:%s" (car vc-git-root-log-format)) "--abbrev-commit" ,@(ensure-list vc-git-shortlog-switches) - ,(concat "HEAD.." (if (string= remote-location "") + ,(concat "HEAD.." (if (string-empty-p remote-location) "@{upstream}" remote-location))))) +(defun vc-git-incoming-revision (remote-location) + (vc-git--fetch-incoming remote-location) + (ignore-errors ; in order to return nil if no such branch + (with-output-to-string + (vc-git-command standard-output 0 nil + "log" "--max-count=1" "--pretty=format:%H" + (if (string-empty-p remote-location) + "@{upstream}" + remote-location))))) + (defun vc-git-log-search (buffer pattern) "Search the log of changes for PATTERN and output results into BUFFER. diff --git a/lisp/vc/vc-hg.el b/lisp/vc/vc-hg.el index 5c0758b93b2..490118ad0f3 100644 --- a/lisp/vc/vc-hg.el +++ b/lisp/vc/vc-hg.el @@ -1452,13 +1452,26 @@ This runs the command \"hg summary\"." (defun vc-hg-log-incoming (buffer remote-location) (vc-setup-buffer buffer) - (vc-hg-command buffer 1 nil "incoming" "-n" (unless (string= remote-location "") - remote-location))) + (vc-hg-command buffer 1 nil "incoming" "-n" + (and (not (string-empty-p remote-location)) + remote-location))) + +(defun vc-hg-incoming-revision (remote-location) + (let ((output (with-output-to-string + ;; Exits 1 to mean nothing to pull. + (vc-hg-command standard-output 1 nil + "incoming" "-qn" "--limit=1" + "--template={node}" + (and (not (string-empty-p remote-location)) + remote-location))))) + (and (not (string-empty-p output)) + output))) (defun vc-hg-log-outgoing (buffer remote-location) (vc-setup-buffer buffer) - (vc-hg-command buffer 1 nil "outgoing" "-n" (unless (string= remote-location "") - remote-location))) + (vc-hg-command buffer 1 nil "outgoing" "-n" + (and (not (string-empty-p remote-location)) + remote-location))) (defvar vc-hg-error-regexp-alist '(("^M \\(.+\\)" 1 nil nil 0)) diff --git a/lisp/vc/vc.el b/lisp/vc/vc.el index 4d756ad373b..89e5e6b420f 100644 --- a/lisp/vc/vc.el +++ b/lisp/vc/vc.el @@ -354,6 +354,12 @@ ;; Insert in BUFFER the revision log for the changes that will be ;; received when performing a pull operation from REMOTE-LOCATION. ;; +;; * incoming-revision (remote-location) +;; +;; Return revision at the head of the branch at REMOTE-LOCATION. +;; If there is no such branch there, return nil. (Should signal an +;; error, not return nil, in the case that fetching data fails.) +;; ;; - log-search (buffer pattern) ;; ;; Search for PATTERN in the revision log and output results into BUFFER.