From fa256f11ed75b6bcf4c34443d970101cb239022e Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Mon, 1 Sep 2025 09:32:40 +0100 Subject: [PATCH] VC outgoing commands for Git: Don't unconditionally fetch * lisp/vc/vc-bzr.el (vc-bzr-incoming-revision): * lisp/vc/vc-hg.el (vc-hg-incoming-revision): * lisp/vc/vc.el (vc-diff-incoming, vc--incoming-revision): New REFRESH optional argument. (vc-default-log-incoming): Pass it. * lisp/vc/vc-git.el (vc-git-incoming-revision): New REFRESH optional argument. When nil, use cached info (bug#62940). --- lisp/vc/vc-bzr.el | 2 +- lisp/vc/vc-git.el | 29 +++++++++++++++-------------- lisp/vc/vc-hg.el | 2 +- lisp/vc/vc.el | 14 +++++++++----- 4 files changed, 26 insertions(+), 21 deletions(-) diff --git a/lisp/vc/vc-bzr.el b/lisp/vc/vc-bzr.el index f345a1b2779..fcec13cf24e 100644 --- a/lisp/vc/vc-bzr.el +++ b/lisp/vc/vc-bzr.el @@ -822,7 +822,7 @@ If LIMIT is non-nil, show no more than this many entries." (list "--theirs-only" (and (not (string-empty-p remote-location)) remote-location)))) -(defun vc-bzr-incoming-revision (remote-location) +(defun vc-bzr-incoming-revision (remote-location &optional _refresh) (with-temp-buffer (vc-bzr-command "missing" t 1 nil "--log-format=long" "--show-ids" diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el index b5da03764d1..99203402d88 100644 --- a/lisp/vc/vc-git.el +++ b/lisp/vc/vc-git.el @@ -70,7 +70,7 @@ ;; - get-change-comment (files rev) OK ;; HISTORY FUNCTIONS ;; * print-log (files buffer &optional shortlog start-revision limit) OK -;; * incoming-revision (remote-location) OK +;; * incoming-revision (remote-location &optional refresh) OK ;; - log-search (buffer pattern) OK ;; - log-view-mode () OK ;; - show-log-entry (revision) OK @@ -1605,19 +1605,20 @@ If LIMIT is a non-empty string, use it as a base revision." start-revision)) '("--"))))))) -(defun vc-git-incoming-revision (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))) - (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-incoming-revision (remote-location &optional refresh) + (let ((rev (if (string-empty-p remote-location) + "@{upstream}" + remote-location))) + (when (or refresh (null (vc-git--rev-parse rev))) + (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)))) + (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" rev))))) (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 550d13f9adc..c867da5d34f 100644 --- a/lisp/vc/vc-hg.el +++ b/lisp/vc/vc-hg.el @@ -1531,7 +1531,7 @@ This runs the command \"hg summary\"." (nreverse result)) "\n")))) -(defun vc-hg-incoming-revision (remote-location) +(defun vc-hg-incoming-revision (remote-location &optional _refresh) (let* ((remote-location (if (string-empty-p remote-location) "default" remote-location)) diff --git a/lisp/vc/vc.el b/lisp/vc/vc.el index 229ec112bed..3349231df92 100644 --- a/lisp/vc/vc.el +++ b/lisp/vc/vc.el @@ -408,13 +408,16 @@ ;; received when performing a pull operation from REMOTE-LOCATION. ;; Deprecated: implement incoming-revision and mergebase instead. ;; -;; * incoming-revision (remote-location) +;; * incoming-revision (remote-location &optional refresh) ;; ;; 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.) ;; For a distributed VCS, should also fetch that revision into local ;; storage for operating on by subsequent calls into the backend. +;; The backend may rely on cached information from a previous fetch +;; from REMOTE-LOCATION unless REFRESH is non-nil, which means that +;; the most up-to-date information possible is required. ;; ;; - log-search (buffer pattern) ;; @@ -2562,7 +2565,8 @@ global binding." (let* ((fileset (or fileset (vc-deduce-fileset t))) (backend (car fileset)) (incoming (vc--incoming-revision backend - (or remote-location "")))) + (or remote-location "") + 'refresh))) (vc-diff-internal vc-allow-async-diff fileset (vc-call-backend backend 'mergebase incoming) incoming @@ -3548,8 +3552,8 @@ The command prompts for the branch whose change log to show." (read-string "Remote location/branch (empty for default): " nil 'vc-remote-location-history))) -(defun vc--incoming-revision (backend remote-location) - (or (vc-call-backend backend 'incoming-revision remote-location) +(defun vc--incoming-revision (backend remote-location &optional refresh) + (or (vc-call-backend backend 'incoming-revision remote-location refresh) (user-error "No incoming revision -- local-only branch?"))) ;;;###autoload @@ -3565,7 +3569,7 @@ In some version control systems REMOTE-LOCATION can be a remote branch name." (defun vc-default-log-incoming (_backend buffer remote-location) (vc--with-backend-in-rootdir "" - (let ((incoming (vc--incoming-revision backend remote-location))) + (let ((incoming (vc--incoming-revision backend remote-location 'refresh))) (vc-call-backend backend 'print-log (list rootdir) buffer t incoming (vc-call-backend backend 'mergebase incoming)))))