]> git.eshelyaron.com Git - emacs.git/commitdiff
New incoming-revision VC backend action
authorSean Whitton <spwhitton@spwhitton.name>
Sun, 1 Jun 2025 10:55:27 +0000 (11:55 +0100)
committerEshel Yaron <me@eshelyaron.com>
Sat, 7 Jun 2025 19:59:17 +0000 (21:59 +0200)
* 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)

lisp/vc/vc-git.el
lisp/vc/vc-hg.el
lisp/vc/vc.el

index ed71a278887c57a87b349c861e35b49d8772d9fd..e751f49f636e661692cbd4a004ef0a99c6e0e578 100644 (file)
@@ -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.
 
index 5c0758b93b2d90bf59870accf8cfb5927a9b0430..490118ad0f33e06f075ff7ed23abdac8ee1ea60f 100644 (file)
@@ -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))
index 4d756ad373b995a2851a562168d05b7a1d0b27cb..89e5e6b420fb84f3abdb631d55635f33be6d8645 100644 (file)
 ;;   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.