Function: magit-start-process

magit-start-process is a byte-compiled function defined in magit-process.el.

Signature

(magit-start-process PROGRAM &optional INPUT &rest ARGS)

Documentation

Start PROGRAM, prepare for refresh, and return the process object.

If optional argument INPUT is non-nil, it has to be a buffer or the name of an existing buffer. The buffer content becomes the processes standard input.

The process is started using start-file-process and then setup to use the sentinel magit-process-sentinel and the filter magit-process-filter. Information required by these functions is stored in the process object. When this function returns the process has not started to run yet so it is possible to override the sentinel and filter.

After the process returns, magit-process-sentinel refreshes the buffer that was current when magit-start-process was called (if it is a Magit buffer and still alive), as well as the respective Magit status buffer.

Source Code

;; Defined in ~/.emacs.d/elpa/magit-20260411.1452/magit-process.el
(defun magit-start-process (program &optional input &rest args)
  "Start PROGRAM, prepare for refresh, and return the process object.

If optional argument INPUT is non-nil, it has to be a buffer or
the name of an existing buffer.  The buffer content becomes the
processes standard input.

The process is started using `start-file-process' and then setup
to use the sentinel `magit-process-sentinel' and the filter
`magit-process-filter'.  Information required by these functions
is stored in the process object.  When this function returns the
process has not started to run yet so it is possible to override
the sentinel and filter.

After the process returns, `magit-process-sentinel' refreshes the
buffer that was current when `magit-start-process' was called (if
it is a Magit buffer and still alive), as well as the respective
Magit status buffer."
  (pcase-let*
      ((`(,process-buf . ,section)
        (magit-process-setup program args))
       (process
        (let ((process-connection-type ;t=pty nil=pipe
               (or
                ;; With Tramp, maybe force use a pty.  #4720
                (and (file-remote-p default-directory)
                     (eq magit-tramp-pipe-stty-settings 'pty))
                ;; Without input, don't use a pty, because it would
                ;; set icrnl, which would modify the input.  #20
                (and (not input) magit-process-connection-type)))
              (tramp-pipe-stty-settings
               (or (and (not (eq magit-tramp-pipe-stty-settings 'pty))
                        ;; Defaults to "", to allow staging hunks over
                        ;; Tramp again.  #4720
                        magit-tramp-pipe-stty-settings)
                   (bound-and-true-p tramp-pipe-stty-settings)))
              (process-environment (magit-process-environment))
              (default-process-coding-system (magit--process-coding-system)))
          (apply #'start-file-process
                 (file-name-nondirectory program)
                 process-buf program args))))
    (with-editor-set-process-filter process #'magit-process-filter)
    (set-process-sentinel process #'magit-process-sentinel)
    (set-process-buffer   process process-buf)
    (when (eq system-type 'windows-nt)
      ;; On w32, git expects UTF-8 encoded input, ignore any user
      ;; configuration telling us otherwise.
      (set-process-coding-system process nil 'utf-8-unix))
    (process-put process 'section section)
    (process-put process 'command-buf (current-buffer))
    (process-put process 'default-dir default-directory)
    (when magit-inhibit-refresh
      (process-put process 'inhibit-refresh t))
    (oset section process process)
    (with-current-buffer process-buf
      (set-marker (process-mark process) (point)))
    (when input
      (with-current-buffer input
        (process-send-region process (point-min) (point-max))
        ;; `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)
    process))