From 9dfd724593407c1d879213c578042bd5e7f1888f Mon Sep 17 00:00:00 2001 From: Eshel Yaron Date: Wed, 19 Jun 2024 12:09:55 +0200 Subject: [PATCH] * admin/cherry.el: Optimize --- admin/cherry.el | 50 +++++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/admin/cherry.el b/admin/cherry.el index 6e567b67205..5db698da801 100644 --- a/admin/cherry.el +++ b/admin/cherry.el @@ -44,26 +44,13 @@ " HEAD")) t))) -(defun cherry-picked-p (commit merge-base) - (car - (string-lines - (shell-command-to-string - (concat "git -C " source-directory - " log -1 --pretty=%H --grep='(cherry picked from commit " - commit - ")' " - merge-base "..HEAD")) - t))) - -(defun cherry-skipped-p (commit) - (= 0 (call-process "grep" cherry-skip-list-file nil nil - "-q" "-E" (concat "^" commit)))) - (defun cherry-upstream-commits () (string-lines (shell-command-to-string (concat "git -C " source-directory - " cherry HEAD upstream/master | grep -vE '^-' | cut -f 2 -d ' '")) + " cherry HEAD " + cherry-upstream-remote "/" cherry-upstream-branch + " | grep -vE '^-' | cut -f 2 -d ' '")) t)) (defun cherry-pick-new-commits () @@ -74,14 +61,29 @@ (user-error "Working directory is dirty, cannot start cherry picking")) (message "Fetching from upstream...") (cherry--call-git "fetch" cherry-upstream-remote) - (message "Checking for new commits...") - (let* ((merge-base (cherry-merge-base)) - (new-commits - (seq-remove - (lambda (commit) - (or (cherry-picked-p commit merge-base) - (cherry-skipped-p commit))) - (cherry-upstream-commits)))) + (message "Listing upstream commits...") + (let ((upstream-commits (cherry-upstream-commits)) + (new-commits nil) + (old-commits (make-hash-table :test 'equal))) + (message "Reading skip list...") + (dolist (line (with-temp-buffer + (insert-file-contents cherry-skip-list-file) + (split-string (buffer-string) "\n" t))) + (puthash (substring line 0 40) t old-commits)) + (message "Finding picked commits...") + (dolist (commit + (string-lines + (shell-command-to-string + (concat "git -C " source-directory + " log --grep '(cherry picked from commit' " + (cherry-merge-base) "..HEAD" + " | grep '(cherry picked from commit' | sed -e 's/^.*commit \\(.*\\)).*$/\\1/g'")) + t)) + (puthash commit t old-commits)) + (dolist-with-progress-reporter (commit upstream-commits) + "Checking for new commits" + (or (gethash commit old-commits) (push commit new-commits))) + (setq new-commits (nreverse new-commits)) (if (null new-commits) (message "No new commits.") (let ((num-new (length new-commits)) -- 2.39.2