X-Git-Url: https://git.distorted.org.uk/~mdw/stgit/blobdiff_plain/5038381d0f32d23c03b8535cccee5bbbed85570f..5ab0897e67b0203470690a11885b61ca1cb4ab8a:/contrib/stgit.el diff --git a/contrib/stgit.el b/contrib/stgit.el index ec3c1d0..7ab17a9 100644 --- a/contrib/stgit.el +++ b/contrib/stgit.el @@ -677,13 +677,13 @@ at point." (smerge-mode 1)))) (defun stgit-expand (&optional patches collapse) - "Show the contents selected patches, or the patch at point. + "Show the contents of marked patches, or the patch at point. See also `stgit-collapse'. Non-interactively, operate on PATCHES, and collapse instead of expand if COLLAPSE is not nil." - (interactive (list (stgit-patches-marked-or-at-point))) + (interactive (list (stgit-patches-marked-or-at-point t))) (stgit-assert-mode) (let ((patches-diff (funcall (if collapse #'intersection #'set-difference) patches stgit-expanded-patches))) @@ -697,10 +697,10 @@ expand if COLLAPSE is not nil." (move-to-column (stgit-goal-column))) (defun stgit-collapse (&optional patches) - "Hide the contents selected patches, or the patch at point. + "Hide the contents of marked patches, or the patch at point. See also `stgit-expand'." - (interactive (list (stgit-patches-marked-or-at-point))) + (interactive (list (stgit-patches-marked-or-at-point t))) (stgit-assert-mode) (stgit-expand patches t)) @@ -904,23 +904,25 @@ file for (applied) copies and renames." :active (stgit-patch-name-at-point nil t)] ["Rename patch" stgit-rename :active (stgit-patch-name-at-point nil t)] ["Push/pop patch" stgit-push-or-pop - :label (if (stgit-applied-at-point-p) "Pop patch" "Push patch") - :active (stgit-patch-name-at-point nil t)] - ["Delete patch" stgit-delete :active (stgit-patch-name-at-point nil t)] + :label (if (subsetp (stgit-patches-marked-or-at-point nil t) + (stgit-applied-patchsyms t)) + "Pop patches" "Push patches")] + ["Delete patches" stgit-delete + :active (stgit-patches-marked-or-at-point nil t)] "-" ["Move patches" stgit-move-patches :active stgit-marked-patches - :help "Move selected patch(es) to point"] + :help "Move marked patch(es) to point"] ["Squash patches" stgit-squash :active (> (length stgit-marked-patches) 1) - :help "Merge selected patches into one"] + :help "Merge marked patches into one"] "-" ["Refresh top patch" stgit-refresh :active (not (and (stgit-index-empty-p) (stgit-work-tree-empty-p))) :help "Refresh the top patch with changes in index or work tree"] ["Refresh this patch" (stgit-refresh t) :keys "\\[universal-argument] \\[stgit-refresh]" - :help "Refresh the patch at point with changes in index or work tree" + :help "Refresh marked patch with changes in index or work tree" :active (and (not (and (stgit-index-empty-p) (stgit-work-tree-empty-p))) (stgit-patch-name-at-point nil t))] @@ -1010,11 +1012,12 @@ Commands for patches: \\[stgit-refresh] Refresh patch with changes in index or work tree \\[stgit-diff] Show the patch log and diff -\\[stgit-expand] Show changes in selected patches -\\[stgit-collapse] Hide changes in selected patches +\\[stgit-expand] Show changes in marked patches +\\[stgit-collapse] Hide changes in marked patches -\\[stgit-new] Create a new, empty patch \\[stgit-new-and-refresh] Create a new patch from index or work tree +\\[stgit-new] Create a new, empty patch + \\[stgit-rename] Rename patch \\[stgit-edit] Edit patch description \\[stgit-delete] Delete patch(es) @@ -1024,11 +1027,11 @@ Commands for patches: \\[stgit-push-next] Push next patch onto stack \\[stgit-pop-next] Pop current patch from stack -\\[stgit-push-or-pop] Push or pop patch at point -\\[stgit-goto] Make current patch current by popping or pushing +\\[stgit-push-or-pop] Push or pop marked patches +\\[stgit-goto] Make patch at point current by popping or pushing \\[stgit-squash] Squash (meld together) patches -\\[stgit-move-patches] Move patch(es) to point +\\[stgit-move-patches] Move marked patches to point \\[stgit-commit] Commit patch(es) \\[stgit-uncommit] Uncommit patch(es) @@ -1132,14 +1135,16 @@ index or work tree." (defun stgit-patched-file-at-point () (get-text-property (point) 'file-data)) -(defun stgit-patches-marked-or-at-point () - "Return the symbols of the marked patches, or the patch on the current line." +(defun stgit-patches-marked-or-at-point (&optional cause-error only-patches) + "Return the symbols of the marked patches, or the patch on the current line. +If CAUSE-ERRROR is not nil, signal an error if none found. +If ONLY-PATCHES is not nil, do not include index or work tree." (if stgit-marked-patches stgit-marked-patches - (let ((patch (stgit-patch-name-at-point))) - (if patch - (list patch) - '())))) + (let ((patch (stgit-patch-name-at-point nil only-patches))) + (cond (patch (list patch)) + (cause-error (error "No patches marked or at this line")) + (t nil))))) (defun stgit-goto-patch (patchsym &optional file) "Move point to the line containing patch PATCHSYM. @@ -1460,20 +1465,38 @@ With numeric prefix argument, pop that many patches." (stgit-reload) (stgit-refresh-git-status)) -(defun stgit-applied-at-point-p () - "Return non-nil if the patch at point is applied." - (let ((patch (stgit-patch-at-point t))) - (not (eq (stgit-patch-status patch) 'unapplied)))) +(defun stgit-applied-patches (&optional only-patches) + "Return a list of the applied patches. + +If ONLY-PATCHES is not nil, exclude index and work tree." + (let ((states (if only-patches + '(applied top) + '(applied top index work))) + result) + (ewoc-map (lambda (patch) (when (memq (stgit-patch-status patch) states) + (setq result (cons patch result)))) + stgit-ewoc) + result)) + +(defun stgit-applied-patchsyms (&optional only-patches) + "Return a list of the symbols of the applied patches. + +If ONLY-PATCHES is not nil, exclude index and work tree." + (mapcar #'stgit-patch-name (stgit-applied-patches only-patches))) (defun stgit-push-or-pop () - "Push or pop the patch on the current line." + "Push or pop the marked patches." (interactive) (stgit-assert-mode) - (let ((patchsym (stgit-patch-name-at-point t t)) - (applied (stgit-applied-at-point-p))) + (let* ((patchsyms (stgit-patches-marked-or-at-point t t)) + (applied-syms (stgit-applied-patchsyms t)) + (unapplied (set-difference patchsyms applied-syms))) (stgit-capture-output nil - (stgit-run (if applied "pop" "push") patchsym)) - (stgit-reload))) + (apply 'stgit-run + (if unapplied "push" "pop") + "--" + (stgit-sort-patches (if unapplied unapplied patchsyms))))) + (stgit-reload)) (defun stgit-goto () "Go to the patch on the current line." @@ -1753,7 +1776,7 @@ Interactively, delete the marked patches, or the patch at point. With a prefix argument, or SPILL-P, spill the patch contents to the work tree and index." - (interactive (list (stgit-patches-marked-or-at-point) + (interactive (list (stgit-patches-marked-or-at-point t t) current-prefix-arg)) (stgit-assert-mode) (unless patchsyms @@ -1781,13 +1804,21 @@ the work tree and index." "Return the patchsym indicating a target patch for `stgit-move-patches'. -This is either the patch at point, or one of :top and :bottom, if -the point is after or before the applied patches." - - (let ((patchsym (stgit-patch-name-at-point nil t))) - (cond (patchsym patchsym) - ((save-excursion (re-search-backward "^>" nil t)) :top) - (t :bottom)))) +This is either the first unmarked patch at or after point, or one +of :top and :bottom if the point is after or before the applied +patches." + + (save-excursion + (let (result) + (while (not result) + (let ((patchsym (stgit-patch-name-at-point))) + (cond ((memq patchsym '(:work :index)) (setq result :top)) + (patchsym (if (memq patchsym stgit-marked-patches) + (stgit-next-patch) + (setq result patchsym))) + ((re-search-backward "^>" nil t) (setq result :top)) + (t (setq result :bottom))))) + result))) (defun stgit-sort-patches (patchsyms) "Returns the list of patches in PATCHSYMS sorted according to @@ -1826,20 +1857,17 @@ Interactively, move the marked patches to where the point is." (unless target-patch (error "Point not at a patch")) - (if (eq target-patch :top) - (stgit-capture-output nil - (apply 'stgit-run "float" patchsyms)) - - ;; need to have patchsyms sorted by position in the stack - (let ((sorted-patchsyms (stgit-sort-patches patchsyms))) - (while sorted-patchsyms - (setq sorted-patchsyms - (and (stgit-capture-output nil - (if (eq target-patch :bottom) - (stgit-run "sink" "--" (car sorted-patchsyms)) - (stgit-run "sink" "--to" target-patch "--" - (car sorted-patchsyms)))) - (cdr sorted-patchsyms)))))) + ;; need to have patchsyms sorted by position in the stack + (let ((sorted-patchsyms (stgit-sort-patches patchsyms))) + (stgit-capture-output nil + (if (eq target-patch :top) + (apply 'stgit-run "float" sorted-patchsyms) + (apply 'stgit-run + "sink" + (append (unless (eq target-patch :bottom) + (list "--to" target-patch)) + '("--") + sorted-patchsyms))))) (stgit-reload)) (defun stgit-squash (patchsyms) @@ -1930,13 +1958,10 @@ With prefix argument, refresh the marked patch or the patch under point." (interactive "P") (stgit-assert-mode) (let ((patchargs (if arg - (let ((patches (stgit-patches-marked-or-at-point))) - (cond ((null patches) - (error "No patch to update")) - ((> (length patches) 1) - (error "Too many patches selected")) - (t - (cons "-p" patches)))) + (let ((patches (stgit-patches-marked-or-at-point nil t))) + (when (> (length patches) 1) + (error "Too many patches marked")) + (cons "-p" patches)) nil))) (unless (stgit-index-empty-p) (setq patchargs (cons "--index" patchargs)))