From fc8021447a1c26f6615799f023cdbf84fc24f4a2 Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Thu, 3 Jul 2025 20:21:29 +0100 Subject: [PATCH] Factor out some common code from VC incoming/outgoing functions * lisp/vc/vc.el (vc--maybe-read-remote-location) (vc--incoming-revision): New functions, factored out. (vc-log-incoming, vc-default-log-incoming, vc-log-outgoing) (vc-default-log-outgoing): Use them. (cherry picked from commit 8c6d549f6ffd623e30fef9aeb73ccb1194bcfb58) --- lisp/vc/vc.el | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/lisp/vc/vc.el b/lisp/vc/vc.el index d6c45b6f215..069fa40ea1f 100644 --- a/lisp/vc/vc.el +++ b/lisp/vc/vc.el @@ -3289,24 +3289,27 @@ The command prompts for the branch whose change log to show." (list rootdir) branch t (when (> vc-log-show-limit 0) vc-log-show-limit)))) +(defun vc--maybe-read-remote-location () + (and current-prefix-arg + (list (read-string "Remote location/branch (empty for default): ")))) + +(defun vc--incoming-revision (backend remote-location) + (or (vc-call-backend backend 'incoming-revision remote-location) + (user-error "No incoming revision -- local-only branch?"))) + ;;;###autoload (defun vc-log-incoming (&optional remote-location) "Show log of changes that will be received with pull from REMOTE-LOCATION. When called interactively with a prefix argument, prompt for REMOTE-LOCATION. In some version control systems REMOTE-LOCATION can be a remote branch name." - (interactive - (when current-prefix-arg - (list (read-string "Remote location/branch (empty for default): ")))) + (interactive (vc--maybe-read-remote-location)) (vc--with-backend-in-rootdir "VC root-log" (vc-incoming-outgoing-internal backend (or remote-location "") "*vc-incoming*" 'log-incoming))) (defun vc-default-log-incoming (_backend buffer remote-location) (vc--with-backend-in-rootdir "" - (let ((incoming (or (vc-call-backend backend - 'incoming-revision - remote-location) - (user-error "No incoming revision -- local-only branch?")))) + (let ((incoming (vc--incoming-revision backend remote-location))) (vc-call-backend backend 'print-log (list rootdir) buffer t incoming (vc-call-backend backend 'mergebase incoming))))) @@ -3316,19 +3319,14 @@ In some version control systems REMOTE-LOCATION can be a remote branch name." "Show log of changes that will be sent with a push operation to REMOTE-LOCATION. When called interactively with a prefix argument, prompt for REMOTE-LOCATION. In some version control systems REMOTE-LOCATION can be a remote branch name." - (interactive - (when current-prefix-arg - (list (read-string "Remote location/branch (empty for default): ")))) + (interactive (vc--maybe-read-remote-location)) (vc--with-backend-in-rootdir "VC root-log" (vc-incoming-outgoing-internal backend (or remote-location "") "*vc-outgoing*" 'log-outgoing))) (defun vc-default-log-outgoing (_backend buffer remote-location) (vc--with-backend-in-rootdir "" - (let ((incoming (or (vc-call-backend backend - 'incoming-revision - remote-location) - (user-error "No incoming revision -- local-only branch?")))) + (let ((incoming (vc--incoming-revision backend remote-location))) (vc-call-backend backend 'print-log (list rootdir) buffer t "" (vc-call-backend backend 'mergebase incoming))))) -- 2.39.5