Commit c6fbd96d authored by Jonas Bernoulli's avatar Jonas Bernoulli

magit-process-buffer: truncate sections if appropriate

Now that `magit-process-buffer' always creates the buffer if it doesn't
exist yet, we can perform all the housekeeping here.  When appropriate
truncate the sections here instead of in `magit-process-setup'.
parent 45222024
...@@ -136,15 +136,17 @@ When this is nil, no sections are ever removed." ...@@ -136,15 +136,17 @@ When this is nil, no sections are ever removed."
(hack-dir-local-variables-non-file-buffer)) (hack-dir-local-variables-non-file-buffer))
(defun magit-process-buffer () (defun magit-process-buffer ()
(or (magit-mode-get-buffer 'magit-process-mode) (let ((buf (magit-mode-get-buffer-create 'magit-process-mode)))
(with-current-buffer (with-current-buffer buf
(magit-mode-get-buffer-create 'magit-process-mode) (if magit-root-section
(when magit-process-log-max
(magit-process-truncate-log))
(magit-process-mode) (magit-process-mode)
(let ((inhibit-read-only t)) (let ((inhibit-read-only t))
(make-local-variable 'text-property-default-nonsticky) (make-local-variable 'text-property-default-nonsticky)
(magit-insert-section (processbuf) (magit-insert-section (processbuf)
(insert "\n"))) (insert "\n")))))
(current-buffer)))) buf))
(defun magit-process () (defun magit-process ()
"Display Magit process buffer." "Display Magit process buffer."
...@@ -454,7 +456,6 @@ tracked in the current repository are reverted if ...@@ -454,7 +456,6 @@ tracked in the current repository are reverted if
(let ((pwd default-directory) (let ((pwd default-directory)
(buf (magit-process-buffer))) (buf (magit-process-buffer)))
(cons buf (with-current-buffer buf (cons buf (with-current-buffer buf
(magit-process-truncate-log buf)
(prog1 (magit-process-insert-section pwd program args nil nil) (prog1 (magit-process-insert-section pwd program args nil nil)
(backward-char 1)))))) (backward-char 1))))))
...@@ -487,28 +488,26 @@ tracked in the current repository are reverted if ...@@ -487,28 +488,26 @@ tracked in the current repository are reverted if
(goto-char (1- (point-max)))) (goto-char (1- (point-max))))
(insert "\n")))) (insert "\n"))))
(defun magit-process-truncate-log (buffer) (defun magit-process-truncate-log ()
(when magit-process-log-max (let* ((head nil)
(with-current-buffer buffer (tail (magit-section-children magit-root-section))
(let* ((head nil) (count (length tail)))
(tail (magit-section-children magit-root-section)) (when (> (1+ count) magit-process-log-max)
(count (length tail))) (while (and (cdr tail)
(when (> (1+ count) magit-process-log-max) (> count (/ magit-process-log-max 2)))
(while (and (cdr tail) (let* ((inhibit-read-only t)
(> count (/ magit-process-log-max 2))) (section (car tail))
(let* ((inhibit-read-only t) (process (magit-section-process section)))
(section (car tail)) (cond ((not process))
(process (magit-section-process section))) ((memq (process-status process) '(exit signal))
(cond ((not process)) (delete-region (magit-section-start section)
((memq (process-status process) '(exit signal)) (1+ (magit-section-end section)))
(delete-region (magit-section-start section) (cl-decf count))
(1+ (magit-section-end section))) (t
(cl-decf count)) (push section head))))
(t (pop tail))
(push section head)))) (setf (magit-section-children magit-root-section)
(pop tail)) (nconc (reverse head) tail)))))
(setf (magit-section-children magit-root-section)
(nconc (reverse head) tail)))))))
(defun magit-process-sentinel (process event) (defun magit-process-sentinel (process event)
"Default sentinel used by `magit-start-process'." "Default sentinel used by `magit-start-process'."
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment