Function: magit-pop-revision-stack

magit-pop-revision-stack is an autoloaded, interactive and byte-compiled function defined in magit-extras.el.

Signature

(magit-pop-revision-stack REV TOPLEVEL)

Documentation

Insert a representation of a revision into the current buffer.

Pop a revision from the magit-revision-stack and insert it into the current buffer according to magit-pop-revision-stack-format. Revisions can be put on the stack using magit-copy-section-value and magit-copy-buffer-revision.

If the stack is empty or with a prefix argument, instead read a revision in the minibuffer. By using the minibuffer history this allows selecting an item which was popped earlier or to insert an arbitrary reference or revision without first pushing it onto the stack.

When reading the revision from the minibuffer, then it might not be possible to guess the correct repository. When this command is called inside a repository (e.g., while composing a commit message), then that repository is used. Otherwise (e.g., while composing an email) then the repository recorded for the top element of the stack is used (even though we insert another revision). If not called inside a repository and with an empty stack, or with two prefix arguments, then read the repository in the minibuffer too.

Key Bindings

Source Code

;; Defined in ~/.emacs.d/elpa/magit-20260411.1452/magit-extras.el
;;;###autoload
(defun magit-pop-revision-stack (rev toplevel)
  "Insert a representation of a revision into the current buffer.

Pop a revision from the `magit-revision-stack' and insert it into
the current buffer according to `magit-pop-revision-stack-format'.
Revisions can be put on the stack using `magit-copy-section-value'
and `magit-copy-buffer-revision'.

If the stack is empty or with a prefix argument, instead read a
revision in the minibuffer.  By using the minibuffer history this
allows selecting an item which was popped earlier or to insert an
arbitrary reference or revision without first pushing it onto the
stack.

When reading the revision from the minibuffer, then it might not
be possible to guess the correct repository.  When this command
is called inside a repository (e.g., while composing a commit
message), then that repository is used.  Otherwise (e.g., while
composing an email) then the repository recorded for the top
element of the stack is used (even though we insert another
revision).  If not called inside a repository and with an empty
stack, or with two prefix arguments, then read the repository in
the minibuffer too."
  (interactive
    (if (or current-prefix-arg (not magit-revision-stack))
        (let ((default-directory
               (or (and (not (= (prefix-numeric-value current-prefix-arg) 16))
                        (or (magit-toplevel)
                            (cadr (car magit-revision-stack))))
                   (magit-read-repository))))
          (list (magit-read-branch-or-commit "Insert revision")
                default-directory))
      (push (caar magit-revision-stack) magit-revision-history)
      (pop magit-revision-stack)))
  (unless rev
    (user-error "Revision stack is empty"))
  (pcase-let ((`(,pnt-format ,eob-format ,idx-format)
               magit-pop-revision-stack-format))
    (let ((default-directory toplevel)
          (idx (and idx-format
                    (if (save-excursion
                          (re-search-backward idx-format nil t))
                        (number-to-string (1+ (string-to-number (match-str 1))))
                      "1")))
          (pnt-args nil)
          (eob-args nil))
      (when (listp pnt-format)
        (setq pnt-args (cdr pnt-format))
        (setq pnt-format (car pnt-format)))
      (when (listp eob-format)
        (setq eob-args (cdr eob-format))
        (setq eob-format (car eob-format)))
      (when pnt-format
        (when idx-format
          (setq pnt-format (string-replace "%N" idx pnt-format)))
        (magit-rev-insert-format pnt-format rev pnt-args)
        (delete-char -1))
      (when eob-format
        (when idx-format
          (setq eob-format (string-replace "%N" idx eob-format)))
        (save-excursion
          (goto-char (point-max))
          (skip-syntax-backward ">-")
          (beginning-of-line)
          (if (and comment-start (looking-at comment-start))
              (while (looking-at comment-start)
                (forward-line -1))
            (forward-line)
            (unless (= (current-column) 0)
              (insert ?\n)))
          (insert ?\n)
          (magit-rev-insert-format eob-format rev eob-args)
          (delete-char -1))))))