From 9959f2800101965e87886028c20b96a6c08e26c4 Mon Sep 17 00:00:00 2001 From: Eshel Yaron Date: Mon, 1 Jul 2024 08:39:04 +0200 Subject: [PATCH] (cherry-pick-new-commits): Only fetch once, or with prefix arg --- admin/cherry.el | 41 ++++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/admin/cherry.el b/admin/cherry.el index 5db698da801..0eefbbdd5e2 100644 --- a/admin/cherry.el +++ b/admin/cherry.el @@ -32,6 +32,10 @@ (defvar cherry-skip-list-file (expand-file-name "admin/cherry-skip-list" source-directory)) +(defvar cherry-did-fetch nil) + +(defvar cherry-upstream-commits nil) + (defun cherry--call-git (&rest args) (apply #'call-process "git" nil nil nil "-C" source-directory args)) @@ -45,22 +49,33 @@ t))) (defun cherry-upstream-commits () - (string-lines - (shell-command-to-string - (concat "git -C " source-directory - " cherry HEAD " - cherry-upstream-remote "/" cherry-upstream-branch - " | grep -vE '^-' | cut -f 2 -d ' '")) - t)) - -(defun cherry-pick-new-commits () - "Pick or skip new commits in the upstream branch." - (interactive) + (setq cherry-upstream-commits + (or cherry-upstream-commits + (string-lines + (shell-command-to-string + (concat "git -C " source-directory + " cherry HEAD " + cherry-upstream-remote "/" cherry-upstream-branch + " | grep -vE '^-' | cut -f 2 -d ' '")) + t)))) + +(defun cherry-pick-new-commits (&optional force) + "Pick or skip new commits in the upstream branch. + +With non-nil optional argument FORCE (interactively, the prefix +argument), force fetching and scanning for upstream commits even if +already done in this session." + (interactive "P") (message "Ensuring working directory is clean...") (unless (= 0 (cherry--call-git "diff-index" "--quiet" "HEAD" "--")) (user-error "Working directory is dirty, cannot start cherry picking")) - (message "Fetching from upstream...") - (cherry--call-git "fetch" cherry-upstream-remote) + (when force + (setq cherry-did-fetch nil + cherry-upstream-commits nil)) + (unless cherry-did-fetch + (message "Fetching from upstream...") + (cherry--call-git "fetch" cherry-upstream-remote) + (setq cherry-did-fetch t)) (message "Listing upstream commits...") (let ((upstream-commits (cherry-upstream-commits)) (new-commits nil) -- 2.39.2