update of packages
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
;;; magit-process.el --- Process functionality -*- lexical-binding:t -*-
|
||||
|
||||
;; Copyright (C) 2008-2022 The Magit Project Contributors
|
||||
;; Copyright (C) 2008-2023 The Magit Project Contributors
|
||||
|
||||
;; Author: Jonas Bernoulli <jonas@bernoul.li>
|
||||
;; Maintainer: Jonas Bernoulli <jonas@bernoul.li>
|
||||
@@ -37,6 +37,8 @@
|
||||
(require 'ansi-color)
|
||||
(require 'with-editor)
|
||||
|
||||
(defvar y-or-n-p-map)
|
||||
|
||||
;;; Options
|
||||
|
||||
(defcustom magit-process-connection-type (not (eq system-type 'cygwin))
|
||||
@@ -150,13 +152,13 @@ itself from the hook, to avoid further futile attempts."
|
||||
(const :tag "Don't start a cache daemon" nil)))
|
||||
|
||||
(defcustom magit-process-yes-or-no-prompt-regexp
|
||||
(concat " [\[(]"
|
||||
(concat " [([]"
|
||||
"\\([Yy]\\(?:es\\)?\\)"
|
||||
"[/|]"
|
||||
"\\([Nn]o?\\)"
|
||||
;; OpenSSH v8 prints this. See #3969.
|
||||
"\\(?:/\\[fingerprint\\]\\)?"
|
||||
"[\])] ?[?:]? ?$")
|
||||
"[])] ?[?:]? ?$")
|
||||
"Regexp matching Yes-or-No prompts of Git and its subprocesses."
|
||||
:package-version '(magit . "2.1.0")
|
||||
:group 'magit-process
|
||||
@@ -165,7 +167,8 @@ itself from the hook, to avoid further futile attempts."
|
||||
(defcustom magit-process-password-prompt-regexps
|
||||
'("^\\(Enter \\)?[Pp]assphrase\\( for \\(RSA \\)?key '.*'\\)?: ?$"
|
||||
;; Match-group 99 is used to identify the "user@host" part.
|
||||
"^\\(Enter \\)?[Pp]assword\\( for '?\\(https?://\\)?\\(?99:[^']*\\)'?\\)?: ?$"
|
||||
"^\\(Enter \\|([^) ]+) \\)?\
|
||||
[Pp]assword\\( for '?\\(https?://\\)?\\(?99:[^']*\\)'?\\)?: ?$"
|
||||
"Please enter the passphrase for the ssh key"
|
||||
"Please enter the passphrase to unlock the OpenPGP secret key"
|
||||
"^.*'s password: ?$"
|
||||
@@ -222,7 +225,7 @@ hook allows users to deal with such questions explicitly.
|
||||
Each function is called with the process and the output string
|
||||
as arguments until one of the functions returns non-nil. The
|
||||
function is responsible for asking the user the appropriate
|
||||
question using e.g. `read-char-choice' and then forwarding the
|
||||
question using, e.g., `read-char-choice' and then forwarding the
|
||||
answer to the process using `process-send-string'.
|
||||
|
||||
While functions such as `magit-process-yes-or-no-prompt' may not
|
||||
@@ -245,6 +248,15 @@ implement such functions."
|
||||
:group 'magit-process
|
||||
:type 'boolean)
|
||||
|
||||
(defcustom magit-process-timestamp-format nil
|
||||
"Format of timestamp for each process in the process buffer.
|
||||
If non-nil, pass this to `format-time-string' when creating a
|
||||
process section in the process buffer, and insert the returned
|
||||
string in the heading of its section."
|
||||
:package-version '(magit . "4.0.0")
|
||||
:group 'magit-process
|
||||
:type '(choice (const :tag "none" nil) string))
|
||||
|
||||
(defface magit-process-ok
|
||||
'((t :inherit magit-section-heading :foreground "green"))
|
||||
"Face for zero exit-status."
|
||||
@@ -269,11 +281,10 @@ Used when `magit-process-display-mode-line-error' is non-nil."
|
||||
|
||||
;;; Process Mode
|
||||
|
||||
(defvar magit-process-mode-map
|
||||
(let ((map (make-sparse-keymap)))
|
||||
(set-keymap-parent map magit-mode-map)
|
||||
map)
|
||||
"Keymap for `magit-process-mode'.")
|
||||
(defvar-keymap magit-process-mode-map
|
||||
:doc "Keymap for `magit-process-mode'."
|
||||
:parent magit-mode-map
|
||||
"<remap> <magit-delete-thing>" #'magit-process-kill)
|
||||
|
||||
(define-derived-mode magit-process-mode magit-mode "Magit Process"
|
||||
"Mode for looking at Git process output."
|
||||
@@ -427,8 +438,8 @@ conversion."
|
||||
(cdr (assoc magit-git-executable magit-git-w32-path-hack)))
|
||||
(and local magit-need-cygwin-noglob
|
||||
(mapcar (lambda (var)
|
||||
(concat var "=" (--if-let (getenv var)
|
||||
(concat it " noglob")
|
||||
(concat var "=" (if-let ((val (getenv var)))
|
||||
(concat val " noglob")
|
||||
"noglob")))
|
||||
'("CYGWIN" "MSYS")))
|
||||
process-environment)))
|
||||
@@ -596,7 +607,12 @@ Magit status buffer."
|
||||
(when input
|
||||
(with-current-buffer input
|
||||
(process-send-region process (point-min) (point-max))
|
||||
(process-send-eof process)))
|
||||
;; `process-send-eof' appears to be broken over
|
||||
;; Tramp from Windows. See #3624 and bug#43226.
|
||||
(if (and (eq system-type 'windows-nt)
|
||||
(file-remote-p (process-get process 'default-dir) nil t))
|
||||
(process-send-string process "")
|
||||
(process-send-eof process))))
|
||||
(setq magit-this-process process)
|
||||
(oset section value process)
|
||||
(magit-process-display-buffer process)
|
||||
@@ -641,6 +657,8 @@ Magit status buffer."
|
||||
(format "%3s " (propertize (number-to-string errcode)
|
||||
'font-lock-face 'magit-process-ng))
|
||||
"run "))
|
||||
(when magit-process-timestamp-format
|
||||
(insert (format-time-string magit-process-timestamp-format) " "))
|
||||
(unless (equal (expand-file-name pwd)
|
||||
(expand-file-name default-directory))
|
||||
(insert (file-relative-name pwd default-directory) ?\s))
|
||||
@@ -657,19 +675,17 @@ Magit status buffer."
|
||||
(defun magit-process--format-arguments (program args)
|
||||
(cond
|
||||
((and args (equal program (magit-git-executable)))
|
||||
(setq args (-split-at (length magit-git-global-arguments) args))
|
||||
(concat (propertize (file-name-nondirectory program)
|
||||
'font-lock-face 'magit-section-heading)
|
||||
" "
|
||||
(propertize (if (stringp magit-ellipsis)
|
||||
magit-ellipsis
|
||||
;; For backward compatibility.
|
||||
(char-to-string magit-ellipsis))
|
||||
'font-lock-face 'magit-section-heading
|
||||
'help-echo (mapconcat #'identity (car args) " "))
|
||||
" "
|
||||
(propertize (mapconcat #'shell-quote-argument (cadr args) " ")
|
||||
'font-lock-face 'magit-section-heading)))
|
||||
(let ((global (length magit-git-global-arguments)))
|
||||
(concat
|
||||
(propertize (file-name-nondirectory program)
|
||||
'font-lock-face 'magit-section-heading)
|
||||
" "
|
||||
(propertize (magit--ellipsis)
|
||||
'font-lock-face 'magit-section-heading
|
||||
'help-echo (mapconcat #'identity (seq-take args global) " "))
|
||||
" "
|
||||
(propertize (mapconcat #'shell-quote-argument (seq-drop args global) " ")
|
||||
'font-lock-face 'magit-section-heading))))
|
||||
((and args (equal program shell-file-name))
|
||||
(propertize (cadr args)
|
||||
'font-lock-face 'magit-section-heading))
|
||||
@@ -728,16 +744,16 @@ Magit status buffer."
|
||||
(status-buf (with-current-buffer process-buf
|
||||
(magit-get-mode-buffer 'magit-status-mode))))
|
||||
(with-current-buffer status-buf
|
||||
(--when-let
|
||||
(magit-get-section
|
||||
`((commit . ,(magit-rev-parse "HEAD"))
|
||||
(,(pcase (car (cadr (-split-at
|
||||
(1+ (length magit-git-global-arguments))
|
||||
(process-command process))))
|
||||
((or "rebase" "am") 'rebase-sequence)
|
||||
((or "cherry-pick" "revert") 'sequence)))
|
||||
(status)))
|
||||
(goto-char (oref it start))
|
||||
(when-let ((section
|
||||
(magit-get-section
|
||||
`((commit . ,(magit-rev-parse "HEAD"))
|
||||
(,(pcase (car (seq-drop
|
||||
(process-command process)
|
||||
(1+ (length magit-git-global-arguments))))
|
||||
((or "rebase" "am") 'rebase-sequence)
|
||||
((or "cherry-pick" "revert") 'sequence)))
|
||||
(status)))))
|
||||
(goto-char (oref section start))
|
||||
(magit-section-update-highlight))))))
|
||||
|
||||
(defun magit-process-filter (proc string)
|
||||
@@ -750,6 +766,7 @@ Magit status buffer."
|
||||
(when-let ((ret-pos (cl-position ?\r string :from-end t)))
|
||||
(cl-callf substring string (1+ ret-pos))
|
||||
(delete-region (line-beginning-position) (point)))
|
||||
(setq string (magit-process-remove-bogus-errors string))
|
||||
(insert (propertize string 'magit-section
|
||||
(process-get proc 'section)))
|
||||
(set-marker (process-mark proc) (point))
|
||||
@@ -760,35 +777,55 @@ Magit status buffer."
|
||||
(run-hook-with-args-until-success 'magit-process-prompt-functions
|
||||
proc string))))
|
||||
|
||||
(defmacro magit-process-kill-on-abort (proc &rest body)
|
||||
(declare (indent 1) (debug (form body)))
|
||||
(let ((map (cl-gensym)))
|
||||
`(let ((,map (make-sparse-keymap)))
|
||||
(set-keymap-parent ,map minibuffer-local-map)
|
||||
;; Note: Leaving (kbd ...) unevaluated leads to the
|
||||
;; magit-process:password-prompt test failing.
|
||||
(define-key ,map ,(kbd "C-g")
|
||||
(lambda ()
|
||||
(interactive)
|
||||
(ignore-errors (kill-process ,proc))
|
||||
(abort-recursive-edit)))
|
||||
(let ((minibuffer-local-map ,map))
|
||||
,@body))))
|
||||
(defun magit-process-make-keymap (process parent)
|
||||
"Remap `abort-minibuffers' to a command that also kills PROCESS.
|
||||
PARENT is used as the parent of the returned keymap."
|
||||
(let ((cmd (lambda ()
|
||||
(interactive)
|
||||
(ignore-errors (kill-process process))
|
||||
(if (fboundp 'abort-minibuffers)
|
||||
(abort-minibuffers)
|
||||
(abort-recursive-edit)))))
|
||||
(define-keymap :parent parent
|
||||
"C-g" cmd
|
||||
"<remap> <abort-minibuffers>" cmd
|
||||
"<remap> <abort-recursive-edit>" cmd)))
|
||||
|
||||
(defmacro magit-process-kill-on-abort (process &rest body)
|
||||
(declare (indent 1)
|
||||
(debug (form body))
|
||||
(obsolete magit-process-make-keymap "Magit 4.0.0"))
|
||||
`(let ((minibuffer-local-map
|
||||
(magit-process-make-keymap ,process minibuffer-local-map)))
|
||||
,@body))
|
||||
|
||||
(defun magit-process-remove-bogus-errors (str)
|
||||
(save-match-data
|
||||
(when (string-match "^\\(\\*ERROR\\*: \\)Canceled by user" str)
|
||||
(setq str (replace-match "" nil nil str 1)))
|
||||
(when (string-match "^error: There was a problem with the editor.*\n" str)
|
||||
(setq str (replace-match "" nil nil str)))
|
||||
(when (string-match
|
||||
"^Please supply the message using either -m or -F option\\.\n" str)
|
||||
(setq str (replace-match "" nil nil str))))
|
||||
str)
|
||||
|
||||
(defun magit-process-yes-or-no-prompt (process string)
|
||||
"Forward Yes-or-No prompts to the user."
|
||||
(when-let ((beg (string-match magit-process-yes-or-no-prompt-regexp string)))
|
||||
(let ((max-mini-window-height 30))
|
||||
(process-send-string
|
||||
process
|
||||
(downcase
|
||||
(concat
|
||||
(match-string
|
||||
(if (save-match-data
|
||||
(magit-process-kill-on-abort process
|
||||
(yes-or-no-p (substring string 0 beg)))) 1 2)
|
||||
string)
|
||||
"\n"))))))
|
||||
(process-send-string
|
||||
process
|
||||
(if (save-match-data
|
||||
(let ((max-mini-window-height 30)
|
||||
(minibuffer-local-map
|
||||
(magit-process-make-keymap process minibuffer-local-map))
|
||||
;; In case yes-or-no-p is fset to that, but does
|
||||
;; not cover use-dialog-box-p and y-or-n-p-read-key.
|
||||
(y-or-n-p-map
|
||||
(magit-process-make-keymap process y-or-n-p-map)))
|
||||
(yes-or-no-p (substring string 0 beg))))
|
||||
(concat (downcase (match-string 1 string)) "\n")
|
||||
(concat (downcase (match-string 2 string)) "\n")))))
|
||||
|
||||
(defun magit-process-password-auth-source (key)
|
||||
"Use `auth-source-search' to get a password.
|
||||
@@ -869,20 +906,24 @@ from the user."
|
||||
(when-let ((prompt (magit-process-match-prompt
|
||||
magit-process-password-prompt-regexps string)))
|
||||
(process-send-string
|
||||
process (magit-process-kill-on-abort process
|
||||
(concat (or (and-let* ((key (match-string 99 string)))
|
||||
(run-hook-with-args-until-success
|
||||
'magit-process-find-password-functions key))
|
||||
(read-passwd prompt))
|
||||
"\n")))))
|
||||
process
|
||||
(concat (or (and-let* ((key (match-string 99 string)))
|
||||
(run-hook-with-args-until-success
|
||||
'magit-process-find-password-functions key))
|
||||
(let ((read-passwd-map
|
||||
(magit-process-make-keymap process read-passwd-map)))
|
||||
(read-passwd prompt)))
|
||||
"\n"))))
|
||||
|
||||
(defun magit-process-username-prompt (process string)
|
||||
"Forward username prompts to the user."
|
||||
(--when-let (magit-process-match-prompt
|
||||
magit-process-username-prompt-regexps string)
|
||||
(when-let ((prompt (magit-process-match-prompt
|
||||
magit-process-username-prompt-regexps string)))
|
||||
(process-send-string
|
||||
process (magit-process-kill-on-abort process
|
||||
(concat (read-string it nil nil (user-login-name)) "\n")))))
|
||||
process
|
||||
(let ((minibuffer-local-map
|
||||
(magit-process-make-keymap process minibuffer-local-map)))
|
||||
(concat (read-string prompt nil nil (user-login-name)) "\n")))))
|
||||
|
||||
(defun magit-process-match-prompt (prompts string)
|
||||
"Match STRING against PROMPTS and set match data.
|
||||
@@ -931,7 +972,7 @@ as argument."
|
||||
(magit-git-executable)
|
||||
"credential-cache--daemon"
|
||||
magit-credential-cache-daemon-socket)
|
||||
;; Some Git implementations (e.g. Windows) won't have
|
||||
;; Some Git implementations (e.g., Windows) won't have
|
||||
;; this program; if we fail the first time, stop trying.
|
||||
((debug error)
|
||||
(remove-hook 'magit-credential-hook
|
||||
@@ -962,12 +1003,9 @@ as argument."
|
||||
(advice-add 'tramp-sh-handle-process-file :around
|
||||
#'tramp-sh-handle-process-file--magit-tramp-process-environment)
|
||||
|
||||
(defvar magit-mode-line-process-map
|
||||
(let ((map (make-sparse-keymap)))
|
||||
(define-key map (kbd "<mode-line> <mouse-1>")
|
||||
'magit-process-buffer)
|
||||
map)
|
||||
"Keymap for `mode-line-process'.")
|
||||
(defvar-keymap magit-mode-line-process-map
|
||||
:doc "Keymap for `mode-line-process'."
|
||||
"<mode-line> <mouse-1>" ''magit-process-buffer)
|
||||
|
||||
(defun magit-process-set-mode-line (program args)
|
||||
"Display the git command (sans arguments) in the mode line."
|
||||
@@ -1142,11 +1180,10 @@ Limited by `magit-process-error-tooltip-max-lines'."
|
||||
(goto-char (1+ (line-end-position)))
|
||||
(delete-char -1)
|
||||
(oset section content nil))
|
||||
(let ((buf (magit-process-buffer t)))
|
||||
(when (and (= arg 0)
|
||||
(not (--any-p (eq (window-buffer it) buf)
|
||||
(window-list))))
|
||||
(magit-section-hide section)))))))
|
||||
(when (and (= arg 0)
|
||||
(not (--any-p (eq (window-buffer it) process-buf)
|
||||
(window-list))))
|
||||
(magit-section-hide section))))))
|
||||
(if (= arg 0)
|
||||
;; Unset the `mode-line-process' value upon success.
|
||||
(magit-process-unset-mode-line default-dir)
|
||||
|
||||
Reference in New Issue
Block a user