branch: elpa/magit commit 8e7276726242ed7040a9c721a247a6d52397da95 Author: Jonas Bernoulli <jo...@bernoul.li> Commit: Jonas Bernoulli <jo...@bernoul.li>
Speed-up inserting rebase sequences --- lisp/git-rebase.el | 3 +- lisp/magit-sequence.el | 77 ++++++++++++++++++++++++++++---------------------- 2 files changed, 46 insertions(+), 34 deletions(-) diff --git a/lisp/git-rebase.el b/lisp/git-rebase.el index afe5da9806..d86b9f8c53 100644 --- a/lisp/git-rebase.el +++ b/lisp/git-rebase.el @@ -275,7 +275,8 @@ If the region is active, act on all lines touched by the region." (action-options :initarg :action-options :initform nil) (target :initarg :target :initform nil) (trailer :initarg :trailer :initform nil) - (comment-p :initarg :comment-p :initform nil))) + (comment-p :initarg :comment-p :initform nil) + (abbrev))) (defvar git-rebase-line-regexps `((commit . ,(concat diff --git a/lisp/magit-sequence.el b/lisp/magit-sequence.el index bc88ff7b5f..8be5352efb 100644 --- a/lisp/magit-sequence.el +++ b/lisp/magit-sequence.el @@ -991,36 +991,42 @@ If no such sequence is in progress, do nothing." These are ordered in that the same way they'll be sorted in the status buffer (i.e., the reverse of how they will be applied)." (let ((comment-start (or (magit-get "core.commentChar") "#")) - lines) + (commits ()) + (actions ())) (with-temp-buffer (insert-file-contents (expand-file-name "rebase-merge/git-rebase-todo" (magit-gitdir))) (while (not (eobp)) - (let ((ln (git-rebase-current-line))) - (when (oref ln action-type) - (push ln lines))) + (when-let ((obj (git-rebase-current-line))) + (push obj actions) + (when (memq (oref obj action-type) '(commit merge)) + (push obj commits))) (forward-line))) - lines)) + (let ((abbrevs + (magit-git-lines + "log" "--no-walk" "--format=%h" + (mapcar (lambda (obj) + (if (eq (oref obj action) 'merge) + (let ((options (oref obj action-options))) + (and (string-match "-[cC] \\([^ ]+\\)" options) + (match-string 1 options))) + (oref obj target))) + commits)))) + (while-let ((obj (pop commits)) + (val (pop abbrevs))) + (oset obj abbrev val))) + (nreverse actions))) (defun magit-rebase-insert-merge-sequence (onto) - (dolist (line (magit-rebase--todo)) - (with-slots (action-type action action-options target) line + (dolist (obj (magit-rebase--todo)) + (with-slots (action-type action action-options target abbrev trailer) obj (pcase action-type - ('commit - (magit-sequence-insert-commit action target 'magit-sequence-pick)) - ((or (or `exec `label) - (and `merge (guard (not action-options)))) + ((or 'commit (and 'merge (guard abbrev))) + (magit-sequence-insert-commit action target 'magit-sequence-pick + abbrev trailer)) + ((or 'exec 'label 'merge) (insert (propertize action 'font-lock-face 'magit-sequence-onto) "\s" - (propertize target 'font-lock-face 'git-rebase-label) "\n")) - ('merge - (if-let ((hash (and (string-match "-[cC] \\([^ ]+\\)" action-options) - (match-string 1 action-options)))) - (magit-insert-section (commit hash) - (magit-insert-heading - (propertize "merge" 'font-lock-face 'magit-sequence-pick) - "\s" - (magit-format-rev-summary hash) "\n")) - (error "Failed to parse merge message hash")))))) + (propertize target 'font-lock-face 'git-rebase-label) "\n"))))) (let ((dir (magit-gitdir))) (magit-sequence-insert-sequence (magit-file-line (expand-file-name "rebase-merge/stopped-sha" dir)) @@ -1053,13 +1059,15 @@ status buffer (i.e., the reverse of how they will be applied)." (defun magit-sequence-insert-sequence (stop onto &optional orig) (let ((head (magit-rev-parse "HEAD")) done) (setq onto (if onto (magit-rev-parse onto) head)) - (setq done (magit-git-lines "log" "--format=%H" (concat onto "..HEAD"))) - (when (and stop (not (member (magit-rev-parse stop) done))) + (setq done (mapcar (##split-string % "\0") + (magit-git-lines "log" "--format=%H%x00%h%x00%s" + (concat onto "..HEAD")))) + (when (and stop (not (assoc (magit-rev-parse stop) done))) (let ((id (magit-patch-id stop))) - (if-let ((matched (seq-find (##equal (magit-patch-id %) id) done))) + (if-let ((matched (car (assoc (##equal (magit-patch-id %) id) done)))) (setq stop matched) (cond - ((seq-find (##magit-rev-equal % stop) done) + ((assoc (##magit-rev-equal % stop) done) ;; The commit's testament has been executed. (magit-sequence-insert-commit "void" stop 'magit-sequence-drop)) ;; The faith of the commit is still undecided... @@ -1085,14 +1093,14 @@ status buffer (i.e., the reverse of how they will be applied)." (t "work"))) stop 'magit-sequence-part)) ;; The commit is definitely gone... - ((seq-find (##magit-rev-equal % stop) done) + ((assoc (##magit-rev-equal % stop) done) ;; ...but all of its changes are still in effect. (magit-sequence-insert-commit "poof" stop 'magit-sequence-drop)) (t ;; ...and some changes are gone and/or other changes were added. (magit-sequence-insert-commit "gone" stop 'magit-sequence-drop))) (setq stop nil)))) - (dolist (rev done) + (pcase-dolist (`(,rev ,abbrev ,msg) done) (apply #'magit-sequence-insert-commit (cond ((equal rev stop) ;; ...but its reincarnation lives on. @@ -1104,21 +1112,24 @@ status buffer (i.e., the reverse of how they will be applied)." "like") ; There are new commits. rev (if (equal rev head) 'magit-sequence-head - 'magit-sequence-stop))) + 'magit-sequence-stop) + abbrev msg)) ((equal rev head) - (list "done" rev 'magit-sequence-head)) + (list "done" rev 'magit-sequence-head abbrev msg)) (t - (list "done" rev 'magit-sequence-done))))) + (list "done" rev 'magit-sequence-done abbrev msg))))) (magit-sequence-insert-commit "onto" onto (if (equal onto head) 'magit-sequence-head 'magit-sequence-onto)))) -(defun magit-sequence-insert-commit (type hash face) +(defun magit-sequence-insert-commit (type hash face &optional abbrev msg) (magit-insert-section (commit hash) (magit-insert-heading - (propertize type 'font-lock-face face) "\s" - (magit-format-rev-summary hash) "\n"))) + (propertize type 'font-lock-face face) " " + (if abbrev + (concat (propertize abbrev 'face 'magit-hash) " " msg "\n") + (concat (magit-format-rev-summary hash) "\n"))))) ;;; _ (provide 'magit-sequence)