]> git.eshelyaron.com Git - emacs.git/commitdiff
(cherry-pick-new-commits): Only fetch once, or with prefix arg
authorEshel Yaron <me@eshelyaron.com>
Mon, 1 Jul 2024 06:39:04 +0000 (08:39 +0200)
committerEshel Yaron <me@eshelyaron.com>
Mon, 1 Jul 2024 06:43:15 +0000 (08:43 +0200)
admin/cherry.el

index 5db698da801557450f362dc02fb593b662c8d51c..0eefbbdd5e214f00cf05b8182070dc204f65a31c 100644 (file)
 (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))
 
     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)